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

Move platform specific information to PlatformConfiguration class #19652

Merged
Merged
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
7 changes: 5 additions & 2 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@ FILE: ../../../flutter/lib/ui/ui_benchmarks.cc
FILE: ../../../flutter/lib/ui/ui_dart_state.cc
FILE: ../../../flutter/lib/ui/ui_dart_state.h
FILE: ../../../flutter/lib/ui/window.dart
FILE: ../../../flutter/lib/ui/window/platform_configuration.cc
FILE: ../../../flutter/lib/ui/window/platform_configuration.h
FILE: ../../../flutter/lib/ui/window/platform_configuration_unittests.cc
FILE: ../../../flutter/lib/ui/window/platform_message.cc
FILE: ../../../flutter/lib/ui/window/platform_message.h
FILE: ../../../flutter/lib/ui/window/platform_message_response.cc
Expand Down Expand Up @@ -575,6 +578,8 @@ FILE: ../../../flutter/runtime/dart_vm_unittests.cc
FILE: ../../../flutter/runtime/embedder_resources.cc
FILE: ../../../flutter/runtime/embedder_resources.h
FILE: ../../../flutter/runtime/fixtures/runtime_test.dart
FILE: ../../../flutter/runtime/platform_data.cc
FILE: ../../../flutter/runtime/platform_data.h
FILE: ../../../flutter/runtime/ptrace_ios.cc
FILE: ../../../flutter/runtime/ptrace_ios.h
FILE: ../../../flutter/runtime/runtime_controller.cc
Expand All @@ -587,8 +592,6 @@ FILE: ../../../flutter/runtime/skia_concurrent_executor.cc
FILE: ../../../flutter/runtime/skia_concurrent_executor.h
FILE: ../../../flutter/runtime/test_font_data.cc
FILE: ../../../flutter/runtime/test_font_data.h
FILE: ../../../flutter/runtime/window_data.cc
FILE: ../../../flutter/runtime/window_data.h
FILE: ../../../flutter/shell/common/animator.cc
FILE: ../../../flutter/shell/common/animator.h
FILE: ../../../flutter/shell/common/animator_unittests.cc
Expand Down
3 changes: 3 additions & 0 deletions lib/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ source_set_maybe_fuchsia_legacy("ui") {
"text/text_box.h",
"ui_dart_state.cc",
"ui_dart_state.h",
"window/platform_configuration.cc",
"window/platform_configuration.h",
"window/platform_message.cc",
"window/platform_message.h",
"window/platform_message_response.cc",
Expand Down Expand Up @@ -180,6 +182,7 @@ if (enable_unittests) {
sources = [
"painting/image_encoding_unittests.cc",
"painting/vertices_unittests.cc",
"window/platform_configuration_unittests.cc",
"window/pointer_data_packet_converter_unittests.cc",
]

Expand Down
6 changes: 5 additions & 1 deletion lib/ui/compositing/scene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "flutter/lib/ui/painting/image.h"
#include "flutter/lib/ui/painting/picture.h"
#include "flutter/lib/ui/ui_dart_state.h"
#include "flutter/lib/ui/window/platform_configuration.h"
#include "flutter/lib/ui/window/window.h"
#include "third_party/skia/include/core/SkImageInfo.h"
#include "third_party/skia/include/core/SkSurface.h"
Expand Down Expand Up @@ -41,7 +42,10 @@ Scene::Scene(std::shared_ptr<flutter::Layer> rootLayer,
uint32_t rasterizerTracingThreshold,
bool checkerboardRasterCacheImages,
bool checkerboardOffscreenLayers) {
auto viewport_metrics = UIDartState::Current()->window()->viewport_metrics();
auto viewport_metrics = UIDartState::Current()
->platform_configuration()
->window()
->viewport_metrics();

layer_tree_ = std::make_unique<LayerTree>(
SkISize::Make(viewport_metrics.physical_width,
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/dart_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "flutter/lib/ui/text/font_collection.h"
#include "flutter/lib/ui/text/paragraph.h"
#include "flutter/lib/ui/text/paragraph_builder.h"
#include "flutter/lib/ui/window/window.h"
#include "flutter/lib/ui/window/platform_configuration.h"
#include "third_party/tonic/converter/dart_converter.h"
#include "third_party/tonic/logging/dart_error.h"

Expand Down Expand Up @@ -85,7 +85,7 @@ void DartUI::InitForGlobal() {
SemanticsUpdate::RegisterNatives(g_natives);
SemanticsUpdateBuilder::RegisterNatives(g_natives);
Vertices::RegisterNatives(g_natives);
Window::RegisterNatives(g_natives);
PlatformConfiguration::RegisterNatives(g_natives);
#if defined(LEGACY_FUCHSIA_EMBEDDER)
SceneHost::RegisterNatives(g_natives);
#endif
Expand Down
7 changes: 5 additions & 2 deletions lib/ui/fixtures/ui_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void createVertices() {
);
_validateVertices(vertices);
}

void _validateVertices(Vertices vertices) native 'ValidateVertices';

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

@pragma('vm:entry-point')
void messageCallback(dynamic data) {
}
void messageCallback(dynamic data) {}

@pragma('vm:entry-point')
void validateConfiguration() native 'ValidateConfiguration';


// Draw a circle on a Canvas that has a PictureRecorder. Take the image from
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/hooks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void _runMainZoned(Function startMainIsolateFunction,
}, null);
}

void _reportUnhandledException(String error, String stackTrace) native 'Window_reportUnhandledException';
void _reportUnhandledException(String error, String stackTrace) native 'PlatformConfiguration_reportUnhandledException';

/// Invokes [callback] inside the given [zone].
void _invoke(void callback()?, Zone zone) {
Expand Down
8 changes: 6 additions & 2 deletions lib/ui/painting/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "flutter/lib/ui/painting/image.h"
#include "flutter/lib/ui/painting/matrix.h"
#include "flutter/lib/ui/ui_dart_state.h"
#include "flutter/lib/ui/window/platform_configuration.h"
#include "flutter/lib/ui/window/window.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h"
Expand Down Expand Up @@ -474,8 +475,11 @@ void Canvas::drawShadow(const CanvasPath* path,
ToDart("Canvas.drawShader called with non-genuine Path."));
return;
}
SkScalar dpr =
UIDartState::Current()->window()->viewport_metrics().device_pixel_ratio;
SkScalar dpr = UIDartState::Current()
->platform_configuration()
->window()
->viewport_metrics()
.device_pixel_ratio;
external_allocation_size_ += path->path().approximateBytesUsed();
flutter::PhysicalShapeLayer::DrawShadow(canvas_, path->path(), color,
elevation, transparentOccluder, dpr);
Expand Down
8 changes: 5 additions & 3 deletions lib/ui/text/font_collection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "flutter/lib/ui/text/asset_manager_font_provider.h"
#include "flutter/lib/ui/ui_dart_state.h"
#include "flutter/lib/ui/window/window.h"
#include "flutter/lib/ui/window/platform_configuration.h"
#include "flutter/runtime/test_font_data.h"
#include "rapidjson/document.h"
#include "rapidjson/rapidjson.h"
Expand All @@ -30,8 +30,10 @@ namespace {
void LoadFontFromList(tonic::Uint8List& font_data, // NOLINT
Dart_Handle callback,
std::string family_name) {
FontCollection& font_collection =
UIDartState::Current()->window()->client()->GetFontCollection();
FontCollection& font_collection = UIDartState::Current()
->platform_configuration()
->client()
->GetFontCollection();
font_collection.LoadFontFromList(font_data.data(), font_data.num_elements(),
family_name);
font_data.Release();
Expand Down
8 changes: 5 additions & 3 deletions lib/ui/text/paragraph_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "flutter/fml/task_runner.h"
#include "flutter/lib/ui/text/font_collection.h"
#include "flutter/lib/ui/ui_dart_state.h"
#include "flutter/lib/ui/window/window.h"
#include "flutter/lib/ui/window/platform_configuration.h"
#include "flutter/third_party/txt/src/txt/font_style.h"
#include "flutter/third_party/txt/src/txt/font_weight.h"
#include "flutter/third_party/txt/src/txt/paragraph_style.h"
Expand Down Expand Up @@ -288,8 +288,10 @@ ParagraphBuilder::ParagraphBuilder(
style.locale = locale;
}

FontCollection& font_collection =
UIDartState::Current()->window()->client()->GetFontCollection();
FontCollection& font_collection = UIDartState::Current()
->platform_configuration()
->client()
->GetFontCollection();

#if FLUTTER_ENABLE_SKSHAPER
#define FLUTTER_PARAGRAPH_BUILDER txt::ParagraphBuilder::CreateSkiaBuilder
Expand Down
17 changes: 10 additions & 7 deletions lib/ui/ui_dart_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "flutter/lib/ui/ui_dart_state.h"

#include "flutter/fml/message_loop.h"
#include "flutter/lib/ui/window/window.h"
#include "flutter/lib/ui/window/platform_configuration.h"
#include "third_party/tonic/converter/dart_converter.h"
#include "third_party/tonic/dart_message_handler.h"

Expand Down Expand Up @@ -73,19 +73,22 @@ void UIDartState::ThrowIfUIOperationsProhibited() {

void UIDartState::SetDebugName(const std::string debug_name) {
debug_name_ = debug_name;
if (window_) {
window_->client()->UpdateIsolateDescription(debug_name_, main_port_);
if (platform_configuration_) {
platform_configuration_->client()->UpdateIsolateDescription(debug_name_,
main_port_);
}
}

UIDartState* UIDartState::Current() {
return static_cast<UIDartState*>(DartState::Current());
}

void UIDartState::SetWindow(std::unique_ptr<Window> window) {
window_ = std::move(window);
if (window_) {
window_->client()->UpdateIsolateDescription(debug_name_, main_port_);
void UIDartState::SetPlatformConfiguration(
std::unique_ptr<PlatformConfiguration> platform_configuration) {
platform_configuration_ = std::move(platform_configuration);
if (platform_configuration_) {
platform_configuration_->client()->UpdateIsolateDescription(debug_name_,
main_port_);
}
}

Expand Down
11 changes: 7 additions & 4 deletions lib/ui/ui_dart_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

namespace flutter {
class FontSelector;
class Window;
class PlatformConfiguration;

class UIDartState : public tonic::DartState {
public:
Expand All @@ -44,7 +44,9 @@ class UIDartState : public tonic::DartState {

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

Window* window() const { return window_.get(); }
PlatformConfiguration* platform_configuration() const {
return platform_configuration_.get();
}

const TaskRunners& GetTaskRunners() const;

Expand Down Expand Up @@ -97,7 +99,8 @@ class UIDartState : public tonic::DartState {

~UIDartState() override;

void SetWindow(std::unique_ptr<Window> window);
void SetPlatformConfiguration(
std::unique_ptr<PlatformConfiguration> platform_configuration);

const std::string& GetAdvisoryScriptURI() const;

Expand All @@ -119,7 +122,7 @@ class UIDartState : public tonic::DartState {
Dart_Port main_port_ = ILLEGAL_PORT;
const bool is_root_isolate_;
std::string debug_name_;
std::unique_ptr<Window> window_;
std::unique_ptr<PlatformConfiguration> platform_configuration_;
tonic::DartMicrotaskQueue microtask_queue_;
UnhandledExceptionCallback unhandled_exception_callback_;
const std::shared_ptr<IsolateNameServer> isolate_name_server_;
Expand Down
22 changes: 11 additions & 11 deletions lib/ui/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ class Window {
}
return null;
}
List<String> _computePlatformResolvedLocale(List<String?> supportedLocalesData) native 'Window_computePlatformResolvedLocale';
List<String> _computePlatformResolvedLocale(List<String?> supportedLocalesData) native 'PlatformConfiguration_computePlatformResolvedLocale';

/// A callback that is invoked whenever [locale] changes value.
///
Expand Down Expand Up @@ -1001,7 +1001,7 @@ class Window {
}

late _SetNeedsReportTimingsFunc _setNeedsReportTimings;
void _nativeSetNeedsReportTimings(bool value) native 'Window_setNeedsReportTimings';
void _nativeSetNeedsReportTimings(bool value) native 'PlatformConfiguration_setNeedsReportTimings';

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

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

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

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

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

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

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

/// Sends a message to a platform-specific plugin.
///
Expand All @@ -1179,7 +1179,7 @@ class Window {
}
String? _sendPlatformMessage(String name,
PlatformMessageResponseCallback? callback,
ByteData? data) native 'Window_sendPlatformMessage';
ByteData? data) native 'PlatformConfiguration_sendPlatformMessage';

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

/// Called by [_dispatchPlatformMessage].
void _respondToPlatformMessage(int responseId, ByteData? data)
native 'Window_respondToPlatformMessage';
native 'PlatformConfiguration_respondToPlatformMessage';

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

/// Additional accessibility features that may be enabled by the platform.
Expand Down
Loading