From 0a439f3f88ad4a715ee710c438f31ea9d90739d0 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Fri, 12 Aug 2016 22:41:54 -0700 Subject: [PATCH] Add //flutter/content_handler (#2923) We're now producing a flutter_content_handler binary for Fuchsia that builds and links. --- BUILD.gn | 1 + content_handler/BUILD.gn | 37 +++++++++ content_handler/application_impl.cc | 40 ++++++++++ content_handler/application_impl.h | 40 ++++++++++ content_handler/content_handler_impl.cc | 25 ++++++ content_handler/content_handler_impl.h | 32 ++++++++ content_handler/main.cc | 79 +++++++++++++++++++ flow/BUILD.gn | 20 ++--- flow/bitmap_image.cc | 16 ++++ flow/bitmap_image.h | 17 ++++ flow/texture_image.h | 2 - ...exture_image.cc => texture_image_gles2.cc} | 16 +--- flow/texture_image_none.cc | 14 ++++ lib/ui/painting/image_decoding.cc | 16 ++-- runtime/dart_init.cc | 3 +- 15 files changed, 323 insertions(+), 35 deletions(-) create mode 100644 content_handler/BUILD.gn create mode 100644 content_handler/application_impl.cc create mode 100644 content_handler/application_impl.h create mode 100644 content_handler/content_handler_impl.cc create mode 100644 content_handler/content_handler_impl.h create mode 100644 content_handler/main.cc create mode 100644 flow/bitmap_image.cc create mode 100644 flow/bitmap_image.h rename flow/{texture_image.cc => texture_image_gles2.cc} (96%) create mode 100644 flow/texture_image_none.cc diff --git a/BUILD.gn b/BUILD.gn index 698b9477c..452384ad9 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -8,6 +8,7 @@ group("flutter") { if (is_fuchsia) { # TODO(abarth) Remove this specific list once Fuchsia can build everything. deps = [ + "//flutter/content_handler", "//flutter/flow", "//flutter/runtime", "//flutter/snapshotter", diff --git a/content_handler/BUILD.gn b/content_handler/BUILD.gn new file mode 100644 index 000000000..81034a6b8 --- /dev/null +++ b/content_handler/BUILD.gn @@ -0,0 +1,37 @@ +# 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. + +assert(is_fuchsia) + +executable("content_handler") { + output_name = "flutter_content_handler" + + sources = [ + "application_impl.cc", + "application_impl.h", + "content_handler_impl.cc", + "content_handler_impl.h", + "main.cc", + ] + + deps = [ + "//dart/runtime:libdart", + "//dart/runtime/vm:libdart_platform", + "//flutter/common", + "//flutter/runtime", + "//lib/ftl", + "//lib/mtl", + "//mojo/public/cpp/application", + "//mojo/public/cpp/bindings", + "//mojo/public/cpp/system", + "//mojo/public/cpp/utility", + "//mojo/public/interfaces/application", + "//mojo/services/content_handler/interfaces", + "//mojo/system", + + # TODO(abarth): We shouldn't need to depend on libdart_builtin but we fail + # to link otherwise. + "//dart/runtime/bin:libdart_builtin", + ] +} diff --git a/content_handler/application_impl.cc b/content_handler/application_impl.cc new file mode 100644 index 000000000..645ac0f77 --- /dev/null +++ b/content_handler/application_impl.cc @@ -0,0 +1,40 @@ +// 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 "lib/ftl/logging.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)), + initial_response_(std::move(response)) {} + +ApplicationImpl::~ApplicationImpl() {} + +void ApplicationImpl::Initialize(mojo::InterfaceHandle shell, + mojo::Array args, + const mojo::String& url) { + FTL_DCHECK(initial_response_); + shell_ = mojo::ShellPtr::Create(shell.Pass()); + url_ = url; +} + +void ApplicationImpl::AcceptConnection( + const mojo::String& requestor_url, + const mojo::String& resolved_url, + mojo::InterfaceRequest services) {} + +void ApplicationImpl::RequestQuit() { + binding_.Close(); + delete this; +} + +} // namespace flutter_content_handler diff --git a/content_handler/application_impl.h b/content_handler/application_impl.h new file mode 100644 index 000000000..e04700030 --- /dev/null +++ b/content_handler/application_impl.h @@ -0,0 +1,40 @@ +// 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 "mojo/public/cpp/bindings/strong_binding.h" +#include "mojo/public/interfaces/application/application.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 ApplicationImpl : public mojo::Application { + 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::StrongBinding binding_; + mojo::URLResponsePtr initial_response_; + std::string url_; + mojo::ShellPtr shell_; +}; + +} // 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 new file mode 100644 index 000000000..161c3f7a9 --- /dev/null +++ b/content_handler/content_handler_impl.cc @@ -0,0 +1,25 @@ +// 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 new file mode 100644 index 000000000..98b5ef50e --- /dev/null +++ b/content_handler/content_handler_impl.h @@ -0,0 +1,32 @@ +// 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 new file mode 100644 index 000000000..e5a96cc61 --- /dev/null +++ b/content_handler/main.cc @@ -0,0 +1,79 @@ +// 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 + +#include +#include + +#include "flutter/common/settings.h" +#include "flutter/common/threads.h" +#include "flutter/content_handler/content_handler_impl.h" +#include "flutter/runtime/dart_init.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" +#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 { + +class App : public mojo::ApplicationImplBase { + public: + App() {} + + ~App() override { + io_thread_.join(); + ui_thread_.join(); + gpu_thread_.join(); + } + + // Overridden from ApplicationDelegate: + void OnInitialize() override { + ftl::RefPtr gpu_task_runner; + gpu_thread_ = mtl::CreateThread(&gpu_task_runner); + + ftl::RefPtr ui_task_runner; + ui_thread_ = mtl::CreateThread(&ui_task_runner); + + ftl::RefPtr io_task_runner; + io_thread_ = mtl::CreateThread(&io_task_runner); + + blink::Threads::Set(blink::Threads(std::move(gpu_task_runner), + std::move(ui_task_runner), + std::move(io_task_runner))); + blink::Settings::Set(blink::Settings()); + blink::InitDartVM(); + } + + 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: + std::thread gpu_thread_; + std::thread ui_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); +} diff --git a/flow/BUILD.gn b/flow/BUILD.gn index 73f69c02d..1100c403a 100644 --- a/flow/BUILD.gn +++ b/flow/BUILD.gn @@ -6,8 +6,6 @@ source_set("flow") { sources = [ "compositor_context.cc", "compositor_context.h", - "gl_connection.cc", - "gl_connection.h", "instrumentation.cc", "instrumentation.h", "layers/backdrop_filter_layer.cc", @@ -38,10 +36,10 @@ source_set("flow") { "layers/shader_mask_layer.h", "layers/transform_layer.cc", "layers/transform_layer.h", - "open_gl.h", "raster_cache.cc", "raster_cache.h", - "texture_image.cc", + "bitmap_image.cc", + "bitmap_image.h", "texture_image.h", ] @@ -53,11 +51,15 @@ source_set("flow") { ] if (is_fuchsia) { - # TODO(abarth): In principle, we should add "//mojo/public/c/gpu" as a - # dependency, but that doesn't work currently because GPU support on Fuchsia - # is still a work in progress. - include_dirs = [ - "//mojo/public/c/gpu", + sources += [ + "texture_image_none.cc", + ] + } else { + sources += [ + "gl_connection.cc", + "gl_connection.h", + "open_gl.h", + "texture_image_gles2.cc", ] } } diff --git a/flow/bitmap_image.cc b/flow/bitmap_image.cc new file mode 100644 index 000000000..69e58d0ac --- /dev/null +++ b/flow/bitmap_image.cc @@ -0,0 +1,16 @@ +// 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/flow/bitmap_image.h" + +namespace flow { + +sk_sp BitmapImageCreate(SkImageGenerator& generator) { + SkBitmap bitmap; + if (generator.tryGenerateBitmap(&bitmap)) + return SkImage::MakeFromBitmap(bitmap); + return nullptr; +} + +} // namespace flow diff --git a/flow/bitmap_image.h b/flow/bitmap_image.h new file mode 100644 index 000000000..3245c5384 --- /dev/null +++ b/flow/bitmap_image.h @@ -0,0 +1,17 @@ +// 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_FLOW_BITMAP_IMAGE_H_ +#define FLUTTER_FLOW_BITMAP_IMAGE_H_ + +#include "third_party/skia/include/core/SkImage.h" +#include "third_party/skia/include/core/SkImageGenerator.h" + +namespace flow { + +sk_sp BitmapImageCreate(SkImageGenerator& generator); + +} // namespace flow + +#endif // FLUTTER_FLOW_BITMAP_IMAGE_H_ diff --git a/flow/texture_image.h b/flow/texture_image.h index 1596c7b79..a535537fe 100644 --- a/flow/texture_image.h +++ b/flow/texture_image.h @@ -13,8 +13,6 @@ namespace flow { sk_sp TextureImageCreate(GrContext* context, SkImageGenerator& generator); -sk_sp BitmapImageCreate(SkImageGenerator& generator); - } // namespace flow #endif // FLUTTER_FLOW_TEXTURE_IMAGE_H_ diff --git a/flow/texture_image.cc b/flow/texture_image_gles2.cc similarity index 96% rename from flow/texture_image.cc rename to flow/texture_image_gles2.cc index f7d1072d9..ac5e36a09 100644 --- a/flow/texture_image.cc +++ b/flow/texture_image_gles2.cc @@ -2,8 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "flutter/flow/open_gl.h" #include "flutter/flow/texture_image.h" + +#include "flutter/flow/open_gl.h" #include "flutter/glue/trace_event.h" #include "third_party/skia/include/gpu/gl/GrGLTypes.h" @@ -76,9 +77,8 @@ static sk_sp TextureImageCreate(GrContext* context, TRACE_EVENT2("flutter", __func__, "width", size.width(), "height", size.height()); - if (context == nullptr) { + if (!context) return nullptr; - } GLuint handle = GL_NONE; @@ -180,16 +180,6 @@ static sk_sp TextureImageCreate(GrContext* context, ); } -sk_sp BitmapImageCreate(SkImageGenerator& generator) { - SkBitmap bitmap; - - if (generator.tryGenerateBitmap(&bitmap)) { - return SkImage::MakeFromBitmap(bitmap); - } - - return nullptr; -} - sk_sp TextureImageCreate(GrContext* context, SkImageGenerator& generator) { if (context == nullptr) { diff --git a/flow/texture_image_none.cc b/flow/texture_image_none.cc new file mode 100644 index 000000000..171ffad73 --- /dev/null +++ b/flow/texture_image_none.cc @@ -0,0 +1,14 @@ +// 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/flow/texture_image.h" + +namespace flow { + +sk_sp TextureImageCreate(GrContext* context, + SkImageGenerator& generator) { + return nullptr; +} + +} // namespace flow diff --git a/lib/ui/painting/image_decoding.cc b/lib/ui/painting/image_decoding.cc index 0667e1688..ea6fb2279 100644 --- a/lib/ui/painting/image_decoding.cc +++ b/lib/ui/painting/image_decoding.cc @@ -5,6 +5,7 @@ #include "flutter/lib/ui/painting/image_decoding.h" #include "flutter/common/threads.h" +#include "flutter/flow/bitmap_image.h" #include "flutter/flow/texture_image.h" #include "flutter/glue/drain_data_pipe_job.h" #include "flutter/glue/movable_wrapper.h" @@ -28,29 +29,24 @@ namespace { sk_sp DecodeImage(std::vector buffer) { TRACE_EVENT0("blink", "DecodeImage"); - if (buffer.empty()) { + if (buffer.empty()) return nullptr; - } sk_sp sk_data = SkData::MakeWithoutCopy(buffer.data(), buffer.size()); - if (sk_data == nullptr) { + if (sk_data == nullptr) return nullptr; - } std::unique_ptr generator( SkImageGenerator::NewFromEncoded(sk_data.get())); - if (generator == nullptr) { + if (generator == nullptr) return nullptr; - } - - GrContext* context = ResourceContext::Get(); // First, try to create a texture image from the generator. - if (sk_sp image = flow::TextureImageCreate(context, *generator)) { + GrContext* context = ResourceContext::Get(); + if (sk_sp image = flow::TextureImageCreate(context, *generator)) return image; - } // The, as a fallback, try to create a regular Skia managed image. These // don't require a context ready. diff --git a/runtime/dart_init.cc b/runtime/dart_init.cc index 65397b974..77d5e8782 100644 --- a/runtime/dart_init.cc +++ b/runtime/dart_init.cc @@ -30,6 +30,7 @@ #include "flutter/runtime/dart_service_isolate.h" #include "flutter/runtime/start_up.h" #include "lib/ftl/arraysize.h" +#include "lib/ftl/build_config.h" #include "lib/ftl/files/eintr_wrapper.h" #include "lib/ftl/files/unique_fd.h" #include "lib/ftl/logging.h" @@ -295,7 +296,7 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri, } Dart_Handle GetVMServiceAssetsArchiveCallback() { -#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_RELEASE +#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_RELEASE || defined(OS_FUCHSIA) return nullptr; #else // FLUTTER_RUNTIME_MODE return tonic::DartConverter::ToDart( -- GitLab