From e493b1011e084071eefda35fd2b91e6d083fe8fe Mon Sep 17 00:00:00 2001 From: Caroline Liu <10456171+caroqliu@users.noreply.github.com> Date: Tue, 8 Aug 2023 14:20:09 -0400 Subject: [PATCH] Remove GFX branches from Flutter engine (flutter/engine#44401) This change does the following: - Refactors `engine.cc`/`.h` and `component_v2.cc`/`.h` to remove GFX ctors and callbacks. - Removes `gfx_external_view_embedder`, `gfx_platform_view`, `gfx_session_connection`, their tests, and any supporting testing infrastructure (e.g. `fake_session`) from the build. This change does not delete the source files themselves in order to keep the change size smaller (as all these file deletions together are about another ~8K lines worth of deletions.) A separate follow up change will delete these files. Related bug: fxbug.dev/64206 --- .../ci/licenses_golden/licenses_flutter | 12 +- .../shell/platform/fuchsia/flutter/BUILD.gn | 21 +- .../platform/fuchsia/flutter/component_v2.cc | 30 -- .../platform/fuchsia/flutter/component_v2.h | 5 - .../shell/platform/fuchsia/flutter/engine.cc | 360 +++++------------- .../shell/platform/fuchsia/flutter/engine.h | 49 +-- ..._embedder.cc => external_view_embedder.cc} | 128 +++---- ...ew_embedder.h => external_view_embedder.h} | 38 +- .../fuchsia/flutter/flatland_connection.cc | 2 +- .../fuchsia/flutter/flatland_platform_view.cc | 303 --------------- .../fuchsia/flutter/flatland_platform_view.h | 106 ------ .../fuchsia/flutter/meta/common.shard.cml | 1 - .../platform/fuchsia/flutter/platform_view.cc | 335 +++++++++++++--- .../platform/fuchsia/flutter/platform_view.h | 107 ++++-- .../fuchsia/flutter/platform_view_unittest.cc | 24 +- .../flutter/pointer_injector_delegate.cc | 36 +- .../flutter/pointer_injector_delegate.h | 17 +- .../pointer_injector_delegate_unittest.cc | 158 +------- .../fuchsia/flutter/software_surface.cc | 96 ++--- .../fuchsia/flutter/software_surface.h | 10 +- .../flutter/software_surface_producer.cc | 18 +- .../flutter/software_surface_producer.h | 5 +- ...cc => external_view_embedder_unittests.cc} | 65 ++-- .../flutter/tests/fakes/scenic/BUILD.gn | 6 - ..._unittest.cc => platform_view_unittest.cc} | 191 +++++----- .../fuchsia/flutter/vulkan_surface.cc | 86 ++--- .../platform/fuchsia/flutter/vulkan_surface.h | 12 +- .../fuchsia/flutter/vulkan_surface_pool.cc | 20 +- .../fuchsia/flutter/vulkan_surface_pool.h | 5 +- .../flutter/vulkan_surface_producer.cc | 9 +- .../fuchsia/flutter/vulkan_surface_producer.h | 6 +- 31 files changed, 779 insertions(+), 1482 deletions(-) rename engine/src/flutter/shell/platform/fuchsia/flutter/{flatland_external_view_embedder.cc => external_view_embedder.cc} (86%) rename engine/src/flutter/shell/platform/fuchsia/flutter/{flatland_external_view_embedder.h => external_view_embedder.h} (86%) delete mode 100644 engine/src/flutter/shell/platform/fuchsia/flutter/flatland_platform_view.cc delete mode 100644 engine/src/flutter/shell/platform/fuchsia/flutter/flatland_platform_view.h rename engine/src/flutter/shell/platform/fuchsia/flutter/tests/{flatland_external_view_embedder_unittests.cc => external_view_embedder_unittests.cc} (96%) rename engine/src/flutter/shell/platform/fuchsia/flutter/tests/{flatland_platform_view_unittest.cc => platform_view_unittest.cc} (92%) diff --git a/engine/src/flutter/ci/licenses_golden/licenses_flutter b/engine/src/flutter/ci/licenses_golden/licenses_flutter index fa648debe3..4bd05d1799 100644 --- a/engine/src/flutter/ci/licenses_golden/licenses_flutter +++ b/engine/src/flutter/ci/licenses_golden/licenses_flutter @@ -2935,14 +2935,12 @@ ORIGIN: ../../../flutter/shell/platform/fuchsia/flutter/component_v2.cc + ../../ ORIGIN: ../../../flutter/shell/platform/fuchsia/flutter/component_v2.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/fuchsia/flutter/engine.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/fuchsia/flutter/engine.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/fuchsia/flutter/external_view_embedder.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/fuchsia/flutter/external_view_embedder.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/fuchsia/flutter/file_in_namespace_buffer.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/fuchsia/flutter/file_in_namespace_buffer.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/fuchsia/flutter/flatland_connection.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/fuchsia/flutter/flatland_connection.h + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/shell/platform/fuchsia/flutter/flatland_external_view_embedder.cc + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/shell/platform/fuchsia/flutter/flatland_external_view_embedder.h + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/shell/platform/fuchsia/flutter/flatland_platform_view.cc + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/shell/platform/fuchsia/flutter/flatland_platform_view.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/fuchsia/flutter/flutter_runner_fakes.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.h + ../../../flutter/LICENSE @@ -5676,14 +5674,12 @@ FILE: ../../../flutter/shell/platform/fuchsia/flutter/component_v2.cc FILE: ../../../flutter/shell/platform/fuchsia/flutter/component_v2.h FILE: ../../../flutter/shell/platform/fuchsia/flutter/engine.cc FILE: ../../../flutter/shell/platform/fuchsia/flutter/engine.h +FILE: ../../../flutter/shell/platform/fuchsia/flutter/external_view_embedder.cc +FILE: ../../../flutter/shell/platform/fuchsia/flutter/external_view_embedder.h FILE: ../../../flutter/shell/platform/fuchsia/flutter/file_in_namespace_buffer.cc FILE: ../../../flutter/shell/platform/fuchsia/flutter/file_in_namespace_buffer.h FILE: ../../../flutter/shell/platform/fuchsia/flutter/flatland_connection.cc FILE: ../../../flutter/shell/platform/fuchsia/flutter/flatland_connection.h -FILE: ../../../flutter/shell/platform/fuchsia/flutter/flatland_external_view_embedder.cc -FILE: ../../../flutter/shell/platform/fuchsia/flutter/flatland_external_view_embedder.h -FILE: ../../../flutter/shell/platform/fuchsia/flutter/flatland_platform_view.cc -FILE: ../../../flutter/shell/platform/fuchsia/flutter/flatland_platform_view.h FILE: ../../../flutter/shell/platform/fuchsia/flutter/flutter_runner_fakes.h FILE: ../../../flutter/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.cc FILE: ../../../flutter/shell/platform/fuchsia/flutter/flutter_runner_product_configuration.h diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/BUILD.gn b/engine/src/flutter/shell/platform/fuchsia/flutter/BUILD.gn index 2b529a85e4..5018005b5a 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/BUILD.gn +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/BUILD.gn @@ -64,26 +64,18 @@ template("runner_sources") { "component_v2.h", "engine.cc", "engine.h", + "external_view_embedder.cc", + "external_view_embedder.h", "file_in_namespace_buffer.cc", "file_in_namespace_buffer.h", "flatland_connection.cc", "flatland_connection.h", - "flatland_external_view_embedder.cc", - "flatland_external_view_embedder.h", - "flatland_platform_view.cc", - "flatland_platform_view.h", "flutter_runner_product_configuration.cc", "flutter_runner_product_configuration.h", "focus_delegate.cc", "focus_delegate.h", "fuchsia_intl.cc", "fuchsia_intl.h", - "gfx_external_view_embedder.cc", - "gfx_external_view_embedder.h", - "gfx_platform_view.cc", - "gfx_platform_view.h", - "gfx_session_connection.cc", - "gfx_session_connection.h", "isolate_configurator.cc", "isolate_configurator.h", "keyboard.cc", @@ -168,7 +160,6 @@ template("runner_sources") { "$fuchsia_sdk_root/fidl:fuchsia.ui.composition", "$fuchsia_sdk_root/fidl:fuchsia.ui.pointer", "$fuchsia_sdk_root/fidl:fuchsia.ui.pointerinjector", - "$fuchsia_sdk_root/fidl:fuchsia.ui.scenic", "$fuchsia_sdk_root/fidl:fuchsia.ui.test.input", "$fuchsia_sdk_root/fidl:fuchsia.ui.views", "$fuchsia_sdk_root/pkg:async-cpp", @@ -509,19 +500,15 @@ if (enable_unittests) { "focus_delegate_unittests.cc", "fuchsia_intl_unittest.cc", "keyboard_unittest.cc", - "platform_view_unittest.cc", "pointer_delegate_unittests.cc", "pointer_injector_delegate_unittest.cc", "rtree_unittests.cc", "tests/engine_unittests.cc", + "tests/external_view_embedder_unittests.cc", "tests/fake_flatland_unittests.cc", - "tests/fake_session_unittests.cc", "tests/flatland_connection_unittests.cc", - "tests/flatland_external_view_embedder_unittests.cc", - "tests/flatland_platform_view_unittest.cc", "tests/flutter_runner_product_configuration_unittests.cc", - "tests/gfx_external_view_embedder_unittests.cc", - "tests/gfx_session_connection_unittests.cc", + "tests/platform_view_unittest.cc", "tests/pointer_event_utility.cc", "tests/pointer_event_utility.h", "text_delegate_unittests.cc", diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/component_v2.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/component_v2.cc index 9a5a882efe..3208146044 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/component_v2.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/component_v2.cc @@ -627,36 +627,6 @@ void ComponentV2::OnEngineTerminate(const Engine* shell_holder) { } } -void ComponentV2::CreateViewWithViewRef( - zx::eventpair view_token, - fuchsia::ui::views::ViewRefControl control_ref, - fuchsia::ui::views::ViewRef view_ref) { - if (!svc_) { - FML_LOG(ERROR) - << "Component incoming services was invalid when attempting to " - "create a shell for a view provider request."; - return; - } - - shell_holders_.emplace(std::make_unique( - *this, // delegate - debug_label_, // thread label - svc_, // Component incoming services - runner_incoming_services_, // Runner incoming services - settings_, // settings - scenic::ToViewToken(std::move(view_token)), // view token - scenic::ViewRefPair{ - .control_ref = std::move(control_ref), - .view_ref = std::move(view_ref), - }, - std::move(fdio_ns_), // FDIO namespace - std::move(directory_request_), // outgoing request - product_config_, // product configuration - std::vector(), // dart entrypoint args - false // not a v1 component - )); -} - void ComponentV2::CreateView2(fuchsia::ui::app::CreateView2Args view_args) { if (!svc_) { FML_LOG(ERROR) diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/component_v2.h b/engine/src/flutter/shell/platform/fuchsia/flutter/component_v2.h index 57a0aa62cd..f750319e98 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/component_v2.h +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/component_v2.h @@ -110,11 +110,6 @@ class ComponentV2 final // |fuchsia::component::runner::ComponentController| void Stop() override; - // |fuchsia::ui::app::ViewProvider| - void CreateViewWithViewRef(zx::eventpair view_token, - fuchsia::ui::views::ViewRefControl control_ref, - fuchsia::ui::views::ViewRef view_ref) override; - // |fuchsia::ui::app::ViewProvider| void CreateView2(fuchsia::ui::app::CreateView2Args view_args) override; diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/engine.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/engine.cc index 40eba58810..2bc9583329 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/engine.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/engine.cc @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -31,10 +30,9 @@ #include "../runtime/dart/utils/files.h" #include "../runtime/dart/utils/root_inspect_node.h" -#include "flatland_platform_view.h" #include "focus_delegate.h" #include "fuchsia_intl.h" -#include "gfx_platform_view.h" +#include "platform_view.h" #include "software_surface_producer.h" #include "surface.h" #include "vsync_waiter.h" @@ -199,32 +197,6 @@ flutter::ThreadHost Engine::CreateThreadHost( return flutter::ThreadHost(thread_host_config); } -Engine::Engine(Delegate& delegate, - std::string thread_label, - std::shared_ptr svc, - std::shared_ptr runner_services, - flutter::Settings settings, - fuchsia::ui::views::ViewToken view_token, - scenic::ViewRefPair view_ref_pair, - UniqueFDIONS fdio_ns, - fidl::InterfaceRequest directory_request, - FlutterRunnerProductConfiguration product_config, - const std::vector& dart_entrypoint_args, - bool for_v1_component) - : delegate_(delegate), - thread_label_(std::move(thread_label)), - thread_host_(CreateThreadHost(thread_label_, runner_services)), - view_token_(std::move(view_token)), - 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(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), dart_entrypoint_args, for_v1_component); -} - Engine::Engine(Delegate& delegate, std::string thread_label, std::shared_ptr svc, @@ -245,14 +217,13 @@ Engine::Engine(Delegate& delegate, 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(view_ref_pair), std::move(svc), + Initialize(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), dart_entrypoint_args, for_v1_component); } void Engine::Initialize( - bool use_flatland, scenic::ViewRefPair view_ref_pair, std::shared_ptr svc, std::shared_ptr runner_services, @@ -262,9 +233,8 @@ void Engine::Initialize( FlutterRunnerProductConfiguration product_config, const std::vector& dart_entrypoint_args, bool for_v1_component) { - // Flatland uses |view_creation_token_| for linking. Gfx uses |view_token_|. - FML_CHECK((use_flatland && view_creation_token_.value.is_valid()) || - (!use_flatland && view_token_.value.is_valid())); + // Flatland uses |view_creation_token_| for linking. + FML_CHECK(view_creation_token_.value.is_valid()); // Get the task runners from the managed threads. The current thread will be // used as the "platform" thread. @@ -279,39 +249,23 @@ void Engine::Initialize( thread_host_.io_thread->GetTaskRunner() // io ); - // Connect to Scenic. - auto scenic = runner_services->Connect(); - fuchsia::ui::scenic::SessionEndpoints gfx_protocols; - fuchsia::ui::scenic::SessionHandle session; - gfx_protocols.set_session(session.NewRequest()); - fuchsia::ui::scenic::SessionListenerHandle session_listener; - auto session_listener_request = session_listener.NewRequest(); - gfx_protocols.set_session_listener(session_listener.Bind()); fuchsia::ui::views::FocuserHandle focuser; fuchsia::ui::views::ViewRefFocusedHandle view_ref_focused; fuchsia::ui::pointer::TouchSourceHandle touch_source; fuchsia::ui::pointer::MouseSourceHandle mouse_source; - fuchsia::ui::composition::ViewBoundProtocols flatland_view_protocols; - if (use_flatland) { - flatland_view_protocols.set_view_focuser(focuser.NewRequest()); - flatland_view_protocols.set_view_ref_focused(view_ref_focused.NewRequest()); - flatland_view_protocols.set_touch_source(touch_source.NewRequest()); - flatland_view_protocols.set_mouse_source(mouse_source.NewRequest()); - } else { - gfx_protocols.set_view_focuser(focuser.NewRequest()); - gfx_protocols.set_view_ref_focused(view_ref_focused.NewRequest()); - gfx_protocols.set_touch_source(touch_source.NewRequest()); - // GFX used only on products without a mouse. - } - scenic->CreateSessionT(std::move(gfx_protocols), [] {}); + fuchsia::ui::composition::ViewBoundProtocols view_protocols; + view_protocols.set_view_focuser(focuser.NewRequest()); + view_protocols.set_view_ref_focused(view_ref_focused.NewRequest()); + view_protocols.set_touch_source(touch_source.NewRequest()); + view_protocols.set_mouse_source(mouse_source.NewRequest()); // Connect to Flatland. fuchsia::ui::composition::FlatlandHandle flatland; zx_status_t flatland_status = runner_services->Connect( flatland.NewRequest()); - if (flatland_status != ZX_OK && use_flatland) { + if (flatland_status != ZX_OK) { FML_LOG(WARNING) << "fuchsia::ui::composition::Flatland connection failed: " << zx_status_get_string(flatland_status); } @@ -393,57 +347,34 @@ void Engine::Initialize( task_runners.GetRasterTaskRunner()->PostTask(fml::MakeCopyable( [this, &view_embedder_latch, session_inspect_node = std::move(session_inspect_node), - session = std::move(session), flatland = std::move(flatland), - session_error_callback = std::move(session_error_callback), use_flatland, - view_token = std::move(view_token_), + flatland = std::move(flatland), + session_error_callback = std::move(session_error_callback), view_creation_token = std::move(view_creation_token_), - flatland_view_protocols = std::move(flatland_view_protocols), + view_protocols = std::move(view_protocols), request = parent_viewport_watcher.NewRequest(), 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(), software_rendering = product_config.software_rendering()]() mutable { - if (use_flatland) { - if (software_rendering) { - surface_producer_ = std::make_shared( - /*scenic_session=*/nullptr); - } else { - surface_producer_ = std::make_shared( - /*scenic_session=*/nullptr); - } - - flatland_connection_ = std::make_shared( - thread_label_, std::move(flatland), - std::move(session_error_callback), [](auto) {}, - max_frames_in_flight, vsync_offset); - - fuchsia::ui::views::ViewIdentityOnCreation view_identity = { - .view_ref = std::move(view_ref_pair.view_ref), - .view_ref_control = std::move(view_ref_pair.control_ref)}; - flatland_view_embedder_ = - std::make_shared( - std::move(view_creation_token), std::move(view_identity), - std::move(flatland_view_protocols), std::move(request), - flatland_connection_, surface_producer_, - intercept_all_input_); + if (software_rendering) { + surface_producer_ = std::make_shared(); } else { - session_connection_ = std::make_shared( - thread_label_, std::move(session_inspect_node), - std::move(session), std::move(session_error_callback), - [](auto) {}, max_frames_in_flight, vsync_offset); - - if (software_rendering) { - surface_producer_ = std::make_shared( - session_connection_->get()); - } else { - surface_producer_ = std::make_shared( - session_connection_->get()); - } - - external_view_embedder_ = std::make_shared( - thread_label_, std::move(view_token), std::move(view_ref_pair), - session_connection_, surface_producer_, intercept_all_input_); + surface_producer_ = std::make_shared(); } + + flatland_connection_ = std::make_shared( + thread_label_, std::move(flatland), + std::move(session_error_callback), [](auto) {}, + max_frames_in_flight, vsync_offset); + + fuchsia::ui::views::ViewIdentityOnCreation view_identity = { + .view_ref = std::move(view_ref_pair.view_ref), + .view_ref_control = std::move(view_ref_pair.control_ref)}; + view_embedder_ = std::make_shared( + std::move(view_creation_token), std::move(view_identity), + std::move(view_protocols), std::move(request), flatland_connection_, + surface_producer_, intercept_all_input_); + view_embedder_latch.Signal(); })); view_embedder_latch.Wait(); @@ -476,32 +407,21 @@ void Engine::Initialize( dart_utils::RootInspectNode::CreateRootChild( std::move(accessibility_inspect_name))); - OnEnableWireframe on_enable_wireframe_callback = std::bind( + OnEnableWireframeCallback on_enable_wireframe_callback = std::bind( &Engine::DebugWireframeSettingsChanged, this, std::placeholders::_1); - OnCreateGfxView on_create_gfx_view_callback = - std::bind(&Engine::CreateGfxView, this, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3, - std::placeholders::_4, std::placeholders::_5); + OnCreateViewCallback on_create_view_callback = std::bind( + &Engine::CreateView, this, std::placeholders::_1, std::placeholders::_2, + std::placeholders::_3, std::placeholders::_4, std::placeholders::_5); - OnCreateFlatlandView on_create_flatland_view_callback = - std::bind(&Engine::CreateFlatlandView, this, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3, - std::placeholders::_4, std::placeholders::_5); - - OnUpdateView on_update_view_callback = std::bind( + OnUpdateViewCallback on_update_view_callback = std::bind( &Engine::UpdateView, this, std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3, std::placeholders::_4, use_flatland); + std::placeholders::_3, std::placeholders::_4); - OnDestroyGfxView on_destroy_gfx_view_callback = - std::bind(&Engine::DestroyGfxView, this, std::placeholders::_1, - std::placeholders::_2); + OnDestroyViewCallback on_destroy_view_callback = std::bind( + &Engine::DestroyView, this, std::placeholders::_1, std::placeholders::_2); - OnDestroyFlatlandView on_destroy_flatland_view_callback = - std::bind(&Engine::DestroyFlatlandView, this, std::placeholders::_1, - std::placeholders::_2); - - OnCreateSurface on_create_surface_callback = + OnCreateSurfaceCallback on_create_surface_callback = std::bind(&Engine::CreateSurface, this); // SessionListener has a OnScenicError method; invoke this callback on the @@ -526,12 +446,12 @@ void Engine::Initialize( settings, task_runners.GetIOTaskRunner()); run_configuration.SetEntrypointArgs(std::move(dart_entrypoint_args)); - OnSemanticsNodeUpdate on_semantics_node_update_callback = + OnSemanticsNodeUpdateCallback on_semantics_node_update_callback = [this](flutter::SemanticsNodeUpdates updates, float pixel_ratio) { accessibility_bridge_->AddSemanticsNodeUpdate(updates, pixel_ratio); }; - OnRequestAnnounce on_request_announce_callback = + OnRequestAnnounceCallback on_request_announce_callback = [this](const std::string& message) { accessibility_bridge_->RequestAnnounce(message); }; @@ -539,8 +459,7 @@ void Engine::Initialize( // Setup the callback that will instantiate the platform view. flutter::Shell::CreateCallback on_create_platform_view = fml::MakeCopyable( - [this, use_flatland, view_ref = std::move(platform_view_ref), - session_listener_request = std::move(session_listener_request), + [this, view_ref = std::move(platform_view_ref), parent_viewport_watcher = std::move(parent_viewport_watcher), ime_service = std::move(ime_service), keyboard = std::move(keyboard), focuser = std::move(focuser), @@ -552,14 +471,9 @@ void Engine::Initialize( std::move(on_session_listener_error_callback), on_enable_wireframe_callback = std::move(on_enable_wireframe_callback), - on_create_gfx_view_callback = std::move(on_create_gfx_view_callback), - on_create_flatland_view_callback = - std::move(on_create_flatland_view_callback), + on_create_view_callback = std::move(on_create_view_callback), on_update_view_callback = std::move(on_update_view_callback), - on_destroy_gfx_view_callback = - std::move(on_destroy_gfx_view_callback), - on_destroy_flatland_view_callback = - std::move(on_destroy_flatland_view_callback), + on_destroy_view_callback = std::move(on_destroy_view_callback), on_create_surface_callback = std::move(on_create_surface_callback), on_semantics_node_update_callback = std::move(on_semantics_node_update_callback), @@ -567,27 +481,19 @@ void Engine::Initialize( std::move(on_request_announce_callback), external_view_embedder = GetExternalViewEmbedder(), await_vsync_callback = - [this, use_flatland](FireCallbackCallback cb) { - if (use_flatland) { - flatland_connection_->AwaitVsync(cb); - } else { - session_connection_->AwaitVsync(cb); - } + [this](FireCallbackCallback cb) { + flatland_connection_->AwaitVsync(cb); }, await_vsync_for_secondary_callback_callback = - [this, use_flatland](FireCallbackCallback cb) { - if (use_flatland) { - flatland_connection_->AwaitVsyncForSecondaryCallback(cb); - } else { - session_connection_->AwaitVsyncForSecondaryCallback(cb); - } + [this](FireCallbackCallback cb) { + flatland_connection_->AwaitVsyncForSecondaryCallback(cb); }, product_config, svc](flutter::Shell& shell) mutable { - OnShaderWarmup on_shader_warmup = nullptr; + OnShaderWarmupCallback on_shader_warmup_callback = nullptr; if (product_config.enable_shader_warmup()) { FML_DCHECK(surface_producer_); if (product_config.enable_shader_warmup_dart_hooks()) { - on_shader_warmup = + on_shader_warmup_callback = [this, &shell]( const std::vector& skp_names, std::function completion_callback, @@ -616,50 +522,24 @@ void Engine::Initialize( } } - std::unique_ptr platform_view; - if (use_flatland) { - platform_view = - std::make_unique( - 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(mouse_source), std::move(focuser), - std::move(view_ref_focused), - std::move(parent_viewport_watcher), - std::move(pointerinjector_registry), - std::move(on_enable_wireframe_callback), - std::move(on_create_flatland_view_callback), - std::move(on_update_view_callback), - std::move(on_destroy_flatland_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(await_vsync_callback), - std::move(await_vsync_for_secondary_callback_callback), - std::move(svc)); - } else { - platform_view = std::make_unique( - 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(mouse_source), std::move(focuser), - std::move(view_ref_focused), - std::move(pointerinjector_registry), - 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), - std::move(on_update_view_callback), - std::move(on_destroy_gfx_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(await_vsync_callback), - std::move(await_vsync_for_secondary_callback_callback), - std::move(svc)); - } - return platform_view; + return std::make_unique( + 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(mouse_source), std::move(focuser), + std::move(view_ref_focused), std::move(parent_viewport_watcher), + std::move(pointerinjector_registry), + std::move(on_enable_wireframe_callback), + std::move(on_create_view_callback), + std::move(on_update_view_callback), + std::move(on_destroy_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_callback), + std::move(await_vsync_callback), + std::move(await_vsync_for_secondary_callback_callback), + std::move(svc)); }); // Setup the callback that will instantiate the rasterizer. @@ -828,15 +708,9 @@ Engine::~Engine() { fml::AutoResetWaitableEvent view_embedder_latch; thread_host_.raster_thread->GetTaskRunner()->PostTask( fml::MakeCopyable([this, &view_embedder_latch]() mutable { - if (flatland_view_embedder_ != nullptr) { - flatland_view_embedder_.reset(); - flatland_connection_.reset(); - surface_producer_.reset(); - } else { - external_view_embedder_.reset(); - surface_producer_.reset(); - session_connection_.reset(); - } + view_embedder_.reset(); + flatland_connection_.reset(); + surface_producer_.reset(); view_embedder_latch.Signal(); })); view_embedder_latch.Wait(); @@ -881,92 +755,50 @@ void Engine::Terminate() { void Engine::DebugWireframeSettingsChanged(bool enabled) { FML_CHECK(shell_); - // TODO(fxbug.dev/116000): Investigate if we can add flatland wireframe code - // for debugging. - shell_->GetTaskRunners().GetRasterTaskRunner()->PostTask([this, enabled]() { - if (external_view_embedder_) { - external_view_embedder_->EnableWireframe(enabled); - } + shell_->GetTaskRunners().GetRasterTaskRunner()->PostTask([]() { + // TODO(fxbug.dev/116000): Investigate if we can add flatland wireframe code + // for debugging. }); } -void Engine::CreateGfxView(int64_t view_id, - ViewCallback on_view_created, - GfxViewIdCallback on_view_bound, - bool hit_testable, - bool focusable) { +void Engine::CreateView(int64_t view_id, + ViewCallback on_view_created, + ViewCreatedCallback on_view_bound, + bool hit_testable, + bool focusable) { FML_CHECK(shell_); shell_->GetTaskRunners().GetRasterTaskRunner()->PostTask( [this, view_id, hit_testable, focusable, on_view_created = std::move(on_view_created), on_view_bound = std::move(on_view_bound)]() { - FML_CHECK(external_view_embedder_); - external_view_embedder_->CreateView(view_id, std::move(on_view_created), - std::move(on_view_bound)); - external_view_embedder_->SetViewProperties(view_id, SkRect::MakeEmpty(), - hit_testable, focusable); - }); -} - -void Engine::CreateFlatlandView(int64_t view_id, - ViewCallback on_view_created, - FlatlandViewCreatedCallback on_view_bound, - bool hit_testable, - bool focusable) { - FML_CHECK(shell_); - shell_->GetTaskRunners().GetRasterTaskRunner()->PostTask( - [this, view_id, hit_testable, focusable, - on_view_created = std::move(on_view_created), - on_view_bound = std::move(on_view_bound)]() { - FML_CHECK(flatland_view_embedder_); - flatland_view_embedder_->CreateView(view_id, std::move(on_view_created), - std::move(on_view_bound)); - flatland_view_embedder_->SetViewProperties(view_id, SkRect::MakeEmpty(), - hit_testable, focusable); + FML_CHECK(view_embedder_); + view_embedder_->CreateView(view_id, std::move(on_view_created), + std::move(on_view_bound)); + view_embedder_->SetViewProperties(view_id, SkRect::MakeEmpty(), + hit_testable, focusable); }); } void Engine::UpdateView(int64_t view_id, SkRect occlusion_hint, bool hit_testable, - bool focusable, - bool use_flatland) { + bool focusable) { FML_CHECK(shell_); shell_->GetTaskRunners().GetRasterTaskRunner()->PostTask( - [this, use_flatland, view_id, occlusion_hint, hit_testable, focusable]() { - if (use_flatland) { - FML_CHECK(flatland_view_embedder_); - flatland_view_embedder_->SetViewProperties(view_id, occlusion_hint, - hit_testable, focusable); - } else { - FML_CHECK(external_view_embedder_); - external_view_embedder_->SetViewProperties(view_id, occlusion_hint, - hit_testable, focusable); - } + [this, view_id, occlusion_hint, hit_testable, focusable]() { + FML_CHECK(view_embedder_); + view_embedder_->SetViewProperties(view_id, occlusion_hint, hit_testable, + focusable); }); } -void Engine::DestroyGfxView(int64_t view_id, - GfxViewIdCallback on_view_unbound) { +void Engine::DestroyView(int64_t view_id, ViewIdCallback on_view_unbound) { FML_CHECK(shell_); shell_->GetTaskRunners().GetRasterTaskRunner()->PostTask( [this, view_id, on_view_unbound = std::move(on_view_unbound)]() { - FML_CHECK(external_view_embedder_); - external_view_embedder_->DestroyView(view_id, - std::move(on_view_unbound)); - }); -} - -void Engine::DestroyFlatlandView(int64_t view_id, - FlatlandViewIdCallback on_view_unbound) { - FML_CHECK(shell_); - - shell_->GetTaskRunners().GetRasterTaskRunner()->PostTask( - [this, view_id, on_view_unbound = std::move(on_view_unbound)]() { - FML_CHECK(flatland_view_embedder_); - flatland_view_embedder_->DestroyView(view_id, - std::move(on_view_unbound)); + FML_CHECK(view_embedder_); + view_embedder_->DestroyView(view_id, std::move(on_view_unbound)); }); } @@ -977,12 +809,8 @@ std::unique_ptr Engine::CreateSurface() { std::shared_ptr Engine::GetExternalViewEmbedder() { - FML_CHECK(external_view_embedder_ || flatland_view_embedder_); - - if (external_view_embedder_) { - return external_view_embedder_; - } - return flatland_view_embedder_; + FML_CHECK(view_embedder_); + return view_embedder_; } #if !defined(DART_PRODUCT) diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/engine.h b/engine/src/flutter/shell/platform/fuchsia/flutter/engine.h index cfcbe1e2ca..113e6e1589 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/engine.h +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/engine.h @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -25,11 +24,9 @@ #include "flutter/shell/common/thread_host.h" #include "flutter/shell/platform/fuchsia/flutter/accessibility_bridge.h" +#include "external_view_embedder.h" #include "flatland_connection.h" -#include "flatland_external_view_embedder.h" #include "flutter_runner_product_configuration.h" -#include "gfx_external_view_embedder.h" -#include "gfx_session_connection.h" #include "isolate_configurator.h" #include "surface_producer.h" @@ -52,21 +49,6 @@ class Engine final : public fuchsia::memorypressure::Watcher { const std::string& name_prefix, const std::shared_ptr& runner_services = nullptr); - // Gfx connection ctor. - Engine(Delegate& delegate, - std::string thread_label, - std::shared_ptr svc, - std::shared_ptr runner_services, - flutter::Settings settings, - fuchsia::ui::views::ViewToken view_token, - scenic::ViewRefPair view_ref_pair, - UniqueFDIONS fdio_ns, - fidl::InterfaceRequest directory_request, - FlutterRunnerProductConfiguration product_config, - const std::vector& dart_entrypoint_args, - bool for_v1_component); - - // Flatland connection ctor. Engine(Delegate& delegate, std::string thread_label, std::shared_ptr svc, @@ -92,7 +74,6 @@ class Engine final : public fuchsia::memorypressure::Watcher { private: void Initialize( - bool use_flatland, scenic::ViewRefPair view_ref_pair, std::shared_ptr svc, std::shared_ptr runner_services, @@ -120,24 +101,16 @@ class Engine final : public fuchsia::memorypressure::Watcher { void Terminate(); void DebugWireframeSettingsChanged(bool enabled); - void CreateGfxView(int64_t view_id, - ViewCallback on_view_created, - GfxViewIdCallback on_view_bound, - bool hit_testable, - bool focusable); - void CreateFlatlandView(int64_t view_id, - ViewCallback on_view_created, - FlatlandViewCreatedCallback on_view_bound, - bool hit_testable, - bool focusable); + void CreateView(int64_t view_id, + ViewCallback on_view_created, + ViewCreatedCallback on_view_bound, + bool hit_testable, + bool focusable); void UpdateView(int64_t view_id, SkRect occlusion_hint, bool hit_testable, - bool focusable, - bool use_flatland); - void DestroyGfxView(int64_t view_id, GfxViewIdCallback on_view_unbound); - void DestroyFlatlandView(int64_t view_id, - FlatlandViewIdCallback on_view_unbound); + bool focusable); + void DestroyView(int64_t view_id, ViewIdCallback on_view_unbound); // |fuchsia::memorypressure::Watcher| void OnLevelChanged(fuchsia::memorypressure::Level level, @@ -153,15 +126,11 @@ class Engine final : public fuchsia::memorypressure::Watcher { 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 - session_connection_; // Must come before surface_producer_ std::shared_ptr flatland_connection_; // Must come before surface_producer_ std::shared_ptr surface_producer_; - std::shared_ptr external_view_embedder_; - std::shared_ptr flatland_view_embedder_; + std::shared_ptr view_embedder_; std::unique_ptr isolate_configurator_; std::unique_ptr shell_; diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/flatland_external_view_embedder.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/external_view_embedder.cc similarity index 86% rename from engine/src/flutter/shell/platform/fuchsia/flutter/flatland_external_view_embedder.cc rename to engine/src/flutter/shell/platform/fuchsia/flutter/external_view_embedder.cc index 640dc0728b..6a5604015e 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/flatland_external_view_embedder.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/external_view_embedder.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "flatland_external_view_embedder.h" +#include "external_view_embedder.h" #include #include @@ -17,7 +17,7 @@ namespace { void AttachClipTransformChild( FlatlandConnection* flatland, - FlatlandExternalViewEmbedder::ClipTransform* parent_clip_transform, + ExternalViewEmbedder::ClipTransform* parent_clip_transform, const fuchsia::ui::composition::TransformId& child_transform_id) { flatland->flatland()->AddChild(parent_clip_transform->transform_id, child_transform_id); @@ -26,7 +26,7 @@ void AttachClipTransformChild( void DetachClipTransformChildren( FlatlandConnection* flatland, - FlatlandExternalViewEmbedder::ClipTransform* clip_transform) { + ExternalViewEmbedder::ClipTransform* clip_transform) { for (auto& child : clip_transform->children) { flatland->flatland()->RemoveChild(clip_transform->transform_id, child); } @@ -35,7 +35,7 @@ void DetachClipTransformChildren( } // namespace -FlatlandExternalViewEmbedder::FlatlandExternalViewEmbedder( +ExternalViewEmbedder::ExternalViewEmbedder( fuchsia::ui::views::ViewCreationToken view_creation_token, fuchsia::ui::views::ViewIdentityOnCreation view_identity, fuchsia::ui::composition::ViewBoundProtocols view_protocols, @@ -66,9 +66,9 @@ FlatlandExternalViewEmbedder::FlatlandExternalViewEmbedder( } } -FlatlandExternalViewEmbedder::~FlatlandExternalViewEmbedder() = default; +ExternalViewEmbedder::~ExternalViewEmbedder() = default; -flutter::DlCanvas* FlatlandExternalViewEmbedder::GetRootCanvas() { +flutter::DlCanvas* ExternalViewEmbedder::GetRootCanvas() { auto found = frame_layers_.find(kRootLayerId); if (found == frame_layers_.end()) { FML_LOG(WARNING) @@ -81,7 +81,7 @@ flutter::DlCanvas* FlatlandExternalViewEmbedder::GetRootCanvas() { return found->second.canvas_spy->GetSpyingCanvas(); } -void FlatlandExternalViewEmbedder::PrerollCompositeEmbeddedView( +void ExternalViewEmbedder::PrerollCompositeEmbeddedView( int64_t view_id, std::unique_ptr params) { zx_handle_t handle = static_cast(view_id); @@ -93,7 +93,7 @@ void FlatlandExternalViewEmbedder::PrerollCompositeEmbeddedView( frame_composition_order_.push_back(handle); } -flutter::DlCanvas* FlatlandExternalViewEmbedder::CompositeEmbeddedView( +flutter::DlCanvas* ExternalViewEmbedder::CompositeEmbeddedView( int64_t view_id) { zx_handle_t handle = static_cast(view_id); auto found = frame_layers_.find(handle); @@ -102,17 +102,17 @@ flutter::DlCanvas* FlatlandExternalViewEmbedder::CompositeEmbeddedView( return found->second.canvas_spy->GetSpyingCanvas(); } -flutter::PostPrerollResult FlatlandExternalViewEmbedder::PostPrerollAction( +flutter::PostPrerollResult ExternalViewEmbedder::PostPrerollAction( fml::RefPtr raster_thread_merger) { return flutter::PostPrerollResult::kSuccess; } -void FlatlandExternalViewEmbedder::BeginFrame( +void ExternalViewEmbedder::BeginFrame( SkISize frame_size, GrDirectContext* context, double device_pixel_ratio, fml::RefPtr raster_thread_merger) { - TRACE_EVENT0("flutter", "FlatlandExternalViewEmbedder::BeginFrame"); + TRACE_EVENT0("flutter", "ExternalViewEmbedder::BeginFrame"); // Reset for new frame. Reset(); @@ -126,17 +126,17 @@ void FlatlandExternalViewEmbedder::BeginFrame( frame_composition_order_.push_back(kRootLayerId); } -void FlatlandExternalViewEmbedder::EndFrame( +void ExternalViewEmbedder::EndFrame( bool should_resubmit_frame, fml::RefPtr raster_thread_merger) { - TRACE_EVENT0("flutter", "FlatlandExternalViewEmbedder::EndFrame"); + TRACE_EVENT0("flutter", "ExternalViewEmbedder::EndFrame"); } -void FlatlandExternalViewEmbedder::SubmitFrame( +void ExternalViewEmbedder::SubmitFrame( GrDirectContext* context, const std::shared_ptr& aiks_context, std::unique_ptr frame) { - TRACE_EVENT0("flutter", "FlatlandExternalViewEmbedder::SubmitFrame"); + TRACE_EVENT0("flutter", "ExternalViewEmbedder::SubmitFrame"); std::vector> frame_surfaces; std::unordered_map frame_surface_indices; @@ -211,7 +211,7 @@ void FlatlandExternalViewEmbedder::SubmitFrame( const float inv_dpr = 1.0f / frame_dpr_; flatland_->flatland()->SetScale(root_transform_id_, {inv_dpr, inv_dpr}); - size_t flatland_layer_index = 0; + size_t layer_index = 0; for (const auto& layer_id : frame_composition_order_) { const auto& layer = frame_layers_.find(layer_id); FML_CHECK(layer != frame_layers_.end()); @@ -221,10 +221,10 @@ void FlatlandExternalViewEmbedder::SubmitFrame( FML_CHECK(layer->second.embedded_view_params.has_value()); auto& view_params = layer->second.embedded_view_params.value(); - // Get the FlatlandView structure corresponding to the platform view. - auto found = flatland_views_.find(layer_id.value()); - FML_CHECK(found != flatland_views_.end()) - << "No FlatlandView for layer_id = " << layer_id.value() + // Get the View structure corresponding to the platform view. + auto found = views_.find(layer_id.value()); + FML_CHECK(found != views_.end()) + << "No View for layer_id = " << layer_id.value() << ". This typically indicates that the Dart code in " "Fuchsia's fuchsia_scenic_flutter library failed to create " "the platform view, leading to a crash later down the road in " @@ -355,7 +355,7 @@ void FlatlandExternalViewEmbedder::SubmitFrame( viewport.occlusion_hint = viewport.pending_occlusion_hint; } - // Attach the FlatlandView to the main scene graph. + // Attach the View to the main scene graph. const auto main_child_transform = viewport.mutators.clips.empty() ? viewport.transform_id @@ -386,17 +386,16 @@ void FlatlandExternalViewEmbedder::SubmitFrame( // Draw the layer if we acquired a surface for it successfully. if (surface_for_layer != nullptr) { // Create a new layer if needed for the surface. - FML_CHECK(flatland_layer_index <= flatland_layers_.size()); - if (flatland_layer_index == flatland_layers_.size()) { - FlatlandLayer new_layer{.transform_id = flatland_->NextTransformId()}; + FML_CHECK(layer_index <= layers_.size()); + if (layer_index == layers_.size()) { + Layer new_layer{.transform_id = flatland_->NextTransformId()}; flatland_->flatland()->CreateTransform(new_layer.transform_id); - flatland_layers_.emplace_back(std::move(new_layer)); + layers_.emplace_back(std::move(new_layer)); } // Update the image content and set size. - flatland_->flatland()->SetContent( - flatland_layers_[flatland_layer_index].transform_id, - {surface_for_layer->GetImageId()}); + flatland_->flatland()->SetContent(layers_[layer_index].transform_id, + {surface_for_layer->GetImageId()}); flatland_->flatland()->SetImageDestinationSize( {surface_for_layer->GetImageId()}, {static_cast(surface_for_layer->GetSize().width()), @@ -406,9 +405,8 @@ void FlatlandExternalViewEmbedder::SubmitFrame( // For now, we assume any layer beyond the first has alpha. flatland_->flatland()->SetImageBlendingFunction( {surface_for_layer->GetImageId()}, - flatland_layer_index == 0 - ? fuchsia::ui::composition::BlendMode::SRC - : fuchsia::ui::composition::BlendMode::SRC_OVER); + layer_index == 0 ? fuchsia::ui::composition::BlendMode::SRC + : fuchsia::ui::composition::BlendMode::SRC_OVER); // Set hit regions for this layer; these hit regions correspond to the // portions of the layer on which skia drew content. @@ -431,20 +429,17 @@ void FlatlandExternalViewEmbedder::SubmitFrame( } flatland_->flatland()->SetHitRegions( - flatland_layers_[flatland_layer_index].transform_id, - std::move(hit_regions)); + layers_[layer_index].transform_id, std::move(hit_regions)); } - // Attach the FlatlandLayer to the main scene graph. - flatland_->flatland()->AddChild( - root_transform_id_, - flatland_layers_[flatland_layer_index].transform_id); - child_transforms_.emplace_back( - flatland_layers_[flatland_layer_index].transform_id); + // Attach the Layer to the main scene graph. + flatland_->flatland()->AddChild(root_transform_id_, + layers_[layer_index].transform_id); + child_transforms_.emplace_back(layers_[layer_index].transform_id); } // Reset for the next pass: - flatland_layer_index++; + layer_index++; } // Set up the input interceptor at the top of the scene, if applicable. It @@ -507,16 +502,14 @@ void FlatlandExternalViewEmbedder::SubmitFrame( frame->Submit(); } -void FlatlandExternalViewEmbedder::CreateView( - int64_t view_id, - ViewCallback on_view_created, - FlatlandViewCreatedCallback on_view_bound) { - FML_CHECK(flatland_views_.find(view_id) == flatland_views_.end()); +void ExternalViewEmbedder::CreateView(int64_t view_id, + ViewCallback on_view_created, + ViewCreatedCallback on_view_bound) { + FML_CHECK(views_.find(view_id) == views_.end()); const auto transform_id = flatland_->NextTransformId(); const auto viewport_id = flatland_->NextContentId(); - FlatlandView new_view = {.transform_id = transform_id, - .viewport_id = viewport_id}; + View new_view = {.transform_id = transform_id, .viewport_id = viewport_id}; flatland_->flatland()->CreateTransform(new_view.transform_id); fuchsia::ui::composition::ChildViewWatcherHandle child_view_watcher; new_view.pending_create_viewport_callback = @@ -538,19 +531,18 @@ void FlatlandExternalViewEmbedder::CreateView( on_view_created(); on_view_bound(new_view.viewport_id, std::move(child_view_watcher)); - flatland_views_.emplace(std::make_pair(view_id, std::move(new_view))); + views_.emplace(std::make_pair(view_id, std::move(new_view))); } -void FlatlandExternalViewEmbedder::DestroyView( - int64_t view_id, - FlatlandViewIdCallback on_view_unbound) { - auto flatland_view = flatland_views_.find(view_id); - FML_CHECK(flatland_view != flatland_views_.end()); +void ExternalViewEmbedder::DestroyView(int64_t view_id, + ViewIdCallback on_view_unbound) { + auto view = views_.find(view_id); + FML_CHECK(view != views_.end()); - auto viewport_id = flatland_view->second.viewport_id; - auto transform_id = flatland_view->second.transform_id; - auto& clip_transforms = flatland_view->second.clip_transforms; - if (!flatland_view->second.pending_create_viewport_callback) { + auto viewport_id = view->second.viewport_id; + auto transform_id = view->second.transform_id; + auto& clip_transforms = view->second.clip_transforms; + if (!view->second.pending_create_viewport_callback) { flatland_->flatland()->ReleaseViewport(viewport_id, [](auto) {}); } auto itr = std::find_if( @@ -573,17 +565,16 @@ void FlatlandExternalViewEmbedder::DestroyView( flatland_->flatland()->ReleaseTransform(clip_transform.transform_id); } - flatland_views_.erase(flatland_view); + views_.erase(view); on_view_unbound(viewport_id); } -void FlatlandExternalViewEmbedder::SetViewProperties( - int64_t view_id, - const SkRect& occlusion_hint, - bool hit_testable, - bool focusable) { - auto found = flatland_views_.find(view_id); - FML_CHECK(found != flatland_views_.end()); +void ExternalViewEmbedder::SetViewProperties(int64_t view_id, + const SkRect& occlusion_hint, + bool hit_testable, + bool focusable) { + auto found = views_.find(view_id); + FML_CHECK(found != views_.end()); // Note that pending_create_viewport_callback might not have run at this // point. @@ -591,7 +582,7 @@ void FlatlandExternalViewEmbedder::SetViewProperties( viewport.pending_occlusion_hint = occlusion_hint; } -void FlatlandExternalViewEmbedder::Reset() { +void ExternalViewEmbedder::Reset() { frame_layers_.clear(); frame_composition_order_.clear(); frame_size_ = SkISize::Make(0, 0); @@ -604,13 +595,12 @@ void FlatlandExternalViewEmbedder::Reset() { child_transforms_.clear(); // Clear images on all layers so they aren't cached unnecessarily. - for (const auto& layer : flatland_layers_) { + for (const auto& layer : layers_) { flatland_->flatland()->SetContent(layer.transform_id, {0}); } } -FlatlandExternalViewEmbedder::ViewMutators -FlatlandExternalViewEmbedder::ParseMutatorStack( +ExternalViewEmbedder::ViewMutators ExternalViewEmbedder::ParseMutatorStack( const flutter::MutatorsStack& mutators_stack) { ViewMutators mutators; SkMatrix total_transform = SkMatrix::I(); diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/flatland_external_view_embedder.h b/engine/src/flutter/shell/platform/fuchsia/flutter/external_view_embedder.h similarity index 86% rename from engine/src/flutter/shell/platform/fuchsia/flutter/flatland_external_view_embedder.h rename to engine/src/flutter/shell/platform/fuchsia/flutter/external_view_embedder.h index 8c794c2c7f..7c489da2bb 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/flatland_external_view_embedder.h +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/external_view_embedder.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_FLATLAND_EXTERNAL_VIEW_EMBEDDER_H_ -#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_FLATLAND_EXTERNAL_VIEW_EMBEDDER_H_ +#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_EXTERNAL_VIEW_EMBEDDER_H_ +#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_EXTERNAL_VIEW_EMBEDDER_H_ #include #include @@ -33,21 +33,19 @@ namespace flutter_runner { using ViewCallback = std::function; -using FlatlandViewCreatedCallback = std::function; -using FlatlandViewIdCallback = - std::function; +using ViewIdCallback = std::function; -// This class orchestrates interaction with the Scenic's Flatland compositor on +// This class orchestrates interaction with the Scenic's compositor on // Fuchsia. It ensures that flutter content and platform view content are both // rendered correctly in a unified scene. -class FlatlandExternalViewEmbedder final - : public flutter::ExternalViewEmbedder { +class ExternalViewEmbedder final : public flutter::ExternalViewEmbedder { public: - constexpr static uint32_t kFlatlandDefaultViewportSize = 32; + constexpr static uint32_t kDefaultViewportSize = 32; - FlatlandExternalViewEmbedder( + ExternalViewEmbedder( fuchsia::ui::views::ViewCreationToken view_creation_token, fuchsia::ui::views::ViewIdentityOnCreation view_identity, fuchsia::ui::composition::ViewBoundProtocols endpoints, @@ -56,7 +54,7 @@ class FlatlandExternalViewEmbedder final std::shared_ptr flatland, std::shared_ptr surface_producer, bool intercept_all_input = false); - ~FlatlandExternalViewEmbedder(); + ~ExternalViewEmbedder(); // |ExternalViewEmbedder| flutter::DlCanvas* GetRootCanvas() override; @@ -101,14 +99,14 @@ class FlatlandExternalViewEmbedder final // properties for the next |UpdateView| call. void CreateView(int64_t view_id, ViewCallback on_view_created, - FlatlandViewCreatedCallback on_view_bound); - void DestroyView(int64_t view_id, FlatlandViewIdCallback on_view_unbound); + ViewCreatedCallback on_view_bound); + void DestroyView(int64_t view_id, ViewIdCallback on_view_unbound); void SetViewProperties(int64_t view_id, const SkRect& occlusion_hint, bool hit_testable, bool focusable); - // Holds the clip transform that may be applied on a FlatlandView. + // Holds the clip transform that may be applied on a View. struct ClipTransform { fuchsia::ui::composition::TransformId transform_id; std::vector children; @@ -174,7 +172,7 @@ class FlatlandExternalViewEmbedder final using EmbedderLayerId = std::optional; constexpr static EmbedderLayerId kRootLayerId = EmbedderLayerId{}; - struct FlatlandView { + struct View { std::vector clip_transforms; fuchsia::ui::composition::TransformId transform_id; fuchsia::ui::composition::ContentId viewport_id; @@ -186,7 +184,7 @@ class FlatlandExternalViewEmbedder final pending_create_viewport_callback; }; - struct FlatlandLayer { + struct Layer { // Transform on which Images are set. fuchsia::ui::composition::TransformId transform_id; }; @@ -198,8 +196,8 @@ class FlatlandExternalViewEmbedder final fuchsia::ui::composition::TransformId root_transform_id_; - std::unordered_map flatland_views_; - std::vector flatland_layers_; + std::unordered_map views_; + std::vector layers_; std::unordered_map frame_layers_; std::vector frame_composition_order_; @@ -212,9 +210,9 @@ class FlatlandExternalViewEmbedder final std::optional input_interceptor_transform_; - FML_DISALLOW_COPY_AND_ASSIGN(FlatlandExternalViewEmbedder); + FML_DISALLOW_COPY_AND_ASSIGN(ExternalViewEmbedder); }; } // namespace flutter_runner -#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_FLATLAND_EXTERNAL_VIEW_EMBEDDER_H_ +#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_EXTERNAL_VIEW_EMBEDDER_H_ diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/flatland_connection.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/flatland_connection.cc index df0014f719..5b3a029fab 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/flatland_connection.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/flatland_connection.cc @@ -91,7 +91,7 @@ void FlatlandConnection::AwaitVsync(FireCallbackCallback callback) { // Immediately fire callbacks until the first Present. We might receive // multiple requests for AwaitVsync() until the first Present, which relies on - // receiving size on FlatlandPlatformView::OnGetLayout() at an uncertain time. + // receiving size on PlatformView::OnGetLayout() at an uncertain time. if (!threadsafe_state_.first_present_called_) { callback(now, now + kDefaultFlatlandPresentationInterval); return; diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/flatland_platform_view.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/flatland_platform_view.cc deleted file mode 100644 index 39febd8c6d..0000000000 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/flatland_platform_view.cc +++ /dev/null @@ -1,303 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "flatland_platform_view.h" - -#include "flutter/fml/make_copyable.h" - -namespace flutter_runner { - -static constexpr int64_t kFlutterImplicitViewId = 0ll; - -FlatlandPlatformView::FlatlandPlatformView( - flutter::PlatformView::Delegate& delegate, - flutter::TaskRunners task_runners, - fuchsia::ui::views::ViewRef view_ref, - std::shared_ptr external_view_embedder, - fuchsia::ui::input::ImeServiceHandle ime_service, - fuchsia::ui::input3::KeyboardHandle keyboard, - fuchsia::ui::pointer::TouchSourceHandle touch_source, - fuchsia::ui::pointer::MouseSourceHandle mouse_source, - fuchsia::ui::views::FocuserHandle focuser, - fuchsia::ui::views::ViewRefFocusedHandle view_ref_focused, - fuchsia::ui::composition::ParentViewportWatcherHandle - parent_viewport_watcher, - fuchsia::ui::pointerinjector::RegistryHandle pointerinjector_registry, - OnEnableWireframe wireframe_enabled_callback, - OnCreateFlatlandView on_create_view_callback, - OnUpdateView on_update_view_callback, - OnDestroyFlatlandView on_destroy_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, - std::shared_ptr dart_application_svc) - : PlatformView(true /* is_flatland */, - delegate, - std::move(task_runners), - std::move(view_ref), - std::move(external_view_embedder), - std::move(ime_service), - std::move(keyboard), - std::move(touch_source), - std::move(mouse_source), - std::move(focuser), - std::move(view_ref_focused), - std::move(pointerinjector_registry), - 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(await_vsync_callback), - std::move(await_vsync_for_secondary_callback_callback), - std::move(dart_application_svc)), - 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) { - parent_viewport_watcher_.set_error_handler([](zx_status_t status) { - FML_LOG(ERROR) << "Interface error on: ParentViewportWatcher status: " - << status; - }); - - parent_viewport_watcher_->GetLayout( - fit::bind_member(this, &FlatlandPlatformView::OnGetLayout)); - parent_viewport_watcher_->GetStatus( - fit::bind_member(this, &FlatlandPlatformView::OnParentViewportStatus)); -} - -FlatlandPlatformView::~FlatlandPlatformView() = default; - -void FlatlandPlatformView::OnGetLayout( - fuchsia::ui::composition::LayoutInfo info) { - view_logical_size_ = {static_cast(info.logical_size().width), - static_cast(info.logical_size().height)}; - - if (info.has_device_pixel_ratio()) { - // Flatland returns a Vec2 for DPR but both values should be identical. - FML_DCHECK(info.device_pixel_ratio().x == info.device_pixel_ratio().y); - view_pixel_ratio_ = info.device_pixel_ratio().x; - } - - float pixel_ratio = view_pixel_ratio_ ? *view_pixel_ratio_ : 1.0f; - flutter::ViewportMetrics metrics{ - pixel_ratio, // device_pixel_ratio - std::round(view_logical_size_.value()[0] * - pixel_ratio), // physical_width - std::round(view_logical_size_.value()[1] * - pixel_ratio), // physical_height - 0.0f, // physical_padding_top - 0.0f, // physical_padding_right - 0.0f, // physical_padding_bottom - 0.0f, // physical_padding_left - 0.0f, // physical_view_inset_top - 0.0f, // physical_view_inset_right - 0.0f, // physical_view_inset_bottom - 0.0f, // physical_view_inset_left - 0.0f, // p_physical_system_gesture_inset_top - 0.0f, // p_physical_system_gesture_inset_right - 0.0f, // p_physical_system_gesture_inset_bottom - 0.0f, // p_physical_system_gesture_inset_left, - -1.0, // p_physical_touch_slop, - {}, // p_physical_display_features_bounds - {}, // p_physical_display_features_type - {}, // p_physical_display_features_state - 0, // p_display_id - }; - SetViewportMetrics(kFlutterImplicitViewId, metrics); - - parent_viewport_watcher_->GetLayout( - fit::bind_member(this, &FlatlandPlatformView::OnGetLayout)); -} - -void FlatlandPlatformView::OnParentViewportStatus( - fuchsia::ui::composition::ParentViewportStatus status) { - // TODO(fxbug.dev/116001): Investigate if it is useful to send hidden/shown - // signals. - parent_viewport_status_ = status; - parent_viewport_watcher_->GetStatus( - fit::bind_member(this, &FlatlandPlatformView::OnParentViewportStatus)); -} - -void FlatlandPlatformView::OnChildViewStatus( - uint64_t content_id, - fuchsia::ui::composition::ChildViewStatus status) { - FML_DCHECK(child_view_info_.count(content_id) == 1); - - std::ostringstream out; - out << "{" - << "\"method\":\"View.viewStateChanged\"," - << "\"args\":{" - << " \"viewId\":" << child_view_info_.at(content_id).view_id - << "," // ViewId - << " \"is_rendering\":true," // IsViewRendering - << " \"state\":true" // IsViewRendering - << " }" - << "}"; - auto call = out.str(); - - std::unique_ptr message = - std::make_unique( - "flutter/platform_views", - fml::MallocMapping::Copy(call.c_str(), call.size()), nullptr); - DispatchPlatformMessage(std::move(message)); - - child_view_info_.at(content_id) - .child_view_watcher->GetStatus( - [this, content_id](fuchsia::ui::composition::ChildViewStatus status) { - OnChildViewStatus(content_id, status); - }); -} - -void FlatlandPlatformView::OnChildViewViewRef( - uint64_t content_id, - uint64_t view_id, - fuchsia::ui::views::ViewRef view_ref) { - FML_CHECK(child_view_info_.count(content_id) == 1); - - fuchsia::ui::views::ViewRef view_ref_clone; - fidl::Clone(view_ref, &view_ref_clone); - - focus_delegate_->OnChildViewViewRef(view_id, std::move(view_ref)); - - pointer_injector_delegate_->OnCreateView(view_id, std::move(view_ref_clone)); - OnChildViewConnected(content_id); -} - -void FlatlandPlatformView::OnCreateView(ViewCallback on_view_created, - int64_t view_id_raw, - bool hit_testable, - bool focusable) { - auto on_view_bound = [weak = weak_factory_.GetWeakPtr(), - platform_task_runner = - task_runners_.GetPlatformTaskRunner(), - view_id = view_id_raw]( - fuchsia::ui::composition::ContentId content_id, - fuchsia::ui::composition::ChildViewWatcherHandle - child_view_watcher_handle) { - FML_CHECK(weak); - FML_CHECK(weak->child_view_info_.count(content_id.value) == 0); - - platform_task_runner->PostTask(fml::MakeCopyable( - [weak, view_id, content_id, - watcher_handle = std::move(child_view_watcher_handle)]() mutable { - if (!weak) { - FML_LOG(WARNING) - << "Flatland View bound to PlatformView after PlatformView was " - "destroyed; ignoring."; - return; - } - - // Bind the child view watcher to the platform thread so that the FIDL - // calls are handled on the platform thread. - fuchsia::ui::composition::ChildViewWatcherPtr child_view_watcher = - watcher_handle.Bind(); - FML_CHECK(child_view_watcher); - - child_view_watcher.set_error_handler([weak, view_id, content_id]( - zx_status_t status) { - FML_LOG(WARNING) - << "Child disconnected. ChildViewWatcher status: " << status; - - if (!weak) { - FML_LOG(WARNING) << "Flatland View bound to PlatformView after " - "PlatformView was " - "destroyed; ignoring."; - return; - } - - // Disconnected views cannot listen to pointer events. - weak->pointer_injector_delegate_->OnDestroyView(view_id); - - weak->OnChildViewDisconnected(content_id.value); - }); - - weak->child_view_info_.emplace( - std::piecewise_construct, std::forward_as_tuple(content_id.value), - std::forward_as_tuple(view_id, std::move(child_view_watcher))); - - weak->child_view_info_.at(content_id.value) - .child_view_watcher->GetStatus( - [weak, id = content_id.value]( - fuchsia::ui::composition::ChildViewStatus status) { - weak->OnChildViewStatus(id, status); - }); - - weak->child_view_info_.at(content_id.value) - .child_view_watcher->GetViewRef( - [weak, content_id = content_id.value, - view_id](fuchsia::ui::views::ViewRef view_ref) { - weak->OnChildViewViewRef(content_id, view_id, - std::move(view_ref)); - }); - })); - }; - - on_create_view_callback_(view_id_raw, std::move(on_view_created), - std::move(on_view_bound), hit_testable, focusable); -} - -void FlatlandPlatformView::OnDisposeView(int64_t view_id_raw) { - auto on_view_unbound = - [weak = weak_factory_.GetWeakPtr(), - platform_task_runner = task_runners_.GetPlatformTaskRunner(), - view_id_raw](fuchsia::ui::composition::ContentId content_id) { - platform_task_runner->PostTask([weak, content_id, view_id_raw]() { - if (!weak) { - FML_LOG(WARNING) - << "Flatland View unbound from PlatformView after PlatformView" - "was destroyed; ignoring."; - return; - } - - FML_DCHECK(weak->child_view_info_.count(content_id.value) == 1); - weak->OnChildViewDisconnected(content_id.value); - weak->child_view_info_.erase(content_id.value); - weak->focus_delegate_->OnDisposeChildView(view_id_raw); - weak->pointer_injector_delegate_->OnDestroyView(view_id_raw); - }); - }; - on_destroy_view_callback_(view_id_raw, std::move(on_view_unbound)); -} - -void FlatlandPlatformView::OnChildViewConnected(uint64_t content_id) { - FML_CHECK(child_view_info_.count(content_id) == 1); - std::ostringstream out; - out << "{" - << "\"method\":\"View.viewConnected\"," - << "\"args\":{" - << " \"viewId\":" << child_view_info_.at(content_id).view_id << " }" - << "}"; - auto call = out.str(); - - std::unique_ptr message = - std::make_unique( - "flutter/platform_views", - fml::MallocMapping::Copy(call.c_str(), call.size()), nullptr); - DispatchPlatformMessage(std::move(message)); -} - -void FlatlandPlatformView::OnChildViewDisconnected(uint64_t content_id) { - FML_CHECK(child_view_info_.count(content_id) == 1); - std::ostringstream out; - out << "{" - << "\"method\":\"View.viewDisconnected\"," - << "\"args\":{" - << " \"viewId\":" << child_view_info_.at(content_id).view_id << " }" - << "}"; - auto call = out.str(); - - std::unique_ptr message = - std::make_unique( - "flutter/platform_views", - fml::MallocMapping::Copy(call.c_str(), call.size()), nullptr); - DispatchPlatformMessage(std::move(message)); -} - -} // namespace flutter_runner diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/flatland_platform_view.h b/engine/src/flutter/shell/platform/fuchsia/flutter/flatland_platform_view.h deleted file mode 100644 index 8e839c9b1e..0000000000 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/flatland_platform_view.h +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_FLATLAND_PLATFORM_VIEW_H_ -#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_FLATLAND_PLATFORM_VIEW_H_ - -#include "flutter/shell/platform/fuchsia/flutter/platform_view.h" - -#include - -#include "flutter/fml/memory/weak_ptr.h" -#include "flutter/shell/platform/fuchsia/flutter/flatland_external_view_embedder.h" - -namespace flutter_runner { - -using OnCreateFlatlandView = fit::function< - void(int64_t, ViewCallback, FlatlandViewCreatedCallback, bool, bool)>; -using OnDestroyFlatlandView = - fit::function; - -// The FlatlandPlatformView that does Flatland specific... -class FlatlandPlatformView final : public flutter_runner::PlatformView { - public: - FlatlandPlatformView( - flutter::PlatformView::Delegate& delegate, - flutter::TaskRunners task_runners, - fuchsia::ui::views::ViewRef view_ref, - std::shared_ptr external_view_embedder, - fuchsia::ui::input::ImeServiceHandle ime_service, - fuchsia::ui::input3::KeyboardHandle keyboard, - fuchsia::ui::pointer::TouchSourceHandle touch_source, - fuchsia::ui::pointer::MouseSourceHandle mouse_source, - fuchsia::ui::views::FocuserHandle focuser, - fuchsia::ui::views::ViewRefFocusedHandle view_ref_focused, - fuchsia::ui::composition::ParentViewportWatcherHandle - parent_viewport_watcher, - fuchsia::ui::pointerinjector::RegistryHandle pointerinjector_registry, - OnEnableWireframe wireframe_enabled_callback, - OnCreateFlatlandView on_create_view_callback, - OnUpdateView on_update_view_callback, - OnDestroyFlatlandView on_destroy_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, - std::shared_ptr dart_application_svc); - ~FlatlandPlatformView() override; - - void OnGetLayout(fuchsia::ui::composition::LayoutInfo info); - void OnParentViewportStatus( - fuchsia::ui::composition::ParentViewportStatus status); - void OnChildViewStatus(uint64_t content_id, - fuchsia::ui::composition::ChildViewStatus status); - void OnChildViewViewRef(uint64_t content_id, - uint64_t view_id, - fuchsia::ui::views::ViewRef view_ref); - - private: - void OnCreateView(ViewCallback on_view_created, - int64_t view_id_raw, - bool hit_testable, - bool focusable) override; - void OnDisposeView(int64_t view_id_raw) override; - - // Sends a 'View.viewConnected' platform message over 'flutter/platform_views' - // channel when a view gets created. - void OnChildViewConnected(uint64_t content_id); - - // Sends a 'View.viewDisconnected' platform message over - // 'flutter/platform_views' channel when a view gets destroyed or the child - // view watcher channel of a view closes. - void OnChildViewDisconnected(uint64_t content_id); - - // child_view_ids_ maintains a persistent mapping from Flatland ContentId's to - // flutter view ids, which are really zx_handle_t of ViewCreationToken. - struct ChildViewInfo { - ChildViewInfo(zx_handle_t token, - fuchsia::ui::composition::ChildViewWatcherPtr watcher) - : view_id(token), child_view_watcher(std::move(watcher)) {} - zx_handle_t view_id; - fuchsia::ui::composition::ChildViewWatcherPtr child_view_watcher; - }; - std::unordered_map - child_view_info_; - - fuchsia::ui::composition::ParentViewportWatcherPtr parent_viewport_watcher_; - - OnCreateFlatlandView on_create_view_callback_; - OnDestroyFlatlandView on_destroy_view_callback_; - - fuchsia::ui::composition::ParentViewportStatus parent_viewport_status_; - - fml::WeakPtrFactory - weak_factory_; // Must be the last member. - - FML_DISALLOW_COPY_AND_ASSIGN(FlatlandPlatformView); -}; - -} // namespace flutter_runner - -#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_FLATLAND_PLATFORM_VIEW_H_ diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/meta/common.shard.cml b/engine/src/flutter/shell/platform/fuchsia/flutter/meta/common.shard.cml index 5e93f1ed7a..3fccfc6408 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/meta/common.shard.cml +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/meta/common.shard.cml @@ -47,7 +47,6 @@ "fuchsia.ui.input.ImeService", "fuchsia.ui.input3.Keyboard", "fuchsia.ui.pointerinjector.Registry", - "fuchsia.ui.scenic.Scenic", "fuchsia.vulkan.loader.Loader", // Copied from vulkan/client.shard.cml. ], }, diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view.cc index 05658820c9..22fd9dbfa8 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view.cc @@ -24,6 +24,7 @@ #include "third_party/rapidjson/include/rapidjson/stringbuffer.h" #include "third_party/rapidjson/include/rapidjson/writer.h" +#include "flutter/fml/make_copyable.h" #include "logging.h" #include "pointer_injector_delegate.h" #include "runtime/dart/utils/inlines.h" @@ -54,9 +55,9 @@ static constexpr char kFlutterPlatformViewsChannel[] = "flutter/platform_views"; static constexpr char kFuchsiaShaderWarmupChannel[] = "fuchsia/shader_warmup"; static constexpr char kFuchsiaInputTestChannel[] = "fuchsia/input_test"; static constexpr char kFuchsiaChildViewChannel[] = "fuchsia/child_view"; +static constexpr int64_t kFlutterImplicitViewId = 0ll; PlatformView::PlatformView( - bool is_flatland, flutter::PlatformView::Delegate& delegate, flutter::TaskRunners task_runners, fuchsia::ui::views::ViewRef view_ref, @@ -67,13 +68,17 @@ PlatformView::PlatformView( fuchsia::ui::pointer::MouseSourceHandle mouse_source, fuchsia::ui::views::FocuserHandle focuser, fuchsia::ui::views::ViewRefFocusedHandle view_ref_focused, + fuchsia::ui::composition::ParentViewportWatcherHandle + parent_viewport_watcher, fuchsia::ui::pointerinjector::RegistryHandle pointerinjector_registry, - 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, + OnEnableWireframeCallback wireframe_enabled_callback, + OnCreateViewCallback on_create_view_callback, + OnUpdateViewCallback on_update_view_callback, + OnDestroyViewCallback on_destroy_view_callback, + OnCreateSurfaceCallback on_create_surface_callback, + OnSemanticsNodeUpdateCallback on_semantics_node_update_callback, + OnRequestAnnounceCallback on_request_announce_callback, + OnShaderWarmupCallback on_shader_warmup_callback, AwaitVsyncCallback await_vsync_callback, AwaitVsyncForSecondaryCallbackCallback await_vsync_for_secondary_callback_callback, @@ -92,11 +97,14 @@ PlatformView::PlatformView( on_semantics_node_update_callback_( 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)), + on_create_view_callback_(std::move(on_create_view_callback)), + on_destroy_view_callback_(std::move(on_destroy_view_callback)), + on_shader_warmup_callback_(std::move(on_shader_warmup_callback)), await_vsync_callback_(await_vsync_callback), await_vsync_for_secondary_callback_callback_( await_vsync_for_secondary_callback_callback), dart_application_svc_(dart_application_svc), + parent_viewport_watcher_(parent_viewport_watcher.Bind()), weak_factory_(this) { fuchsia::ui::views::ViewRef view_ref_clone; fidl::Clone(view_ref, &view_ref_clone); @@ -159,8 +167,7 @@ PlatformView::PlatformView( // Configure the pointer injector delegate. pointer_injector_delegate_ = std::make_unique( - std::move(pointerinjector_registry), std::move(view_ref_clone), - is_flatland); + std::move(pointerinjector_registry), std::move(view_ref_clone)); // This is only used by the integration tests. if (dart_application_svc) { @@ -209,6 +216,16 @@ PlatformView::PlatformView( // Finally! Register the native platform message handlers. RegisterPlatformMessageHandlers(); + + parent_viewport_watcher_.set_error_handler([](zx_status_t status) { + FML_LOG(ERROR) << "Interface error on: ParentViewportWatcher status: " + << status; + }); + + parent_viewport_watcher_->GetLayout( + fit::bind_member(this, &PlatformView::OnGetLayout)); + parent_viewport_watcher_->GetStatus( + fit::bind_member(this, &PlatformView::OnParentViewportStatus)); } PlatformView::~PlatformView() = default; @@ -228,7 +245,7 @@ void PlatformView::RegisterPlatformMessageHandlers() { this, std::placeholders::_1); platform_message_handlers_[kFuchsiaShaderWarmupChannel] = std::bind(&HandleFuchsiaShaderWarmupChannelPlatformMessage, - on_shader_warmup_, std::placeholders::_1); + on_shader_warmup_callback_, std::placeholders::_1); platform_message_handlers_[kFuchsiaInputTestChannel] = std::bind(&PlatformView::HandleFuchsiaInputTestChannelPlatformMessage, this, std::placeholders::_1); @@ -309,6 +326,230 @@ std::array PlatformView::ClampToViewSpace(const float x, return {clamped_x, clamped_y}; } +void PlatformView::OnGetLayout(fuchsia::ui::composition::LayoutInfo info) { + view_logical_size_ = {static_cast(info.logical_size().width), + static_cast(info.logical_size().height)}; + + if (info.has_device_pixel_ratio()) { + // Both values should be identical for the Vec2 for DPR. + FML_DCHECK(info.device_pixel_ratio().x == info.device_pixel_ratio().y); + view_pixel_ratio_ = info.device_pixel_ratio().x; + } + + float pixel_ratio = view_pixel_ratio_ ? *view_pixel_ratio_ : 1.0f; + flutter::ViewportMetrics metrics{ + pixel_ratio, // device_pixel_ratio + std::round(view_logical_size_.value()[0] * + pixel_ratio), // physical_width + std::round(view_logical_size_.value()[1] * + pixel_ratio), // physical_height + 0.0f, // physical_padding_top + 0.0f, // physical_padding_right + 0.0f, // physical_padding_bottom + 0.0f, // physical_padding_left + 0.0f, // physical_view_inset_top + 0.0f, // physical_view_inset_right + 0.0f, // physical_view_inset_bottom + 0.0f, // physical_view_inset_left + 0.0f, // p_physical_system_gesture_inset_top + 0.0f, // p_physical_system_gesture_inset_right + 0.0f, // p_physical_system_gesture_inset_bottom + 0.0f, // p_physical_system_gesture_inset_left, + -1.0, // p_physical_touch_slop, + {}, // p_physical_display_features_bounds + {}, // p_physical_display_features_type + {}, // p_physical_display_features_state + 0, // p_display_id + }; + SetViewportMetrics(kFlutterImplicitViewId, metrics); + + parent_viewport_watcher_->GetLayout( + fit::bind_member(this, &PlatformView::OnGetLayout)); +} + +void PlatformView::OnParentViewportStatus( + fuchsia::ui::composition::ParentViewportStatus status) { + // TODO(fxbug.dev/116001): Investigate if it is useful to send hidden/shown + // signals. + parent_viewport_status_ = status; + parent_viewport_watcher_->GetStatus( + fit::bind_member(this, &PlatformView::OnParentViewportStatus)); +} + +void PlatformView::OnChildViewStatus( + uint64_t content_id, + fuchsia::ui::composition::ChildViewStatus status) { + FML_DCHECK(child_view_info_.count(content_id) == 1); + + std::ostringstream out; + out << "{" + << "\"method\":\"View.viewStateChanged\"," + << "\"args\":{" + << " \"viewId\":" << child_view_info_.at(content_id).view_id + << "," // ViewId + << " \"is_rendering\":true," // IsViewRendering + << " \"state\":true" // IsViewRendering + << " }" + << "}"; + auto call = out.str(); + + std::unique_ptr message = + std::make_unique( + "flutter/platform_views", + fml::MallocMapping::Copy(call.c_str(), call.size()), nullptr); + DispatchPlatformMessage(std::move(message)); + + child_view_info_.at(content_id) + .child_view_watcher->GetStatus( + [this, content_id](fuchsia::ui::composition::ChildViewStatus status) { + OnChildViewStatus(content_id, status); + }); +} + +void PlatformView::OnChildViewViewRef(uint64_t content_id, + uint64_t view_id, + fuchsia::ui::views::ViewRef view_ref) { + FML_CHECK(child_view_info_.count(content_id) == 1); + + fuchsia::ui::views::ViewRef view_ref_clone; + fidl::Clone(view_ref, &view_ref_clone); + + focus_delegate_->OnChildViewViewRef(view_id, std::move(view_ref)); + + pointer_injector_delegate_->OnCreateView(view_id, std::move(view_ref_clone)); + OnChildViewConnected(content_id); +} + +void PlatformView::OnCreateView(ViewCallback on_view_created, + int64_t view_id_raw, + bool hit_testable, + bool focusable) { + auto on_view_bound = [weak = weak_factory_.GetWeakPtr(), + platform_task_runner = + task_runners_.GetPlatformTaskRunner(), + view_id = view_id_raw]( + fuchsia::ui::composition::ContentId content_id, + fuchsia::ui::composition::ChildViewWatcherHandle + child_view_watcher_handle) { + FML_CHECK(weak); + FML_CHECK(weak->child_view_info_.count(content_id.value) == 0); + + platform_task_runner->PostTask(fml::MakeCopyable( + [weak, view_id, content_id, + watcher_handle = std::move(child_view_watcher_handle)]() mutable { + if (!weak) { + FML_LOG(WARNING) + << "View bound to PlatformView after PlatformView was " + "destroyed; ignoring."; + return; + } + + // Bind the child view watcher to the platform thread so that the FIDL + // calls are handled on the platform thread. + fuchsia::ui::composition::ChildViewWatcherPtr child_view_watcher = + watcher_handle.Bind(); + FML_CHECK(child_view_watcher); + + child_view_watcher.set_error_handler([weak, view_id, content_id]( + zx_status_t status) { + FML_LOG(WARNING) + << "Child disconnected. ChildViewWatcher status: " << status; + + if (!weak) { + FML_LOG(WARNING) << "View bound to PlatformView after " + "PlatformView was " + "destroyed; ignoring."; + return; + } + + // Disconnected views cannot listen to pointer events. + weak->pointer_injector_delegate_->OnDestroyView(view_id); + + weak->OnChildViewDisconnected(content_id.value); + }); + + weak->child_view_info_.emplace( + std::piecewise_construct, std::forward_as_tuple(content_id.value), + std::forward_as_tuple(view_id, std::move(child_view_watcher))); + + weak->child_view_info_.at(content_id.value) + .child_view_watcher->GetStatus( + [weak, id = content_id.value]( + fuchsia::ui::composition::ChildViewStatus status) { + weak->OnChildViewStatus(id, status); + }); + + weak->child_view_info_.at(content_id.value) + .child_view_watcher->GetViewRef( + [weak, content_id = content_id.value, + view_id](fuchsia::ui::views::ViewRef view_ref) { + weak->OnChildViewViewRef(content_id, view_id, + std::move(view_ref)); + }); + })); + }; + + on_create_view_callback_(view_id_raw, std::move(on_view_created), + std::move(on_view_bound), hit_testable, focusable); +} + +void PlatformView::OnDisposeView(int64_t view_id_raw) { + auto on_view_unbound = + [weak = weak_factory_.GetWeakPtr(), + platform_task_runner = task_runners_.GetPlatformTaskRunner(), + view_id_raw](fuchsia::ui::composition::ContentId content_id) { + platform_task_runner->PostTask([weak, content_id, view_id_raw]() { + if (!weak) { + FML_LOG(WARNING) + << "View unbound from PlatformView after PlatformView" + "was destroyed; ignoring."; + return; + } + + FML_DCHECK(weak->child_view_info_.count(content_id.value) == 1); + weak->OnChildViewDisconnected(content_id.value); + weak->child_view_info_.erase(content_id.value); + weak->focus_delegate_->OnDisposeChildView(view_id_raw); + weak->pointer_injector_delegate_->OnDestroyView(view_id_raw); + }); + }; + on_destroy_view_callback_(view_id_raw, std::move(on_view_unbound)); +} + +void PlatformView::OnChildViewConnected(uint64_t content_id) { + FML_CHECK(child_view_info_.count(content_id) == 1); + std::ostringstream out; + out << "{" + << "\"method\":\"View.viewConnected\"," + << "\"args\":{" + << " \"viewId\":" << child_view_info_.at(content_id).view_id << " }" + << "}"; + auto call = out.str(); + + std::unique_ptr message = + std::make_unique( + "flutter/platform_views", + fml::MallocMapping::Copy(call.c_str(), call.size()), nullptr); + DispatchPlatformMessage(std::move(message)); +} + +void PlatformView::OnChildViewDisconnected(uint64_t content_id) { + FML_CHECK(child_view_info_.count(content_id) == 1); + std::ostringstream out; + out << "{" + << "\"method\":\"View.viewDisconnected\"," + << "\"args\":{" + << " \"viewId\":" << child_view_info_.at(content_id).view_id << " }" + << "}"; + auto call = out.str(); + + std::unique_ptr message = + std::make_unique( + "flutter/platform_views", + fml::MallocMapping::Copy(call.c_str(), call.size()), nullptr); + DispatchPlatformMessage(std::move(message)); +} + bool PlatformView::OnHandlePointerEvent( const fuchsia::ui::input::PointerEvent& pointer) { TRACE_EVENT0("flutter", "PlatformView::OnHandlePointerEvent"); @@ -667,11 +908,11 @@ bool PlatformView::HandleFlutterPlatformViewsChannelPlatformMessage( } bool PlatformView::HandleFuchsiaShaderWarmupChannelPlatformMessage( - OnShaderWarmup on_shader_warmup, + OnShaderWarmupCallback on_shader_warmup_callback, std::unique_ptr message) { FML_DCHECK(message->channel() == kFuchsiaShaderWarmupChannel); - if (!on_shader_warmup) { + if (!on_shader_warmup_callback) { FML_LOG(ERROR) << "No shader warmup callback set!"; std::string result = "[0]"; message->response()->Complete( @@ -741,7 +982,7 @@ bool PlatformView::HandleFuchsiaShaderWarmupChannelPlatformMessage( (const uint8_t*)result.c_str() + result.length()))); }; - on_shader_warmup(skp_paths, completion_callback, width, height); + on_shader_warmup_callback(skp_paths, completion_callback, width, height); // The response has already been completed by us. return true; } @@ -876,14 +1117,13 @@ bool PlatformView::HandleFuchsiaChildViewChannelPlatformMessage( FML_DCHECK(message->channel() == kFuchsiaChildViewChannel); if (message->data().GetSize() != 1 || - (message->data().GetMapping()[0] != '0' && - message->data().GetMapping()[0] != '1')) { + (message->data().GetMapping()[0] != '1')) { FML_LOG(ERROR) << kFuchsiaChildViewChannel - << " data must be '0' (for gfx) or '1' (for flatland)."; + << " data must be singularly '1'."; return false; } - bool flatland = message->data().GetMapping()[0] == '1'; + FML_DCHECK(message->data().GetMapping()[0] == '1'); if (!message->response()) { FML_LOG(ERROR) << kFuchsiaChildViewChannel @@ -908,53 +1148,22 @@ bool PlatformView::HandleFuchsiaChildViewChannelPlatformMessage( zx::handle view_id; - if (flatland) { - zx::channel view_tokens[2]; - fuchsia::ui::views::ViewportCreationToken viewport_creation_token; - fuchsia::ui::views::ViewCreationToken view_creation_token; - status = zx::channel::create(0, &viewport_creation_token.value, - &view_creation_token.value); - if (status != ZX_OK) { - FML_LOG(ERROR) << "Creating view tokens: " - << zx_status_get_string(status); - return false; - } - - fuchsia::ui::app::CreateView2Args create_view_args; - create_view_args.set_view_creation_token(std::move(view_creation_token)); - view_provider->CreateView2(std::move(create_view_args)); - - view_id = std::move(viewport_creation_token.value); - } else { - zx::eventpair view_tokens[2]; - status = zx::eventpair::create(0, &view_tokens[0], &view_tokens[1]); - if (status != ZX_OK) { - FML_LOG(ERROR) << "Creating view tokens: " - << zx_status_get_string(status); - return false; - } - fuchsia::ui::views::ViewHolderToken view_holder_token; - view_holder_token.value = std::move(view_tokens[0]); - - zx::eventpair view_refs[2]; - status = zx::eventpair::create(0, &view_refs[0], &view_refs[1]); - if (status != ZX_OK) { - FML_LOG(ERROR) << "Creating view refs: " << zx_status_get_string(status); - return false; - } - fuchsia::ui::views::ViewRefControl view_ref_control; - view_refs[0].duplicate(ZX_DEFAULT_EVENTPAIR_RIGHTS & ~ZX_RIGHT_DUPLICATE, - &view_ref_control.reference); - fuchsia::ui::views::ViewRef view_ref; - view_refs[1].duplicate(ZX_RIGHTS_BASIC, &view_ref.reference); - - view_provider->CreateViewWithViewRef(std::move(view_tokens[1]), - std::move(view_ref_control), - std::move(view_ref)); - - view_id = std::move(view_holder_token.value); + zx::channel view_tokens[2]; + fuchsia::ui::views::ViewportCreationToken viewport_creation_token; + fuchsia::ui::views::ViewCreationToken view_creation_token; + status = zx::channel::create(0, &viewport_creation_token.value, + &view_creation_token.value); + if (status != ZX_OK) { + FML_LOG(ERROR) << "Creating view tokens: " << zx_status_get_string(status); + return false; } + fuchsia::ui::app::CreateView2Args create_view_args; + create_view_args.set_view_creation_token(std::move(view_creation_token)); + view_provider->CreateView2(std::move(create_view_args)); + + view_id = std::move(viewport_creation_token.value); + if (view_id) { message->response()->Complete( std::make_unique(std::to_string(view_id.release()) diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view.h b/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view.h index 724780dde7..32995bc7b3 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view.h +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view.h @@ -6,10 +6,10 @@ #define FLUTTER_SHELL_PLATFORM_FUCHSIA_PLATFORM_VIEW_H_ #include +#include #include #include #include -#include #include #include #include @@ -24,6 +24,8 @@ #include #include #include +#include "flutter/fml/memory/weak_ptr.h" +#include "flutter/shell/platform/fuchsia/flutter/external_view_embedder.h" #include "flow/embedded_views.h" #include "flutter/fml/macros.h" @@ -39,20 +41,26 @@ namespace flutter_runner { -using OnEnableWireframe = fit::function; +using OnEnableWireframeCallback = fit::function; using ViewCallback = std::function; -using OnUpdateView = fit::function; -using OnCreateSurface = fit::function()>; -using OnSemanticsNodeUpdate = +using OnUpdateViewCallback = fit::function; +using OnCreateSurfaceCallback = + fit::function()>; +using OnSemanticsNodeUpdateCallback = fit::function; -using OnRequestAnnounce = fit::function; +using OnRequestAnnounceCallback = fit::function; +using OnCreateViewCallback = + fit::function; +using OnDestroyViewCallback = fit::function; + // we use an std::function here because the fit::funtion causes problems with // std:bind since HandleFuchsiaShaderWarmupChannelPlatformMessage takes one of // these as its first argument. -using OnShaderWarmup = std::function&, - std::function, - uint64_t, - uint64_t)>; +using OnShaderWarmupCallback = + std::function&, + std::function, + uint64_t, + uint64_t)>; // PlatformView is the per-engine component residing on the platform thread that // is responsible for all platform specific integrations -- particularly @@ -65,7 +73,6 @@ using OnShaderWarmup = std::function&, class PlatformView : public flutter::PlatformView { public: PlatformView( - bool is_flatland, flutter::PlatformView::Delegate& delegate, flutter::TaskRunners task_runners, fuchsia::ui::views::ViewRef view_ref, @@ -76,13 +83,17 @@ class PlatformView : public flutter::PlatformView { fuchsia::ui::pointer::MouseSourceHandle mouse_source, fuchsia::ui::views::FocuserHandle focuser, fuchsia::ui::views::ViewRefFocusedHandle view_ref_focused, + fuchsia::ui::composition::ParentViewportWatcherHandle + parent_viewport_watcher, fuchsia::ui::pointerinjector::RegistryHandle pointerinjector_registry, - 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, + OnEnableWireframeCallback wireframe_enabled_callback, + OnCreateViewCallback on_create_view_callback, + OnUpdateViewCallback on_update_view_callback, + OnDestroyViewCallback on_destroy_view_callback, + OnCreateSurfaceCallback on_create_surface_callback, + OnSemanticsNodeUpdateCallback on_semantics_node_update_callback, + OnRequestAnnounceCallback on_request_announce_callback, + OnShaderWarmupCallback on_shader_warmup_callback, AwaitVsyncCallback await_vsync_callback, AwaitVsyncForSecondaryCallbackCallback await_vsync_for_secondary_callback_callback, @@ -90,6 +101,15 @@ class PlatformView : public flutter::PlatformView { ~PlatformView() override; + void OnGetLayout(fuchsia::ui::composition::LayoutInfo info); + void OnParentViewportStatus( + fuchsia::ui::composition::ParentViewportStatus status); + void OnChildViewStatus(uint64_t content_id, + fuchsia::ui::composition::ChildViewStatus status); + void OnChildViewViewRef(uint64_t content_id, + uint64_t view_id, + fuchsia::ui::views::ViewRef view_ref); + // |flutter::PlatformView| void SetSemanticsEnabled(bool enabled) override; @@ -97,7 +117,7 @@ class PlatformView : public flutter::PlatformView { std::shared_ptr CreateExternalViewEmbedder() override; - protected: + private: void RegisterPlatformMessageHandlers(); bool OnHandlePointerEvent(const fuchsia::ui::input::PointerEvent& pointer); @@ -135,7 +155,7 @@ class PlatformView : public flutter::PlatformView { // Channel handler for kFuchsiaShaderWarmupChannel. static bool HandleFuchsiaShaderWarmupChannelPlatformMessage( - OnShaderWarmup on_shader_warmup, + OnShaderWarmupCallback on_shader_warmup_callback, std::unique_ptr message); // Channel handler for kFuchsiaInputTestChannel. @@ -146,11 +166,20 @@ class PlatformView : public flutter::PlatformView { bool HandleFuchsiaChildViewChannelPlatformMessage( std::unique_ptr message); - virtual void OnCreateView(ViewCallback on_view_created, - int64_t view_id_raw, - bool hit_testable, - bool focusable) = 0; - virtual void OnDisposeView(int64_t view_id_raw) = 0; + void OnCreateView(ViewCallback on_view_created, + int64_t view_id_raw, + bool hit_testable, + bool focusable); + void OnDisposeView(int64_t view_id_raw); + + // Sends a 'View.viewConnected' platform message over 'flutter/platform_views' + // channel when a view gets created. + void OnChildViewConnected(uint64_t content_id); + + // Sends a 'View.viewDisconnected' platform message over + // 'flutter/platform_views' channel when a view gets destroyed or the child + // view watcher channel of a view closes. + void OnChildViewDisconnected(uint64_t content_id); // Utility function for coordinate massaging. std::array ClampToViewSpace(const float x, const float y) const; @@ -186,12 +215,14 @@ class PlatformView : public flutter::PlatformView { // https://github.com/flutter/flutter/issues/55966 std::set unregistered_channels_; - 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_; + OnEnableWireframeCallback wireframe_enabled_callback_; + OnUpdateViewCallback on_update_view_callback_; + OnCreateSurfaceCallback on_create_surface_callback_; + OnSemanticsNodeUpdateCallback on_semantics_node_update_callback_; + OnRequestAnnounceCallback on_request_announce_callback_; + OnCreateViewCallback on_create_view_callback_; + OnDestroyViewCallback on_destroy_view_callback_; + OnShaderWarmupCallback on_shader_warmup_callback_; AwaitVsyncCallback await_vsync_callback_; AwaitVsyncForSecondaryCallbackCallback await_vsync_for_secondary_callback_callback_; @@ -204,6 +235,22 @@ class PlatformView : public flutter::PlatformView { // Component's service directory. std::shared_ptr dart_application_svc_; + // child_view_ids_ maintains a persistent mapping from Flatland ContentId's to + // flutter view ids, which are really zx_handle_t of ViewCreationToken. + struct ChildViewInfo { + ChildViewInfo(zx_handle_t token, + fuchsia::ui::composition::ChildViewWatcherPtr watcher) + : view_id(token), child_view_watcher(std::move(watcher)) {} + zx_handle_t view_id; + fuchsia::ui::composition::ChildViewWatcherPtr child_view_watcher; + }; + std::unordered_map + child_view_info_; + + fuchsia::ui::composition::ParentViewportWatcherPtr parent_viewport_watcher_; + fuchsia::ui::composition::ParentViewportStatus parent_viewport_status_; + fml::WeakPtrFactory weak_factory_; // Must be the last member. FML_DISALLOW_COPY_AND_ASSIGN(PlatformView); diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view_unittest.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view_unittest.cc index 54a9c7a593..34959fd30a 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view_unittest.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/platform_view_unittest.cc @@ -284,7 +284,8 @@ class PlatformViewBuilder { return *this; } - PlatformViewBuilder& SetEnableWireframeCallback(OnEnableWireframe callback) { + PlatformViewBuilder& SetEnableWireframeCallback( + OnEnableWireframeCallback callback) { wireframe_enabled_callback_ = std::move(callback); return *this; } @@ -309,7 +310,8 @@ class PlatformViewBuilder { return *this; } - PlatformViewBuilder& SetShaderWarmupCallback(OnShaderWarmup callback) { + PlatformViewBuilder& SetShaderWarmupCallback( + OnShaderWarmupCallback callback) { on_shader_warmup_callback_ = std::move(callback); return *this; } @@ -356,14 +358,12 @@ class PlatformViewBuilder { fidl::InterfaceRequest 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_; + OnEnableWireframeCallback wireframe_enabled_callback_; + OnUpdateViewCallback on_update_view_callback_; + OnCreateSurfaceCallback on_create_surface_callback_; + OnSemanticsNodeUpdateCallback on_semantics_node_update_callback_; + OnRequestAnnounceCallback on_request_announce_callback_; + OnShaderWarmupCallback on_shader_warmup_callback_; bool built_{false}; }; @@ -1330,7 +1330,7 @@ TEST_F(PlatformViewTests, OnShaderWarmup) { uint64_t height = 100; std::vector shaders = {"foo.skp", "bar.skp", "baz.skp"}; - OnShaderWarmup on_shader_warmup = + OnShaderWarmupCallback on_shader_warmup_callback = [&](const std::vector& shaders_in, std::function completion_callback, uint64_t width_in, uint64_t height_in) { @@ -1346,7 +1346,7 @@ TEST_F(PlatformViewTests, OnShaderWarmup) { flutter_runner::GfxPlatformView platform_view = PlatformViewBuilder(delegate, std::move(task_runners)) - .SetShaderWarmupCallback(on_shader_warmup) + .SetShaderWarmupCallback(on_shader_warmup_callback) .Build(); std::ostringstream shaders_array_ostream; diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/pointer_injector_delegate.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/pointer_injector_delegate.cc index a1a2da8b89..ba93b9e2bc 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/pointer_injector_delegate.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/pointer_injector_delegate.cc @@ -107,30 +107,6 @@ bool PointerInjectorDelegate::HandlePlatformMessage( return false; } - // For GFX, the viewRef for the view is provided through the platform - // message. For flatland, the viewRef is provided through |OnCreateView|. - std::optional view_ref; - if (!is_flatland_) { - auto view_ref_arg = args.FindMember("viewRef"); - if (!view_ref_arg->value.IsUint64()) { - FML_LOG(ERROR) << "Argument 'viewRef' is not a uint64"; - return false; - } - - zx_handle_t handle = view_ref_arg->value.GetUint64(); - zx_handle_t out_handle; - zx_status_t status = - zx_handle_duplicate(handle, ZX_RIGHT_SAME_RIGHTS, &out_handle); - if (status != ZX_OK) { - FML_LOG(ERROR) << "Argument 'viewRef' is not valid"; - return false; - } - auto ref = fuv_ViewRef({ - .reference = zx::eventpair(out_handle), - }); - view_ref = std::move(ref); - } - auto width = args.FindMember("logicalWidth"); if (!width->value.IsFloat() && !width->value.IsInt()) { FML_LOG(ERROR) << "Argument 'logicalWidth' is not a float"; @@ -155,7 +131,6 @@ bool PointerInjectorDelegate::HandlePlatformMessage( .pointer_id = pointer_id->value.GetUint(), .phase = static_cast(phase->value.GetInt()), .trace_flow_id = trace_flow_id->value.GetUint64(), - .view_ref = std::move(view_ref), .logical_size = {width->value.GetFloat(), height->value.GetFloat()}, .timestamp = timestamp->value.GetInt()}; @@ -282,18 +257,11 @@ void PointerInjectorDelegate::PointerInjectorEndpoint::RegisterInjector( context.set_view(std::move(context_clone)); config.set_context(std::move(context)); - FML_CHECK(request.view_ref.has_value() || view_ref_.has_value()); + FML_CHECK(view_ref_.has_value()); fup_Target target; fuv_ViewRef target_clone; - // GFX. - if (request.view_ref.has_value()) { - fidl::Clone(*request.view_ref, &target_clone); - } - // Flatland. - else { - fidl::Clone(*view_ref_, &target_clone); - } + fidl::Clone(*view_ref_, &target_clone); target.set_view(std::move(target_clone)); config.set_target(std::move(target)); diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/pointer_injector_delegate.h b/engine/src/flutter/shell/platform/fuchsia/flutter/pointer_injector_delegate.h index 1e2666ee83..fd9790b38b 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/pointer_injector_delegate.h +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/pointer_injector_delegate.h @@ -28,13 +28,11 @@ class PointerInjectorDelegate { "View.pointerinjector.inject"; PointerInjectorDelegate(fuchsia::ui::pointerinjector::RegistryHandle registry, - fuchsia::ui::views::ViewRef host_view_ref, - bool is_flatland) + fuchsia::ui::views::ViewRef host_view_ref) : registry_(std::make_shared( registry.Bind())), host_view_ref_(std::make_shared( - std::move(host_view_ref))), - is_flatland_(is_flatland) {} + std::move(host_view_ref))) {} // Handles the following pointer event related platform message requests: // View.Pointerinjector.inject @@ -45,8 +43,7 @@ class PointerInjectorDelegate { fml::RefPtr response); // Adds an endpoint for |view_id| in |valid_views_| for lifecycle management. - // Called in |GFXPlatformView::OnCreateView()| and - // |FlatlandPlatformView::OnChildViewViewRef()|. + // Called in |PlatformView::OnChildViewViewRef()|. void OnCreateView( uint64_t view_id, std::optional view_ref = std::nullopt); @@ -72,10 +69,6 @@ class PointerInjectorDelegate { // |fuchsia.ui.pointerinjector.Event.trace_flow_id|. uint64_t trace_flow_id = 0; - // The view for which dispatch is attempted for the pointer event. For - // flatland views, this value is set as std::nullopt. - std::optional view_ref; - // Logical size of the view's coordinate system. std::array logical_size = {0.f, 0.f}; @@ -153,7 +146,7 @@ class PointerInjectorDelegate { // ViewRef for the main flutter app launching the embedded child views. std::shared_ptr host_view_ref_; - // ViewRef for a flatland view. For GFX this value is set as std::nullopt. + // ViewRef for a flatland view. // Set in |OnCreateView|. std::optional view_ref_; @@ -190,8 +183,6 @@ class PointerInjectorDelegate { // ViewRef for the main flutter app launching the embedded child views. std::shared_ptr host_view_ref_; - bool is_flatland_ = false; - FML_DISALLOW_COPY_AND_ASSIGN(PointerInjectorDelegate); }; diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/pointer_injector_delegate_unittest.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/pointer_injector_delegate_unittest.cc index f38d032063..5153000fc3 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/pointer_injector_delegate_unittest.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/pointer_injector_delegate_unittest.cc @@ -91,13 +91,6 @@ class PlatformMessageBuilder { return *this; } - PlatformMessageBuilder& SetViewRefMaybe(std::optional view_ref) { - if (view_ref.has_value()) { - view_ref_ = std::move(*view_ref); - } - return *this; - } - PlatformMessageBuilder& SetLogicalWidth(float width) { width_ = width; return *this; @@ -221,31 +214,25 @@ class PointerInjectorDelegateTest : public ::testing::Test, fuv_ViewRef host_view_ref_clone; fidl::Clone(host_view_ref_, &host_view_ref_clone); - is_flatland_ = GetParam(); pointer_injector_delegate_ = std::make_unique( - std::move(registry), std::move(host_view_ref_clone), is_flatland_); + std::move(registry), std::move(host_view_ref_clone)); } void CreateView(uint64_t view_id, std::optional view_ref = std::nullopt) { - if (!is_flatland_) { - pointer_injector_delegate_->OnCreateView(view_id); + fuv_ViewRef ref; + if (view_ref.has_value()) { + ref = std::move(*view_ref); } else { - fuv_ViewRef ref; - if (view_ref.has_value()) { - ref = std::move(*view_ref); - } else { - auto view_ref_pair = scenic::ViewRefPair::New(); - ref = std::move(view_ref_pair.view_ref); - } - pointer_injector_delegate_->OnCreateView(view_id, std::move(ref)); + auto view_ref_pair = scenic::ViewRefPair::New(); + ref = std::move(view_ref_pair.view_ref); } + pointer_injector_delegate_->OnCreateView(view_id, std::move(ref)); } std::unique_ptr pointer_injector_delegate_; std::unique_ptr registry_; fuv_ViewRef host_view_ref_; - bool is_flatland_ = false; private: async::Loop loop_; @@ -299,20 +286,8 @@ TEST_P(PointerInjectorDelegateTest, ViewsReceiveInjectedEvents) { for (size_t i = 0; i < num_events; i++) { auto response = FakePlatformMessageResponse::Create(); - // Flatland views do not rely on ViewRef to be passed in the platform - // message. - std::optional view_ref_clone; - if (fuv_ViewRef temp_ref; !is_flatland_) { - fidl::Clone(view_ref_pair.view_ref, &temp_ref); - view_ref_clone = std::move(temp_ref); - } - EXPECT_TRUE(pointer_injector_delegate_->HandlePlatformMessage( - PlatformMessageBuilder() - .SetViewId(view_id) - .SetViewRefMaybe(std::move(view_ref_clone)) - .Build(), - response)); + PlatformMessageBuilder().SetViewId(view_id).Build(), response)); response->ExpectCompleted("[0]"); } @@ -329,20 +304,8 @@ TEST_P(PointerInjectorDelegateTest, ViewsReceiveInjectedEvents) { for (size_t i = 0; i < num_events; i++) { auto response = FakePlatformMessageResponse::Create(); - // Flatland views do not rely on ViewRef to be passed in the platform - // message. - std::optional view_ref_clone; - if (fuv_ViewRef temp_ref; !is_flatland_) { - fidl::Clone(view_ref_pair.view_ref, &temp_ref); - view_ref_clone = std::move(temp_ref); - } - EXPECT_TRUE(pointer_injector_delegate_->HandlePlatformMessage( - PlatformMessageBuilder() - .SetViewId(view_id) - .SetViewRefMaybe(std::move(view_ref_clone)) - .Build(), - response)); + PlatformMessageBuilder().SetViewId(view_id).Build(), response)); response->ExpectCompleted("[0]"); } @@ -370,24 +333,12 @@ TEST_P(PointerInjectorDelegateTest, for (size_t i = 0; i < num_events; i++) { auto response = FakePlatformMessageResponse::Create(); - // Flatland views do not rely on ViewRef to be passed in the platform - // message. - std::optional view_ref_clone; - if (fuv_ViewRef temp_ref; !is_flatland_) { - fidl::Clone(view_ref_pair.view_ref, &temp_ref); - view_ref_clone = std::move(temp_ref); - } - // The platform message is *silently* accepted for non-existent views, in // order to cleanly handle the lifecycle case where the child view is // forcibly killed. By doing so, products avoid "MissingPluginException" // log spam. EXPECT_TRUE(pointer_injector_delegate_->HandlePlatformMessage( - PlatformMessageBuilder() - .SetViewId(view_id_1) - .SetViewRefMaybe(std::move(view_ref_clone)) - .Build(), - response)); + PlatformMessageBuilder().SetViewId(view_id_1).Build(), response)); } } @@ -400,24 +351,12 @@ TEST_P(PointerInjectorDelegateTest, for (size_t i = 0; i < num_events; i++) { auto response = FakePlatformMessageResponse::Create(); - // Flatland views do not rely on ViewRef to be passed in the platform - // message. - std::optional view_ref_clone; - if (fuv_ViewRef temp_ref; !is_flatland_) { - fidl::Clone(view_ref_pair.view_ref, &temp_ref); - view_ref_clone = std::move(temp_ref); - } - // The platform message is *silently* accepted for non-existent views, in // order to cleanly handle the lifecycle case where the child view is // forcibly killed. By doing so, products avoid "MissingPluginException" // log spam. EXPECT_TRUE(pointer_injector_delegate_->HandlePlatformMessage( - PlatformMessageBuilder() - .SetViewId(view_id_2) - .SetViewRefMaybe(std::move(view_ref_clone)) - .Build(), - response)); + PlatformMessageBuilder().SetViewId(view_id_2).Build(), response)); } } @@ -438,19 +377,11 @@ TEST_P(PointerInjectorDelegateTest, ValidRegistrationConfigTest) { auto response = FakePlatformMessageResponse::Create(); auto view_ref_pair = scenic::ViewRefPair::New(); - std::optional view_ref_clone; // Create the view. - if (!is_flatland_) { - CreateView(view_id); - fuv_ViewRef temp_ref; - fidl::Clone(view_ref_pair.view_ref, &temp_ref); - view_ref_clone = std::move(temp_ref); - } else { - fuv_ViewRef view_ref; - fidl::Clone(view_ref_pair.view_ref, &view_ref); - CreateView(view_id, std::move(view_ref)); - } + fuv_ViewRef view_ref; + fidl::Clone(view_ref_pair.view_ref, &view_ref); + CreateView(view_id, std::move(view_ref)); // Inject a platform message. EXPECT_TRUE(pointer_injector_delegate_->HandlePlatformMessage( @@ -461,7 +392,6 @@ TEST_P(PointerInjectorDelegateTest, ValidRegistrationConfigTest) { .SetPhase(phase) .SetPointerId(pointer_id) .SetTraceFlowId(trace_flow_id) - .SetViewRefMaybe(std::move(view_ref_clone)) .SetLogicalWidth(width) .SetLogicalHeight(height) .SetTimestamp(timestamp) @@ -519,19 +449,10 @@ TEST_P(PointerInjectorDelegateTest, ValidPointerEventTest) { auto view_ref_pair = scenic::ViewRefPair::New(); - std::optional view_ref_clone; - // Create the view. - if (!is_flatland_) { - CreateView(view_id); - fuv_ViewRef temp_ref; - fidl::Clone(view_ref_pair.view_ref, &temp_ref); - view_ref_clone = std::move(temp_ref); - } else { - fuv_ViewRef view_ref; - fidl::Clone(view_ref_pair.view_ref, &view_ref); - CreateView(view_id, std::move(view_ref)); - } + fuv_ViewRef view_ref; + fidl::Clone(view_ref_pair.view_ref, &view_ref); + CreateView(view_id, std::move(view_ref)); // Inject a platform message. EXPECT_TRUE(pointer_injector_delegate_->HandlePlatformMessage( @@ -542,7 +463,6 @@ TEST_P(PointerInjectorDelegateTest, ValidPointerEventTest) { .SetPhase(phase) .SetPointerId(pointer_id) .SetTraceFlowId(trace_flow_id) - .SetViewRefMaybe(std::move(view_ref_clone)) .SetLogicalWidth(width) .SetLogicalHeight(height) .SetTimestamp(timestamp) @@ -597,20 +517,8 @@ TEST_P(PointerInjectorDelegateTest, DestroyedViewsDontGetPointerEvents) { for (size_t i = 0; i < num_events; i++) { auto response = FakePlatformMessageResponse::Create(); - // Flatland views do not rely on ViewRef to be passed in the platform - // message. - std::optional view_ref_clone; - if (fuv_ViewRef temp_ref; !is_flatland_) { - fidl::Clone(view_ref_pair.view_ref, &temp_ref); - view_ref_clone = std::move(temp_ref); - } - EXPECT_TRUE(pointer_injector_delegate_->HandlePlatformMessage( - PlatformMessageBuilder() - .SetViewId(view_id) - .SetViewRefMaybe(std::move(view_ref_clone)) - .Build(), - response)); + PlatformMessageBuilder().SetViewId(view_id).Build(), response)); response->ExpectCompleted("[0]"); } @@ -640,19 +548,10 @@ TEST_P(PointerInjectorDelegateTest, ViewsGetPointerEventsInFIFO) { for (size_t i = 0; i < num_events; i++) { auto response = FakePlatformMessageResponse::Create(); - // Flatland views do not rely on ViewRef to be passed in the platform - // message. - std::optional view_ref_clone; - if (fuv_ViewRef temp_ref; !is_flatland_) { - fidl::Clone(view_ref_pair.view_ref, &temp_ref); - view_ref_clone = std::move(temp_ref); - } - EXPECT_TRUE(pointer_injector_delegate_->HandlePlatformMessage( PlatformMessageBuilder() .SetViewId(view_id) .SetPointerId(static_cast(i)) - .SetViewRefMaybe(std::move(view_ref_clone)) .Build(), response)); @@ -697,29 +596,15 @@ TEST_P(PointerInjectorDelegateTest, DeviceRetriesRegisterWhenClosed) { auto response = FakePlatformMessageResponse::Create(); auto response_2 = FakePlatformMessageResponse::Create(); - std::optional view_ref_clone; - std::optional view_ref_clone_2; - // Create the view. - if (!is_flatland_) { - CreateView(view_id); - fuv_ViewRef temp_ref; - fuv_ViewRef temp_ref_2; - fidl::Clone(view_ref_pair.view_ref, &temp_ref); - fidl::Clone(view_ref_pair.view_ref, &temp_ref_2); - view_ref_clone = std::move(temp_ref); - view_ref_clone_2 = std::move(temp_ref_2); - } else { - fuv_ViewRef view_ref; - fidl::Clone(view_ref_pair.view_ref, &view_ref); - CreateView(view_id, std::move(view_ref)); - } + fuv_ViewRef view_ref; + fidl::Clone(view_ref_pair.view_ref, &view_ref); + CreateView(view_id, std::move(view_ref)); EXPECT_TRUE(pointer_injector_delegate_->HandlePlatformMessage( PlatformMessageBuilder() .SetViewId(view_id) .SetPointerId(pointer_id) - .SetViewRefMaybe(std::move(view_ref_clone)) .Build(), response)); @@ -741,7 +626,6 @@ TEST_P(PointerInjectorDelegateTest, DeviceRetriesRegisterWhenClosed) { PlatformMessageBuilder() .SetViewId(view_id) .SetPointerId(pointer_id) - .SetViewRefMaybe(std::move(view_ref_clone_2)) .Build(), response_2)); diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/software_surface.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/software_surface.cc index 802c3ccda0..d776cd7d50 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/software_surface.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/software_surface.cc @@ -46,16 +46,12 @@ uint32_t BytesPerRow(const fuchsia::sysmem::SingleBufferSettings& settings, } // namespace -uint32_t SoftwareSurface::sNextBufferId = 1; // 0 is invalid; start at 1. - SoftwareSurface::SoftwareSurface( fuchsia::sysmem::AllocatorSyncPtr& sysmem_allocator, fuchsia::ui::composition::AllocatorPtr& flatland_allocator, - scenic::Session* session, const SkISize& size) - : session_(session), wait_for_surface_read_finished_(this) { - FML_CHECK((session_ || flatland_allocator.is_bound()) && - !(session_ && flatland_allocator.is_bound())); + : wait_for_surface_read_finished_(this) { + FML_CHECK(flatland_allocator.is_bound()); if (!SetupSkiaSurface(sysmem_allocator, flatland_allocator, size)) { FML_LOG(ERROR) << "Could not create render surface."; @@ -67,14 +63,6 @@ SoftwareSurface::SoftwareSurface( return; } - if (session) { - if (image_id_ == 0) { - image_id_ = session->AllocResourceId(); - } - session->Enqueue(scenic::NewCreateImage2Cmd( - image_id_, sk_surface_->width(), sk_surface_->height(), buffer_id_, 0)); - } - wait_for_surface_read_finished_.set_object(release_event_.get()); wait_for_surface_read_finished_.set_trigger(ZX_EVENT_SIGNALED); Reset(); @@ -83,16 +71,7 @@ SoftwareSurface::SoftwareSurface( } SoftwareSurface::~SoftwareSurface() { - if (session_) { - if (image_id_) { - session_->Enqueue(scenic::NewReleaseResourceCmd(image_id_)); - } - if (buffer_id_) { - session_->DeregisterBufferCollection(buffer_id_); - } - } else { - release_image_callback_(); - } + release_image_callback_(); wait_for_surface_read_finished_.Cancel(); wait_for_surface_read_finished_.set_object(ZX_HANDLE_INVALID); } @@ -160,42 +139,34 @@ bool SoftwareSurface::SetupSkiaSurface( } auto scenic_token = std::move(duplicate_tokens[0]); - // Register the sysmem token with flatland (or scenic's legacy gfx interface). + // Register the sysmem token with flatland. // // This binds the sysmem token to a composition token, which is used later // to associate the rendering surface with a specific flatland Image. - // - // Under gfx, scenic uses an integral `buffer_id` instead of the composition - // token. - if (session_) { - buffer_id_ = sNextBufferId++; - session_->RegisterBufferCollection(buffer_id_, std::move(scenic_token)); - } else { - fuchsia::ui::composition::BufferCollectionExportToken export_token; - zx_status_t token_create_status = - zx::eventpair::create(0, &export_token.value, &import_token_.value); - if (token_create_status != ZX_OK) { - FML_LOG(ERROR) << "Failed to create flatland export token: " - << zx_status_get_string(token_create_status); - return false; - } - - fuchsia::ui::composition::RegisterBufferCollectionArgs args; - args.set_export_token(std::move(export_token)); - args.set_buffer_collection_token(std::move(scenic_token)); - args.set_usage( - fuchsia::ui::composition::RegisterBufferCollectionUsage::DEFAULT); - flatland_allocator->RegisterBufferCollection( - std::move(args), - [](fuchsia::ui::composition::Allocator_RegisterBufferCollection_Result - result) { - if (result.is_err()) { - FML_LOG(ERROR) - << "RegisterBufferCollection call to Scenic Allocator failed."; - } - }); + fuchsia::ui::composition::BufferCollectionExportToken export_token; + zx_status_t token_create_status = + zx::eventpair::create(0, &export_token.value, &import_token_.value); + if (token_create_status != ZX_OK) { + FML_LOG(ERROR) << "Failed to create flatland export token: " + << zx_status_get_string(token_create_status); + return false; } + fuchsia::ui::composition::RegisterBufferCollectionArgs args; + args.set_export_token(std::move(export_token)); + args.set_buffer_collection_token(std::move(scenic_token)); + args.set_usage( + fuchsia::ui::composition::RegisterBufferCollectionUsage::DEFAULT); + flatland_allocator->RegisterBufferCollection( + std::move(args), + [](fuchsia::ui::composition::Allocator_RegisterBufferCollection_Result + result) { + if (result.is_err()) { + FML_LOG(ERROR) + << "RegisterBufferCollection call to Scenic Allocator failed."; + } + }); + // Acquire flutter's local handle to the sysmem buffer. fuchsia::sysmem::BufferCollectionSyncPtr buffer_collection; zx_status_t bind_status = sysmem_allocator->BindSharedCollection( @@ -309,7 +280,6 @@ bool SoftwareSurface::SetupSkiaSurface( void SoftwareSurface::SetImageId(uint32_t image_id) { FML_CHECK(image_id_ == 0); - FML_CHECK(!session_); image_id_ = image_id; } @@ -323,28 +293,24 @@ sk_sp SoftwareSurface::GetSkiaSurface() const { fuchsia::ui::composition::BufferCollectionImportToken SoftwareSurface::GetBufferCollectionImportToken() { - FML_CHECK(!session_); fuchsia::ui::composition::BufferCollectionImportToken import_dup; import_token_.value.duplicate(ZX_RIGHT_SAME_RIGHTS, &import_dup.value); return import_dup; } zx::event SoftwareSurface::GetAcquireFence() { - FML_CHECK(!session_); zx::event fence; acquire_event_.duplicate(ZX_RIGHT_SAME_RIGHTS, &fence); return fence; } zx::event SoftwareSurface::GetReleaseFence() { - FML_CHECK(!session_); zx::event fence; release_event_.duplicate(ZX_RIGHT_SAME_RIGHTS, &fence); return fence; } void SoftwareSurface::SetReleaseImageCallback( ReleaseImageCallback release_image_callback) { - FML_CHECK(!session_); release_image_callback_ = release_image_callback; } @@ -353,16 +319,6 @@ size_t SoftwareSurface::AdvanceAndGetAge() { } bool SoftwareSurface::FlushSessionAcquireAndReleaseEvents() { - if (session_) { - zx::event acquire, release; - if (acquire_event_.duplicate(ZX_RIGHT_SAME_RIGHTS, &acquire) != ZX_OK || - release_event_.duplicate(ZX_RIGHT_SAME_RIGHTS, &release) != ZX_OK) { - return false; - } - session_->EnqueueAcquireFence(std::move(acquire)); - session_->EnqueueReleaseFence(std::move(release)); - } - age_ = 0; return true; } diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/software_surface.h b/engine/src/flutter/shell/platform/fuchsia/flutter/software_surface.h index c1af8fb715..b2bcee0efd 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/software_surface.h +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/software_surface.h @@ -28,7 +28,6 @@ class SoftwareSurface final : public SurfaceProducerSurface { public: SoftwareSurface(fuchsia::sysmem::AllocatorSyncPtr& sysmem_allocator, fuchsia::ui::composition::AllocatorPtr& flatland_allocator, - scenic::Session* session, const SkISize& size); ~SoftwareSurface() override; @@ -88,11 +87,7 @@ class SoftwareSurface final : public SurfaceProducerSurface { bool CreateFences(); void Reset(); - - static uint32_t sNextBufferId; // For legacy gfx; counter for `buffer_id_`. - - scenic::Session* session_; // Legacy gfx API endpoint. - scenic::ResourceId image_id_{0}; // Legacy gfx image ID. + uint32_t image_id_ = 0; sk_sp sk_surface_; @@ -105,12 +100,11 @@ class SoftwareSurface final : public SurfaceProducerSurface { // `SoftwareSurfaceProducer` to re-use the surface. std::function surface_read_finished_callback_; // Called when the surface is destroyed, to allow - // `FlatlandExternalViewEmbedder` to release the associated Flatland image. + // `ExternalViewEmbedder` to release the associated Flatland image. ReleaseImageCallback release_image_callback_; // Allows Flatland to associate this surface with a Flatland Image. fuchsia::ui::composition::BufferCollectionImportToken import_token_; - uint32_t buffer_id_{0}; // Legacy gfx version of the import_token_. zx::event acquire_event_; // Signals to scenic that writing is finished. zx::event release_event_; // Signalled by scenic that reading is finished. zx::vmo surface_vmo_; // VMO that is backing the surface memory. diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/software_surface_producer.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/software_surface_producer.cc index 4246ed5653..a7be9e3bb2 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/software_surface_producer.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/software_surface_producer.cc @@ -47,9 +47,7 @@ zx_koid_t GetCurrentProcessId() { } // namespace -SoftwareSurfaceProducer::SoftwareSurfaceProducer( - scenic::Session* scenic_session) - : scenic_session_(scenic_session) { +SoftwareSurfaceProducer::SoftwareSurfaceProducer() { zx_status_t status = fdio_service_connect( "/svc/fuchsia.sysmem.Allocator", sysmem_allocator_.NewRequest().TakeChannel().release()); @@ -57,12 +55,10 @@ SoftwareSurfaceProducer::SoftwareSurfaceProducer( GetCurrentProcessId()); FML_DCHECK(status == ZX_OK); - if (!scenic_session_) { - status = fdio_service_connect( - "/svc/fuchsia.ui.composition.Allocator", - flatland_allocator_.NewRequest().TakeChannel().release()); - FML_DCHECK(status == ZX_OK); - } + status = fdio_service_connect( + "/svc/fuchsia.ui.composition.Allocator", + flatland_allocator_.NewRequest().TakeChannel().release()); + FML_DCHECK(status == ZX_OK); valid_ = true; } @@ -152,8 +148,8 @@ std::unique_ptr SoftwareSurfaceProducer::CreateSurface( const SkISize& size) { TRACE_EVENT2("flutter", "SoftwareSurfacePool::CreateSurface", "width", size.width(), "height", size.height()); - auto surface = std::make_unique( - sysmem_allocator_, flatland_allocator_, scenic_session_, size); + auto surface = std::make_unique(sysmem_allocator_, + flatland_allocator_, size); if (!surface->IsValid()) { FML_LOG(ERROR) << "Created surface is invalid."; return nullptr; diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/software_surface_producer.h b/engine/src/flutter/shell/platform/fuchsia/flutter/software_surface_producer.h index 9e0ddbcf27..e18bc5a05c 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/software_surface_producer.h +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/software_surface_producer.h @@ -6,8 +6,6 @@ #include #include -#include -#include #include @@ -24,7 +22,7 @@ class SoftwareSurfaceProducer final : public SurfaceProducer { // If a surface doesn't get used for 3 or more generations, we discard it. static constexpr int kMaxSurfaceAge = 3; - explicit SoftwareSurfaceProducer(scenic::Session* scenic_session); + explicit SoftwareSurfaceProducer(); ~SoftwareSurfaceProducer() override; bool IsValid() const { return valid_; } @@ -55,7 +53,6 @@ class SoftwareSurfaceProducer final : public SurfaceProducer { void TraceStats(); - scenic::Session* scenic_session_; // Legacy gfx API endpoint. fuchsia::sysmem::AllocatorSyncPtr sysmem_allocator_; fuchsia::ui::composition::AllocatorPtr flatland_allocator_; diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/flatland_external_view_embedder_unittests.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/external_view_embedder_unittests.cc similarity index 96% rename from engine/src/flutter/shell/platform/fuchsia/flutter/tests/flatland_external_view_embedder_unittests.cc rename to engine/src/flutter/shell/platform/fuchsia/flutter/tests/external_view_embedder_unittests.cc index 58af0ccb88..a9d28b9191 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/flatland_external_view_embedder_unittests.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/external_view_embedder_unittests.cc @@ -2,7 +2,7 @@ // 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/flatland_external_view_embedder.h" +#include "flutter/shell/platform/fuchsia/flutter/external_view_embedder.h" #include #include @@ -321,7 +321,7 @@ fuchsia::ui::composition::OnNextFrameBeginValues WithPresentCredits( return values; } -void DrawSimpleFrame(FlatlandExternalViewEmbedder& external_view_embedder, +void DrawSimpleFrame(ExternalViewEmbedder& external_view_embedder, SkISize frame_size, float frame_dpr, std::function draw_callback) { @@ -344,7 +344,7 @@ void DrawSimpleFrame(FlatlandExternalViewEmbedder& external_view_embedder, } void DrawFrameWithView( - FlatlandExternalViewEmbedder& external_view_embedder, + ExternalViewEmbedder& external_view_embedder, SkISize frame_size, float frame_dpr, int view_id, @@ -376,14 +376,14 @@ void DrawFrameWithView( }; // namespace -class FlatlandExternalViewEmbedderTest : public ::testing::Test { +class ExternalViewEmbedderTest : public ::testing::Test { protected: - FlatlandExternalViewEmbedderTest() + ExternalViewEmbedderTest() : session_subloop_(loop_.StartNewLoop()), flatland_connection_(CreateFlatlandConnection()), fake_surface_producer_( std::make_shared(CreateFlatlandAllocator())) {} - ~FlatlandExternalViewEmbedderTest() override = default; + ~ExternalViewEmbedderTest() override = default; async::TestLoop& loop() { return loop_; } @@ -435,7 +435,7 @@ class FlatlandExternalViewEmbedderTest : public ::testing::Test { std::shared_ptr fake_surface_producer_; }; -TEST_F(FlatlandExternalViewEmbedderTest, RootScene) { +TEST_F(ExternalViewEmbedderTest, RootScene) { fuchsia::ui::composition::ParentViewportWatcherPtr parent_viewport_watcher; fuchsia::ui::views::ViewportCreationToken viewport_creation_token; fuchsia::ui::views::ViewCreationToken view_creation_token; @@ -446,7 +446,7 @@ TEST_F(FlatlandExternalViewEmbedderTest, RootScene) { auto view_ref_pair = scenic::ViewRefPair::New(); view_ref_pair.view_ref.Clone(&view_ref); - FlatlandExternalViewEmbedder external_view_embedder( + ExternalViewEmbedder external_view_embedder( std::move(view_creation_token), fuchsia::ui::views::ViewIdentityOnCreation{ .view_ref = std::move(view_ref_pair.view_ref), @@ -470,7 +470,7 @@ TEST_F(FlatlandExternalViewEmbedderTest, RootScene) { view_ref)); } -TEST_F(FlatlandExternalViewEmbedderTest, SimpleScene) { +TEST_F(ExternalViewEmbedderTest, SimpleScene) { fuchsia::ui::composition::ParentViewportWatcherPtr parent_viewport_watcher; fuchsia::ui::views::ViewportCreationToken viewport_creation_token; fuchsia::ui::views::ViewCreationToken view_creation_token; @@ -481,9 +481,9 @@ TEST_F(FlatlandExternalViewEmbedderTest, SimpleScene) { auto view_ref_pair = scenic::ViewRefPair::New(); view_ref_pair.view_ref.Clone(&view_ref); - // Create the `FlatlandExternalViewEmbedder` and pump the message loop until + // Create the `ExternalViewEmbedder` and pump the message loop until // the initial scene graph is setup. - FlatlandExternalViewEmbedder external_view_embedder( + ExternalViewEmbedder external_view_embedder( std::move(view_creation_token), fuchsia::ui::views::ViewIdentityOnCreation{ .view_ref = std::move(view_ref_pair.view_ref), @@ -542,7 +542,7 @@ TEST_F(FlatlandExternalViewEmbedderTest, SimpleScene) { fuchsia::ui::composition::HitTestInteraction::DEFAULT)})})); } -TEST_F(FlatlandExternalViewEmbedderTest, SceneWithOneView) { +TEST_F(ExternalViewEmbedderTest, SceneWithOneView) { fuchsia::ui::composition::ParentViewportWatcherPtr parent_viewport_watcher; fuchsia::ui::views::ViewportCreationToken viewport_creation_token; fuchsia::ui::views::ViewCreationToken view_creation_token; @@ -553,9 +553,9 @@ TEST_F(FlatlandExternalViewEmbedderTest, SceneWithOneView) { auto view_ref_pair = scenic::ViewRefPair::New(); view_ref_pair.view_ref.Clone(&view_ref); - // Create the `FlatlandExternalViewEmbedder` and pump the message loop until + // Create the `ExternalViewEmbedder` and pump the message loop until // the initial scene graph is setup. - FlatlandExternalViewEmbedder external_view_embedder( + ExternalViewEmbedder external_view_embedder( std::move(view_creation_token), fuchsia::ui::views::ViewIdentityOnCreation{ .view_ref = std::move(view_ref_pair.view_ref), @@ -766,7 +766,7 @@ TEST_F(FlatlandExternalViewEmbedderTest, SceneWithOneView) { fuchsia::ui::composition::HitTestInteraction::DEFAULT)})})); } -TEST_F(FlatlandExternalViewEmbedderTest, SceneWithOneClippedView) { +TEST_F(ExternalViewEmbedderTest, SceneWithOneClippedView) { fuchsia::ui::composition::ParentViewportWatcherPtr parent_viewport_watcher; fuchsia::ui::views::ViewportCreationToken viewport_creation_token; fuchsia::ui::views::ViewCreationToken view_creation_token; @@ -777,9 +777,9 @@ TEST_F(FlatlandExternalViewEmbedderTest, SceneWithOneClippedView) { auto view_ref_pair = scenic::ViewRefPair::New(); view_ref_pair.view_ref.Clone(&view_ref); - // Create the `FlatlandExternalViewEmbedder` and pump the message loop until + // Create the `ExternalViewEmbedder` and pump the message loop until // the initial scene graph is setup. - FlatlandExternalViewEmbedder external_view_embedder( + ExternalViewEmbedder external_view_embedder( std::move(view_creation_token), fuchsia::ui::views::ViewIdentityOnCreation{ .view_ref = std::move(view_ref_pair.view_ref), @@ -1018,7 +1018,7 @@ TEST_F(FlatlandExternalViewEmbedderTest, SceneWithOneClippedView) { fuchsia::ui::composition::HitTestInteraction::DEFAULT)})})); } -TEST_F(FlatlandExternalViewEmbedderTest, SceneWithOneView_NoOverlay) { +TEST_F(ExternalViewEmbedderTest, SceneWithOneView_NoOverlay) { fuchsia::ui::composition::ParentViewportWatcherPtr parent_viewport_watcher; fuchsia::ui::views::ViewportCreationToken viewport_creation_token; fuchsia::ui::views::ViewCreationToken view_creation_token; @@ -1029,9 +1029,9 @@ TEST_F(FlatlandExternalViewEmbedderTest, SceneWithOneView_NoOverlay) { auto view_ref_pair = scenic::ViewRefPair::New(); view_ref_pair.view_ref.Clone(&view_ref); - // Create the `FlatlandExternalViewEmbedder` and pump the message loop until + // Create the `ExternalViewEmbedder` and pump the message loop until // the initial scene graph is setup. - FlatlandExternalViewEmbedder external_view_embedder( + ExternalViewEmbedder external_view_embedder( std::move(view_creation_token), fuchsia::ui::views::ViewIdentityOnCreation{ .view_ref = std::move(view_ref_pair.view_ref), @@ -1191,8 +1191,7 @@ TEST_F(FlatlandExternalViewEmbedderTest, SceneWithOneView_NoOverlay) { fuchsia::ui::composition::HitTestInteraction::DEFAULT)})})); } -TEST_F(FlatlandExternalViewEmbedderTest, - SceneWithOneView_DestroyBeforeDrawing) { +TEST_F(ExternalViewEmbedderTest, SceneWithOneView_DestroyBeforeDrawing) { fuchsia::ui::composition::ParentViewportWatcherPtr parent_viewport_watcher; fuchsia::ui::views::ViewportCreationToken viewport_creation_token; fuchsia::ui::views::ViewCreationToken view_creation_token; @@ -1203,9 +1202,9 @@ TEST_F(FlatlandExternalViewEmbedderTest, auto view_ref_pair = scenic::ViewRefPair::New(); view_ref_pair.view_ref.Clone(&view_ref); - // Create the `FlatlandExternalViewEmbedder` and pump the message loop until + // Create the `ExternalViewEmbedder` and pump the message loop until // the initial scene graph is setup. - FlatlandExternalViewEmbedder external_view_embedder( + ExternalViewEmbedder external_view_embedder( std::move(view_creation_token), fuchsia::ui::views::ViewIdentityOnCreation{ .view_ref = std::move(view_ref_pair.view_ref), @@ -1342,7 +1341,7 @@ TEST_F(FlatlandExternalViewEmbedderTest, // This test case exercises the scenario in which the view contains two disjoint // regions with painted content; we should generate two separate hit regions // matching the bounds of the painted regions in this case. -TEST_F(FlatlandExternalViewEmbedderTest, SimpleScene_DisjointHitRegions) { +TEST_F(ExternalViewEmbedderTest, SimpleScene_DisjointHitRegions) { fuchsia::ui::composition::ParentViewportWatcherPtr parent_viewport_watcher; fuchsia::ui::views::ViewportCreationToken viewport_creation_token; fuchsia::ui::views::ViewCreationToken view_creation_token; @@ -1353,9 +1352,9 @@ TEST_F(FlatlandExternalViewEmbedderTest, SimpleScene_DisjointHitRegions) { auto view_ref_pair = scenic::ViewRefPair::New(); view_ref_pair.view_ref.Clone(&view_ref); - // Create the `FlatlandExternalViewEmbedder` and pump the message loop until + // Create the `ExternalViewEmbedder` and pump the message loop until // the initial scene graph is setup. - FlatlandExternalViewEmbedder external_view_embedder( + ExternalViewEmbedder external_view_embedder( std::move(view_creation_token), fuchsia::ui::views::ViewIdentityOnCreation{ .view_ref = std::move(view_ref_pair.view_ref), @@ -1435,7 +1434,7 @@ TEST_F(FlatlandExternalViewEmbedderTest, SimpleScene_DisjointHitRegions) { // overlapping regions with painted content; we should generate one hit // region matching the union of the bounds of the two painted regions in // this case. -TEST_F(FlatlandExternalViewEmbedderTest, SimpleScene_OverlappingHitRegions) { +TEST_F(ExternalViewEmbedderTest, SimpleScene_OverlappingHitRegions) { fuchsia::ui::composition::ParentViewportWatcherPtr parent_viewport_watcher; fuchsia::ui::views::ViewportCreationToken viewport_creation_token; fuchsia::ui::views::ViewCreationToken view_creation_token; @@ -1446,9 +1445,9 @@ TEST_F(FlatlandExternalViewEmbedderTest, SimpleScene_OverlappingHitRegions) { auto view_ref_pair = scenic::ViewRefPair::New(); view_ref_pair.view_ref.Clone(&view_ref); - // Create the `FlatlandExternalViewEmbedder` and pump the message loop until + // Create the `ExternalViewEmbedder` and pump the message loop until // the initial scene graph is setup. - FlatlandExternalViewEmbedder external_view_embedder( + ExternalViewEmbedder external_view_embedder( std::move(view_creation_token), fuchsia::ui::views::ViewIdentityOnCreation{ .view_ref = std::move(view_ref_pair.view_ref), @@ -1517,7 +1516,7 @@ TEST_F(FlatlandExternalViewEmbedderTest, SimpleScene_OverlappingHitRegions) { fuchsia::ui::composition::HitTestInteraction::DEFAULT)})})); } -TEST_F(FlatlandExternalViewEmbedderTest, ViewportCoveredWithInputInterceptor) { +TEST_F(ExternalViewEmbedderTest, ViewportCoveredWithInputInterceptor) { fuchsia::ui::composition::ParentViewportWatcherPtr parent_viewport_watcher; fuchsia::ui::views::ViewportCreationToken viewport_creation_token; fuchsia::ui::views::ViewCreationToken view_creation_token; @@ -1528,9 +1527,9 @@ TEST_F(FlatlandExternalViewEmbedderTest, ViewportCoveredWithInputInterceptor) { auto view_ref_pair = scenic::ViewRefPair::New(); view_ref_pair.view_ref.Clone(&view_ref); - // Create the `FlatlandExternalViewEmbedder` and pump the message loop until + // Create the `ExternalViewEmbedder` and pump the message loop until // the initial scene graph is setup. - FlatlandExternalViewEmbedder external_view_embedder( + ExternalViewEmbedder external_view_embedder( std::move(view_creation_token), fuchsia::ui::views::ViewIdentityOnCreation{ .view_ref = std::move(view_ref_pair.view_ref), diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/fakes/scenic/BUILD.gn b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/fakes/scenic/BUILD.gn index f1c40fd448..4ca6cf0290 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/fakes/scenic/BUILD.gn +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/fakes/scenic/BUILD.gn @@ -12,18 +12,12 @@ source_set("scenic") { "fake_flatland.h", "fake_flatland_types.cc", "fake_flatland_types.h", - "fake_resources.cc", - "fake_resources.h", - "fake_session.cc", - "fake_session.h", ] public_deps = [ "//build/fuchsia/fidl:fuchsia.images", "//build/fuchsia/fidl:fuchsia.scenic.scheduling", "//build/fuchsia/fidl:fuchsia.ui.composition", - "//build/fuchsia/fidl:fuchsia.ui.gfx", - "//build/fuchsia/fidl:fuchsia.ui.scenic", "//build/fuchsia/fidl:fuchsia.ui.views", "//build/fuchsia/pkg:async-cpp", "//build/fuchsia/pkg:async-testing", diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/flatland_platform_view_unittest.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/platform_view_unittest.cc similarity index 92% rename from engine/src/flutter/shell/platform/fuchsia/flutter/tests/flatland_platform_view_unittest.cc rename to engine/src/flutter/shell/platform/fuchsia/flutter/tests/platform_view_unittest.cc index ff4347015e..2869c15129 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/flatland_platform_view_unittest.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/platform_view_unittest.cc @@ -25,7 +25,7 @@ #include "flutter/lib/ui/window/pointer_data.h" #include "flutter/lib/ui/window/viewport_metrics.h" #include "flutter/shell/common/context_options.h" -#include "flutter/shell/platform/fuchsia/flutter/flatland_platform_view.h" +#include "flutter/shell/platform/fuchsia/flutter/platform_view.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -383,7 +383,8 @@ class PlatformViewBuilder { return *this; } - PlatformViewBuilder& SetEnableWireframeCallback(OnEnableWireframe callback) { + PlatformViewBuilder& SetEnableWireframeCallback( + OnEnableWireframeCallback callback) { wireframe_enabled_callback_ = std::move(callback); return *this; } @@ -395,36 +396,38 @@ class PlatformViewBuilder { return *this; } - PlatformViewBuilder& SetCreateViewCallback(OnCreateFlatlandView callback) { + PlatformViewBuilder& SetCreateViewCallback(OnCreateViewCallback callback) { on_create_view_callback_ = std::move(callback); return *this; } - PlatformViewBuilder& SetDestroyViewCallback(OnDestroyFlatlandView callback) { + PlatformViewBuilder& SetDestroyViewCallback(OnDestroyViewCallback callback) { on_destroy_view_callback_ = std::move(callback); return *this; } - PlatformViewBuilder& SetUpdateViewCallback(OnUpdateView callback) { + PlatformViewBuilder& SetUpdateViewCallback(OnUpdateViewCallback callback) { on_update_view_callback_ = std::move(callback); return *this; } - PlatformViewBuilder& SetCreateSurfaceCallback(OnCreateSurface callback) { + PlatformViewBuilder& SetCreateSurfaceCallback( + OnCreateSurfaceCallback callback) { on_create_surface_callback_ = std::move(callback); return *this; } - PlatformViewBuilder& SetShaderWarmupCallback(OnShaderWarmup callback) { + PlatformViewBuilder& SetShaderWarmupCallback( + OnShaderWarmupCallback callback) { on_shader_warmup_callback_ = std::move(callback); return *this; } // Once Build is called, the instance is no longer usable. - FlatlandPlatformView Build() { + PlatformView Build() { EXPECT_FALSE(std::exchange(built_, true)) << "Build() was already called, this builder is good for one use only."; - return FlatlandPlatformView( + return PlatformView( 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_), @@ -459,16 +462,16 @@ class PlatformViewBuilder { fuchsia::ui::views::FocuserHandle focuser_; fuchsia::ui::pointerinjector::RegistryHandle pointerinjector_registry_; fit::closure on_session_listener_error_callback_; - OnEnableWireframe wireframe_enabled_callback_; + OnEnableWireframeCallback wireframe_enabled_callback_; fuchsia::ui::composition::ParentViewportWatcherHandle parent_viewport_watcher_; - OnCreateFlatlandView on_create_view_callback_; - OnDestroyFlatlandView on_destroy_view_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_callback_; + OnCreateViewCallback on_create_view_callback_; + OnDestroyViewCallback on_destroy_view_callback_; + OnUpdateViewCallback on_update_view_callback_; + OnCreateSurfaceCallback on_create_surface_callback_; + OnSemanticsNodeUpdateCallback on_semantics_node_update_callback_; + OnRequestAnnounceCallback on_request_announce_callback_; + OnShaderWarmupCallback on_shader_warmup_callback_; bool built_{false}; }; @@ -490,9 +493,9 @@ void UnpackPointerPacket(std::vector& output, // NOLINT } // namespace -class FlatlandPlatformViewTests : public ::testing::Test { +class PlatformViewTests : public ::testing::Test { protected: - FlatlandPlatformViewTests() : loop_(&kAsyncLoopConfigAttachToCurrentThread) {} + PlatformViewTests() : loop_(&kAsyncLoopConfigAttachToCurrentThread) {} async_dispatcher_t* dispatcher() { return loop_.dispatcher(); } @@ -535,12 +538,12 @@ class FlatlandPlatformViewTests : public ::testing::Test { std::vector> child_view_watchers_; - FML_DISALLOW_COPY_AND_ASSIGN(FlatlandPlatformViewTests); + FML_DISALLOW_COPY_AND_ASSIGN(PlatformViewTests); }; // 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(FlatlandPlatformViewTests, InvalidPlatformMessageRequest) { +TEST_F(PlatformViewTests, InvalidPlatformMessageRequest) { MockPlatformViewDelegate delegate; flutter::TaskRunners task_runners = flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr); @@ -602,7 +605,7 @@ TEST_F(FlatlandPlatformViewTests, InvalidPlatformMessageRequest) { // This test makes sure that the PlatformView correctly returns a Surface // instance that can surface the provided gr_context and external_view_embedder. -TEST_F(FlatlandPlatformViewTests, CreateSurfaceTest) { +TEST_F(PlatformViewTests, CreateSurfaceTest) { MockPlatformViewDelegate delegate; flutter::TaskRunners task_runners = @@ -641,7 +644,7 @@ TEST_F(FlatlandPlatformViewTests, CreateSurfaceTest) { // This test makes sure that the PlatformView correctly registers Scenic // MetricsEvents sent to it via FIDL, correctly parses the metrics it receives, // and calls the SetViewportMetrics callback with the appropriate parameters. -TEST_F(FlatlandPlatformViewTests, SetViewportMetrics) { +TEST_F(PlatformViewTests, SetViewportMetrics) { constexpr float kDPR = 2; constexpr uint32_t width = 640; constexpr uint32_t height = 480; @@ -669,7 +672,7 @@ TEST_F(FlatlandPlatformViewTests, SetViewportMetrics) { // This test makes sure that the PlatformView correctly registers semantics // settings changes applied to it and calls the SetSemanticsEnabled / // SetAccessibilityFeatures callbacks with the appropriate parameters. -TEST_F(FlatlandPlatformViewTests, ChangesAccessibilitySettings) { +TEST_F(PlatformViewTests, ChangesAccessibilitySettings) { MockPlatformViewDelegate delegate; flutter::TaskRunners task_runners = flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr); @@ -697,7 +700,7 @@ TEST_F(FlatlandPlatformViewTests, ChangesAccessibilitySettings) { // This test makes sure that the PlatformView forwards messages on the // "flutter/platform_views" channel for EnableWireframe. -TEST_F(FlatlandPlatformViewTests, EnableWireframeTest) { +TEST_F(PlatformViewTests, EnableWireframeTest) { MockPlatformViewDelegate delegate; flutter::TaskRunners task_runners = flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr); @@ -741,7 +744,7 @@ TEST_F(FlatlandPlatformViewTests, EnableWireframeTest) { // This test makes sure that the PlatformView forwards messages on the // "flutter/platform_views" channel for Createview. -TEST_F(FlatlandPlatformViewTests, CreateViewTest) { +TEST_F(PlatformViewTests, CreateViewTest) { MockPlatformViewDelegate delegate; const uint64_t view_id = 42; flutter::TaskRunners task_runners = @@ -760,8 +763,8 @@ TEST_F(FlatlandPlatformViewTests, CreateViewTest) { auto CreateViewCallback = [&create_view_called, this]( int64_t view_id, flutter_runner::ViewCallback on_view_created, - flutter_runner::FlatlandViewCreatedCallback on_view_bound, - bool hit_testable, bool focusable) { + flutter_runner::ViewCreatedCallback on_view_bound, bool hit_testable, + bool focusable) { create_view_called = true; on_view_created(); fuchsia::ui::composition::ContentId content_id; @@ -817,7 +820,7 @@ TEST_F(FlatlandPlatformViewTests, CreateViewTest) { // This test makes sure that the PlatformView forwards messages on the // "flutter/platform_views" channel for UpdateView. -TEST_F(FlatlandPlatformViewTests, UpdateViewTest) { +TEST_F(PlatformViewTests, UpdateViewTest) { MockPlatformViewDelegate delegate; flutter::TaskRunners task_runners = flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr); @@ -932,7 +935,7 @@ TEST_F(FlatlandPlatformViewTests, UpdateViewTest) { // This test makes sure that the PlatformView forwards messages on the // "flutter/platform_views" channel for DestroyView. -TEST_F(FlatlandPlatformViewTests, DestroyViewTest) { +TEST_F(PlatformViewTests, DestroyViewTest) { MockPlatformViewDelegate delegate; const uint64_t view_id = 42; @@ -947,26 +950,25 @@ TEST_F(FlatlandPlatformViewTests, DestroyViewTest) { bool destroy_view_called = false; - auto on_destroy_view = - [&destroy_view_called]( - int64_t view_id, - flutter_runner::FlatlandViewIdCallback on_view_unbound) { - destroy_view_called = true; - fuchsia::ui::composition::ContentId content_id; - on_view_unbound(std::move(content_id)); - }; + auto on_destroy_view = [&destroy_view_called]( + int64_t view_id, + flutter_runner::ViewIdCallback on_view_unbound) { + destroy_view_called = true; + fuchsia::ui::composition::ContentId content_id; + on_view_unbound(std::move(content_id)); + }; bool create_view_called = false; - auto on_create_view = - [&create_view_called, this]( - int64_t view_id, flutter_runner::ViewCallback on_view_created, - flutter_runner::FlatlandViewCreatedCallback on_view_bound, - bool hit_testable, bool focusable) { - create_view_called = true; - on_view_created(); - fuchsia::ui::composition::ContentId content_id; - on_view_bound(std::move(content_id), MakeChildViewWatcher()); - }; + auto on_create_view = [&create_view_called, this]( + int64_t view_id, + flutter_runner::ViewCallback on_view_created, + flutter_runner::ViewCreatedCallback on_view_bound, + bool hit_testable, bool focusable) { + create_view_called = true; + on_view_created(); + fuchsia::ui::composition::ContentId content_id; + on_view_bound(std::move(content_id), MakeChildViewWatcher()); + }; auto platform_view = PlatformViewBuilder(delegate, std::move(task_runners)) .SetCreateViewCallback(on_create_view) @@ -1033,7 +1035,7 @@ TEST_F(FlatlandPlatformViewTests, DestroyViewTest) { // This test makes sure that the PlatformView forwards messages on the // "flutter/platform_views" channel for View.focus.getCurrent and // View.focus.getNext. -TEST_F(FlatlandPlatformViewTests, GetFocusStatesTest) { +TEST_F(PlatformViewTests, GetFocusStatesTest) { MockPlatformViewDelegate delegate; flutter::TaskRunners task_runners = flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr); @@ -1092,7 +1094,7 @@ TEST_F(FlatlandPlatformViewTests, GetFocusStatesTest) { // This test makes sure that the PlatformView forwards messages on the // "flutter/platform_views" channel for View.focus.request. -TEST_F(FlatlandPlatformViewTests, RequestFocusTest) { +TEST_F(PlatformViewTests, RequestFocusTest) { MockPlatformViewDelegate delegate; flutter::TaskRunners task_runners = flutter::TaskRunners("test_runners", // label @@ -1108,16 +1110,16 @@ TEST_F(FlatlandPlatformViewTests, RequestFocusTest) { auto focuser_handle = focuser_bindings.AddBinding(&focuser); bool create_view_called = false; - auto on_create_view = - [&create_view_called, this]( - int64_t view_id, flutter_runner::ViewCallback on_view_created, - flutter_runner::FlatlandViewCreatedCallback on_view_bound, - bool hit_testable, bool focusable) { - create_view_called = true; - on_view_created(); - fuchsia::ui::composition::ContentId content_id; - on_view_bound(std::move(content_id), MakeChildViewWatcher()); - }; + auto on_create_view = [&create_view_called, this]( + int64_t view_id, + flutter_runner::ViewCallback on_view_created, + flutter_runner::ViewCreatedCallback on_view_bound, + bool hit_testable, bool focusable) { + create_view_called = true; + on_view_created(); + fuchsia::ui::composition::ContentId content_id; + on_view_bound(std::move(content_id), MakeChildViewWatcher()); + }; auto platform_view = PlatformViewBuilder(delegate, std::move(task_runners)) .SetFocuser(std::move(focuser_handle)) @@ -1167,7 +1169,7 @@ TEST_F(FlatlandPlatformViewTests, RequestFocusTest) { } // This test tries to set focus on a view without creating it first -TEST_F(FlatlandPlatformViewTests, RequestFocusNeverCreatedTest) { +TEST_F(PlatformViewTests, RequestFocusNeverCreatedTest) { MockPlatformViewDelegate delegate; flutter::TaskRunners task_runners = flutter::TaskRunners("test_runners", // label @@ -1183,16 +1185,16 @@ TEST_F(FlatlandPlatformViewTests, RequestFocusNeverCreatedTest) { auto focuser_handle = focuser_bindings.AddBinding(&focuser); bool create_view_called = false; - auto on_create_view = - [&create_view_called, this]( - int64_t view_id, flutter_runner::ViewCallback on_view_created, - flutter_runner::FlatlandViewCreatedCallback on_view_bound, - bool hit_testable, bool focusable) { - create_view_called = true; - on_view_created(); - fuchsia::ui::composition::ContentId content_id; - on_view_bound(std::move(content_id), MakeChildViewWatcher()); - }; + auto on_create_view = [&create_view_called, this]( + int64_t view_id, + flutter_runner::ViewCallback on_view_created, + flutter_runner::ViewCreatedCallback on_view_bound, + bool hit_testable, bool focusable) { + create_view_called = true; + on_view_created(); + fuchsia::ui::composition::ContentId content_id; + on_view_bound(std::move(content_id), MakeChildViewWatcher()); + }; auto platform_view = PlatformViewBuilder(delegate, std::move(task_runners)) .SetFocuser(std::move(focuser_handle)) @@ -1221,7 +1223,7 @@ TEST_F(FlatlandPlatformViewTests, RequestFocusNeverCreatedTest) { EXPECT_FALSE(focuser.request_focus_called()); } -TEST_F(FlatlandPlatformViewTests, RequestFocusDisposedTest) { +TEST_F(PlatformViewTests, RequestFocusDisposedTest) { MockPlatformViewDelegate delegate; flutter::TaskRunners task_runners = flutter::TaskRunners("test_runners", // label @@ -1237,27 +1239,26 @@ TEST_F(FlatlandPlatformViewTests, RequestFocusDisposedTest) { auto focuser_handle = focuser_bindings.AddBinding(&focuser); bool create_view_called = false; - auto on_create_view = - [&create_view_called, this]( - int64_t view_id, flutter_runner::ViewCallback on_view_created, - flutter_runner::FlatlandViewCreatedCallback on_view_bound, - bool hit_testable, bool focusable) { - create_view_called = true; - on_view_created(); - fuchsia::ui::composition::ContentId content_id; - on_view_bound(std::move(content_id), MakeChildViewWatcher()); - }; + auto on_create_view = [&create_view_called, this]( + int64_t view_id, + flutter_runner::ViewCallback on_view_created, + flutter_runner::ViewCreatedCallback on_view_bound, + bool hit_testable, bool focusable) { + create_view_called = true; + on_view_created(); + fuchsia::ui::composition::ContentId content_id; + on_view_bound(std::move(content_id), MakeChildViewWatcher()); + }; bool destroy_view_called = false; - auto on_destroy_view = - [&destroy_view_called]( - int64_t view_id, - flutter_runner::FlatlandViewIdCallback on_view_unbound) { - destroy_view_called = true; - fuchsia::ui::composition::ContentId content_id; - on_view_unbound(std::move(content_id)); - }; + auto on_destroy_view = [&destroy_view_called]( + int64_t view_id, + flutter_runner::ViewIdCallback on_view_unbound) { + destroy_view_called = true; + fuchsia::ui::composition::ContentId content_id; + on_view_unbound(std::move(content_id)); + }; auto platform_view = PlatformViewBuilder(delegate, std::move(task_runners)) .SetFocuser(std::move(focuser_handle)) @@ -1320,7 +1321,7 @@ TEST_F(FlatlandPlatformViewTests, RequestFocusDisposedTest) { } // Makes sure that OnKeyEvent is dispatched as a platform message. -TEST_F(FlatlandPlatformViewTests, OnKeyEvent) { +TEST_F(PlatformViewTests, OnKeyEvent) { struct EventFlow { fuchsia::ui::input3::KeyEvent event; fuchsia::ui::input3::KeyEventStatus expected_key_event_status; @@ -1405,7 +1406,7 @@ TEST_F(FlatlandPlatformViewTests, OnKeyEvent) { } } -TEST_F(FlatlandPlatformViewTests, OnShaderWarmup) { +TEST_F(PlatformViewTests, OnShaderWarmup) { MockPlatformViewDelegate delegate; flutter::TaskRunners task_runners = flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr); @@ -1414,7 +1415,7 @@ TEST_F(FlatlandPlatformViewTests, OnShaderWarmup) { uint64_t height = 100; std::vector shaders = {"foo.skp", "bar.skp", "baz.skp"}; - OnShaderWarmup on_shader_warmup = + OnShaderWarmupCallback on_shader_warmup_callback = [&](const std::vector& shaders_in, std::function completion_callback, uint64_t width_in, uint64_t height_in) { @@ -1429,7 +1430,7 @@ TEST_F(FlatlandPlatformViewTests, OnShaderWarmup) { }; auto platform_view = PlatformViewBuilder(delegate, std::move(task_runners)) - .SetShaderWarmupCallback(on_shader_warmup) + .SetShaderWarmupCallback(on_shader_warmup_callback) .Build(); std::ostringstream shaders_array_ostream; @@ -1472,7 +1473,7 @@ TEST_F(FlatlandPlatformViewTests, OnShaderWarmup) { EXPECT_EQ(expected_result_string, response->result_string); } -TEST_F(FlatlandPlatformViewTests, TouchSourceLogicalToPhysicalConversion) { +TEST_F(PlatformViewTests, TouchSourceLogicalToPhysicalConversion) { constexpr uint32_t width = 640; constexpr uint32_t height = 480; constexpr std::array, 2> kRect = { diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface.cc index fc542ee1d0..7d0f526ca5 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface.cc @@ -148,15 +148,13 @@ VulkanSurface::VulkanSurface( fuchsia::sysmem::AllocatorSyncPtr& sysmem_allocator, fuchsia::ui::composition::AllocatorPtr& flatland_allocator, sk_sp context, - scenic::Session* session, - const SkISize& size, - uint32_t buffer_id) - : vulkan_provider_(vulkan_provider), session_(session), wait_(this) { - FML_CHECK(session_ || flatland_allocator.is_bound()); + const SkISize& size) + : vulkan_provider_(vulkan_provider), wait_(this) { + FML_CHECK(flatland_allocator.is_bound()); FML_CHECK(context != nullptr); if (!AllocateDeviceMemory(sysmem_allocator, flatland_allocator, - std::move(context), size, buffer_id)) { + std::move(context), size)) { FML_LOG(ERROR) << "VulkanSurface: Could not allocate device memory."; return; } @@ -166,8 +164,6 @@ VulkanSurface::VulkanSurface( return; } - PushSessionImageSetupOps(session); - std::fill(size_history_.begin(), size_history_.end(), SkISize::MakeEmpty()); wait_.set_object(release_event_.get()); @@ -178,14 +174,7 @@ VulkanSurface::VulkanSurface( } VulkanSurface::~VulkanSurface() { - if (session_) { - if (image_id_) { - session_->Enqueue(scenic::NewReleaseResourceCmd(image_id_)); - } - if (buffer_id_) { - session_->DeregisterBufferCollection(buffer_id_); - } - } else if (release_image_callback_) { + if (release_image_callback_) { release_image_callback_(); } wait_.Cancel(); @@ -275,8 +264,7 @@ bool VulkanSurface::AllocateDeviceMemory( fuchsia::sysmem::AllocatorSyncPtr& sysmem_allocator, fuchsia::ui::composition::AllocatorPtr& flatland_allocator, sk_sp context, - const SkISize& size, - uint32_t buffer_id) { + const SkISize& size) { if (size.isEmpty()) { FML_LOG(ERROR) << "VulkanSurface: Failed to allocate surface, size is empty"; @@ -297,29 +285,23 @@ bool VulkanSurface::AllocateDeviceMemory( LOG_AND_RETURN(status != ZX_OK, "VulkanSurface: Failed to sync collection token"); - if (session_) { - session_->RegisterBufferCollection(buffer_id, std::move(scenic_token)); - buffer_id_ = buffer_id; - } else { - fuchsia::ui::composition::BufferCollectionExportToken export_token; - status = - zx::eventpair::create(0, &export_token.value, &import_token_.value); + fuchsia::ui::composition::BufferCollectionExportToken export_token; + status = zx::eventpair::create(0, &export_token.value, &import_token_.value); - fuchsia::ui::composition::RegisterBufferCollectionArgs args; - args.set_export_token(std::move(export_token)); - args.set_buffer_collection_token(std::move(scenic_token)); - args.set_usage( - fuchsia::ui::composition::RegisterBufferCollectionUsage::DEFAULT); - flatland_allocator->RegisterBufferCollection( - std::move(args), - [](fuchsia::ui::composition::Allocator_RegisterBufferCollection_Result - result) { - if (result.is_err()) { - FML_LOG(ERROR) - << "RegisterBufferCollection call to Scenic Allocator failed"; - } - }); - } + fuchsia::ui::composition::RegisterBufferCollectionArgs args; + args.set_export_token(std::move(export_token)); + args.set_buffer_collection_token(std::move(scenic_token)); + args.set_usage( + fuchsia::ui::composition::RegisterBufferCollectionUsage::DEFAULT); + flatland_allocator->RegisterBufferCollection( + std::move(args), + [](fuchsia::ui::composition::Allocator_RegisterBufferCollection_Result + result) { + if (result.is_err()) { + FML_LOG(ERROR) + << "RegisterBufferCollection call to Scenic Allocator failed"; + } + }); VkBufferCollectionCreateInfoFUCHSIA import_info{ .sType = VK_STRUCTURE_TYPE_BUFFER_COLLECTION_CREATE_INFO_FUCHSIA, @@ -451,18 +433,8 @@ bool VulkanSurface::SetupSkiaSurface(sk_sp context, return true; } -void VulkanSurface::PushSessionImageSetupOps(scenic::Session* session) { - if (session) { - if (image_id_ == 0) - image_id_ = session->AllocResourceId(); - session->Enqueue(scenic::NewCreateImage2Cmd( - image_id_, sk_surface_->width(), sk_surface_->height(), buffer_id_, 0)); - } -} - void VulkanSurface::SetImageId(uint32_t image_id) { FML_CHECK(image_id_ == 0); - FML_CHECK(!session_); image_id_ = image_id; } @@ -476,28 +448,24 @@ sk_sp VulkanSurface::GetSkiaSurface() const { fuchsia::ui::composition::BufferCollectionImportToken VulkanSurface::GetBufferCollectionImportToken() { - FML_CHECK(!session_); fuchsia::ui::composition::BufferCollectionImportToken import_dup; import_token_.value.duplicate(ZX_RIGHT_SAME_RIGHTS, &import_dup.value); return import_dup; } zx::event VulkanSurface::GetAcquireFence() { - FML_CHECK(!session_); zx::event fence; acquire_event_.duplicate(ZX_RIGHT_SAME_RIGHTS, &fence); return fence; } zx::event VulkanSurface::GetReleaseFence() { - FML_CHECK(!session_); zx::event fence; release_event_.duplicate(ZX_RIGHT_SAME_RIGHTS, &fence); return fence; } void VulkanSurface::SetReleaseImageCallback( ReleaseImageCallback release_image_callback) { - FML_CHECK(!session_); release_image_callback_ = release_image_callback; } @@ -509,16 +477,6 @@ size_t VulkanSurface::AdvanceAndGetAge() { } bool VulkanSurface::FlushSessionAcquireAndReleaseEvents() { - if (session_) { - zx::event acquire, release; - if (acquire_event_.duplicate(ZX_RIGHT_SAME_RIGHTS, &acquire) != ZX_OK || - release_event_.duplicate(ZX_RIGHT_SAME_RIGHTS, &release) != ZX_OK) { - return false; - } - session_->EnqueueAcquireFence(std::move(acquire)); - session_->EnqueueReleaseFence(std::move(release)); - } - age_ = 0; return true; } diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface.h b/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface.h index 37db0c4fe3..674b9e99f7 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface.h +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface.h @@ -5,7 +5,6 @@ #pragma once #include -#include #include #include @@ -47,9 +46,7 @@ class VulkanSurface final : public SurfaceProducerSurface { fuchsia::sysmem::AllocatorSyncPtr& sysmem_allocator, fuchsia::ui::composition::AllocatorPtr& flatland_allocator, sk_sp context, - scenic::Session* session, - const SkISize& size, - uint32_t buffer_id); + const SkISize& size); ~VulkanSurface() override; @@ -140,8 +137,7 @@ class VulkanSurface final : public SurfaceProducerSurface { fuchsia::sysmem::AllocatorSyncPtr& sysmem_allocator, fuchsia::ui::composition::AllocatorPtr& flatland_allocator, sk_sp context, - const SkISize& size, - uint32_t buffer_id); + const SkISize& size); bool CreateVulkanImage(vulkan::VulkanProvider& vulkan_provider, const SkISize& size, @@ -155,21 +151,17 @@ class VulkanSurface final : public SurfaceProducerSurface { bool CreateFences(); - void PushSessionImageSetupOps(scenic::Session* session); - void Reset(); vulkan::VulkanHandle SemaphoreFromEvent( const zx::event& event) const; vulkan::VulkanProvider& vulkan_provider_; - scenic::Session* session_; VulkanImage vulkan_image_; vulkan::VulkanHandle vk_memory_; VkMemoryAllocateInfo vk_memory_info_; vulkan::VulkanHandle command_buffer_fence_; sk_sp sk_surface_; - uint32_t buffer_id_ = 0; fuchsia::ui::composition::BufferCollectionImportToken import_token_; uint32_t image_id_ = 0; vulkan::VulkanHandle collection_; diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_pool.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_pool.cc index ce6fa2e03b..94df4a0f6f 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_pool.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_pool.cc @@ -30,11 +30,8 @@ static zx_koid_t GetCurrentProcessId() { } VulkanSurfacePool::VulkanSurfacePool(vulkan::VulkanProvider& vulkan_provider, - sk_sp context, - scenic::Session* scenic_session) - : vulkan_provider_(vulkan_provider), - context_(std::move(context)), - scenic_session_(scenic_session) { + sk_sp context) + : vulkan_provider_(vulkan_provider), context_(std::move(context)) { FML_CHECK(context_ != nullptr); zx_status_t status = fdio_service_connect( @@ -44,12 +41,10 @@ VulkanSurfacePool::VulkanSurfacePool(vulkan::VulkanProvider& vulkan_provider, GetCurrentProcessId()); FML_DCHECK(status == ZX_OK); - if (!scenic_session_) { - status = fdio_service_connect( - "/svc/fuchsia.ui.composition.Allocator", - flatland_allocator_.NewRequest().TakeChannel().release()); - FML_DCHECK(status == ZX_OK); - } + status = fdio_service_connect( + "/svc/fuchsia.ui.composition.Allocator", + flatland_allocator_.NewRequest().TakeChannel().release()); + FML_DCHECK(status == ZX_OK); } VulkanSurfacePool::~VulkanSurfacePool() {} @@ -124,8 +119,7 @@ std::unique_ptr VulkanSurfacePool::CreateSurface( TRACE_EVENT2("flutter", "VulkanSurfacePool::CreateSurface", "width", size.width(), "height", size.height()); auto surface = std::make_unique( - vulkan_provider_, sysmem_allocator_, flatland_allocator_, context_, - scenic_session_, size, buffer_id_++); + vulkan_provider_, sysmem_allocator_, flatland_allocator_, context_, size); if (!surface->IsValid()) { FML_LOG(ERROR) << "VulkanSurfaceProducer: Created surface is invalid"; return nullptr; diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_pool.h b/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_pool.h index 694b8396c6..93f85dff13 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_pool.h +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_pool.h @@ -23,8 +23,7 @@ class VulkanSurfacePool final { static constexpr int kMaxSurfaceAge = 3; VulkanSurfacePool(vulkan::VulkanProvider& vulkan_provider, - sk_sp context, - scenic::Session* scenic_session); + sk_sp context); ~VulkanSurfacePool(); @@ -42,13 +41,11 @@ class VulkanSurfacePool final { private: vulkan::VulkanProvider& vulkan_provider_; sk_sp context_; - scenic::Session* scenic_session_; fuchsia::sysmem::AllocatorSyncPtr sysmem_allocator_; fuchsia::ui::composition::AllocatorPtr flatland_allocator_; std::vector> available_surfaces_; std::unordered_map> pending_surfaces_; - uint32_t buffer_id_ = 1; size_t trace_surfaces_created_ = 0; size_t trace_surfaces_reused_ = 0; diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_producer.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_producer.cc index 7c5c2b27fc..824b4e1093 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_producer.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_producer.cc @@ -40,8 +40,8 @@ constexpr size_t kGrCacheMaxByteSize = 1024 * 600 * 12 * 4; } // namespace -VulkanSurfaceProducer::VulkanSurfaceProducer(scenic::Session* scenic_session) { - valid_ = Initialize(scenic_session); +VulkanSurfaceProducer::VulkanSurfaceProducer() { + valid_ = Initialize(); if (!valid_) { FML_LOG(FATAL) << "VulkanSurfaceProducer: Initialization failed"; @@ -57,7 +57,7 @@ VulkanSurfaceProducer::~VulkanSurfaceProducer() { } }; -bool VulkanSurfaceProducer::Initialize(scenic::Session* scenic_session) { +bool VulkanSurfaceProducer::Initialize() { vk_ = fml::MakeRefCounted(); std::vector extensions = { @@ -163,8 +163,7 @@ bool VulkanSurfaceProducer::Initialize(scenic::Session* scenic_session) { // Use local limits specified in this file above instead of flutter defaults. context_->setResourceCacheLimit(kGrCacheMaxByteSize); - surface_pool_ = - std::make_unique(*this, context_, scenic_session); + surface_pool_ = std::make_unique(*this, context_); return true; } diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_producer.h b/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_producer.h index 10f025399b..55e3af4ac3 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_producer.h +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/vulkan_surface_producer.h @@ -7,8 +7,6 @@ #include #include #include -#include -#include #include "flutter/flutter_vma/flutter_skia_vma.h" #include "flutter/fml/macros.h" @@ -28,7 +26,7 @@ namespace flutter_runner { class VulkanSurfaceProducer final : public SurfaceProducer, public vulkan::VulkanProvider { public: - explicit VulkanSurfaceProducer(scenic::Session* scenic_session); + explicit VulkanSurfaceProducer(); ~VulkanSurfaceProducer() override; bool IsValid() const { return valid_; } @@ -55,7 +53,7 @@ class VulkanSurfaceProducer final : public SurfaceProducer, return logical_device_->GetHandle(); } - bool Initialize(scenic::Session* scenic_session); + bool Initialize(); void SubmitSurface(std::unique_ptr surface); bool TransitionSurfacesToExternal(