mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Switch Flutter to //lib/fidl (#3206)
This commit is contained in:
parent
84a060820a
commit
ced9a91c3a
@ -47,7 +47,7 @@ def main():
|
||||
'--packages=%s' % args.packages,
|
||||
'--snapshot=%s' % args.snapshot,
|
||||
'--output-file=%s' % args.output_file,
|
||||
'--header=#!mojo mojo:flutter_content_handler',
|
||||
'--header=#!fuchsia file:///system/apps/flutter_runner',
|
||||
], env=env, cwd=args.app_dir)
|
||||
|
||||
return result
|
||||
|
||||
@ -5,13 +5,13 @@
|
||||
assert(is_fuchsia)
|
||||
|
||||
executable("content_handler") {
|
||||
output_name = "flutter_content_handler"
|
||||
output_name = "flutter_runner"
|
||||
|
||||
sources = [
|
||||
"application_impl.cc",
|
||||
"application_impl.h",
|
||||
"content_handler_impl.cc",
|
||||
"content_handler_impl.h",
|
||||
"app.cc",
|
||||
"app.h",
|
||||
"application_controller_impl.cc",
|
||||
"application_controller_impl.h",
|
||||
"main.cc",
|
||||
"rasterizer.cc",
|
||||
"rasterizer.h",
|
||||
@ -22,11 +22,12 @@ executable("content_handler") {
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//apps/mozart/services/composition/interfaces",
|
||||
"//apps/mozart/services/input/interfaces",
|
||||
"//apps/mozart/services/views/interfaces",
|
||||
"//dart/runtime:libdart",
|
||||
"//apps/modular/lib/app",
|
||||
"//apps/mozart/services/composition",
|
||||
"//apps/mozart/services/input",
|
||||
"//apps/mozart/services/views",
|
||||
"//dart/runtime/vm:libdart_platform",
|
||||
"//dart/runtime:libdart",
|
||||
"//flutter/assets",
|
||||
"//flutter/common",
|
||||
"//flutter/flow",
|
||||
@ -36,15 +37,7 @@ executable("content_handler") {
|
||||
"//flutter/sky/engine/platform",
|
||||
"//lib/ftl",
|
||||
"//lib/mtl",
|
||||
"//lib/trace_event",
|
||||
"//lib/zip",
|
||||
"//mojo/public/cpp/application",
|
||||
"//mojo/public/cpp/bindings",
|
||||
"//mojo/public/cpp/system",
|
||||
"//mojo/public/interfaces/application",
|
||||
"//mojo/services/content_handler/interfaces",
|
||||
"//mojo/services/framebuffer/interfaces",
|
||||
"//mojo/system",
|
||||
"//third_party/skia",
|
||||
|
||||
# TODO(abarth): We shouldn't need to depend on libdart_builtin but we fail
|
||||
|
||||
87
content_handler/app.cc
Normal file
87
content_handler/app.cc
Normal file
@ -0,0 +1,87 @@
|
||||
// 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/app.h"
|
||||
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
|
||||
#include "flutter/common/settings.h"
|
||||
#include "flutter/common/threads.h"
|
||||
#include "flutter/runtime/runtime_init.h"
|
||||
#include "flutter/sky/engine/platform/fonts/fuchsia/FontCacheFuchsia.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"
|
||||
|
||||
namespace flutter_runner {
|
||||
namespace {
|
||||
|
||||
void QuitMessageLoop() {
|
||||
mtl::MessageLoop::GetCurrent()->QuitNow();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
App::App() {
|
||||
context_ = modular::ApplicationContext::CreateFromStartupInfo();
|
||||
|
||||
// TODO(abarth): Initialize tracing.
|
||||
|
||||
ftl::RefPtr<ftl::TaskRunner> gpu_task_runner;
|
||||
gpu_thread_ = mtl::CreateThread(&gpu_task_runner);
|
||||
|
||||
ftl::RefPtr<ftl::TaskRunner> ui_task_runner(
|
||||
mtl::MessageLoop::GetCurrent()->task_runner());
|
||||
|
||||
ftl::RefPtr<ftl::TaskRunner> io_task_runner;
|
||||
io_thread_ = mtl::CreateThread(&io_task_runner);
|
||||
|
||||
// Notice that the Platform and UI threads are actually the same.
|
||||
blink::Threads::Set(blink::Threads(ui_task_runner, gpu_task_runner,
|
||||
ui_task_runner, io_task_runner));
|
||||
blink::Settings::Set(blink::Settings());
|
||||
blink::InitRuntime();
|
||||
|
||||
blink::SetFontProvider(
|
||||
context_->ConnectToEnvironmentService<fonts::FontProvider>());
|
||||
|
||||
context_->outgoing_services()->AddService<modular::ApplicationRunner>(
|
||||
[this](fidl::InterfaceRequest<modular::ApplicationRunner> request) {
|
||||
runner_bindings_.AddBinding(this, std::move(request));
|
||||
});
|
||||
}
|
||||
|
||||
App::~App() {
|
||||
StopThreads();
|
||||
}
|
||||
|
||||
void App::StartApplication(
|
||||
modular::ApplicationPackagePtr application,
|
||||
modular::ApplicationStartupInfoPtr startup_info,
|
||||
fidl::InterfaceRequest<modular::ApplicationController> controller) {
|
||||
std::unique_ptr<ApplicationControllerImpl> impl =
|
||||
std::make_unique<ApplicationControllerImpl>(this, std::move(application),
|
||||
std::move(startup_info),
|
||||
std::move(controller));
|
||||
ApplicationControllerImpl* key = impl.get();
|
||||
controllers_.emplace(key, std::move(impl));
|
||||
}
|
||||
|
||||
void App::Destroy(ApplicationControllerImpl* controller) {
|
||||
auto it = controllers_.find(controller);
|
||||
if (it == controllers_.end())
|
||||
return;
|
||||
controllers_.erase(it);
|
||||
}
|
||||
|
||||
void App::StopThreads() {
|
||||
blink::Threads::Gpu()->PostTask(QuitMessageLoop);
|
||||
blink::Threads::IO()->PostTask(QuitMessageLoop);
|
||||
gpu_thread_.join();
|
||||
io_thread_.join();
|
||||
}
|
||||
|
||||
} // namespace flutter_runner
|
||||
51
content_handler/app.h
Normal file
51
content_handler/app.h
Normal file
@ -0,0 +1,51 @@
|
||||
// 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_APP_H_
|
||||
#define FLUTTER_CONTENT_HANDLER_APP_H_
|
||||
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "apps/modular/lib/app/application_context.h"
|
||||
#include "apps/modular/services/application/application_runner.fidl.h"
|
||||
#include "flutter/content_handler/application_controller_impl.h"
|
||||
#include "lib/ftl/macros.h"
|
||||
|
||||
namespace flutter_runner {
|
||||
|
||||
class App : public modular::ApplicationRunner {
|
||||
public:
|
||||
App();
|
||||
~App();
|
||||
|
||||
// |modular::ApplicationRunner| implementation:
|
||||
|
||||
void StartApplication(modular::ApplicationPackagePtr application,
|
||||
modular::ApplicationStartupInfoPtr startup_info,
|
||||
fidl::InterfaceRequest<modular::ApplicationController>
|
||||
controller) override;
|
||||
|
||||
void Destroy(ApplicationControllerImpl* controller);
|
||||
|
||||
private:
|
||||
void StopThreads();
|
||||
|
||||
std::unique_ptr<modular::ApplicationContext> context_;
|
||||
std::thread gpu_thread_;
|
||||
std::thread io_thread_;
|
||||
|
||||
fidl::BindingSet<modular::ApplicationRunner> runner_bindings_;
|
||||
|
||||
std::unordered_map<ApplicationControllerImpl*,
|
||||
std::unique_ptr<ApplicationControllerImpl>>
|
||||
controllers_;
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(App);
|
||||
};
|
||||
|
||||
} // namespace flutter_runner
|
||||
|
||||
#endif // FLUTTER_CONTENT_HANDLER_APP_H_
|
||||
81
content_handler/application_controller_impl.cc
Normal file
81
content_handler/application_controller_impl.cc
Normal file
@ -0,0 +1,81 @@
|
||||
// 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_controller_impl.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "apps/modular/lib/app/connect.h"
|
||||
#include "flutter/content_handler/app.h"
|
||||
#include "flutter/content_handler/runtime_holder.h"
|
||||
#include "lib/ftl/logging.h"
|
||||
#include "lib/mtl/vmo/vector.h"
|
||||
|
||||
namespace flutter_runner {
|
||||
|
||||
ApplicationControllerImpl::ApplicationControllerImpl(
|
||||
App* app,
|
||||
modular::ApplicationPackagePtr application,
|
||||
modular::ApplicationStartupInfoPtr startup_info,
|
||||
fidl::InterfaceRequest<modular::ApplicationController> controller)
|
||||
: app_(app), binding_(this) {
|
||||
if (controller.is_pending()) {
|
||||
binding_.Bind(std::move(controller));
|
||||
binding_.set_connection_error_handler([this] {
|
||||
app_->Destroy(this);
|
||||
// |this| has been deleted at this point.
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<char> bundle;
|
||||
if (!mtl::VectorFromVmo(std::move(application->data), &bundle)) {
|
||||
FTL_LOG(ERROR) << "Failed to receive bundle.";
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO(abarth): The Dart code should end up with outgoing_services.
|
||||
if (startup_info->outgoing_services.is_pending()) {
|
||||
service_provider_bindings_.AddBinding(
|
||||
this, std::move(startup_info->outgoing_services));
|
||||
}
|
||||
|
||||
url_ = startup_info->url;
|
||||
runtime_holder_.reset(new RuntimeHolder());
|
||||
|
||||
// TODO(abarth): The Dart code should end up with environment_services.
|
||||
runtime_holder_->Init(modular::ServiceProviderPtr::Create(
|
||||
std::move(startup_info->environment_services)),
|
||||
std::move(bundle));
|
||||
}
|
||||
|
||||
ApplicationControllerImpl::~ApplicationControllerImpl() = default;
|
||||
|
||||
void ApplicationControllerImpl::Kill(const KillCallback& callback) {
|
||||
runtime_holder_.reset();
|
||||
app_->Destroy(this);
|
||||
// |this| has been deleted at this point.
|
||||
}
|
||||
|
||||
void ApplicationControllerImpl::Detach() {
|
||||
binding_.set_connection_error_handler(ftl::Closure());
|
||||
}
|
||||
|
||||
void ApplicationControllerImpl::ConnectToService(
|
||||
const fidl::String& service_name,
|
||||
mx::channel client_handle) {
|
||||
if (service_name == mozart::ViewProvider::Name_) {
|
||||
view_provider_bindings_.AddBinding(
|
||||
this,
|
||||
fidl::InterfaceRequest<mozart::ViewProvider>(std::move(client_handle)));
|
||||
}
|
||||
}
|
||||
|
||||
void ApplicationControllerImpl::CreateView(
|
||||
fidl::InterfaceRequest<mozart::ViewOwner> view_owner_request,
|
||||
fidl::InterfaceRequest<modular::ServiceProvider> services) {
|
||||
runtime_holder_->CreateView(url_, std::move(view_owner_request),
|
||||
std::move(services));
|
||||
}
|
||||
|
||||
} // namespace flutter_runner
|
||||
67
content_handler/application_controller_impl.h
Normal file
67
content_handler/application_controller_impl.h
Normal file
@ -0,0 +1,67 @@
|
||||
// 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 <memory>
|
||||
|
||||
#include "apps/modular/services/application/application_controller.fidl.h"
|
||||
#include "apps/modular/services/application/application_runner.fidl.h"
|
||||
#include "apps/modular/services/application/service_provider.fidl.h"
|
||||
#include "apps/mozart/services/views/view_provider.fidl.h"
|
||||
#include "lib/fidl/cpp/bindings/binding.h"
|
||||
#include "lib/fidl/cpp/bindings/binding_set.h"
|
||||
#include "lib/ftl/macros.h"
|
||||
|
||||
namespace flutter_runner {
|
||||
class App;
|
||||
class RuntimeHolder;
|
||||
|
||||
class ApplicationControllerImpl : public modular::ApplicationController,
|
||||
public modular::ServiceProvider,
|
||||
public mozart::ViewProvider {
|
||||
public:
|
||||
ApplicationControllerImpl(
|
||||
App* app,
|
||||
modular::ApplicationPackagePtr application,
|
||||
modular::ApplicationStartupInfoPtr startup_info,
|
||||
fidl::InterfaceRequest<modular::ApplicationController> controller);
|
||||
|
||||
~ApplicationControllerImpl() override;
|
||||
|
||||
// |modular::ApplicationController| implementation
|
||||
|
||||
void Kill(const KillCallback& callback) override;
|
||||
void Detach() override;
|
||||
|
||||
// |modular::ServiceProvider| implementation
|
||||
|
||||
void ConnectToService(const fidl::String& service_name,
|
||||
mx::channel client_handle) override;
|
||||
|
||||
// |mozart::ViewProvider| implementation
|
||||
|
||||
void CreateView(
|
||||
fidl::InterfaceRequest<mozart::ViewOwner> view_owner_request,
|
||||
fidl::InterfaceRequest<modular::ServiceProvider> services) override;
|
||||
|
||||
private:
|
||||
void StartRuntimeIfReady();
|
||||
|
||||
App* app_;
|
||||
fidl::Binding<modular::ApplicationController> binding_;
|
||||
|
||||
fidl::BindingSet<modular::ServiceProvider> service_provider_bindings_;
|
||||
fidl::BindingSet<mozart::ViewProvider> view_provider_bindings_;
|
||||
|
||||
std::string url_;
|
||||
std::unique_ptr<RuntimeHolder> runtime_holder_;
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(ApplicationControllerImpl);
|
||||
};
|
||||
|
||||
} // namespace flutter_runner
|
||||
|
||||
#endif // FLUTTER_CONTENT_HANDLER_APPLICATION_IMPL_H_
|
||||
@ -1,85 +0,0 @@
|
||||
// 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 "flutter/content_handler/runtime_holder.h"
|
||||
#include "lib/ftl/logging.h"
|
||||
#include "lib/mtl/data_pipe/vector.h"
|
||||
#include "lib/mtl/shared_buffer/vector.h"
|
||||
#include "lib/zip/unzipper.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)) {
|
||||
if (response->body->is_stream()) {
|
||||
// TODO(abarth): Currently we block the UI thread to drain the response body,
|
||||
// but we should do that work asynchronously instead. However, there when I
|
||||
// tried draining the data pipe asynchronously, the drain didn't complete.
|
||||
// We'll need to investigate why in more detail.
|
||||
bool result = mtl::BlockingCopyToVector(std::move(response->body->get_stream()), &bundle_);
|
||||
if (!result) {
|
||||
FTL_LOG(ERROR) << "Failed to receive bundle.";
|
||||
return;
|
||||
}
|
||||
} else if (response->body->is_buffer()) {
|
||||
bool result = mtl::VectorFromSharedBuffer(std::move(response->body->get_buffer()), &bundle_);
|
||||
if (!result) {
|
||||
FTL_LOG(ERROR) << "Failed to receive bundle.";
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
FTL_NOTREACHED();
|
||||
}
|
||||
}
|
||||
|
||||
ApplicationImpl::~ApplicationImpl() {}
|
||||
|
||||
void ApplicationImpl::Initialize(mojo::InterfaceHandle<mojo::Shell> shell,
|
||||
mojo::Array<mojo::String> args,
|
||||
const mojo::String& url) {
|
||||
shell_ = mojo::ShellPtr::Create(shell.Pass());
|
||||
url_ = url;
|
||||
mojo::ApplicationConnectorPtr connector;
|
||||
shell_->CreateApplicationConnector(mojo::GetProxy(&connector));
|
||||
runtime_holder_.reset(new RuntimeHolder());
|
||||
runtime_holder_->Init(std::move(connector), std::move(bundle_));
|
||||
}
|
||||
|
||||
void ApplicationImpl::AcceptConnection(
|
||||
const mojo::String& requestor_url,
|
||||
const mojo::String& resolved_url,
|
||||
mojo::InterfaceRequest<mojo::ServiceProvider> services) {
|
||||
service_provider_bindings_.AddBinding(this, std::move(services));
|
||||
}
|
||||
|
||||
void ApplicationImpl::RequestQuit() {
|
||||
binding_.Close();
|
||||
delete this;
|
||||
}
|
||||
|
||||
void ApplicationImpl::ConnectToService(
|
||||
const mojo::String& service_name,
|
||||
mojo::ScopedMessagePipeHandle client_handle) {
|
||||
if (service_name == mozart::ViewProvider::Name_) {
|
||||
view_provider_bindings_.AddBinding(
|
||||
this,
|
||||
mojo::InterfaceRequest<mozart::ViewProvider>(std::move(client_handle)));
|
||||
}
|
||||
}
|
||||
|
||||
void ApplicationImpl::CreateView(
|
||||
mojo::InterfaceRequest<mozart::ViewOwner> view_owner_request,
|
||||
mojo::InterfaceRequest<mojo::ServiceProvider> services) {
|
||||
runtime_holder_->CreateView(url_, std::move(view_owner_request),
|
||||
std::move(services));
|
||||
}
|
||||
|
||||
} // namespace flutter_content_handler
|
||||
@ -1,70 +0,0 @@
|
||||
// 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 <memory>
|
||||
|
||||
#include "apps/mozart/services/views/interfaces/view_provider.mojom.h"
|
||||
#include "flutter/glue/drain_data_pipe_job.h"
|
||||
#include "lib/ftl/macros.h"
|
||||
#include "mojo/public/cpp/bindings/binding_set.h"
|
||||
#include "mojo/public/cpp/bindings/strong_binding.h"
|
||||
#include "mojo/public/interfaces/application/application.mojom.h"
|
||||
#include "mojo/public/interfaces/application/service_provider.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 RuntimeHolder;
|
||||
|
||||
class ApplicationImpl : public mojo::Application,
|
||||
public mojo::ServiceProvider,
|
||||
public mozart::ViewProvider {
|
||||
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::ServiceProvider
|
||||
void ConnectToService(const mojo::String& service_name,
|
||||
mojo::ScopedMessagePipeHandle client_handle) override;
|
||||
|
||||
// mozart::ViewProvider
|
||||
void CreateView(
|
||||
mojo::InterfaceRequest<mozart::ViewOwner> view_owner_request,
|
||||
mojo::InterfaceRequest<mojo::ServiceProvider> services) override;
|
||||
|
||||
void StartRuntimeIfReady();
|
||||
|
||||
mojo::StrongBinding<mojo::Application> binding_;
|
||||
std::unique_ptr<glue::DrainDataPipeJob> drainer_;
|
||||
|
||||
mojo::BindingSet<mojo::ServiceProvider> service_provider_bindings_;
|
||||
mojo::BindingSet<mozart::ViewProvider> view_provider_bindings_;
|
||||
|
||||
std::vector<char> bundle_;
|
||||
mojo::ShellPtr shell_;
|
||||
std::string url_;
|
||||
|
||||
std::unique_ptr<RuntimeHolder> runtime_holder_;
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl);
|
||||
};
|
||||
|
||||
} // namespace flutter_content_handler
|
||||
|
||||
#endif // FLUTTER_CONTENT_HANDLER_APPLICATION_IMPL_H_
|
||||
@ -1,25 +0,0 @@
|
||||
// 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
|
||||
@ -1,32 +0,0 @@
|
||||
// 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_
|
||||
@ -2,104 +2,12 @@
|
||||
// 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/runtime_init.h"
|
||||
#include "flutter/sky/engine/platform/fonts/fuchsia/FontCacheFuchsia.h"
|
||||
#include "lib/ftl/macros.h"
|
||||
#include "lib/ftl/tasks/task_runner.h"
|
||||
#include "flutter/content_handler/app.h"
|
||||
#include "lib/mtl/tasks/message_loop.h"
|
||||
#include "lib/mtl/threading/create_thread.h"
|
||||
#include "lib/trace_event/tracing_client.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 {
|
||||
|
||||
void QuitMessageLoop() {
|
||||
mtl::MessageLoop::GetCurrent()->QuitNow();
|
||||
}
|
||||
|
||||
class App : public mojo::ApplicationImplBase {
|
||||
public:
|
||||
App() {}
|
||||
~App() override {
|
||||
if (initialized_) {
|
||||
StopThreads();
|
||||
trace_event::DestroyTracer();
|
||||
}
|
||||
}
|
||||
|
||||
// Overridden from ApplicationDelegate:
|
||||
void OnInitialize() override {
|
||||
FTL_DCHECK(!initialized_);
|
||||
initialized_ = true;
|
||||
|
||||
tracing::TraceProviderRegistryPtr registry;
|
||||
ConnectToService(shell(), "mojo:tracing", GetProxy(®istry));
|
||||
trace_event::InitializeTracer(std::move(registry));
|
||||
|
||||
ftl::RefPtr<ftl::TaskRunner> gpu_task_runner;
|
||||
gpu_thread_ = mtl::CreateThread(&gpu_task_runner);
|
||||
|
||||
ftl::RefPtr<ftl::TaskRunner> ui_task_runner(
|
||||
mtl::MessageLoop::GetCurrent()->task_runner());
|
||||
|
||||
ftl::RefPtr<ftl::TaskRunner> io_task_runner;
|
||||
io_thread_ = mtl::CreateThread(&io_task_runner);
|
||||
|
||||
// Notice that the Platform and UI threads are actually the same.
|
||||
blink::Threads::Set(blink::Threads(ui_task_runner, gpu_task_runner,
|
||||
ui_task_runner, io_task_runner));
|
||||
blink::Settings::Set(blink::Settings());
|
||||
blink::InitRuntime();
|
||||
|
||||
mojo::FontProviderPtr font_provider;
|
||||
mojo::ConnectToService(shell(), "mojo:fonts",
|
||||
mojo::GetProxy(&font_provider));
|
||||
blink::SetFontProvider(std::move(font_provider));
|
||||
}
|
||||
|
||||
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:
|
||||
void StopThreads() {
|
||||
FTL_DCHECK(initialized_);
|
||||
blink::Threads::Gpu()->PostTask(QuitMessageLoop);
|
||||
blink::Threads::IO()->PostTask(QuitMessageLoop);
|
||||
gpu_thread_.join();
|
||||
io_thread_.join();
|
||||
}
|
||||
|
||||
bool initialized_ = false;
|
||||
std::thread gpu_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);
|
||||
int main(int argc, const char** argv) {
|
||||
mtl::MessageLoop loop;
|
||||
flutter_runner::App app;
|
||||
loop.Run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -6,12 +6,12 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "apps/mozart/services/composition/interfaces/image.mojom.h"
|
||||
#include "apps/mozart/services/composition/image.fidl.h"
|
||||
#include "flutter/content_handler/skia_surface_holder.h"
|
||||
#include "lib/ftl/logging.h"
|
||||
#include "third_party/skia/include/core/SkCanvas.h"
|
||||
|
||||
namespace flutter_content_handler {
|
||||
namespace flutter_runner {
|
||||
|
||||
namespace {
|
||||
constexpr uint32_t kContentImageResourceId = 1;
|
||||
@ -22,7 +22,7 @@ Rasterizer::Rasterizer() {}
|
||||
|
||||
Rasterizer::~Rasterizer() {}
|
||||
|
||||
void Rasterizer::SetScene(mojo::InterfaceHandle<mozart::Scene> scene) {
|
||||
void Rasterizer::SetScene(fidl::InterfaceHandle<mozart::Scene> scene) {
|
||||
scene_.Bind(std::move(scene));
|
||||
}
|
||||
|
||||
@ -48,14 +48,15 @@ void Rasterizer::Draw(std::unique_ptr<flow::LayerTree> layer_tree,
|
||||
layer_tree->Raster(frame);
|
||||
canvas->flush();
|
||||
|
||||
mojo::RectF bounds;
|
||||
mozart::RectF bounds;
|
||||
bounds.width = frame_size.width();
|
||||
bounds.height = frame_size.height();
|
||||
|
||||
auto content_resource = mozart::Resource::New();
|
||||
content_resource->set_image(mozart::ImageResource::New());
|
||||
content_resource->get_image()->image = surface_holder.TakeImage();
|
||||
update->resources.insert(kContentImageResourceId, content_resource.Pass());
|
||||
update->resources.insert(kContentImageResourceId,
|
||||
std::move(content_resource));
|
||||
|
||||
auto root_node = mozart::Node::New();
|
||||
root_node->hit_test_behavior = mozart::HitTestBehavior::New();
|
||||
@ -63,12 +64,11 @@ void Rasterizer::Draw(std::unique_ptr<flow::LayerTree> layer_tree,
|
||||
root_node->op->set_image(mozart::ImageNodeOp::New());
|
||||
root_node->op->get_image()->content_rect = bounds.Clone();
|
||||
root_node->op->get_image()->image_resource_id = kContentImageResourceId;
|
||||
update->nodes.insert(kRootNodeId, root_node.Pass());
|
||||
update->nodes.insert(kRootNodeId, std::move(root_node));
|
||||
|
||||
layer_tree->UpdateScene(update.get(), root_node.get());
|
||||
} else {
|
||||
auto root_node = mozart::Node::New();
|
||||
update->nodes.insert(kRootNodeId, root_node.Pass());
|
||||
update->nodes.insert(kRootNodeId, mozart::Node::New());
|
||||
}
|
||||
|
||||
scene_->Update(std::move(update));
|
||||
@ -80,4 +80,4 @@ void Rasterizer::Draw(std::unique_ptr<flow::LayerTree> layer_tree,
|
||||
callback();
|
||||
}
|
||||
|
||||
} // namespace flutter_content_handler
|
||||
} // namespace flutter_runner
|
||||
|
||||
@ -5,20 +5,20 @@
|
||||
#ifndef FLUTTER_CONTENT_HANDLER_RASTERIZER_H_
|
||||
#define FLUTTER_CONTENT_HANDLER_RASTERIZER_H_
|
||||
|
||||
#include "apps/mozart/services/composition/interfaces/scenes.mojom.h"
|
||||
#include "apps/mozart/services/composition/scenes.fidl.h"
|
||||
#include "flutter/flow/compositor_context.h"
|
||||
#include "flutter/flow/layers/layer_tree.h"
|
||||
#include "lib/ftl/functional/closure.h"
|
||||
#include "lib/ftl/macros.h"
|
||||
|
||||
namespace flutter_content_handler {
|
||||
namespace flutter_runner {
|
||||
|
||||
class Rasterizer {
|
||||
public:
|
||||
Rasterizer();
|
||||
~Rasterizer();
|
||||
|
||||
void SetScene(mojo::InterfaceHandle<mozart::Scene> scene);
|
||||
void SetScene(fidl::InterfaceHandle<mozart::Scene> scene);
|
||||
|
||||
void Draw(std::unique_ptr<flow::LayerTree> layer_tree, ftl::Closure callback);
|
||||
|
||||
@ -29,6 +29,6 @@ class Rasterizer {
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(Rasterizer);
|
||||
};
|
||||
|
||||
} // namespace flutter_content_handler
|
||||
} // namespace flutter_runner
|
||||
|
||||
#endif // FLUTTER_CONTENT_HANDLER_RASTERIZER_H_
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "apps/modular/lib/app/connect.h"
|
||||
#include "flutter/assets/zip_asset_store.h"
|
||||
#include "flutter/common/threads.h"
|
||||
#include "flutter/content_handler/rasterizer.h"
|
||||
@ -17,9 +18,8 @@
|
||||
#include "lib/ftl/logging.h"
|
||||
#include "lib/ftl/time/time_delta.h"
|
||||
#include "lib/zip/create_unzipper.h"
|
||||
#include "mojo/public/cpp/application/connect.h"
|
||||
|
||||
namespace flutter_content_handler {
|
||||
namespace flutter_runner {
|
||||
namespace {
|
||||
|
||||
constexpr char kSnapshotKey[] = "snapshot_blob.bin";
|
||||
@ -61,20 +61,19 @@ RuntimeHolder::~RuntimeHolder() {
|
||||
}));
|
||||
}
|
||||
|
||||
void RuntimeHolder::Init(mojo::ApplicationConnectorPtr connector,
|
||||
void RuntimeHolder::Init(modular::ServiceProviderPtr environment_services,
|
||||
std::vector<char> bundle) {
|
||||
FTL_DCHECK(!rasterizer_);
|
||||
rasterizer_.reset(new Rasterizer());
|
||||
InitRootBundle(std::move(bundle));
|
||||
|
||||
mojo::ConnectToService(connector.get(), "mojo:view_manager_service",
|
||||
mojo::GetProxy(&view_manager_));
|
||||
ConnectToService(environment_services.get(), fidl::GetProxy(&view_manager_));
|
||||
}
|
||||
|
||||
void RuntimeHolder::CreateView(
|
||||
const std::string& script_uri,
|
||||
mojo::InterfaceRequest<mozart::ViewOwner> view_owner_request,
|
||||
mojo::InterfaceRequest<mojo::ServiceProvider> services) {
|
||||
fidl::InterfaceRequest<mozart::ViewOwner> view_owner_request,
|
||||
fidl::InterfaceRequest<modular::ServiceProvider> services) {
|
||||
if (view_listener_binding_.is_bound()) {
|
||||
// TODO(jeffbrown): Refactor this to support multiple view instances
|
||||
// sharing the same underlying root bundle (but with different runtimes).
|
||||
@ -89,22 +88,22 @@ void RuntimeHolder::CreateView(
|
||||
}
|
||||
|
||||
mozart::ViewListenerPtr view_listener;
|
||||
view_listener_binding_.Bind(mojo::GetProxy(&view_listener));
|
||||
view_manager_->CreateView(mojo::GetProxy(&view_),
|
||||
view_listener_binding_.Bind(fidl::GetProxy(&view_listener));
|
||||
view_manager_->CreateView(fidl::GetProxy(&view_),
|
||||
std::move(view_owner_request),
|
||||
std::move(view_listener), script_uri);
|
||||
|
||||
mojo::ServiceProviderPtr view_services;
|
||||
modular::ServiceProviderPtr view_services;
|
||||
view_->GetServiceProvider(GetProxy(&view_services));
|
||||
|
||||
// Listen for input events.
|
||||
mojo::ConnectToService(view_services.get(), GetProxy(&input_connection_));
|
||||
ConnectToService(view_services.get(), GetProxy(&input_connection_));
|
||||
mozart::InputListenerPtr input_listener;
|
||||
input_listener_binding_.Bind(GetProxy(&input_listener));
|
||||
input_connection_->SetListener(std::move(input_listener));
|
||||
|
||||
mozart::ScenePtr scene;
|
||||
view_->CreateScene(mojo::GetProxy(&scene));
|
||||
view_->CreateScene(fidl::GetProxy(&scene));
|
||||
blink::Threads::Gpu()->PostTask(ftl::MakeCopyable([
|
||||
rasterizer = rasterizer_.get(), scene = std::move(scene)
|
||||
]() mutable { rasterizer->SetScene(std::move(scene)); }));
|
||||
@ -117,7 +116,7 @@ void RuntimeHolder::CreateView(
|
||||
}
|
||||
|
||||
void RuntimeHolder::ScheduleFrame() {
|
||||
if (pending_invalidation_ || !deferred_invalidation_callback_.is_null())
|
||||
if (pending_invalidation_ || deferred_invalidation_callback_)
|
||||
return;
|
||||
pending_invalidation_ = true;
|
||||
view_->Invalidate();
|
||||
@ -207,7 +206,7 @@ void RuntimeHolder::OnEvent(mozart::EventPtr event,
|
||||
runtime_->DispatchPointerDataPacket(packet);
|
||||
handled = true;
|
||||
}
|
||||
callback.Run(handled);
|
||||
callback(handled);
|
||||
}
|
||||
|
||||
void RuntimeHolder::OnInvalidation(mozart::ViewInvalidationPtr invalidation,
|
||||
@ -233,7 +232,7 @@ void RuntimeHolder::OnInvalidation(mozart::ViewInvalidationPtr invalidation,
|
||||
|
||||
// TODO(jeffbrown): Flow the frame time through the rendering pipeline.
|
||||
if (outstanding_requests_ >= kMaxPipelineDepth) {
|
||||
FTL_DCHECK(deferred_invalidation_callback_.is_null());
|
||||
FTL_DCHECK(!deferred_invalidation_callback_);
|
||||
deferred_invalidation_callback_ = callback;
|
||||
return;
|
||||
}
|
||||
@ -245,7 +244,7 @@ void RuntimeHolder::OnInvalidation(mozart::ViewInvalidationPtr invalidation,
|
||||
// Note that this may result in the view processing stale view properties
|
||||
// (such as size) if it prematurely acks the frame but takes too long
|
||||
// to handle it.
|
||||
callback.Run();
|
||||
callback();
|
||||
}
|
||||
|
||||
ftl::WeakPtr<RuntimeHolder> RuntimeHolder::GetWeakPtr() {
|
||||
@ -274,16 +273,16 @@ void RuntimeHolder::OnFrameComplete() {
|
||||
FTL_DCHECK(outstanding_requests_ > 0);
|
||||
--outstanding_requests_;
|
||||
|
||||
if (!deferred_invalidation_callback_.is_null() &&
|
||||
if (deferred_invalidation_callback_ &&
|
||||
outstanding_requests_ <= kRecoveryPipelineDepth) {
|
||||
// Schedule frame first to avoid potentially generating a second
|
||||
// invalidation in case the view manager already has one pending
|
||||
// awaiting acknowledgement of the deferred invalidation.
|
||||
OnInvalidationCallback callback = deferred_invalidation_callback_;
|
||||
deferred_invalidation_callback_.reset();
|
||||
OnInvalidationCallback callback =
|
||||
std::move(deferred_invalidation_callback_);
|
||||
ScheduleFrame();
|
||||
callback.Run();
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace flutter_content_handler
|
||||
} // namespace flutter_runner
|
||||
|
||||
@ -5,8 +5,9 @@
|
||||
#ifndef FLUTTER_CONTENT_HANDLER_RUNTIME_HOLDER_H_
|
||||
#define FLUTTER_CONTENT_HANDLER_RUNTIME_HOLDER_H_
|
||||
|
||||
#include "apps/mozart/services/input/interfaces/input_connection.mojom.h"
|
||||
#include "apps/mozart/services/views/interfaces/view_manager.mojom.h"
|
||||
#include "apps/modular/services/application/service_provider.fidl.h"
|
||||
#include "apps/mozart/services/input/input_connection.fidl.h"
|
||||
#include "apps/mozart/services/views/view_manager.fidl.h"
|
||||
#include "flutter/assets/unzipper_provider.h"
|
||||
#include "flutter/assets/zip_asset_store.h"
|
||||
#include "flutter/flow/layers/layer_tree.h"
|
||||
@ -16,10 +17,9 @@
|
||||
#include "lib/ftl/functional/closure.h"
|
||||
#include "lib/ftl/macros.h"
|
||||
#include "lib/ftl/memory/weak_ptr.h"
|
||||
#include "mojo/public/cpp/bindings/binding.h"
|
||||
#include "mojo/public/interfaces/application/application_connector.mojom.h"
|
||||
#include "lib/fidl/cpp/bindings/binding.h"
|
||||
|
||||
namespace flutter_content_handler {
|
||||
namespace flutter_runner {
|
||||
class Rasterizer;
|
||||
|
||||
class RuntimeHolder : public blink::RuntimeDelegate,
|
||||
@ -29,10 +29,11 @@ class RuntimeHolder : public blink::RuntimeDelegate,
|
||||
RuntimeHolder();
|
||||
~RuntimeHolder();
|
||||
|
||||
void Init(mojo::ApplicationConnectorPtr connector, std::vector<char> bundle);
|
||||
void Init(modular::ServiceProviderPtr environment_services,
|
||||
std::vector<char> bundle);
|
||||
void CreateView(const std::string& script_uri,
|
||||
mojo::InterfaceRequest<mozart::ViewOwner> view_owner_request,
|
||||
mojo::InterfaceRequest<mojo::ServiceProvider> services);
|
||||
fidl::InterfaceRequest<mozart::ViewOwner> view_owner_request,
|
||||
fidl::InterfaceRequest<modular::ServiceProvider> services);
|
||||
|
||||
private:
|
||||
// |blink::RuntimeDelegate| implementation:
|
||||
@ -69,8 +70,8 @@ class RuntimeHolder : public blink::RuntimeDelegate,
|
||||
blink::ViewportMetrics viewport_metrics_;
|
||||
|
||||
mozart::ViewManagerPtr view_manager_;
|
||||
mojo::Binding<mozart::ViewListener> view_listener_binding_;
|
||||
mojo::Binding<mozart::InputListener> input_listener_binding_;
|
||||
fidl::Binding<mozart::ViewListener> view_listener_binding_;
|
||||
fidl::Binding<mozart::InputListener> input_listener_binding_;
|
||||
mozart::InputConnectionPtr input_connection_;
|
||||
mozart::ViewPtr view_;
|
||||
mozart::ViewPropertiesPtr view_properties_;
|
||||
@ -86,6 +87,6 @@ class RuntimeHolder : public blink::RuntimeDelegate,
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(RuntimeHolder);
|
||||
};
|
||||
|
||||
} // namespace flutter_content_handler
|
||||
} // namespace flutter_runner
|
||||
|
||||
#endif // FLUTTER_CONTENT_HANDLER_RUNTIME_HOLDER_H_
|
||||
|
||||
@ -4,45 +4,53 @@
|
||||
|
||||
#include "flutter/content_handler/skia_surface_holder.h"
|
||||
|
||||
#include <mx/process.h>
|
||||
|
||||
#include "lib/ftl/logging.h"
|
||||
#include "mojo/public/cpp/system/buffer.h"
|
||||
#include "third_party/skia/include/core/SkCanvas.h"
|
||||
|
||||
namespace flutter_content_handler {
|
||||
namespace flutter_runner {
|
||||
|
||||
SkiaSurfaceHolder::SkiaSurfaceHolder(const SkISize& size) {
|
||||
size_t row_bytes = size.width() * sizeof(uint32_t);
|
||||
size_t total_bytes = size.height() * row_bytes;
|
||||
|
||||
FTL_CHECK(MOJO_RESULT_OK ==
|
||||
mojo::CreateSharedBuffer(nullptr, total_bytes, &buffer_handle_));
|
||||
FTL_CHECK(MOJO_RESULT_OK == mojo::MapBuffer(buffer_handle_.get(), 0u,
|
||||
total_bytes, &buffer_,
|
||||
MOJO_MAP_BUFFER_FLAG_NONE));
|
||||
mx_status_t rv = mx::vmo::create(total_bytes, 0, &vmo_);
|
||||
FTL_CHECK(rv == NO_ERROR);
|
||||
|
||||
uintptr_t address = 0;
|
||||
rv = mx::process::self().map_vm(vmo_, 0, total_bytes, &address,
|
||||
MX_VM_FLAG_PERM_READ | MX_VM_FLAG_PERM_WRITE);
|
||||
FTL_CHECK(rv == NO_ERROR);
|
||||
|
||||
buffer_ = reinterpret_cast<void*>(address);
|
||||
|
||||
surface_ = SkSurface::MakeRasterDirect(
|
||||
SkImageInfo::Make(size.width(), size.height(), kBGRA_8888_SkColorType,
|
||||
kPremul_SkAlphaType),
|
||||
buffer_, row_bytes);
|
||||
|
||||
FTL_CHECK(surface_);
|
||||
}
|
||||
|
||||
SkiaSurfaceHolder::~SkiaSurfaceHolder() {
|
||||
FTL_CHECK(MOJO_RESULT_OK == mojo::UnmapBuffer(buffer_));
|
||||
mx_status_t rv =
|
||||
mx::process::self().unmap_vm(reinterpret_cast<uintptr_t>(buffer_), 0);
|
||||
FTL_CHECK(rv == NO_ERROR);
|
||||
}
|
||||
|
||||
mozart::ImagePtr SkiaSurfaceHolder::TakeImage() {
|
||||
FTL_DCHECK(buffer_handle_.get().value());
|
||||
FTL_DCHECK(vmo_);
|
||||
|
||||
auto image = mozart::Image::New();
|
||||
image->size = mojo::Size::New();
|
||||
image->size = mozart::Size::New();
|
||||
image->size->width = surface_->width();
|
||||
image->size->height = surface_->height();
|
||||
image->stride = image->size->width * sizeof(uint32_t);
|
||||
image->pixel_format = mozart::Image::PixelFormat::B8G8R8A8;
|
||||
image->alpha_format = mozart::Image::AlphaFormat::PREMULTIPLIED;
|
||||
image->buffer = std::move(buffer_handle_);
|
||||
image->buffer = std::move(vmo_);
|
||||
return image;
|
||||
}
|
||||
|
||||
} // namespace flutter_content_handler
|
||||
} // namespace flutter_runner
|
||||
|
||||
@ -5,13 +5,15 @@
|
||||
#ifndef FLUTTER_CONTENT_HANDLER_SKIA_SURFACE_HOLDER_H_
|
||||
#define FLUTTER_CONTENT_HANDLER_SKIA_SURFACE_HOLDER_H_
|
||||
|
||||
#include "apps/mozart/services/composition/interfaces/image.mojom.h"
|
||||
#include <mx/vmo.h>
|
||||
|
||||
#include "apps/mozart/services/composition/image.fidl.h"
|
||||
#include "apps/mozart/services/geometry/geometry.fidl.h"
|
||||
#include "lib/ftl/macros.h"
|
||||
#include "mojo/services/geometry/interfaces/geometry.mojom.h"
|
||||
#include "third_party/skia/include/core/SkSize.h"
|
||||
#include "third_party/skia/include/core/SkSurface.h"
|
||||
|
||||
namespace flutter_content_handler {
|
||||
namespace flutter_runner {
|
||||
|
||||
// Provides an |SkSurface| backed by a shared memory buffer for software
|
||||
// rendering which can then be passed to the Mozart compositor in the form
|
||||
@ -35,13 +37,13 @@ class SkiaSurfaceHolder {
|
||||
mozart::ImagePtr TakeImage();
|
||||
|
||||
private:
|
||||
mojo::ScopedSharedBufferHandle buffer_handle_;
|
||||
mx::vmo vmo_;
|
||||
void* buffer_;
|
||||
sk_sp<SkSurface> surface_;
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(SkiaSurfaceHolder);
|
||||
};
|
||||
|
||||
} // namespace flutter_content_handler
|
||||
} // namespace flutter_runner
|
||||
|
||||
#endif // FLUTTER_CONTENT_HANDLER_SKIA_SURFACE_HOLDER_H_
|
||||
|
||||
@ -55,8 +55,8 @@ source_set("flow") {
|
||||
"layers/child_scene_layer.h",
|
||||
"texture_image_none.cc",
|
||||
]
|
||||
deps += [
|
||||
"//apps/mozart/services/composition/interfaces",
|
||||
public_deps = [
|
||||
"//apps/mozart/services/composition",
|
||||
]
|
||||
} else {
|
||||
sources += [
|
||||
|
||||
@ -7,9 +7,9 @@
|
||||
namespace flow {
|
||||
namespace {
|
||||
|
||||
mojo::TransformPtr GetTransformFromSkMatrix(const SkMatrix& input) {
|
||||
mozart::TransformPtr GetTransformFromSkMatrix(const SkMatrix& input) {
|
||||
// Expand 3x3 to 4x4.
|
||||
auto output = mojo::Transform::New();
|
||||
auto output = mozart::Transform::New();
|
||||
output->matrix.resize(16u);
|
||||
output->matrix[0] = input[0];
|
||||
output->matrix[1] = input[1];
|
||||
@ -27,7 +27,7 @@ mojo::TransformPtr GetTransformFromSkMatrix(const SkMatrix& input) {
|
||||
output->matrix[13] = input[7];
|
||||
output->matrix[14] = 0.f;
|
||||
output->matrix[15] = input[8];
|
||||
return output.Pass();
|
||||
return output;
|
||||
}
|
||||
|
||||
// TODO(abarth): We need to figure out how to allocate these ids sensibly.
|
||||
@ -58,17 +58,17 @@ void ChildSceneLayer::UpdateScene(mozart::SceneUpdate* update,
|
||||
child_resource->set_scene(mozart::SceneResource::New());
|
||||
child_resource->get_scene()->scene_token = mozart::SceneToken::New();
|
||||
child_resource->get_scene()->scene_token->value = scene_token_;
|
||||
update->resources.insert(id, child_resource.Pass());
|
||||
update->resources.insert(id, std::move(child_resource));
|
||||
|
||||
auto child_node = mozart::Node::New();
|
||||
child_node->op = mozart::NodeOp::New();
|
||||
child_node->op->set_scene(mozart::SceneNodeOp::New());
|
||||
child_node->op->get_scene()->scene_resource_id = id;
|
||||
child_node->content_clip = mojo::RectF::New();
|
||||
child_node->content_clip = mozart::RectF::New();
|
||||
child_node->content_clip->width = physical_size_.width();
|
||||
child_node->content_clip->height = physical_size_.height();
|
||||
child_node->content_transform = GetTransformFromSkMatrix(transform_);
|
||||
update->nodes.insert(id, child_node.Pass());
|
||||
update->nodes.insert(id, std::move(child_node));
|
||||
container->child_node_ids.push_back(id);
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
#define FLUTTER_FLOW_LAYERS_CHILD_SCENE_LAYER_H_
|
||||
|
||||
#include "flutter/flow/layers/layer.h"
|
||||
#include "apps/mozart/services/composition/interfaces/scenes.mojom.h"
|
||||
#include "apps/mozart/services/composition/scenes.fidl.h"
|
||||
|
||||
namespace flow {
|
||||
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
source_set("glue") {
|
||||
sources = [
|
||||
"stack_trace.h",
|
||||
"thread.h",
|
||||
"trace_event.h",
|
||||
]
|
||||
|
||||
@ -15,27 +14,13 @@ source_set("glue") {
|
||||
|
||||
if (is_fuchsia) {
|
||||
sources += [
|
||||
"drain_data_pipe_job.h",
|
||||
"drain_data_pipe_job_fuchsia.cc",
|
||||
"stack_trace_fuchsia.cc",
|
||||
"thread_fuchsia.cc",
|
||||
]
|
||||
|
||||
deps += [
|
||||
"//lib/mtl",
|
||||
"//mojo/public/cpp/environment",
|
||||
"//mojo/public/cpp/system",
|
||||
]
|
||||
|
||||
public_deps = [
|
||||
"//lib/trace_event",
|
||||
]
|
||||
} else {
|
||||
sources += [
|
||||
"stack_trace_base.cc",
|
||||
"task_runner_adaptor.cc",
|
||||
"task_runner_adaptor.h",
|
||||
"thread_base.cc",
|
||||
]
|
||||
|
||||
deps += [
|
||||
|
||||
@ -1,35 +0,0 @@
|
||||
// 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_GLU_DRAIN_DATA_PIPE_JOB_H_
|
||||
#define FLUTTER_GLU_DRAIN_DATA_PIPE_JOB_H_
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "lib/ftl/macros.h"
|
||||
#include "mojo/public/cpp/system/data_pipe.h"
|
||||
|
||||
namespace glue {
|
||||
|
||||
class DrainDataPipeJob {
|
||||
public:
|
||||
using ResultCallback = std::function<void(std::vector<uint8_t>)>;
|
||||
|
||||
DrainDataPipeJob(mojo::ScopedDataPipeConsumerHandle handle,
|
||||
const ResultCallback& callback);
|
||||
~DrainDataPipeJob();
|
||||
|
||||
private:
|
||||
class JobImpl;
|
||||
|
||||
std::unique_ptr<JobImpl> impl_;
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(DrainDataPipeJob);
|
||||
};
|
||||
|
||||
} // namespace glue
|
||||
|
||||
#endif // FLUTTER_GLU_DRAIN_DATA_PIPE_JOB_H_
|
||||
@ -1,45 +0,0 @@
|
||||
// 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/glue/drain_data_pipe_job.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "lib/mtl/data_pipe/data_pipe_drainer.h"
|
||||
|
||||
using mtl::DataPipeDrainer;
|
||||
|
||||
namespace glue {
|
||||
|
||||
class DrainDataPipeJob::JobImpl : public DataPipeDrainer::Client {
|
||||
public:
|
||||
explicit JobImpl(mojo::ScopedDataPipeConsumerHandle handle,
|
||||
const ResultCallback& callback)
|
||||
: callback_(callback), drainer_(this) {
|
||||
drainer_.Start(std::move(handle));
|
||||
}
|
||||
|
||||
private:
|
||||
// mojo::common::DataPipeDrainer::Client
|
||||
void OnDataAvailable(const void* data, size_t num_bytes) override {
|
||||
const uint8_t* bytes = static_cast<const uint8_t*>(data);
|
||||
buffer_.insert(buffer_.end(), bytes, bytes + num_bytes);
|
||||
}
|
||||
|
||||
void OnDataComplete() override { callback_(std::move(buffer_)); }
|
||||
|
||||
std::vector<uint8_t> buffer_;
|
||||
ResultCallback callback_;
|
||||
DataPipeDrainer drainer_;
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(JobImpl);
|
||||
};
|
||||
|
||||
DrainDataPipeJob::DrainDataPipeJob(mojo::ScopedDataPipeConsumerHandle handle,
|
||||
const ResultCallback& callback)
|
||||
: impl_(new JobImpl(std::move(handle), callback)) {}
|
||||
|
||||
DrainDataPipeJob::~DrainDataPipeJob() {}
|
||||
|
||||
} // namespace glue
|
||||
@ -1,34 +0,0 @@
|
||||
// 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_GLU_THREAD_H_
|
||||
#define FLUTTER_GLU_THREAD_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "lib/ftl/tasks/task_runner.h"
|
||||
|
||||
namespace glue {
|
||||
|
||||
class Thread {
|
||||
public:
|
||||
Thread(std::string name);
|
||||
~Thread();
|
||||
|
||||
bool Start();
|
||||
|
||||
const ftl::RefPtr<ftl::TaskRunner>& task_runner() { return task_runner_; }
|
||||
|
||||
private:
|
||||
class ThreadImpl;
|
||||
|
||||
std::unique_ptr<ThreadImpl> impl_;
|
||||
ftl::RefPtr<ftl::TaskRunner> task_runner_;
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(Thread);
|
||||
};
|
||||
|
||||
} // namespace glue
|
||||
|
||||
#endif // FLUTTER_GLU_THREAD_H_
|
||||
@ -1,29 +0,0 @@
|
||||
// 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/glue/thread.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "base/threading/thread.h"
|
||||
#include "flutter/glue/task_runner_adaptor.h"
|
||||
|
||||
namespace glue {
|
||||
|
||||
class Thread::ThreadImpl : public base::Thread {
|
||||
public:
|
||||
ThreadImpl(std::string name) : base::Thread(std::move(name)) {}
|
||||
};
|
||||
|
||||
Thread::Thread(std::string name) : impl_(new ThreadImpl(name)) {}
|
||||
|
||||
Thread::~Thread() {}
|
||||
|
||||
bool Thread::Start() {
|
||||
bool result = impl_->Start();
|
||||
task_runner_ = ftl::MakeRefCounted<TaskRunnerAdaptor>(impl_->task_runner());
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace glue
|
||||
@ -1,27 +0,0 @@
|
||||
// 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/glue/thread.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "lib/mtl/threading/create_thread.h"
|
||||
|
||||
namespace glue {
|
||||
|
||||
class Thread::ThreadImpl {
|
||||
public:
|
||||
std::thread thread_;
|
||||
};
|
||||
|
||||
Thread::Thread(std::string name) : impl_(new ThreadImpl()) {}
|
||||
|
||||
Thread::~Thread() {}
|
||||
|
||||
bool Thread::Start() {
|
||||
impl_->thread_ = mtl::CreateThread(&task_runner_);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace glue
|
||||
@ -3,7 +3,13 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#if defined(__Fuchsia__)
|
||||
#include "lib/trace_event/macros.h"
|
||||
#define TRACE_EVENT0(a, b)
|
||||
#define TRACE_EVENT1(a, b, c, d)
|
||||
#define TRACE_EVENT2(a, b, c, d, e, f)
|
||||
#define TRACE_EVENT_ASYNC_BEGIN0(a, b, c)
|
||||
#define TRACE_EVENT_ASYNC_END0(a, b, c)
|
||||
#define TRACE_EVENT_ASYNC_BEGIN1(a, b, c, d, e)
|
||||
#define TRACE_EVENT_ASYNC_END1(a, b, c, d, e)
|
||||
#else
|
||||
#include "base/trace_event/trace_event.h"
|
||||
#endif // defined(__Fuchsia__)
|
||||
|
||||
@ -290,10 +290,7 @@ source_set("platform") {
|
||||
]
|
||||
|
||||
deps += [
|
||||
"//mojo/public/cpp/bindings",
|
||||
"//mojo/public/cpp/system",
|
||||
"//mojo/services/ui/fonts/interfaces",
|
||||
"//mojo/system",
|
||||
"//apps/fonts/services",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@ -6,13 +6,15 @@
|
||||
|
||||
#include <limits>
|
||||
#include <magenta/syscalls.h>
|
||||
#include <mx/process.h>
|
||||
#include <mx/vmo.h>
|
||||
#include <utility>
|
||||
|
||||
#include "apps/fonts/services/font_provider.fidl.h"
|
||||
#include "flutter/sky/engine/platform/fonts/AlternateFontFamily.h"
|
||||
#include "flutter/sky/engine/platform/fonts/FontCache.h"
|
||||
#include "flutter/sky/engine/platform/fonts/FontDescription.h"
|
||||
#include "lib/ftl/logging.h"
|
||||
#include "mojo/services/ui/fonts/interfaces/font_provider.mojom.h"
|
||||
#include "third_party/skia/include/core/SkData.h"
|
||||
#include "third_party/skia/include/core/SkTypeface.h"
|
||||
#include "third_party/skia/include/ports/SkFontMgr.h"
|
||||
@ -20,7 +22,7 @@
|
||||
namespace blink {
|
||||
namespace {
|
||||
|
||||
uint32_t ToMojoWeight(FontWeight weight) {
|
||||
uint32_t ToIntegerWeight(FontWeight weight) {
|
||||
switch (weight) {
|
||||
case FontWeight100:
|
||||
return 100;
|
||||
@ -45,48 +47,46 @@ uint32_t ToMojoWeight(FontWeight weight) {
|
||||
return 400;
|
||||
}
|
||||
|
||||
mojo::FontSlant ToMojoSlant(FontStyle style) {
|
||||
fonts::FontSlant ToFontSlant(FontStyle style) {
|
||||
switch (style) {
|
||||
case FontStyleNormal:
|
||||
return mojo::FontSlant::UPRIGHT;
|
||||
return fonts::FontSlant::UPRIGHT;
|
||||
case FontStyleItalic:
|
||||
return mojo::FontSlant::ITALIC;
|
||||
return fonts::FontSlant::ITALIC;
|
||||
}
|
||||
ASSERT_NOT_REACHED();
|
||||
return mojo::FontSlant::UPRIGHT;
|
||||
return fonts::FontSlant::UPRIGHT;
|
||||
}
|
||||
|
||||
void UnmapMemory(const void* buffer, void* context) {
|
||||
mx_process_unmap_vm(mx_process_self(), reinterpret_cast<uintptr_t>(buffer),
|
||||
0);
|
||||
mx::process::self().unmap_vm(reinterpret_cast<uintptr_t>(buffer), 0);
|
||||
}
|
||||
|
||||
sk_sp<SkData> MakeSkDataFromVMO(mx_handle_t vmo) {
|
||||
sk_sp<SkData> MakeSkDataFromVMO(const mx::vmo& vmo) {
|
||||
uint64_t size = 0;
|
||||
mx_status_t status = mx_vmo_get_size(vmo, &size);
|
||||
mx_status_t status = vmo.get_size(&size);
|
||||
if (status != NO_ERROR || size > std::numeric_limits<mx_size_t>::max())
|
||||
return nullptr;
|
||||
uintptr_t buffer = 0;
|
||||
status = mx_process_map_vm(mx_process_self(), vmo, 0, size, &buffer,
|
||||
MX_VM_FLAG_PERM_READ);
|
||||
mx::process::self().map_vm(vmo, 0, size, &buffer, MX_VM_FLAG_PERM_READ);
|
||||
if (status != NO_ERROR)
|
||||
return nullptr;
|
||||
return SkData::MakeWithProc(reinterpret_cast<void*>(buffer), size,
|
||||
UnmapMemory, nullptr);
|
||||
}
|
||||
|
||||
mojo::FontProviderPtr* g_font_provider = nullptr;
|
||||
fonts::FontProviderPtr* g_font_provider = nullptr;
|
||||
|
||||
mojo::FontProviderPtr& GetFontProvider() {
|
||||
fonts::FontProviderPtr& GetFontProvider() {
|
||||
FTL_CHECK(g_font_provider);
|
||||
return *g_font_provider;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void SetFontProvider(mojo::FontProviderPtr provider) {
|
||||
void SetFontProvider(fonts::FontProviderPtr provider) {
|
||||
FTL_CHECK(!g_font_provider);
|
||||
g_font_provider = new mojo::FontProviderPtr;
|
||||
g_font_provider = new fonts::FontProviderPtr;
|
||||
*g_font_provider = std::move(provider);
|
||||
}
|
||||
|
||||
@ -106,24 +106,23 @@ sk_sp<SkTypeface> FontCache::createTypeface(
|
||||
name = family.utf8();
|
||||
}
|
||||
|
||||
auto request = mojo::FontRequest::New();
|
||||
auto request = fonts::FontRequest::New();
|
||||
request->family = name.data();
|
||||
request->weight = ToMojoWeight(fontDescription.weight());
|
||||
request->weight = ToIntegerWeight(fontDescription.weight());
|
||||
request->width = static_cast<uint32_t>(fontDescription.stretch());
|
||||
request->slant = ToMojoSlant(fontDescription.style());
|
||||
request->slant = ToFontSlant(fontDescription.style());
|
||||
|
||||
mojo::FontResponsePtr response;
|
||||
fonts::FontResponsePtr response;
|
||||
auto& font_provider = GetFontProvider();
|
||||
font_provider->GetFont(
|
||||
std::move(request),
|
||||
[&response](mojo::FontResponsePtr r) { response = std::move(r); });
|
||||
[&response](fonts::FontResponsePtr r) { response = std::move(r); });
|
||||
font_provider.WaitForIncomingResponse();
|
||||
|
||||
if (!response)
|
||||
return nullptr;
|
||||
|
||||
sk_sp<SkData> data = MakeSkDataFromVMO(
|
||||
static_cast<mx_handle_t>(response->data->vmo.get().value()));
|
||||
sk_sp<SkData> data = MakeSkDataFromVMO(response->data->vmo);
|
||||
if (!data)
|
||||
return nullptr;
|
||||
|
||||
|
||||
@ -5,11 +5,11 @@
|
||||
#ifndef SKY_ENGINE_PLATFORM_FONTS_FUCHSIA_FONT_CACHE_FUCHSIA_H_
|
||||
#define SKY_ENGINE_PLATFORM_FONTS_FUCHSIA_FONT_CACHE_FUCHSIA_H_
|
||||
|
||||
#include "mojo/services/ui/fonts/interfaces/font_provider.mojom.h"
|
||||
#include "apps/fonts/services/font_provider.fidl.h"
|
||||
|
||||
namespace blink {
|
||||
|
||||
void SetFontProvider(mojo::FontProviderPtr provider);
|
||||
void SetFontProvider(fonts::FontProviderPtr provider);
|
||||
|
||||
} // namespace blink
|
||||
|
||||
|
||||
@ -254,9 +254,4 @@ executable("unittests") {
|
||||
":wtf",
|
||||
"//third_party/gtest",
|
||||
]
|
||||
|
||||
if (is_fuchsia) {
|
||||
# TODO(abarth): This shouldn't be necessary.
|
||||
deps += [ "//mojo/system" ]
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user