From ced9a91c3ac3e66cfc7852d550cb3d76650bbd39 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Mon, 7 Nov 2016 15:51:42 -0800 Subject: [PATCH] Switch Flutter to //lib/fidl (#3206) --- build/package.py | 2 +- content_handler/BUILD.gn | 27 ++--- content_handler/app.cc | 87 +++++++++++++++ content_handler/app.h | 51 +++++++++ .../application_controller_impl.cc | 81 ++++++++++++++ content_handler/application_controller_impl.h | 67 +++++++++++ content_handler/application_impl.cc | 85 -------------- content_handler/application_impl.h | 70 ------------ content_handler/content_handler_impl.cc | 25 ----- content_handler/content_handler_impl.h | 32 ------ content_handler/main.cc | 104 +----------------- content_handler/rasterizer.cc | 18 +-- content_handler/rasterizer.h | 8 +- content_handler/runtime_holder.cc | 41 ++++--- content_handler/runtime_holder.h | 23 ++-- content_handler/skia_surface_holder.cc | 32 ++++-- content_handler/skia_surface_holder.h | 12 +- flow/BUILD.gn | 4 +- flow/layers/child_scene_layer.cc | 12 +- flow/layers/child_scene_layer.h | 2 +- glue/BUILD.gn | 15 --- glue/drain_data_pipe_job.h | 35 ------ glue/drain_data_pipe_job_fuchsia.cc | 45 -------- glue/thread.h | 34 ------ glue/thread_base.cc | 29 ----- glue/thread_fuchsia.cc | 27 ----- glue/trace_event.h | 8 +- sky/engine/platform/BUILD.gn | 5 +- .../fonts/fuchsia/FontCacheFuchsia.cpp | 45 ++++---- .../platform/fonts/fuchsia/FontCacheFuchsia.h | 4 +- sky/engine/wtf/BUILD.gn | 5 - 31 files changed, 416 insertions(+), 619 deletions(-) create mode 100644 content_handler/app.cc create mode 100644 content_handler/app.h create mode 100644 content_handler/application_controller_impl.cc create mode 100644 content_handler/application_controller_impl.h delete mode 100644 content_handler/application_impl.cc delete mode 100644 content_handler/application_impl.h delete mode 100644 content_handler/content_handler_impl.cc delete mode 100644 content_handler/content_handler_impl.h delete mode 100644 glue/drain_data_pipe_job.h delete mode 100644 glue/drain_data_pipe_job_fuchsia.cc delete mode 100644 glue/thread.h delete mode 100644 glue/thread_base.cc delete mode 100644 glue/thread_fuchsia.cc diff --git a/build/package.py b/build/package.py index 6b8fc2d0328..76603ea3870 100755 --- a/build/package.py +++ b/build/package.py @@ -47,7 +47,7 @@ def main(): '--packages=%s' % args.packages, '--snapshot=%s' % args.snapshot, '--output-file=%s' % args.output_file, - '--header=#!mojo mojo:flutter_content_handler', + '--header=#!fuchsia file:///system/apps/flutter_runner', ], env=env, cwd=args.app_dir) return result diff --git a/content_handler/BUILD.gn b/content_handler/BUILD.gn index ef46ee35c8e..c85bf352589 100644 --- a/content_handler/BUILD.gn +++ b/content_handler/BUILD.gn @@ -5,13 +5,13 @@ assert(is_fuchsia) executable("content_handler") { - output_name = "flutter_content_handler" + output_name = "flutter_runner" sources = [ - "application_impl.cc", - "application_impl.h", - "content_handler_impl.cc", - "content_handler_impl.h", + "app.cc", + "app.h", + "application_controller_impl.cc", + "application_controller_impl.h", "main.cc", "rasterizer.cc", "rasterizer.h", @@ -22,11 +22,12 @@ executable("content_handler") { ] deps = [ - "//apps/mozart/services/composition/interfaces", - "//apps/mozart/services/input/interfaces", - "//apps/mozart/services/views/interfaces", - "//dart/runtime:libdart", + "//apps/modular/lib/app", + "//apps/mozart/services/composition", + "//apps/mozart/services/input", + "//apps/mozart/services/views", "//dart/runtime/vm:libdart_platform", + "//dart/runtime:libdart", "//flutter/assets", "//flutter/common", "//flutter/flow", @@ -36,15 +37,7 @@ executable("content_handler") { "//flutter/sky/engine/platform", "//lib/ftl", "//lib/mtl", - "//lib/trace_event", "//lib/zip", - "//mojo/public/cpp/application", - "//mojo/public/cpp/bindings", - "//mojo/public/cpp/system", - "//mojo/public/interfaces/application", - "//mojo/services/content_handler/interfaces", - "//mojo/services/framebuffer/interfaces", - "//mojo/system", "//third_party/skia", # TODO(abarth): We shouldn't need to depend on libdart_builtin but we fail diff --git a/content_handler/app.cc b/content_handler/app.cc new file mode 100644 index 00000000000..ba26ba3a1be --- /dev/null +++ b/content_handler/app.cc @@ -0,0 +1,87 @@ +// Copyright 2016 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. + +#include "flutter/content_handler/app.h" + +#include +#include + +#include "flutter/common/settings.h" +#include "flutter/common/threads.h" +#include "flutter/runtime/runtime_init.h" +#include "flutter/sky/engine/platform/fonts/fuchsia/FontCacheFuchsia.h" +#include "lib/ftl/macros.h" +#include "lib/ftl/tasks/task_runner.h" +#include "lib/mtl/tasks/message_loop.h" +#include "lib/mtl/threading/create_thread.h" + +namespace flutter_runner { +namespace { + +void QuitMessageLoop() { + mtl::MessageLoop::GetCurrent()->QuitNow(); +} + +} // namespace + +App::App() { + context_ = modular::ApplicationContext::CreateFromStartupInfo(); + + // TODO(abarth): Initialize tracing. + + ftl::RefPtr gpu_task_runner; + gpu_thread_ = mtl::CreateThread(&gpu_task_runner); + + ftl::RefPtr ui_task_runner( + mtl::MessageLoop::GetCurrent()->task_runner()); + + ftl::RefPtr io_task_runner; + io_thread_ = mtl::CreateThread(&io_task_runner); + + // Notice that the Platform and UI threads are actually the same. + blink::Threads::Set(blink::Threads(ui_task_runner, gpu_task_runner, + ui_task_runner, io_task_runner)); + blink::Settings::Set(blink::Settings()); + blink::InitRuntime(); + + blink::SetFontProvider( + context_->ConnectToEnvironmentService()); + + context_->outgoing_services()->AddService( + [this](fidl::InterfaceRequest request) { + runner_bindings_.AddBinding(this, std::move(request)); + }); +} + +App::~App() { + StopThreads(); +} + +void App::StartApplication( + modular::ApplicationPackagePtr application, + modular::ApplicationStartupInfoPtr startup_info, + fidl::InterfaceRequest controller) { + std::unique_ptr impl = + std::make_unique(this, std::move(application), + std::move(startup_info), + std::move(controller)); + ApplicationControllerImpl* key = impl.get(); + controllers_.emplace(key, std::move(impl)); +} + +void App::Destroy(ApplicationControllerImpl* controller) { + auto it = controllers_.find(controller); + if (it == controllers_.end()) + return; + controllers_.erase(it); +} + +void App::StopThreads() { + blink::Threads::Gpu()->PostTask(QuitMessageLoop); + blink::Threads::IO()->PostTask(QuitMessageLoop); + gpu_thread_.join(); + io_thread_.join(); +} + +} // namespace flutter_runner diff --git a/content_handler/app.h b/content_handler/app.h new file mode 100644 index 00000000000..90e1751cf5d --- /dev/null +++ b/content_handler/app.h @@ -0,0 +1,51 @@ +// Copyright 2016 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. + +#ifndef FLUTTER_CONTENT_HANDLER_APP_H_ +#define FLUTTER_CONTENT_HANDLER_APP_H_ + +#include +#include +#include + +#include "apps/modular/lib/app/application_context.h" +#include "apps/modular/services/application/application_runner.fidl.h" +#include "flutter/content_handler/application_controller_impl.h" +#include "lib/ftl/macros.h" + +namespace flutter_runner { + +class App : public modular::ApplicationRunner { + public: + App(); + ~App(); + + // |modular::ApplicationRunner| implementation: + + void StartApplication(modular::ApplicationPackagePtr application, + modular::ApplicationStartupInfoPtr startup_info, + fidl::InterfaceRequest + controller) override; + + void Destroy(ApplicationControllerImpl* controller); + + private: + void StopThreads(); + + std::unique_ptr context_; + std::thread gpu_thread_; + std::thread io_thread_; + + fidl::BindingSet runner_bindings_; + + std::unordered_map> + controllers_; + + FTL_DISALLOW_COPY_AND_ASSIGN(App); +}; + +} // namespace flutter_runner + +#endif // FLUTTER_CONTENT_HANDLER_APP_H_ diff --git a/content_handler/application_controller_impl.cc b/content_handler/application_controller_impl.cc new file mode 100644 index 00000000000..3c1deabb8b9 --- /dev/null +++ b/content_handler/application_controller_impl.cc @@ -0,0 +1,81 @@ +// Copyright 2016 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. + +#include "flutter/content_handler/application_controller_impl.h" + +#include + +#include "apps/modular/lib/app/connect.h" +#include "flutter/content_handler/app.h" +#include "flutter/content_handler/runtime_holder.h" +#include "lib/ftl/logging.h" +#include "lib/mtl/vmo/vector.h" + +namespace flutter_runner { + +ApplicationControllerImpl::ApplicationControllerImpl( + App* app, + modular::ApplicationPackagePtr application, + modular::ApplicationStartupInfoPtr startup_info, + fidl::InterfaceRequest controller) + : app_(app), binding_(this) { + if (controller.is_pending()) { + binding_.Bind(std::move(controller)); + binding_.set_connection_error_handler([this] { + app_->Destroy(this); + // |this| has been deleted at this point. + }); + } + + std::vector bundle; + if (!mtl::VectorFromVmo(std::move(application->data), &bundle)) { + FTL_LOG(ERROR) << "Failed to receive bundle."; + return; + } + + // TODO(abarth): The Dart code should end up with outgoing_services. + if (startup_info->outgoing_services.is_pending()) { + service_provider_bindings_.AddBinding( + this, std::move(startup_info->outgoing_services)); + } + + url_ = startup_info->url; + runtime_holder_.reset(new RuntimeHolder()); + + // TODO(abarth): The Dart code should end up with environment_services. + runtime_holder_->Init(modular::ServiceProviderPtr::Create( + std::move(startup_info->environment_services)), + std::move(bundle)); +} + +ApplicationControllerImpl::~ApplicationControllerImpl() = default; + +void ApplicationControllerImpl::Kill(const KillCallback& callback) { + runtime_holder_.reset(); + app_->Destroy(this); + // |this| has been deleted at this point. +} + +void ApplicationControllerImpl::Detach() { + binding_.set_connection_error_handler(ftl::Closure()); +} + +void ApplicationControllerImpl::ConnectToService( + const fidl::String& service_name, + mx::channel client_handle) { + if (service_name == mozart::ViewProvider::Name_) { + view_provider_bindings_.AddBinding( + this, + fidl::InterfaceRequest(std::move(client_handle))); + } +} + +void ApplicationControllerImpl::CreateView( + fidl::InterfaceRequest view_owner_request, + fidl::InterfaceRequest services) { + runtime_holder_->CreateView(url_, std::move(view_owner_request), + std::move(services)); +} + +} // namespace flutter_runner diff --git a/content_handler/application_controller_impl.h b/content_handler/application_controller_impl.h new file mode 100644 index 00000000000..3dd3e35e74b --- /dev/null +++ b/content_handler/application_controller_impl.h @@ -0,0 +1,67 @@ +// Copyright 2016 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. + +#ifndef FLUTTER_CONTENT_HANDLER_APPLICATION_IMPL_H_ +#define FLUTTER_CONTENT_HANDLER_APPLICATION_IMPL_H_ + +#include + +#include "apps/modular/services/application/application_controller.fidl.h" +#include "apps/modular/services/application/application_runner.fidl.h" +#include "apps/modular/services/application/service_provider.fidl.h" +#include "apps/mozart/services/views/view_provider.fidl.h" +#include "lib/fidl/cpp/bindings/binding.h" +#include "lib/fidl/cpp/bindings/binding_set.h" +#include "lib/ftl/macros.h" + +namespace flutter_runner { +class App; +class RuntimeHolder; + +class ApplicationControllerImpl : public modular::ApplicationController, + public modular::ServiceProvider, + public mozart::ViewProvider { + public: + ApplicationControllerImpl( + App* app, + modular::ApplicationPackagePtr application, + modular::ApplicationStartupInfoPtr startup_info, + fidl::InterfaceRequest controller); + + ~ApplicationControllerImpl() override; + + // |modular::ApplicationController| implementation + + void Kill(const KillCallback& callback) override; + void Detach() override; + + // |modular::ServiceProvider| implementation + + void ConnectToService(const fidl::String& service_name, + mx::channel client_handle) override; + + // |mozart::ViewProvider| implementation + + void CreateView( + fidl::InterfaceRequest view_owner_request, + fidl::InterfaceRequest services) override; + + private: + void StartRuntimeIfReady(); + + App* app_; + fidl::Binding binding_; + + fidl::BindingSet service_provider_bindings_; + fidl::BindingSet view_provider_bindings_; + + std::string url_; + std::unique_ptr runtime_holder_; + + FTL_DISALLOW_COPY_AND_ASSIGN(ApplicationControllerImpl); +}; + +} // namespace flutter_runner + +#endif // FLUTTER_CONTENT_HANDLER_APPLICATION_IMPL_H_ diff --git a/content_handler/application_impl.cc b/content_handler/application_impl.cc deleted file mode 100644 index 1c15fae33cc..00000000000 --- a/content_handler/application_impl.cc +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2016 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. - -#include "flutter/content_handler/application_impl.h" - -#include - -#include "flutter/content_handler/runtime_holder.h" -#include "lib/ftl/logging.h" -#include "lib/mtl/data_pipe/vector.h" -#include "lib/mtl/shared_buffer/vector.h" -#include "lib/zip/unzipper.h" -#include "mojo/public/cpp/application/connect.h" - -namespace flutter_content_handler { - -ApplicationImpl::ApplicationImpl( - mojo::InterfaceRequest application, - mojo::URLResponsePtr response) - : binding_(this, std::move(application)) { - if (response->body->is_stream()) { - // TODO(abarth): Currently we block the UI thread to drain the response body, - // but we should do that work asynchronously instead. However, there when I - // tried draining the data pipe asynchronously, the drain didn't complete. - // We'll need to investigate why in more detail. - bool result = mtl::BlockingCopyToVector(std::move(response->body->get_stream()), &bundle_); - if (!result) { - FTL_LOG(ERROR) << "Failed to receive bundle."; - return; - } - } else if (response->body->is_buffer()) { - bool result = mtl::VectorFromSharedBuffer(std::move(response->body->get_buffer()), &bundle_); - if (!result) { - FTL_LOG(ERROR) << "Failed to receive bundle."; - return; - } - } else { - FTL_NOTREACHED(); - } -} - -ApplicationImpl::~ApplicationImpl() {} - -void ApplicationImpl::Initialize(mojo::InterfaceHandle shell, - mojo::Array args, - const mojo::String& url) { - shell_ = mojo::ShellPtr::Create(shell.Pass()); - url_ = url; - mojo::ApplicationConnectorPtr connector; - shell_->CreateApplicationConnector(mojo::GetProxy(&connector)); - runtime_holder_.reset(new RuntimeHolder()); - runtime_holder_->Init(std::move(connector), std::move(bundle_)); -} - -void ApplicationImpl::AcceptConnection( - const mojo::String& requestor_url, - const mojo::String& resolved_url, - mojo::InterfaceRequest services) { - service_provider_bindings_.AddBinding(this, std::move(services)); -} - -void ApplicationImpl::RequestQuit() { - binding_.Close(); - delete this; -} - -void ApplicationImpl::ConnectToService( - const mojo::String& service_name, - mojo::ScopedMessagePipeHandle client_handle) { - if (service_name == mozart::ViewProvider::Name_) { - view_provider_bindings_.AddBinding( - this, - mojo::InterfaceRequest(std::move(client_handle))); - } -} - -void ApplicationImpl::CreateView( - mojo::InterfaceRequest view_owner_request, - mojo::InterfaceRequest services) { - runtime_holder_->CreateView(url_, std::move(view_owner_request), - std::move(services)); -} - -} // namespace flutter_content_handler diff --git a/content_handler/application_impl.h b/content_handler/application_impl.h deleted file mode 100644 index 142b2d53dfb..00000000000 --- a/content_handler/application_impl.h +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2016 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. - -#ifndef FLUTTER_CONTENT_HANDLER_APPLICATION_IMPL_H_ -#define FLUTTER_CONTENT_HANDLER_APPLICATION_IMPL_H_ - -#include - -#include "apps/mozart/services/views/interfaces/view_provider.mojom.h" -#include "flutter/glue/drain_data_pipe_job.h" -#include "lib/ftl/macros.h" -#include "mojo/public/cpp/bindings/binding_set.h" -#include "mojo/public/cpp/bindings/strong_binding.h" -#include "mojo/public/interfaces/application/application.mojom.h" -#include "mojo/public/interfaces/application/service_provider.mojom.h" -#include "mojo/public/interfaces/application/shell.mojom.h" -#include "mojo/services/content_handler/interfaces/content_handler.mojom.h" - -namespace flutter_content_handler { -class RuntimeHolder; - -class ApplicationImpl : public mojo::Application, - public mojo::ServiceProvider, - public mozart::ViewProvider { - public: - ApplicationImpl(mojo::InterfaceRequest application, - mojo::URLResponsePtr response); - ~ApplicationImpl() override; - - private: - // mojo::Application - void Initialize(mojo::InterfaceHandle shell, - mojo::Array args, - const mojo::String& url) override; - void AcceptConnection( - const mojo::String& requestor_url, - const mojo::String& resolved_url, - mojo::InterfaceRequest services) override; - void RequestQuit() override; - - // mojo::ServiceProvider - void ConnectToService(const mojo::String& service_name, - mojo::ScopedMessagePipeHandle client_handle) override; - - // mozart::ViewProvider - void CreateView( - mojo::InterfaceRequest view_owner_request, - mojo::InterfaceRequest services) override; - - void StartRuntimeIfReady(); - - mojo::StrongBinding binding_; - std::unique_ptr drainer_; - - mojo::BindingSet service_provider_bindings_; - mojo::BindingSet view_provider_bindings_; - - std::vector bundle_; - mojo::ShellPtr shell_; - std::string url_; - - std::unique_ptr runtime_holder_; - - FTL_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl); -}; - -} // namespace flutter_content_handler - -#endif // FLUTTER_CONTENT_HANDLER_APPLICATION_IMPL_H_ diff --git a/content_handler/content_handler_impl.cc b/content_handler/content_handler_impl.cc deleted file mode 100644 index 161c3f7a9d2..00000000000 --- a/content_handler/content_handler_impl.cc +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2015 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. - -#include "flutter/content_handler/content_handler_impl.h" - -#include - -#include "flutter/content_handler/application_impl.h" - -namespace flutter_content_handler { - -ContentHandlerImpl::ContentHandlerImpl( - mojo::InterfaceRequest request) - : binding_(this, request.Pass()) {} - -ContentHandlerImpl::~ContentHandlerImpl() {} - -void ContentHandlerImpl::StartApplication( - mojo::InterfaceRequest application, - mojo::URLResponsePtr response) { - new ApplicationImpl(std::move(application), std::move(response)); -} - -} // namespace flutter_content_handler diff --git a/content_handler/content_handler_impl.h b/content_handler/content_handler_impl.h deleted file mode 100644 index 98b5ef50eeb..00000000000 --- a/content_handler/content_handler_impl.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2016 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. - -#ifndef FLUTTER_CONTENT_HANDLER_CONTENT_HANDLER_IMPL_H_ -#define FLUTTER_CONTENT_HANDLER_CONTENT_HANDLER_IMPL_H_ - -#include "lib/ftl/macros.h" -#include "mojo/public/cpp/bindings/strong_binding.h" -#include "mojo/services/content_handler/interfaces/content_handler.mojom.h" - -namespace flutter_content_handler { - -class ContentHandlerImpl : public mojo::ContentHandler { - public: - explicit ContentHandlerImpl( - mojo::InterfaceRequest request); - ~ContentHandlerImpl() override; - - private: - // Overridden from ContentHandler: - void StartApplication(mojo::InterfaceRequest application, - mojo::URLResponsePtr response) override; - - mojo::StrongBinding binding_; - - FTL_DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl); -}; - -} // namespace flutter_content_handler - -#endif // FLUTTER_CONTENT_HANDLER_CONTENT_HANDLER_IMPL_H_ diff --git a/content_handler/main.cc b/content_handler/main.cc index 2432c3366e9..814e800bdfb 100644 --- a/content_handler/main.cc +++ b/content_handler/main.cc @@ -2,104 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include - -#include -#include - -#include "flutter/common/settings.h" -#include "flutter/common/threads.h" -#include "flutter/content_handler/content_handler_impl.h" -#include "flutter/runtime/runtime_init.h" -#include "flutter/sky/engine/platform/fonts/fuchsia/FontCacheFuchsia.h" -#include "lib/ftl/macros.h" -#include "lib/ftl/tasks/task_runner.h" +#include "flutter/content_handler/app.h" #include "lib/mtl/tasks/message_loop.h" -#include "lib/mtl/threading/create_thread.h" -#include "lib/trace_event/tracing_client.h" -#include "mojo/public/cpp/application/application_impl_base.h" -#include "mojo/public/cpp/application/connect.h" -#include "mojo/public/cpp/application/run_application.h" -#include "mojo/public/cpp/application/service_provider_impl.h" -#include "mojo/services/content_handler/interfaces/content_handler.mojom.h" -namespace flutter_content_handler { -namespace { - -void QuitMessageLoop() { - mtl::MessageLoop::GetCurrent()->QuitNow(); -} - -class App : public mojo::ApplicationImplBase { - public: - App() {} - ~App() override { - if (initialized_) { - StopThreads(); - trace_event::DestroyTracer(); - } - } - - // Overridden from ApplicationDelegate: - void OnInitialize() override { - FTL_DCHECK(!initialized_); - initialized_ = true; - - tracing::TraceProviderRegistryPtr registry; - ConnectToService(shell(), "mojo:tracing", GetProxy(®istry)); - trace_event::InitializeTracer(std::move(registry)); - - ftl::RefPtr gpu_task_runner; - gpu_thread_ = mtl::CreateThread(&gpu_task_runner); - - ftl::RefPtr ui_task_runner( - mtl::MessageLoop::GetCurrent()->task_runner()); - - ftl::RefPtr io_task_runner; - io_thread_ = mtl::CreateThread(&io_task_runner); - - // Notice that the Platform and UI threads are actually the same. - blink::Threads::Set(blink::Threads(ui_task_runner, gpu_task_runner, - ui_task_runner, io_task_runner)); - blink::Settings::Set(blink::Settings()); - blink::InitRuntime(); - - mojo::FontProviderPtr font_provider; - mojo::ConnectToService(shell(), "mojo:fonts", - mojo::GetProxy(&font_provider)); - blink::SetFontProvider(std::move(font_provider)); - } - - bool OnAcceptConnection( - mojo::ServiceProviderImpl* service_provider_impl) override { - service_provider_impl->AddService( - [](const mojo::ConnectionContext& connection_context, - mojo::InterfaceRequest request) { - new ContentHandlerImpl(std::move(request)); - }); - return true; - } - - private: - void StopThreads() { - FTL_DCHECK(initialized_); - blink::Threads::Gpu()->PostTask(QuitMessageLoop); - blink::Threads::IO()->PostTask(QuitMessageLoop); - gpu_thread_.join(); - io_thread_.join(); - } - - bool initialized_ = false; - std::thread gpu_thread_; - std::thread io_thread_; - - FTL_DISALLOW_COPY_AND_ASSIGN(App); -}; - -} // namespace -} // namespace flutter_content_handler - -MojoResult MojoMain(MojoHandle request) { - flutter_content_handler::App app; - return mojo::RunApplication(request, &app); +int main(int argc, const char** argv) { + mtl::MessageLoop loop; + flutter_runner::App app; + loop.Run(); + return 0; } diff --git a/content_handler/rasterizer.cc b/content_handler/rasterizer.cc index 482b3f30858..36ba4676b79 100644 --- a/content_handler/rasterizer.cc +++ b/content_handler/rasterizer.cc @@ -6,12 +6,12 @@ #include -#include "apps/mozart/services/composition/interfaces/image.mojom.h" +#include "apps/mozart/services/composition/image.fidl.h" #include "flutter/content_handler/skia_surface_holder.h" #include "lib/ftl/logging.h" #include "third_party/skia/include/core/SkCanvas.h" -namespace flutter_content_handler { +namespace flutter_runner { namespace { constexpr uint32_t kContentImageResourceId = 1; @@ -22,7 +22,7 @@ Rasterizer::Rasterizer() {} Rasterizer::~Rasterizer() {} -void Rasterizer::SetScene(mojo::InterfaceHandle scene) { +void Rasterizer::SetScene(fidl::InterfaceHandle scene) { scene_.Bind(std::move(scene)); } @@ -48,14 +48,15 @@ void Rasterizer::Draw(std::unique_ptr layer_tree, layer_tree->Raster(frame); canvas->flush(); - mojo::RectF bounds; + mozart::RectF bounds; bounds.width = frame_size.width(); bounds.height = frame_size.height(); auto content_resource = mozart::Resource::New(); content_resource->set_image(mozart::ImageResource::New()); content_resource->get_image()->image = surface_holder.TakeImage(); - update->resources.insert(kContentImageResourceId, content_resource.Pass()); + update->resources.insert(kContentImageResourceId, + std::move(content_resource)); auto root_node = mozart::Node::New(); root_node->hit_test_behavior = mozart::HitTestBehavior::New(); @@ -63,12 +64,11 @@ void Rasterizer::Draw(std::unique_ptr layer_tree, root_node->op->set_image(mozart::ImageNodeOp::New()); root_node->op->get_image()->content_rect = bounds.Clone(); root_node->op->get_image()->image_resource_id = kContentImageResourceId; - update->nodes.insert(kRootNodeId, root_node.Pass()); + update->nodes.insert(kRootNodeId, std::move(root_node)); layer_tree->UpdateScene(update.get(), root_node.get()); } else { - auto root_node = mozart::Node::New(); - update->nodes.insert(kRootNodeId, root_node.Pass()); + update->nodes.insert(kRootNodeId, mozart::Node::New()); } scene_->Update(std::move(update)); @@ -80,4 +80,4 @@ void Rasterizer::Draw(std::unique_ptr layer_tree, callback(); } -} // namespace flutter_content_handler +} // namespace flutter_runner diff --git a/content_handler/rasterizer.h b/content_handler/rasterizer.h index e15080d5caf..403c766b9f3 100644 --- a/content_handler/rasterizer.h +++ b/content_handler/rasterizer.h @@ -5,20 +5,20 @@ #ifndef FLUTTER_CONTENT_HANDLER_RASTERIZER_H_ #define FLUTTER_CONTENT_HANDLER_RASTERIZER_H_ -#include "apps/mozart/services/composition/interfaces/scenes.mojom.h" +#include "apps/mozart/services/composition/scenes.fidl.h" #include "flutter/flow/compositor_context.h" #include "flutter/flow/layers/layer_tree.h" #include "lib/ftl/functional/closure.h" #include "lib/ftl/macros.h" -namespace flutter_content_handler { +namespace flutter_runner { class Rasterizer { public: Rasterizer(); ~Rasterizer(); - void SetScene(mojo::InterfaceHandle scene); + void SetScene(fidl::InterfaceHandle scene); void Draw(std::unique_ptr layer_tree, ftl::Closure callback); @@ -29,6 +29,6 @@ class Rasterizer { FTL_DISALLOW_COPY_AND_ASSIGN(Rasterizer); }; -} // namespace flutter_content_handler +} // namespace flutter_runner #endif // FLUTTER_CONTENT_HANDLER_RASTERIZER_H_ diff --git a/content_handler/runtime_holder.cc b/content_handler/runtime_holder.cc index 717ee7c779d..e0235a1236d 100644 --- a/content_handler/runtime_holder.cc +++ b/content_handler/runtime_holder.cc @@ -6,6 +6,7 @@ #include +#include "apps/modular/lib/app/connect.h" #include "flutter/assets/zip_asset_store.h" #include "flutter/common/threads.h" #include "flutter/content_handler/rasterizer.h" @@ -17,9 +18,8 @@ #include "lib/ftl/logging.h" #include "lib/ftl/time/time_delta.h" #include "lib/zip/create_unzipper.h" -#include "mojo/public/cpp/application/connect.h" -namespace flutter_content_handler { +namespace flutter_runner { namespace { constexpr char kSnapshotKey[] = "snapshot_blob.bin"; @@ -61,20 +61,19 @@ RuntimeHolder::~RuntimeHolder() { })); } -void RuntimeHolder::Init(mojo::ApplicationConnectorPtr connector, +void RuntimeHolder::Init(modular::ServiceProviderPtr environment_services, std::vector bundle) { FTL_DCHECK(!rasterizer_); rasterizer_.reset(new Rasterizer()); InitRootBundle(std::move(bundle)); - mojo::ConnectToService(connector.get(), "mojo:view_manager_service", - mojo::GetProxy(&view_manager_)); + ConnectToService(environment_services.get(), fidl::GetProxy(&view_manager_)); } void RuntimeHolder::CreateView( const std::string& script_uri, - mojo::InterfaceRequest view_owner_request, - mojo::InterfaceRequest services) { + fidl::InterfaceRequest view_owner_request, + fidl::InterfaceRequest services) { if (view_listener_binding_.is_bound()) { // TODO(jeffbrown): Refactor this to support multiple view instances // sharing the same underlying root bundle (but with different runtimes). @@ -89,22 +88,22 @@ void RuntimeHolder::CreateView( } mozart::ViewListenerPtr view_listener; - view_listener_binding_.Bind(mojo::GetProxy(&view_listener)); - view_manager_->CreateView(mojo::GetProxy(&view_), + view_listener_binding_.Bind(fidl::GetProxy(&view_listener)); + view_manager_->CreateView(fidl::GetProxy(&view_), std::move(view_owner_request), std::move(view_listener), script_uri); - mojo::ServiceProviderPtr view_services; + modular::ServiceProviderPtr view_services; view_->GetServiceProvider(GetProxy(&view_services)); // Listen for input events. - mojo::ConnectToService(view_services.get(), GetProxy(&input_connection_)); + ConnectToService(view_services.get(), GetProxy(&input_connection_)); mozart::InputListenerPtr input_listener; input_listener_binding_.Bind(GetProxy(&input_listener)); input_connection_->SetListener(std::move(input_listener)); mozart::ScenePtr scene; - view_->CreateScene(mojo::GetProxy(&scene)); + view_->CreateScene(fidl::GetProxy(&scene)); blink::Threads::Gpu()->PostTask(ftl::MakeCopyable([ rasterizer = rasterizer_.get(), scene = std::move(scene) ]() mutable { rasterizer->SetScene(std::move(scene)); })); @@ -117,7 +116,7 @@ void RuntimeHolder::CreateView( } void RuntimeHolder::ScheduleFrame() { - if (pending_invalidation_ || !deferred_invalidation_callback_.is_null()) + if (pending_invalidation_ || deferred_invalidation_callback_) return; pending_invalidation_ = true; view_->Invalidate(); @@ -207,7 +206,7 @@ void RuntimeHolder::OnEvent(mozart::EventPtr event, runtime_->DispatchPointerDataPacket(packet); handled = true; } - callback.Run(handled); + callback(handled); } void RuntimeHolder::OnInvalidation(mozart::ViewInvalidationPtr invalidation, @@ -233,7 +232,7 @@ void RuntimeHolder::OnInvalidation(mozart::ViewInvalidationPtr invalidation, // TODO(jeffbrown): Flow the frame time through the rendering pipeline. if (outstanding_requests_ >= kMaxPipelineDepth) { - FTL_DCHECK(deferred_invalidation_callback_.is_null()); + FTL_DCHECK(!deferred_invalidation_callback_); deferred_invalidation_callback_ = callback; return; } @@ -245,7 +244,7 @@ void RuntimeHolder::OnInvalidation(mozart::ViewInvalidationPtr invalidation, // Note that this may result in the view processing stale view properties // (such as size) if it prematurely acks the frame but takes too long // to handle it. - callback.Run(); + callback(); } ftl::WeakPtr RuntimeHolder::GetWeakPtr() { @@ -274,16 +273,16 @@ void RuntimeHolder::OnFrameComplete() { FTL_DCHECK(outstanding_requests_ > 0); --outstanding_requests_; - if (!deferred_invalidation_callback_.is_null() && + if (deferred_invalidation_callback_ && outstanding_requests_ <= kRecoveryPipelineDepth) { // Schedule frame first to avoid potentially generating a second // invalidation in case the view manager already has one pending // awaiting acknowledgement of the deferred invalidation. - OnInvalidationCallback callback = deferred_invalidation_callback_; - deferred_invalidation_callback_.reset(); + OnInvalidationCallback callback = + std::move(deferred_invalidation_callback_); ScheduleFrame(); - callback.Run(); + callback(); } } -} // namespace flutter_content_handler +} // namespace flutter_runner diff --git a/content_handler/runtime_holder.h b/content_handler/runtime_holder.h index 737461423a8..6689f939e81 100644 --- a/content_handler/runtime_holder.h +++ b/content_handler/runtime_holder.h @@ -5,8 +5,9 @@ #ifndef FLUTTER_CONTENT_HANDLER_RUNTIME_HOLDER_H_ #define FLUTTER_CONTENT_HANDLER_RUNTIME_HOLDER_H_ -#include "apps/mozart/services/input/interfaces/input_connection.mojom.h" -#include "apps/mozart/services/views/interfaces/view_manager.mojom.h" +#include "apps/modular/services/application/service_provider.fidl.h" +#include "apps/mozart/services/input/input_connection.fidl.h" +#include "apps/mozart/services/views/view_manager.fidl.h" #include "flutter/assets/unzipper_provider.h" #include "flutter/assets/zip_asset_store.h" #include "flutter/flow/layers/layer_tree.h" @@ -16,10 +17,9 @@ #include "lib/ftl/functional/closure.h" #include "lib/ftl/macros.h" #include "lib/ftl/memory/weak_ptr.h" -#include "mojo/public/cpp/bindings/binding.h" -#include "mojo/public/interfaces/application/application_connector.mojom.h" +#include "lib/fidl/cpp/bindings/binding.h" -namespace flutter_content_handler { +namespace flutter_runner { class Rasterizer; class RuntimeHolder : public blink::RuntimeDelegate, @@ -29,10 +29,11 @@ class RuntimeHolder : public blink::RuntimeDelegate, RuntimeHolder(); ~RuntimeHolder(); - void Init(mojo::ApplicationConnectorPtr connector, std::vector bundle); + void Init(modular::ServiceProviderPtr environment_services, + std::vector bundle); void CreateView(const std::string& script_uri, - mojo::InterfaceRequest view_owner_request, - mojo::InterfaceRequest services); + fidl::InterfaceRequest view_owner_request, + fidl::InterfaceRequest services); private: // |blink::RuntimeDelegate| implementation: @@ -69,8 +70,8 @@ class RuntimeHolder : public blink::RuntimeDelegate, blink::ViewportMetrics viewport_metrics_; mozart::ViewManagerPtr view_manager_; - mojo::Binding view_listener_binding_; - mojo::Binding input_listener_binding_; + fidl::Binding view_listener_binding_; + fidl::Binding input_listener_binding_; mozart::InputConnectionPtr input_connection_; mozart::ViewPtr view_; mozart::ViewPropertiesPtr view_properties_; @@ -86,6 +87,6 @@ class RuntimeHolder : public blink::RuntimeDelegate, FTL_DISALLOW_COPY_AND_ASSIGN(RuntimeHolder); }; -} // namespace flutter_content_handler +} // namespace flutter_runner #endif // FLUTTER_CONTENT_HANDLER_RUNTIME_HOLDER_H_ diff --git a/content_handler/skia_surface_holder.cc b/content_handler/skia_surface_holder.cc index 807bec99c01..570f2acac44 100644 --- a/content_handler/skia_surface_holder.cc +++ b/content_handler/skia_surface_holder.cc @@ -4,45 +4,53 @@ #include "flutter/content_handler/skia_surface_holder.h" +#include + #include "lib/ftl/logging.h" -#include "mojo/public/cpp/system/buffer.h" #include "third_party/skia/include/core/SkCanvas.h" -namespace flutter_content_handler { +namespace flutter_runner { SkiaSurfaceHolder::SkiaSurfaceHolder(const SkISize& size) { size_t row_bytes = size.width() * sizeof(uint32_t); size_t total_bytes = size.height() * row_bytes; - FTL_CHECK(MOJO_RESULT_OK == - mojo::CreateSharedBuffer(nullptr, total_bytes, &buffer_handle_)); - FTL_CHECK(MOJO_RESULT_OK == mojo::MapBuffer(buffer_handle_.get(), 0u, - total_bytes, &buffer_, - MOJO_MAP_BUFFER_FLAG_NONE)); + mx_status_t rv = mx::vmo::create(total_bytes, 0, &vmo_); + FTL_CHECK(rv == NO_ERROR); + + uintptr_t address = 0; + rv = mx::process::self().map_vm(vmo_, 0, total_bytes, &address, + MX_VM_FLAG_PERM_READ | MX_VM_FLAG_PERM_WRITE); + FTL_CHECK(rv == NO_ERROR); + + buffer_ = reinterpret_cast(address); surface_ = SkSurface::MakeRasterDirect( SkImageInfo::Make(size.width(), size.height(), kBGRA_8888_SkColorType, kPremul_SkAlphaType), buffer_, row_bytes); + FTL_CHECK(surface_); } SkiaSurfaceHolder::~SkiaSurfaceHolder() { - FTL_CHECK(MOJO_RESULT_OK == mojo::UnmapBuffer(buffer_)); + mx_status_t rv = + mx::process::self().unmap_vm(reinterpret_cast(buffer_), 0); + FTL_CHECK(rv == NO_ERROR); } mozart::ImagePtr SkiaSurfaceHolder::TakeImage() { - FTL_DCHECK(buffer_handle_.get().value()); + FTL_DCHECK(vmo_); auto image = mozart::Image::New(); - image->size = mojo::Size::New(); + image->size = mozart::Size::New(); image->size->width = surface_->width(); image->size->height = surface_->height(); image->stride = image->size->width * sizeof(uint32_t); image->pixel_format = mozart::Image::PixelFormat::B8G8R8A8; image->alpha_format = mozart::Image::AlphaFormat::PREMULTIPLIED; - image->buffer = std::move(buffer_handle_); + image->buffer = std::move(vmo_); return image; } -} // namespace flutter_content_handler +} // namespace flutter_runner diff --git a/content_handler/skia_surface_holder.h b/content_handler/skia_surface_holder.h index 5e764d0d4c7..33fd686df91 100644 --- a/content_handler/skia_surface_holder.h +++ b/content_handler/skia_surface_holder.h @@ -5,13 +5,15 @@ #ifndef FLUTTER_CONTENT_HANDLER_SKIA_SURFACE_HOLDER_H_ #define FLUTTER_CONTENT_HANDLER_SKIA_SURFACE_HOLDER_H_ -#include "apps/mozart/services/composition/interfaces/image.mojom.h" +#include + +#include "apps/mozart/services/composition/image.fidl.h" +#include "apps/mozart/services/geometry/geometry.fidl.h" #include "lib/ftl/macros.h" -#include "mojo/services/geometry/interfaces/geometry.mojom.h" #include "third_party/skia/include/core/SkSize.h" #include "third_party/skia/include/core/SkSurface.h" -namespace flutter_content_handler { +namespace flutter_runner { // Provides an |SkSurface| backed by a shared memory buffer for software // rendering which can then be passed to the Mozart compositor in the form @@ -35,13 +37,13 @@ class SkiaSurfaceHolder { mozart::ImagePtr TakeImage(); private: - mojo::ScopedSharedBufferHandle buffer_handle_; + mx::vmo vmo_; void* buffer_; sk_sp surface_; FTL_DISALLOW_COPY_AND_ASSIGN(SkiaSurfaceHolder); }; -} // namespace flutter_content_handler +} // namespace flutter_runner #endif // FLUTTER_CONTENT_HANDLER_SKIA_SURFACE_HOLDER_H_ diff --git a/flow/BUILD.gn b/flow/BUILD.gn index f5a309eeab2..b57985fcf57 100644 --- a/flow/BUILD.gn +++ b/flow/BUILD.gn @@ -55,8 +55,8 @@ source_set("flow") { "layers/child_scene_layer.h", "texture_image_none.cc", ] - deps += [ - "//apps/mozart/services/composition/interfaces", + public_deps = [ + "//apps/mozart/services/composition", ] } else { sources += [ diff --git a/flow/layers/child_scene_layer.cc b/flow/layers/child_scene_layer.cc index 1ae7cbd3ccf..1f0233c878e 100644 --- a/flow/layers/child_scene_layer.cc +++ b/flow/layers/child_scene_layer.cc @@ -7,9 +7,9 @@ namespace flow { namespace { -mojo::TransformPtr GetTransformFromSkMatrix(const SkMatrix& input) { +mozart::TransformPtr GetTransformFromSkMatrix(const SkMatrix& input) { // Expand 3x3 to 4x4. - auto output = mojo::Transform::New(); + auto output = mozart::Transform::New(); output->matrix.resize(16u); output->matrix[0] = input[0]; output->matrix[1] = input[1]; @@ -27,7 +27,7 @@ mojo::TransformPtr GetTransformFromSkMatrix(const SkMatrix& input) { output->matrix[13] = input[7]; output->matrix[14] = 0.f; output->matrix[15] = input[8]; - return output.Pass(); + return output; } // TODO(abarth): We need to figure out how to allocate these ids sensibly. @@ -58,17 +58,17 @@ void ChildSceneLayer::UpdateScene(mozart::SceneUpdate* update, child_resource->set_scene(mozart::SceneResource::New()); child_resource->get_scene()->scene_token = mozart::SceneToken::New(); child_resource->get_scene()->scene_token->value = scene_token_; - update->resources.insert(id, child_resource.Pass()); + update->resources.insert(id, std::move(child_resource)); auto child_node = mozart::Node::New(); child_node->op = mozart::NodeOp::New(); child_node->op->set_scene(mozart::SceneNodeOp::New()); child_node->op->get_scene()->scene_resource_id = id; - child_node->content_clip = mojo::RectF::New(); + child_node->content_clip = mozart::RectF::New(); child_node->content_clip->width = physical_size_.width(); child_node->content_clip->height = physical_size_.height(); child_node->content_transform = GetTransformFromSkMatrix(transform_); - update->nodes.insert(id, child_node.Pass()); + update->nodes.insert(id, std::move(child_node)); container->child_node_ids.push_back(id); } diff --git a/flow/layers/child_scene_layer.h b/flow/layers/child_scene_layer.h index 86262d9eff4..649a2a83661 100644 --- a/flow/layers/child_scene_layer.h +++ b/flow/layers/child_scene_layer.h @@ -6,7 +6,7 @@ #define FLUTTER_FLOW_LAYERS_CHILD_SCENE_LAYER_H_ #include "flutter/flow/layers/layer.h" -#include "apps/mozart/services/composition/interfaces/scenes.mojom.h" +#include "apps/mozart/services/composition/scenes.fidl.h" namespace flow { diff --git a/glue/BUILD.gn b/glue/BUILD.gn index 15b087d0ba5..148492b8d71 100644 --- a/glue/BUILD.gn +++ b/glue/BUILD.gn @@ -5,7 +5,6 @@ source_set("glue") { sources = [ "stack_trace.h", - "thread.h", "trace_event.h", ] @@ -15,27 +14,13 @@ source_set("glue") { if (is_fuchsia) { sources += [ - "drain_data_pipe_job.h", - "drain_data_pipe_job_fuchsia.cc", "stack_trace_fuchsia.cc", - "thread_fuchsia.cc", - ] - - deps += [ - "//lib/mtl", - "//mojo/public/cpp/environment", - "//mojo/public/cpp/system", - ] - - public_deps = [ - "//lib/trace_event", ] } else { sources += [ "stack_trace_base.cc", "task_runner_adaptor.cc", "task_runner_adaptor.h", - "thread_base.cc", ] deps += [ diff --git a/glue/drain_data_pipe_job.h b/glue/drain_data_pipe_job.h deleted file mode 100644 index 3a80f2867ba..00000000000 --- a/glue/drain_data_pipe_job.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2016 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. - -#ifndef FLUTTER_GLU_DRAIN_DATA_PIPE_JOB_H_ -#define FLUTTER_GLU_DRAIN_DATA_PIPE_JOB_H_ - -#include -#include -#include - -#include "lib/ftl/macros.h" -#include "mojo/public/cpp/system/data_pipe.h" - -namespace glue { - -class DrainDataPipeJob { - public: - using ResultCallback = std::function)>; - - DrainDataPipeJob(mojo::ScopedDataPipeConsumerHandle handle, - const ResultCallback& callback); - ~DrainDataPipeJob(); - - private: - class JobImpl; - - std::unique_ptr impl_; - - FTL_DISALLOW_COPY_AND_ASSIGN(DrainDataPipeJob); -}; - -} // namespace glue - -#endif // FLUTTER_GLU_DRAIN_DATA_PIPE_JOB_H_ diff --git a/glue/drain_data_pipe_job_fuchsia.cc b/glue/drain_data_pipe_job_fuchsia.cc deleted file mode 100644 index 3f25501d00c..00000000000 --- a/glue/drain_data_pipe_job_fuchsia.cc +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2016 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. - -#include "flutter/glue/drain_data_pipe_job.h" - -#include - -#include "lib/mtl/data_pipe/data_pipe_drainer.h" - -using mtl::DataPipeDrainer; - -namespace glue { - -class DrainDataPipeJob::JobImpl : public DataPipeDrainer::Client { - public: - explicit JobImpl(mojo::ScopedDataPipeConsumerHandle handle, - const ResultCallback& callback) - : callback_(callback), drainer_(this) { - drainer_.Start(std::move(handle)); - } - - private: - // mojo::common::DataPipeDrainer::Client - void OnDataAvailable(const void* data, size_t num_bytes) override { - const uint8_t* bytes = static_cast(data); - buffer_.insert(buffer_.end(), bytes, bytes + num_bytes); - } - - void OnDataComplete() override { callback_(std::move(buffer_)); } - - std::vector buffer_; - ResultCallback callback_; - DataPipeDrainer drainer_; - - FTL_DISALLOW_COPY_AND_ASSIGN(JobImpl); -}; - -DrainDataPipeJob::DrainDataPipeJob(mojo::ScopedDataPipeConsumerHandle handle, - const ResultCallback& callback) - : impl_(new JobImpl(std::move(handle), callback)) {} - -DrainDataPipeJob::~DrainDataPipeJob() {} - -} // namespace glue diff --git a/glue/thread.h b/glue/thread.h deleted file mode 100644 index bd6e68d27d6..00000000000 --- a/glue/thread.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2016 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. - -#ifndef FLUTTER_GLU_THREAD_H_ -#define FLUTTER_GLU_THREAD_H_ - -#include - -#include "lib/ftl/tasks/task_runner.h" - -namespace glue { - -class Thread { - public: - Thread(std::string name); - ~Thread(); - - bool Start(); - - const ftl::RefPtr& task_runner() { return task_runner_; } - - private: - class ThreadImpl; - - std::unique_ptr impl_; - ftl::RefPtr task_runner_; - - FTL_DISALLOW_COPY_AND_ASSIGN(Thread); -}; - -} // namespace glue - -#endif // FLUTTER_GLU_THREAD_H_ diff --git a/glue/thread_base.cc b/glue/thread_base.cc deleted file mode 100644 index 16d6c10a0a7..00000000000 --- a/glue/thread_base.cc +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2016 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. - -#include "flutter/glue/thread.h" - -#include - -#include "base/threading/thread.h" -#include "flutter/glue/task_runner_adaptor.h" - -namespace glue { - -class Thread::ThreadImpl : public base::Thread { - public: - ThreadImpl(std::string name) : base::Thread(std::move(name)) {} -}; - -Thread::Thread(std::string name) : impl_(new ThreadImpl(name)) {} - -Thread::~Thread() {} - -bool Thread::Start() { - bool result = impl_->Start(); - task_runner_ = ftl::MakeRefCounted(impl_->task_runner()); - return result; -} - -} // namespace glue diff --git a/glue/thread_fuchsia.cc b/glue/thread_fuchsia.cc deleted file mode 100644 index 61252c993af..00000000000 --- a/glue/thread_fuchsia.cc +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2016 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. - -#include "flutter/glue/thread.h" - -#include - -#include "lib/mtl/threading/create_thread.h" - -namespace glue { - -class Thread::ThreadImpl { - public: - std::thread thread_; -}; - -Thread::Thread(std::string name) : impl_(new ThreadImpl()) {} - -Thread::~Thread() {} - -bool Thread::Start() { - impl_->thread_ = mtl::CreateThread(&task_runner_); - return true; -} - -} // namespace glue diff --git a/glue/trace_event.h b/glue/trace_event.h index c03c94c0a55..e84a2f20495 100644 --- a/glue/trace_event.h +++ b/glue/trace_event.h @@ -3,7 +3,13 @@ // found in the LICENSE file. #if defined(__Fuchsia__) -#include "lib/trace_event/macros.h" +#define TRACE_EVENT0(a, b) +#define TRACE_EVENT1(a, b, c, d) +#define TRACE_EVENT2(a, b, c, d, e, f) +#define TRACE_EVENT_ASYNC_BEGIN0(a, b, c) +#define TRACE_EVENT_ASYNC_END0(a, b, c) +#define TRACE_EVENT_ASYNC_BEGIN1(a, b, c, d, e) +#define TRACE_EVENT_ASYNC_END1(a, b, c, d, e) #else #include "base/trace_event/trace_event.h" #endif // defined(__Fuchsia__) diff --git a/sky/engine/platform/BUILD.gn b/sky/engine/platform/BUILD.gn index 9c602ff7011..8e8c4c2c3a5 100644 --- a/sky/engine/platform/BUILD.gn +++ b/sky/engine/platform/BUILD.gn @@ -290,10 +290,7 @@ source_set("platform") { ] deps += [ - "//mojo/public/cpp/bindings", - "//mojo/public/cpp/system", - "//mojo/services/ui/fonts/interfaces", - "//mojo/system", + "//apps/fonts/services", ] } diff --git a/sky/engine/platform/fonts/fuchsia/FontCacheFuchsia.cpp b/sky/engine/platform/fonts/fuchsia/FontCacheFuchsia.cpp index 5273c5c05b5..46fa2a169cb 100644 --- a/sky/engine/platform/fonts/fuchsia/FontCacheFuchsia.cpp +++ b/sky/engine/platform/fonts/fuchsia/FontCacheFuchsia.cpp @@ -6,13 +6,15 @@ #include #include +#include +#include #include +#include "apps/fonts/services/font_provider.fidl.h" #include "flutter/sky/engine/platform/fonts/AlternateFontFamily.h" #include "flutter/sky/engine/platform/fonts/FontCache.h" #include "flutter/sky/engine/platform/fonts/FontDescription.h" #include "lib/ftl/logging.h" -#include "mojo/services/ui/fonts/interfaces/font_provider.mojom.h" #include "third_party/skia/include/core/SkData.h" #include "third_party/skia/include/core/SkTypeface.h" #include "third_party/skia/include/ports/SkFontMgr.h" @@ -20,7 +22,7 @@ namespace blink { namespace { -uint32_t ToMojoWeight(FontWeight weight) { +uint32_t ToIntegerWeight(FontWeight weight) { switch (weight) { case FontWeight100: return 100; @@ -45,48 +47,46 @@ uint32_t ToMojoWeight(FontWeight weight) { return 400; } -mojo::FontSlant ToMojoSlant(FontStyle style) { +fonts::FontSlant ToFontSlant(FontStyle style) { switch (style) { case FontStyleNormal: - return mojo::FontSlant::UPRIGHT; + return fonts::FontSlant::UPRIGHT; case FontStyleItalic: - return mojo::FontSlant::ITALIC; + return fonts::FontSlant::ITALIC; } ASSERT_NOT_REACHED(); - return mojo::FontSlant::UPRIGHT; + return fonts::FontSlant::UPRIGHT; } void UnmapMemory(const void* buffer, void* context) { - mx_process_unmap_vm(mx_process_self(), reinterpret_cast(buffer), - 0); + mx::process::self().unmap_vm(reinterpret_cast(buffer), 0); } -sk_sp MakeSkDataFromVMO(mx_handle_t vmo) { +sk_sp MakeSkDataFromVMO(const mx::vmo& vmo) { uint64_t size = 0; - mx_status_t status = mx_vmo_get_size(vmo, &size); + mx_status_t status = vmo.get_size(&size); if (status != NO_ERROR || size > std::numeric_limits::max()) return nullptr; uintptr_t buffer = 0; - status = mx_process_map_vm(mx_process_self(), vmo, 0, size, &buffer, - MX_VM_FLAG_PERM_READ); + mx::process::self().map_vm(vmo, 0, size, &buffer, MX_VM_FLAG_PERM_READ); if (status != NO_ERROR) return nullptr; return SkData::MakeWithProc(reinterpret_cast(buffer), size, UnmapMemory, nullptr); } -mojo::FontProviderPtr* g_font_provider = nullptr; +fonts::FontProviderPtr* g_font_provider = nullptr; -mojo::FontProviderPtr& GetFontProvider() { +fonts::FontProviderPtr& GetFontProvider() { FTL_CHECK(g_font_provider); return *g_font_provider; } } // namespace -void SetFontProvider(mojo::FontProviderPtr provider) { +void SetFontProvider(fonts::FontProviderPtr provider) { FTL_CHECK(!g_font_provider); - g_font_provider = new mojo::FontProviderPtr; + g_font_provider = new fonts::FontProviderPtr; *g_font_provider = std::move(provider); } @@ -106,24 +106,23 @@ sk_sp FontCache::createTypeface( name = family.utf8(); } - auto request = mojo::FontRequest::New(); + auto request = fonts::FontRequest::New(); request->family = name.data(); - request->weight = ToMojoWeight(fontDescription.weight()); + request->weight = ToIntegerWeight(fontDescription.weight()); request->width = static_cast(fontDescription.stretch()); - request->slant = ToMojoSlant(fontDescription.style()); + request->slant = ToFontSlant(fontDescription.style()); - mojo::FontResponsePtr response; + fonts::FontResponsePtr response; auto& font_provider = GetFontProvider(); font_provider->GetFont( std::move(request), - [&response](mojo::FontResponsePtr r) { response = std::move(r); }); + [&response](fonts::FontResponsePtr r) { response = std::move(r); }); font_provider.WaitForIncomingResponse(); if (!response) return nullptr; - sk_sp data = MakeSkDataFromVMO( - static_cast(response->data->vmo.get().value())); + sk_sp data = MakeSkDataFromVMO(response->data->vmo); if (!data) return nullptr; diff --git a/sky/engine/platform/fonts/fuchsia/FontCacheFuchsia.h b/sky/engine/platform/fonts/fuchsia/FontCacheFuchsia.h index 7a0070e663a..072640c0a94 100644 --- a/sky/engine/platform/fonts/fuchsia/FontCacheFuchsia.h +++ b/sky/engine/platform/fonts/fuchsia/FontCacheFuchsia.h @@ -5,11 +5,11 @@ #ifndef SKY_ENGINE_PLATFORM_FONTS_FUCHSIA_FONT_CACHE_FUCHSIA_H_ #define SKY_ENGINE_PLATFORM_FONTS_FUCHSIA_FONT_CACHE_FUCHSIA_H_ -#include "mojo/services/ui/fonts/interfaces/font_provider.mojom.h" +#include "apps/fonts/services/font_provider.fidl.h" namespace blink { -void SetFontProvider(mojo::FontProviderPtr provider); +void SetFontProvider(fonts::FontProviderPtr provider); } // namespace blink diff --git a/sky/engine/wtf/BUILD.gn b/sky/engine/wtf/BUILD.gn index 3b07f3ef054..1c3dbbef0f8 100644 --- a/sky/engine/wtf/BUILD.gn +++ b/sky/engine/wtf/BUILD.gn @@ -254,9 +254,4 @@ executable("unittests") { ":wtf", "//third_party/gtest", ] - - if (is_fuchsia) { - # TODO(abarth): This shouldn't be necessary. - deps += [ "//mojo/system" ] - } }