Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert migration to FML messageloops on Fuchsia #15903

Merged
merged 1 commit into from
Jan 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,8 @@ FILE: ../../../flutter/shell/platform/fuchsia/flutter/kernel/extract_far.dart
FILE: ../../../flutter/shell/platform/fuchsia/flutter/kernel/framework_shim.dart
FILE: ../../../flutter/shell/platform/fuchsia/flutter/kernel/libraries.json
FILE: ../../../flutter/shell/platform/fuchsia/flutter/logging.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/loop.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/loop.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/main.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/meta/aot_product_runtime
FILE: ../../../flutter/shell/platform/fuchsia/flutter/meta/aot_runtime
Expand All @@ -1042,6 +1044,12 @@ FILE: ../../../flutter/shell/platform/fuchsia/flutter/session_connection.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/session_connection.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/surface.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/surface.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/task_observers.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/task_observers.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/task_runner_adapter.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/task_runner_adapter.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/thread.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/thread.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/unique_fdio_ns.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/vsync_recorder.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/vsync_recorder.h
Expand Down
4 changes: 0 additions & 4 deletions fml/thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

#if defined(OS_WIN)
#include <windows.h>
#elif defined(OS_FUCHSIA)
#include <lib/zx/thread.h>
#else
#include <pthread.h>
#endif
Expand Down Expand Up @@ -87,8 +85,6 @@ void Thread::SetCurrentThreadName(const std::string& name) {
reinterpret_cast<DWORD_PTR*>(&info));
} __except (EXCEPTION_CONTINUE_EXECUTION) {
}
#elif OS_FUCHSIA
zx::thread::self()->set_property(ZX_PROP_NAME, name.c_str(), name.size());
#else
FML_DLOG(INFO) << "Could not set the thread name to '" << name
<< "' on this platform.";
Expand Down
8 changes: 8 additions & 0 deletions shell/platform/fuchsia/flutter/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ executable("flutter_runner_unittests") {
"fuchsia_intl.h",
"fuchsia_intl_unittest.cc",
"logging.h",
"loop.cc",
"loop.h",
"platform_view.cc",
"platform_view.h",
"platform_view_unittest.cc",
Expand All @@ -311,6 +313,12 @@ executable("flutter_runner_unittests") {
"runner_unittest.cc",
"surface.cc",
"surface.h",
"task_observers.cc",
"task_observers.h",
"task_runner_adapter.cc",
"task_runner_adapter.h",
"thread.cc",
"thread.h",
"vsync_recorder.cc",
"vsync_recorder.h",
"vsync_waiter.cc",
Expand Down
25 changes: 14 additions & 11 deletions shell/platform/fuchsia/flutter/component.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#define FML_USED_ON_EMBEDDER

#include "component.h"

#include <dlfcn.h>
Expand Down Expand Up @@ -38,6 +36,10 @@
#include "runtime/dart/utils/tempfs.h"
#include "runtime/dart/utils/vmo.h"

#include "task_observers.h"
#include "task_runner_adapter.h"
#include "thread.h"

// TODO(kaushikiska): Use these constants from ::llcpp::fuchsia::io
// Can read from target object.
constexpr uint32_t OPEN_RIGHT_READABLE = 1u;
Expand All @@ -57,11 +59,11 @@ ActiveApplication Application::Create(
fuchsia::sys::StartupInfo startup_info,
std::shared_ptr<sys::ServiceDirectory> runner_incoming_services,
fidl::InterfaceRequest<fuchsia::sys::ComponentController> controller) {
std::unique_ptr<fml::Thread> thread = std::make_unique<fml::Thread>();
std::unique_ptr<Thread> thread = std::make_unique<Thread>();
std::unique_ptr<Application> application;

fml::AutoResetWaitableEvent latch;
fml::TaskRunner::RunNowOrPostTask(thread->GetTaskRunner(), [&]() mutable {
async::PostTask(thread->dispatcher(), [&]() mutable {
application.reset(
new Application(std::move(termination_callback), std::move(package),
std::move(startup_info), runner_incoming_services,
Expand Down Expand Up @@ -345,12 +347,12 @@ Application::Application(
settings_.disable_dart_asserts = true;
#endif

settings_.task_observer_add = [](intptr_t key, fml::closure callback) {
fml::MessageLoop::GetCurrent().AddTaskObserver(key, std::move(callback));
};
settings_.task_observer_remove = [](intptr_t key) {
fml::MessageLoop::GetCurrent().RemoveTaskObserver(key);
};
settings_.task_observer_add =
std::bind(&CurrentMessageLoopAddAfterTaskObserver, std::placeholders::_1,
std::placeholders::_2);

settings_.task_observer_remove = std::bind(
&CurrentMessageLoopRemoveAfterTaskObserver, std::placeholders::_1);

// TODO(FL-117): Re-enable causal async stack traces when this issue is
// addressed.
Expand All @@ -377,7 +379,8 @@ Application::Application(
#endif // defined(__aarch64__)

auto weak_application = weak_factory_.GetWeakPtr();
auto platform_task_runner = fml::MessageLoop::GetCurrent().GetTaskRunner();
auto platform_task_runner =
CreateFMLTaskRunner(async_get_default_dispatcher());
const std::string component_url = package.resolved_url;
settings_.unhandled_exception_callback = [weak_application,
platform_task_runner,
Expand Down
4 changes: 2 additions & 2 deletions shell/platform/fuchsia/flutter/component.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@
#include "engine.h"
#include "flutter/common/settings.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/thread.h"

#include "thread.h"
#include "unique_fdio_ns.h"

namespace flutter_runner {

class Application;

struct ActiveApplication {
std::unique_ptr<fml::Thread> thread;
std::unique_ptr<Thread> thread;
std::unique_ptr<Application> application;

ActiveApplication& operator=(ActiveApplication&& other) noexcept {
Expand Down
32 changes: 19 additions & 13 deletions shell/platform/fuchsia/flutter/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#define FML_USED_ON_EMBEDDER

#include "engine.h"

#include <lib/async/cpp/task.h>
Expand All @@ -20,7 +18,9 @@
#include "fuchsia_intl.h"
#include "platform_view.h"
#include "runtime/dart/utils/files.h"
#include "task_runner_adapter.h"
#include "third_party/skia/include/ports/SkFontMgr_fuchsia.h"
#include "thread.h"

namespace flutter_runner {

Expand Down Expand Up @@ -60,17 +60,19 @@ Engine::Engine(Delegate& delegate,
fidl::InterfaceRequest<fuchsia::io::Directory> directory_request)
: delegate_(delegate),
thread_label_(std::move(thread_label)),
thread_host_(thread_label_ + ".",
flutter::ThreadHost::Type::IO |
flutter::ThreadHost::Type::UI |
flutter::ThreadHost::Type::GPU),
settings_(std::move(settings)),
weak_factory_(this) {
if (zx::event::create(0, &vsync_event_) != ZX_OK) {
FML_DLOG(ERROR) << "Could not create the vsync event.";
return;
}

// Launch the threads that will be used to run the shell. These threads will
// be joined in the destructor.
for (auto& thread : threads_) {
thread.reset(new Thread());
}

// Set up the session connection.
auto scenic = svc->Connect<fuchsia::ui::scenic::Scenic>();
fidl::InterfaceHandle<fuchsia::ui::scenic::Session> session;
Expand Down Expand Up @@ -165,14 +167,12 @@ Engine::Engine(Delegate& delegate,

// Get the task runners from the managed threads. The current thread will be
// used as the "platform" thread.
fml::MessageLoop::EnsureInitializedForCurrentThread();

const flutter::TaskRunners task_runners(
thread_label_, // Dart thread labels
fml::MessageLoop::GetCurrent().GetTaskRunner(), // platform
thread_host_.gpu_thread->GetTaskRunner(), // gpu
thread_host_.ui_thread->GetTaskRunner(), // ui
thread_host_.io_thread->GetTaskRunner() // io
thread_label_, // Dart thread labels
CreateFMLTaskRunner(async_get_default_dispatcher()), // platform
CreateFMLTaskRunner(threads_[0]->dispatcher()), // gpu
CreateFMLTaskRunner(threads_[1]->dispatcher()), // ui
CreateFMLTaskRunner(threads_[2]->dispatcher()) // io
);

// Setup the callback that will instantiate the rasterizer.
Expand Down Expand Up @@ -353,6 +353,12 @@ Engine::Engine(Delegate& delegate,

Engine::~Engine() {
shell_.reset();
for (const auto& thread : threads_) {
thread->Quit();
}
for (const auto& thread : threads_) {
thread->Join();
}
}

std::pair<bool, uint32_t> Engine::GetEngineReturnCode() const {
Expand Down
4 changes: 2 additions & 2 deletions shell/platform/fuchsia/flutter/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

#include "flutter/fml/macros.h"
#include "flutter/shell/common/shell.h"
#include "flutter/shell/common/thread_host.h"
#include "isolate_configurator.h"
#include "thread.h"

namespace flutter_runner {

Expand Down Expand Up @@ -53,8 +53,8 @@ class Engine final {
private:
Delegate& delegate_;
const std::string thread_label_;
flutter::ThreadHost thread_host_;
flutter::Settings settings_;
std::array<std::unique_ptr<Thread>, 3> threads_;
std::unique_ptr<IsolateConfigurator> isolate_configurator_;
std::unique_ptr<flutter::Shell> shell_;
zx::event vsync_event_;
Expand Down
8 changes: 8 additions & 0 deletions shell/platform/fuchsia/flutter/engine_flutter_runner.gni
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ template("flutter_runner") {
"isolate_configurator.cc",
"isolate_configurator.h",
"logging.h",
"loop.cc",
"loop.h",
"main.cc",
"platform_view.cc",
"platform_view.h",
Expand All @@ -64,6 +66,12 @@ template("flutter_runner") {
"session_connection.h",
"surface.cc",
"surface.h",
"task_observers.cc",
"task_observers.h",
"task_runner_adapter.cc",
"task_runner_adapter.h",
"thread.cc",
"thread.h",
"unique_fdio_ns.h",
"vsync_recorder.cc",
"vsync_recorder.h",
Expand Down
1 change: 1 addition & 0 deletions shell/platform/fuchsia/flutter/fuchsia_intl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <string>
#include <vector>

#include "loop.h"
#include "rapidjson/document.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/writer.h"
Expand Down
47 changes: 47 additions & 0 deletions shell/platform/fuchsia/flutter/loop.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "loop.h"

#include <lib/async-loop/loop.h>
#include <lib/async/default.h>

#include "task_observers.h"

namespace flutter_runner {

namespace {

static void LoopEpilogue(async_loop_t*, void*) {
ExecuteAfterTaskObservers();
}

constexpr async_loop_config_t kAttachedLoopConfig = {
.default_accessors =
{
.getter = async_get_default_dispatcher,
.setter = async_set_default_dispatcher,
},
.make_default_for_current_thread = true,
.epilogue = &LoopEpilogue,
};

constexpr async_loop_config_t kDetachedLoopConfig = {
.default_accessors =
{
.getter = async_get_default_dispatcher,
.setter = async_set_default_dispatcher,
},
.make_default_for_current_thread = false,
.epilogue = &LoopEpilogue,
};

} // namespace

async::Loop* MakeObservableLoop(bool attachToThread) {
return new async::Loop(
&(attachToThread ? kAttachedLoopConfig : kDetachedLoopConfig));
}

} // namespace flutter_runner
17 changes: 17 additions & 0 deletions shell/platform/fuchsia/flutter/loop.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_LOOP_H_
#define FLUTTER_SHELL_PLATFORM_FUCHSIA_LOOP_H_

#include <lib/async-loop/cpp/loop.h>

namespace flutter_runner {

// Creates a loop which allows task observers to be attached to it.
async::Loop* MakeObservableLoop(bool attachToThread);

} // namespace flutter_runner

#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_LOOP_H_
14 changes: 5 additions & 9 deletions shell/platform/fuchsia/flutter/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,36 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#define FML_USED_ON_EMBEDDER

#include <lib/async-loop/cpp/loop.h>
#include <lib/async-loop/default.h>
#include <lib/trace-provider/provider.h>
#include <lib/trace/event.h>

#include <cstdlib>

#include "loop.h"
#include "runner.h"
#include "runtime/dart/utils/tempfs.h"

int main(int argc, char const* argv[]) {
fml::MessageLoop::EnsureInitializedForCurrentThread();
auto& message_loop = fml::MessageLoop::GetCurrent();
std::unique_ptr<async::Loop> loop(flutter_runner::MakeObservableLoop(true));

std::unique_ptr<trace::TraceProviderWithFdio> provider;
{
TRACE_DURATION("flutter", "CreateTraceProvider");
bool already_started;
// Use CreateSynchronously to prevent loss of early events.
trace::TraceProviderWithFdio::CreateSynchronously(
async_get_default_dispatcher(), "flutter_runner", &provider,
&already_started);
loop->dispatcher(), "flutter_runner", &provider, &already_started);
}

// Set up the process-wide /tmp memfs.
dart_utils::RunnerTemp runner_temp;

FML_DLOG(INFO) << "Flutter application services initialized.";

flutter_runner::Runner runner(message_loop);
flutter_runner::Runner runner(loop.get());

message_loop.Run();
loop->Run();

FML_DLOG(INFO) << "Flutter application services terminated.";

Expand Down
Loading