未验证 提交 7a27e75c 编写于 作者: C chunhtai 提交者: GitHub

Add shell api to set default for windows data (#14002)

上级 e6f2dcc8
......@@ -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
......
......@@ -68,6 +68,8 @@ source_set("runtime") {
"skia_concurrent_executor.h",
"start_up.cc",
"start_up.h",
"window_data.cc",
"window_data.h",
]
deps = [
......
......@@ -14,37 +14,6 @@
namespace flutter {
RuntimeController::RuntimeController(
RuntimeDelegate& p_client,
DartVM* p_vm,
fml::RefPtr<const DartSnapshot> p_isolate_snapshot,
TaskRunners p_task_runners,
fml::WeakPtr<SnapshotDelegate> p_snapshot_delegate,
fml::WeakPtr<IOManager> p_io_manager,
fml::RefPtr<SkiaUnrefQueue> p_unref_queue,
fml::WeakPtr<ImageDecoder> p_image_decoder,
std::string p_advisory_script_uri,
std::string p_advisory_script_entrypoint,
const std::function<void(int64_t)>& p_idle_notification_callback,
const fml::closure& p_isolate_create_callback,
const fml::closure& p_isolate_shutdown_callback,
std::shared_ptr<const fml::Mapping> 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<void(int64_t)>& 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<const fml::Mapping> 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
......@@ -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<void(int64_t)>& idle_notification_callback,
const WindowData& data,
const fml::closure& isolate_create_callback,
const fml::closure& isolate_shutdown_callback,
std::shared_ptr<const fml::Mapping> 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<std::string> 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<const DartSnapshot> isolate_snapshot_;
......@@ -144,23 +123,6 @@ class RuntimeController final : public WindowClient {
const fml::closure isolate_shutdown_callback_;
std::shared_ptr<const fml::Mapping> persistent_isolate_data_;
RuntimeController(
RuntimeDelegate& client,
DartVM* vm,
fml::RefPtr<const DartSnapshot> isolate_snapshot,
TaskRunners task_runners,
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
fml::WeakPtr<IOManager> io_manager,
fml::RefPtr<SkiaUnrefQueue> unref_queue,
fml::WeakPtr<ImageDecoder> image_decoder,
std::string advisory_script_uri,
std::string advisory_script_entrypoint,
const std::function<void(int64_t)>& idle_notification_callback,
WindowData data,
const fml::closure& isolate_create_callback,
const fml::closure& isolate_shutdown_callback,
std::shared_ptr<const fml::Mapping> persistent_isolate_data);
Window* GetWindowIfAvailable();
bool FlushRuntimeStateToIsolate();
......
// 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
// 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 <memory>
#include <string>
#include <vector>
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<std::string> 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_
......@@ -40,6 +40,7 @@ Engine::Engine(Delegate& delegate,
DartVM& vm,
fml::RefPtr<const DartSnapshot> isolate_snapshot,
TaskRunners task_runners,
const WindowData window_data,
Settings settings,
std::unique_ptr<Animator> animator,
fml::WeakPtr<IOManager> 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
......
......@@ -276,6 +276,7 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate {
DartVM& vm,
fml::RefPtr<const DartSnapshot> isolate_snapshot,
TaskRunners task_runners,
const WindowData window_data,
Settings settings,
std::unique_ptr<Animator> animator,
fml::WeakPtr<IOManager> io_manager,
......
......@@ -42,6 +42,7 @@ constexpr char kFontChange[] = "fontsChange";
std::unique_ptr<Shell> Shell::CreateShellOnPlatformThread(
DartVMRef vm,
TaskRunners task_runners,
const WindowData window_data,
Settings settings,
fml::RefPtr<const DartSnapshot> isolate_snapshot,
const Shell::CreateCallback<PlatformView>& on_create_platform_view,
......@@ -132,6 +133,7 @@ std::unique_ptr<Shell> 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> 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> Shell::Create(
Settings settings,
const Shell::CreateCallback<PlatformView>& on_create_platform_view,
const Shell::CreateCallback<Rasterizer>& 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> Shell::Create(
TaskRunners task_runners,
const WindowData window_data,
Settings settings,
Shell::CreateCallback<PlatformView> on_create_platform_view,
Shell::CreateCallback<Rasterizer> on_create_rasterizer) {
PerformInitializationTasks(settings);
PersistentCache::SetCacheSkSL(settings.cache_sksl);
......@@ -236,6 +253,7 @@ std::unique_ptr<Shell> 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> Shell::Create(
std::unique_ptr<Shell> Shell::Create(
TaskRunners task_runners,
const WindowData window_data,
Settings settings,
fml::RefPtr<const DartSnapshot> isolate_snapshot,
const Shell::CreateCallback<PlatformView>& on_create_platform_view,
......@@ -269,6 +288,7 @@ std::unique_ptr<Shell> 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> Shell::Create(
]() mutable {
shell = CreateShellOnPlatformThread(std::move(vm),
std::move(task_runners), //
window_data, //
settings, //
std::move(isolate_snapshot), //
on_create_platform_view, //
......
......@@ -126,6 +126,44 @@ class Shell final : public PlatformView::Delegate,
const CreateCallback<PlatformView>& on_create_platform_view,
const CreateCallback<Rasterizer>& 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<Shell> Create(
TaskRunners task_runners,
const WindowData window_data,
Settings settings,
CreateCallback<PlatformView> on_create_platform_view,
CreateCallback<Rasterizer> 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<Shell> Create(
TaskRunners task_runners,
const WindowData window_data,
Settings settings,
fml::RefPtr<const DartSnapshot> isolate_snapshot,
const CreateCallback<PlatformView>& on_create_platform_view,
......@@ -371,6 +413,7 @@ class Shell final : public PlatformView::Delegate,
static std::unique_ptr<Shell> CreateShellOnPlatformThread(
DartVMRef vm,
TaskRunners task_runners,
const WindowData window_data,
Settings settings,
fml::RefPtr<const DartSnapshot> isolate_snapshot,
const Shell::CreateCallback<PlatformView>& on_create_platform_view,
......
......@@ -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
......
......@@ -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"
......
......@@ -168,6 +168,14 @@ static flutter::Settings DefaultSettingsForProcess(NSBundle* bundle = nil) {
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 @@ static flutter::Settings DefaultSettingsForProcess(NSBundle* bundle = nil) {
);
}
#pragma mark - windowData utilities
@end
......@@ -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;
......
......@@ -388,6 +388,7 @@ NSString* const FlutterDefaultDartEntrypoint = nil;
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 @@ NSString* const FlutterDefaultDartEntrypoint = nil;
);
// 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 @@ NSString* const FlutterDefaultDartEntrypoint = nil;
);
// 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
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册