Skip to content

Commit

Permalink
Port flutter content handler to FIDL2. (flutter#4903)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Brown authored and abarth committed Mar 30, 2018
1 parent 94cdd81 commit ac552fb
Show file tree
Hide file tree
Showing 27 changed files with 227 additions and 233 deletions.
5 changes: 2 additions & 3 deletions content_handler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ template("flutter_content_handler") {
"//garnet/public/lib/svc/cpp",
"//garnet/public/lib/ui/input/fidl",
"//garnet/public/lib/ui/scenic:client",
"//garnet/public/lib/ui/views/fidl",
"//garnet/public/lib/ui/views/fidl:v1",
"//garnet/public/lib/vulkan",
"//garnet/public/lib/zip",
"//peridot/public/lib/clipboard/fidl",
"//peridot/public/lib/context/fidl",
"//peridot/public/lib:fidl",
"//third_party/rapidjson",
"//third_party/skia",
"//topaz/lib/tonic",
Expand Down
3 changes: 1 addition & 2 deletions content_handler/accessibility_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "flutter/lib/ui/semantics/semantics_node.h"
#include "lib/app/cpp/application_context.h"
#include "lib/context/fidl/context_writer.fidl.h"
#include "lib/fxl/macros.h"
#include "third_party/rapidjson/rapidjson/document.h"
#include "third_party/rapidjson/rapidjson/stringbuffer.h"
Expand All @@ -17,7 +16,7 @@
namespace flutter_runner {

AccessibilityBridge::AccessibilityBridge(component::ApplicationContext* context)
: writer_(context->ConnectToEnvironmentService<maxwell::ContextWriter>()) {}
: writer_(context->ConnectToEnvironmentService<modular::ContextWriter>()) {}

void AccessibilityBridge::UpdateSemantics(
const blink::SemanticsNodeUpdates& update) {
Expand Down
4 changes: 2 additions & 2 deletions content_handler/accessibility_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "flutter/lib/ui/semantics/semantics_node.h"
#include "lib/app/cpp/application_context.h"
#include "lib/context/fidl/context_writer.fidl.h"
#include <fuchsia/cpp/modular.h>

namespace flutter_runner {

Expand All @@ -34,7 +34,7 @@ class AccessibilityBridge {
void EraseUnvisitedNodes(const std::vector<int>& visited_nodes);

std::map<int, blink::SemanticsNode> semantics_nodes_;
maxwell::ContextWriterPtr writer_;
modular::ContextWriterPtr writer_;
};

} // namespace flutter_runner
Expand Down
10 changes: 5 additions & 5 deletions content_handler/app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ App::App() {
}

context_->outgoing_services()->AddService<component::ApplicationRunner>(
[this](f1dl::InterfaceRequest<component::ApplicationRunner> request) {
[this](fidl::InterfaceRequest<component::ApplicationRunner> request) {
runner_bindings_.AddBinding(this, std::move(request));
});
}
Expand Down Expand Up @@ -129,12 +129,12 @@ void App::WaitForPlatformViewsIdsUIThread(
}

void App::StartApplication(
component::ApplicationPackagePtr application,
component::ApplicationStartupInfoPtr startup_info,
f1dl::InterfaceRequest<component::ApplicationController> controller) {
component::ApplicationPackage application,
component::ApplicationStartupInfo startup_info,
fidl::InterfaceRequest<component::ApplicationController> controller) {
if (controllers_.empty()) {
// Name this process after the url of the first application being launched.
base_label_ = "flutter:" + GetLabelFromURL(startup_info->launch_info->url);
base_label_ = "flutter:" + GetLabelFromURL(startup_info.launch_info.url);
}

std::unique_ptr<ApplicationControllerImpl> impl =
Expand Down
10 changes: 5 additions & 5 deletions content_handler/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "flutter/content_handler/application_controller_impl.h"
#include "lib/app/cpp/application_context.h"
#include "lib/app/fidl/application_runner.fidl.h"
#include <fuchsia/cpp/component.h>
#include "lib/fsl/threading/thread.h"
#include "lib/fxl/macros.h"
#include "lib/fxl/synchronization/waitable_event.h"
Expand All @@ -27,9 +27,9 @@ class App : public component::ApplicationRunner {
// |component::ApplicationRunner| implementation:

void StartApplication(
component::ApplicationPackagePtr application,
component::ApplicationStartupInfoPtr startup_info,
f1dl::InterfaceRequest<component::ApplicationController> controller) override;
component::ApplicationPackage application,
component::ApplicationStartupInfo startup_info,
fidl::InterfaceRequest<component::ApplicationController> controller) override;

void Destroy(ApplicationControllerImpl* controller);

Expand All @@ -50,7 +50,7 @@ class App : public component::ApplicationRunner {
std::unique_ptr<component::ApplicationContext> context_;
std::unique_ptr<fsl::Thread> gpu_thread_;
std::unique_ptr<fsl::Thread> io_thread_;
f1dl::BindingSet<component::ApplicationRunner> runner_bindings_;
fidl::BindingSet<component::ApplicationRunner> runner_bindings_;
std::unordered_map<ApplicationControllerImpl*,
std::unique_ptr<ApplicationControllerImpl>>
controllers_;
Expand Down
42 changes: 21 additions & 21 deletions content_handler/application_controller_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ namespace flutter_runner {

ApplicationControllerImpl::ApplicationControllerImpl(
App* app,
component::ApplicationPackagePtr application,
component::ApplicationStartupInfoPtr startup_info,
f1dl::InterfaceRequest<component::ApplicationController> controller)
component::ApplicationPackage application,
component::ApplicationStartupInfo startup_info,
fidl::InterfaceRequest<component::ApplicationController> controller)
: app_(app), binding_(this) {
if (controller.is_valid()) {
binding_.Bind(std::move(controller));
Expand All @@ -32,8 +32,8 @@ ApplicationControllerImpl::ApplicationControllerImpl(
}

std::vector<char> bundle;
if (application->data) {
if (!fsl::VectorFromVmo(std::move(application->data), &bundle)) {
if (application.data) {
if (!fsl::VectorFromVmo(std::move(*application.data), &bundle)) {
FXL_LOG(ERROR) << "Failed to receive bundle.";
return;
}
Expand All @@ -42,27 +42,27 @@ ApplicationControllerImpl::ApplicationControllerImpl(
// TODO(jeffbrown): Decide what to do with command-line arguments and
// startup handles.

if (startup_info->launch_info->directory_request.is_valid()) {
if (startup_info.launch_info.directory_request.is_valid()) {
service_provider_bridge_.ServeDirectory(
std::move(startup_info->launch_info->directory_request));
std::move(startup_info.launch_info.directory_request));
}

service_provider_bridge_.AddService<mozart::ViewProvider>(
[this](f1dl::InterfaceRequest<mozart::ViewProvider> request) {
service_provider_bridge_.AddService<views_v1::ViewProvider>(
[this](fidl::InterfaceRequest<views_v1::ViewProvider> request) {
view_provider_bindings_.AddBinding(this, std::move(request));
});

component::ServiceProviderPtr service_provider;
auto request = service_provider.NewRequest();
service_provider_bridge_.set_backend(std::move(service_provider));

fdio_ns_t* fdio_ns = SetupNamespace(startup_info->flat_namespace);
fdio_ns_t* fdio_ns = SetupNamespace(std::move(startup_info.flat_namespace));
if (fdio_ns == nullptr) {
FXL_LOG(ERROR) << "Failed to initialize namespace";
return;
}

url_ = startup_info->launch_info->url;
url_ = startup_info.launch_info.url;
runtime_holder_.reset(new RuntimeHolder());
runtime_holder_->SetMainIsolateShutdownCallback([this]() { Kill(); });
runtime_holder_->Init(
Expand All @@ -75,24 +75,24 @@ ApplicationControllerImpl::~ApplicationControllerImpl() = default;
constexpr char kServiceRootPath[] = "/svc";

fdio_ns_t* ApplicationControllerImpl::SetupNamespace(
const component::FlatNamespacePtr& flat) {
component::FlatNamespace flat) {
fdio_ns_t* fdio_namespc;
zx_status_t status = fdio_ns_create(&fdio_namespc);
if (status != ZX_OK) {
FXL_LOG(ERROR) << "Failed to create namespace";
return nullptr;
}
for (size_t i = 0; i < flat->paths->size(); ++i) {
if (flat->paths->at(i) == kServiceRootPath) {
for (size_t i = 0; i < flat.paths->size(); ++i) {
if (flat.paths->at(i) == kServiceRootPath) {
// Ownership of /svc goes to the ApplicationContext created above.
continue;
}
zx::channel dir = std::move(flat->directories->at(i));
zx::channel dir = std::move(flat.directories->at(i));
zx_handle_t dir_handle = dir.release();
const char* path = flat->paths->at(i)->data();
const char* path = flat.paths->at(i)->data();
status = fdio_ns_bind(fdio_namespc, path, dir_handle);
if (status != ZX_OK) {
FXL_LOG(ERROR) << "Failed to bind " << flat->paths->at(i)
FXL_LOG(ERROR) << "Failed to bind " << flat.paths->at(i)
<< " to namespace";
zx_handle_close(dir_handle);
fdio_ns_destroy(fdio_namespc);
Expand All @@ -113,8 +113,8 @@ void ApplicationControllerImpl::Detach() {
binding_.set_error_handler(fxl::Closure());
}

void ApplicationControllerImpl::Wait(const WaitCallback& callback) {
wait_callbacks_.push_back(callback);
void ApplicationControllerImpl::Wait(WaitCallback callback) {
wait_callbacks_.push_back(std::move(callback));
}

void ApplicationControllerImpl::SendReturnCode(int32_t return_code) {
Expand All @@ -125,8 +125,8 @@ void ApplicationControllerImpl::SendReturnCode(int32_t return_code) {
}

void ApplicationControllerImpl::CreateView(
f1dl::InterfaceRequest<mozart::ViewOwner> view_owner_request,
f1dl::InterfaceRequest<component::ServiceProvider> services) {
fidl::InterfaceRequest<views_v1_token::ViewOwner> view_owner_request,
fidl::InterfaceRequest<component::ServiceProvider> services) {
runtime_holder_->CreateView(url_, std::move(view_owner_request),
std::move(services));
}
Expand Down
34 changes: 17 additions & 17 deletions content_handler/application_controller_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,43 @@

#include <fdio/namespace.h>

#include "lib/app/fidl/application_controller.fidl.h"
#include "lib/app/fidl/application_runner.fidl.h"
#include "lib/app/fidl/service_provider.fidl.h"
#include "lib/fidl/cpp/bindings/binding.h"
#include "lib/fidl/cpp/bindings/binding_set.h"
#include <fuchsia/cpp/component.h>
#include <fuchsia/cpp/ui.h>
#include <fuchsia/cpp/views_v1.h>

#include "lib/fidl/cpp/binding.h"
#include "lib/fidl/cpp/binding_set.h"
#include "lib/fxl/macros.h"
#include "lib/fxl/synchronization/waitable_event.h"
#include "lib/svc/cpp/service_provider_bridge.h"
#include "lib/ui/views/fidl/view_provider.fidl.h"
#include "third_party/dart/runtime/include/dart_api.h"

namespace flutter_runner {
class App;
class RuntimeHolder;

class ApplicationControllerImpl : public component::ApplicationController,
public mozart::ViewProvider {
public views_v1::ViewProvider {
public:
ApplicationControllerImpl(
App* app,
component::ApplicationPackagePtr application,
component::ApplicationStartupInfoPtr startup_info,
f1dl::InterfaceRequest<component::ApplicationController> controller);
component::ApplicationPackage application,
component::ApplicationStartupInfo startup_info,
fidl::InterfaceRequest<component::ApplicationController> controller);

~ApplicationControllerImpl() override;

// |component::ApplicationController| implementation

void Kill() override;
void Detach() override;
void Wait(const WaitCallback& callback) override;
void Wait(WaitCallback callback) override;

// |mozart::ViewProvider| implementation
// |views_v1::ViewProvider| implementation

void CreateView(
f1dl::InterfaceRequest<mozart::ViewOwner> view_owner_request,
f1dl::InterfaceRequest<component::ServiceProvider> services) override;
fidl::InterfaceRequest<views_v1_token::ViewOwner> view_owner_request,
fidl::InterfaceRequest<component::ServiceProvider> services) override;

Dart_Port GetUIIsolateMainPort();
std::string GetUIIsolateName();
Expand All @@ -54,14 +54,14 @@ class ApplicationControllerImpl : public component::ApplicationController,
void StartRuntimeIfReady();
void SendReturnCode(int32_t return_code);

fdio_ns_t* SetupNamespace(const component::FlatNamespacePtr& flat);
fdio_ns_t* SetupNamespace(component::FlatNamespace flat);

App* app_;
f1dl::Binding<component::ApplicationController> binding_;
fidl::Binding<component::ApplicationController> binding_;

component::ServiceProviderBridge service_provider_bridge_;

f1dl::BindingSet<mozart::ViewProvider> view_provider_bindings_;
fidl::BindingSet<views_v1::ViewProvider> view_provider_bindings_;

std::string url_;
std::unique_ptr<RuntimeHolder> runtime_holder_;
Expand Down
22 changes: 11 additions & 11 deletions content_handler/fuchsia_font_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ void UnmapMemory(const void* buffer, void* context) {
zx::vmar::root_self().unmap(reinterpret_cast<uintptr_t>(buffer), size);
}

sk_sp<SkData> MakeSkDataFromVMO(const fsl::SizedVmoTransportPtr& vmo) {
if (!fsl::SizedVmo::IsSizeValid(vmo->vmo, vmo->size) ||
vmo->size > std::numeric_limits<size_t>::max()) {
sk_sp<SkData> MakeSkDataFromVMO(fsl::SizedVmoTransport vmo) {
if (!fsl::SizedVmo::IsSizeValid(vmo.vmo, vmo.size) ||
vmo.size > std::numeric_limits<size_t>::max()) {
return nullptr;
}
uint64_t size = vmo->size;
uint64_t size = vmo.size;
uintptr_t buffer = 0;
zx_status_t status = zx::vmar::root_self().map(0, vmo->vmo, 0, size,
zx_status_t status = zx::vmar::root_self().map(0, vmo.vmo, 0, size,
ZX_VM_FLAG_PERM_READ, &buffer);
if (status != ZX_OK)
return nullptr;
Expand Down Expand Up @@ -88,11 +88,11 @@ SkFontStyleSet* FuchsiaFontManager::onMatchFamily(

SkTypeface* FuchsiaFontManager::onMatchFamilyStyle(
const char family_name[], const SkFontStyle& style) const {
auto request = fonts::FontRequest::New();
request->family = family_name;
request->weight = style.weight();
request->width = style.width();
request->slant = ToFontSlant(style.slant());
fonts::FontRequest request;
request.family = family_name;
request.weight = style.weight();
request.width = style.width();
request.slant = ToFontSlant(style.slant());

fonts::FontResponsePtr response;
font_provider_->GetFont(
Expand All @@ -107,7 +107,7 @@ SkTypeface* FuchsiaFontManager::onMatchFamilyStyle(
if (!response)
return nullptr;

sk_sp<SkData> data = MakeSkDataFromVMO(response->data->vmo);
sk_sp<SkData> data = MakeSkDataFromVMO(std::move(response->data.vmo));
if (!data)
return nullptr;

Expand Down
2 changes: 1 addition & 1 deletion content_handler/fuchsia_font_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define TXT_FUCHSIA_FONT_MANAGER_H_

#include <memory>
#include "lib/fonts/fidl/font_provider.fidl.h"
#include <fuchsia/cpp/fonts.h>
#include "lib/fxl/macros.h"
#include "third_party/skia/include/core/SkStream.h"
#include "third_party/skia/include/core/SkTypeface.h"
Expand Down
2 changes: 1 addition & 1 deletion content_handler/rasterizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Rasterizer {
static std::unique_ptr<Rasterizer> Create();

virtual void SetScene(
f1dl::InterfaceHandle<ui::Scenic> mozart,
fidl::InterfaceHandle<ui::Scenic> mozart,
zx::eventpair import_token,
fxl::Closure metrics_changed_callback) = 0;

Expand Down
Loading

0 comments on commit ac552fb

Please sign in to comment.