Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions shell/platform/fuchsia/dart-pkg/fuchsia/lib/fuchsia.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ Handle _environment;
@pragma('vm:entry-point')
Handle _outgoingServices;

@pragma('vm:entry-point')
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(
Expand All @@ -31,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(
Expand All @@ -40,6 +45,18 @@ class MxStartupInfo {
_outgoingServices = null;
return handle;
}

// TODO: refactor Handle to a ViewRef
// https://github.com/flutter/flutter/issues/49439
static Handle takeViewRef() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add // TODO: refactor Handle to an EventPair

Also, is there any issue open for those TODOs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is, I will create one.

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';
Expand Down
10 changes: 9 additions & 1 deletion shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ void SetReturnCode(Dart_NativeArguments arguments) {
} // namespace

void Initialize(fidl::InterfaceHandle<fuchsia::sys::Environment> environment,
zx::channel directory_request) {
zx::channel directory_request,
std::optional<zx::eventpair> view_ref) {
zircon::dart::Initialize();

Dart_Handle library = Dart_LookupLibrary(ToDart("dart:fuchsia"));
Expand All @@ -128,6 +129,13 @@ void Initialize(fidl::InterfaceHandle<fuchsia::sys::Environment> environment,
ToDart(zircon::dart::Handle::Create(std::move(directory_request))));
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
Expand Down
3 changes: 2 additions & 1 deletion shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace fuchsia {
namespace dart {

void Initialize(fidl::InterfaceHandle<fuchsia::sys::Environment> environment,
zx::channel directory_request);
zx::channel directory_request,
std::optional<zx::eventpair> view_ref);

} // namespace dart
} // namespace fuchsia
Expand Down
4 changes: 3 additions & 1 deletion shell/platform/fuchsia/dart_runner/builtin_libraries.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <lib/fdio/namespace.h>
#include <lib/zx/channel.h>
#include <optional>

#include "dart-pkg/fuchsia/sdk_ext/fuchsia.h"
#include "flutter/fml/logging.h"
Expand Down Expand Up @@ -103,9 +104,10 @@ void InitBuiltinLibrariesForIsolate(
zx::channel directory_request,
bool service_isolate) {
// dart:fuchsia --------------------------------------------------------------
// dart runner doesn't care about scenic view ref.
if (!service_isolate) {
fuchsia::dart::Initialize(std::move(environment),
std::move(directory_request));
std::move(directory_request), std::nullopt);
}

// dart:fuchsia.builtin ------------------------------------------------------
Expand Down
2 changes: 0 additions & 2 deletions shell/platform/fuchsia/flutter/component.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <lib/async/default.h>
#include <lib/fdio/directory.h>
#include <lib/fdio/namespace.h>
#include <lib/ui/scenic/cpp/view_ref_pair.h>
#include <lib/ui/scenic/cpp/view_token_pair.h>
#include <lib/vfs/cpp/composed_service_dir.h>
#include <lib/vfs/cpp/remote_dir.h>
Expand Down Expand Up @@ -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
));
Expand Down
14 changes: 10 additions & 4 deletions shell/platform/fuchsia/flutter/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "engine.h"

#include <lib/async/cpp/task.h>
#include <lib/ui/scenic/cpp/view_ref_pair.h>
#include <zircon/status.h>
#include <sstream>

Expand Down Expand Up @@ -55,7 +56,6 @@ Engine::Engine(Delegate& delegate,
flutter::Settings settings,
fml::RefPtr<const flutter::DartSnapshot> isolate_snapshot,
fuchsia::ui::views::ViewToken view_token,
scenic::ViewRefPair view_ref_pair,
UniqueFDIONS fdio_ns,
fidl::InterfaceRequest<fuchsia::io::Directory> directory_request)
: delegate_(delegate),
Expand Down Expand Up @@ -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<flutter::PlatformView>
on_create_platform_view = fml::MakeCopyable(
Expand Down Expand Up @@ -256,9 +261,10 @@ Engine::Engine(Delegate& delegate,
svc->Connect(environment.NewRequest());

isolate_configurator_ = std::make_unique<IsolateConfigurator>(
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) //
);
}

Expand Down
2 changes: 0 additions & 2 deletions shell/platform/fuchsia/flutter/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <fuchsia/ui/views/cpp/fidl.h>
#include <lib/async-loop/cpp/loop.h>
#include <lib/sys/cpp/service_directory.h>
#include <lib/ui/scenic/cpp/view_ref_pair.h>
#include <lib/zx/event.h>

#include "flutter/fml/macros.h"
Expand All @@ -37,7 +36,6 @@ class Engine final {
flutter::Settings settings,
fml::RefPtr<const flutter::DartSnapshot> isolate_snapshot,
fuchsia::ui::views::ViewToken view_token,
scenic::ViewRefPair view_ref_pair,
UniqueFDIONS fdio_ns,
fidl::InterfaceRequest<fuchsia::io::Directory> directory_request);
~Engine();
Expand Down
9 changes: 6 additions & 3 deletions shell/platform/fuchsia/flutter/isolate_configurator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ namespace flutter_runner {
IsolateConfigurator::IsolateConfigurator(
UniqueFDIONS fdio_ns,
fidl::InterfaceHandle<fuchsia::sys::Environment> 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;

Expand All @@ -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() {
Expand Down
4 changes: 3 additions & 1 deletion shell/platform/fuchsia/flutter/isolate_configurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class IsolateConfigurator final {
IsolateConfigurator(
UniqueFDIONS fdio_ns,
fidl::InterfaceHandle<fuchsia::sys::Environment> environment,
zx::channel directory_request);
zx::channel directory_request,
zx::eventpair view_ref);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, I would make the view_ref optional

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I will make the optional change.


~IsolateConfigurator();

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

void BindFuchsia();

Expand Down
4 changes: 0 additions & 4 deletions shell/platform/fuchsia/flutter/session_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down