-
Notifications
You must be signed in to change notification settings - Fork 6k
Updated background execution implementation for Android #5640
Changes from 8 commits
1be3595
ca823d9
1e36a0d
67dc24a
2dab42a
f02d63a
8cc0880
fcc1c03
2449c41
8868cdf
109b34e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,34 +23,51 @@ namespace shell { | |
|
|
||
| AndroidShellHolder::AndroidShellHolder( | ||
| blink::Settings settings, | ||
| fml::jni::JavaObjectWeakGlobalRef java_object) | ||
| fml::jni::JavaObjectWeakGlobalRef java_object, | ||
| bool is_background_view) | ||
| : settings_(std::move(settings)), java_object_(java_object) { | ||
| static size_t shell_count = 1; | ||
| auto thread_label = std::to_string(shell_count++); | ||
|
|
||
| FXL_CHECK(pthread_key_create(&thread_destruct_key_, ThreadDestructCallback) == | ||
| 0); | ||
|
|
||
| thread_host_ = {thread_label, ThreadHost::Type::UI | ThreadHost::Type::GPU | | ||
| ThreadHost::Type::IO}; | ||
| if (is_background_view) { | ||
| thread_host_ = {thread_label, ThreadHost::Type::UI}; | ||
| } else { | ||
| thread_host_ = {thread_label, ThreadHost::Type::UI | ThreadHost::Type::GPU | | ||
| ThreadHost::Type::IO}; | ||
| } | ||
|
|
||
| // Detach from JNI when the UI and GPU threads exit. | ||
| auto jni_exit_task([key = thread_destruct_key_]() { | ||
| FXL_CHECK(pthread_setspecific(key, reinterpret_cast<void*>(1)) == 0); | ||
| }); | ||
| thread_host_.ui_thread->GetTaskRunner()->PostTask(jni_exit_task); | ||
| thread_host_.gpu_thread->GetTaskRunner()->PostTask(jni_exit_task); | ||
| if (!is_background_view) { | ||
| thread_host_.gpu_thread->GetTaskRunner()->PostTask(jni_exit_task); | ||
| } | ||
|
|
||
| fml::WeakPtr<PlatformViewAndroid> weak_platform_view; | ||
| Shell::CreateCallback<PlatformView> on_create_platform_view = | ||
| [java_object, &weak_platform_view](Shell& shell) { | ||
| auto platform_view_android = std::make_unique<PlatformViewAndroid>( | ||
| shell, // delegate | ||
| shell.GetTaskRunners(), // task runners | ||
| java_object, // java object handle for JNI interop | ||
| shell.GetSettings() | ||
| .enable_software_rendering // use software rendering | ||
| ); | ||
| [is_background_view, java_object, &weak_platform_view](Shell& shell) { | ||
| std::unique_ptr<PlatformViewAndroid> platform_view_android; | ||
| if (is_background_view) { | ||
| platform_view_android = std::make_unique<PlatformViewAndroid>( | ||
| shell, // delegate | ||
| shell.GetTaskRunners(), // task runners | ||
| java_object // java object handle for JNI interop | ||
| ); | ||
|
|
||
| } else { | ||
| platform_view_android = std::make_unique<PlatformViewAndroid>( | ||
| shell, // delegate | ||
| shell.GetTaskRunners(), // task runners | ||
| java_object, // java object handle for JNI interop | ||
| shell.GetSettings() | ||
| .enable_software_rendering // use software rendering | ||
| ); | ||
| } | ||
| weak_platform_view = platform_view_android->GetWeakPtr(); | ||
| return platform_view_android; | ||
| }; | ||
|
|
@@ -62,13 +79,25 @@ AndroidShellHolder::AndroidShellHolder( | |
| // The current thread will be used as the platform thread. Ensure that the | ||
| // message loop is initialized. | ||
| fml::MessageLoop::EnsureInitializedForCurrentThread(); | ||
|
|
||
| fxl::RefPtr<fml::TaskRunner> gpu_runner; | ||
| fxl::RefPtr<fml::TaskRunner> ui_runner; | ||
| fxl::RefPtr<fml::TaskRunner> io_runner; | ||
| if (!is_background_view) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think positive! Change to if (is_background_view) and swap if and else.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| gpu_runner = thread_host_.gpu_thread->GetTaskRunner(); | ||
| ui_runner = thread_host_.ui_thread->GetTaskRunner(); | ||
| io_runner = thread_host_.io_thread->GetTaskRunner(); | ||
| } else { | ||
| auto single_task_runner = thread_host_.ui_thread->GetTaskRunner(); | ||
| gpu_runner = single_task_runner; | ||
| ui_runner = single_task_runner; | ||
| io_runner = single_task_runner; | ||
| } | ||
| blink::TaskRunners task_runners( | ||
| thread_label, // label | ||
| fml::MessageLoop::GetCurrent().GetTaskRunner(), // platform | ||
| thread_host_.gpu_thread->GetTaskRunner(), // gpu | ||
| thread_host_.ui_thread->GetTaskRunner(), // ui | ||
| thread_host_.io_thread->GetTaskRunner() // io | ||
| gpu_runner, // gpu | ||
| ui_runner, // ui | ||
| io_runner // io | ||
| ); | ||
|
|
||
| shell_ = | ||
|
|
@@ -129,13 +158,19 @@ void AndroidShellHolder::Launch(RunConfiguration config) { | |
|
|
||
| shell_->GetTaskRunners().GetUITaskRunner()->PostTask( | ||
| fxl::MakeCopyable([engine = shell_->GetEngine(), // | ||
| config = std::move(config) // | ||
| config = std::move(config), // | ||
| view = platform_view_.get() // | ||
| ]() mutable { | ||
| if (engine) { | ||
| if (!engine->Run(std::move(config))) { | ||
| FXL_LOG(ERROR) << "Could not launch engine in configuration."; | ||
| } | ||
| bool success = false; | ||
| FXL_LOG(INFO) << "Attempting to launch engine configuration..."; | ||
| if (!engine || !engine->Run(std::move(config))) { | ||
| FXL_LOG(ERROR) << "Could not launch engine in configuration."; | ||
| } else { | ||
| FXL_LOG(INFO) << "Isolate for engine configuration successfully " | ||
| "started and run."; | ||
| success = true; | ||
| } | ||
| view->InvokeOnStartedCallback(success); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Attach a closure to the Be careful that the callback in the settings object is fire on the UI thread, you might have to post a task back to the platform thread to fire a message back to the platform.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On second thought, I don't think this is particularly useful if we have no way of notifying the plugin that we failed to start. I've gone ahead and removed this. |
||
| })); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Copyright 2018 The Chromium Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| package io.flutter.view; | ||
|
|
||
| /** | ||
| * A class representing information for a callback registered using | ||
| * `PluginUtilities` from `dart:ui`. | ||
| */ | ||
| public final class FlutterCallbackInformation { | ||
| final public String callbackName; | ||
| final public String callbackClassName; | ||
| final public String callbackLibraryPath; | ||
|
|
||
| /** | ||
| * Get callback information for a given handle. | ||
| * @param handle the handle for the callback, generated by | ||
| * `PluginUtilities.getCallbackHandle` in `dart:ui`. | ||
| * @return an instance of FlutterCallbackInformation for the provided handle. | ||
| */ | ||
| public static FlutterCallbackInformation lookupCallbackInformation(long handle) { | ||
| return nativeLookupCallbackInformation(handle); | ||
| } | ||
|
|
||
| private FlutterCallbackInformation(String callbackName, | ||
| String callbackClassName, String callbackLibraryPath) { | ||
| this.callbackName = callbackName; | ||
| this.callbackClassName = callbackClassName; | ||
| this.callbackLibraryPath = callbackLibraryPath; | ||
| } | ||
|
|
||
| private static native FlutterCallbackInformation nativeLookupCallbackInformation(long handle); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Copyright 2018 The Chromium Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| package io.flutter.view; | ||
|
|
||
| /** | ||
| * An interface for a callback which is invoked once a new isolate has been | ||
| * started by the engine. | ||
| */ | ||
| public interface FlutterIsolateStartedEvent { | ||
| public void onStarted(boolean success); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does a headless shell need to be designated as a background view?
Would it be sufficient to create a standard shell and just not attach a surface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This flag determines whether or not a surface is created for the platform view and what number of task runners are created (see here)