未验证 提交 bd8c9555 编写于 作者: K Kaushik Iska 提交者: GitHub

[fuchsia] Expose view_ref as part of dart:fuchsia initialization (#15958)

fixes https://github.com/flutter/flutter/issues/47178
上级 abdf4bde
......@@ -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(
......@@ -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(
......@@ -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() {
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';
......
......@@ -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"));
......@@ -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
......
......@@ -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
......
......@@ -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"
......@@ -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 ------------------------------------------------------
......
......@@ -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>
......@@ -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
));
......
......@@ -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>
......@@ -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),
......@@ -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(
......@@ -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) //
);
}
......
......@@ -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"
......@@ -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();
......
......@@ -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;
......@@ -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() {
......
......@@ -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);
~IsolateConfigurator();
......@@ -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();
......
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册