From 7daabf4b53421127881427b1f44afdfa4ed19d7f Mon Sep 17 00:00:00 2001 From: Chun-Heng Tai Date: Fri, 22 Nov 2019 17:06:15 -0800 Subject: [PATCH 01/10] Add shell api to set default for windows data --- runtime/runtime_controller.cc | 37 +---------- runtime/runtime_controller.h | 61 +++++++------------ shell/common/engine.cc | 2 + shell/common/engine.h | 1 + shell/common/shell.cc | 21 +++++++ shell/common/shell.h | 41 +++++++++++++ .../platform/android/android_shell_holder.cc | 8 +++ shell/platform/android/android_shell_holder.h | 3 + .../framework/Source/FlutterDartProject.mm | 14 +++++ .../Source/FlutterDartProject_Internal.h | 2 + .../ios/framework/Source/FlutterEngine.mm | 3 + 11 files changed, 119 insertions(+), 74 deletions(-) diff --git a/runtime/runtime_controller.cc b/runtime/runtime_controller.cc index 59380508a6e6b..f231f71eccc75 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, @@ -400,10 +369,10 @@ RuntimeController::Locale::Locale(std::string language_code_, RuntimeController::Locale::~Locale() = default; -RuntimeController::WindowData::WindowData() = default; +WindowData::WindowData() = default; -RuntimeController::WindowData::WindowData(const WindowData& other) = default; +WindowData::WindowData(const WindowData& other) = default; -RuntimeController::WindowData::~WindowData() = default; +WindowData::~WindowData() = default; } // namespace flutter diff --git a/runtime/runtime_controller.h b/runtime/runtime_controller.h index 584f490ad9d36..6d3029cd299ab 100644 --- a/runtime/runtime_controller.h +++ b/runtime/runtime_controller.h @@ -26,6 +26,26 @@ class RuntimeDelegate; class View; class Window; +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; + bool semantics_enabled = false; + bool assistive_technology_enabled = false; + int32_t accessibility_feature_flags_ = 0; +}; + class RuntimeController final : public WindowClient { public: RuntimeController( @@ -40,6 +60,7 @@ class RuntimeController final : public WindowClient { 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); @@ -103,29 +124,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 +142,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/shell/common/engine.cc b/shell/common/engine.cc index 543ed34767c5c..efde31adf8fca 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, + 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, 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..8a170f625361e 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, + 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..446646f3a33e7 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, + 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, + 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, + 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..dc8e3a820a97d 100644 --- a/shell/common/shell.h +++ b/shell/common/shell.h @@ -126,6 +126,43 @@ 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 + /// window. + /// @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, + 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 +173,8 @@ 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 + /// window. /// @param[in] settings The settings /// @param[in] isolate_snapshot A custom isolate snapshot. Takes /// precedence over any snapshots @@ -160,6 +199,7 @@ class Shell final : public PlatformView::Delegate, /// static std::unique_ptr Create( TaskRunners task_runners, + WindowData window_data, Settings settings, fml::RefPtr isolate_snapshot, const CreateCallback& on_create_platform_view, @@ -371,6 +411,7 @@ class Shell final : public PlatformView::Delegate, static std::unique_ptr CreateShellOnPlatformThread( DartVMRef vm, TaskRunners task_runners, + WindowData windowd_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..09cdb9dd20f30 100644 --- a/shell/platform/android/android_shell_holder.cc +++ b/shell/platform/android/android_shell_holder.cc @@ -101,8 +101,12 @@ AndroidShellHolder::AndroidShellHolder( io_runner // io ); + flutter::WindowData window_data; + InitializesWindowData(window_data); + shell_ = Shell::Create(task_runners, // task runners + window_data, // window data settings_, // settings on_create_platform_view, // platform view create callback on_create_rasterizer // rasterizer create callback @@ -140,6 +144,10 @@ AndroidShellHolder::~AndroidShellHolder() { FML_CHECK(pthread_key_delete(thread_destruct_key_) == 0); } +void AndroidShellHolder::InitializesWindowData(WindowData& window_data) { + window_data.lifecycle_state = "AppLifecycleState.detached"; +} + void AndroidShellHolder::ThreadDestructCallback(void* value) { fml::jni::DetachFromVM(); } diff --git a/shell/platform/android/android_shell_holder.h b/shell/platform/android/android_shell_holder.h index 83d92b77886b3..54e365a03b986 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/runtime_controller.h" #include "flutter/shell/common/run_configuration.h" #include "flutter/shell/common/shell.h" #include "flutter/shell/common/thread_host.h" @@ -49,6 +50,8 @@ class AndroidShellHolder { pthread_key_t thread_destruct_key_; uint64_t next_pointer_flow_id_ = 0; + void InitializesWindowData(WindowData& window_data); + static void ThreadDestructCallback(void* value); FML_DISALLOW_COPY_AND_ASSIGN(AndroidShellHolder); diff --git a/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm b/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm index 84fb859cbc424..8fdb1b60dc612 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm @@ -148,6 +148,7 @@ @implementation FlutterDartProject { flutter::Settings _settings; + flutter::WindowData _windowData; } #pragma mark - Override base class designated initializers @@ -163,11 +164,18 @@ - (instancetype)initWithPrecompiledDartBundle:(nullable NSBundle*)bundle { if (self) { _settings = DefaultSettingsForProcess(bundle); + [self initializesWindowData]; } return self; } +#pragma mark - WindowData accessors + +- (const flutter::WindowData&)windowData { + return _windowData; +} + #pragma mark - Settings accessors - (const flutter::Settings&)settings { @@ -253,4 +261,10 @@ - (void)setPersistentIsolateData:(NSData*)data { ); } +#pragma mark - windowData utilities + +- (void)initializesWindowData { + _windowData.lifecycle_state = std::string([@"AppLifecycleState.detached" UTF8String]); +} + @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..0d9c474b32437 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/runtime_controller.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&)windowData; - (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..2b58b8ed6e3f1 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() windowData]; 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 From 552403c6e447758a765ac1bdccef147b55409d0d Mon Sep 17 00:00:00 2001 From: Chun-Heng Tai Date: Mon, 25 Nov 2019 15:41:05 -0800 Subject: [PATCH 02/10] update --- shell/common/engine.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/common/engine.cc b/shell/common/engine.cc index efde31adf8fca..d65af575c8e78 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -71,7 +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, // window data settings_.isolate_create_callback, // isolate create callback settings_.isolate_shutdown_callback, // isolate shutdown callback settings_.persistent_isolate_data // persistent isolate data From fb5d3e66171608a44a7d29e589ecb051e9b35c3b Mon Sep 17 00:00:00 2001 From: Chun-Heng Tai Date: Mon, 25 Nov 2019 16:19:20 -0800 Subject: [PATCH 03/10] fix build --- shell/common/shell.cc | 10 +++++----- shell/platform/fuchsia/flutter/engine.cc | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/shell/common/shell.cc b/shell/common/shell.cc index 446646f3a33e7..f236586670af7 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -228,11 +228,11 @@ 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) // + 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) // ); } diff --git a/shell/platform/fuchsia/flutter/engine.cc b/shell/platform/fuchsia/flutter/engine.cc index a894f005807d6..a7c81f8345ec6 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 + WindowData{}, // default window data settings_, // shell launch settings std::move(isolate_snapshot), // isolate snapshot on_create_platform_view, // platform view create callback From d022162b7362bb758cbc94b68fa095d9fe2fbac3 Mon Sep 17 00:00:00 2001 From: Chun-Heng Tai Date: Mon, 25 Nov 2019 16:58:06 -0800 Subject: [PATCH 04/10] update --- shell/platform/fuchsia/flutter/engine.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/fuchsia/flutter/engine.cc b/shell/platform/fuchsia/flutter/engine.cc index a7c81f8345ec6..76c6f39e41d09 100644 --- a/shell/platform/fuchsia/flutter/engine.cc +++ b/shell/platform/fuchsia/flutter/engine.cc @@ -235,7 +235,7 @@ Engine::Engine(Delegate& delegate, TRACE_EVENT0("flutter", "CreateShell"); shell_ = flutter::Shell::Create( task_runners, // host task runners - WindowData{}, // default window data + WindowData(), // default window data settings_, // shell launch settings std::move(isolate_snapshot), // isolate snapshot on_create_platform_view, // platform view create callback From 636aa1f9a4bf08a922ea15093ab8114f3051f568 Mon Sep 17 00:00:00 2001 From: Chun-Heng Tai Date: Mon, 25 Nov 2019 17:23:00 -0800 Subject: [PATCH 05/10] update --- shell/platform/fuchsia/flutter/engine.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/fuchsia/flutter/engine.cc b/shell/platform/fuchsia/flutter/engine.cc index 76c6f39e41d09..484d5b8145cd3 100644 --- a/shell/platform/fuchsia/flutter/engine.cc +++ b/shell/platform/fuchsia/flutter/engine.cc @@ -235,7 +235,7 @@ Engine::Engine(Delegate& delegate, TRACE_EVENT0("flutter", "CreateShell"); shell_ = flutter::Shell::Create( task_runners, // host task runners - WindowData(), // default window data + flutter::WindowData(), // default window data settings_, // shell launch settings std::move(isolate_snapshot), // isolate snapshot on_create_platform_view, // platform view create callback From cd3c18c60bde104a011ae59c613e9ecc9bd524a5 Mon Sep 17 00:00:00 2001 From: Chun-Heng Tai Date: Fri, 20 Dec 2019 16:10:38 -0800 Subject: [PATCH 06/10] refactor and addressing comment --- ci/licenses_golden/licenses_flutter | 2 + runtime/BUILD.gn | 2 + runtime/runtime_controller.cc | 8 +--- runtime/runtime_controller.h | 23 +-------- runtime/window_data.cc | 12 +++++ runtime/window_data.h | 48 +++++++++++++++++++ shell/common/engine.cc | 2 +- shell/common/engine.h | 2 +- shell/common/shell.cc | 6 +-- shell/common/shell.h | 12 +++-- .../platform/android/android_shell_holder.cc | 9 ++-- shell/platform/android/android_shell_holder.h | 4 +- .../framework/Source/FlutterDartProject.mm | 12 ++--- .../Source/FlutterDartProject_Internal.h | 4 +- .../ios/framework/Source/FlutterEngine.mm | 2 +- 15 files changed, 92 insertions(+), 56 deletions(-) create mode 100644 runtime/window_data.cc create mode 100644 runtime/window_data.h 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 f231f71eccc75..f61e69f4a43f3 100644 --- a/runtime/runtime_controller.cc +++ b/runtime/runtime_controller.cc @@ -26,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) @@ -369,10 +369,4 @@ RuntimeController::Locale::Locale(std::string language_code_, RuntimeController::Locale::~Locale() = default; -WindowData::WindowData() = default; - -WindowData::WindowData(const WindowData& other) = default; - -WindowData::~WindowData() = default; - } // namespace flutter diff --git a/runtime/runtime_controller.h b/runtime/runtime_controller.h index 6d3029cd299ab..21b8ed6a089c0 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" @@ -26,26 +27,6 @@ class RuntimeDelegate; class View; class Window; -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; - bool semantics_enabled = false; - bool assistive_technology_enabled = false; - int32_t accessibility_feature_flags_ = 0; -}; - class RuntimeController final : public WindowClient { public: RuntimeController( @@ -60,7 +41,7 @@ class RuntimeController final : public WindowClient { std::string advisory_script_uri, std::string advisory_script_entrypoint, const std::function& idle_notification_callback, - WindowData data, + const WindowData data, const fml::closure& isolate_create_callback, const fml::closure& isolate_shutdown_callback, std::shared_ptr persistent_isolate_data); 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..824e72c168b89 --- /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. Uses 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 d65af575c8e78..c998d49042b30 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -40,7 +40,7 @@ Engine::Engine(Delegate& delegate, DartVM& vm, fml::RefPtr isolate_snapshot, TaskRunners task_runners, - WindowData window_data, + const WindowData window_data, Settings settings, std::unique_ptr animator, fml::WeakPtr io_manager, diff --git a/shell/common/engine.h b/shell/common/engine.h index 8a170f625361e..896334a1aa08e 100644 --- a/shell/common/engine.h +++ b/shell/common/engine.h @@ -276,7 +276,7 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate { DartVM& vm, fml::RefPtr isolate_snapshot, TaskRunners task_runners, - WindowData window_data, + 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 f236586670af7..3a3f9cfa901ef 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -42,7 +42,7 @@ constexpr char kFontChange[] = "fontsChange"; std::unique_ptr Shell::CreateShellOnPlatformThread( DartVMRef vm, TaskRunners task_runners, - WindowData window_data, + const WindowData window_data, Settings settings, fml::RefPtr isolate_snapshot, const Shell::CreateCallback& on_create_platform_view, @@ -238,7 +238,7 @@ std::unique_ptr Shell::Create( std::unique_ptr Shell::Create( TaskRunners task_runners, - WindowData window_data, + const WindowData window_data, Settings settings, Shell::CreateCallback on_create_platform_view, Shell::CreateCallback on_create_rasterizer) { @@ -264,7 +264,7 @@ std::unique_ptr Shell::Create( std::unique_ptr Shell::Create( TaskRunners task_runners, - WindowData window_data, + const WindowData window_data, Settings settings, fml::RefPtr isolate_snapshot, const Shell::CreateCallback& on_create_platform_view, diff --git a/shell/common/shell.h b/shell/common/shell.h index dc8e3a820a97d..404fdf9cc67ed 100644 --- a/shell/common/shell.h +++ b/shell/common/shell.h @@ -137,7 +137,8 @@ class Shell final : public PlatformView::Delegate, /// /// @param[in] task_runners The task runners /// @param[in] window_data The default data for setting up - /// window. + /// 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 @@ -158,7 +159,7 @@ class Shell final : public PlatformView::Delegate, /// static std::unique_ptr Create( TaskRunners task_runners, - WindowData window_data, + const WindowData window_data, Settings settings, CreateCallback on_create_platform_view, CreateCallback on_create_rasterizer); @@ -174,7 +175,8 @@ class Shell final : public PlatformView::Delegate, /// /// @param[in] task_runners The task runners /// @param[in] window_data The default data for setting up - /// window. + /// 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 @@ -199,7 +201,7 @@ class Shell final : public PlatformView::Delegate, /// static std::unique_ptr Create( TaskRunners task_runners, - WindowData window_data, + const WindowData window_data, Settings settings, fml::RefPtr isolate_snapshot, const CreateCallback& on_create_platform_view, @@ -411,7 +413,7 @@ class Shell final : public PlatformView::Delegate, static std::unique_ptr CreateShellOnPlatformThread( DartVMRef vm, TaskRunners task_runners, - WindowData windowd_data, + 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 09cdb9dd20f30..7e82f123d5781 100644 --- a/shell/platform/android/android_shell_holder.cc +++ b/shell/platform/android/android_shell_holder.cc @@ -101,12 +101,9 @@ AndroidShellHolder::AndroidShellHolder( io_runner // io ); - flutter::WindowData window_data; - InitializesWindowData(window_data); - shell_ = Shell::Create(task_runners, // task runners - window_data, // window data + getDefaultWindowData(), // window data settings_, // settings on_create_platform_view, // platform view create callback on_create_rasterizer // rasterizer create callback @@ -144,8 +141,10 @@ AndroidShellHolder::~AndroidShellHolder() { FML_CHECK(pthread_key_delete(thread_destruct_key_) == 0); } -void AndroidShellHolder::InitializesWindowData(WindowData& window_data) { +WindowData AndroidShellHolder::getDefaultWindowData() { + WindowData window_data; window_data.lifecycle_state = "AppLifecycleState.detached"; + return window_data; } void AndroidShellHolder::ThreadDestructCallback(void* value) { diff --git a/shell/platform/android/android_shell_holder.h b/shell/platform/android/android_shell_holder.h index 54e365a03b986..ea725c328f707 100644 --- a/shell/platform/android/android_shell_holder.h +++ b/shell/platform/android/android_shell_holder.h @@ -11,7 +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/runtime_controller.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" @@ -50,7 +50,7 @@ class AndroidShellHolder { pthread_key_t thread_destruct_key_; uint64_t next_pointer_flow_id_ = 0; - void InitializesWindowData(WindowData& window_data); + WindowData getDefaultWindowData(); static void ThreadDestructCallback(void* value); diff --git a/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm b/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm index 8fdb1b60dc612..0e70b025a76bd 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm @@ -148,7 +148,6 @@ @implementation FlutterDartProject { flutter::Settings _settings; - flutter::WindowData _windowData; } #pragma mark - Override base class designated initializers @@ -164,7 +163,6 @@ - (instancetype)initWithPrecompiledDartBundle:(nullable NSBundle*)bundle { if (self) { _settings = DefaultSettingsForProcess(bundle); - [self initializesWindowData]; } return self; @@ -172,8 +170,10 @@ - (instancetype)initWithPrecompiledDartBundle:(nullable NSBundle*)bundle { #pragma mark - WindowData accessors -- (const flutter::WindowData&)windowData { - return _windowData; +- (const flutter::WindowData)defaultWindowData { + flutter::WindowData windowData; + windowData.lifecycle_state = std::string("AppLifecycleState.detached"); + return windowData; } #pragma mark - Settings accessors @@ -263,8 +263,4 @@ - (void)setPersistentIsolateData:(NSData*)data { #pragma mark - windowData utilities -- (void)initializesWindowData { - _windowData.lifecycle_state = std::string([@"AppLifecycleState.detached" UTF8String]); -} - @end diff --git a/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h index 0d9c474b32437..b21a38a9be6fd 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h @@ -6,7 +6,7 @@ #define SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTERDARTPROJECT_INTERNAL_H_ #include "flutter/common/settings.h" -#include "flutter/runtime/runtime_controller.h" +#include "flutter/runtime/window_data.h" #include "flutter/shell/common/engine.h" #include "flutter/shell/platform/darwin/ios/framework/Headers/FlutterDartProject.h" @@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN @interface FlutterDartProject () - (const flutter::Settings&)settings; -- (const flutter::WindowData&)windowData; +- (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 2b58b8ed6e3f1..204dba1c6b2db 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -388,7 +388,7 @@ - (BOOL)createShell:(NSString*)entrypoint libraryURI:(NSString*)libraryURI { static size_t shellCount = 1; auto settings = [_dartProject.get() settings]; - auto windowData = [_dartProject.get() windowData]; + auto windowData = [_dartProject.get() defaultWindowData]; if (libraryURI) { FML_DCHECK(entrypoint) << "Must specify entrypoint if specifying library"; From 1d1e3a33ae8831bea2c38d9a8ec8fc4fd3824fdb Mon Sep 17 00:00:00 2001 From: Chun-Heng Tai Date: Wed, 8 Jan 2020 16:31:26 -0800 Subject: [PATCH 07/10] addressing comment --- runtime/runtime_controller.cc | 2 +- runtime/runtime_controller.h | 2 +- runtime/window_data.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/runtime_controller.cc b/runtime/runtime_controller.cc index f61e69f4a43f3..f7695d3d00a3b 100644 --- a/runtime/runtime_controller.cc +++ b/runtime/runtime_controller.cc @@ -26,7 +26,7 @@ RuntimeController::RuntimeController( std::string p_advisory_script_uri, std::string p_advisory_script_entrypoint, const std::function& idle_notification_callback, - const 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) diff --git a/runtime/runtime_controller.h b/runtime/runtime_controller.h index 21b8ed6a089c0..cea325bad7444 100644 --- a/runtime/runtime_controller.h +++ b/runtime/runtime_controller.h @@ -41,7 +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 WindowData& data, const fml::closure& isolate_create_callback, const fml::closure& isolate_shutdown_callback, std::shared_ptr persistent_isolate_data); diff --git a/runtime/window_data.h b/runtime/window_data.h index 824e72c168b89..086bc2ab40258 100644 --- a/runtime/window_data.h +++ b/runtime/window_data.h @@ -17,7 +17,7 @@ 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. Uses this struct to set the desired default value for ui.Window +/// 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: From 366e45dd37ec6d08b3811f0ea1dc3ea03e7c9727 Mon Sep 17 00:00:00 2001 From: Chun-Heng Tai Date: Wed, 8 Jan 2020 17:28:57 -0800 Subject: [PATCH 08/10] fix format --- runtime/window_data.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/runtime/window_data.h b/runtime/window_data.h index 086bc2ab40258..c3a62a16c43f2 100644 --- a/runtime/window_data.h +++ b/runtime/window_data.h @@ -17,8 +17,9 @@ 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. +/// 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: /// From 4d36fc0a80408f9a5cc61cb8498d2339e0727a5f Mon Sep 17 00:00:00 2001 From: Chun-Heng Tai Date: Wed, 8 Jan 2020 18:16:39 -0800 Subject: [PATCH 09/10] reformat --- runtime/window_data.h | 3 +-- shell/common/shell.h | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/runtime/window_data.h b/runtime/window_data.h index c3a62a16c43f2..e234d2f558162 100644 --- a/runtime/window_data.h +++ b/runtime/window_data.h @@ -24,8 +24,7 @@ namespace flutter { /// See also: /// /// * flutter::Shell::Create, which takes a window_data to initialize the -/// ui.Window -/// attached to it. +/// ui.Window attached to it. struct WindowData { WindowData(); diff --git a/shell/common/shell.h b/shell/common/shell.h index 404fdf9cc67ed..39ffd6055435c 100644 --- a/shell/common/shell.h +++ b/shell/common/shell.h @@ -132,8 +132,8 @@ class Shell final : public PlatformView::Delegate, /// 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. + /// 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 From 641c6f0567ac0d88a3c9441680227161b6974147 Mon Sep 17 00:00:00 2001 From: Chun-Heng Tai Date: Wed, 8 Jan 2020 18:41:09 -0800 Subject: [PATCH 10/10] addressing comment --- shell/platform/android/android_shell_holder.cc | 14 +++++++------- shell/platform/android/android_shell_holder.h | 2 -- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/shell/platform/android/android_shell_holder.cc b/shell/platform/android/android_shell_holder.cc index 7e82f123d5781..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,7 +109,7 @@ AndroidShellHolder::AndroidShellHolder( shell_ = Shell::Create(task_runners, // task runners - getDefaultWindowData(), // window data + GetDefaultWindowData(), // window data settings_, // settings on_create_platform_view, // platform view create callback on_create_rasterizer // rasterizer create callback @@ -141,12 +147,6 @@ AndroidShellHolder::~AndroidShellHolder() { FML_CHECK(pthread_key_delete(thread_destruct_key_) == 0); } -WindowData AndroidShellHolder::getDefaultWindowData() { - WindowData window_data; - window_data.lifecycle_state = "AppLifecycleState.detached"; - return window_data; -} - void AndroidShellHolder::ThreadDestructCallback(void* value) { fml::jni::DetachFromVM(); } diff --git a/shell/platform/android/android_shell_holder.h b/shell/platform/android/android_shell_holder.h index ea725c328f707..9be7f35df0bb8 100644 --- a/shell/platform/android/android_shell_holder.h +++ b/shell/platform/android/android_shell_holder.h @@ -50,8 +50,6 @@ class AndroidShellHolder { pthread_key_t thread_destruct_key_; uint64_t next_pointer_flow_id_ = 0; - WindowData getDefaultWindowData(); - static void ThreadDestructCallback(void* value); FML_DISALLOW_COPY_AND_ASSIGN(AndroidShellHolder);