diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 0c1905ccd6cd7..932311cb00bd3 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -536,6 +536,8 @@ FILE: ../../../flutter/runtime/start_up.cc FILE: ../../../flutter/runtime/start_up.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 diff --git a/runtime/BUILD.gn b/runtime/BUILD.gn index c970e05b30a29..c9125cb2b78b2 100644 --- a/runtime/BUILD.gn +++ b/runtime/BUILD.gn @@ -68,6 +68,8 @@ source_set("runtime") { "skia_concurrent_executor.h", "start_up.cc", "start_up.h", + "window_data.cc", + "window_data.h", ] deps = [ diff --git a/runtime/runtime_controller.cc b/runtime/runtime_controller.cc index 59380508a6e6b..f7695d3d00a3b 100644 --- a/runtime/runtime_controller.cc +++ b/runtime/runtime_controller.cc @@ -14,37 +14,6 @@ namespace flutter { -RuntimeController::RuntimeController( - RuntimeDelegate& p_client, - DartVM* p_vm, - fml::RefPtr p_isolate_snapshot, - TaskRunners p_task_runners, - fml::WeakPtr p_snapshot_delegate, - fml::WeakPtr p_io_manager, - fml::RefPtr p_unref_queue, - fml::WeakPtr p_image_decoder, - std::string p_advisory_script_uri, - std::string p_advisory_script_entrypoint, - const std::function& p_idle_notification_callback, - const fml::closure& p_isolate_create_callback, - const fml::closure& p_isolate_shutdown_callback, - std::shared_ptr p_persistent_isolate_data) - : RuntimeController(p_client, - p_vm, - std::move(p_isolate_snapshot), - std::move(p_task_runners), - std::move(p_snapshot_delegate), - std::move(p_io_manager), - std::move(p_unref_queue), - std::move(p_image_decoder), - std::move(p_advisory_script_uri), - std::move(p_advisory_script_entrypoint), - p_idle_notification_callback, - WindowData{/* default window data */}, - p_isolate_create_callback, - p_isolate_shutdown_callback, - std::move(p_persistent_isolate_data)) {} - RuntimeController::RuntimeController( RuntimeDelegate& p_client, DartVM* p_vm, @@ -57,7 +26,7 @@ RuntimeController::RuntimeController( std::string p_advisory_script_uri, std::string p_advisory_script_entrypoint, const std::function& idle_notification_callback, - WindowData p_window_data, + const WindowData& p_window_data, const fml::closure& p_isolate_create_callback, const fml::closure& p_isolate_shutdown_callback, std::shared_ptr p_persistent_isolate_data) @@ -400,10 +369,4 @@ RuntimeController::Locale::Locale(std::string language_code_, RuntimeController::Locale::~Locale() = default; -RuntimeController::WindowData::WindowData() = default; - -RuntimeController::WindowData::WindowData(const WindowData& other) = default; - -RuntimeController::WindowData::~WindowData() = default; - } // namespace flutter diff --git a/runtime/runtime_controller.h b/runtime/runtime_controller.h index 584f490ad9d36..cea325bad7444 100644 --- a/runtime/runtime_controller.h +++ b/runtime/runtime_controller.h @@ -17,6 +17,7 @@ #include "flutter/lib/ui/window/pointer_data_packet.h" #include "flutter/lib/ui/window/window.h" #include "flutter/runtime/dart_vm.h" +#include "flutter/runtime/window_data.h" #include "rapidjson/document.h" #include "rapidjson/stringbuffer.h" @@ -40,6 +41,7 @@ class RuntimeController final : public WindowClient { std::string advisory_script_uri, std::string advisory_script_entrypoint, const std::function& idle_notification_callback, + const WindowData& data, const fml::closure& isolate_create_callback, const fml::closure& isolate_shutdown_callback, std::shared_ptr persistent_isolate_data); @@ -103,29 +105,6 @@ class RuntimeController final : public WindowClient { std::string variant_code; }; - // Stores data about the window to be used at startup - // as well as on hot restarts. Data kept here will persist - // after hot restart. - struct WindowData { - WindowData(); - - WindowData(const WindowData& other); - - ~WindowData(); - - ViewportMetrics viewport_metrics; - std::string language_code; - std::string country_code; - std::string script_code; - std::string variant_code; - std::vector locale_data; - std::string user_settings_data = "{}"; - std::string lifecycle_state = "AppLifecycleState.detached"; - bool semantics_enabled = false; - bool assistive_technology_enabled = false; - int32_t accessibility_feature_flags_ = 0; - }; - RuntimeDelegate& client_; DartVM* const vm_; fml::RefPtr isolate_snapshot_; @@ -144,23 +123,6 @@ class RuntimeController final : public WindowClient { const fml::closure isolate_shutdown_callback_; std::shared_ptr persistent_isolate_data_; - RuntimeController( - RuntimeDelegate& client, - DartVM* vm, - fml::RefPtr isolate_snapshot, - TaskRunners task_runners, - fml::WeakPtr snapshot_delegate, - fml::WeakPtr io_manager, - fml::RefPtr unref_queue, - fml::WeakPtr image_decoder, - std::string advisory_script_uri, - std::string advisory_script_entrypoint, - const std::function& idle_notification_callback, - WindowData data, - const fml::closure& isolate_create_callback, - const fml::closure& isolate_shutdown_callback, - std::shared_ptr persistent_isolate_data); - Window* GetWindowIfAvailable(); bool FlushRuntimeStateToIsolate(); diff --git a/runtime/window_data.cc b/runtime/window_data.cc new file mode 100644 index 0000000000000..a92839d5e8a5d --- /dev/null +++ b/runtime/window_data.cc @@ -0,0 +1,12 @@ +// 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. + +#include "flutter/runtime/window_data.h" + +namespace flutter { +WindowData::WindowData() = default; + +WindowData::~WindowData() = default; + +} // namespace flutter diff --git a/runtime/window_data.h b/runtime/window_data.h new file mode 100644 index 0000000000000..e234d2f558162 --- /dev/null +++ b/runtime/window_data.h @@ -0,0 +1,48 @@ +// 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_RUNTIME_WINDOW_DATA_H_ +#define FLUTTER_RUNTIME_WINDOW_DATA_H_ + +#include "flutter/lib/ui/window/viewport_metrics.h" + +#include +#include +#include + +namespace flutter { + +//------------------------------------------------------------------------------ +/// The struct of platform-specific data used for initializing ui.Window. +/// +/// framework may request data from ui.Window before platform is properly +/// configured. Engine this struct to set the desired default value for +/// ui.Window when creating Shell before platform is ready to send the real +/// data. +/// +/// See also: +/// +/// * flutter::Shell::Create, which takes a window_data to initialize the +/// ui.Window attached to it. +struct WindowData { + WindowData(); + + ~WindowData(); + + ViewportMetrics viewport_metrics; + std::string language_code; + std::string country_code; + std::string script_code; + std::string variant_code; + std::vector locale_data; + std::string user_settings_data = "{}"; + std::string lifecycle_state; + bool semantics_enabled = false; + bool assistive_technology_enabled = false; + int32_t accessibility_feature_flags_ = 0; +}; + +} // namespace flutter + +#endif // FLUTTER_RUNTIME_WINDOW_DATA_H_ diff --git a/shell/common/engine.cc b/shell/common/engine.cc index 543ed34767c5c..c998d49042b30 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -40,6 +40,7 @@ Engine::Engine(Delegate& delegate, DartVM& vm, fml::RefPtr isolate_snapshot, TaskRunners task_runners, + const WindowData window_data, Settings settings, std::unique_ptr animator, fml::WeakPtr io_manager, @@ -70,6 +71,7 @@ Engine::Engine(Delegate& delegate, settings_.advisory_script_uri, // advisory script uri settings_.advisory_script_entrypoint, // advisory script entrypoint settings_.idle_notification_callback, // idle notification callback + window_data, // window data settings_.isolate_create_callback, // isolate create callback settings_.isolate_shutdown_callback, // isolate shutdown callback settings_.persistent_isolate_data // persistent isolate data diff --git a/shell/common/engine.h b/shell/common/engine.h index 7c85d33c584b3..896334a1aa08e 100644 --- a/shell/common/engine.h +++ b/shell/common/engine.h @@ -276,6 +276,7 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate { DartVM& vm, fml::RefPtr isolate_snapshot, TaskRunners task_runners, + const WindowData window_data, Settings settings, std::unique_ptr animator, fml::WeakPtr io_manager, diff --git a/shell/common/shell.cc b/shell/common/shell.cc index fc7833fcbfb70..3a3f9cfa901ef 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -42,6 +42,7 @@ constexpr char kFontChange[] = "fontsChange"; std::unique_ptr Shell::CreateShellOnPlatformThread( DartVMRef vm, TaskRunners task_runners, + const WindowData window_data, Settings settings, fml::RefPtr isolate_snapshot, const Shell::CreateCallback& on_create_platform_view, @@ -132,6 +133,7 @@ std::unique_ptr Shell::CreateShellOnPlatformThread( fml::MakeCopyable([&engine_promise, // shell = shell.get(), // &dispatcher_maker, // + &window_data, // isolate_snapshot = std::move(isolate_snapshot), // vsync_waiter = std::move(vsync_waiter), // &weak_io_manager_future, // @@ -152,6 +154,7 @@ std::unique_ptr Shell::CreateShellOnPlatformThread( *shell->GetDartVM(), // std::move(isolate_snapshot), // task_runners, // + window_data, // shell->GetSettings(), // std::move(animator), // weak_io_manager_future.get(), // @@ -225,6 +228,20 @@ std::unique_ptr Shell::Create( Settings settings, const Shell::CreateCallback& on_create_platform_view, const Shell::CreateCallback& on_create_rasterizer) { + return Shell::Create(std::move(task_runners), // + WindowData{/* default window data */}, // + std::move(settings), // + std::move(on_create_platform_view), // + std::move(on_create_rasterizer) // + ); +} + +std::unique_ptr Shell::Create( + TaskRunners task_runners, + const WindowData window_data, + Settings settings, + Shell::CreateCallback on_create_platform_view, + Shell::CreateCallback on_create_rasterizer) { PerformInitializationTasks(settings); PersistentCache::SetCacheSkSL(settings.cache_sksl); @@ -236,6 +253,7 @@ std::unique_ptr Shell::Create( auto vm_data = vm->GetVMData(); return Shell::Create(std::move(task_runners), // + std::move(window_data), // std::move(settings), // vm_data->GetIsolateSnapshot(), // isolate snapshot on_create_platform_view, // @@ -246,6 +264,7 @@ std::unique_ptr Shell::Create( std::unique_ptr Shell::Create( TaskRunners task_runners, + const WindowData window_data, Settings settings, fml::RefPtr isolate_snapshot, const Shell::CreateCallback& on_create_platform_view, @@ -269,6 +288,7 @@ std::unique_ptr Shell::Create( vm = std::move(vm), // &shell, // task_runners = std::move(task_runners), // + window_data, // settings, // isolate_snapshot = std::move(isolate_snapshot), // on_create_platform_view, // @@ -276,6 +296,7 @@ std::unique_ptr Shell::Create( ]() mutable { shell = CreateShellOnPlatformThread(std::move(vm), std::move(task_runners), // + window_data, // settings, // std::move(isolate_snapshot), // on_create_platform_view, // diff --git a/shell/common/shell.h b/shell/common/shell.h index d306006c92b52..39ffd6055435c 100644 --- a/shell/common/shell.h +++ b/shell/common/shell.h @@ -126,6 +126,44 @@ class Shell final : public PlatformView::Delegate, const CreateCallback& on_create_platform_view, const CreateCallback& on_create_rasterizer); + //---------------------------------------------------------------------------- + /// @brief Creates a shell instance using the provided settings. The + /// callbacks to create the various shell subcomponents will be + /// called on the appropriate threads before this method returns. + /// Unlike the simpler variant of this factory method, this method + /// allows for specification of window data. If this is the first + /// instance of a shell in the process, this call also bootstraps + /// the Dart VM. + /// + /// @param[in] task_runners The task runners + /// @param[in] window_data The default data for setting up + /// ui.Window that attached to this + /// intance. + /// @param[in] settings The settings + /// @param[in] on_create_platform_view The callback that must return a + /// platform view. This will be called on + /// the platform task runner before this + /// method returns. + /// @param[in] on_create_rasterizer That callback that must provide a + /// valid rasterizer. This will be called + /// on the render task runner before this + /// method returns. + /// + /// @return A full initialized shell if the settings and callbacks are + /// valid. The root isolate has been created but not yet launched. + /// It may be launched by obtaining the engine weak pointer and + /// posting a task onto the UI task runner with a valid run + /// configuration to run the isolate. The embedder must always + /// check the validity of the shell (using the IsSetup call) + /// immediately after getting a pointer to it. + /// + static std::unique_ptr Create( + TaskRunners task_runners, + const WindowData window_data, + Settings settings, + CreateCallback on_create_platform_view, + CreateCallback on_create_rasterizer); + //---------------------------------------------------------------------------- /// @brief Creates a shell instance using the provided settings. The /// callbacks to create the various shell subcomponents will be @@ -136,6 +174,9 @@ class Shell final : public PlatformView::Delegate, /// requires the specification of a running VM instance. /// /// @param[in] task_runners The task runners + /// @param[in] window_data The default data for setting up + /// ui.Window that attached to this + /// intance. /// @param[in] settings The settings /// @param[in] isolate_snapshot A custom isolate snapshot. Takes /// precedence over any snapshots @@ -160,6 +201,7 @@ class Shell final : public PlatformView::Delegate, /// static std::unique_ptr Create( TaskRunners task_runners, + const WindowData window_data, Settings settings, fml::RefPtr isolate_snapshot, const CreateCallback& on_create_platform_view, @@ -371,6 +413,7 @@ class Shell final : public PlatformView::Delegate, static std::unique_ptr CreateShellOnPlatformThread( DartVMRef vm, TaskRunners task_runners, + const WindowData window_data, Settings settings, fml::RefPtr isolate_snapshot, const Shell::CreateCallback& on_create_platform_view, diff --git a/shell/platform/android/android_shell_holder.cc b/shell/platform/android/android_shell_holder.cc index 452e069bd5276..cb54c2b736c48 100644 --- a/shell/platform/android/android_shell_holder.cc +++ b/shell/platform/android/android_shell_holder.cc @@ -21,6 +21,12 @@ namespace flutter { +static WindowData GetDefaultWindowData() { + WindowData window_data; + window_data.lifecycle_state = "AppLifecycleState.detached"; + return window_data; +} + AndroidShellHolder::AndroidShellHolder( flutter::Settings settings, fml::jni::JavaObjectWeakGlobalRef java_object, @@ -103,6 +109,7 @@ AndroidShellHolder::AndroidShellHolder( shell_ = Shell::Create(task_runners, // task runners + GetDefaultWindowData(), // window data settings_, // settings on_create_platform_view, // platform view create callback on_create_rasterizer // rasterizer create callback diff --git a/shell/platform/android/android_shell_holder.h b/shell/platform/android/android_shell_holder.h index 83d92b77886b3..9be7f35df0bb8 100644 --- a/shell/platform/android/android_shell_holder.h +++ b/shell/platform/android/android_shell_holder.h @@ -11,6 +11,7 @@ #include "flutter/fml/platform/android/jni_weak_ref.h" #include "flutter/fml/unique_fd.h" #include "flutter/lib/ui/window/viewport_metrics.h" +#include "flutter/runtime/window_data.h" #include "flutter/shell/common/run_configuration.h" #include "flutter/shell/common/shell.h" #include "flutter/shell/common/thread_host.h" diff --git a/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm b/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm index 84fb859cbc424..0e70b025a76bd 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm @@ -168,6 +168,14 @@ - (instancetype)initWithPrecompiledDartBundle:(nullable NSBundle*)bundle { return self; } +#pragma mark - WindowData accessors + +- (const flutter::WindowData)defaultWindowData { + flutter::WindowData windowData; + windowData.lifecycle_state = std::string("AppLifecycleState.detached"); + return windowData; +} + #pragma mark - Settings accessors - (const flutter::Settings&)settings { @@ -253,4 +261,6 @@ - (void)setPersistentIsolateData:(NSData*)data { ); } +#pragma mark - windowData utilities + @end diff --git a/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h index a93af57eaaa0d..b21a38a9be6fd 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h @@ -6,6 +6,7 @@ #define SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTERDARTPROJECT_INTERNAL_H_ #include "flutter/common/settings.h" +#include "flutter/runtime/window_data.h" #include "flutter/shell/common/engine.h" #include "flutter/shell/platform/darwin/ios/framework/Headers/FlutterDartProject.h" @@ -14,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN @interface FlutterDartProject () - (const flutter::Settings&)settings; +- (const flutter::WindowData)defaultWindowData; - (flutter::RunConfiguration)runConfiguration; - (flutter::RunConfiguration)runConfigurationForEntrypoint:(nullable NSString*)entrypointOrNil; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 4e9ea96d03de4..204dba1c6b2db 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -388,6 +388,7 @@ - (BOOL)createShell:(NSString*)entrypoint libraryURI:(NSString*)libraryURI { static size_t shellCount = 1; auto settings = [_dartProject.get() settings]; + auto windowData = [_dartProject.get() defaultWindowData]; if (libraryURI) { FML_DCHECK(entrypoint) << "Must specify entrypoint if specifying library"; @@ -441,6 +442,7 @@ - (BOOL)createShell:(NSString*)entrypoint libraryURI:(NSString*)libraryURI { ); // Create the shell. This is a blocking operation. _shell = flutter::Shell::Create(std::move(task_runners), // task runners + std::move(windowData), // window data std::move(settings), // settings on_create_platform_view, // platform view creation on_create_rasterizer // rasterzier creation @@ -454,6 +456,7 @@ - (BOOL)createShell:(NSString*)entrypoint libraryURI:(NSString*)libraryURI { ); // Create the shell. This is a blocking operation. _shell = flutter::Shell::Create(std::move(task_runners), // task runners + std::move(windowData), // window data std::move(settings), // settings on_create_platform_view, // platform view creation on_create_rasterizer // rasterzier creation diff --git a/shell/platform/fuchsia/flutter/engine.cc b/shell/platform/fuchsia/flutter/engine.cc index a894f005807d6..484d5b8145cd3 100644 --- a/shell/platform/fuchsia/flutter/engine.cc +++ b/shell/platform/fuchsia/flutter/engine.cc @@ -235,6 +235,7 @@ Engine::Engine(Delegate& delegate, TRACE_EVENT0("flutter", "CreateShell"); shell_ = flutter::Shell::Create( task_runners, // host task runners + flutter::WindowData(), // default window data settings_, // shell launch settings std::move(isolate_snapshot), // isolate snapshot on_create_platform_view, // platform view create callback