未验证 提交 79b9ffb1 编写于 作者: C Chinmay Garde 提交者: GitHub

Fixup Fuchsia content handler post shell refactor. (#5072)

上级 ec611470
......@@ -7,14 +7,13 @@
#include <unordered_set>
#include "lib/app/cpp/application_context.h"
#include "lib/context/fidl/context_writer.fidl.h"
#include "third_party/rapidjson/rapidjson/document.h"
#include "third_party/rapidjson/rapidjson/stringbuffer.h"
#include "third_party/rapidjson/rapidjson/writer.h"
namespace flutter {
AccessibilityBridge::AccessibilityBridge(maxwell::ContextWriterPtr writer)
AccessibilityBridge::AccessibilityBridge(modular::ContextWriterPtr writer)
: writer_(std::move(writer)) {}
AccessibilityBridge::~AccessibilityBridge() = default;
......
......@@ -6,8 +6,9 @@
#include <map>
#include <fuchsia/cpp/modular.h>
#include "flutter/lib/ui/semantics/semantics_node.h"
#include "lib/context/fidl/context_writer.fidl.h"
#include "lib/fxl/macros.h"
namespace flutter {
......@@ -16,7 +17,7 @@ namespace flutter {
// with the Context Service.
class AccessibilityBridge final {
public:
AccessibilityBridge(maxwell::ContextWriterPtr writer);
AccessibilityBridge(modular::ContextWriterPtr writer);
~AccessibilityBridge();
......@@ -25,7 +26,7 @@ class AccessibilityBridge final {
void UpdateSemantics(const blink::SemanticsNodeUpdates& update);
private:
maxwell::ContextWriterPtr writer_;
modular::ContextWriterPtr writer_;
std::map<int, blink::SemanticsNode> semantics_nodes_;
// Walk the semantics node tree starting at |id|, and store the id of each
......
......@@ -21,9 +21,9 @@ namespace flutter {
std::pair<std::unique_ptr<fsl::Thread>, std::unique_ptr<Application>>
Application::Create(
Application::Delegate& delegate,
component::ApplicationPackagePtr package,
component::ApplicationStartupInfoPtr startup_info,
f1dl::InterfaceRequest<component::ApplicationController> controller) {
component::ApplicationPackage package,
component::ApplicationStartupInfo startup_info,
fidl::InterfaceRequest<component::ApplicationController> controller) {
auto thread = std::make_unique<fsl::Thread>();
std::unique_ptr<Application> application;
......@@ -52,52 +52,48 @@ static std::string DebugLabelForURL(const std::string url) {
Application::Application(
Application::Delegate& delegate,
component::ApplicationPackagePtr package,
component::ApplicationStartupInfoPtr startup_info,
f1dl::InterfaceRequest<component::ApplicationController>
component::ApplicationPackage,
component::ApplicationStartupInfo startup_info,
fidl::InterfaceRequest<component::ApplicationController>
application_controller_request)
: delegate_(delegate),
debug_label_(DebugLabelForURL(startup_info->launch_info->url)),
debug_label_(DebugLabelForURL(startup_info.launch_info.url)),
application_controller_(this) {
application_controller_.set_error_handler([this]() { Kill(); });
FXL_DCHECK(fdio_ns_.is_valid());
// ApplicationLaunchInfo::url non-optional.
auto& launch_info = startup_info->launch_info;
auto& launch_info = startup_info.launch_info;
// ApplicationLaunchInfo::arguments optional.
if (auto& arguments = launch_info->arguments) {
if (auto& arguments = launch_info.arguments) {
settings_ = shell::SettingsFromCommandLine(
fxl::CommandLineFromIterators(arguments->begin(), arguments->end()));
}
// TODO: ApplicationLaunchInfo::out optional.
// TODO: ApplicationLaunchInfo::out.
// TODO: ApplicationLaunchInfo::err optional.
// TODO: ApplicationLaunchInfo::err.
// ApplicationLaunchInfo::service_request optional.
if (launch_info->directory_request) {
if (launch_info.directory_request) {
service_provider_bridge_.ServeDirectory(
std::move(launch_info->directory_request));
std::move(launch_info.directory_request));
}
// ApplicationLaunchInfo::flat_namespace optional.
if (auto& flat_namespace = startup_info->flat_namespace) {
for (size_t i = 0; i < flat_namespace->paths->size(); ++i) {
const auto& path = flat_namespace->paths->at(i);
if (path == "/svc") {
continue;
}
zx::channel dir = std::move(flat_namespace->directories->at(i));
zx_handle_t dir_handle = dir.release();
if (fdio_ns_bind(fdio_ns_.get(), path->data(), dir_handle) != ZX_OK) {
FXL_DLOG(ERROR) << "Could not bind path to namespace: " << path;
zx_handle_close(dir_handle);
}
for (size_t i = 0; i < startup_info.flat_namespace.paths->size(); ++i) {
const auto& path = startup_info.flat_namespace.paths->at(i);
if (path == "/svc") {
continue;
}
zx::channel dir = std::move(startup_info.flat_namespace.directories->at(i));
zx_handle_t dir_handle = dir.release();
if (fdio_ns_bind(fdio_ns_.get(), path->data(), dir_handle) != ZX_OK) {
FXL_DLOG(ERROR) << "Could not bind path to namespace: " << path;
zx_handle_close(dir_handle);
}
} else {
FXL_DLOG(ERROR) << "There was no flat namespace.";
}
application_directory_.reset(fdio_ns_opendir(fdio_ns_.get()));
......@@ -108,15 +104,11 @@ Application::Application(
// TODO: ApplicationLaunchInfo::additional_services optional.
// ApplicationPackage::data: This is legacy FLX data. Ensure that we dont have
// any.
FXL_DCHECK(!package->data) << "Legacy FLX data must not be supplied.";
// All launch arguments have been read. Perform service binding and
// final settings configuration. The next call will be to create a view
// for this application.
service_provider_bridge_.AddService<mozart::ViewProvider>(
service_provider_bridge_.AddService<views_v1::ViewProvider>(
std::bind(&Application::CreateShellForView, this, std::placeholders::_1));
component::ServiceProviderPtr outgoing_services;
......@@ -193,10 +185,10 @@ void Application::AttemptVMLaunchWithCurrentSettings(
return;
}
auto lib = fxl::MakeRefCounted<fml::NativeLibrary>(
library_handle, // library handle
true // close the handle when done
);
auto lib =
fml::NativeLibrary::CreateWithHandle(library_handle, // library handle
true // close the handle when done
);
auto symbol = [](const char* str) {
return std::string{"_"} + std::string{str};
......@@ -248,7 +240,7 @@ void Application::Detach() {
}
// |component::ApplicationController|
void Application::Wait(const WaitCallback& callback) {
void Application::Wait(WaitCallback callback) {
wait_callbacks_.emplace_back(std::move(callback));
}
......@@ -281,14 +273,14 @@ void Application::OnEngineTerminate(const Engine* shell_holder) {
}
void Application::CreateShellForView(
f1dl::InterfaceRequest<mozart::ViewProvider> view_provider_request) {
fidl::InterfaceRequest<views_v1::ViewProvider> view_provider_request) {
shells_bindings_.AddBinding(this, std::move(view_provider_request));
}
// |mozart::ViewProvider|
// |views_v1::ViewProvider|
void Application::CreateView(
f1dl::InterfaceRequest<mozart::ViewOwner> view_owner,
f1dl::InterfaceRequest<component::ServiceProvider>) {
fidl::InterfaceRequest<views_v1_token::ViewOwner> view_owner,
fidl::InterfaceRequest<component::ServiceProvider>) {
if (!application_context_) {
FXL_DLOG(ERROR) << "Application context was invalid when attempting to "
"create a shell for a view provider request.";
......
......@@ -8,16 +8,19 @@
#include <memory>
#include <set>
#include <fuchsia/cpp/component.h>
#include <fuchsia/cpp/views_v1.h>
#include <fuchsia/cpp/views_v1_token.h>
#include "engine.h"
#include "flutter/common/settings.h"
#include "lib/app/cpp/application_context.h"
#include "lib/app/fidl/application_controller.fidl.h"
#include "lib/fidl/cpp/bindings/binding_set.h"
#include "lib/fidl/cpp/binding_set.h"
#include "lib/fidl/cpp/interface_request.h"
#include "lib/fsl/threading/thread.h"
#include "lib/fxl/files/unique_fd.h"
#include "lib/fxl/macros.h"
#include "lib/svc/cpp/service_provider_bridge.h"
#include "lib/ui/views/fidl/view_provider.fidl.h"
#include "unique_fdio_ns.h"
namespace flutter {
......@@ -26,7 +29,7 @@ namespace flutter {
// Flutter engine instances.
class Application final : public Engine::Delegate,
public component::ApplicationController,
public mozart::ViewProvider {
public views_v1::ViewProvider {
public:
class Delegate {
public:
......@@ -38,9 +41,9 @@ class Application final : public Engine::Delegate,
// This is a synchronous operation.
static std::pair<std::unique_ptr<fsl::Thread>, std::unique_ptr<Application>>
Create(Application::Delegate& delegate,
component::ApplicationPackagePtr package,
component::ApplicationStartupInfoPtr startup_info,
f1dl::InterfaceRequest<component::ApplicationController> controller);
component::ApplicationPackage package,
component::ApplicationStartupInfo startup_info,
fidl::InterfaceRequest<component::ApplicationController> controller);
// Must be called on the same thread returned from the create call. The thread
// may be collected after.
......@@ -53,20 +56,20 @@ class Application final : public Engine::Delegate,
UniqueFDIONS fdio_ns_ = UniqueFDIONSCreate();
fxl::UniqueFD application_directory_;
fxl::UniqueFD application_assets_directory_;
f1dl::Binding<component::ApplicationController> application_controller_;
f1dl::InterfaceRequest<component::ServiceProvider> outgoing_services_request_;
fidl::Binding<component::ApplicationController> application_controller_;
fidl::InterfaceRequest<component::ServiceProvider> outgoing_services_request_;
component::ServiceProviderBridge service_provider_bridge_;
std::unique_ptr<component::ApplicationContext> application_context_;
f1dl::BindingSet<mozart::ViewProvider> shells_bindings_;
fidl::BindingSet<views_v1::ViewProvider> shells_bindings_;
std::set<std::unique_ptr<Engine>> shell_holders_;
std::vector<WaitCallback> wait_callbacks_;
std::pair<bool, uint32_t> last_return_code_;
Application(
Application::Delegate& delegate,
component::ApplicationPackagePtr package,
component::ApplicationStartupInfoPtr startup_info,
f1dl::InterfaceRequest<component::ApplicationController> controller);
component::ApplicationPackage package,
component::ApplicationStartupInfo startup_info,
fidl::InterfaceRequest<component::ApplicationController> controller);
// |component::ApplicationController|
void Kill() override;
......@@ -75,18 +78,18 @@ class Application final : public Engine::Delegate,
void Detach() override;
// |component::ApplicationController|
void Wait(const WaitCallback& callback) override;
void Wait(WaitCallback callback) override;
// |mozart::ViewProvider|
// |views_v1::ViewProvider|
void CreateView(
f1dl::InterfaceRequest<mozart::ViewOwner> view_owner,
f1dl::InterfaceRequest<component::ServiceProvider> services) override;
fidl::InterfaceRequest<views_v1_token::ViewOwner> view_owner,
fidl::InterfaceRequest<component::ServiceProvider> services) override;
// |flutter::Engine::Delegate|
void OnEngineTerminate(const Engine* holder) override;
void CreateShellForView(
f1dl::InterfaceRequest<mozart::ViewProvider> view_provider_request);
fidl::InterfaceRequest<views_v1::ViewProvider> view_provider_request);
void AttemptVMLaunchWithCurrentSettings(
const blink::Settings& settings) const;
......
......@@ -8,7 +8,6 @@
#include "flutter/lib/ui/text/font_collection.h"
#include "fuchsia_font_manager.h"
#include "lib/fonts/fidl/font_provider.fidl.h"
#include "lib/icu_data/cpp/icu_data.h"
namespace flutter {
......@@ -38,14 +37,14 @@ ApplicationRunner::~ApplicationRunner() {
}
void ApplicationRunner::RegisterApplication(
f1dl::InterfaceRequest<component::ApplicationRunner> request) {
fidl::InterfaceRequest<component::ApplicationRunner> request) {
active_applications_bindings_.AddBinding(this, std::move(request));
}
void ApplicationRunner::StartApplication(
component::ApplicationPackagePtr package,
component::ApplicationStartupInfoPtr startup_info,
f1dl::InterfaceRequest<component::ApplicationController> controller) {
component::ApplicationPackage package,
component::ApplicationStartupInfo startup_info,
fidl::InterfaceRequest<component::ApplicationController> controller) {
auto thread_application_pair =
Application::Create(*this, // delegate
std::move(package), // application pacakge
......
......@@ -7,10 +7,11 @@
#include <memory>
#include <unordered_map>
#include <fuchsia/cpp/component.h>
#include "application.h"
#include "lib/app/cpp/application_context.h"
#include "lib/app/fidl/application_runner.fidl.h"
#include "lib/fidl/cpp/bindings/binding_set.h"
#include "lib/fidl/cpp/binding_set.h"
#include "lib/fsl/tasks/message_loop.h"
#include "lib/fxl/functional/make_copyable.h"
#include "lib/fxl/macros.h"
......@@ -49,18 +50,18 @@ class ApplicationRunner final : public Application::Delegate,
fxl::Closure on_termination_callback_;
std::unique_ptr<component::ApplicationContext> host_context_;
f1dl::BindingSet<component::ApplicationRunner> active_applications_bindings_;
fidl::BindingSet<component::ApplicationRunner> active_applications_bindings_;
std::unordered_map<const Application*, ActiveApplication>
active_applications_;
// |component::ApplicationRunner|
void StartApplication(component::ApplicationPackagePtr application,
component::ApplicationStartupInfoPtr startup_info,
f1dl::InterfaceRequest<component::ApplicationController>
void StartApplication(component::ApplicationPackage application,
component::ApplicationStartupInfo startup_info,
fidl::InterfaceRequest<component::ApplicationController>
controller) override;
void RegisterApplication(
f1dl::InterfaceRequest<component::ApplicationRunner> request);
fidl::InterfaceRequest<component::ApplicationRunner> request);
void UnregisterApplication(const Application* application);
......
......@@ -4,8 +4,9 @@
#pragma once
#include <fuchsia/cpp/ui.h>
#include "flutter/flow/compositor_context.h"
#include "garnet/public/lib/ui/scenic/fidl/scenic.fidl-common.h"
#include "lib/fxl/macros.h"
#include "session_connection.h"
......
......@@ -15,19 +15,15 @@
#include "lib/fxl/synchronization/waitable_event.h"
#include "platform_view.h"
#ifdef ERROR
#undef ERROR
#endif
namespace flutter {
Engine::Engine(Delegate& delegate,
std::string thread_label,
component::ApplicationContext& application_context,
blink::Settings settings,
f1dl::InterfaceRequest<mozart::ViewOwner> view_owner,
fidl::InterfaceRequest<views_v1_token::ViewOwner> view_owner,
const UniqueFDIONS& fdio_ns,
f1dl::InterfaceRequest<component::ServiceProvider>
fidl::InterfaceRequest<component::ServiceProvider>
outgoing_services_request)
: delegate_(delegate),
thread_label_(std::move(thread_label)),
......@@ -39,7 +35,7 @@ Engine::Engine(Delegate& delegate,
thread.Run();
}
mozart::ViewManagerPtr view_manager;
views_v1::ViewManagerPtr view_manager;
application_context.ConnectToEnvironmentService(view_manager.NewRequest());
zx::eventpair import_token, export_token;
......@@ -66,10 +62,21 @@ Engine::Engine(Delegate& delegate,
// Grab the accessibilty context writer that can understand the semtics tree
// on the platform view.
maxwell::ContextWriterPtr accessibility_context_writer;
modular::ContextWriterPtr accessibility_context_writer;
application_context.ConnectToEnvironmentService(
accessibility_context_writer.NewRequest());
// Create the compositor context from the scenic pointer to create the
// rasterizer.
std::unique_ptr<flow::CompositorContext> compositor_context =
std::make_unique<flutter::CompositorContext>(
scenic, // scenic
thread_label_, // debug label
std::move(import_token), // import token
on_session_metrics_change_callback, // session metrics did change
on_session_error_callback // session did encounter error
);
// Setup the callback that will instantiate the platform view.
shell::Shell::CreateCallback<shell::PlatformView> on_create_platform_view =
fxl::MakeCopyable([debug_label = thread_label_, //
......@@ -80,10 +87,8 @@ Engine::Engine(Delegate& delegate,
scenic = std::move(scenic), //
accessibility_context_writer =
std::move(accessibility_context_writer), //
export_token = std::move(export_token), //
import_token = std::move(import_token), //
on_session_metrics_change_callback, //
on_session_error_callback //
export_token = std::move(export_token) //
](shell::Shell& shell) mutable {
return std::make_unique<flutter::PlatformView>(
shell, // delegate
......@@ -94,21 +99,20 @@ Engine::Engine(Delegate& delegate,
std::move(view_owner), // view owner
std::move(scenic), // scenic
std::move(export_token), // export token
std::move(import_token), // import token
std::move(
accessibility_context_writer), // accessibility context writer
std::move(on_session_metrics_change_callback), // metrics change
std::move(on_session_error_callback) // session_error
accessibility_context_writer) // accessibility context writer
);
});
// Setup the callback that will instantiate the rasterizer.
shell::Shell::CreateCallback<shell::Rasterizer> on_create_rasterizer =
[](shell::Shell& shell) {
fxl::MakeCopyable([compositor_context = std::move(compositor_context)](
shell::Shell& shell) mutable {
return std::make_unique<shell::Rasterizer>(
shell.GetTaskRunners() // task runners
shell.GetTaskRunners(), // task runners
std::move(compositor_context) // compositor context
);
};
});
// Get the task runners from the managed threads. The current thread will be
// used as the "platform" thread.
......
......@@ -4,13 +4,15 @@
#pragma once
#include <fuchsia/cpp/views_v1.h>
#include <fuchsia/cpp/views_v1_token.h>
#include "flutter/shell/common/shell.h"
#include "isolate_configurator.h"
#include "lib/app/cpp/application_context.h"
#include "lib/fsl/threading/thread.h"
#include "lib/fxl/macros.h"
#include "lib/fxl/memory/weak_ptr.h"
#include "lib/ui/views/fidl/view_manager.fidl.h"
namespace flutter {
......@@ -27,9 +29,9 @@ class Engine final {
std::string thread_label,
component::ApplicationContext& application_context,
blink::Settings settings,
f1dl::InterfaceRequest<mozart::ViewOwner> view_owner,
fidl::InterfaceRequest<views_v1_token::ViewOwner> view_owner,
const UniqueFDIONS& fdio_ns,
f1dl::InterfaceRequest<component::ServiceProvider>
fidl::InterfaceRequest<component::ServiceProvider>
outgoing_services_request);
~Engine();
......
......@@ -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> MakeSkDataFromBuffer(const mem::Buffer& data) {
if (!fsl::SizedVmo::IsSizeValid(data.vmo, data.size) ||
data.size > std::numeric_limits<size_t>::max()) {
return nullptr;
}
uint64_t size = vmo->size;
uint64_t size = data.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, data.vmo, 0, size,
ZX_VM_FLAG_PERM_READ, &buffer);
if (status != ZX_OK)
return nullptr;
......@@ -90,11 +90,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(
......@@ -108,7 +108,7 @@ SkTypeface* FuchsiaFontManager::onMatchFamilyStyle(
return nullptr;
}
sk_sp<SkData> data = MakeSkDataFromVMO(response->data->vmo);
sk_sp<SkData> data = MakeSkDataFromBuffer(response->data.buffer);
if (!data)
return nullptr;
......
......@@ -16,9 +16,9 @@ namespace flutter {
IsolateConfigurator::IsolateConfigurator(
const UniqueFDIONS& fdio_ns,
mozart::ViewPtr& view,
views_v1::ViewPtr& view,
component::ApplicationEnvironmentPtr application_environment,
f1dl::InterfaceRequest<component::ServiceProvider>
fidl::InterfaceRequest<component::ServiceProvider>
outgoing_services_request)
: fdio_ns_(fdio_ns),
view_(view),
......@@ -42,7 +42,7 @@ bool IsolateConfigurator::ConfigureCurrentIsolate() {
}
// |mozart::NativesDelegate|
mozart::View* IsolateConfigurator::GetMozartView() {
views_v1::View* IsolateConfigurator::GetMozartView() {
return view_.get();
}
......@@ -102,7 +102,7 @@ void IsolateConfigurator::BindScenic() {
tonic::ToDart("_context"), //
tonic::DartConverter<uint64_t>::ToDart(reinterpret_cast<intptr_t>(
static_cast<mozart::NativesDelegate*>(this)))));
mozart::ViewContainerPtr view_container;
views_v1::ViewContainerPtr view_container;
view_->GetContainer(view_container.NewRequest());
DART_CHECK_VALID(
Dart_SetField(mozart_internal, //
......
......@@ -4,11 +4,12 @@
#pragma once
#include "lib/app/fidl/application_environment.fidl.h"
#include <fuchsia/cpp/component.h>
#include <fuchsia/cpp/ui.h>
#include <fuchsia/cpp/views_v1.h>
#include "lib/fxl/macros.h"
#include "lib/ui/flutter/sdk_ext/src/natives.h"
#include "lib/ui/views/fidl/view_containers.fidl.h"
#include "lib/ui/views/fidl/views.fidl.h"
#include "unique_fdio_ns.h"
namespace flutter {
......@@ -20,9 +21,9 @@ class IsolateConfigurator final : mozart::NativesDelegate {
public:
IsolateConfigurator(
const UniqueFDIONS& fdio_ns,
mozart::ViewPtr& view,
views_v1::ViewPtr& view,
component::ApplicationEnvironmentPtr application_environment,
f1dl::InterfaceRequest<component::ServiceProvider>
fidl::InterfaceRequest<component::ServiceProvider>
outgoing_services_request);
~IsolateConfigurator();
......@@ -34,12 +35,12 @@ class IsolateConfigurator final : mozart::NativesDelegate {
private:
bool used_ = false;
const UniqueFDIONS& fdio_ns_;
mozart::ViewPtr& view_;
views_v1::ViewPtr& view_;
component::ApplicationEnvironmentPtr application_environment_;
f1dl::InterfaceRequest<component::ServiceProvider> outgoing_services_request_;
fidl::InterfaceRequest<component::ServiceProvider> outgoing_services_request_;
// |mozart::NativesDelegate|
mozart::View* GetMozartView() override;
views_v1::View* GetMozartView() override;
void BindFuchsia();
......
......@@ -25,14 +25,11 @@ PlatformView::PlatformView(
std::string debug_label,
blink::TaskRunners task_runners,
component::ServiceProviderPtr parent_environment_service_provider,
mozart::ViewManagerPtr& view_manager,
f1dl::InterfaceRequest<mozart::ViewOwner> view_owner,
views_v1::ViewManagerPtr& view_manager,
fidl::InterfaceRequest<views_v1_token::ViewOwner> view_owner,
ui::ScenicPtr scenic,
zx::eventpair export_token,
zx::eventpair import_token,
maxwell::ContextWriterPtr accessibility_context_writer,
OnMetricsUpdate on_session_metrics_did_change,
fxl::Closure session_error_callback)
modular::ContextWriterPtr accessibility_context_writer)
: shell::PlatformView(delegate, std::move(task_runners)),
debug_label_(std::move(debug_label)),
view_listener_(this),
......@@ -40,12 +37,7 @@ PlatformView::PlatformView(
ime_client_(this),
scenic_(std::move(scenic)),
accessibility_bridge_(std::move(accessibility_context_writer)),
surface_(
std::make_unique<Surface>(scenic_,
debug_label_,
std::move(import_token),
std::move(on_session_metrics_did_change),
std::move(session_error_callback))) {
surface_(std::make_unique<Surface>(debug_label_)) {
// Create the view.
view_manager->CreateView(view_.NewRequest(), // view
std::move(view_owner), // view owner
......@@ -86,30 +78,26 @@ void PlatformView::RegisterPlatformMessageHandlers() {
std::placeholders::_1);
}
mozart::ViewPtr& PlatformView::GetMozartView() {
views_v1::ViewPtr& PlatformView::GetMozartView() {
return view_;
}
// |mozart::ViewListener|
void PlatformView::OnPropertiesChanged(
mozart::ViewPropertiesPtr properties,
const OnPropertiesChangedCallback& callback) {
UpdateViewportMetrics(properties->view_layout);
// |views_v1::ViewListener|
void PlatformView::OnPropertiesChanged(views_v1::ViewProperties properties,
OnPropertiesChangedCallback callback) {
if (properties.view_layout) {
UpdateViewportMetrics(*properties.view_layout);
}
callback();
}
void PlatformView::UpdateViewportMetrics(const mozart::ViewLayoutPtr& layout) {
if (!layout) {
return;
}
metrics_.size.width = layout->size->width;
metrics_.size.height = layout->size->height;
metrics_.padding.left = layout->inset->left;
metrics_.padding.top = layout->inset->top;
metrics_.padding.right = layout->inset->right;
metrics_.padding.bottom = layout->inset->bottom;
void PlatformView::UpdateViewportMetrics(const views_v1::ViewLayout& layout) {
metrics_.size.width = layout.size.width;
metrics_.size.height = layout.size.height;
metrics_.padding.left = layout.inset.left;
metrics_.padding.top = layout.inset.top;
metrics_.padding.right = layout.inset.right;
metrics_.padding.bottom = layout.inset.bottom;
FlushViewportMetrics();
}
......@@ -150,31 +138,30 @@ void PlatformView::FlushViewportMetrics() {
SetViewportMetrics(metrics);
}
// |mozart::InputMethodEditorClient|
void PlatformView::DidUpdateState(mozart::TextInputStatePtr state,
mozart::InputEventPtr event) {
// |input::InputMethodEditorClient|
void PlatformView::DidUpdateState(input::TextInputState state,
std::unique_ptr<input::InputEvent>) {
rapidjson::Document document;
auto& allocator = document.GetAllocator();
rapidjson::Value encoded_state(rapidjson::kObjectType);
encoded_state.AddMember("text", state->text.get(), allocator);
encoded_state.AddMember("selectionBase", state->selection->base, allocator);
encoded_state.AddMember("selectionExtent", state->selection->extent,
allocator);
switch (state->selection->affinity) {
case mozart::TextAffinity::UPSTREAM:
encoded_state.AddMember("text", state.text.get(), allocator);
encoded_state.AddMember("selectionBase", state.selection.base, allocator);
encoded_state.AddMember("selectionExtent", state.selection.extent, allocator);
switch (state.selection.affinity) {
case input::TextAffinity::UPSTREAM:
encoded_state.AddMember("selectionAffinity",
rapidjson::Value("TextAffinity.upstream"),
allocator);
break;
case mozart::TextAffinity::DOWNSTREAM:
case input::TextAffinity::DOWNSTREAM:
encoded_state.AddMember("selectionAffinity",
rapidjson::Value("TextAffinity.downstream"),
allocator);
break;
}
encoded_state.AddMember("selectionIsDirectional", true, allocator);
encoded_state.AddMember("composingBase", state->composing->start, allocator);
encoded_state.AddMember("composingExtent", state->composing->end, allocator);
encoded_state.AddMember("composingBase", state.composing.start, allocator);
encoded_state.AddMember("composingExtent", state.composing.end, allocator);
rapidjson::Value args(rapidjson::kArrayType);
args.PushBack(current_text_input_client_, allocator);
......@@ -198,8 +185,8 @@ void PlatformView::DidUpdateState(mozart::TextInputStatePtr state,
);
}
// |mozart::InputMethodEditorClient|
void PlatformView::OnAction(mozart::InputMethodAction action) {
// |input::InputMethodEditorClient|
void PlatformView::OnAction(input::InputMethodAction action) {
rapidjson::Document document;
auto& allocator = document.GetAllocator();
......@@ -226,21 +213,20 @@ void PlatformView::OnAction(mozart::InputMethodAction action) {
);
}
// |mozart::InputListener|
void PlatformView::OnEvent(mozart::InputEventPtr event,
const OnEventCallback& callback) {
using Type = mozart::InputEvent::Tag;
switch (event->which()) {
case Type::POINTER:
callback(OnHandlePointerEvent(event->get_pointer()));
// |input::InputListener|
void PlatformView::OnEvent(input::InputEvent event, OnEventCallback callback) {
using Type = input::InputEvent::Tag;
switch (event.Which()) {
case Type::kPointer:
callback(OnHandlePointerEvent(event.pointer()));
return;
case Type::KEYBOARD:
callback(OnHandleKeyboardEvent(event->get_keyboard()));
case Type::kKeyboard:
callback(OnHandleKeyboardEvent(event.keyboard()));
return;
case Type::FOCUS:
callback(OnHandleFocusEvent(event->get_focus()));
case Type::kFocus:
callback(OnHandleFocusEvent(event.focus()));
return;
case Type::__UNKNOWN__:
default:
break;
}
......@@ -248,21 +234,21 @@ void PlatformView::OnEvent(mozart::InputEventPtr event,
}
static blink::PointerData::Change GetChangeFromPointerEventPhase(
mozart::PointerEvent::Phase phase) {
input::PointerEventPhase phase) {
switch (phase) {
case mozart::PointerEvent::Phase::ADD:
case input::PointerEventPhase::ADD:
return blink::PointerData::Change::kAdd;
case mozart::PointerEvent::Phase::HOVER:
case input::PointerEventPhase::HOVER:
return blink::PointerData::Change::kHover;
case mozart::PointerEvent::Phase::DOWN:
case input::PointerEventPhase::DOWN:
return blink::PointerData::Change::kDown;
case mozart::PointerEvent::Phase::MOVE:
case input::PointerEventPhase::MOVE:
return blink::PointerData::Change::kMove;
case mozart::PointerEvent::Phase::UP:
case input::PointerEventPhase::UP:
return blink::PointerData::Change::kUp;
case mozart::PointerEvent::Phase::REMOVE:
case input::PointerEventPhase::REMOVE:
return blink::PointerData::Change::kRemove;
case mozart::PointerEvent::Phase::CANCEL:
case input::PointerEventPhase::CANCEL:
return blink::PointerData::Change::kCancel;
default:
return blink::PointerData::Change::kCancel;
......@@ -270,26 +256,27 @@ static blink::PointerData::Change GetChangeFromPointerEventPhase(
}
static blink::PointerData::DeviceKind GetKindFromPointerType(
mozart::PointerEvent::Type type) {
input::PointerEventType type) {
switch (type) {
case mozart::PointerEvent::Type::TOUCH:
case input::PointerEventType::TOUCH:
return blink::PointerData::DeviceKind::kTouch;
case mozart::PointerEvent::Type::MOUSE:
case input::PointerEventType::MOUSE:
return blink::PointerData::DeviceKind::kMouse;
default:
return blink::PointerData::DeviceKind::kTouch;
}
}
bool PlatformView::OnHandlePointerEvent(
const mozart::PointerEventPtr& pointer) {
bool PlatformView::OnHandlePointerEvent(const input::PointerEvent& pointer) {
blink::PointerData pointer_data;
pointer_data.time_stamp = pointer->event_time / 1000;
pointer_data.change = GetChangeFromPointerEventPhase(pointer->phase);
pointer_data.kind = GetKindFromPointerType(pointer->type);
pointer_data.device = pointer->pointer_id;
pointer_data.physical_x = pointer->x * metrics_.scale;
pointer_data.physical_y = pointer->y * metrics_.scale;
pointer_data.time_stamp = pointer.event_time / 1000;
pointer_data.change = GetChangeFromPointerEventPhase(pointer.phase);
pointer_data.kind = GetKindFromPointerType(pointer.type);
pointer_data.device = pointer.pointer_id;
pointer_data.physical_x = pointer.x * metrics_.scale;
pointer_data.physical_y = pointer.y * metrics_.scale;
// Buttons are single bit values starting with kMousePrimaryButton = 1.
pointer_data.buttons = static_cast<uint64_t>(pointer.buttons);
switch (pointer_data.change) {
case blink::PointerData::Change::kDown:
......@@ -327,14 +314,13 @@ bool PlatformView::OnHandlePointerEvent(
return true;
}
bool PlatformView::OnHandleKeyboardEvent(
const mozart::KeyboardEventPtr& keyboard) {
bool PlatformView::OnHandleKeyboardEvent(const input::KeyboardEvent& keyboard) {
const char* type = nullptr;
if (keyboard->phase == mozart::KeyboardEvent::Phase::PRESSED) {
if (keyboard.phase == input::KeyboardEventPhase::PRESSED) {
type = "keydown";
} else if (keyboard->phase == mozart::KeyboardEvent::Phase::REPEAT) {
} else if (keyboard.phase == input::KeyboardEventPhase::REPEAT) {
type = "keydown"; // TODO change this to keyrepeat
} else if (keyboard->phase == mozart::KeyboardEvent::Phase::RELEASED) {
} else if (keyboard.phase == input::KeyboardEventPhase::RELEASED) {
type = "keyup";
}
......@@ -348,9 +334,9 @@ bool PlatformView::OnHandleKeyboardEvent(
document.SetObject();
document.AddMember("type", rapidjson::Value(type, strlen(type)), allocator);
document.AddMember("keymap", rapidjson::Value("fuchsia"), allocator);
document.AddMember("hidUsage", keyboard->hid_usage, allocator);
document.AddMember("codePoint", keyboard->code_point, allocator);
document.AddMember("modifiers", keyboard->modifiers, allocator);
document.AddMember("hidUsage", keyboard.hid_usage, allocator);
document.AddMember("codePoint", keyboard.code_point, allocator);
document.AddMember("modifiers", keyboard.modifiers, allocator);
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
document.Accept(writer);
......@@ -365,8 +351,8 @@ bool PlatformView::OnHandleKeyboardEvent(
return true;
}
bool PlatformView::OnHandleFocusEvent(const mozart::FocusEventPtr& focus) {
if (!focus->focused && current_text_input_client_ != 0) {
bool PlatformView::OnHandleFocusEvent(const input::FocusEvent& focus) {
if (!focus.focused && current_text_input_client_ != 0) {
current_text_input_client_ = 0;
if (ime_) {
ime_->Hide();
......@@ -434,13 +420,13 @@ void PlatformView::HandleFlutterPlatformChannelPlatformMessage(
clipboard_->Push(text);
response->CompleteEmpty();
} else if (method->value == "Clipboard.getData") {
clipboard_->Peek([response](const f1dl::String& text) {
clipboard_->Peek([response](fidl::StringPtr text) {
rapidjson::StringBuffer json_buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(json_buffer);
writer.StartArray();
writer.StartObject();
writer.Key("text");
writer.String(text);
writer.String(text.get());
writer.EndObject();
writer.EndArray();
std::string result = json_buffer.GetString();
......@@ -491,13 +477,14 @@ void PlatformView::HandleFlutterTextInputChannelPlatformMessage(
}
// TODO(abarth): Read the keyboard type from the configuration.
current_text_input_client_ = args->value[0].GetInt();
mozart::TextInputStatePtr state = mozart::TextInputState::New();
state->text = std::string();
state->selection = mozart::TextSelection::New();
state->composing = mozart::TextRange::New();
input_connection_->GetInputMethodEditor(
mozart::KeyboardType::TEXT, mozart::InputMethodAction::DONE,
std::move(state), ime_client_.NewBinding(), ime_.NewRequest());
input::KeyboardType::TEXT, // keyboard type
input::InputMethodAction::DONE, // input method action
input::TextInputState{}, // initial state
ime_client_.NewBinding(), // client
ime_.NewRequest() // editor
);
} else if (method->value == "TextInput.setEditingState") {
if (ime_) {
auto args_it = root.FindMember("args");
......@@ -505,36 +492,34 @@ void PlatformView::HandleFlutterTextInputChannelPlatformMessage(
return;
}
const auto& args = args_it->value;
mozart::TextInputStatePtr state = mozart::TextInputState::New();
state->selection = mozart::TextSelection::New();
state->composing = mozart::TextRange::New();
input::TextInputState state;
// TODO(abarth): Deserialize state.
auto text = args.FindMember("text");
if (text != args.MemberEnd() && text->value.IsString())
state->text = text->value.GetString();
state.text = text->value.GetString();
auto selection_base = args.FindMember("selectionBase");
if (selection_base != args.MemberEnd() && selection_base->value.IsInt())
state->selection->base = selection_base->value.GetInt();
state.selection.base = selection_base->value.GetInt();
auto selection_extent = args.FindMember("selectionExtent");
if (selection_extent != args.MemberEnd() &&
selection_extent->value.IsInt())
state->selection->extent = selection_extent->value.GetInt();
state.selection.extent = selection_extent->value.GetInt();
auto selection_affinity = args.FindMember("selectionAffinity");
if (selection_affinity != args.MemberEnd() &&
selection_affinity->value.IsString() &&
selection_affinity->value == "TextAffinity.upstream")
state->selection->affinity = mozart::TextAffinity::UPSTREAM;
state.selection.affinity = input::TextAffinity::UPSTREAM;
else
state->selection->affinity = mozart::TextAffinity::DOWNSTREAM;
state.selection.affinity = input::TextAffinity::DOWNSTREAM;
// We ignore selectionIsDirectional because that concept doesn't exist on
// Fuchsia.
auto composing_base = args.FindMember("composingBase");
if (composing_base != args.MemberEnd() && composing_base->value.IsInt())
state->composing->start = composing_base->value.GetInt();
state.composing.start = composing_base->value.GetInt();
auto composing_extent = args.FindMember("composingExtent");
if (composing_extent != args.MemberEnd() &&
composing_extent->value.IsInt())
state->composing->end = composing_extent->value.GetInt();
state.composing.end = composing_extent->value.GetInt();
ime_->SetState(std::move(state));
}
} else if (method->value == "TextInput.clearClient") {
......
......@@ -7,15 +7,16 @@
#include <map>
#include <set>
#include <fuchsia/cpp/input.h>
#include <fuchsia/cpp/modular.h>
#include <fuchsia/cpp/views_v1.h>
#include <fuchsia/cpp/views_v1_token.h>
#include "accessibility_bridge.h"
#include "flutter/lib/ui/window/viewport_metrics.h"
#include "flutter/shell/common/platform_view.h"
#include "lib/clipboard/fidl/clipboard.fidl.h"
#include "lib/fidl/cpp/bindings/binding.h"
#include "lib/fidl/cpp/binding.h"
#include "lib/fxl/macros.h"
#include "lib/ui/input/fidl/input_connection.fidl.h"
#include "lib/ui/views/fidl/view_manager.fidl.h"
#include "lib/ui/views/fidl/views.fidl.h"
#include "surface.h"
namespace flutter {
......@@ -23,39 +24,36 @@ namespace flutter {
// The per engine component residing on the platform thread is responsible for
// all platform specific integrations.
class PlatformView final : public shell::PlatformView,
public mozart::ViewListener,
public mozart::InputMethodEditorClient,
public mozart::InputListener {
public views_v1::ViewListener,
public input::InputMethodEditorClient,
public input::InputListener {
public:
PlatformView(
PlatformView::Delegate& delegate,
std::string debug_label,
blink::TaskRunners task_runners,
component::ServiceProviderPtr parent_environment_service_provider,
mozart::ViewManagerPtr& view_manager,
f1dl::InterfaceRequest<mozart::ViewOwner> view_owner,
views_v1::ViewManagerPtr& view_manager,
fidl::InterfaceRequest<views_v1_token::ViewOwner> view_owner,
ui::ScenicPtr scenic,
zx::eventpair export_token,
zx::eventpair import_token,
maxwell::ContextWriterPtr accessibility_context_writer,
OnMetricsUpdate on_session_metrics_did_change,
fxl::Closure session_error_callback);
modular::ContextWriterPtr accessibility_context_writer);
~PlatformView();
void UpdateViewportMetrics(double pixel_ratio);
mozart::ViewPtr& GetMozartView();
views_v1::ViewPtr& GetMozartView();
private:
const std::string debug_label_;
mozart::ViewPtr view_;
f1dl::Binding<mozart::ViewListener> view_listener_;
mozart::InputConnectionPtr input_connection_;
f1dl::Binding<mozart::InputListener> input_listener_;
views_v1::ViewPtr view_;
fidl::Binding<views_v1::ViewListener> view_listener_;
input::InputConnectionPtr input_connection_;
fidl::Binding<input::InputListener> input_listener_;
int current_text_input_client_ = 0;
f1dl::Binding<mozart::InputMethodEditorClient> ime_client_;
mozart::InputMethodEditorPtr ime_;
fidl::Binding<input::InputMethodEditorClient> ime_client_;
input::InputMethodEditorPtr ime_;
modular::ClipboardPtr clipboard_;
ui::ScenicPtr scenic_;
AccessibilityBridge accessibility_bridge_;
......@@ -70,31 +68,29 @@ class PlatformView final : public shell::PlatformView,
void RegisterPlatformMessageHandlers();
void UpdateViewportMetrics(const mozart::ViewLayoutPtr& layout);
void UpdateViewportMetrics(const views_v1::ViewLayout& layout);
void FlushViewportMetrics();
// |mozart::ViewListener|
void OnPropertiesChanged(
mozart::ViewPropertiesPtr properties,
const OnPropertiesChangedCallback& callback) override;
// |views_v1::ViewListener|
void OnPropertiesChanged(views_v1::ViewProperties properties,
OnPropertiesChangedCallback callback) override;
// |mozart::InputMethodEditorClient|
void DidUpdateState(mozart::TextInputStatePtr state,
mozart::InputEventPtr event) override;
// |input::InputMethodEditorClient|
void DidUpdateState(input::TextInputState state,
std::unique_ptr<input::InputEvent> event) override;
// |mozart::InputMethodEditorClient|
void OnAction(mozart::InputMethodAction action) override;
// |input::InputMethodEditorClient|
void OnAction(input::InputMethodAction action) override;
// |mozart::InputListener|
void OnEvent(mozart::InputEventPtr event,
const OnEventCallback& callback) override;
// |input::InputListener|
void OnEvent(input::InputEvent event, OnEventCallback callback) override;
bool OnHandlePointerEvent(const mozart::PointerEventPtr& pointer);
bool OnHandlePointerEvent(const input::PointerEvent& pointer);
bool OnHandleKeyboardEvent(const mozart::KeyboardEventPtr& keyboard);
bool OnHandleKeyboardEvent(const input::KeyboardEvent& keyboard);
bool OnHandleFocusEvent(const mozart::FocusEventPtr& focus);
bool OnHandleFocusEvent(const input::FocusEvent& focus);
// |shell::PlatformView|
std::unique_ptr<shell::Surface> CreateRenderingSurface() override;
......
......@@ -4,6 +4,7 @@
#include "session_connection.h"
#include "lib/fidl/cpp/optional.h"
#include "lib/ui/scenic/fidl_helpers.h"
namespace flutter {
......@@ -26,28 +27,29 @@ SessionConnection::SessionConnection(
this, std::placeholders::_1));
root_node_.Bind(std::move(import_token));
root_node_.SetEventMask(ui::gfx::kMetricsEventMask);
session_.Present(0, [](ui::PresentationInfoPtr info) {});
root_node_.SetEventMask(gfx::kMetricsEventMask);
session_.Present(0, [](auto) {});
}
SessionConnection::~SessionConnection() = default;
void SessionConnection::OnSessionEvents(f1dl::Array<ui::EventPtr> events) {
using Type = ui::gfx::Event::Tag;
void SessionConnection::OnSessionEvents(fidl::VectorPtr<ui::Event> events) {
using Type = gfx::Event::Tag;
for (auto& raw_event : *events) {
if (!raw_event->is_gfx()) {
if (!raw_event.is_gfx()) {
continue;
}
auto& event = raw_event->get_gfx();
auto& event = raw_event.gfx();
switch (event->which()) {
case Type::METRICS: {
if (event->get_metrics()->node_id == root_node_.id()) {
auto& metrics = event->get_metrics()->metrics;
double device_pixel_ratio = metrics->scale_x;
scene_update_context_.set_metrics(std::move(metrics));
switch (event.Which()) {
case Type::kMetrics: {
if (event.metrics().node_id == root_node_.id()) {
auto& metrics = event.metrics().metrics;
double device_pixel_ratio = metrics.scale_x;
scene_update_context_.set_metrics(
fidl::MakeOptional(std::move(metrics)));
if (metrics_changed_callback_) {
metrics_changed_callback_(device_pixel_ratio);
}
......@@ -63,8 +65,8 @@ void SessionConnection::Present(flow::CompositorContext::ScopedFrame& frame) {
// Flush all session ops. Paint tasks have not yet executed but those are
// fenced. The compositor can start processing ops while we finalize paint
// tasks.
session_.Present(0, // presentation_time. (placeholder).
[](ui::PresentationInfoPtr) {} // callback
session_.Present(0, // presentation_time. (placeholder).
[](auto) {} // callback
);
// Execute paint tasks and signal fences.
......
......@@ -8,7 +8,7 @@
#include "flutter/flow/compositor_context.h"
#include "flutter/flow/scene_update_context.h"
#include "lib/fidl/cpp/bindings/interface_handle.h"
#include "lib/fidl/cpp/interface_handle.h"
#include "lib/fxl/functional/closure.h"
#include "lib/fxl/macros.h"
#include "lib/ui/scenic/client/resources.h"
......@@ -33,7 +33,7 @@ class SessionConnection final {
bool has_metrics() const { return scene_update_context_.has_metrics(); }
const ui::gfx::MetricsPtr& metrics() const {
const gfx::MetricsPtr& metrics() const {
return scene_update_context_.metrics();
}
......@@ -53,7 +53,7 @@ class SessionConnection final {
flow::SceneUpdateContext scene_update_context_;
OnMetricsUpdate metrics_changed_callback_;
void OnSessionEvents(f1dl::Array<ui::EventPtr> events);
void OnSessionEvents(fidl::VectorPtr<ui::Event> events);
void EnqueueClearOps();
......
......@@ -13,18 +13,8 @@
namespace flutter {
Surface::Surface(const ui::ScenicPtr& scenic,
std::string debug_label,
zx::eventpair import_token,
OnMetricsUpdate session_metrics_did_change_callback,
fxl::Closure session_error_callback)
: shell::Surface(std::make_unique<CompositorContext>(
scenic,
debug_label,
std::move(import_token),
std::move(session_metrics_did_change_callback),
std::move(session_error_callback))),
debug_label_(debug_label) {}
Surface::Surface(std::string debug_label)
: debug_label_(std::move(debug_label)) {}
Surface::~Surface() = default;
......@@ -58,15 +48,15 @@ static zx_status_t DriverWatcher(int dirfd,
}
bool Surface::CanConnectToDisplay() {
constexpr char kDisplayDriverClass[] = "/dev/class/display";
fxl::UniqueFD fd(open(kDisplayDriverClass, O_DIRECTORY | O_RDONLY));
constexpr char kGpuDriverClass[] = "/dev/class/gpu";
fxl::UniqueFD fd(open(kGpuDriverClass, O_DIRECTORY | O_RDONLY));
if (fd.get() < 0) {
FXL_DLOG(ERROR) << "Failed to open " << kDisplayDriverClass;
FXL_DLOG(ERROR) << "Failed to open " << kGpuDriverClass;
return false;
}
zx_status_t status = fdio_watch_directory(
fd.get(), DriverWatcher, zx_deadline_after(ZX_SEC(1)), nullptr);
fd.get(), DriverWatcher, zx_deadline_after(ZX_SEC(5)), nullptr);
return status == ZX_ERR_STOP;
}
......
......@@ -16,18 +16,13 @@ namespace flutter {
// thread.
class Surface final : public shell::Surface {
public:
Surface(const ui::ScenicPtr& scenic,
std::string debug_label,
zx::eventpair import_token,
OnMetricsUpdate session_metrics_did_change_callback,
fxl::Closure session_error_callback);
Surface(std::string debug_label);
~Surface() override;
private:
const bool valid_ = CanConnectToDisplay();
const std::string debug_label_;
std::unique_ptr<CompositorContext> compositor_context_;
// |shell::Surface|
bool IsValid() override;
......
......@@ -48,11 +48,8 @@ VulkanSurface::VulkanSurface(vulkan::VulkanProvider& vulkan_provider,
}
VulkanSurface::~VulkanSurface() {
if (async_) {
wait_.Cancel(async_);
wait_.set_object(ZX_HANDLE_INVALID);
async_ = nullptr;
}
wait_.Cancel();
wait_.set_object(ZX_HANDLE_INVALID);
}
bool VulkanSurface::IsValid() const {
......@@ -192,10 +189,12 @@ bool VulkanSurface::AllocateDeviceMemory(sk_sp<GrContext> context,
break;
}
}
VkExportMemoryAllocateInfoKHR export_allocate_info = {
.sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR,
.pNext = nullptr,
.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_FUCHSIA_VMO_BIT_KHR};
const VkMemoryAllocateInfo alloc_info = {
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
.pNext = &export_allocate_info,
......@@ -262,12 +261,12 @@ bool VulkanSurface::SetupSkiaSurface(sk_sp<GrContext> context,
}
const GrVkImageInfo image_info = {
vk_image_, // image
{vk_memory_, 0, memory_reqs.size, 0}, // alloc
image_create_info.tiling, // tiling
image_create_info.initialLayout, // layout
image_create_info.format, // format
image_create_info.mipLevels, // level count
vk_image_, // image
{vk_memory_, 0, memory_reqs.size, 0}, // alloc
image_create_info.tiling, // tiling
image_create_info.initialLayout, // layout
image_create_info.format, // format
image_create_info.mipLevels, // level count
};
GrBackendRenderTarget sk_render_target(size.width(), size.height(), 0,
......@@ -399,10 +398,10 @@ void VulkanSurface::Reset() {
}
}
async_wait_result_t VulkanSurface::OnHandleReady(
async_t* async,
zx_status_t status,
const zx_packet_signal_t* signal) {
void VulkanSurface::OnHandleReady(async_t* async,
async::WaitBase* wait,
zx_status_t status,
const zx_packet_signal_t* signal) {
if (status != ZX_OK)
return;
FXL_DCHECK(signal->observed & ZX_EVENT_SIGNALED);
......
......@@ -151,13 +151,14 @@ bool VulkanSurfaceProducer::TransitionSurfacesToExternal(
if (!command_buffer->Begin())
return false;
GrBackendRenderTarget backendRT = vk_surface->GetSkiaSurface()->getBackendRenderTarget(
SkSurface::kFlushRead_BackendHandleAccess);
GrBackendRenderTarget backendRT =
vk_surface->GetSkiaSurface()->getBackendRenderTarget(
SkSurface::kFlushRead_BackendHandleAccess);
if (!backendRT.isValid()) {
return false;
}
GrVkImageInfo imageInfo;
if(!backendRT.getVkImageInfo(&imageInfo)) {
if (!backendRT.getVkImageInfo(&imageInfo)) {
return false;
}
......
......@@ -26,6 +26,10 @@ class NativeLibrary : public fxl::RefCountedThreadSafe<NativeLibrary> {
static fxl::RefPtr<NativeLibrary> Create(const char* path);
static fxl::RefPtr<NativeLibrary> CreateWithHandle(
Handle handle,
bool close_handle_when_done);
static fxl::RefPtr<NativeLibrary> CreateForCurrentProcess();
const uint8_t* ResolveSymbol(const char* symbol);
......
......@@ -45,6 +45,14 @@ fxl::RefPtr<NativeLibrary> NativeLibrary::Create(const char* path) {
return library->GetHandle() != nullptr ? library : nullptr;
}
fxl::RefPtr<NativeLibrary> NativeLibrary::CreateWithHandle(
Handle handle,
bool close_handle_when_done) {
auto library =
fxl::AdoptRef(new NativeLibrary(handle, close_handle_when_done));
return library->GetHandle() != nullptr ? library : nullptr;
}
fxl::RefPtr<NativeLibrary> NativeLibrary::CreateForCurrentProcess() {
return fxl::AdoptRef(new NativeLibrary(RTLD_DEFAULT, false));
}
......
......@@ -37,6 +37,14 @@ fxl::RefPtr<NativeLibrary> NativeLibrary::Create(const char* path) {
return library->GetHandle() != nullptr ? library : nullptr;
}
fxl::RefPtr<NativeLibrary> NativeLibrary::CreateWithHandle(
Handle handle,
bool close_handle_when_done) {
auto library =
fxl::AdoptRef(new NativeLibrary(handle, close_handle_when_done));
return library->GetHandle() != nullptr ? library : nullptr;
}
fxl::RefPtr<NativeLibrary> NativeLibrary::CreateForCurrentProcess() {
return fxl::AdoptRef(new NativeLibrary(::GetModuleHandle(nullptr), false));
}
......
......@@ -29,33 +29,14 @@ if (is_fuchsia) {
# The sole purpose of this target is to generate a .packages file.
sources = []
dot_packages_file = "$target_gen_dir/snapshot.packages"
outputs = [
dot_packages_file,
]
deps = []
foreach(dep, dart_deps) {
deps += [ "$dep($dart_toolchain)" ]
}
infer_package_name = true
disable_analysis = true
script = "//build/dart/gen_dot_packages.py"
args = [
"--out",
rebase_path(dot_packages_file, root_build_dir),
"--source-dir",
rebase_path("."),
"--root-build-dir",
rebase_path(root_build_dir),
"--root-gen-dir",
rebase_path(dart_root_gen_dir),
"--package-name",
"snapshot_root",
"--depfile",
rebase_path(depfile),
"--deps",
] + dart_deps
deps = [
"//topaz/public/dart/fuchsia",
"//topaz/public/dart/zircon",
]
}
}
......@@ -148,10 +129,11 @@ action("generate_snapshot_bin") {
}
if (is_fuchsia) {
package_gen_dir = get_label_info(":bogus($dart_toolchain)",
"target_gen_dir")
package_gen_dir =
get_label_info(":bogus($dart_toolchain)", "target_gen_dir")
package_file = "$package_gen_dir/generate_package_map.packages"
inputs += zircon_sdk_ext_files + mozart_dart_sdk_ext_files + [package_file]
inputs +=
zircon_sdk_ext_files + mozart_dart_sdk_ext_files + [ package_file ]
zircon_path = rebase_path(zircon_sdk_ext_lib)
fuchsia_path = rebase_path(fuchsia_sdk_ext_lib)
mozart_internal_path = rebase_path(mozart_dart_sdk_ext_lib)
......@@ -329,7 +311,7 @@ copy_entry_points_extra_json("entry_points_extra_json") {
group("entry_points_json_files") {
public_deps = [
":entry_points_json",
":entry_points_extra_json",
":entry_points_json",
]
}
......@@ -4,7 +4,7 @@
#include "flutter/lib/ui/compositing/scene.h"
#include "flutter/fml/trace_event.h"
#include "flutter/glue/trace_event.h"
#include "flutter/lib/ui/painting/image.h"
#include "lib/fxl/functional/make_copyable.h"
#include "lib/tonic/converter/dart_converter.h"
......
......@@ -16,7 +16,17 @@
namespace shell {
Rasterizer::Rasterizer(blink::TaskRunners task_runners)
: task_runners_(std::move(task_runners)), weak_factory_(this) {}
: Rasterizer(std::move(task_runners),
std::make_unique<flow::CompositorContext>()) {}
Rasterizer::Rasterizer(
blink::TaskRunners task_runners,
std::unique_ptr<flow::CompositorContext> compositor_context)
: task_runners_(std::move(task_runners)),
compositor_context_(std::move(compositor_context)),
weak_factory_(this) {
FXL_DCHECK(compositor_context_);
}
Rasterizer::~Rasterizer() = default;
......@@ -26,17 +36,17 @@ fml::WeakPtr<Rasterizer> Rasterizer::GetWeakPtr() const {
void Rasterizer::Setup(std::unique_ptr<Surface> surface) {
surface_ = std::move(surface);
compositor_context_.OnGrContextCreated();
compositor_context_->OnGrContextCreated();
}
void Rasterizer::Teardown() {
compositor_context_.OnGrContextDestroyed();
compositor_context_->OnGrContextDestroyed();
surface_.reset();
last_layer_tree_.reset();
}
flow::TextureRegistry* Rasterizer::GetTextureRegistry() {
return &compositor_context_.texture_registry();
return &compositor_context_->texture_registry();
}
flow::LayerTree* Rasterizer::GetLastLayerTree() {
......@@ -96,12 +106,12 @@ bool Rasterizer::DrawToSurface(flow::LayerTree& layer_tree) {
// There is no way for the compositor to know how long the layer tree
// construction took. Fortunately, the layer tree does. Grab that time
// for instrumentation.
compositor_context_.engine_time().SetLapTime(layer_tree.construction_time());
compositor_context_->engine_time().SetLapTime(layer_tree.construction_time());
auto canvas = frame->SkiaCanvas();
auto compositor_frame =
compositor_context_.AcquireFrame(surface_->GetContext(), canvas, true);
compositor_context_->AcquireFrame(surface_->GetContext(), canvas, true);
if (canvas) {
canvas->clear(SK_ColorBLACK);
......
......@@ -8,6 +8,7 @@
#include <memory>
#include "flutter/common/task_runners.h"
#include "flutter/flow/compositor_context.h"
#include "flutter/flow/layers/layer_tree.h"
#include "flutter/fml/memory/weak_ptr.h"
#include "flutter/shell/common/surface.h"
......@@ -21,6 +22,9 @@ class Rasterizer final {
public:
Rasterizer(blink::TaskRunners task_runners);
Rasterizer(blink::TaskRunners task_runners,
std::unique_ptr<flow::CompositorContext> compositor_context);
~Rasterizer();
void Setup(std::unique_ptr<Surface> surface);
......@@ -62,7 +66,7 @@ class Rasterizer final {
private:
blink::TaskRunners task_runners_;
std::unique_ptr<Surface> surface_;
flow::CompositorContext compositor_context_;
std::unique_ptr<flow::CompositorContext> compositor_context_;
std::unique_ptr<flow::LayerTree> last_layer_tree_;
fxl::Closure next_frame_callback_;
fml::WeakPtrFactory<Rasterizer> weak_factory_;
......
......@@ -223,12 +223,12 @@ sk_sp<SkSurface> VulkanSwapchain::CreateSkiaSurface(
}
const GrVkImageInfo image_info = {
image, // image
GrVkAlloc(), // alloc
VK_IMAGE_TILING_OPTIMAL, // tiling
VK_IMAGE_LAYOUT_UNDEFINED, // layout
surface_format_.format, // format
1, // level count
image, // image
GrVkAlloc(), // alloc
VK_IMAGE_TILING_OPTIMAL, // tiling
VK_IMAGE_LAYOUT_UNDEFINED, // layout
surface_format_.format, // format
1, // level count
};
// TODO(chinmaygarde): Setup the stencil buffer and the sampleCnt.
......@@ -460,7 +460,7 @@ VulkanSwapchain::AcquireResult VulkanSwapchain::AcquireSurface() {
FXL_DLOG(INFO) << "Could not access surface at the image index.";
return error;
}
GrBackendRenderTarget backendRT = surface->getBackendRenderTarget(
SkSurface::kFlushRead_BackendHandleAccess);
if (!backendRT.isValid()) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册