diff --git a/BUILD.gn b/BUILD.gn index 698b9477c5f96465c5b3e345cc15d1e5518f4efe..452384ad90d9a22891d78e45274053bbb65bc136 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 0000000000000000000000000000000000000000..81034a6b804d6e98b0e6002b4de281af27828644 --- /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 0000000000000000000000000000000000000000..645ac0f77e47577487bbc41e3bbc9c5ea7b9c70b --- /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 0000000000000000000000000000000000000000..e047000308c12cf04e3cc4d8c234298bc583e2bf --- /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 0000000000000000000000000000000000000000..161c3f7a9d2b81fdcd411e405f58b842828fd71d --- /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 0000000000000000000000000000000000000000..98b5ef50eeba4eeec9d48093c1a8968d21c285b3 --- /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 0000000000000000000000000000000000000000..e5a96cc61a83e26c4b9831b67e9d3f3d0348343f --- /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 73f69c02d1f6569095c83a8e7b1a3a1a163c5c8f..1100c403a605863d98db98cc9f6400bc8d31dfe0 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 0000000000000000000000000000000000000000..69e58d0ac4de6857b67fcdfd3c9d29bee5211edc --- /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 0000000000000000000000000000000000000000..3245c5384739cfa66047c72ad14d62da9306d009 --- /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 1596c7b79b20838bc624cb711ca046c5fbca3278..a535537fe6eeec3fb727497c0e7416cd2610137c 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 f7d1072d9f0f49b4404872fa7abc3a64fc964908..ac5e36a09619cee0005146da179f60ecdf165339 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 0000000000000000000000000000000000000000..171ffad737ad52b397ef9ba6ba2d5834b257d848 --- /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 0667e1688b8077f1af808794489995048948c312..ea6fb2279ead42eddcc8870851e61527fd166768 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 65397b97459b9a558bfa08ef41541229aeba2332..77d5e87828baa0370b373c9ef8bf7139f4a19c3d 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(