Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple top-level windows on Windows #56090

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ci/licenses_golden/excluded_files
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@
../../../flutter/shell/platform/windows/direct_manipulation_unittests.cc
../../../flutter/shell/platform/windows/dpi_utils_unittests.cc
../../../flutter/shell/platform/windows/fixtures
../../../flutter/shell/platform/windows/flutter_host_window_controller_unittests.cc
../../../flutter/shell/platform/windows/flutter_project_bundle_unittests.cc
../../../flutter/shell/platform/windows/flutter_window_unittests.cc
../../../flutter/shell/platform/windows/flutter_windows_engine_unittests.cc
Expand All @@ -425,6 +426,7 @@
../../../flutter/shell/platform/windows/text_input_plugin_unittest.cc
../../../flutter/shell/platform/windows/window_proc_delegate_manager_unittests.cc
../../../flutter/shell/platform/windows/window_unittests.cc
../../../flutter/shell/platform/windows/windowing_handler_unittests.cc
../../../flutter/shell/platform/windows/windows_lifecycle_manager_unittests.cc
../../../flutter/shell/profiling/sampling_profiler_unittest.cc
../../../flutter/shell/testing
Expand Down
7 changes: 7 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -47462,6 +47462,7 @@ FILE: ../../../flutter/shell/platform/common/text_editing_delta.h
FILE: ../../../flutter/shell/platform/common/text_input_model.cc
FILE: ../../../flutter/shell/platform/common/text_input_model.h
FILE: ../../../flutter/shell/platform/common/text_range.h
FILE: ../../../flutter/shell/platform/common/windowing.h
FILE: ../../../flutter/shell/platform/darwin/common/availability_version_check.cc
FILE: ../../../flutter/shell/platform/darwin/common/availability_version_check.h
FILE: ../../../flutter/shell/platform/darwin/common/buffer_conversions.h
Expand Down Expand Up @@ -48208,6 +48209,10 @@ FILE: ../../../flutter/shell/platform/windows/flutter_platform_node_delegate_win
FILE: ../../../flutter/shell/platform/windows/flutter_platform_node_delegate_windows.h
FILE: ../../../flutter/shell/platform/windows/flutter_project_bundle.cc
FILE: ../../../flutter/shell/platform/windows/flutter_project_bundle.h
FILE: ../../../flutter/shell/platform/windows/flutter_host_window.cc
FILE: ../../../flutter/shell/platform/windows/flutter_host_window.h
FILE: ../../../flutter/shell/platform/windows/flutter_host_window_controller.cc
FILE: ../../../flutter/shell/platform/windows/flutter_host_window_controller.h
FILE: ../../../flutter/shell/platform/windows/flutter_window.cc
FILE: ../../../flutter/shell/platform/windows/flutter_window.h
FILE: ../../../flutter/shell/platform/windows/flutter_windows.cc
Expand Down Expand Up @@ -48257,6 +48262,8 @@ FILE: ../../../flutter/shell/platform/windows/window_binding_handler_delegate.h
FILE: ../../../flutter/shell/platform/windows/window_proc_delegate_manager.cc
FILE: ../../../flutter/shell/platform/windows/window_proc_delegate_manager.h
FILE: ../../../flutter/shell/platform/windows/window_state.h
FILE: ../../../flutter/shell/platform/windows/windowing_handler.cc
FILE: ../../../flutter/shell/platform/windows/windowing_handler.h
FILE: ../../../flutter/shell/platform/windows/windows_lifecycle_manager.cc
FILE: ../../../flutter/shell/platform/windows/windows_lifecycle_manager.h
FILE: ../../../flutter/shell/platform/windows/windows_proc_table.cc
Expand Down
4 changes: 4 additions & 0 deletions common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ struct Settings {
// If true, the UI thread is the platform thread on supported
// platforms.
bool merged_platform_ui_thread = true;

// Enable support for multiple windows. Ignored if not supported on the
// platform.
bool enable_multi_window = false;
};

} // namespace flutter
Expand Down
11 changes: 11 additions & 0 deletions shell/common/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,17 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
settings.merged_platform_ui_thread = !command_line.HasOption(
FlagForSwitch(Switch::DisableMergedPlatformUIThread));

#if FML_OS_WIN
// Process the EnableMultiWindow switch on Windows.
{
std::string enable_multi_window_value;
if (command_line.GetOptionValue(FlagForSwitch(Switch::EnableMultiWindow),
&enable_multi_window_value)) {
settings.enable_multi_window = "true" == enable_multi_window_value;
}
}
#endif // FML_OS_WIN

return settings;
}

Expand Down
4 changes: 4 additions & 0 deletions shell/common/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ DEF_SWITCH(DisableMergedPlatformUIThread,
DEF_SWITCH(DisableAndroidSurfaceControl,
"disable-surface-control",
"Disable the SurfaceControl backed swapchain even when supported.")
DEF_SWITCH(EnableMultiWindow,
"enable-multi-window",
"Enable support for multiple windows. Ignored if not supported on "
"the platform.")
DEF_SWITCHES_END

void PrintUsage(const std::string& executable_name);
Expand Down
1 change: 1 addition & 0 deletions shell/platform/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ source_set("common_cpp_core") {
public = [
"geometry.h",
"path_utils.h",
"windowing.h",
]

sources = [ "path_utils.cc" ]
Expand Down
87 changes: 87 additions & 0 deletions shell/platform/common/windowing.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FLUTTER_SHELL_PLATFORM_COMMON_WINDOWING_H_
#define FLUTTER_SHELL_PLATFORM_COMMON_WINDOWING_H_

#include <optional>

namespace flutter {

// A unique identifier for a view.
using FlutterViewId = int64_t;

// A point in 2D space for window positioning using integer coordinates.
struct WindowPoint {
int x = 0;
int y = 0;

friend WindowPoint operator+(WindowPoint const& lhs, WindowPoint const& rhs) {
return {lhs.x + rhs.x, lhs.y + rhs.y};
}

friend WindowPoint operator-(WindowPoint const& lhs, WindowPoint const& rhs) {
return {lhs.x - rhs.x, lhs.y - rhs.y};
}

friend bool operator==(WindowPoint const& lhs, WindowPoint const& rhs) {
return lhs.x == rhs.x && lhs.y == rhs.y;
}
};

// A 2D size using integer dimensions.
struct WindowSize {
int width = 0;
int height = 0;

explicit operator WindowPoint() const { return {width, height}; }

friend bool operator==(WindowSize const& lhs, WindowSize const& rhs) {
return lhs.width == rhs.width && lhs.height == rhs.height;
}
};

// A rectangular area defined by a top-left point and size.
struct WindowRectangle {
WindowPoint top_left;
WindowSize size;

// Checks if this rectangle fully contains |rect|.
// Note: An empty rectangle can still contain other empty rectangles,
// which are treated as points or lines of thickness zero
bool contains(WindowRectangle const& rect) const {
return rect.top_left.x >= top_left.x &&
rect.top_left.x + rect.size.width <= top_left.x + size.width &&
rect.top_left.y >= top_left.y &&
rect.top_left.y + rect.size.height <= top_left.y + size.height;
}

friend bool operator==(WindowRectangle const& lhs,
WindowRectangle const& rhs) {
return lhs.top_left == rhs.top_left && lhs.size == rhs.size;
}
};

// Types of windows.
enum class WindowArchetype {
// Regular top-level window.
regular,
};

// Window metadata returned as the result of creating a Flutter window.
struct WindowMetadata {
// The ID of the view used for this window, which is unique to each window.
FlutterViewId view_id = 0;
// The type of the window.
WindowArchetype archetype = WindowArchetype::regular;
// Size of the created window, in logical coordinates.
WindowSize size;
// The ID of the view used by the parent window. If not set, the window is
// assumed a top-level window.
std::optional<FlutterViewId> parent_id;
};

} // namespace flutter

#endif // FLUTTER_SHELL_PLATFORM_COMMON_WINDOWING_H_
8 changes: 8 additions & 0 deletions shell/platform/windows/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ source_set("flutter_windows_source") {
"external_texture_d3d.h",
"external_texture_pixelbuffer.cc",
"external_texture_pixelbuffer.h",
"flutter_host_window.cc",
"flutter_host_window.h",
"flutter_host_window_controller.cc",
"flutter_host_window_controller.h",
"flutter_key_map.g.cc",
"flutter_platform_node_delegate_windows.cc",
"flutter_platform_node_delegate_windows.h",
Expand Down Expand Up @@ -125,6 +129,8 @@ source_set("flutter_windows_source") {
"window_proc_delegate_manager.cc",
"window_proc_delegate_manager.h",
"window_state.h",
"windowing_handler.cc",
"windowing_handler.h",
"windows_lifecycle_manager.cc",
"windows_lifecycle_manager.h",
"windows_proc_table.cc",
Expand Down Expand Up @@ -202,6 +208,7 @@ executable("flutter_windows_unittests") {
"cursor_handler_unittests.cc",
"direct_manipulation_unittests.cc",
"dpi_utils_unittests.cc",
"flutter_host_window_controller_unittests.cc",
"flutter_project_bundle_unittests.cc",
"flutter_window_unittests.cc",
"flutter_windows_engine_unittests.cc",
Expand Down Expand Up @@ -249,6 +256,7 @@ executable("flutter_windows_unittests") {
"text_input_plugin_unittest.cc",
"window_proc_delegate_manager_unittests.cc",
"window_unittests.cc",
"windowing_handler_unittests.cc",
"windows_lifecycle_manager_unittests.cc",
]

Expand Down
Loading
Loading