Skip to content

Commit da7c7a3

Browse files
authored
Add foundational support for Windows multi-window in the engine (#15)
1 parent bbb45fb commit da7c7a3

18 files changed

+1666
-0
lines changed

engine/src/flutter/ci/licenses_golden/excluded_files

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,10 @@
402402
../../../flutter/shell/platform/windows/direct_manipulation_unittests.cc
403403
../../../flutter/shell/platform/windows/dpi_utils_unittests.cc
404404
../../../flutter/shell/platform/windows/fixtures
405+
../../../flutter/shell/platform/windows/flutter_host_window_controller_unittests.cc
405406
../../../flutter/shell/platform/windows/flutter_project_bundle_unittests.cc
406407
../../../flutter/shell/platform/windows/flutter_window_unittests.cc
408+
../../../flutter/shell/platform/windows/flutter_windowing_handler_unittests.cc
407409
../../../flutter/shell/platform/windows/flutter_windows_engine_unittests.cc
408410
../../../flutter/shell/platform/windows/flutter_windows_texture_registrar_unittests.cc
409411
../../../flutter/shell/platform/windows/flutter_windows_unittests.cc

engine/src/flutter/ci/licenses_golden/licenses_flutter

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43825,6 +43825,7 @@ ORIGIN: ../../../flutter/shell/platform/common/text_editing_delta.h + ../../../f
4382543825
ORIGIN: ../../../flutter/shell/platform/common/text_input_model.cc + ../../../flutter/LICENSE
4382643826
ORIGIN: ../../../flutter/shell/platform/common/text_input_model.h + ../../../flutter/LICENSE
4382743827
ORIGIN: ../../../flutter/shell/platform/common/text_range.h + ../../../flutter/LICENSE
43828+
ORIGIN: ../../../flutter/shell/platform/common/windowing.h + ../../../flutter/LICENSE
4382843829
ORIGIN: ../../../flutter/shell/platform/darwin/common/availability_version_check.cc + ../../../flutter/LICENSE
4382943830
ORIGIN: ../../../flutter/shell/platform/darwin/common/availability_version_check.h + ../../../flutter/LICENSE
4383043831
ORIGIN: ../../../flutter/shell/platform/darwin/common/buffer_conversions.h + ../../../flutter/LICENSE
@@ -44556,6 +44557,10 @@ ORIGIN: ../../../flutter/shell/platform/windows/flutter_platform_node_delegate_w
4455644557
ORIGIN: ../../../flutter/shell/platform/windows/flutter_platform_node_delegate_windows.h + ../../../flutter/LICENSE
4455744558
ORIGIN: ../../../flutter/shell/platform/windows/flutter_project_bundle.cc + ../../../flutter/LICENSE
4455844559
ORIGIN: ../../../flutter/shell/platform/windows/flutter_project_bundle.h + ../../../flutter/LICENSE
44560+
ORIGIN: ../../../flutter/shell/platform/windows/flutter_host_window.cc + ../../../flutter/LICENSE
44561+
ORIGIN: ../../../flutter/shell/platform/windows/flutter_host_window.h + ../../../flutter/LICENSE
44562+
ORIGIN: ../../../flutter/shell/platform/windows/flutter_host_window_controller.cc + ../../../flutter/LICENSE
44563+
ORIGIN: ../../../flutter/shell/platform/windows/flutter_host_window_controller.h + ../../../flutter/LICENSE
4455944564
ORIGIN: ../../../flutter/shell/platform/windows/flutter_window.cc + ../../../flutter/LICENSE
4456044565
ORIGIN: ../../../flutter/shell/platform/windows/flutter_window.h + ../../../flutter/LICENSE
4456144566
ORIGIN: ../../../flutter/shell/platform/windows/flutter_windows.cc + ../../../flutter/LICENSE
@@ -44605,6 +44610,8 @@ ORIGIN: ../../../flutter/shell/platform/windows/window_binding_handler_delegate.
4460544610
ORIGIN: ../../../flutter/shell/platform/windows/window_proc_delegate_manager.cc + ../../../flutter/LICENSE
4460644611
ORIGIN: ../../../flutter/shell/platform/windows/window_proc_delegate_manager.h + ../../../flutter/LICENSE
4460744612
ORIGIN: ../../../flutter/shell/platform/windows/window_state.h + ../../../flutter/LICENSE
44613+
ORIGIN: ../../../flutter/shell/platform/windows/windowing_handle.cc + ../../../flutter/LICENSE
44614+
ORIGIN: ../../../flutter/shell/platform/windows/windowing_handle.h + ../../../flutter/LICENSE
4460844615
ORIGIN: ../../../flutter/shell/platform/windows/windows_lifecycle_manager.cc + ../../../flutter/LICENSE
4460944616
ORIGIN: ../../../flutter/shell/platform/windows/windows_lifecycle_manager.h + ../../../flutter/LICENSE
4461044617
ORIGIN: ../../../flutter/shell/platform/windows/windows_proc_table.cc + ../../../flutter/LICENSE
@@ -46778,6 +46785,7 @@ FILE: ../../../flutter/shell/platform/common/text_editing_delta.h
4677846785
FILE: ../../../flutter/shell/platform/common/text_input_model.cc
4677946786
FILE: ../../../flutter/shell/platform/common/text_input_model.h
4678046787
FILE: ../../../flutter/shell/platform/common/text_range.h
46788+
FILE: ../../../flutter/shell/platform/common/windowing.h
4678146789
FILE: ../../../flutter/shell/platform/darwin/common/availability_version_check.cc
4678246790
FILE: ../../../flutter/shell/platform/darwin/common/availability_version_check.h
4678346791
FILE: ../../../flutter/shell/platform/darwin/common/buffer_conversions.h
@@ -47524,6 +47532,10 @@ FILE: ../../../flutter/shell/platform/windows/flutter_platform_node_delegate_win
4752447532
FILE: ../../../flutter/shell/platform/windows/flutter_platform_node_delegate_windows.h
4752547533
FILE: ../../../flutter/shell/platform/windows/flutter_project_bundle.cc
4752647534
FILE: ../../../flutter/shell/platform/windows/flutter_project_bundle.h
47535+
FILE: ../../../flutter/shell/platform/windows/flutter_host_window.cc
47536+
FILE: ../../../flutter/shell/platform/windows/flutter_host_window.h
47537+
FILE: ../../../flutter/shell/platform/windows/flutter_host_window_controller.cc
47538+
FILE: ../../../flutter/shell/platform/windows/flutter_host_window_controller.h
4752747539
FILE: ../../../flutter/shell/platform/windows/flutter_window.cc
4752847540
FILE: ../../../flutter/shell/platform/windows/flutter_window.h
4752947541
FILE: ../../../flutter/shell/platform/windows/flutter_windows.cc
@@ -47573,6 +47585,8 @@ FILE: ../../../flutter/shell/platform/windows/window_binding_handler_delegate.h
4757347585
FILE: ../../../flutter/shell/platform/windows/window_proc_delegate_manager.cc
4757447586
FILE: ../../../flutter/shell/platform/windows/window_proc_delegate_manager.h
4757547587
FILE: ../../../flutter/shell/platform/windows/window_state.h
47588+
FILE: ../../../flutter/shell/platform/windows/windowing_handler.cc
47589+
FILE: ../../../flutter/shell/platform/windows/windowing_handler.h
4757647590
FILE: ../../../flutter/shell/platform/windows/windows_lifecycle_manager.cc
4757747591
FILE: ../../../flutter/shell/platform/windows/windows_lifecycle_manager.h
4757847592
FILE: ../../../flutter/shell/platform/windows/windows_proc_table.cc

engine/src/flutter/common/settings.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ struct Settings {
367367
// If true, the UI thread is the platform thread on supported
368368
// platforms.
369369
bool merged_platform_ui_thread = true;
370+
371+
// Enable support for multiple windows. Ignored if not supported on the
372+
// platform.
373+
bool enable_multi_window = false;
370374
};
371375

372376
} // namespace flutter

engine/src/flutter/shell/common/switches.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,17 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
532532
settings.merged_platform_ui_thread = !command_line.HasOption(
533533
FlagForSwitch(Switch::DisableMergedPlatformUIThread));
534534

535+
#if FML_OS_WIN
536+
// Process the EnableMultiWindow switch on Windows.
537+
{
538+
std::string enable_multi_window_value;
539+
if (command_line.GetOptionValue(FlagForSwitch(Switch::EnableMultiWindow),
540+
&enable_multi_window_value)) {
541+
settings.enable_multi_window = "true" == enable_multi_window_value;
542+
}
543+
}
544+
#endif // FML_OS_WIN
545+
535546
return settings;
536547
}
537548

engine/src/flutter/shell/common/switches.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ DEF_SWITCH(DisableMergedPlatformUIThread,
300300
DEF_SWITCH(DisableAndroidSurfaceControl,
301301
"disable-surface-control",
302302
"Disable the SurfaceControl backed swapchain even when supported.")
303+
DEF_SWITCH(EnableMultiWindow,
304+
"enable-multi-window",
305+
"Enable support for multiple windows. Ignored if not supported on "
306+
"the platform.")
303307
DEF_SWITCHES_END
304308

305309
void PrintUsage(const std::string& executable_name);

engine/src/flutter/shell/platform/common/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ source_set("common_cpp_core") {
142142
public = [
143143
"geometry.h",
144144
"path_utils.h",
145+
"windowing.h",
145146
]
146147

147148
sources = [ "path_utils.cc" ]
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef FLUTTER_SHELL_PLATFORM_COMMON_WINDOWING_H_
6+
#define FLUTTER_SHELL_PLATFORM_COMMON_WINDOWING_H_
7+
8+
#include <optional>
9+
10+
namespace flutter {
11+
12+
// A unique identifier for a view.
13+
using FlutterViewId = int64_t;
14+
15+
// A point in 2D space for window positioning using integer coordinates.
16+
struct WindowPoint {
17+
int x = 0;
18+
int y = 0;
19+
20+
friend WindowPoint operator+(WindowPoint const& lhs, WindowPoint const& rhs) {
21+
return {lhs.x + rhs.x, lhs.y + rhs.y};
22+
}
23+
24+
friend WindowPoint operator-(WindowPoint const& lhs, WindowPoint const& rhs) {
25+
return {lhs.x - rhs.x, lhs.y - rhs.y};
26+
}
27+
28+
friend bool operator==(WindowPoint const& lhs, WindowPoint const& rhs) {
29+
return lhs.x == rhs.x && lhs.y == rhs.y;
30+
}
31+
};
32+
33+
// A 2D size using integer dimensions.
34+
struct WindowSize {
35+
int width = 0;
36+
int height = 0;
37+
38+
explicit operator WindowPoint() const { return {width, height}; }
39+
40+
friend bool operator==(WindowSize const& lhs, WindowSize const& rhs) {
41+
return lhs.width == rhs.width && lhs.height == rhs.height;
42+
}
43+
};
44+
45+
// A rectangular area defined by a top-left point and size.
46+
struct WindowRectangle {
47+
WindowPoint top_left;
48+
WindowSize size;
49+
50+
// Checks if this rectangle fully contains |rect|.
51+
// Note: An empty rectangle can still contain other empty rectangles,
52+
// which are treated as points or lines of thickness zero
53+
bool contains(WindowRectangle const& rect) const {
54+
return rect.top_left.x >= top_left.x &&
55+
rect.top_left.x + rect.size.width <= top_left.x + size.width &&
56+
rect.top_left.y >= top_left.y &&
57+
rect.top_left.y + rect.size.height <= top_left.y + size.height;
58+
}
59+
60+
friend bool operator==(WindowRectangle const& lhs,
61+
WindowRectangle const& rhs) {
62+
return lhs.top_left == rhs.top_left && lhs.size == rhs.size;
63+
}
64+
};
65+
66+
// Types of windows.
67+
enum class WindowArchetype {
68+
// Regular top-level window.
69+
regular,
70+
};
71+
72+
// Window metadata returned as the result of creating a Flutter window.
73+
struct WindowMetadata {
74+
// The ID of the view used for this window, which is unique to each window.
75+
FlutterViewId view_id = 0;
76+
// The type of the window.
77+
WindowArchetype archetype = WindowArchetype::regular;
78+
// Size of the created window, in logical coordinates.
79+
WindowSize size;
80+
// The ID of the view used by the parent window. If not set, the window is
81+
// assumed a top-level window.
82+
std::optional<FlutterViewId> parent_id;
83+
};
84+
85+
} // namespace flutter
86+
87+
#endif // FLUTTER_SHELL_PLATFORM_COMMON_WINDOWING_H_

engine/src/flutter/shell/platform/windows/BUILD.gn

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ source_set("flutter_windows_source") {
7373
"external_texture_d3d.h",
7474
"external_texture_pixelbuffer.cc",
7575
"external_texture_pixelbuffer.h",
76+
"flutter_host_window.cc",
77+
"flutter_host_window.h",
78+
"flutter_host_window_controller.cc",
79+
"flutter_host_window_controller.h",
7680
"flutter_key_map.g.cc",
7781
"flutter_platform_node_delegate_windows.cc",
7882
"flutter_platform_node_delegate_windows.h",
@@ -125,6 +129,8 @@ source_set("flutter_windows_source") {
125129
"window_proc_delegate_manager.cc",
126130
"window_proc_delegate_manager.h",
127131
"window_state.h",
132+
"windowing_handler.cc",
133+
"windowing_handler.h",
128134
"windows_lifecycle_manager.cc",
129135
"windows_lifecycle_manager.h",
130136
"windows_proc_table.cc",
@@ -202,6 +208,7 @@ executable("flutter_windows_unittests") {
202208
"cursor_handler_unittests.cc",
203209
"direct_manipulation_unittests.cc",
204210
"dpi_utils_unittests.cc",
211+
"flutter_host_window_controller_unittests.cc",
205212
"flutter_project_bundle_unittests.cc",
206213
"flutter_window_unittests.cc",
207214
"flutter_windows_engine_unittests.cc",
@@ -249,6 +256,7 @@ executable("flutter_windows_unittests") {
249256
"text_input_plugin_unittest.cc",
250257
"window_proc_delegate_manager_unittests.cc",
251258
"window_unittests.cc",
259+
"windowing_handler_unittests.cc",
252260
"windows_lifecycle_manager_unittests.cc",
253261
]
254262

0 commit comments

Comments
 (0)