From fa4b341f9d55b5a47b9c4a016ce009c5d3e34e98 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Thu, 23 Jan 2020 17:54:47 -0800 Subject: [PATCH 1/2] [fuchsia] Expose view_ref as part of dart:fuchsia initialization --- .../fuchsia/dart-pkg/fuchsia/lib/fuchsia.dart | 13 +++++++++++++ .../fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.cc | 8 +++++++- .../fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.h | 3 ++- .../fuchsia/dart_runner/builtin_libraries.cc | 5 ++++- shell/platform/fuchsia/flutter/component.cc | 2 -- shell/platform/fuchsia/flutter/engine.cc | 14 ++++++++++---- shell/platform/fuchsia/flutter/engine.h | 2 -- .../fuchsia/flutter/isolate_configurator.cc | 9 ++++++--- .../fuchsia/flutter/isolate_configurator.h | 4 +++- .../platform/fuchsia/flutter/session_connection.cc | 4 ---- 10 files changed, 45 insertions(+), 19 deletions(-) diff --git a/shell/platform/fuchsia/dart-pkg/fuchsia/lib/fuchsia.dart b/shell/platform/fuchsia/dart-pkg/fuchsia/lib/fuchsia.dart index b04fe363d8f40..5b9715ce85b2b 100644 --- a/shell/platform/fuchsia/dart-pkg/fuchsia/lib/fuchsia.dart +++ b/shell/platform/fuchsia/dart-pkg/fuchsia/lib/fuchsia.dart @@ -18,6 +18,9 @@ Handle _environment; @pragma('vm:entry-point') Handle _outgoingServices; +@pragma('vm:entry-point') +Handle _viewRef; + class MxStartupInfo { // TODO: refactor Handle to a Channel static Handle takeEnvironment() { @@ -40,6 +43,16 @@ class MxStartupInfo { _outgoingServices = null; return handle; } + + static Handle takeViewRef() { + if (_viewRef == null && Platform.isFuchsia) { + throw Exception( + 'Attempting to call takeViewRef more than once per process'); + } + Handle handle = _viewRef; + _viewRef = null; + return handle; + } } void _setReturnCode(int returnCode) native 'SetReturnCode'; diff --git a/shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.cc b/shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.cc index 5960a2ddeebba..f788576575627 100644 --- a/shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.cc +++ b/shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.cc @@ -102,7 +102,8 @@ void SetReturnCode(Dart_NativeArguments arguments) { } // namespace void Initialize(fidl::InterfaceHandle environment, - zx::channel directory_request) { + zx::channel directory_request, + zx::eventpair view_ref) { zircon::dart::Initialize(); Dart_Handle library = Dart_LookupLibrary(ToDart("dart:fuchsia")); @@ -128,6 +129,11 @@ void Initialize(fidl::InterfaceHandle environment, ToDart(zircon::dart::Handle::Create(std::move(directory_request)))); FML_CHECK(!tonic::LogIfError(result)); } + + result = + Dart_SetField(library, ToDart("_viewRef"), + ToDart(zircon::dart::Handle::Create(view_ref.release()))); + FML_CHECK(!tonic::LogIfError(result)); } } // namespace dart diff --git a/shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.h b/shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.h index e516ffc6daaff..5ef0272642dfa 100644 --- a/shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.h +++ b/shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.h @@ -11,7 +11,8 @@ namespace fuchsia { namespace dart { void Initialize(fidl::InterfaceHandle environment, - zx::channel directory_request); + zx::channel directory_request, + zx::eventpair view_ref); } // namespace dart } // namespace fuchsia diff --git a/shell/platform/fuchsia/dart_runner/builtin_libraries.cc b/shell/platform/fuchsia/dart_runner/builtin_libraries.cc index 54f4f9a10ab30..f6413c1901814 100644 --- a/shell/platform/fuchsia/dart_runner/builtin_libraries.cc +++ b/shell/platform/fuchsia/dart_runner/builtin_libraries.cc @@ -103,9 +103,12 @@ void InitBuiltinLibrariesForIsolate( zx::channel directory_request, bool service_isolate) { // dart:fuchsia -------------------------------------------------------------- + // dart runner doesn't care about scenic view ref. + zx::eventpair dummy_view_ref; if (!service_isolate) { fuchsia::dart::Initialize(std::move(environment), - std::move(directory_request)); + std::move(directory_request), + std::move(dummy_view_ref)); } // dart:fuchsia.builtin ------------------------------------------------------ diff --git a/shell/platform/fuchsia/flutter/component.cc b/shell/platform/fuchsia/flutter/component.cc index dee414d344538..f859d670e1771 100644 --- a/shell/platform/fuchsia/flutter/component.cc +++ b/shell/platform/fuchsia/flutter/component.cc @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -616,7 +615,6 @@ void Application::CreateView( settings_, // settings std::move(isolate_snapshot_), // isolate snapshot scenic::ToViewToken(std::move(view_token)), // view token - scenic::ViewRefPair::New(), // view ref pair std::move(fdio_ns_), // FDIO namespace std::move(directory_request_) // outgoing request )); diff --git a/shell/platform/fuchsia/flutter/engine.cc b/shell/platform/fuchsia/flutter/engine.cc index 484d5b8145cd3..90b12d51fae8d 100644 --- a/shell/platform/fuchsia/flutter/engine.cc +++ b/shell/platform/fuchsia/flutter/engine.cc @@ -7,6 +7,7 @@ #include "engine.h" #include +#include #include #include @@ -55,7 +56,6 @@ Engine::Engine(Delegate& delegate, flutter::Settings settings, fml::RefPtr isolate_snapshot, fuchsia::ui::views::ViewToken view_token, - scenic::ViewRefPair view_ref_pair, UniqueFDIONS fdio_ns, fidl::InterfaceRequest directory_request) : delegate_(delegate), @@ -111,9 +111,14 @@ Engine::Engine(Delegate& delegate, }); }; + auto view_ref_pair = scenic::ViewRefPair::New(); fuchsia::ui::views::ViewRef view_ref; view_ref_pair.view_ref.Clone(&view_ref); + fuchsia::ui::views::ViewRef dart_view_ref; + view_ref_pair.view_ref.Clone(&dart_view_ref); + zx::eventpair dart_view_ref_event_pair(std::move(dart_view_ref.reference)); + // Setup the callback that will instantiate the platform view. flutter::Shell::CreateCallback on_create_platform_view = fml::MakeCopyable( @@ -256,9 +261,10 @@ Engine::Engine(Delegate& delegate, svc->Connect(environment.NewRequest()); isolate_configurator_ = std::make_unique( - std::move(fdio_ns), // - std::move(environment), // - directory_request.TakeChannel() // + std::move(fdio_ns), // + std::move(environment), // + directory_request.TakeChannel(), // + std::move(dart_view_ref_event_pair) // ); } diff --git a/shell/platform/fuchsia/flutter/engine.h b/shell/platform/fuchsia/flutter/engine.h index f1171b5ad3487..22e66436d17ec 100644 --- a/shell/platform/fuchsia/flutter/engine.h +++ b/shell/platform/fuchsia/flutter/engine.h @@ -11,7 +11,6 @@ #include #include #include -#include #include #include "flutter/fml/macros.h" @@ -37,7 +36,6 @@ class Engine final { flutter::Settings settings, fml::RefPtr isolate_snapshot, fuchsia::ui::views::ViewToken view_token, - scenic::ViewRefPair view_ref_pair, UniqueFDIONS fdio_ns, fidl::InterfaceRequest directory_request); ~Engine(); diff --git a/shell/platform/fuchsia/flutter/isolate_configurator.cc b/shell/platform/fuchsia/flutter/isolate_configurator.cc index d6e9bc6f851bc..ceb2a85a3d4b5 100644 --- a/shell/platform/fuchsia/flutter/isolate_configurator.cc +++ b/shell/platform/fuchsia/flutter/isolate_configurator.cc @@ -16,10 +16,12 @@ namespace flutter_runner { IsolateConfigurator::IsolateConfigurator( UniqueFDIONS fdio_ns, fidl::InterfaceHandle environment, - zx::channel directory_request) + zx::channel directory_request, + zx::eventpair view_ref) : fdio_ns_(std::move(fdio_ns)), environment_(std::move(environment)), - directory_request_(std::move(directory_request)) {} + directory_request_(std::move(directory_request)), + view_ref_(std::move(view_ref)) {} IsolateConfigurator::~IsolateConfigurator() = default; @@ -42,7 +44,8 @@ bool IsolateConfigurator::ConfigureCurrentIsolate() { void IsolateConfigurator::BindFuchsia() { fuchsia::dart::Initialize(std::move(environment_), - std::move(directory_request_)); + std::move(directory_request_), + std::move(view_ref_)); } void IsolateConfigurator::BindZircon() { diff --git a/shell/platform/fuchsia/flutter/isolate_configurator.h b/shell/platform/fuchsia/flutter/isolate_configurator.h index f2992dd233512..57634ecf97757 100644 --- a/shell/platform/fuchsia/flutter/isolate_configurator.h +++ b/shell/platform/fuchsia/flutter/isolate_configurator.h @@ -21,7 +21,8 @@ class IsolateConfigurator final { IsolateConfigurator( UniqueFDIONS fdio_ns, fidl::InterfaceHandle environment, - zx::channel directory_request); + zx::channel directory_request, + zx::eventpair view_ref); ~IsolateConfigurator(); @@ -34,6 +35,7 @@ class IsolateConfigurator final { UniqueFDIONS fdio_ns_; fidl::InterfaceHandle environment_; zx::channel directory_request_; + zx::eventpair view_ref_; void BindFuchsia(); diff --git a/shell/platform/fuchsia/flutter/session_connection.cc b/shell/platform/fuchsia/flutter/session_connection.cc index 767b3f077e4fc..6517d4a9baecf 100644 --- a/shell/platform/fuchsia/flutter/session_connection.cc +++ b/shell/platform/fuchsia/flutter/session_connection.cc @@ -36,10 +36,6 @@ SessionConnection::SessionConnection( session_wrapper_.SetDebugName(debug_label_); - // TODO(SCN-975): Re-enable. - // view_->GetToken(std::bind(&PlatformView::ConnectSemanticsProvider, this, - // std::placeholders::_1)); - root_view_.AddChild(root_node_); root_node_.SetEventMask(fuchsia::ui::gfx::kMetricsEventMask | fuchsia::ui::gfx::kSizeChangeHintEventMask); From 3bd932dbbcef2c3f2ca992ee5947d94af331b8df Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Fri, 24 Jan 2020 11:36:54 -0800 Subject: [PATCH 2/2] Use std::optional and file an issue for TODOs in fuchsia.dart --- .../fuchsia/dart-pkg/fuchsia/lib/fuchsia.dart | 4 ++++ .../fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.cc | 12 +++++++----- .../fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.h | 2 +- .../fuchsia/dart_runner/builtin_libraries.cc | 5 ++--- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/shell/platform/fuchsia/dart-pkg/fuchsia/lib/fuchsia.dart b/shell/platform/fuchsia/dart-pkg/fuchsia/lib/fuchsia.dart index 5b9715ce85b2b..b351284b1b2f6 100644 --- a/shell/platform/fuchsia/dart-pkg/fuchsia/lib/fuchsia.dart +++ b/shell/platform/fuchsia/dart-pkg/fuchsia/lib/fuchsia.dart @@ -23,6 +23,7 @@ Handle _viewRef; class MxStartupInfo { // TODO: refactor Handle to a Channel + // https://github.com/flutter/flutter/issues/49439 static Handle takeEnvironment() { if (_outgoingServices == null && Platform.isFuchsia) { throw Exception( @@ -34,6 +35,7 @@ class MxStartupInfo { } // TODO: refactor Handle to a Channel + // https://github.com/flutter/flutter/issues/49439 static Handle takeOutgoingServices() { if (_outgoingServices == null && Platform.isFuchsia) { throw Exception( @@ -44,6 +46,8 @@ class MxStartupInfo { return handle; } + // TODO: refactor Handle to a ViewRef + // https://github.com/flutter/flutter/issues/49439 static Handle takeViewRef() { if (_viewRef == null && Platform.isFuchsia) { throw Exception( diff --git a/shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.cc b/shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.cc index f788576575627..3c7194df29ece 100644 --- a/shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.cc +++ b/shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.cc @@ -103,7 +103,7 @@ void SetReturnCode(Dart_NativeArguments arguments) { void Initialize(fidl::InterfaceHandle environment, zx::channel directory_request, - zx::eventpair view_ref) { + std::optional view_ref) { zircon::dart::Initialize(); Dart_Handle library = Dart_LookupLibrary(ToDart("dart:fuchsia")); @@ -130,10 +130,12 @@ void Initialize(fidl::InterfaceHandle environment, FML_CHECK(!tonic::LogIfError(result)); } - result = - Dart_SetField(library, ToDart("_viewRef"), - ToDart(zircon::dart::Handle::Create(view_ref.release()))); - FML_CHECK(!tonic::LogIfError(result)); + if (view_ref) { + result = Dart_SetField( + library, ToDart("_viewRef"), + ToDart(zircon::dart::Handle::Create((*view_ref).release()))); + FML_CHECK(!tonic::LogIfError(result)); + } } } // namespace dart diff --git a/shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.h b/shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.h index 5ef0272642dfa..59a1e4414e02f 100644 --- a/shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.h +++ b/shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.h @@ -12,7 +12,7 @@ namespace dart { void Initialize(fidl::InterfaceHandle environment, zx::channel directory_request, - zx::eventpair view_ref); + std::optional view_ref); } // namespace dart } // namespace fuchsia diff --git a/shell/platform/fuchsia/dart_runner/builtin_libraries.cc b/shell/platform/fuchsia/dart_runner/builtin_libraries.cc index f6413c1901814..476682a03310b 100644 --- a/shell/platform/fuchsia/dart_runner/builtin_libraries.cc +++ b/shell/platform/fuchsia/dart_runner/builtin_libraries.cc @@ -6,6 +6,7 @@ #include #include +#include #include "dart-pkg/fuchsia/sdk_ext/fuchsia.h" #include "flutter/fml/logging.h" @@ -104,11 +105,9 @@ void InitBuiltinLibrariesForIsolate( bool service_isolate) { // dart:fuchsia -------------------------------------------------------------- // dart runner doesn't care about scenic view ref. - zx::eventpair dummy_view_ref; if (!service_isolate) { fuchsia::dart::Initialize(std::move(environment), - std::move(directory_request), - std::move(dummy_view_ref)); + std::move(directory_request), std::nullopt); } // dart:fuchsia.builtin ------------------------------------------------------