Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 0a4fc9f

Browse files
committed
Migrate the engine to use an API that knows about screens.
1 parent 4162095 commit 0a4fc9f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2404
-723
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ FILE: ../../../flutter/lib/ui/ui_benchmarks.cc
394394
FILE: ../../../flutter/lib/ui/ui_dart_state.cc
395395
FILE: ../../../flutter/lib/ui/ui_dart_state.h
396396
FILE: ../../../flutter/lib/ui/window.dart
397+
FILE: ../../../flutter/lib/ui/window/platform_configuration.cc
398+
FILE: ../../../flutter/lib/ui/window/platform_configuration.h
399+
FILE: ../../../flutter/lib/ui/window/platform_configuration_unittests.cc
397400
FILE: ../../../flutter/lib/ui/window/platform_message.cc
398401
FILE: ../../../flutter/lib/ui/window/platform_message.h
399402
FILE: ../../../flutter/lib/ui/window/platform_message_response.cc
@@ -407,6 +410,10 @@ FILE: ../../../flutter/lib/ui/window/pointer_data_packet.h
407410
FILE: ../../../flutter/lib/ui/window/pointer_data_packet_converter.cc
408411
FILE: ../../../flutter/lib/ui/window/pointer_data_packet_converter.h
409412
FILE: ../../../flutter/lib/ui/window/pointer_data_packet_converter_unittests.cc
413+
FILE: ../../../flutter/lib/ui/window/screen.cc
414+
FILE: ../../../flutter/lib/ui/window/screen.h
415+
FILE: ../../../flutter/lib/ui/window/screen_metrics.cc
416+
FILE: ../../../flutter/lib/ui/window/screen_metrics.h
410417
FILE: ../../../flutter/lib/ui/window/viewport_metrics.cc
411418
FILE: ../../../flutter/lib/ui/window/viewport_metrics.h
412419
FILE: ../../../flutter/lib/ui/window/window.cc

examples/glfw/FlutterEmbedderGLFW.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,31 @@ static void GLFWKeyCallback(GLFWwindow* window,
6868
}
6969

7070
void GLFWwindowSizeCallback(GLFWwindow* window, int width, int height) {
71+
int left, top;
72+
glfwGetWindowPos(window, &left, &top);
7173
FlutterWindowMetricsEvent event = {};
7274
event.struct_size = sizeof(event);
75+
event.window_id = 0;
76+
event.screen_id = 0;
77+
event.left = left * g_pixelRatio;
78+
event.top = top * g_pixelRatio;
79+
event.width = width * g_pixelRatio;
80+
event.height = height * g_pixelRatio;
81+
event.pixel_ratio = g_pixelRatio;
82+
FlutterEngineSendWindowMetricsEvent(
83+
reinterpret_cast<FlutterEngine>(glfwGetWindowUserPointer(window)),
84+
&event);
85+
}
86+
87+
void GLFWwindowPosCallback(GLFWwindow* window, int left, int top) {
88+
int width, height;
89+
glfwGetWindowSize(window, &width, &height);
90+
FlutterWindowMetricsEvent event = {};
91+
event.struct_size = sizeof(event);
92+
event.window_id = 0;
93+
event.screen_id = 0;
94+
event.left = left * g_pixelRatio;
95+
event.top = top * g_pixelRatio;
7396
event.width = width * g_pixelRatio;
7497
event.height = height * g_pixelRatio;
7598
event.pixel_ratio = g_pixelRatio;
@@ -150,6 +173,7 @@ int main(int argc, const char* argv[]) {
150173

151174
glfwSetKeyCallback(window, GLFWKeyCallback);
152175
glfwSetWindowSizeCallback(window, GLFWwindowSizeCallback);
176+
glfwSetWindowPosCallback(window, GLFWwindowPosCallback);
153177
glfwSetMouseButtonCallback(window, GLFWmouseButtonCallback);
154178

155179
while (!glfwWindowShouldClose(window)) {

lib/ui/BUILD.gn

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ source_set_maybe_fuchsia_legacy("ui") {
8989
"text/text_box.h",
9090
"ui_dart_state.cc",
9191
"ui_dart_state.h",
92+
"window/platform_configuration.cc",
93+
"window/platform_configuration.h",
9294
"window/platform_message.cc",
9395
"window/platform_message.h",
9496
"window/platform_message_response.cc",
@@ -101,6 +103,10 @@ source_set_maybe_fuchsia_legacy("ui") {
101103
"window/pointer_data_packet.h",
102104
"window/pointer_data_packet_converter.cc",
103105
"window/pointer_data_packet_converter.h",
106+
"window/screen.cc",
107+
"window/screen.h",
108+
"window/screen_metrics.cc",
109+
"window/screen_metrics.h",
104110
"window/viewport_metrics.cc",
105111
"window/viewport_metrics.h",
106112
"window/window.cc",
@@ -162,6 +168,7 @@ if (current_toolchain == host_toolchain) {
162168
sources = [
163169
"painting/image_decoder_unittests.cc",
164170
"painting/vertices_unittests.cc",
171+
"window/platform_configuration_unittests.cc",
165172
"window/pointer_data_packet_converter_unittests.cc",
166173
]
167174

lib/ui/compositing/scene.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "flutter/lib/ui/painting/image.h"
99
#include "flutter/lib/ui/painting/picture.h"
1010
#include "flutter/lib/ui/ui_dart_state.h"
11+
#include "flutter/lib/ui/window/platform_configuration.h"
1112
#include "flutter/lib/ui/window/window.h"
1213
#include "third_party/skia/include/core/SkImageInfo.h"
1314
#include "third_party/skia/include/core/SkSurface.h"
@@ -41,7 +42,13 @@ Scene::Scene(std::shared_ptr<flutter::Layer> rootLayer,
4142
uint32_t rasterizerTracingThreshold,
4243
bool checkerboardRasterCacheImages,
4344
bool checkerboardOffscreenLayers) {
44-
auto viewport_metrics = UIDartState::Current()->window()->viewport_metrics();
45+
// TODO(gspencergoog): Currently, there is only one window. This will change
46+
// as multi-window support is added. See
47+
// https://github.com/flutter/flutter/issues/60131
48+
auto viewport_metrics = UIDartState::Current()
49+
->platform_configuration()
50+
->get_window(0)
51+
->viewport_metrics();
4552

4653
layer_tree_ = std::make_unique<LayerTree>(
4754
SkISize::Make(viewport_metrics.physical_width,

lib/ui/dart_ui.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "flutter/lib/ui/text/font_collection.h"
2929
#include "flutter/lib/ui/text/paragraph.h"
3030
#include "flutter/lib/ui/text/paragraph_builder.h"
31-
#include "flutter/lib/ui/window/window.h"
31+
#include "flutter/lib/ui/window/platform_configuration.h"
3232
#include "third_party/tonic/converter/dart_converter.h"
3333
#include "third_party/tonic/logging/dart_error.h"
3434

@@ -81,7 +81,7 @@ void DartUI::InitForGlobal() {
8181
SemanticsUpdate::RegisterNatives(g_natives);
8282
SemanticsUpdateBuilder::RegisterNatives(g_natives);
8383
Vertices::RegisterNatives(g_natives);
84-
Window::RegisterNatives(g_natives);
84+
PlatformConfiguration::RegisterNatives(g_natives);
8585
#if defined(LEGACY_FUCHSIA_EMBEDDER)
8686
SceneHost::RegisterNatives(g_natives);
8787
#endif

lib/ui/hooks.dart

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,32 @@ void _updateWindowMetrics(
5555
_invoke(window.onMetricsChanged, window._onMetricsChangedZone);
5656
}
5757

58+
@pragma('vm:entry-point')
59+
// ignore: unused_element
60+
void _updateScreenMetrics(
61+
Object screenId,
62+
double left,
63+
double top,
64+
double width,
65+
double height,
66+
double devicePixelRatio,
67+
double viewPaddingTop,
68+
double viewPaddingRight,
69+
double viewPaddingBottom,
70+
double viewPaddingLeft,
71+
double viewInsetTop,
72+
double viewInsetRight,
73+
double viewInsetBottom,
74+
double viewInsetLeft,
75+
double systemGestureInsetTop,
76+
double systemGestureInsetRight,
77+
double systemGestureInsetBottom,
78+
double systemGestureInsetLeft,
79+
) {
80+
// TODO(gspencergoog): Once dart:ui understands screens, set their metrics
81+
// here. See https://github.com/flutter/flutter/issues/60131
82+
}
83+
5884
typedef _LocaleClosure = String? Function();
5985

6086
String? _localeClosure() {
@@ -238,7 +264,7 @@ void _runMainZoned(Function startMainIsolateFunction,
238264
}, null);
239265
}
240266

241-
void _reportUnhandledException(String error, String stackTrace) native 'Window_reportUnhandledException';
267+
void _reportUnhandledException(String error, String stackTrace) native 'PlatformConfiguration_reportUnhandledException';
242268

243269
/// Invokes [callback] inside the given [zone].
244270
void _invoke(void callback()?, Zone zone) {

lib/ui/painting/canvas.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "flutter/lib/ui/painting/image.h"
1212
#include "flutter/lib/ui/painting/matrix.h"
1313
#include "flutter/lib/ui/ui_dart_state.h"
14+
#include "flutter/lib/ui/window/platform_configuration.h"
1415
#include "flutter/lib/ui/window/window.h"
1516
#include "third_party/skia/include/core/SkBitmap.h"
1617
#include "third_party/skia/include/core/SkCanvas.h"
@@ -422,11 +423,18 @@ void Canvas::drawShadow(const CanvasPath* path,
422423
SkColor color,
423424
double elevation,
424425
bool transparentOccluder) {
425-
if (!path)
426+
if (!path) {
426427
Dart_ThrowException(
427428
ToDart("Canvas.drawShader called with non-genuine Path."));
428-
SkScalar dpr =
429-
UIDartState::Current()->window()->viewport_metrics().device_pixel_ratio;
429+
}
430+
// TODO(gspencergoog): Currently, there is only one window. This will change
431+
// as multi-window support is added. See
432+
// https://github.com/flutter/flutter/issues/60131
433+
SkScalar dpr = UIDartState::Current()
434+
->platform_configuration()
435+
->get_window(0)
436+
->viewport_metrics()
437+
.device_pixel_ratio;
430438
external_allocation_size_ += path->path().approximateBytesUsed();
431439
flutter::PhysicalShapeLayer::DrawShadow(canvas_, path->path(), color,
432440
elevation, transparentOccluder, dpr);

lib/ui/text/font_collection.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "flutter/lib/ui/text/asset_manager_font_provider.h"
1010
#include "flutter/lib/ui/ui_dart_state.h"
11-
#include "flutter/lib/ui/window/window.h"
11+
#include "flutter/lib/ui/window/platform_configuration.h"
1212
#include "flutter/runtime/test_font_data.h"
1313
#include "rapidjson/document.h"
1414
#include "rapidjson/rapidjson.h"
@@ -30,8 +30,10 @@ namespace {
3030
void LoadFontFromList(tonic::Uint8List& font_data,
3131
Dart_Handle callback,
3232
std::string family_name) {
33-
FontCollection& font_collection =
34-
UIDartState::Current()->window()->client()->GetFontCollection();
33+
FontCollection& font_collection = UIDartState::Current()
34+
->platform_configuration()
35+
->client()
36+
->GetFontCollection();
3537
font_collection.LoadFontFromList(font_data.data(), font_data.num_elements(),
3638
family_name);
3739
font_data.Release();

lib/ui/text/paragraph_builder.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "flutter/fml/task_runner.h"
1111
#include "flutter/lib/ui/text/font_collection.h"
1212
#include "flutter/lib/ui/ui_dart_state.h"
13-
#include "flutter/lib/ui/window/window.h"
13+
#include "flutter/lib/ui/window/platform_configuration.h"
1414
#include "flutter/third_party/txt/src/txt/font_style.h"
1515
#include "flutter/third_party/txt/src/txt/font_weight.h"
1616
#include "flutter/third_party/txt/src/txt/paragraph_style.h"
@@ -288,8 +288,10 @@ ParagraphBuilder::ParagraphBuilder(
288288
style.locale = locale;
289289
}
290290

291-
FontCollection& font_collection =
292-
UIDartState::Current()->window()->client()->GetFontCollection();
291+
FontCollection& font_collection = UIDartState::Current()
292+
->platform_configuration()
293+
->client()
294+
->GetFontCollection();
293295

294296
#if FLUTTER_ENABLE_SKSHAPER
295297
#define FLUTTER_PARAGRAPH_BUILDER txt::ParagraphBuilder::CreateSkiaBuilder

lib/ui/ui_dart_state.cc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "flutter/lib/ui/ui_dart_state.h"
66

77
#include "flutter/fml/message_loop.h"
8+
#include "flutter/lib/ui/window/platform_configuration.h"
89
#include "flutter/lib/ui/window/window.h"
910
#include "third_party/tonic/converter/dart_converter.h"
1011
#include "third_party/tonic/dart_message_handler.h"
@@ -73,18 +74,23 @@ void UIDartState::ThrowIfUIOperationsProhibited() {
7374

7475
void UIDartState::SetDebugName(const std::string debug_name) {
7576
debug_name_ = debug_name;
76-
if (window_)
77-
window_->client()->UpdateIsolateDescription(debug_name_, main_port_);
77+
if (platform_configuration_) {
78+
platform_configuration_->client()->UpdateIsolateDescription(debug_name_,
79+
main_port_);
80+
}
7881
}
7982

8083
UIDartState* UIDartState::Current() {
8184
return static_cast<UIDartState*>(DartState::Current());
8285
}
8386

84-
void UIDartState::SetWindow(std::unique_ptr<Window> window) {
85-
window_ = std::move(window);
86-
if (window_)
87-
window_->client()->UpdateIsolateDescription(debug_name_, main_port_);
87+
void UIDartState::SetPlatformConfiguration(
88+
std::unique_ptr<PlatformConfiguration> platform_configuration) {
89+
platform_configuration_ = std::move(platform_configuration);
90+
if (platform_configuration_) {
91+
platform_configuration_->client()->UpdateIsolateDescription(debug_name_,
92+
main_port_);
93+
}
8894
}
8995

9096
const TaskRunners& UIDartState::GetTaskRunners() const {

0 commit comments

Comments
 (0)