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

Commit 4ded4dc

Browse files
committed
Move platform specific information to PlatformConfiguration class.
1 parent d9e68f4 commit 4ded4dc

Some content is hidden

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

41 files changed

+973
-690
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 5 additions & 2 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
@@ -569,6 +572,8 @@ FILE: ../../../flutter/runtime/dart_vm_unittests.cc
569572
FILE: ../../../flutter/runtime/embedder_resources.cc
570573
FILE: ../../../flutter/runtime/embedder_resources.h
571574
FILE: ../../../flutter/runtime/fixtures/runtime_test.dart
575+
FILE: ../../../flutter/runtime/platform_data.cc
576+
FILE: ../../../flutter/runtime/platform_data.h
572577
FILE: ../../../flutter/runtime/ptrace_ios.cc
573578
FILE: ../../../flutter/runtime/ptrace_ios.h
574579
FILE: ../../../flutter/runtime/runtime_controller.cc
@@ -581,8 +586,6 @@ FILE: ../../../flutter/runtime/skia_concurrent_executor.cc
581586
FILE: ../../../flutter/runtime/skia_concurrent_executor.h
582587
FILE: ../../../flutter/runtime/test_font_data.cc
583588
FILE: ../../../flutter/runtime/test_font_data.h
584-
FILE: ../../../flutter/runtime/window_data.cc
585-
FILE: ../../../flutter/runtime/window_data.h
586589
FILE: ../../../flutter/shell/common/animator.cc
587590
FILE: ../../../flutter/shell/common/animator.h
588591
FILE: ../../../flutter/shell/common/animator_unittests.cc

lib/ui/BUILD.gn

Lines changed: 3 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",
@@ -162,6 +164,7 @@ if (current_toolchain == host_toolchain) {
162164
sources = [
163165
"painting/image_decoder_unittests.cc",
164166
"painting/vertices_unittests.cc",
167+
"window/platform_configuration_unittests.cc",
165168
"window/pointer_data_packet_converter_unittests.cc",
166169
]
167170

lib/ui/compositing/scene.cc

Lines changed: 5 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,10 @@ 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+
auto viewport_metrics = UIDartState::Current()
46+
->platform_configuration()
47+
->get_window()
48+
.viewport_metrics();
4549

4650
layer_tree_ = std::make_unique<LayerTree>(
4751
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: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,25 @@ void _updateWindowMetrics(
2828
double systemGestureInsetBottom,
2929
double systemGestureInsetLeft,
3030
) {
31+
print('''
32+
Updated window metrics:
33+
devicePixelRatio: $devicePixelRatio
34+
width: $width
35+
height: $height
36+
depth: $depth
37+
viewPaddingTop: $viewPaddingTop
38+
viewPaddingRight: $viewPaddingRight
39+
viewPaddingBottom: $viewPaddingBottom
40+
viewPaddingLeft: $viewPaddingLeft
41+
viewInsetTop: $viewInsetTop
42+
viewInsetRight: $viewInsetRight
43+
viewInsetBottom: $viewInsetBottom
44+
viewInsetLeft: $viewInsetLeft
45+
systemGestureInsetTop: $systemGestureInsetTop
46+
systemGestureInsetRight: $systemGestureInsetRight
47+
systemGestureInsetBottom: $systemGestureInsetBottom
48+
systemGestureInsetLeft: $systemGestureInsetLeft
49+
''');
3150
window
3251
.._devicePixelRatio = devicePixelRatio
3352
.._physicalSize = Size(width, height)
@@ -238,7 +257,7 @@ void _runMainZoned(Function startMainIsolateFunction,
238257
}, null);
239258
}
240259

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

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

lib/ui/painting/canvas.cc

Lines changed: 8 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"
@@ -421,11 +422,15 @@ void Canvas::drawShadow(const CanvasPath* path,
421422
SkColor color,
422423
double elevation,
423424
bool transparentOccluder) {
424-
if (!path)
425+
if (!path) {
425426
Dart_ThrowException(
426427
ToDart("Canvas.drawShader called with non-genuine Path."));
427-
SkScalar dpr =
428-
UIDartState::Current()->window()->viewport_metrics().device_pixel_ratio;
428+
}
429+
SkScalar dpr = UIDartState::Current()
430+
->platform_configuration()
431+
->get_window()
432+
.viewport_metrics()
433+
.device_pixel_ratio;
429434
external_allocation_size_ += path->path().approximateBytesUsed();
430435
flutter::PhysicalShapeLayer::DrawShadow(canvas_, path->path(), color,
431436
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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +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/window.h"
8+
#include "flutter/lib/ui/window/platform_configuration.h"
99
#include "third_party/tonic/converter/dart_converter.h"
1010
#include "third_party/tonic/dart_message_handler.h"
1111

@@ -73,18 +73,23 @@ void UIDartState::ThrowIfUIOperationsProhibited() {
7373

7474
void UIDartState::SetDebugName(const std::string debug_name) {
7575
debug_name_ = debug_name;
76-
if (window_)
77-
window_->client()->UpdateIsolateDescription(debug_name_, main_port_);
76+
if (platform_configuration_) {
77+
platform_configuration_->client()->UpdateIsolateDescription(debug_name_,
78+
main_port_);
79+
}
7880
}
7981

8082
UIDartState* UIDartState::Current() {
8183
return static_cast<UIDartState*>(DartState::Current());
8284
}
8385

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_);
86+
void UIDartState::SetPlatformConfiguration(
87+
std::unique_ptr<PlatformConfiguration> platform_configuration) {
88+
platform_configuration_ = std::move(platform_configuration);
89+
if (platform_configuration_) {
90+
platform_configuration_->client()->UpdateIsolateDescription(debug_name_,
91+
main_port_);
92+
}
8893
}
8994

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

lib/ui/ui_dart_state.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
namespace flutter {
2929
class FontSelector;
30-
class Window;
30+
class PlatformConfiguration;
3131

3232
class UIDartState : public tonic::DartState {
3333
public:
@@ -44,7 +44,9 @@ class UIDartState : public tonic::DartState {
4444

4545
const std::string& logger_prefix() const { return logger_prefix_; }
4646

47-
Window* window() const { return window_.get(); }
47+
PlatformConfiguration* platform_configuration() const {
48+
return platform_configuration_.get();
49+
}
4850

4951
const TaskRunners& GetTaskRunners() const;
5052

@@ -97,7 +99,8 @@ class UIDartState : public tonic::DartState {
9799

98100
~UIDartState() override;
99101

100-
void SetWindow(std::unique_ptr<Window> window);
102+
void SetPlatformConfiguration(
103+
std::unique_ptr<PlatformConfiguration> platform_configuration);
101104

102105
const std::string& GetAdvisoryScriptURI() const;
103106

@@ -119,7 +122,7 @@ class UIDartState : public tonic::DartState {
119122
Dart_Port main_port_ = ILLEGAL_PORT;
120123
const bool is_root_isolate_;
121124
std::string debug_name_;
122-
std::unique_ptr<Window> window_;
125+
std::unique_ptr<PlatformConfiguration> platform_configuration_;
123126
tonic::DartMicrotaskQueue microtask_queue_;
124127
UnhandledExceptionCallback unhandled_exception_callback_;
125128
const std::shared_ptr<IsolateNameServer> isolate_name_server_;

lib/ui/window.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ class Window {
822822
}
823823
return null;
824824
}
825-
List<String> _computePlatformResolvedLocale(List<String?> supportedLocalesData) native 'Window_computePlatformResolvedLocale';
825+
List<String> _computePlatformResolvedLocale(List<String?> supportedLocalesData) native 'PlatformConfiguration_computePlatformResolvedLocale';
826826

827827
/// A callback that is invoked whenever [locale] changes value.
828828
///
@@ -1000,7 +1000,7 @@ class Window {
10001000
}
10011001

10021002
late _SetNeedsReportTimingsFunc _setNeedsReportTimings;
1003-
void _nativeSetNeedsReportTimings(bool value) native 'Window_setNeedsReportTimings';
1003+
void _nativeSetNeedsReportTimings(bool value) native 'PlatformConfiguration_setNeedsReportTimings';
10041004

10051005
/// A callback that is invoked when pointer data is available.
10061006
///
@@ -1050,7 +1050,7 @@ class Window {
10501050
/// * [SystemChannels.navigation], which handles subsequent navigation
10511051
/// requests from the embedder.
10521052
String get defaultRouteName => _defaultRouteName();
1053-
String _defaultRouteName() native 'Window_defaultRouteName';
1053+
String _defaultRouteName() native 'PlatformConfiguration_defaultRouteName';
10541054

10551055
/// Requests that, at the next appropriate opportunity, the [onBeginFrame]
10561056
/// and [onDrawFrame] callbacks be invoked.
@@ -1059,7 +1059,7 @@ class Window {
10591059
///
10601060
/// * [SchedulerBinding], the Flutter framework class which manages the
10611061
/// scheduling of frames.
1062-
void scheduleFrame() native 'Window_scheduleFrame';
1062+
void scheduleFrame() native 'PlatformConfiguration_scheduleFrame';
10631063

10641064
/// Updates the application's rendering on the GPU with the newly provided
10651065
/// [Scene]. This function must be called within the scope of the
@@ -1085,7 +1085,7 @@ class Window {
10851085
/// scheduling of frames.
10861086
/// * [RendererBinding], the Flutter framework class which manages layout and
10871087
/// painting.
1088-
void render(Scene scene) native 'Window_render';
1088+
void render(Scene scene) native 'PlatformConfiguration_render';
10891089

10901090
/// Whether the user has requested that [updateSemantics] be called when
10911091
/// the semantic contents of window changes.
@@ -1125,7 +1125,7 @@ class Window {
11251125

11261126
/// Additional accessibility features that may be enabled by the platform.
11271127
AccessibilityFeatures get accessibilityFeatures => _accessibilityFeatures;
1128-
// The zero value matches the default value in `window_data.h`.
1128+
// The zero value matches the default value in `platform_data.h`.
11291129
AccessibilityFeatures _accessibilityFeatures = const AccessibilityFeatures._(0);
11301130

11311131
/// A callback that is invoked when the value of [accessibilityFeatures] changes.
@@ -1147,7 +1147,7 @@ class Window {
11471147
///
11481148
/// In either case, this function disposes the given update, which means the
11491149
/// semantics update cannot be used further.
1150-
void updateSemantics(SemanticsUpdate update) native 'Window_updateSemantics';
1150+
void updateSemantics(SemanticsUpdate update) native 'PlatformConfiguration_updateSemantics';
11511151

11521152
/// Set the debug name associated with this window's root isolate.
11531153
///
@@ -1157,7 +1157,7 @@ class Window {
11571157
/// This can be combined with flutter tools `--isolate-filter` flag to debug
11581158
/// specific root isolates. For example: `flutter attach --isolate-filter=[name]`.
11591159
/// Note that this does not rename any child isolates of the root.
1160-
void setIsolateDebugName(String name) native 'Window_setIsolateDebugName';
1160+
void setIsolateDebugName(String name) native 'PlatformConfiguration_setIsolateDebugName';
11611161

11621162
/// Sends a message to a platform-specific plugin.
11631163
///
@@ -1178,7 +1178,7 @@ class Window {
11781178
}
11791179
String? _sendPlatformMessage(String name,
11801180
PlatformMessageResponseCallback? callback,
1181-
ByteData? data) native 'Window_sendPlatformMessage';
1181+
ByteData? data) native 'PlatformConfiguration_sendPlatformMessage';
11821182

11831183
/// Called whenever this window receives a message from a platform-specific
11841184
/// plugin.
@@ -1203,7 +1203,7 @@ class Window {
12031203

12041204
/// Called by [_dispatchPlatformMessage].
12051205
void _respondToPlatformMessage(int responseId, ByteData? data)
1206-
native 'Window_respondToPlatformMessage';
1206+
native 'PlatformConfiguration_respondToPlatformMessage';
12071207

12081208
/// Wraps the given [callback] in another callback that ensures that the
12091209
/// original callback is called in the zone it was registered in.
@@ -1229,7 +1229,7 @@ class Window {
12291229
///
12301230
/// For asynchronous communication between the embedder and isolate, a
12311231
/// platform channel may be used.
1232-
ByteData? getPersistentIsolateData() native 'Window_getPersistentIsolateData';
1232+
ByteData? getPersistentIsolateData() native 'PlatformConfiguration_getPersistentIsolateData';
12331233
}
12341234

12351235
/// Additional accessibility features that may be enabled by the platform.

0 commit comments

Comments
 (0)