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

Commit 91de367

Browse files
author
Chris Yang
committed
draft
1 parent 825ca5a commit 91de367

File tree

5 files changed

+50
-16
lines changed

5 files changed

+50
-16
lines changed

common/settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ struct Settings {
213213
/// to log a timeline event that tracks the latency of engine startup.
214214
std::chrono::microseconds engine_start_timestamp = {};
215215

216+
bool use_embedded_view = false;
217+
216218
std::string ToString() const;
217219
};
218220

shell/platform/android/android_shell_holder.cc

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,28 +101,53 @@ AndroidShellHolder::AndroidShellHolder(
101101
ui_runner = thread_host_.ui_thread->GetTaskRunner();
102102
io_runner = thread_host_.io_thread->GetTaskRunner();
103103
}
104-
flutter::TaskRunners task_runners(thread_label, // label
105-
platform_runner, // platform
106-
gpu_runner, // raster
107-
ui_runner, // ui
108-
io_runner // io
109-
);
110-
111-
shell_ =
104+
if (settings.use_embedded_view) {
105+
// Embedded views requires the gpu and the platform views to be the same.
106+
// The plan is to eventually dynamically merge the threads when there's a
107+
// platform view in the layer tree.
108+
// For now we use a fixed thread configuration with the same thread used as the
109+
// gpu and platform task runner.
110+
// TODO(amirh/chinmaygarde): remove this, and dynamically change the thread configuration.
111+
// https://github.com/flutter/flutter/issues/23975
112+
// https://github.com/flutter/flutter/issues/59930
113+
flutter::TaskRunners task_runners(thread_label, // label
114+
platform_runner, // platform
115+
platform_runner, // raster
116+
ui_runner, // ui
117+
io_runner // io
118+
);
119+
120+
shell_ =
112121
Shell::Create(task_runners, // task runners
113122
GetDefaultWindowData(), // window data
114123
settings_, // settings
115124
on_create_platform_view, // platform view create callback
116125
on_create_rasterizer // rasterizer create callback
117126
);
127+
} else {
128+
flutter::TaskRunners task_runners(thread_label, // label
129+
platform_runner, // platform
130+
gpu_runner, // raster
131+
ui_runner, // ui
132+
io_runner // io
133+
);
134+
135+
shell_ =
136+
Shell::Create(task_runners, // task runners
137+
GetDefaultWindowData(), // window data
138+
settings_, // settings
139+
on_create_platform_view, // platform view create callback
140+
on_create_rasterizer // rasterizer create callback
141+
);
142+
}
118143

119144
platform_view_ = weak_platform_view;
120145
FML_DCHECK(platform_view_);
121146

122147
is_valid_ = shell_ != nullptr;
123148

124149
if (is_valid_) {
125-
task_runners.GetRasterTaskRunner()->PostTask([]() {
150+
shell_->GetTaskRunners().GetRasterTaskRunner()->PostTask([]() {
126151
// Android describes -8 as "most important display threads, for
127152
// compositing the screen and retrieving input events". Conservatively
128153
// set the raster thread to slightly lower priority than it.
@@ -134,7 +159,7 @@ AndroidShellHolder::AndroidShellHolder(
134159
}
135160
}
136161
});
137-
task_runners.GetUITaskRunner()->PostTask([]() {
162+
shell_->GetTaskRunners().GetUITaskRunner()->PostTask([]() {
138163
if (::setpriority(PRIO_PROCESS, gettid(), -1) != 0) {
139164
FML_LOG(ERROR) << "Failed to set UI task runner priority";
140165
}

shell/platform/android/flutter_main.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ void FlutterMain::Init(JNIEnv* env,
6363
jstring kernelPath,
6464
jstring appStoragePath,
6565
jstring engineCachesPath,
66-
jlong initTimeMillis) {
66+
jlong initTimeMillis,
67+
jboolean useEmbeddedView) {
6768
std::vector<std::string> args;
6869
args.push_back("flutter");
6970
for (auto& arg : fml::jni::StringArrayToVector(env, jargs)) {
@@ -99,6 +100,8 @@ void FlutterMain::Init(JNIEnv* env,
99100
}
100101
}
101102

103+
settings.use_embedded_view = useEmbeddedView;
104+
102105
settings.task_observer_add = [](intptr_t key, fml::closure callback) {
103106
fml::MessageLoop::GetCurrent().AddTaskObserver(key, std::move(callback));
104107
};
@@ -165,8 +168,7 @@ bool FlutterMain::Register(JNIEnv* env) {
165168
static const JNINativeMethod methods[] = {
166169
{
167170
.name = "nativeInit",
168-
.signature = "(Landroid/content/Context;[Ljava/lang/String;Ljava/"
169-
"lang/String;Ljava/lang/String;Ljava/lang/String;J)V",
171+
.signature = "(Landroid/content/Context;[Ljava/lang/String;Ljava/",
170172
.fnPtr = reinterpret_cast<void*>(&Init),
171173
},
172174
{

shell/platform/android/flutter_main.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class FlutterMain {
3636
jstring kernelPath,
3737
jstring appStoragePath,
3838
jstring engineCachesPath,
39-
jlong initTimeMillis);
39+
jlong initTimeMillis,
40+
jboolean useEmbeddedView);
4041

4142
void SetupObservatoryUriCallback(JNIEnv* env);
4243

shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ public void ensureInitializationComplete(
201201
+ applicationInfo.nativeLibraryDir
202202
+ File.separator
203203
+ DEFAULT_LIBRARY);
204-
205204
if (args != null) {
206205
Collections.addAll(shellArgs, args);
207206
}
@@ -234,13 +233,18 @@ public void ensureInitializationComplete(
234233
}
235234

236235
long initTimeMillis = SystemClock.uptimeMillis() - initStartTimestampMillis;
236+
237+
Bundle bundle = applicationInfo.metaData;
238+
boolean use_embedded_view = bundle.getBoolean("io.flutter.embedded_views_preview");
239+
237240
FlutterJNI.nativeInit(
238241
applicationContext,
239242
shellArgs.toArray(new String[0]),
240243
kernelPath,
241244
result.appStoragePath,
242245
result.engineCachesPath,
243-
initTimeMillis);
246+
initTimeMillis,
247+
use_embedded_view);
244248

245249
initialized = true;
246250
} catch (Exception e) {

0 commit comments

Comments
 (0)