@@ -23,34 +23,51 @@ namespace shell {
2323
2424AndroidShellHolder::AndroidShellHolder (
2525 blink::Settings settings,
26- fml::jni::JavaObjectWeakGlobalRef java_object)
26+ fml::jni::JavaObjectWeakGlobalRef java_object,
27+ bool is_background_view)
2728 : settings_(std::move(settings)), java_object_(java_object) {
2829 static size_t shell_count = 1 ;
2930 auto thread_label = std::to_string (shell_count++);
3031
3132 FXL_CHECK (pthread_key_create (&thread_destruct_key_, ThreadDestructCallback) ==
3233 0 );
3334
34- thread_host_ = {thread_label, ThreadHost::Type::UI | ThreadHost::Type::GPU |
35- ThreadHost::Type::IO};
35+ if (is_background_view) {
36+ thread_host_ = {thread_label, ThreadHost::Type::UI};
37+ } else {
38+ thread_host_ = {thread_label, ThreadHost::Type::UI | ThreadHost::Type::GPU |
39+ ThreadHost::Type::IO};
40+ }
3641
3742 // Detach from JNI when the UI and GPU threads exit.
3843 auto jni_exit_task ([key = thread_destruct_key_]() {
3944 FXL_CHECK (pthread_setspecific (key, reinterpret_cast <void *>(1 )) == 0 );
4045 });
4146 thread_host_.ui_thread ->GetTaskRunner ()->PostTask (jni_exit_task);
42- thread_host_.gpu_thread ->GetTaskRunner ()->PostTask (jni_exit_task);
47+ if (!is_background_view) {
48+ thread_host_.gpu_thread ->GetTaskRunner ()->PostTask (jni_exit_task);
49+ }
4350
4451 fml::WeakPtr<PlatformViewAndroid> weak_platform_view;
4552 Shell::CreateCallback<PlatformView> on_create_platform_view =
46- [java_object, &weak_platform_view](Shell& shell) {
47- auto platform_view_android = std::make_unique<PlatformViewAndroid>(
48- shell, // delegate
49- shell.GetTaskRunners (), // task runners
50- java_object, // java object handle for JNI interop
51- shell.GetSettings ()
52- .enable_software_rendering // use software rendering
53- );
53+ [is_background_view, java_object, &weak_platform_view](Shell& shell) {
54+ std::unique_ptr<PlatformViewAndroid> platform_view_android;
55+ if (is_background_view) {
56+ platform_view_android = std::make_unique<PlatformViewAndroid>(
57+ shell, // delegate
58+ shell.GetTaskRunners (), // task runners
59+ java_object // java object handle for JNI interop
60+ );
61+
62+ } else {
63+ platform_view_android = std::make_unique<PlatformViewAndroid>(
64+ shell, // delegate
65+ shell.GetTaskRunners (), // task runners
66+ java_object, // java object handle for JNI interop
67+ shell.GetSettings ()
68+ .enable_software_rendering // use software rendering
69+ );
70+ }
5471 weak_platform_view = platform_view_android->GetWeakPtr ();
5572 return platform_view_android;
5673 };
@@ -62,13 +79,27 @@ AndroidShellHolder::AndroidShellHolder(
6279 // The current thread will be used as the platform thread. Ensure that the
6380 // message loop is initialized.
6481 fml::MessageLoop::EnsureInitializedForCurrentThread ();
65-
82+ fxl::RefPtr<fml::TaskRunner> gpu_runner;
83+ fxl::RefPtr<fml::TaskRunner> ui_runner;
84+ fxl::RefPtr<fml::TaskRunner> io_runner;
85+ fxl::RefPtr<fml::TaskRunner> platform_runner =
86+ fml::MessageLoop::GetCurrent ().GetTaskRunner ();
87+ if (is_background_view) {
88+ auto single_task_runner = thread_host_.ui_thread ->GetTaskRunner ();
89+ gpu_runner = single_task_runner;
90+ ui_runner = single_task_runner;
91+ io_runner = single_task_runner;
92+ } else {
93+ gpu_runner = thread_host_.gpu_thread ->GetTaskRunner ();
94+ ui_runner = thread_host_.ui_thread ->GetTaskRunner ();
95+ io_runner = thread_host_.io_thread ->GetTaskRunner ();
96+ }
6697 blink::TaskRunners task_runners (
6798 thread_label, // label
68- fml::MessageLoop::GetCurrent (). GetTaskRunner (), // platform
69- thread_host_. gpu_thread -> GetTaskRunner (), // gpu
70- thread_host_. ui_thread -> GetTaskRunner (), // ui
71- thread_host_. io_thread -> GetTaskRunner () // io
99+ platform_runner, // platform
100+ gpu_runner, // gpu
101+ ui_runner, // ui
102+ io_runner // io
72103 );
73104
74105 shell_ =
@@ -131,10 +162,12 @@ void AndroidShellHolder::Launch(RunConfiguration config) {
131162 fxl::MakeCopyable ([engine = shell_->GetEngine (), //
132163 config = std::move (config) //
133164 ]() mutable {
134- if (engine) {
135- if (!engine->Run (std::move (config))) {
136- FXL_LOG (ERROR) << " Could not launch engine in configuration." ;
137- }
165+ FML_LOG (INFO) << " Attempting to launch engine configuration..." ;
166+ if (!engine || !engine->Run (std::move (config))) {
167+ FML_LOG (ERROR) << " Could not launch engine in configuration." ;
168+ } else {
169+ FML_LOG (INFO) << " Isolate for engine configuration successfully "
170+ " started and run." ;
138171 }
139172 }));
140173}
0 commit comments