Skip to content

Commit cef181f

Browse files
chunhtaiNoamDev
authored andcommitted
Add shell api to set default for windows data (flutter#14002)
1 parent 6c45c25 commit cef181f

16 files changed

Lines changed: 158 additions & 78 deletions

File tree

ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ FILE: ../../../flutter/runtime/start_up.cc
536536
FILE: ../../../flutter/runtime/start_up.h
537537
FILE: ../../../flutter/runtime/test_font_data.cc
538538
FILE: ../../../flutter/runtime/test_font_data.h
539+
FILE: ../../../flutter/runtime/window_data.cc
540+
FILE: ../../../flutter/runtime/window_data.h
539541
FILE: ../../../flutter/shell/common/animator.cc
540542
FILE: ../../../flutter/shell/common/animator.h
541543
FILE: ../../../flutter/shell/common/animator_unittests.cc

runtime/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ source_set("runtime") {
6868
"skia_concurrent_executor.h",
6969
"start_up.cc",
7070
"start_up.h",
71+
"window_data.cc",
72+
"window_data.h",
7173
]
7274

7375
deps = [

runtime/runtime_controller.cc

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,6 @@
1414

1515
namespace flutter {
1616

17-
RuntimeController::RuntimeController(
18-
RuntimeDelegate& p_client,
19-
DartVM* p_vm,
20-
fml::RefPtr<const DartSnapshot> p_isolate_snapshot,
21-
TaskRunners p_task_runners,
22-
fml::WeakPtr<SnapshotDelegate> p_snapshot_delegate,
23-
fml::WeakPtr<IOManager> p_io_manager,
24-
fml::RefPtr<SkiaUnrefQueue> p_unref_queue,
25-
fml::WeakPtr<ImageDecoder> p_image_decoder,
26-
std::string p_advisory_script_uri,
27-
std::string p_advisory_script_entrypoint,
28-
const std::function<void(int64_t)>& p_idle_notification_callback,
29-
const fml::closure& p_isolate_create_callback,
30-
const fml::closure& p_isolate_shutdown_callback,
31-
std::shared_ptr<const fml::Mapping> p_persistent_isolate_data)
32-
: RuntimeController(p_client,
33-
p_vm,
34-
std::move(p_isolate_snapshot),
35-
std::move(p_task_runners),
36-
std::move(p_snapshot_delegate),
37-
std::move(p_io_manager),
38-
std::move(p_unref_queue),
39-
std::move(p_image_decoder),
40-
std::move(p_advisory_script_uri),
41-
std::move(p_advisory_script_entrypoint),
42-
p_idle_notification_callback,
43-
WindowData{/* default window data */},
44-
p_isolate_create_callback,
45-
p_isolate_shutdown_callback,
46-
std::move(p_persistent_isolate_data)) {}
47-
4817
RuntimeController::RuntimeController(
4918
RuntimeDelegate& p_client,
5019
DartVM* p_vm,
@@ -57,7 +26,7 @@ RuntimeController::RuntimeController(
5726
std::string p_advisory_script_uri,
5827
std::string p_advisory_script_entrypoint,
5928
const std::function<void(int64_t)>& idle_notification_callback,
60-
WindowData p_window_data,
29+
const WindowData& p_window_data,
6130
const fml::closure& p_isolate_create_callback,
6231
const fml::closure& p_isolate_shutdown_callback,
6332
std::shared_ptr<const fml::Mapping> p_persistent_isolate_data)
@@ -400,10 +369,4 @@ RuntimeController::Locale::Locale(std::string language_code_,
400369

401370
RuntimeController::Locale::~Locale() = default;
402371

403-
RuntimeController::WindowData::WindowData() = default;
404-
405-
RuntimeController::WindowData::WindowData(const WindowData& other) = default;
406-
407-
RuntimeController::WindowData::~WindowData() = default;
408-
409372
} // namespace flutter

runtime/runtime_controller.h

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "flutter/lib/ui/window/pointer_data_packet.h"
1818
#include "flutter/lib/ui/window/window.h"
1919
#include "flutter/runtime/dart_vm.h"
20+
#include "flutter/runtime/window_data.h"
2021
#include "rapidjson/document.h"
2122
#include "rapidjson/stringbuffer.h"
2223

@@ -40,6 +41,7 @@ class RuntimeController final : public WindowClient {
4041
std::string advisory_script_uri,
4142
std::string advisory_script_entrypoint,
4243
const std::function<void(int64_t)>& idle_notification_callback,
44+
const WindowData& data,
4345
const fml::closure& isolate_create_callback,
4446
const fml::closure& isolate_shutdown_callback,
4547
std::shared_ptr<const fml::Mapping> persistent_isolate_data);
@@ -103,29 +105,6 @@ class RuntimeController final : public WindowClient {
103105
std::string variant_code;
104106
};
105107

106-
// Stores data about the window to be used at startup
107-
// as well as on hot restarts. Data kept here will persist
108-
// after hot restart.
109-
struct WindowData {
110-
WindowData();
111-
112-
WindowData(const WindowData& other);
113-
114-
~WindowData();
115-
116-
ViewportMetrics viewport_metrics;
117-
std::string language_code;
118-
std::string country_code;
119-
std::string script_code;
120-
std::string variant_code;
121-
std::vector<std::string> locale_data;
122-
std::string user_settings_data = "{}";
123-
std::string lifecycle_state = "AppLifecycleState.detached";
124-
bool semantics_enabled = false;
125-
bool assistive_technology_enabled = false;
126-
int32_t accessibility_feature_flags_ = 0;
127-
};
128-
129108
RuntimeDelegate& client_;
130109
DartVM* const vm_;
131110
fml::RefPtr<const DartSnapshot> isolate_snapshot_;
@@ -144,23 +123,6 @@ class RuntimeController final : public WindowClient {
144123
const fml::closure isolate_shutdown_callback_;
145124
std::shared_ptr<const fml::Mapping> persistent_isolate_data_;
146125

147-
RuntimeController(
148-
RuntimeDelegate& client,
149-
DartVM* vm,
150-
fml::RefPtr<const DartSnapshot> isolate_snapshot,
151-
TaskRunners task_runners,
152-
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
153-
fml::WeakPtr<IOManager> io_manager,
154-
fml::RefPtr<SkiaUnrefQueue> unref_queue,
155-
fml::WeakPtr<ImageDecoder> image_decoder,
156-
std::string advisory_script_uri,
157-
std::string advisory_script_entrypoint,
158-
const std::function<void(int64_t)>& idle_notification_callback,
159-
WindowData data,
160-
const fml::closure& isolate_create_callback,
161-
const fml::closure& isolate_shutdown_callback,
162-
std::shared_ptr<const fml::Mapping> persistent_isolate_data);
163-
164126
Window* GetWindowIfAvailable();
165127

166128
bool FlushRuntimeStateToIsolate();

runtime/window_data.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "flutter/runtime/window_data.h"
6+
7+
namespace flutter {
8+
WindowData::WindowData() = default;
9+
10+
WindowData::~WindowData() = default;
11+
12+
} // namespace flutter

runtime/window_data.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef FLUTTER_RUNTIME_WINDOW_DATA_H_
6+
#define FLUTTER_RUNTIME_WINDOW_DATA_H_
7+
8+
#include "flutter/lib/ui/window/viewport_metrics.h"
9+
10+
#include <memory>
11+
#include <string>
12+
#include <vector>
13+
14+
namespace flutter {
15+
16+
//------------------------------------------------------------------------------
17+
/// The struct of platform-specific data used for initializing ui.Window.
18+
///
19+
/// framework may request data from ui.Window before platform is properly
20+
/// configured. Engine this struct to set the desired default value for
21+
/// ui.Window when creating Shell before platform is ready to send the real
22+
/// data.
23+
///
24+
/// See also:
25+
///
26+
/// * flutter::Shell::Create, which takes a window_data to initialize the
27+
/// ui.Window attached to it.
28+
struct WindowData {
29+
WindowData();
30+
31+
~WindowData();
32+
33+
ViewportMetrics viewport_metrics;
34+
std::string language_code;
35+
std::string country_code;
36+
std::string script_code;
37+
std::string variant_code;
38+
std::vector<std::string> locale_data;
39+
std::string user_settings_data = "{}";
40+
std::string lifecycle_state;
41+
bool semantics_enabled = false;
42+
bool assistive_technology_enabled = false;
43+
int32_t accessibility_feature_flags_ = 0;
44+
};
45+
46+
} // namespace flutter
47+
48+
#endif // FLUTTER_RUNTIME_WINDOW_DATA_H_

shell/common/engine.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Engine::Engine(Delegate& delegate,
4040
DartVM& vm,
4141
fml::RefPtr<const DartSnapshot> isolate_snapshot,
4242
TaskRunners task_runners,
43+
const WindowData window_data,
4344
Settings settings,
4445
std::unique_ptr<Animator> animator,
4546
fml::WeakPtr<IOManager> io_manager,
@@ -70,6 +71,7 @@ Engine::Engine(Delegate& delegate,
7071
settings_.advisory_script_uri, // advisory script uri
7172
settings_.advisory_script_entrypoint, // advisory script entrypoint
7273
settings_.idle_notification_callback, // idle notification callback
74+
window_data, // window data
7375
settings_.isolate_create_callback, // isolate create callback
7476
settings_.isolate_shutdown_callback, // isolate shutdown callback
7577
settings_.persistent_isolate_data // persistent isolate data

shell/common/engine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate {
276276
DartVM& vm,
277277
fml::RefPtr<const DartSnapshot> isolate_snapshot,
278278
TaskRunners task_runners,
279+
const WindowData window_data,
279280
Settings settings,
280281
std::unique_ptr<Animator> animator,
281282
fml::WeakPtr<IOManager> io_manager,

shell/common/shell.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ constexpr char kFontChange[] = "fontsChange";
4242
std::unique_ptr<Shell> Shell::CreateShellOnPlatformThread(
4343
DartVMRef vm,
4444
TaskRunners task_runners,
45+
const WindowData window_data,
4546
Settings settings,
4647
fml::RefPtr<const DartSnapshot> isolate_snapshot,
4748
const Shell::CreateCallback<PlatformView>& on_create_platform_view,
@@ -132,6 +133,7 @@ std::unique_ptr<Shell> Shell::CreateShellOnPlatformThread(
132133
fml::MakeCopyable([&engine_promise, //
133134
shell = shell.get(), //
134135
&dispatcher_maker, //
136+
&window_data, //
135137
isolate_snapshot = std::move(isolate_snapshot), //
136138
vsync_waiter = std::move(vsync_waiter), //
137139
&weak_io_manager_future, //
@@ -152,6 +154,7 @@ std::unique_ptr<Shell> Shell::CreateShellOnPlatformThread(
152154
*shell->GetDartVM(), //
153155
std::move(isolate_snapshot), //
154156
task_runners, //
157+
window_data, //
155158
shell->GetSettings(), //
156159
std::move(animator), //
157160
weak_io_manager_future.get(), //
@@ -225,6 +228,20 @@ std::unique_ptr<Shell> Shell::Create(
225228
Settings settings,
226229
const Shell::CreateCallback<PlatformView>& on_create_platform_view,
227230
const Shell::CreateCallback<Rasterizer>& on_create_rasterizer) {
231+
return Shell::Create(std::move(task_runners), //
232+
WindowData{/* default window data */}, //
233+
std::move(settings), //
234+
std::move(on_create_platform_view), //
235+
std::move(on_create_rasterizer) //
236+
);
237+
}
238+
239+
std::unique_ptr<Shell> Shell::Create(
240+
TaskRunners task_runners,
241+
const WindowData window_data,
242+
Settings settings,
243+
Shell::CreateCallback<PlatformView> on_create_platform_view,
244+
Shell::CreateCallback<Rasterizer> on_create_rasterizer) {
228245
PerformInitializationTasks(settings);
229246
PersistentCache::SetCacheSkSL(settings.cache_sksl);
230247

@@ -236,6 +253,7 @@ std::unique_ptr<Shell> Shell::Create(
236253
auto vm_data = vm->GetVMData();
237254

238255
return Shell::Create(std::move(task_runners), //
256+
std::move(window_data), //
239257
std::move(settings), //
240258
vm_data->GetIsolateSnapshot(), // isolate snapshot
241259
on_create_platform_view, //
@@ -246,6 +264,7 @@ std::unique_ptr<Shell> Shell::Create(
246264

247265
std::unique_ptr<Shell> Shell::Create(
248266
TaskRunners task_runners,
267+
const WindowData window_data,
249268
Settings settings,
250269
fml::RefPtr<const DartSnapshot> isolate_snapshot,
251270
const Shell::CreateCallback<PlatformView>& on_create_platform_view,
@@ -269,13 +288,15 @@ std::unique_ptr<Shell> Shell::Create(
269288
vm = std::move(vm), //
270289
&shell, //
271290
task_runners = std::move(task_runners), //
291+
window_data, //
272292
settings, //
273293
isolate_snapshot = std::move(isolate_snapshot), //
274294
on_create_platform_view, //
275295
on_create_rasterizer //
276296
]() mutable {
277297
shell = CreateShellOnPlatformThread(std::move(vm),
278298
std::move(task_runners), //
299+
window_data, //
279300
settings, //
280301
std::move(isolate_snapshot), //
281302
on_create_platform_view, //

shell/common/shell.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,44 @@ class Shell final : public PlatformView::Delegate,
126126
const CreateCallback<PlatformView>& on_create_platform_view,
127127
const CreateCallback<Rasterizer>& on_create_rasterizer);
128128

129+
//----------------------------------------------------------------------------
130+
/// @brief Creates a shell instance using the provided settings. The
131+
/// callbacks to create the various shell subcomponents will be
132+
/// called on the appropriate threads before this method returns.
133+
/// Unlike the simpler variant of this factory method, this method
134+
/// allows for specification of window data. If this is the first
135+
/// instance of a shell in the process, this call also bootstraps
136+
/// the Dart VM.
137+
///
138+
/// @param[in] task_runners The task runners
139+
/// @param[in] window_data The default data for setting up
140+
/// ui.Window that attached to this
141+
/// intance.
142+
/// @param[in] settings The settings
143+
/// @param[in] on_create_platform_view The callback that must return a
144+
/// platform view. This will be called on
145+
/// the platform task runner before this
146+
/// method returns.
147+
/// @param[in] on_create_rasterizer That callback that must provide a
148+
/// valid rasterizer. This will be called
149+
/// on the render task runner before this
150+
/// method returns.
151+
///
152+
/// @return A full initialized shell if the settings and callbacks are
153+
/// valid. The root isolate has been created but not yet launched.
154+
/// It may be launched by obtaining the engine weak pointer and
155+
/// posting a task onto the UI task runner with a valid run
156+
/// configuration to run the isolate. The embedder must always
157+
/// check the validity of the shell (using the IsSetup call)
158+
/// immediately after getting a pointer to it.
159+
///
160+
static std::unique_ptr<Shell> Create(
161+
TaskRunners task_runners,
162+
const WindowData window_data,
163+
Settings settings,
164+
CreateCallback<PlatformView> on_create_platform_view,
165+
CreateCallback<Rasterizer> on_create_rasterizer);
166+
129167
//----------------------------------------------------------------------------
130168
/// @brief Creates a shell instance using the provided settings. The
131169
/// callbacks to create the various shell subcomponents will be
@@ -136,6 +174,9 @@ class Shell final : public PlatformView::Delegate,
136174
/// requires the specification of a running VM instance.
137175
///
138176
/// @param[in] task_runners The task runners
177+
/// @param[in] window_data The default data for setting up
178+
/// ui.Window that attached to this
179+
/// intance.
139180
/// @param[in] settings The settings
140181
/// @param[in] isolate_snapshot A custom isolate snapshot. Takes
141182
/// precedence over any snapshots
@@ -160,6 +201,7 @@ class Shell final : public PlatformView::Delegate,
160201
///
161202
static std::unique_ptr<Shell> Create(
162203
TaskRunners task_runners,
204+
const WindowData window_data,
163205
Settings settings,
164206
fml::RefPtr<const DartSnapshot> isolate_snapshot,
165207
const CreateCallback<PlatformView>& on_create_platform_view,
@@ -371,6 +413,7 @@ class Shell final : public PlatformView::Delegate,
371413
static std::unique_ptr<Shell> CreateShellOnPlatformThread(
372414
DartVMRef vm,
373415
TaskRunners task_runners,
416+
const WindowData window_data,
374417
Settings settings,
375418
fml::RefPtr<const DartSnapshot> isolate_snapshot,
376419
const Shell::CreateCallback<PlatformView>& on_create_platform_view,

0 commit comments

Comments
 (0)