Skip to content

Commit

Permalink
Add //flutter/content_handler (flutter#2923)
Browse files Browse the repository at this point in the history
We're now producing a flutter_content_handler binary for Fuchsia that
builds and links.
  • Loading branch information
abarth authored Aug 13, 2016
1 parent 0c000bd commit 0a439f3
Show file tree
Hide file tree
Showing 15 changed files with 323 additions and 35 deletions.
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
37 changes: 37 additions & 0 deletions content_handler/BUILD.gn
Original file line number Diff line number Diff line change
@@ -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",
]
}
40 changes: 40 additions & 0 deletions content_handler/application_impl.cc
Original file line number Diff line number Diff line change
@@ -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 <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
40 changes: 40 additions & 0 deletions content_handler/application_impl.h
Original file line number Diff line number Diff line change
@@ -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<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_
25 changes: 25 additions & 0 deletions content_handler/content_handler_impl.cc
Original file line number Diff line number Diff line change
@@ -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 <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
32 changes: 32 additions & 0 deletions content_handler/content_handler_impl.h
Original file line number Diff line number Diff line change
@@ -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<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_
79 changes: 79 additions & 0 deletions content_handler/main.cc
Original file line number Diff line number Diff line change
@@ -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 <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);
}
20 changes: 11 additions & 9 deletions flow/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
]

Expand All @@ -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",
]
}
}
16 changes: 16 additions & 0 deletions flow/bitmap_image.cc
Original file line number Diff line number Diff line change
@@ -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<SkImage> BitmapImageCreate(SkImageGenerator& generator) {
SkBitmap bitmap;
if (generator.tryGenerateBitmap(&bitmap))
return SkImage::MakeFromBitmap(bitmap);
return nullptr;
}

} // namespace flow
17 changes: 17 additions & 0 deletions flow/bitmap_image.h
Original file line number Diff line number Diff line change
@@ -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<SkImage> BitmapImageCreate(SkImageGenerator& generator);

} // namespace flow

#endif // FLUTTER_FLOW_BITMAP_IMAGE_H_
2 changes: 0 additions & 2 deletions flow/texture_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
16 changes: 3 additions & 13 deletions flow/texture_image.cc → flow/texture_image_gles2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit 0a439f3

Please sign in to comment.