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

Commit 98cfd1d

Browse files
authored
Move platform specific information to PlatformConfiguration class (#19652)
1 parent 13e993e commit 98cfd1d

Some content is hidden

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

43 files changed

+1318
-695
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,9 @@ FILE: ../../../flutter/lib/ui/ui_benchmarks.cc
399399
FILE: ../../../flutter/lib/ui/ui_dart_state.cc
400400
FILE: ../../../flutter/lib/ui/ui_dart_state.h
401401
FILE: ../../../flutter/lib/ui/window.dart
402+
FILE: ../../../flutter/lib/ui/window/platform_configuration.cc
403+
FILE: ../../../flutter/lib/ui/window/platform_configuration.h
404+
FILE: ../../../flutter/lib/ui/window/platform_configuration_unittests.cc
402405
FILE: ../../../flutter/lib/ui/window/platform_message.cc
403406
FILE: ../../../flutter/lib/ui/window/platform_message.h
404407
FILE: ../../../flutter/lib/ui/window/platform_message_response.cc
@@ -575,6 +578,8 @@ FILE: ../../../flutter/runtime/dart_vm_unittests.cc
575578
FILE: ../../../flutter/runtime/embedder_resources.cc
576579
FILE: ../../../flutter/runtime/embedder_resources.h
577580
FILE: ../../../flutter/runtime/fixtures/runtime_test.dart
581+
FILE: ../../../flutter/runtime/platform_data.cc
582+
FILE: ../../../flutter/runtime/platform_data.h
578583
FILE: ../../../flutter/runtime/ptrace_ios.cc
579584
FILE: ../../../flutter/runtime/ptrace_ios.h
580585
FILE: ../../../flutter/runtime/runtime_controller.cc
@@ -587,8 +592,6 @@ FILE: ../../../flutter/runtime/skia_concurrent_executor.cc
587592
FILE: ../../../flutter/runtime/skia_concurrent_executor.h
588593
FILE: ../../../flutter/runtime/test_font_data.cc
589594
FILE: ../../../flutter/runtime/test_font_data.h
590-
FILE: ../../../flutter/runtime/window_data.cc
591-
FILE: ../../../flutter/runtime/window_data.h
592595
FILE: ../../../flutter/shell/common/animator.cc
593596
FILE: ../../../flutter/shell/common/animator.h
594597
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
@@ -93,6 +93,8 @@ source_set_maybe_fuchsia_legacy("ui") {
9393
"text/text_box.h",
9494
"ui_dart_state.cc",
9595
"ui_dart_state.h",
96+
"window/platform_configuration.cc",
97+
"window/platform_configuration.h",
9698
"window/platform_message.cc",
9799
"window/platform_message.h",
98100
"window/platform_message_response.cc",
@@ -180,6 +182,7 @@ if (enable_unittests) {
180182
sources = [
181183
"painting/image_encoding_unittests.cc",
182184
"painting/vertices_unittests.cc",
185+
"window/platform_configuration_unittests.cc",
183186
"window/pointer_data_packet_converter_unittests.cc",
184187
]
185188

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+
->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
@@ -30,7 +30,7 @@
3030
#include "flutter/lib/ui/text/font_collection.h"
3131
#include "flutter/lib/ui/text/paragraph.h"
3232
#include "flutter/lib/ui/text/paragraph_builder.h"
33-
#include "flutter/lib/ui/window/window.h"
33+
#include "flutter/lib/ui/window/platform_configuration.h"
3434
#include "third_party/tonic/converter/dart_converter.h"
3535
#include "third_party/tonic/logging/dart_error.h"
3636

@@ -85,7 +85,7 @@ void DartUI::InitForGlobal() {
8585
SemanticsUpdate::RegisterNatives(g_natives);
8686
SemanticsUpdateBuilder::RegisterNatives(g_natives);
8787
Vertices::RegisterNatives(g_natives);
88-
Window::RegisterNatives(g_natives);
88+
PlatformConfiguration::RegisterNatives(g_natives);
8989
#if defined(LEGACY_FUCHSIA_EMBEDDER)
9090
SceneHost::RegisterNatives(g_natives);
9191
#endif

lib/ui/fixtures/ui_test.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ void createVertices() {
3434
);
3535
_validateVertices(vertices);
3636
}
37+
3738
void _validateVertices(Vertices vertices) native 'ValidateVertices';
3839

3940
@pragma('vm:entry-point')
@@ -42,8 +43,10 @@ void frameCallback(FrameInfo info) {
4243
}
4344

4445
@pragma('vm:entry-point')
45-
void messageCallback(dynamic data) {
46-
}
46+
void messageCallback(dynamic data) {}
47+
48+
@pragma('vm:entry-point')
49+
void validateConfiguration() native 'ValidateConfiguration';
4750

4851

4952
// Draw a circle on a Canvas that has a PictureRecorder. Take the image from

lib/ui/hooks.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ void _runMainZoned(Function startMainIsolateFunction,
238238
}, null);
239239
}
240240

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

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

lib/ui/painting/canvas.cc

Lines changed: 6 additions & 2 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"
@@ -474,8 +475,11 @@ void Canvas::drawShadow(const CanvasPath* path,
474475
ToDart("Canvas.drawShader called with non-genuine Path."));
475476
return;
476477
}
477-
SkScalar dpr =
478-
UIDartState::Current()->window()->viewport_metrics().device_pixel_ratio;
478+
SkScalar dpr = UIDartState::Current()
479+
->platform_configuration()
480+
->window()
481+
->viewport_metrics()
482+
.device_pixel_ratio;
479483
external_allocation_size_ += path->path().approximateBytesUsed();
480484
flutter::PhysicalShapeLayer::DrawShadow(canvas_, path->path(), color,
481485
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, // NOLINT
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: 10 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,19 +73,22 @@ 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_);
7879
}
7980
}
8081

8182
UIDartState* UIDartState::Current() {
8283
return static_cast<UIDartState*>(DartState::Current());
8384
}
8485

85-
void UIDartState::SetWindow(std::unique_ptr<Window> window) {
86-
window_ = std::move(window);
87-
if (window_) {
88-
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_);
8992
}
9093
}
9194

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
@@ -823,7 +823,7 @@ class Window {
823823
}
824824
return null;
825825
}
826-
List<String> _computePlatformResolvedLocale(List<String?> supportedLocalesData) native 'Window_computePlatformResolvedLocale';
826+
List<String> _computePlatformResolvedLocale(List<String?> supportedLocalesData) native 'PlatformConfiguration_computePlatformResolvedLocale';
827827

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

10031003
late _SetNeedsReportTimingsFunc _setNeedsReportTimings;
1004-
void _nativeSetNeedsReportTimings(bool value) native 'Window_setNeedsReportTimings';
1004+
void _nativeSetNeedsReportTimings(bool value) native 'PlatformConfiguration_setNeedsReportTimings';
10051005

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

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

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

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

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

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

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

11631163
/// Sends a message to a platform-specific plugin.
11641164
///
@@ -1179,7 +1179,7 @@ class Window {
11791179
}
11801180
String? _sendPlatformMessage(String name,
11811181
PlatformMessageResponseCallback? callback,
1182-
ByteData? data) native 'Window_sendPlatformMessage';
1182+
ByteData? data) native 'PlatformConfiguration_sendPlatformMessage';
11831183

11841184
/// Called whenever this window receives a message from a platform-specific
11851185
/// plugin.
@@ -1204,7 +1204,7 @@ class Window {
12041204

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

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

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

0 commit comments

Comments
 (0)