fuchsia: Use runner services

This commit is contained in:
David Worsham
2021-09-21 11:41:53 -07:00
committed by David Worsham
parent 7aa7e7ef5b
commit 4114da27f4
21 changed files with 518 additions and 607 deletions

View File

@@ -18,12 +18,13 @@
{
protocol: [
"fuchsia.component.runner.ComponentRunner",
"fuchsia.deprecatedtimezone.Timezone",
"fuchsia.device.NameProvider", // For fdio uname()
"fuchsia.feedback.CrashReporter",
"fuchsia.intl.PropertyProvider",
"fuchsia.logger.LogSink",
"fuchsia.posix.socket.Provider",
"fuchsia.tracing.provider.Registry",
"fuchsia.intl.PropertyProvider", // For dartVM timezone support
"fuchsia.logger.LogSink", // For syslog
"fuchsia.net.name.Lookup", // For fdio sockets
"fuchsia.posix.socket.Provider", // For fdio sockets
"fuchsia.tracing.provider.Registry", // For trace-provider
],
from: "parent",
},

View File

@@ -8,13 +8,13 @@
"root-ssl-certificates"
],
"services": [
"fuchsia.deprecatedtimezone.Timezone",
"fuchsia.device.NameProvider",
"fuchsia.feedback.CrashReporter",
"fuchsia.intl.PropertyProvider",
"fuchsia.logger.LogSink",
"fuchsia.net.name.Lookup",
"fuchsia.posix.socket.Provider",
"fuchsia.tracing.provider.Registry"
"fuchsia.tracing.provider.Registry",
]
}
}
}

View File

@@ -8,13 +8,13 @@
"root-ssl-certificates"
],
"services": [
"fuchsia.deprecatedtimezone.Timezone",
"fuchsia.device.NameProvider",
"fuchsia.feedback.CrashReporter",
"fuchsia.intl.PropertyProvider",
"fuchsia.logger.LogSink",
"fuchsia.net.name.Lookup",
"fuchsia.posix.socket.Provider",
"fuchsia.tracing.provider.Registry"
"fuchsia.tracing.provider.Registry",
]
}
}
}

View File

@@ -9,15 +9,13 @@
"root-ssl-certificates"
],
"services": [
"fuchsia.deprecatedtimezone.Timezone",
"fuchsia.device.NameProvider",
"fuchsia.feedback.CrashReporter",
"fuchsia.intl.PropertyProvider",
"fuchsia.logger.LogSink",
"fuchsia.net.name.Lookup",
"fuchsia.posix.socket.Provider",
"fuchsia.process.Launcher",
"fuchsia.process.Resolver",
"fuchsia.tracing.provider.Registry"
"fuchsia.tracing.provider.Registry",
]
}
}
}

View File

@@ -9,15 +9,13 @@
"root-ssl-certificates"
],
"services": [
"fuchsia.deprecatedtimezone.Timezone",
"fuchsia.device.NameProvider",
"fuchsia.feedback.CrashReporter",
"fuchsia.intl.PropertyProvider",
"fuchsia.logger.LogSink",
"fuchsia.net.name.Lookup",
"fuchsia.posix.socket.Provider",
"fuchsia.process.Launcher",
"fuchsia.process.Resolver",
"fuchsia.tracing.provider.Registry"
"fuchsia.tracing.provider.Registry",
]
}
}
}

View File

@@ -13,20 +13,12 @@
#include "flutter/fml/logging.h"
#include "flutter/lib/ui/semantics/semantics_node.h"
#include "runtime/dart/utils/root_inspect_node.h"
#include "../runtime/dart/utils/root_inspect_node.h"
namespace flutter_runner {
namespace {
// Returns the ViewRef's koid.
zx_koid_t GetKoid(const fuchsia::ui::views::ViewRef& view_ref) {
zx_handle_t handle = view_ref.reference.get();
zx_info_handle_basic_t info;
zx_status_t status = zx_object_get_info(handle, ZX_INFO_HANDLE_BASIC, &info,
sizeof(info), nullptr, nullptr);
return status == ZX_OK ? info.koid : ZX_KOID_INVALID;
}
#if !FLUTTER_RELEASE
static constexpr char kTreeDumpInspectRootName[] = "semantic_tree_root";
@@ -226,36 +218,23 @@ std::string NodeChildrenToString(const flutter::SemanticsNode& node) {
AccessibilityBridge::AccessibilityBridge(
SetSemanticsEnabledCallback set_semantics_enabled_callback,
DispatchSemanticsActionCallback dispatch_semantics_action_callback,
const std::shared_ptr<sys::ServiceDirectory> services,
fuchsia::ui::views::ViewRef view_ref)
: AccessibilityBridge(std::move(set_semantics_enabled_callback),
std::move(dispatch_semantics_action_callback),
services,
dart_utils::RootInspectNode::CreateRootChild(
std::to_string(GetKoid(view_ref))),
std::move(view_ref)) {}
AccessibilityBridge::AccessibilityBridge(
SetSemanticsEnabledCallback set_semantics_enabled_callback,
DispatchSemanticsActionCallback dispatch_semantics_action_callback,
const std::shared_ptr<sys::ServiceDirectory> services,
inspect::Node inspect_node,
fuchsia::ui::views::ViewRef view_ref)
fidl::InterfaceHandle<fuchsia::accessibility::semantics::SemanticsManager>
semantics_manager,
fuchsia::ui::views::ViewRef view_ref,
inspect::Node inspect_node)
: set_semantics_enabled_callback_(
std::move(set_semantics_enabled_callback)),
dispatch_semantics_action_callback_(
std::move(dispatch_semantics_action_callback)),
binding_(this),
fuchsia_semantics_manager_(semantics_manager.Bind()),
inspect_node_(std::move(inspect_node)) {
services->Connect(fuchsia::accessibility::semantics::SemanticsManager::Name_,
fuchsia_semantics_manager_.NewRequest().TakeChannel());
fuchsia_semantics_manager_.set_error_handler([](zx_status_t status) {
FML_LOG(ERROR) << "Flutter cannot connect to SemanticsManager with status: "
<< zx_status_get_string(status) << ".";
});
fidl::InterfaceHandle<fuchsia::accessibility::semantics::SemanticListener>
listener_handle;
binding_.Bind(listener_handle.NewRequest());
fuchsia_semantics_manager_->RegisterViewForSemantics(
std::move(view_ref), binding_.NewBinding(), tree_ptr_.NewRequest());
#if !FLUTTER_RELEASE
// The first argument to |CreateLazyValues| is the name of the lazy node, and
@@ -276,9 +255,6 @@ AccessibilityBridge::AccessibilityBridge(
return fpromise::make_ok_promise(std::move(inspector));
});
#endif // !FLUTTER_RELEASE
fuchsia_semantics_manager_->RegisterViewForSemantics(
std::move(view_ref), std::move(listener_handle), tree_ptr_.NewRequest());
}
bool AccessibilityBridge::GetSemanticsEnabled() const {

View File

@@ -13,7 +13,6 @@
#include <fuchsia/sys/cpp/fidl.h>
#include <fuchsia/ui/gfx/cpp/fidl.h>
#include <lib/fidl/cpp/binding_set.h>
#include <lib/sys/cpp/service_directory.h>
#include <lib/sys/inspect/cpp/component.h>
#include <zircon/types.h>
@@ -67,15 +66,10 @@ class AccessibilityBridge
AccessibilityBridge(
SetSemanticsEnabledCallback set_semantics_enabled_callback,
DispatchSemanticsActionCallback dispatch_semantics_action_callback,
const std::shared_ptr<sys::ServiceDirectory> services,
fuchsia::ui::views::ViewRef view_ref);
AccessibilityBridge(
SetSemanticsEnabledCallback set_semantics_enabled_callback,
DispatchSemanticsActionCallback dispatch_semantics_action_callback,
const std::shared_ptr<sys::ServiceDirectory> services,
inspect::Node inspect_node,
fuchsia::ui::views::ViewRef view_ref);
fidl::InterfaceHandle<fuchsia::accessibility::semantics::SemanticsManager>
semantics_manager,
fuchsia::ui::views::ViewRef view_ref,
inspect::Node inspect_node);
// Returns true if accessible navigation is enabled.
bool GetSemanticsEnabled() const;
@@ -121,10 +115,6 @@ class AccessibilityBridge
SkRect screen_rect;
};
// This is the cache of all nodes we've sent to Fuchsia's SemanticsManager.
// Assists with pruning unreachable nodes and hit testing.
std::unordered_map<int32_t, SemanticsNode> nodes_;
fuchsia::accessibility::semantics::Node GetRootNodeUpdate(size_t& node_size);
// Derives the BoundingBox of a Flutter semantics node from its
@@ -220,10 +210,15 @@ class AccessibilityBridge
DispatchSemanticsActionCallback dispatch_semantics_action_callback_;
flutter::SemanticsNode root_flutter_semantics_node_;
float last_seen_view_pixel_ratio_ = 1.f;
fidl::Binding<fuchsia::accessibility::semantics::SemanticListener> binding_;
fuchsia::accessibility::semantics::SemanticsManagerPtr
fuchsia_semantics_manager_;
fuchsia::accessibility::semantics::SemanticTreePtr tree_ptr_;
// This is the cache of all nodes we've sent to Fuchsia's SemanticsManager.
// Assists with pruning unreachable nodes and hit testing.
std::unordered_map<int32_t, SemanticsNode> nodes_;
bool semantics_enabled_;
// Node to publish inspect data.

View File

@@ -2,9 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/fuchsia/flutter/accessibility_bridge.h"
#include "accessibility_bridge.h"
#include <gtest/gtest.h>
#include <lib/async-loop/cpp/loop.h>
#include <lib/async-loop/default.h>
#include <lib/async/cpp/executor.h>
@@ -14,12 +13,16 @@
#include <lib/inspect/cpp/inspector.h>
#include <lib/inspect/cpp/reader.h>
#include <lib/sys/cpp/testing/service_directory_provider.h>
#include <lib/ui/scenic/cpp/view_ref_pair.h>
#include <zircon/status.h>
#include <zircon/types.h>
#include <memory>
#include "flutter/lib/ui/semantics/semantics_node.h"
#include "flutter/shell/platform/fuchsia/flutter/flutter_runner_fakes.h"
#include "gtest/gtest.h"
#include "flutter_runner_fakes.h"
namespace flutter_runner_test {
@@ -85,9 +88,19 @@ class AccessibilityBridgeTest : public testing::Test {
protected:
void SetUp() override {
zx_status_t status = zx::eventpair::create(
/*flags*/ 0u, &view_ref_control_.reference, &view_ref_.reference);
EXPECT_EQ(status, ZX_OK);
// Connect to SemanticsManager service.
fidl::InterfaceHandle<fuchsia::accessibility::semantics::SemanticsManager>
semantics_manager;
zx_status_t semantics_status =
services_provider_.service_directory()
->Connect<fuchsia::accessibility::semantics::SemanticsManager>(
semantics_manager.NewRequest());
if (semantics_status != ZX_OK) {
FML_LOG(WARNING)
<< "fuchsia::accessibility::semantics::SemanticsManager connection "
"failed: "
<< zx_status_get_string(semantics_status);
}
accessibility_delegate_.actions.clear();
inspector_ = std::make_unique<inspect::Inspector>();
@@ -100,20 +113,19 @@ class AccessibilityBridgeTest : public testing::Test {
[this](int32_t node_id, flutter::SemanticsAction action) {
accessibility_delegate_.DispatchSemanticsAction(node_id, action);
};
auto [view_ref_control, view_ref] = scenic::ViewRefPair::New();
accessibility_bridge_ =
std::make_unique<flutter_runner::AccessibilityBridge>(
std::move(set_semantics_enabled_callback),
std::move(dispatch_semantics_action_callback),
services_provider_.service_directory(),
inspector_->GetRoot().CreateChild("test_node"),
std::move(view_ref_));
std::move(semantics_manager), std::move(view_ref),
inspector_->GetRoot().CreateChild("test_node"));
RunLoopUntilIdle();
}
void TearDown() override { semantics_manager_.ResetTree(); }
fuchsia::ui::views::ViewRefControl view_ref_control_;
fuchsia::ui::views::ViewRef view_ref_;
MockSemanticsManager semantics_manager_;
AccessibilityBridgeTestDelegate accessibility_delegate_;
std::unique_ptr<flutter_runner::AccessibilityBridge> accessibility_bridge_;

View File

@@ -4,8 +4,11 @@
#include "engine.h"
#include <fuchsia/accessibility/semantics/cpp/fidl.h>
#include <fuchsia/ui/scenic/cpp/fidl.h>
#include <lib/async/cpp/task.h>
#include <zircon/status.h>
#include <zircon/types.h>
#include <memory>
#include "flutter/common/graphics/persistent_cache.h"
@@ -34,6 +37,14 @@
namespace flutter_runner {
namespace {
zx_koid_t GetKoid(const fuchsia::ui::views::ViewRef& view_ref) {
zx_handle_t handle = view_ref.reference.get();
zx_info_handle_basic_t info;
zx_status_t status = zx_object_get_info(handle, ZX_INFO_HANDLE_BASIC, &info,
sizeof(info), nullptr, nullptr);
return status == ZX_OK ? info.koid : ZX_KOID_INVALID;
}
std::unique_ptr<flutter::PlatformMessage> MakeLocalizationPlatformMessage(
const fuchsia::intl::Profile& intl_profile) {
return std::make_unique<flutter::PlatformMessage>(
@@ -64,12 +75,11 @@ Engine::Engine(Delegate& delegate,
thread_label_(std::move(thread_label)),
thread_host_(CreateThreadHost(thread_label_)),
view_token_(std::move(view_token)),
view_ref_pair_(std::move(view_ref_pair)),
memory_pressure_watcher_binding_(this),
latest_memory_pressure_level_(fuchsia::memorypressure::Level::NORMAL),
intercept_all_input_(product_config.get_intercept_all_input()),
weak_factory_(this) {
Initialize(/*=use_flatland*/ false, std::move(svc),
Initialize(/*=use_flatland*/ false, std::move(view_ref_pair), std::move(svc),
std::move(runner_services), std::move(settings),
std::move(fdio_ns), std::move(directory_request),
std::move(product_config));
@@ -89,18 +99,19 @@ Engine::Engine(Delegate& delegate,
thread_label_(std::move(thread_label)),
thread_host_(CreateThreadHost(thread_label_)),
view_creation_token_(std::move(view_creation_token)),
view_ref_pair_(std::move(view_ref_pair)),
memory_pressure_watcher_binding_(this),
latest_memory_pressure_level_(fuchsia::memorypressure::Level::NORMAL),
intercept_all_input_(product_config.get_intercept_all_input()),
weak_factory_(this) {
Initialize(/*=use_flatland*/ true, std::move(svc), std::move(runner_services),
std::move(settings), std::move(fdio_ns),
std::move(directory_request), std::move(product_config));
Initialize(/*=use_flatland*/ true, std::move(view_ref_pair), std::move(svc),
std::move(runner_services), std::move(settings),
std::move(fdio_ns), std::move(directory_request),
std::move(product_config));
}
void Engine::Initialize(
bool use_flatland,
scenic::ViewRefPair view_ref_pair,
std::shared_ptr<sys::ServiceDirectory> svc,
std::shared_ptr<sys::ServiceDirectory> runner_services,
flutter::Settings settings,
@@ -125,7 +136,7 @@ void Engine::Initialize(
);
// Connect to Scenic.
auto scenic = svc->Connect<fuchsia::ui::scenic::Scenic>();
auto scenic = runner_services->Connect<fuchsia::ui::scenic::Scenic>();
fuchsia::ui::scenic::SessionEndpoints endpoints;
fidl::InterfaceHandle<fuchsia::ui::scenic::Session> session;
endpoints.set_session(session.NewRequest());
@@ -141,18 +152,46 @@ void Engine::Initialize(
// endpoints.set_touch_source(touch_source.NewRequest());
scenic->CreateSessionT(std::move(endpoints), [] {});
// Make clones of the `ViewRef` before sending it down to Scenic, since the
// refs are not copyable, and multiple consumers need view refs.
// Connect to SemanticsManager service.
fidl::InterfaceHandle<fuchsia::accessibility::semantics::SemanticsManager>
semantics_manager;
zx_status_t semantics_status =
runner_services
->Connect<fuchsia::accessibility::semantics::SemanticsManager>(
semantics_manager.NewRequest());
if (semantics_status != ZX_OK) {
FML_LOG(WARNING)
<< "fuchsia::accessibility::semantics::SemanticsManager connection "
"failed: "
<< zx_status_get_string(semantics_status);
}
// Connect to ImeService service.
fidl::InterfaceHandle<fuchsia::ui::input::ImeService> ime_service;
zx_status_t ime_status =
runner_services->Connect<fuchsia::ui::input::ImeService>(
ime_service.NewRequest());
if (ime_status != ZX_OK) {
FML_LOG(WARNING) << "fuchsia::ui::input::ImeService connection failed: "
<< zx_status_get_string(ime_status);
}
// Connect to Keyboard service.
fidl::InterfaceHandle<fuchsia::ui::input3::Keyboard> keyboard;
zx_status_t keyboard_status =
runner_services->Connect<fuchsia::ui::input3::Keyboard>(
keyboard.NewRequest());
FML_DCHECK(keyboard_status == ZX_OK)
<< "fuchsia::ui::input3::Keyboard connection failed: "
<< zx_status_get_string(keyboard_status);
// Make clones of the `ViewRef` before sending it to various places.
fuchsia::ui::views::ViewRef platform_view_ref;
view_ref_pair_.view_ref.Clone(&platform_view_ref);
fuchsia::ui::views::ViewRef accessibility_bridge_view_ref;
view_ref_pair_.view_ref.Clone(&accessibility_bridge_view_ref);
view_ref_pair.view_ref.Clone(&platform_view_ref);
fuchsia::ui::views::ViewRef accessibility_view_ref;
view_ref_pair.view_ref.Clone(&accessibility_view_ref);
fuchsia::ui::views::ViewRef isolate_view_ref;
view_ref_pair_.view_ref.Clone(&isolate_view_ref);
// Input3 keyboard listener registration requires a ViewRef as an event
// filter. So we clone it here, as ViewRefs can not be reused, only cloned.
fuchsia::ui::views::ViewRef keyboard_view_ref;
view_ref_pair_.view_ref.Clone(&keyboard_view_ref);
view_ref_pair.view_ref.Clone(&isolate_view_ref);
// Session is terminated on the raster thread, but we must terminate ourselves
// on the platform thread.
@@ -169,11 +208,10 @@ void Engine::Initialize(
});
};
fuchsia::ui::composition::ParentViewportWatcherPtr parent_viewport_watcher;
// Set up the session connection and other Scenic helpers on the raster
// thread. We also need to wait for the external view embedder to be set up
// before creating the shell.
fuchsia::ui::composition::ParentViewportWatcherPtr parent_viewport_watcher;
fml::AutoResetWaitableEvent view_embedder_latch;
auto session_inspect_node =
dart_utils::RootInspectNode::CreateRootChild("vsync_stats");
@@ -185,7 +223,7 @@ void Engine::Initialize(
view_token = std::move(view_token_),
view_creation_token = std::move(view_creation_token_),
request = parent_viewport_watcher.NewRequest(),
view_ref_pair = std::move(view_ref_pair_),
view_ref_pair = std::move(view_ref_pair),
max_frames_in_flight = product_config.get_max_frames_in_flight(),
vsync_offset = product_config.get_vsync_offset()]() mutable {
if (use_flatland) {
@@ -215,15 +253,6 @@ void Engine::Initialize(
}));
view_embedder_latch.Wait();
// Grab the parent environment services. The platform view may want to
// access some of these services.
fuchsia::sys::EnvironmentPtr environment;
svc->Connect(environment.NewRequest());
fidl::InterfaceHandle<fuchsia::sys::ServiceProvider>
parent_environment_service_provider;
environment->GetServices(parent_environment_service_provider.NewRequest());
environment.Unbind();
AccessibilityBridge::SetSemanticsEnabledCallback
set_semantics_enabled_callback = [this](bool enabled) {
auto platform_view = shell_->GetPlatformView();
@@ -243,10 +272,14 @@ void Engine::Initialize(
}
};
const std::string accessibility_inspect_name =
std::to_string(GetKoid(accessibility_view_ref));
accessibility_bridge_ = std::make_unique<AccessibilityBridge>(
std::move(set_semantics_enabled_callback),
std::move(dispatch_semantics_action_callback), svc,
std::move(accessibility_bridge_view_ref));
std::move(dispatch_semantics_action_callback),
std::move(semantics_manager), std::move(accessibility_view_ref),
dart_utils::RootInspectNode::CreateRootChild(
std::move(accessibility_inspect_name)));
OnEnableWireframe on_enable_wireframe_callback = std::bind(
&Engine::DebugWireframeSettingsChanged, this, std::placeholders::_1);
@@ -295,26 +328,6 @@ void Engine::Initialize(
auto run_configuration = flutter::RunConfiguration::InferFromSettings(
settings, task_runners.GetIOTaskRunner());
// Connect to fuchsia.ui.input3.Keyboard to hand out a listener.
using fuchsia::ui::input3::Keyboard;
using fuchsia::ui::input3::KeyboardListener;
// Keyboard client-side stub.
keyboard_svc_ = svc->Connect<Keyboard>();
ZX_ASSERT(keyboard_svc_.is_bound());
// KeyboardListener handle pair is not initialized until NewRequest() is
// called.
fidl::InterfaceHandle<KeyboardListener> keyboard_listener;
// Server side of KeyboardListener. Initializes the keyboard_listener
// handle.
fidl::InterfaceRequest<KeyboardListener> keyboard_listener_request =
keyboard_listener.NewRequest();
ZX_ASSERT(keyboard_listener_request.is_valid());
keyboard_svc_->AddListener(std::move(keyboard_view_ref),
keyboard_listener.Bind(), [] {});
OnSemanticsNodeUpdate on_semantics_node_update_callback =
[this](flutter::SemanticsNodeUpdates updates, float pixel_ratio) {
accessibility_bridge_->AddSemanticsNodeUpdate(updates, pixel_ratio);
@@ -328,12 +341,10 @@ void Engine::Initialize(
// Setup the callback that will instantiate the platform view.
flutter::Shell::CreateCallback<flutter::PlatformView>
on_create_platform_view = fml::MakeCopyable(
[this, use_flatland, debug_label = thread_label_,
view_ref = std::move(platform_view_ref), runner_services,
parent_environment_service_provider =
std::move(parent_environment_service_provider),
[this, use_flatland, view_ref = std::move(platform_view_ref),
session_listener_request = std::move(session_listener_request),
parent_viewport_watcher = std::move(parent_viewport_watcher),
ime_service = std::move(ime_service), keyboard = std::move(keyboard),
focuser = std::move(focuser),
view_ref_focused = std::move(view_ref_focused),
touch_source = std::move(touch_source),
@@ -355,7 +366,6 @@ void Engine::Initialize(
on_request_announce_callback =
std::move(on_request_announce_callback),
external_view_embedder = GetExternalViewEmbedder(),
keyboard_listener_request = std::move(keyboard_listener_request),
await_vsync_callback =
[this, use_flatland](FireCallbackCallback cb) {
if (use_flatland) {
@@ -410,19 +420,11 @@ void Engine::Initialize(
if (use_flatland) {
platform_view =
std::make_unique<flutter_runner::FlatlandPlatformView>(
shell, // delegate
debug_label, // debug label
std::move(view_ref), // view ref
shell.GetTaskRunners(), // task runners
std::move(runner_services),
std::move(
parent_environment_service_provider), // services
shell, shell.GetTaskRunners(), std::move(view_ref),
std::move(external_view_embedder), std::move(ime_service),
std::move(keyboard), std::move(touch_source),
std::move(focuser), std::move(view_ref_focused),
std::move(parent_viewport_watcher),
std::move(view_ref_focused), std::move(focuser),
std::move(touch_source),
// Server-side part of the
// fuchsia.ui.input3.KeyboardListener connection.
std::move(keyboard_listener_request),
std::move(on_enable_wireframe_callback),
std::move(on_create_flatland_view_callback),
std::move(on_update_view_callback),
@@ -430,25 +432,16 @@ void Engine::Initialize(
std::move(on_create_surface_callback),
std::move(on_semantics_node_update_callback),
std::move(on_request_announce_callback),
std::move(on_shader_warmup), external_view_embedder,
// Callbacks for VsyncWaiter to call into
// FlatlandConnection.
await_vsync_callback,
await_vsync_for_secondary_callback_callback);
std::move(on_shader_warmup),
std::move(await_vsync_callback),
std::move(await_vsync_for_secondary_callback_callback));
} else {
platform_view = std::make_unique<flutter_runner::GfxPlatformView>(
shell, // delegate
debug_label, // debug label
std::move(view_ref), // view ref
shell.GetTaskRunners(), // task runners
std::move(runner_services),
std::move(parent_environment_service_provider), // services
std::move(session_listener_request), // session listener
std::move(view_ref_focused), std::move(focuser),
std::move(touch_source),
// Server-side part of the fuchsia.ui.input3.KeyboardListener
// connection.
std::move(keyboard_listener_request),
shell, shell.GetTaskRunners(), std::move(view_ref),
std::move(external_view_embedder), std::move(ime_service),
std::move(keyboard), std::move(touch_source),
std::move(focuser), std::move(view_ref_focused),
std::move(session_listener_request),
std::move(on_session_listener_error_callback),
std::move(on_enable_wireframe_callback),
std::move(on_create_gfx_view_callback),
@@ -457,11 +450,8 @@ void Engine::Initialize(
std::move(on_create_surface_callback),
std::move(on_semantics_node_update_callback),
std::move(on_request_announce_callback),
std::move(on_shader_warmup), external_view_embedder,
// Callbacks for VsyncWaiter to call into
// GfxSessionConnection.
await_vsync_callback,
await_vsync_for_secondary_callback_callback);
std::move(on_shader_warmup), std::move(await_vsync_callback),
std::move(await_vsync_for_secondary_callback_callback));
}
return platform_view;
});

View File

@@ -17,7 +17,6 @@
#include <lib/sys/cpp/service_directory.h>
#include <lib/ui/scenic/cpp/id.h>
#include <lib/ui/scenic/cpp/view_ref_pair.h>
#include <lib/zx/event.h>
#include "flutter/flow/embedded_views.h"
#include "flutter/flow/surface.h"
@@ -86,43 +85,9 @@ class Engine final : public fuchsia::memorypressure::Watcher {
#endif // !defined(DART_PRODUCT)
private:
Delegate& delegate_;
const std::string thread_label_;
flutter::ThreadHost thread_host_;
fuchsia::ui::views::ViewToken view_token_;
fuchsia::ui::views::ViewCreationToken view_creation_token_;
std::shared_ptr<GfxSessionConnection>
session_connection_; // Must come before surface_producer_
std::shared_ptr<FlatlandConnection>
flatland_connection_; // Must come before surface_producer_
std::optional<VulkanSurfaceProducer> surface_producer_;
std::shared_ptr<FuchsiaExternalViewEmbedder> external_view_embedder_;
std::shared_ptr<FlatlandExternalViewEmbedder> flatland_view_embedder_;
scenic::ViewRefPair view_ref_pair_;
std::unique_ptr<IsolateConfigurator> isolate_configurator_;
std::unique_ptr<flutter::Shell> shell_;
std::unique_ptr<AccessibilityBridge> accessibility_bridge_;
fuchsia::intl::PropertyProviderPtr intl_property_provider_;
fuchsia::memorypressure::ProviderPtr memory_pressure_provider_;
fidl::Binding<fuchsia::memorypressure::Watcher>
memory_pressure_watcher_binding_;
// We need to track the latest memory pressure level to determine
// the direction of change when a new level is provided.
fuchsia::memorypressure::Level latest_memory_pressure_level_;
zx::event vsync_event_;
bool intercept_all_input_ = false;
fml::WeakPtrFactory<Engine> weak_factory_;
void Initialize(
bool use_flatland,
scenic::ViewRefPair view_ref_pair,
std::shared_ptr<sys::ServiceDirectory> svc,
std::shared_ptr<sys::ServiceDirectory> runner_services,
flutter::Settings settings,
@@ -175,9 +140,39 @@ class Engine final : public fuchsia::memorypressure::Watcher {
std::unique_ptr<flutter::Surface> CreateSurface();
friend class testing::EngineTest;
Delegate& delegate_;
fidl::InterfacePtr<fuchsia::ui::input3::Keyboard> keyboard_svc_;
const std::string thread_label_;
flutter::ThreadHost thread_host_;
fuchsia::ui::views::ViewToken view_token_;
fuchsia::ui::views::ViewCreationToken view_creation_token_;
std::shared_ptr<GfxSessionConnection>
session_connection_; // Must come before surface_producer_
std::shared_ptr<FlatlandConnection>
flatland_connection_; // Must come before surface_producer_
std::optional<VulkanSurfaceProducer> surface_producer_;
std::shared_ptr<FuchsiaExternalViewEmbedder> external_view_embedder_;
std::shared_ptr<FlatlandExternalViewEmbedder> flatland_view_embedder_;
std::unique_ptr<IsolateConfigurator> isolate_configurator_;
std::unique_ptr<flutter::Shell> shell_;
std::unique_ptr<AccessibilityBridge> accessibility_bridge_;
fuchsia::intl::PropertyProviderPtr intl_property_provider_;
fuchsia::memorypressure::ProviderPtr memory_pressure_provider_;
fidl::Binding<fuchsia::memorypressure::Watcher>
memory_pressure_watcher_binding_;
// We need to track the latest memory pressure level to determine
// the direction of change when a new level is provided.
fuchsia::memorypressure::Level latest_memory_pressure_level_;
bool intercept_all_input_ = false;
fml::WeakPtrFactory<Engine> weak_factory_;
friend class testing::EngineTest;
FML_DISALLOW_COPY_AND_ASSIGN(Engine);
};

View File

@@ -10,18 +10,16 @@ namespace flutter_runner {
FlatlandPlatformView::FlatlandPlatformView(
flutter::PlatformView::Delegate& delegate,
std::string debug_label,
fuchsia::ui::views::ViewRef view_ref,
flutter::TaskRunners task_runners,
std::shared_ptr<sys::ServiceDirectory> runner_services,
fidl::InterfaceHandle<fuchsia::sys::ServiceProvider>
parent_environment_service_provider,
fuchsia::ui::composition::ParentViewportWatcherPtr parent_viewport_watcher,
fidl::InterfaceHandle<fuchsia::ui::views::ViewRefFocused> vrf,
fidl::InterfaceHandle<fuchsia::ui::views::Focuser> focuser,
fuchsia::ui::views::ViewRef view_ref,
std::shared_ptr<flutter::ExternalViewEmbedder> external_view_embedder,
fidl::InterfaceHandle<fuchsia::ui::input::ImeService> ime_service,
fidl::InterfaceHandle<fuchsia::ui::input3::Keyboard> keyboard,
fidl::InterfaceHandle<fuchsia::ui::pointer::TouchSource> touch_source,
fidl::InterfaceRequest<fuchsia::ui::input3::KeyboardListener>
keyboard_listener,
fidl::InterfaceHandle<fuchsia::ui::views::Focuser> focuser,
fidl::InterfaceHandle<fuchsia::ui::views::ViewRefFocused> view_ref_focused,
fidl::InterfaceHandle<fuchsia::ui::composition::ParentViewportWatcher>
parent_viewport_watcher,
OnEnableWireframe wireframe_enabled_callback,
OnCreateFlatlandView on_create_view_callback,
OnUpdateView on_update_view_callback,
@@ -30,30 +28,27 @@ FlatlandPlatformView::FlatlandPlatformView(
OnSemanticsNodeUpdate on_semantics_node_update_callback,
OnRequestAnnounce on_request_announce_callback,
OnShaderWarmup on_shader_warmup,
std::shared_ptr<flutter::ExternalViewEmbedder> view_embedder,
AwaitVsyncCallback await_vsync_callback,
AwaitVsyncForSecondaryCallbackCallback
await_vsync_for_secondary_callback_callback)
: PlatformView(delegate,
std::move(debug_label),
std::move(view_ref),
std::move(task_runners),
std::move(runner_services),
std::move(parent_environment_service_provider),
std::move(vrf),
std::move(focuser),
std::move(view_ref),
std::move(external_view_embedder),
std::move(ime_service),
std::move(keyboard),
std::move(touch_source),
std::move(keyboard_listener),
std::move(focuser),
std::move(view_ref_focused),
std::move(wireframe_enabled_callback),
std::move(on_update_view_callback),
std::move(on_create_surface_callback),
std::move(on_semantics_node_update_callback),
std::move(on_request_announce_callback),
std::move(on_shader_warmup),
std::move(view_embedder),
std::move(await_vsync_callback),
std::move(await_vsync_for_secondary_callback_callback)),
parent_viewport_watcher_(std::move(parent_viewport_watcher)),
parent_viewport_watcher_(parent_viewport_watcher.Bind()),
on_create_view_callback_(std::move(on_create_view_callback)),
on_destroy_view_callback_(std::move(on_destroy_view_callback)),
weak_factory_(this) {

View File

@@ -24,19 +24,17 @@ class FlatlandPlatformView final : public flutter_runner::PlatformView {
public:
FlatlandPlatformView(
flutter::PlatformView::Delegate& delegate,
std::string debug_label,
fuchsia::ui::views::ViewRef view_ref,
flutter::TaskRunners task_runners,
std::shared_ptr<sys::ServiceDirectory> runner_services,
fidl::InterfaceHandle<fuchsia::sys::ServiceProvider>
parent_environment_service_provider,
fuchsia::ui::composition::ParentViewportWatcherPtr
parent_viewport_watcher,
fidl::InterfaceHandle<fuchsia::ui::views::ViewRefFocused> vrf,
fidl::InterfaceHandle<fuchsia::ui::views::Focuser> focuser,
fuchsia::ui::views::ViewRef view_ref,
std::shared_ptr<flutter::ExternalViewEmbedder> external_view_embedder,
fidl::InterfaceHandle<fuchsia::ui::input::ImeService> ime_service,
fidl::InterfaceHandle<fuchsia::ui::input3::Keyboard> keyboard,
fidl::InterfaceHandle<fuchsia::ui::pointer::TouchSource> touch_source,
fidl::InterfaceRequest<fuchsia::ui::input3::KeyboardListener>
keyboard_listener,
fidl::InterfaceHandle<fuchsia::ui::views::Focuser> focuser,
fidl::InterfaceHandle<fuchsia::ui::views::ViewRefFocused>
view_ref_focused,
fidl::InterfaceHandle<fuchsia::ui::composition::ParentViewportWatcher>
parent_viewport_watcher,
OnEnableWireframe wireframe_enabled_callback,
OnCreateFlatlandView on_create_view_callback,
OnUpdateView on_update_view_callback,
@@ -45,11 +43,10 @@ class FlatlandPlatformView final : public flutter_runner::PlatformView {
OnSemanticsNodeUpdate on_semantics_node_update_callback,
OnRequestAnnounce on_request_announce_callback,
OnShaderWarmup on_shader_warmup,
std::shared_ptr<flutter::ExternalViewEmbedder> view_embedder,
AwaitVsyncCallback await_vsync_callback,
AwaitVsyncForSecondaryCallbackCallback
await_vsync_for_secondary_callback_callback);
~FlatlandPlatformView();
~FlatlandPlatformView() override;
void OnGetLayout(fuchsia::ui::composition::LayoutInfo info);
void OnParentViewportStatus(

View File

@@ -10,19 +10,16 @@ namespace flutter_runner {
GfxPlatformView::GfxPlatformView(
flutter::PlatformView::Delegate& delegate,
std::string debug_label,
fuchsia::ui::views::ViewRef view_ref,
flutter::TaskRunners task_runners,
std::shared_ptr<sys::ServiceDirectory> runner_services,
fidl::InterfaceHandle<fuchsia::sys::ServiceProvider>
parent_environment_service_provider,
fuchsia::ui::views::ViewRef view_ref,
std::shared_ptr<flutter::ExternalViewEmbedder> external_view_embedder,
fidl::InterfaceHandle<fuchsia::ui::input::ImeService> ime_service,
fidl::InterfaceHandle<fuchsia::ui::input3::Keyboard> keyboard,
fidl::InterfaceHandle<fuchsia::ui::pointer::TouchSource> touch_source,
fidl::InterfaceHandle<fuchsia::ui::views::Focuser> focuser,
fidl::InterfaceHandle<fuchsia::ui::views::ViewRefFocused> view_ref_focused,
fidl::InterfaceRequest<fuchsia::ui::scenic::SessionListener>
session_listener_request,
fidl::InterfaceHandle<fuchsia::ui::views::ViewRefFocused> vrf,
fidl::InterfaceHandle<fuchsia::ui::views::Focuser> focuser,
fidl::InterfaceHandle<fuchsia::ui::pointer::TouchSource> touch_source,
fidl::InterfaceRequest<fuchsia::ui::input3::KeyboardListener>
keyboard_listener,
fit::closure on_session_listener_error_callback,
OnEnableWireframe wireframe_enabled_callback,
OnCreateGfxView on_create_view_callback,
@@ -32,27 +29,24 @@ GfxPlatformView::GfxPlatformView(
OnSemanticsNodeUpdate on_semantics_node_update_callback,
OnRequestAnnounce on_request_announce_callback,
OnShaderWarmup on_shader_warmup,
std::shared_ptr<flutter::ExternalViewEmbedder> view_embedder,
AwaitVsyncCallback await_vsync_callback,
AwaitVsyncForSecondaryCallbackCallback
await_vsync_for_secondary_callback_callback)
: PlatformView(delegate,
std::move(debug_label),
std::move(view_ref),
std::move(task_runners),
std::move(runner_services),
std::move(parent_environment_service_provider),
std::move(vrf),
std::move(focuser),
std::move(view_ref),
std::move(external_view_embedder),
std::move(ime_service),
std::move(keyboard),
std::move(touch_source),
std::move(keyboard_listener),
std::move(focuser),
std::move(view_ref_focused),
std::move(wireframe_enabled_callback),
std::move(on_update_view_callback),
std::move(on_create_surface_callback),
std::move(on_semantics_node_update_callback),
std::move(on_request_announce_callback),
std::move(on_shader_warmup),
std::move(view_embedder),
std::move(await_vsync_callback),
std::move(await_vsync_for_secondary_callback_callback)),
session_listener_binding_(this, std::move(session_listener_request)),

View File

@@ -27,19 +27,17 @@ class GfxPlatformView final : public flutter_runner::PlatformView,
public:
GfxPlatformView(
flutter::PlatformView::Delegate& delegate,
std::string debug_label,
fuchsia::ui::views::ViewRef view_ref,
flutter::TaskRunners task_runners,
std::shared_ptr<sys::ServiceDirectory> runner_services,
fidl::InterfaceHandle<fuchsia::sys::ServiceProvider>
parent_environment_service_provider,
fuchsia::ui::views::ViewRef view_ref,
std::shared_ptr<flutter::ExternalViewEmbedder> external_view_embedder,
fidl::InterfaceHandle<fuchsia::ui::input::ImeService> ime_service,
fidl::InterfaceHandle<fuchsia::ui::input3::Keyboard> keyboard,
fidl::InterfaceHandle<fuchsia::ui::pointer::TouchSource> touch_source,
fidl::InterfaceHandle<fuchsia::ui::views::Focuser> focuser,
fidl::InterfaceHandle<fuchsia::ui::views::ViewRefFocused>
view_ref_focused,
fidl::InterfaceRequest<fuchsia::ui::scenic::SessionListener>
session_listener_request,
fidl::InterfaceHandle<fuchsia::ui::views::ViewRefFocused> vrf,
fidl::InterfaceHandle<fuchsia::ui::views::Focuser> focuser,
fidl::InterfaceHandle<fuchsia::ui::pointer::TouchSource> touch_source,
fidl::InterfaceRequest<fuchsia::ui::input3::KeyboardListener>
keyboard_listener,
fit::closure on_session_listener_error_callback,
OnEnableWireframe wireframe_enabled_callback,
OnCreateGfxView on_create_view_callback,
@@ -49,11 +47,11 @@ class GfxPlatformView final : public flutter_runner::PlatformView,
OnSemanticsNodeUpdate on_semantics_node_update_callback,
OnRequestAnnounce on_request_announce_callback,
OnShaderWarmup on_shader_warmup,
std::shared_ptr<flutter::ExternalViewEmbedder> view_embedder,
AwaitVsyncCallback await_vsync_callback,
AwaitVsyncForSecondaryCallbackCallback
await_vsync_for_secondary_callback_callback);
~GfxPlatformView();
~GfxPlatformView() override;
private:
// |fuchsia::ui::scenic::SessionListener|

View File

@@ -10,9 +10,7 @@
"vulkan"
],
"services": [
"fuchsia.accessibility.SettingsManager",
"fuchsia.accessibility.semantics.SemanticsManager",
"fuchsia.deprecatedtimezone.Timezone",
"fuchsia.device.NameProvider",
"fuchsia.feedback.CrashReporter",
"fuchsia.fonts.Provider",
@@ -22,10 +20,12 @@
"fuchsia.net.name.Lookup",
"fuchsia.posix.socket.Provider",
"fuchsia.sysmem.Allocator",
"fuchsia.timezone.Timezone",
"fuchsia.tracing.provider.Registry",
"fuchsia.ui.composition.Allocator",
"fuchsia.ui.composition.Flatland",
"fuchsia.ui.input.ImeService",
"fuchsia.ui.input3.Keyboard",
"fuchsia.ui.scenic.Scenic",
"fuchsia.vulkan.loader.Loader"
]
}

View File

@@ -10,9 +10,7 @@
"vulkan"
],
"services": [
"fuchsia.accessibility.SettingsManager",
"fuchsia.accessibility.semantics.SemanticsManager",
"fuchsia.deprecatedtimezone.Timezone",
"fuchsia.device.NameProvider",
"fuchsia.feedback.CrashReporter",
"fuchsia.fonts.Provider",
@@ -22,10 +20,12 @@
"fuchsia.net.name.Lookup",
"fuchsia.posix.socket.Provider",
"fuchsia.sysmem.Allocator",
"fuchsia.timezone.Timezone",
"fuchsia.tracing.provider.Registry",
"fuchsia.ui.composition.Allocator",
"fuchsia.ui.composition.Flatland",
"fuchsia.ui.input.ImeService",
"fuchsia.ui.input3.Keyboard",
"fuchsia.ui.scenic.Scenic",
"fuchsia.vulkan.loader.Loader"
]
}

View File

@@ -11,9 +11,7 @@
"vulkan"
],
"services": [
"fuchsia.accessibility.SettingsManager",
"fuchsia.accessibility.semantics.SemanticsManager",
"fuchsia.deprecatedtimezone.Timezone",
"fuchsia.device.NameProvider",
"fuchsia.feedback.CrashReporter",
"fuchsia.fonts.Provider",
@@ -23,10 +21,12 @@
"fuchsia.net.name.Lookup",
"fuchsia.posix.socket.Provider",
"fuchsia.sysmem.Allocator",
"fuchsia.timezone.Timezone",
"fuchsia.tracing.provider.Registry",
"fuchsia.ui.composition.Allocator",
"fuchsia.ui.composition.Flatland",
"fuchsia.ui.input.ImeService",
"fuchsia.ui.input3.Keyboard",
"fuchsia.ui.scenic.Scenic",
"fuchsia.vulkan.loader.Loader"
]
}

View File

@@ -11,9 +11,7 @@
"vulkan"
],
"services": [
"fuchsia.accessibility.SettingsManager",
"fuchsia.accessibility.semantics.SemanticsManager",
"fuchsia.deprecatedtimezone.Timezone",
"fuchsia.device.NameProvider",
"fuchsia.feedback.CrashReporter",
"fuchsia.fonts.Provider",
@@ -23,10 +21,12 @@
"fuchsia.net.name.Lookup",
"fuchsia.posix.socket.Provider",
"fuchsia.sysmem.Allocator",
"fuchsia.timezone.Timezone",
"fuchsia.tracing.provider.Registry",
"fuchsia.ui.composition.Allocator",
"fuchsia.ui.composition.Flatland",
"fuchsia.ui.input.ImeService",
"fuchsia.ui.input3.Keyboard",
"fuchsia.ui.scenic.Scenic",
"fuchsia.vulkan.loader.Loader"
]
}

View File

@@ -40,46 +40,46 @@ template <class T>
void SetInterfaceErrorHandler(fidl::InterfacePtr<T>& interface,
std::string name) {
interface.set_error_handler([name](zx_status_t status) {
FML_LOG(ERROR) << "Interface error on: " << name << "status: " << status;
FML_LOG(ERROR) << "Interface error on: " << name << ", status: " << status;
});
}
template <class T>
void SetInterfaceErrorHandler(fidl::Binding<T>& binding, std::string name) {
binding.set_error_handler([name](zx_status_t status) {
FML_LOG(ERROR) << "Interface error on: " << name << ", status: " << status;
FML_LOG(ERROR) << "Binding error on: " << name << ", status: " << status;
});
}
PlatformView::PlatformView(
flutter::PlatformView::Delegate& delegate,
std::string debug_label,
fuchsia::ui::views::ViewRef view_ref,
flutter::TaskRunners task_runners,
std::shared_ptr<sys::ServiceDirectory> runner_services,
fidl::InterfaceHandle<fuchsia::sys::ServiceProvider>
parent_environment_service_provider_handle,
fidl::InterfaceHandle<fuchsia::ui::views::ViewRefFocused> vrf,
fidl::InterfaceHandle<fuchsia::ui::views::Focuser> focuser,
fuchsia::ui::views::ViewRef view_ref,
std::shared_ptr<flutter::ExternalViewEmbedder> external_view_embedder,
fidl::InterfaceHandle<fuchsia::ui::input::ImeService> ime_service,
fidl::InterfaceHandle<fuchsia::ui::input3::Keyboard> keyboard,
fidl::InterfaceHandle<fuchsia::ui::pointer::TouchSource> touch_source,
fidl::InterfaceRequest<fuchsia::ui::input3::KeyboardListener>
keyboard_listener_request,
fidl::InterfaceHandle<fuchsia::ui::views::Focuser> focuser,
fidl::InterfaceHandle<fuchsia::ui::views::ViewRefFocused> view_ref_focused,
OnEnableWireframe wireframe_enabled_callback,
OnUpdateView on_update_view_callback,
OnCreateSurface on_create_surface_callback,
OnSemanticsNodeUpdate on_semantics_node_update_callback,
OnRequestAnnounce on_request_announce_callback,
OnShaderWarmup on_shader_warmup,
std::shared_ptr<flutter::ExternalViewEmbedder> external_view_embedder,
AwaitVsyncCallback await_vsync_callback,
AwaitVsyncForSecondaryCallbackCallback
await_vsync_for_secondary_callback_callback)
: flutter::PlatformView(delegate, std::move(task_runners)),
debug_label_(std::move(debug_label)),
view_ref_(std::move(view_ref)),
external_view_embedder_(external_view_embedder),
focus_delegate_(
std::make_shared<FocusDelegate>(std::move(vrf), std::move(focuser))),
std::make_shared<FocusDelegate>(std::move(view_ref_focused),
std::move(focuser))),
pointer_delegate_(
std::make_shared<PointerDelegate>(std::move(touch_source))),
ime_client_(this),
text_sync_service_(ime_service.Bind()),
keyboard_listener_binding_(this),
keyboard_(keyboard.Bind()),
wireframe_enabled_callback_(std::move(wireframe_enabled_callback)),
on_update_view_callback_(std::move(on_update_view_callback)),
on_create_surface_callback_(std::move(on_create_surface_callback)),
@@ -87,28 +87,22 @@ PlatformView::PlatformView(
std::move(on_semantics_node_update_callback)),
on_request_announce_callback_(std::move(on_request_announce_callback)),
on_shader_warmup_(std::move(on_shader_warmup)),
external_view_embedder_(external_view_embedder),
ime_client_(this),
keyboard_listener_binding_(this, std::move(keyboard_listener_request)),
await_vsync_callback_(await_vsync_callback),
await_vsync_for_secondary_callback_callback_(
await_vsync_for_secondary_callback_callback),
weak_factory_(this) {
// Register all error handlers.
SetInterfaceErrorHandler(ime_, "Input Method Editor");
SetInterfaceErrorHandler(ime_client_, "IME Client");
SetInterfaceErrorHandler(text_sync_service_, "Text Sync Service");
SetInterfaceErrorHandler(parent_environment_service_provider_,
"Parent Environment Service Provider");
SetInterfaceErrorHandler(keyboard_listener_binding_,
"KeyboardListener Service");
// Access the IME service.
parent_environment_service_provider_ =
parent_environment_service_provider_handle.Bind();
SetInterfaceErrorHandler(keyboard_listener_binding_, "Keyboard Listener");
SetInterfaceErrorHandler(keyboard_, "Keyboard");
parent_environment_service_provider_.get()->ConnectToService(
fuchsia::ui::input::ImeService::Name_,
text_sync_service_.NewRequest().TakeChannel());
// Configure keyboard listener.
keyboard_->AddListener(std::move(view_ref),
keyboard_listener_binding_.NewBinding(), [] {});
// Begin watching for focus changes.
focus_delegate_->WatchLoop([weak = weak_factory_.GetWeakPtr()](bool focused) {
if (!weak) {
FML_LOG(WARNING) << "PlatformView use-after-free attempted. Ignoring.";
@@ -124,6 +118,7 @@ PlatformView::PlatformView(
}
});
// Begin watching for pointer events.
pointer_delegate_->WatchLoop([weak = weak_factory_.GetWeakPtr()](
std::vector<flutter::PointerData> events) {
if (!weak) {
@@ -413,16 +408,18 @@ void PlatformView::OnKeyEvent(
callback(fuchsia::ui::input3::KeyEventStatus::NOT_HANDLED);
return;
}
keyboard_.ConsumeEvent(std::move(key_event));
keyboard_translator_.ConsumeEvent(std::move(key_event));
rapidjson::Document document;
auto& allocator = document.GetAllocator();
document.SetObject();
document.AddMember("type", rapidjson::Value(type, strlen(type)), allocator);
document.AddMember("keymap", rapidjson::Value("fuchsia"), allocator);
document.AddMember("hidUsage", keyboard_.LastHIDUsage(), allocator);
document.AddMember("codePoint", keyboard_.LastCodePoint(), allocator);
document.AddMember("modifiers", keyboard_.Modifiers(), allocator);
document.AddMember("hidUsage", keyboard_translator_.LastHIDUsage(),
allocator);
document.AddMember("codePoint", keyboard_translator_.LastCodePoint(),
allocator);
document.AddMember("modifiers", keyboard_translator_.Modifiers(), allocator);
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
document.Accept(writer);

View File

@@ -65,29 +65,26 @@ class PlatformView : public flutter::PlatformView,
public:
PlatformView(
flutter::PlatformView::Delegate& delegate,
std::string debug_label,
fuchsia::ui::views::ViewRef view_ref,
flutter::TaskRunners task_runners,
std::shared_ptr<sys::ServiceDirectory> runner_services,
fidl::InterfaceHandle<fuchsia::sys::ServiceProvider>
parent_environment_service_provider,
fidl::InterfaceHandle<fuchsia::ui::views::ViewRefFocused> vrf,
fidl::InterfaceHandle<fuchsia::ui::views::Focuser> focuser,
fuchsia::ui::views::ViewRef view_ref,
std::shared_ptr<flutter::ExternalViewEmbedder> external_view_embedder,
fidl::InterfaceHandle<fuchsia::ui::input::ImeService> ime_service,
fidl::InterfaceHandle<fuchsia::ui::input3::Keyboard> keyboard,
fidl::InterfaceHandle<fuchsia::ui::pointer::TouchSource> touch_source,
fidl::InterfaceRequest<fuchsia::ui::input3::KeyboardListener>
keyboard_listener,
fidl::InterfaceHandle<fuchsia::ui::views::Focuser> focuser,
fidl::InterfaceHandle<fuchsia::ui::views::ViewRefFocused>
view_ref_focused,
OnEnableWireframe wireframe_enabled_callback,
OnUpdateView on_update_view_callback,
OnCreateSurface on_create_surface_callback,
OnSemanticsNodeUpdate on_semantics_node_update_callback,
OnRequestAnnounce on_request_announce_callback,
OnShaderWarmup on_shader_warmup,
std::shared_ptr<flutter::ExternalViewEmbedder> view_embedder,
AwaitVsyncCallback await_vsync_callback,
AwaitVsyncForSecondaryCallbackCallback
await_vsync_for_secondary_callback_callback);
virtual ~PlatformView();
~PlatformView() override;
// |flutter::PlatformView|
void SetSemanticsEnabled(bool enabled) override;
@@ -174,13 +171,6 @@ class PlatformView : public flutter::PlatformView,
// Utility function for coordinate massaging.
std::array<float, 2> ClampToViewSpace(const float x, const float y) const;
const std::string debug_label_;
// TODO(MI4-2490): remove once ViewRefControl is passed to Scenic and kept
// alive there
const fuchsia::ui::views::ViewRef view_ref_;
std::shared_ptr<FocusDelegate> focus_delegate_;
std::shared_ptr<PointerDelegate> pointer_delegate_;
// Logical size and origin, and logical->physical ratio. These are optional
// to provide an "unset" state during program startup, before Scenic has sent
// any metrics-related events to provide initial values for these.
@@ -192,23 +182,20 @@ class PlatformView : public flutter::PlatformView,
std::optional<std::array<float, 2>> view_logical_origin_;
std::optional<float> view_pixel_ratio_;
OnEnableWireframe wireframe_enabled_callback_;
OnUpdateView on_update_view_callback_;
OnCreateSurface on_create_surface_callback_;
// Accessibility handlers:
OnSemanticsNodeUpdate on_semantics_node_update_callback_;
OnRequestAnnounce on_request_announce_callback_;
OnShaderWarmup on_shader_warmup_;
std::shared_ptr<flutter::ExternalViewEmbedder> external_view_embedder_;
int current_text_input_client_ = 0;
std::shared_ptr<FocusDelegate> focus_delegate_;
std::shared_ptr<PointerDelegate> pointer_delegate_;
fidl::Binding<fuchsia::ui::input::InputMethodEditorClient> ime_client_;
fuchsia::ui::input::InputMethodEditorPtr ime_;
fuchsia::ui::input::ImeServicePtr text_sync_service_;
int current_text_input_client_ = 0;
fuchsia::sys::ServiceProviderPtr parent_environment_service_provider_;
fidl::Binding<fuchsia::ui::input3::KeyboardListener>
keyboard_listener_binding_;
fuchsia::ui::input3::KeyboardPtr keyboard_;
Keyboard keyboard_translator_;
// last_text_state_ is the last state of the text input as reported by the IME
// or initialized by Flutter. We set it to null if Flutter doesn't want any
@@ -226,13 +213,12 @@ class PlatformView : public flutter::PlatformView,
// https://github.com/flutter/flutter/issues/55966
std::set<std::string /* channel */> unregistered_channels_;
// The registered binding for serving the keyboard listener server endpoint.
fidl::Binding<fuchsia::ui::input3::KeyboardListener>
keyboard_listener_binding_;
// The keyboard translation for fuchsia.ui.input3.KeyEvent.
Keyboard keyboard_;
OnEnableWireframe wireframe_enabled_callback_;
OnUpdateView on_update_view_callback_;
OnCreateSurface on_create_surface_callback_;
OnSemanticsNodeUpdate on_semantics_node_update_callback_;
OnRequestAnnounce on_request_announce_callback_;
OnShaderWarmup on_shader_warmup_;
AwaitVsyncCallback await_vsync_callback_;
AwaitVsyncForSecondaryCallbackCallback
await_vsync_for_secondary_callback_callback_;

View File

@@ -2,14 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "gfx_platform_view.h"
#include <fuchsia/ui/gfx/cpp/fidl.h>
#include <fuchsia/ui/input/cpp/fidl.h>
#include <fuchsia/ui/input3/cpp/fidl.h>
#include <fuchsia/ui/input3/cpp/fidl_test_base.h>
#include <fuchsia/ui/scenic/cpp/fidl.h>
#include <fuchsia/ui/views/cpp/fidl.h>
#include <lib/async-loop/cpp/loop.h>
#include <lib/async-loop/default.h>
#include <lib/async/default.h>
#include <lib/fidl/cpp/binding_set.h>
#include <lib/sys/cpp/testing/service_directory_provider.h>
#include <lib/ui/scenic/cpp/view_ref_pair.h>
#include <memory>
@@ -25,6 +29,8 @@
#include "flutter/shell/platform/fuchsia/flutter/gfx_platform_view.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "platform/assert.h"
#include "surface.h"
#include "task_runner_adapter.h"
#include "tests/fakes/focuser.h"
@@ -36,11 +42,6 @@
namespace flutter_runner::testing {
namespace {
std::string ToString(const fml::Mapping& mapping) {
return std::string(mapping.GetMapping(),
mapping.GetMapping() + mapping.GetSize());
}
class MockExternalViewEmbedder : public flutter::ExternalViewEmbedder {
public:
SkCanvas* GetRootCanvas() override { return nullptr; }
@@ -173,6 +174,47 @@ class MockResponse : public flutter::PlatformMessageResponse {
MOCK_METHOD0(CompleteEmpty, void());
};
class TestPlatformMessageResponse : public flutter::PlatformMessageResponse {
public:
TestPlatformMessageResponse() {}
void Complete(std::unique_ptr<fml::Mapping> data) override {
result_string = std::string(
reinterpret_cast<const char*>(data->GetMapping()), data->GetSize());
is_complete_ = true;
}
void CompleteEmpty() override { is_complete_ = true; }
std::string result_string;
FML_DISALLOW_COPY_AND_ASSIGN(TestPlatformMessageResponse);
};
class MockKeyboard : public fuchsia::ui::input3::testing::Keyboard_TestBase {
public:
explicit MockKeyboard(
fidl::InterfaceRequest<fuchsia::ui::input3::Keyboard> keyboard)
: keyboard_(this, std::move(keyboard)) {}
~MockKeyboard() = default;
void AddListener(
fuchsia::ui::views::ViewRef view_ref,
fidl::InterfaceHandle<fuchsia::ui::input3::KeyboardListener> listener,
AddListenerCallback callback) override {
FML_CHECK(!listener_.is_bound());
listener_ = listener.Bind();
view_ref_ = std::move(view_ref);
callback();
}
void NotImplemented_(const std::string& name) override { FAIL(); }
fidl::Binding<fuchsia::ui::input3::Keyboard> keyboard_;
fuchsia::ui::input3::KeyboardListenerPtr listener_{};
fuchsia::ui::views::ViewRef view_ref_{};
FML_DISALLOW_COPY_AND_ASSIGN(MockKeyboard);
};
// Used to construct partial instances of PlatformView for testing. The
// PlatformView constructor has many parameters, not all of which need to
// be filled out for each test. The builder allows you to initialize only
@@ -181,31 +223,26 @@ class MockResponse : public flutter::PlatformMessageResponse {
class PlatformViewBuilder {
public:
PlatformViewBuilder(flutter::PlatformView::Delegate& delegate,
flutter::TaskRunners task_runners,
std::shared_ptr<sys::ServiceDirectory> runner_services)
flutter::TaskRunners task_runners)
: delegate_(delegate),
debug_label_("test_platform_view"),
view_ref_(fuchsia::ui::views::ViewRef()),
task_runners_(task_runners),
runner_services_(runner_services) {}
view_ref_pair_(scenic::ViewRefPair::New()) {}
// Add builder methods as required.
PlatformViewBuilder& SetServiceProvider(
fidl::InterfaceHandle<fuchsia::sys::ServiceProvider> service_provider) {
parent_environment_service_provider_ = std::move(service_provider);
PlatformViewBuilder& SetExternalViewEmbedder(
std::shared_ptr<flutter::ExternalViewEmbedder> embedder) {
external_external_view_embedder_ = embedder;
return *this;
}
PlatformViewBuilder& SetViewRefFocused(
fidl::InterfaceHandle<fuchsia::ui::views::ViewRefFocused> vrf) {
vrf_ = std::move(vrf);
PlatformViewBuilder& SetImeService(
fidl::InterfaceHandle<fuchsia::ui::input::ImeService> ime_service) {
ime_service_ = std::move(ime_service);
return *this;
}
PlatformViewBuilder& SetFocuser(
fidl::InterfaceHandle<fuchsia::ui::views::Focuser> focuser) {
focuser_ = std::move(focuser);
PlatformViewBuilder& SetKeyboard(
fidl::InterfaceHandle<fuchsia::ui::input3::Keyboard> keyboard) {
keyboard_ = std::move(keyboard);
return *this;
}
@@ -215,13 +252,22 @@ class PlatformViewBuilder {
return *this;
}
PlatformViewBuilder& SetDestroyViewCallback(OnDestroyGfxView callback) {
on_destroy_view_callback_ = std::move(callback);
PlatformViewBuilder& SetFocuser(
fidl::InterfaceHandle<fuchsia::ui::views::Focuser> focuser) {
focuser_ = std::move(focuser);
return *this;
}
PlatformViewBuilder& SetUpdateViewCallback(OnUpdateView callback) {
on_update_view_callback_ = std::move(callback);
PlatformViewBuilder& SetViewRefFocused(
fidl::InterfaceHandle<fuchsia::ui::views::ViewRefFocused>
view_ref_focused) {
view_ref_focused_ = std::move(view_ref_focused);
return *this;
}
PlatformViewBuilder& SetSessionListenerRequest(
fidl::InterfaceRequest<fuchsia::ui::scenic::SessionListener> request) {
session_listener_request_ = std::move(request);
return *this;
}
@@ -235,14 +281,13 @@ class PlatformViewBuilder {
return *this;
}
PlatformViewBuilder& SetShaderWarmupCallback(OnShaderWarmup callback) {
on_shader_warmup_callback_ = std::move(callback);
PlatformViewBuilder& SetUpdateViewCallback(OnUpdateView callback) {
on_update_view_callback_ = std::move(callback);
return *this;
}
PlatformViewBuilder& SetSessionListenerRequest(
fidl::InterfaceRequest<fuchsia::ui::scenic::SessionListener> request) {
session_listener_request_ = std::move(request);
PlatformViewBuilder& SetDestroyViewCallback(OnDestroyGfxView callback) {
on_destroy_view_callback_ = std::move(callback);
return *this;
}
@@ -251,15 +296,8 @@ class PlatformViewBuilder {
return *this;
}
PlatformViewBuilder& SetViewEmbedder(
std::shared_ptr<flutter::ExternalViewEmbedder> embedder) {
view_embedder_ = embedder;
return *this;
}
PlatformViewBuilder& SetKeyboardListener(
fidl::InterfaceRequest<fuchsia::ui::input3::KeyboardListener> listener) {
keyboard_listener_ = std::move(listener);
PlatformViewBuilder& SetShaderWarmupCallback(OnShaderWarmup callback) {
on_shader_warmup_callback_ = std::move(callback);
return *this;
}
@@ -268,11 +306,10 @@ class PlatformViewBuilder {
EXPECT_FALSE(std::exchange(built_, true))
<< "Build() was already called, this buider is good for one use only.";
return GfxPlatformView(
delegate_, debug_label_, std::move(view_ref_), task_runners_,
runner_services_, std::move(parent_environment_service_provider_),
std::move(session_listener_request_), std::move(vrf_),
std::move(focuser_), std::move(touch_source_),
std::move(keyboard_listener_),
delegate_, task_runners_, std::move(view_ref_pair_.view_ref),
external_external_view_embedder_, std::move(ime_service_),
std::move(keyboard_), std::move(touch_source_), std::move(focuser_),
std::move(view_ref_focused_), std::move(session_listener_request_),
std::move(on_session_listener_error_callback_),
std::move(wireframe_enabled_callback_),
std::move(on_create_view_callback_),
@@ -281,46 +318,43 @@ class PlatformViewBuilder {
std::move(on_create_surface_callback_),
std::move(on_semantics_node_update_callback_),
std::move(on_request_announce_callback_),
std::move(on_shader_warmup_callback_), view_embedder_, [](auto...) {},
[](auto...) {});
std::move(on_shader_warmup_callback_), [](auto...) {}, [](auto...) {});
}
private:
PlatformViewBuilder() = delete;
bool built_{false};
// Required elements. Make sure to initialize them.
flutter::PlatformView::Delegate& delegate_;
std::string debug_label_;
fuchsia::ui::views::ViewRef view_ref_;
flutter::TaskRunners task_runners_;
std::shared_ptr<sys::ServiceDirectory> runner_services_{nullptr};
fidl::InterfaceHandle<fuchsia::sys::ServiceProvider>
parent_environment_service_provider_{nullptr};
scenic::ViewRefPair view_ref_pair_;
// Optional elements.
std::shared_ptr<flutter::ExternalViewEmbedder>
external_external_view_embedder_;
fidl::InterfaceHandle<fuchsia::ui::input::ImeService> ime_service_;
fidl::InterfaceHandle<fuchsia::ui::input3::Keyboard> keyboard_;
fidl::InterfaceHandle<fuchsia::ui::pointer::TouchSource> touch_source_;
fidl::InterfaceHandle<fuchsia::ui::views::ViewRefFocused> view_ref_focused_;
fidl::InterfaceHandle<fuchsia::ui::views::Focuser> focuser_;
fidl::InterfaceRequest<fuchsia::ui::scenic::SessionListener>
session_listener_request_{nullptr};
fidl::InterfaceHandle<fuchsia::ui::views::ViewRefFocused> vrf_{nullptr};
fidl::InterfaceHandle<fuchsia::ui::views::Focuser> focuser_{nullptr};
fidl::InterfaceHandle<fuchsia::ui::pointer::TouchSource> touch_source_{
nullptr};
fidl::InterfaceRequest<fuchsia::ui::input3::KeyboardListener>
keyboard_listener_{nullptr};
fit::closure on_session_listener_error_callback_{nullptr};
OnEnableWireframe wireframe_enabled_callback_{nullptr};
OnCreateGfxView on_create_view_callback_{nullptr};
OnUpdateView on_update_view_callback_{nullptr};
OnDestroyGfxView on_destroy_view_callback_{nullptr};
OnCreateSurface on_create_surface_callback_{nullptr};
OnSemanticsNodeUpdate on_semantics_node_update_callback_{nullptr};
OnRequestAnnounce on_request_announce_callback_{nullptr};
OnShaderWarmup on_shader_warmup_callback_{nullptr};
std::shared_ptr<flutter::ExternalViewEmbedder> view_embedder_{nullptr};
fml::TimeDelta vsync_offset_{fml::TimeDelta::Zero()};
session_listener_request_;
fit::closure on_session_listener_error_callback_;
OnEnableWireframe wireframe_enabled_callback_;
OnCreateGfxView on_create_view_callback_;
OnUpdateView on_update_view_callback_;
OnDestroyGfxView on_destroy_view_callback_;
OnCreateSurface on_create_surface_callback_;
OnSemanticsNodeUpdate on_semantics_node_update_callback_;
OnRequestAnnounce on_request_announce_callback_;
OnShaderWarmup on_shader_warmup_callback_;
bool built_{false};
};
std::string ToString(const fml::Mapping& mapping) {
return std::string(mapping.GetMapping(),
mapping.GetMapping() + mapping.GetSize());
}
// Stolen from pointer_data_packet_converter_unittests.cc.
void UnpackPointerPacket(std::vector<flutter::PointerData>& output, // NOLINT
std::unique_ptr<flutter::PointerDataPacket> packet) {
@@ -376,7 +410,6 @@ class PlatformViewTests : public ::testing::Test {
// This test makes sure that the PlatformView always completes a platform
// message request, even for error conditions or if the request is malformed.
TEST_F(PlatformViewTests, InvalidPlatformMessageRequest) {
sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
MockPlatformViewDelegate delegate;
flutter::TaskRunners task_runners =
flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
@@ -386,8 +419,7 @@ TEST_F(PlatformViewTests, InvalidPlatformMessageRequest) {
auto vrf_handle = vrf_bindings.AddBinding(&vrf);
flutter_runner::GfxPlatformView platform_view =
PlatformViewBuilder(delegate, std::move(task_runners),
services_provider.service_directory())
PlatformViewBuilder(delegate, std::move(task_runners))
.SetViewRefFocused(std::move(vrf_handle))
.Build();
@@ -439,9 +471,8 @@ TEST_F(PlatformViewTests, InvalidPlatformMessageRequest) {
}
// This test makes sure that the PlatformView correctly returns a Surface
// instance that can surface the provided gr_context and view_embedder.
// instance that can surface the provided gr_context and external_view_embedder.
TEST_F(PlatformViewTests, CreateSurfaceTest) {
sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
MockPlatformViewDelegate delegate;
flutter::TaskRunners task_runners =
@@ -457,25 +488,24 @@ TEST_F(PlatformViewTests, CreateSurfaceTest) {
sk_sp<GrDirectContext> gr_context = GrDirectContext::MakeMock(
nullptr,
flutter::MakeDefaultContextOptions(flutter::ContextType::kRender));
std::shared_ptr<MockExternalViewEmbedder> view_embedder =
std::shared_ptr<MockExternalViewEmbedder> external_view_embedder =
std::make_shared<MockExternalViewEmbedder>();
auto CreateSurfaceCallback = [&view_embedder, gr_context]() {
auto CreateSurfaceCallback = [&external_view_embedder, gr_context]() {
return std::make_unique<flutter_runner::Surface>(
"PlatformViewTest", view_embedder, gr_context.get());
"PlatformViewTest", external_view_embedder, gr_context.get());
};
flutter_runner::GfxPlatformView platform_view =
PlatformViewBuilder(delegate, std::move(task_runners),
services_provider.service_directory())
PlatformViewBuilder(delegate, std::move(task_runners))
.SetCreateSurfaceCallback(CreateSurfaceCallback)
.SetViewEmbedder(view_embedder)
.SetExternalViewEmbedder(external_view_embedder)
.Build();
platform_view.NotifyCreated();
RunLoopUntilIdle();
EXPECT_EQ(gr_context.get(), delegate.surface()->GetContext());
EXPECT_EQ(view_embedder.get(),
EXPECT_EQ(external_view_embedder.get(),
platform_view.CreateExternalViewEmbedder().get());
}
@@ -493,12 +523,10 @@ TEST_F(PlatformViewTests, SetViewportMetrics) {
fuchsia::ui::scenic::SessionListenerPtr session_listener;
std::vector<fuchsia::ui::scenic::Event> events;
sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
flutter::TaskRunners task_runners("test_runners", nullptr, nullptr, nullptr,
nullptr);
flutter_runner::GfxPlatformView platform_view =
PlatformViewBuilder(delegate, std::move(task_runners),
services_provider.service_directory())
PlatformViewBuilder(delegate, std::move(task_runners))
.SetSessionListenerRequest(session_listener.NewRequest())
.Build();
RunLoopUntilIdle();
@@ -606,8 +634,6 @@ TEST_F(PlatformViewTests, SetViewportMetrics) {
// settings changes applied to it and calls the SetSemanticsEnabled /
// SetAccessibilityFeatures callbacks with the appropriate parameters.
TEST_F(PlatformViewTests, ChangesAccessibilitySettings) {
sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
MockPlatformViewDelegate delegate;
flutter::TaskRunners task_runners =
flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
@@ -616,12 +642,7 @@ TEST_F(PlatformViewTests, ChangesAccessibilitySettings) {
EXPECT_EQ(delegate.semantics_features(), 0);
flutter_runner::GfxPlatformView platform_view =
PlatformViewBuilder(
delegate, // delegate
std::move(task_runners), // task_runners
services_provider.service_directory() // runner_services
)
.Build();
PlatformViewBuilder(delegate, std::move(task_runners)).Build();
RunLoopUntilIdle();
@@ -641,7 +662,6 @@ TEST_F(PlatformViewTests, ChangesAccessibilitySettings) {
// This test makes sure that the PlatformView forwards messages on the
// "flutter/platform_views" channel for EnableWireframe.
TEST_F(PlatformViewTests, EnableWireframeTest) {
sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
MockPlatformViewDelegate delegate;
flutter::TaskRunners task_runners =
flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
@@ -655,8 +675,7 @@ TEST_F(PlatformViewTests, EnableWireframeTest) {
};
flutter_runner::GfxPlatformView platform_view =
PlatformViewBuilder(delegate, std::move(task_runners),
services_provider.service_directory())
PlatformViewBuilder(delegate, std::move(task_runners))
.SetEnableWireframeCallback(EnableWireframeCallback)
.Build();
@@ -688,7 +707,6 @@ TEST_F(PlatformViewTests, EnableWireframeTest) {
// This test makes sure that the PlatformView forwards messages on the
// "flutter/platform_views" channel for Createview.
TEST_F(PlatformViewTests, CreateViewTest) {
sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
MockPlatformViewDelegate delegate;
flutter::TaskRunners task_runners =
flutter::TaskRunners("test_runners", // label
@@ -714,8 +732,7 @@ TEST_F(PlatformViewTests, CreateViewTest) {
};
flutter_runner::GfxPlatformView platform_view =
PlatformViewBuilder(delegate, std::move(task_runners),
services_provider.service_directory())
PlatformViewBuilder(delegate, std::move(task_runners))
.SetCreateViewCallback(CreateViewCallback)
.Build();
@@ -749,7 +766,6 @@ TEST_F(PlatformViewTests, CreateViewTest) {
// This test makes sure that the PlatformView forwards messages on the
// "flutter/platform_views" channel for UpdateView.
TEST_F(PlatformViewTests, UpdateViewTest) {
sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
MockPlatformViewDelegate delegate;
flutter::TaskRunners task_runners =
flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
@@ -767,8 +783,7 @@ TEST_F(PlatformViewTests, UpdateViewTest) {
};
flutter_runner::GfxPlatformView platform_view =
PlatformViewBuilder(delegate, std::move(task_runners),
services_provider.service_directory())
PlatformViewBuilder(delegate, std::move(task_runners))
.SetUpdateViewCallback(UpdateViewCallback)
.Build();
@@ -867,7 +882,6 @@ TEST_F(PlatformViewTests, UpdateViewTest) {
// This test makes sure that the PlatformView forwards messages on the
// "flutter/platform_views" channel for DestroyView.
TEST_F(PlatformViewTests, DestroyViewTest) {
sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
MockPlatformViewDelegate delegate;
flutter::TaskRunners task_runners =
flutter::TaskRunners("test_runners", // label
@@ -890,8 +904,7 @@ TEST_F(PlatformViewTests, DestroyViewTest) {
};
flutter_runner::GfxPlatformView platform_view =
PlatformViewBuilder(delegate, std::move(task_runners),
services_provider.service_directory())
PlatformViewBuilder(delegate, std::move(task_runners))
.SetDestroyViewCallback(DestroyViewCallback)
.Build();
@@ -930,7 +943,6 @@ TEST_F(PlatformViewTests, ViewEventsTest) {
fuchsia::ui::scenic::SessionListenerPtr session_listener;
std::vector<fuchsia::ui::scenic::Event> events;
sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
flutter::TaskRunners task_runners =
flutter::TaskRunners("test_runners", // label
flutter_runner::CreateFMLTaskRunner(
@@ -952,8 +964,7 @@ TEST_F(PlatformViewTests, ViewEventsTest) {
};
flutter_runner::GfxPlatformView platform_view =
PlatformViewBuilder(delegate, std::move(task_runners),
services_provider.service_directory())
PlatformViewBuilder(delegate, std::move(task_runners))
.SetSessionListenerRequest(session_listener.NewRequest())
.SetCreateViewCallback(on_create_view)
.Build();
@@ -1062,7 +1073,6 @@ TEST_F(PlatformViewTests, ViewEventsTest) {
// "flutter/platform_views" channel for View.focus.getCurrent and
// View.focus.getNext.
TEST_F(PlatformViewTests, GetFocusStatesTest) {
sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
MockPlatformViewDelegate delegate;
flutter::TaskRunners task_runners =
flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
@@ -1072,8 +1082,7 @@ TEST_F(PlatformViewTests, GetFocusStatesTest) {
auto vrf_handle = vrf_bindings.AddBinding(&vrf);
flutter_runner::GfxPlatformView platform_view =
PlatformViewBuilder(delegate, std::move(task_runners),
services_provider.service_directory())
PlatformViewBuilder(delegate, std::move(task_runners))
.SetViewRefFocused(std::move(vrf_handle))
.Build();
@@ -1124,7 +1133,6 @@ TEST_F(PlatformViewTests, GetFocusStatesTest) {
// This test makes sure that the PlatformView forwards messages on the
// "flutter/platform_views" channel for View.focus.request.
TEST_F(PlatformViewTests, RequestFocusTest) {
sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
MockPlatformViewDelegate delegate;
flutter::TaskRunners task_runners =
flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
@@ -1134,8 +1142,7 @@ TEST_F(PlatformViewTests, RequestFocusTest) {
auto focuser_handle = focuser_bindings.AddBinding(&focuser);
flutter_runner::GfxPlatformView platform_view =
PlatformViewBuilder(delegate, std::move(task_runners),
services_provider.service_directory())
PlatformViewBuilder(delegate, std::move(task_runners))
.SetFocuser(std::move(focuser_handle))
.Build();
@@ -1169,7 +1176,6 @@ TEST_F(PlatformViewTests, RequestFocusTest) {
// This test makes sure that the PlatformView correctly replies with an error
// response when a View.focus.request call fails.
TEST_F(PlatformViewTests, RequestFocusFailTest) {
sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
MockPlatformViewDelegate delegate;
flutter::TaskRunners task_runners =
flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
@@ -1180,8 +1186,7 @@ TEST_F(PlatformViewTests, RequestFocusFailTest) {
auto focuser_handle = focuser_bindings.AddBinding(&focuser);
flutter_runner::GfxPlatformView platform_view =
PlatformViewBuilder(delegate, std::move(task_runners),
services_provider.service_directory())
PlatformViewBuilder(delegate, std::move(task_runners))
.SetFocuser(std::move(focuser_handle))
.Build();
@@ -1217,93 +1222,93 @@ TEST_F(PlatformViewTests, RequestFocusFailTest) {
EXPECT_TRUE(focuser.request_focus_called());
}
struct EventFlow {
fuchsia::ui::input3::KeyEvent event;
fuchsia::ui::input3::KeyEventStatus expected_key_event_status;
std::string expected_platform_message;
};
// Makes sure that OnKeyEvent is dispatched as a platform message.
TEST_F(PlatformViewTests, OnKeyEvent) {
sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
struct EventFlow {
fuchsia::ui::input3::KeyEvent event;
fuchsia::ui::input3::KeyEventStatus expected_key_event_status;
std::string expected_platform_message;
};
MockPlatformViewDelegate delegate;
flutter::TaskRunners task_runners =
flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
fidl::InterfacePtr<fuchsia::ui::input3::KeyboardListener> keyboard_listener;
fidl::InterfaceHandle<fuchsia::ui::input3::Keyboard> keyboard_service;
MockKeyboard keyboard(keyboard_service.NewRequest());
flutter_runner::GfxPlatformView platform_view =
PlatformViewBuilder(delegate, std::move(task_runners),
services_provider.service_directory())
.SetKeyboardListener(keyboard_listener.NewRequest(dispatcher()))
PlatformViewBuilder(delegate, std::move(task_runners))
.SetKeyboard(std::move(keyboard_service))
.Build();
using fuchsia::input::Key;
using fuchsia::ui::input3::KeyEvent;
using fuchsia::ui::input3::KeyEventStatus;
using fuchsia::ui::input3::KeyEventType;
using fuchsia::ui::input3::Modifiers;
RunLoopUntilIdle();
std::vector<EventFlow> events;
// Press A. Get 'a'.
events.emplace_back(EventFlow{
MakeEvent(KeyEventType::PRESSED, std::nullopt, Key::A),
KeyEventStatus::HANDLED,
MakeEvent(fuchsia::ui::input3::KeyEventType::PRESSED, std::nullopt,
fuchsia::input::Key::A),
fuchsia::ui::input3::KeyEventStatus::HANDLED,
R"({"type":"keydown","keymap":"fuchsia","hidUsage":4,"codePoint":97,"modifiers":0})",
});
// Release A. Get 'a' release.
events.emplace_back(EventFlow{
MakeEvent(KeyEventType::RELEASED, std::nullopt, Key::A),
KeyEventStatus::HANDLED,
MakeEvent(fuchsia::ui::input3::KeyEventType::RELEASED, std::nullopt,
fuchsia::input::Key::A),
fuchsia::ui::input3::KeyEventStatus::HANDLED,
R"({"type":"keyup","keymap":"fuchsia","hidUsage":4,"codePoint":97,"modifiers":0})",
});
// Press CAPS_LOCK. Modifier now active.
events.emplace_back(EventFlow{
MakeEvent(KeyEventType::PRESSED, Modifiers::CAPS_LOCK, Key::CAPS_LOCK),
KeyEventStatus::HANDLED,
MakeEvent(fuchsia::ui::input3::KeyEventType::PRESSED,
fuchsia::ui::input3::Modifiers::CAPS_LOCK,
fuchsia::input::Key::CAPS_LOCK),
fuchsia::ui::input3::KeyEventStatus::HANDLED,
R"({"type":"keydown","keymap":"fuchsia","hidUsage":57,"codePoint":0,"modifiers":1})",
});
// Pres A. Get 'A'.
events.emplace_back(EventFlow{
MakeEvent(KeyEventType::PRESSED, std::nullopt, Key::A),
KeyEventStatus::HANDLED,
MakeEvent(fuchsia::ui::input3::KeyEventType::PRESSED, std::nullopt,
fuchsia::input::Key::A),
fuchsia::ui::input3::KeyEventStatus::HANDLED,
R"({"type":"keydown","keymap":"fuchsia","hidUsage":4,"codePoint":65,"modifiers":1})",
});
// Release CAPS_LOCK.
events.emplace_back(EventFlow{
MakeEvent(KeyEventType::RELEASED, Modifiers::CAPS_LOCK, Key::CAPS_LOCK),
KeyEventStatus::HANDLED,
MakeEvent(fuchsia::ui::input3::KeyEventType::RELEASED,
fuchsia::ui::input3::Modifiers::CAPS_LOCK,
fuchsia::input::Key::CAPS_LOCK),
fuchsia::ui::input3::KeyEventStatus::HANDLED,
R"({"type":"keyup","keymap":"fuchsia","hidUsage":57,"codePoint":0,"modifiers":1})",
});
// Press A again. This time get 'A'.
// CAPS_LOCK is latched active even if it was just released.
events.emplace_back(EventFlow{
MakeEvent(KeyEventType::PRESSED, std::nullopt, Key::A),
KeyEventStatus::HANDLED,
MakeEvent(fuchsia::ui::input3::KeyEventType::PRESSED, std::nullopt,
fuchsia::input::Key::A),
fuchsia::ui::input3::KeyEventStatus::HANDLED,
R"({"type":"keydown","keymap":"fuchsia","hidUsage":4,"codePoint":65,"modifiers":1})",
});
for (const auto& event : events) {
KeyEvent e;
fuchsia::ui::input3::KeyEvent e;
event.event.Clone(&e);
fuchsia::ui::input3::KeyEventStatus key_event_status;
keyboard_listener->OnKeyEvent(
fuchsia::ui::input3::KeyEventStatus key_event_status{0u};
keyboard.listener_->OnKeyEvent(
std::move(e),
[&key_event_status](fuchsia::ui::input3::KeyEventStatus status) {
key_event_status = status;
});
RunLoopUntilIdle();
const fml::MallocMapping data = delegate.message()->releaseData();
const std::string message = ToString(data);
EXPECT_EQ(event.expected_platform_message, message);
EXPECT_EQ(key_event_status, event.expected_key_event_status);
ASSERT_NOTNULL(delegate.message());
// EXPECT_EQ(event.expected_platform_message,
// ToString(delegate.message()->data()));
EXPECT_EQ(event.expected_key_event_status, key_event_status);
}
}
// Makes sure that OnKeyEvent is dispatched as a platform message.
TEST_F(PlatformViewTests, OnShaderWarmup) {
sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
MockPlatformViewDelegate delegate;
flutter::TaskRunners task_runners =
flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
@@ -1327,8 +1332,7 @@ TEST_F(PlatformViewTests, OnShaderWarmup) {
};
flutter_runner::GfxPlatformView platform_view =
PlatformViewBuilder(delegate, std::move(task_runners),
services_provider.service_directory())
PlatformViewBuilder(delegate, std::move(task_runners))
.SetShaderWarmupCallback(on_shader_warmup)
.Build();
@@ -1355,19 +1359,6 @@ TEST_F(PlatformViewTests, OnShaderWarmup) {
<< "}\n";
std::string warmup_shaders_string = warmup_shaders_ostream.str();
class TestPlatformMessageResponse : public flutter::PlatformMessageResponse {
public:
TestPlatformMessageResponse() {}
void Complete(std::unique_ptr<fml::Mapping> data) override {
result_string = std::string(
reinterpret_cast<const char*>(data->GetMapping()), data->GetSize());
is_complete_ = true;
}
void CompleteEmpty() override { is_complete_ = true; }
std::string result_string;
FML_DISALLOW_COPY_AND_ASSIGN(TestPlatformMessageResponse);
};
fml::RefPtr<TestPlatformMessageResponse> response(
new TestPlatformMessageResponse);
static_cast<flutter::PlatformView*>(&platform_view)
@@ -1398,21 +1389,16 @@ TEST_F(PlatformViewTests, TouchSource_LogicalToPhysicalConversion) {
.device_id = 0u, .pointer_id = 1u, .interaction_id = 2u};
constexpr float valid_pixel_ratio = 2.f;
// Setup
sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
MockPlatformViewDelegate delegate;
flutter::TaskRunners task_runners("test_runners", nullptr, nullptr, nullptr,
nullptr);
fuchsia::ui::scenic::SessionListenerPtr session_listener;
FakeTouchSource touch_server;
fidl::BindingSet<fuchsia::ui::pointer::TouchSource> touch_bindings;
auto touch_handle = touch_bindings.AddBinding(&touch_server);
fuchsia::ui::scenic::SessionListenerPtr session_listener;
flutter_runner::GfxPlatformView platform_view =
PlatformViewBuilder(delegate, std::move(task_runners),
services_provider.service_directory())
PlatformViewBuilder(delegate, std::move(task_runners))
.SetSessionListenerRequest(session_listener.NewRequest())
.SetTouchSource(std::move(touch_handle))
.Build();
@@ -1492,56 +1478,46 @@ TEST_F(PlatformViewTests, TouchSource_LogicalToPhysicalConversion) {
}
TEST_F(PlatformViewTests, DownPointerNumericNudge) {
using ScenicEvent = fuchsia::ui::scenic::Event;
using GfxEvent = fuchsia::ui::gfx::Event;
using GfxViewPropertiesChangedEvent =
fuchsia::ui::gfx::ViewPropertiesChangedEvent;
using GfxViewProperties = fuchsia::ui::gfx::ViewProperties;
using GfxBoundingBox = fuchsia::ui::gfx::BoundingBox;
using GfxVec3 = fuchsia::ui::gfx::vec3;
using fuchsia::ui::input::InputEvent;
using fuchsia::ui::input::PointerEvent;
const float kSmallDiscrepancy = -0.00003f;
constexpr float kSmallDiscrepancy = -0.00003f;
fuchsia::ui::scenic::SessionListenerPtr session_listener;
sys::testing::ServiceDirectoryProvider services_provider(dispatcher());
MockPlatformViewDelegate delegate;
flutter::TaskRunners task_runners("test_runners", nullptr, nullptr, nullptr,
nullptr);
flutter_runner::GfxPlatformView platform_view =
PlatformViewBuilder(delegate, std::move(task_runners),
services_provider.service_directory())
PlatformViewBuilder(delegate, std::move(task_runners))
.SetSessionListenerRequest(session_listener.NewRequest())
.Build();
RunLoopUntilIdle();
EXPECT_EQ(delegate.pointer_packets().size(), 0u);
std::vector<fuchsia::ui::scenic::Event> events;
events.emplace_back(ScenicEvent::WithGfx(
GfxEvent::WithViewPropertiesChanged(GfxViewPropertiesChangedEvent{
.view_id = 0,
.properties =
GfxViewProperties{
.bounding_box =
GfxBoundingBox{
.min =
GfxVec3{
.x = 0.f,
.y = 0.f,
.z = 0.f,
},
.max =
GfxVec3{
.x = 100.f,
.y = 100.f,
.z = 100.f,
events.emplace_back(
fuchsia::ui::scenic::Event::WithGfx(
fuchsia::ui::gfx::Event::WithViewPropertiesChanged(
fuchsia::ui::gfx::ViewPropertiesChangedEvent{
.view_id = 0,
.properties =
fuchsia::ui::gfx::ViewProperties{
.bounding_box =
fuchsia::ui::gfx::BoundingBox{
.min =
fuchsia::ui::gfx::vec3{
.x = 0.f,
.y = 0.f,
.z = 0.f,
},
.max =
fuchsia::ui::gfx::vec3{
.x = 100.f,
.y = 100.f,
.z = 100.f,
},
},
},
},
})));
events.emplace_back(
ScenicEvent::WithGfx(GfxEvent::WithMetrics(fuchsia::ui::gfx::MetricsEvent{
})));
events.emplace_back(fuchsia::ui::scenic::Event::WithGfx(
fuchsia::ui::gfx::Event::WithMetrics(fuchsia::ui::gfx::MetricsEvent{
.node_id = 0,
.metrics =
fuchsia::ui::gfx::Metrics{
@@ -1550,45 +1526,48 @@ TEST_F(PlatformViewTests, DownPointerNumericNudge) {
.scale_z = 1.f,
},
})));
events.emplace_back(
ScenicEvent::WithInput(InputEvent::WithPointer(PointerEvent{
.event_time = 1111,
.device_id = 2222,
.pointer_id = 3333,
.type = fuchsia::ui::input::PointerEventType::TOUCH,
.phase = fuchsia::ui::input::PointerEventPhase::ADD,
.x = 50.f,
.y = kSmallDiscrepancy, // floating point inaccuracy
.radius_major = 0.f,
.radius_minor = 0.f,
.buttons = 0u,
})));
events.emplace_back(
ScenicEvent::WithInput(InputEvent::WithPointer(PointerEvent{
.event_time = 1111,
.device_id = 2222,
.pointer_id = 3333,
.type = fuchsia::ui::input::PointerEventType::TOUCH,
.phase = fuchsia::ui::input::PointerEventPhase::DOWN,
.x = 50.f,
.y = kSmallDiscrepancy, // floating point inaccuracy
.radius_major = 0.f,
.radius_minor = 0.f,
.buttons = 0u,
})));
events.emplace_back(
ScenicEvent::WithInput(InputEvent::WithPointer(PointerEvent{
.event_time = 1111,
.device_id = 2222,
.pointer_id = 3333,
.type = fuchsia::ui::input::PointerEventType::TOUCH,
.phase = fuchsia::ui::input::PointerEventPhase::MOVE,
.x = 50.f,
.y = kSmallDiscrepancy, // floating point inaccuracy
.radius_major = 0.f,
.radius_minor = 0.f,
.buttons = 0u,
})));
events.emplace_back(fuchsia::ui::scenic::Event::WithInput(
fuchsia::ui::input::InputEvent::WithPointer(
fuchsia::ui::input::PointerEvent{
.event_time = 1111,
.device_id = 2222,
.pointer_id = 3333,
.type = fuchsia::ui::input::PointerEventType::TOUCH,
.phase = fuchsia::ui::input::PointerEventPhase::ADD,
.x = 50.f,
.y = kSmallDiscrepancy, // floating point inaccuracy
.radius_major = 0.f,
.radius_minor = 0.f,
.buttons = 0u,
})));
events.emplace_back(fuchsia::ui::scenic::Event::WithInput(
fuchsia::ui::input::InputEvent::WithPointer(
fuchsia::ui::input::PointerEvent{
.event_time = 1111,
.device_id = 2222,
.pointer_id = 3333,
.type = fuchsia::ui::input::PointerEventType::TOUCH,
.phase = fuchsia::ui::input::PointerEventPhase::DOWN,
.x = 50.f,
.y = kSmallDiscrepancy, // floating point inaccuracy
.radius_major = 0.f,
.radius_minor = 0.f,
.buttons = 0u,
})));
events.emplace_back(fuchsia::ui::scenic::Event::WithInput(
fuchsia::ui::input::InputEvent::WithPointer(
fuchsia::ui::input::PointerEvent{
.event_time = 1111,
.device_id = 2222,
.pointer_id = 3333,
.type = fuchsia::ui::input::PointerEventType::TOUCH,
.phase = fuchsia::ui::input::PointerEventPhase::MOVE,
.x = 50.f,
.y = kSmallDiscrepancy, // floating point inaccuracy
.radius_major = 0.f,
.radius_minor = 0.f,
.buttons = 0u,
})));
session_listener->OnScenicEvent(std::move(events));
RunLoopUntilIdle();
ASSERT_EQ(delegate.pointer_packets().size(), 3u);