forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add //flutter/content_handler (flutter#2923)
We're now producing a flutter_content_handler binary for Fuchsia that builds and links.
- Loading branch information
Showing
15 changed files
with
323 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.