提交 0a439f3f 编写于 作者: A Adam Barth 提交者: GitHub

Add //flutter/content_handler (#2923)

We're now producing a flutter_content_handler binary for Fuchsia that
builds and links.
上级 0c000bdf
......@@ -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",
......
# 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",
]
}
// 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 <utility>
#include "lib/ftl/logging.h"
#include "mojo/public/cpp/application/connect.h"
namespace flutter_content_handler {
ApplicationImpl::ApplicationImpl(
mojo::InterfaceRequest<mojo::Application> application,
mojo::URLResponsePtr response)
: binding_(this, std::move(application)),
initial_response_(std::move(response)) {}
ApplicationImpl::~ApplicationImpl() {}
void ApplicationImpl::Initialize(mojo::InterfaceHandle<mojo::Shell> shell,
mojo::Array<mojo::String> 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<mojo::ServiceProvider> services) {}
void ApplicationImpl::RequestQuit() {
binding_.Close();
delete this;
}
} // namespace flutter_content_handler
// 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<mojo::Application> application,
mojo::URLResponsePtr response);
~ApplicationImpl() override;
private:
// mojo::Application
void Initialize(mojo::InterfaceHandle<mojo::Shell> shell,
mojo::Array<mojo::String> args,
const mojo::String& url) override;
void AcceptConnection(
const mojo::String& requestor_url,
const mojo::String& resolved_url,
mojo::InterfaceRequest<mojo::ServiceProvider> services) override;
void RequestQuit() override;
mojo::StrongBinding<mojo::Application> binding_;
mojo::URLResponsePtr initial_response_;
std::string url_;
mojo::ShellPtr shell_;
};
} // namespace flutter_content_handler
#endif // FLUTTER_CONTENT_HANDLER_APPLICATION_IMPL_H_
// 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 <utility>
#include "flutter/content_handler/application_impl.h"
namespace flutter_content_handler {
ContentHandlerImpl::ContentHandlerImpl(
mojo::InterfaceRequest<mojo::ContentHandler> request)
: binding_(this, request.Pass()) {}
ContentHandlerImpl::~ContentHandlerImpl() {}
void ContentHandlerImpl::StartApplication(
mojo::InterfaceRequest<mojo::Application> application,
mojo::URLResponsePtr response) {
new ApplicationImpl(std::move(application), std::move(response));
}
} // namespace flutter_content_handler
// 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<mojo::ContentHandler> request);
~ContentHandlerImpl() override;
private:
// Overridden from ContentHandler:
void StartApplication(mojo::InterfaceRequest<mojo::Application> application,
mojo::URLResponsePtr response) override;
mojo::StrongBinding<mojo::ContentHandler> binding_;
FTL_DISALLOW_COPY_AND_ASSIGN(ContentHandlerImpl);
};
} // namespace flutter_content_handler
#endif // FLUTTER_CONTENT_HANDLER_CONTENT_HANDLER_IMPL_H_
// 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 <mojo/system/main.h>
#include <thread>
#include <utility>
#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<ftl::TaskRunner> gpu_task_runner;
gpu_thread_ = mtl::CreateThread(&gpu_task_runner);
ftl::RefPtr<ftl::TaskRunner> ui_task_runner;
ui_thread_ = mtl::CreateThread(&ui_task_runner);
ftl::RefPtr<ftl::TaskRunner> 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<mojo::ContentHandler>(
[](const mojo::ConnectionContext& connection_context,
mojo::InterfaceRequest<mojo::ContentHandler> 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);
}
......@@ -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",
]
}
}
// 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<SkImage> BitmapImageCreate(SkImageGenerator& generator) {
SkBitmap bitmap;
if (generator.tryGenerateBitmap(&bitmap))
return SkImage::MakeFromBitmap(bitmap);
return nullptr;
}
} // namespace flow
// 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<SkImage> BitmapImageCreate(SkImageGenerator& generator);
} // namespace flow
#endif // FLUTTER_FLOW_BITMAP_IMAGE_H_
......@@ -13,8 +13,6 @@ namespace flow {
sk_sp<SkImage> TextureImageCreate(GrContext* context,
SkImageGenerator& generator);
sk_sp<SkImage> BitmapImageCreate(SkImageGenerator& generator);
} // namespace flow
#endif // FLUTTER_FLOW_TEXTURE_IMAGE_H_
......@@ -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<SkImage> 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<SkImage> TextureImageCreate(GrContext* context,
);
}
sk_sp<SkImage> BitmapImageCreate(SkImageGenerator& generator) {
SkBitmap bitmap;
if (generator.tryGenerateBitmap(&bitmap)) {
return SkImage::MakeFromBitmap(bitmap);
}
return nullptr;
}
sk_sp<SkImage> TextureImageCreate(GrContext* context,
SkImageGenerator& generator) {
if (context == nullptr) {
......
// 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<SkImage> TextureImageCreate(GrContext* context,
SkImageGenerator& generator) {
return nullptr;
}
} // namespace flow
......@@ -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<SkImage> DecodeImage(std::vector<char> buffer) {
TRACE_EVENT0("blink", "DecodeImage");
if (buffer.empty()) {
if (buffer.empty())
return nullptr;
}
sk_sp<SkData> sk_data = SkData::MakeWithoutCopy(buffer.data(), buffer.size());
if (sk_data == nullptr) {
if (sk_data == nullptr)
return nullptr;
}
std::unique_ptr<SkImageGenerator> 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<SkImage> image = flow::TextureImageCreate(context, *generator)) {
GrContext* context = ResourceContext::Get();
if (sk_sp<SkImage> 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.
......
......@@ -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<tonic::Uint8List>::ToDart(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册