Skip to content

Commit 5d7c2a9

Browse files
iskakaushikNoamDev
authored andcommitted
[fuchsia] Expose view_ref as part of dart:fuchsia initialization (flutter#15958)
fixes flutter/flutter#47178
1 parent f6056d9 commit 5d7c2a9

File tree

10 files changed

+50
-19
lines changed

10 files changed

+50
-19
lines changed

shell/platform/fuchsia/dart-pkg/fuchsia/lib/fuchsia.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ Handle _environment;
1818
@pragma('vm:entry-point')
1919
Handle _outgoingServices;
2020

21+
@pragma('vm:entry-point')
22+
Handle _viewRef;
23+
2124
class MxStartupInfo {
2225
// TODO: refactor Handle to a Channel
26+
// https://github.com/flutter/flutter/issues/49439
2327
static Handle takeEnvironment() {
2428
if (_outgoingServices == null && Platform.isFuchsia) {
2529
throw Exception(
@@ -31,6 +35,7 @@ class MxStartupInfo {
3135
}
3236

3337
// TODO: refactor Handle to a Channel
38+
// https://github.com/flutter/flutter/issues/49439
3439
static Handle takeOutgoingServices() {
3540
if (_outgoingServices == null && Platform.isFuchsia) {
3641
throw Exception(
@@ -40,6 +45,18 @@ class MxStartupInfo {
4045
_outgoingServices = null;
4146
return handle;
4247
}
48+
49+
// TODO: refactor Handle to a ViewRef
50+
// https://github.com/flutter/flutter/issues/49439
51+
static Handle takeViewRef() {
52+
if (_viewRef == null && Platform.isFuchsia) {
53+
throw Exception(
54+
'Attempting to call takeViewRef more than once per process');
55+
}
56+
Handle handle = _viewRef;
57+
_viewRef = null;
58+
return handle;
59+
}
4360
}
4461

4562
void _setReturnCode(int returnCode) native 'SetReturnCode';

shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ void SetReturnCode(Dart_NativeArguments arguments) {
102102
} // namespace
103103

104104
void Initialize(fidl::InterfaceHandle<fuchsia::sys::Environment> environment,
105-
zx::channel directory_request) {
105+
zx::channel directory_request,
106+
std::optional<zx::eventpair> view_ref) {
106107
zircon::dart::Initialize();
107108

108109
Dart_Handle library = Dart_LookupLibrary(ToDart("dart:fuchsia"));
@@ -128,6 +129,13 @@ void Initialize(fidl::InterfaceHandle<fuchsia::sys::Environment> environment,
128129
ToDart(zircon::dart::Handle::Create(std::move(directory_request))));
129130
FML_CHECK(!tonic::LogIfError(result));
130131
}
132+
133+
if (view_ref) {
134+
result = Dart_SetField(
135+
library, ToDart("_viewRef"),
136+
ToDart(zircon::dart::Handle::Create((*view_ref).release())));
137+
FML_CHECK(!tonic::LogIfError(result));
138+
}
131139
}
132140

133141
} // namespace dart

shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ namespace fuchsia {
1111
namespace dart {
1212

1313
void Initialize(fidl::InterfaceHandle<fuchsia::sys::Environment> environment,
14-
zx::channel directory_request);
14+
zx::channel directory_request,
15+
std::optional<zx::eventpair> view_ref);
1516

1617
} // namespace dart
1718
} // namespace fuchsia

shell/platform/fuchsia/dart_runner/builtin_libraries.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <lib/fdio/namespace.h>
88
#include <lib/zx/channel.h>
9+
#include <optional>
910

1011
#include "dart-pkg/fuchsia/sdk_ext/fuchsia.h"
1112
#include "flutter/fml/logging.h"
@@ -103,9 +104,10 @@ void InitBuiltinLibrariesForIsolate(
103104
zx::channel directory_request,
104105
bool service_isolate) {
105106
// dart:fuchsia --------------------------------------------------------------
107+
// dart runner doesn't care about scenic view ref.
106108
if (!service_isolate) {
107109
fuchsia::dart::Initialize(std::move(environment),
108-
std::move(directory_request));
110+
std::move(directory_request), std::nullopt);
109111
}
110112

111113
// dart:fuchsia.builtin ------------------------------------------------------

shell/platform/fuchsia/flutter/component.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <lib/async/default.h>
1414
#include <lib/fdio/directory.h>
1515
#include <lib/fdio/namespace.h>
16-
#include <lib/ui/scenic/cpp/view_ref_pair.h>
1716
#include <lib/ui/scenic/cpp/view_token_pair.h>
1817
#include <lib/vfs/cpp/composed_service_dir.h>
1918
#include <lib/vfs/cpp/remote_dir.h>
@@ -616,7 +615,6 @@ void Application::CreateView(
616615
settings_, // settings
617616
std::move(isolate_snapshot_), // isolate snapshot
618617
scenic::ToViewToken(std::move(view_token)), // view token
619-
scenic::ViewRefPair::New(), // view ref pair
620618
std::move(fdio_ns_), // FDIO namespace
621619
std::move(directory_request_) // outgoing request
622620
));

shell/platform/fuchsia/flutter/engine.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "engine.h"
88

99
#include <lib/async/cpp/task.h>
10+
#include <lib/ui/scenic/cpp/view_ref_pair.h>
1011
#include <zircon/status.h>
1112
#include <sstream>
1213

@@ -55,7 +56,6 @@ Engine::Engine(Delegate& delegate,
5556
flutter::Settings settings,
5657
fml::RefPtr<const flutter::DartSnapshot> isolate_snapshot,
5758
fuchsia::ui::views::ViewToken view_token,
58-
scenic::ViewRefPair view_ref_pair,
5959
UniqueFDIONS fdio_ns,
6060
fidl::InterfaceRequest<fuchsia::io::Directory> directory_request)
6161
: delegate_(delegate),
@@ -111,9 +111,14 @@ Engine::Engine(Delegate& delegate,
111111
});
112112
};
113113

114+
auto view_ref_pair = scenic::ViewRefPair::New();
114115
fuchsia::ui::views::ViewRef view_ref;
115116
view_ref_pair.view_ref.Clone(&view_ref);
116117

118+
fuchsia::ui::views::ViewRef dart_view_ref;
119+
view_ref_pair.view_ref.Clone(&dart_view_ref);
120+
zx::eventpair dart_view_ref_event_pair(std::move(dart_view_ref.reference));
121+
117122
// Setup the callback that will instantiate the platform view.
118123
flutter::Shell::CreateCallback<flutter::PlatformView>
119124
on_create_platform_view = fml::MakeCopyable(
@@ -256,9 +261,10 @@ Engine::Engine(Delegate& delegate,
256261
svc->Connect(environment.NewRequest());
257262

258263
isolate_configurator_ = std::make_unique<IsolateConfigurator>(
259-
std::move(fdio_ns), //
260-
std::move(environment), //
261-
directory_request.TakeChannel() //
264+
std::move(fdio_ns), //
265+
std::move(environment), //
266+
directory_request.TakeChannel(), //
267+
std::move(dart_view_ref_event_pair) //
262268
);
263269
}
264270

shell/platform/fuchsia/flutter/engine.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <fuchsia/ui/views/cpp/fidl.h>
1212
#include <lib/async-loop/cpp/loop.h>
1313
#include <lib/sys/cpp/service_directory.h>
14-
#include <lib/ui/scenic/cpp/view_ref_pair.h>
1514
#include <lib/zx/event.h>
1615

1716
#include "flutter/fml/macros.h"
@@ -37,7 +36,6 @@ class Engine final {
3736
flutter::Settings settings,
3837
fml::RefPtr<const flutter::DartSnapshot> isolate_snapshot,
3938
fuchsia::ui::views::ViewToken view_token,
40-
scenic::ViewRefPair view_ref_pair,
4139
UniqueFDIONS fdio_ns,
4240
fidl::InterfaceRequest<fuchsia::io::Directory> directory_request);
4341
~Engine();

shell/platform/fuchsia/flutter/isolate_configurator.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ namespace flutter_runner {
1616
IsolateConfigurator::IsolateConfigurator(
1717
UniqueFDIONS fdio_ns,
1818
fidl::InterfaceHandle<fuchsia::sys::Environment> environment,
19-
zx::channel directory_request)
19+
zx::channel directory_request,
20+
zx::eventpair view_ref)
2021
: fdio_ns_(std::move(fdio_ns)),
2122
environment_(std::move(environment)),
22-
directory_request_(std::move(directory_request)) {}
23+
directory_request_(std::move(directory_request)),
24+
view_ref_(std::move(view_ref)) {}
2325

2426
IsolateConfigurator::~IsolateConfigurator() = default;
2527

@@ -42,7 +44,8 @@ bool IsolateConfigurator::ConfigureCurrentIsolate() {
4244

4345
void IsolateConfigurator::BindFuchsia() {
4446
fuchsia::dart::Initialize(std::move(environment_),
45-
std::move(directory_request_));
47+
std::move(directory_request_),
48+
std::move(view_ref_));
4649
}
4750

4851
void IsolateConfigurator::BindZircon() {

shell/platform/fuchsia/flutter/isolate_configurator.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class IsolateConfigurator final {
2121
IsolateConfigurator(
2222
UniqueFDIONS fdio_ns,
2323
fidl::InterfaceHandle<fuchsia::sys::Environment> environment,
24-
zx::channel directory_request);
24+
zx::channel directory_request,
25+
zx::eventpair view_ref);
2526

2627
~IsolateConfigurator();
2728

@@ -34,6 +35,7 @@ class IsolateConfigurator final {
3435
UniqueFDIONS fdio_ns_;
3536
fidl::InterfaceHandle<fuchsia::sys::Environment> environment_;
3637
zx::channel directory_request_;
38+
zx::eventpair view_ref_;
3739

3840
void BindFuchsia();
3941

shell/platform/fuchsia/flutter/session_connection.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ SessionConnection::SessionConnection(
3636

3737
session_wrapper_.SetDebugName(debug_label_);
3838

39-
// TODO(SCN-975): Re-enable.
40-
// view_->GetToken(std::bind(&PlatformView::ConnectSemanticsProvider, this,
41-
// std::placeholders::_1));
42-
4339
root_view_.AddChild(root_node_);
4440
root_node_.SetEventMask(fuchsia::ui::gfx::kMetricsEventMask |
4541
fuchsia::ui::gfx::kSizeChangeHintEventMask);

0 commit comments

Comments
 (0)