@@ -23,34 +23,51 @@ namespace shell {
23
23
24
24
AndroidShellHolder::AndroidShellHolder (
25
25
blink::Settings settings,
26
- fml::jni::JavaObjectWeakGlobalRef java_object)
26
+ fml::jni::JavaObjectWeakGlobalRef java_object,
27
+ bool is_background_view)
27
28
: settings_(std::move(settings)), java_object_(java_object) {
28
29
static size_t shell_count = 1 ;
29
30
auto thread_label = std::to_string (shell_count++);
30
31
31
32
FML_CHECK (pthread_key_create (&thread_destruct_key_, ThreadDestructCallback) ==
32
33
0 );
33
34
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
+ }
36
41
37
42
// Detach from JNI when the UI and GPU threads exit.
38
43
auto jni_exit_task ([key = thread_destruct_key_]() {
39
44
FML_CHECK (pthread_setspecific (key, reinterpret_cast <void *>(1 )) == 0 );
40
45
});
41
46
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
+ }
43
50
44
51
fml::WeakPtr<PlatformViewAndroid> weak_platform_view;
45
52
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
+ }
54
71
weak_platform_view = platform_view_android->GetWeakPtr ();
55
72
return platform_view_android;
56
73
};
@@ -62,13 +79,26 @@ AndroidShellHolder::AndroidShellHolder(
62
79
// The current thread will be used as the platform thread. Ensure that the
63
80
// message loop is initialized.
64
81
fml::MessageLoop::EnsureInitializedForCurrentThread ();
65
-
66
- blink::TaskRunners task_runners (
67
- 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
82
+ fml::RefPtr<fml::TaskRunner> gpu_runner;
83
+ fml::RefPtr<fml::TaskRunner> ui_runner;
84
+ fml::RefPtr<fml::TaskRunner> io_runner;
85
+ fml::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
+ }
97
+ blink::TaskRunners task_runners (thread_label, // label
98
+ platform_runner, // platform
99
+ gpu_runner, // gpu
100
+ ui_runner, // ui
101
+ io_runner // io
72
102
);
73
103
74
104
shell_ =
@@ -131,10 +161,12 @@ void AndroidShellHolder::Launch(RunConfiguration config) {
131
161
fml::MakeCopyable ([engine = shell_->GetEngine (), //
132
162
config = std::move (config) //
133
163
]() mutable {
134
- if (engine) {
135
- if (!engine->Run (std::move (config))) {
136
- FML_LOG (ERROR) << " Could not launch engine in configuration." ;
137
- }
164
+ FML_LOG (INFO) << " Attempting to launch engine configuration..." ;
165
+ if (!engine || !engine->Run (std::move (config))) {
166
+ FML_LOG (ERROR) << " Could not launch engine in configuration." ;
167
+ } else {
168
+ FML_LOG (INFO) << " Isolate for engine configuration successfully "
169
+ " started and run." ;
138
170
}
139
171
}));
140
172
}
0 commit comments