Skip to content

Commit

Permalink
Update to new Dart FIDL bindings API. (flutter#3988)
Browse files Browse the repository at this point in the history
* Update to new Dart FIDL bindings API.
  • Loading branch information
ianloic authored Aug 22, 2017
1 parent 364bfa0 commit f08b084
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 29 deletions.
23 changes: 11 additions & 12 deletions content_handler/runtime_holder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@
#include "flutter/runtime/dart_controller.h"
#include "flutter/runtime/dart_init.h"
#include "flutter/runtime/runtime_init.h"
#include "lib/fidl/dart/sdk_ext/src/handle.h"
#include "lib/fidl/dart/sdk_ext/src/natives.h"
#include "lib/ftl/functional/make_copyable.h"
#include "lib/ftl/logging.h"
#include "lib/ftl/time/time_delta.h"
#include "lib/mtl/vmo/vector.h"
#include "lib/tonic/handle_table.h"
#include "lib/zip/create_unzipper.h"
#include "third_party/rapidjson/rapidjson/document.h"
#include "third_party/rapidjson/rapidjson/stringbuffer.h"
#include "third_party/rapidjson/rapidjson/writer.h"

using tonic::DartConverter;
using tonic::HandleTable;
using tonic::ToDart;

namespace flutter_runner {
Expand Down Expand Up @@ -196,7 +195,7 @@ void RuntimeHolder::CreateView(
std::move(view_listener), // view listener
std::move(export_token), // export token
script_uri // diagnostic label
);
);
app::ServiceProviderPtr view_services;
view_->GetServiceProvider(view_services.NewRequest());

Expand Down Expand Up @@ -365,15 +364,16 @@ void RuntimeHolder::InitFidlInternal() {
DART_CHECK_VALID(Dart_SetNativeResolver(
fidl_internal, fidl::dart::NativeLookup, fidl::dart::NativeSymbol));

HandleTable& handle_table = HandleTable::Current();
fidl::dart::Initialize();

DART_CHECK_VALID(
Dart_SetField(fidl_internal, ToDart("_environment"),
handle_table.AddAndWrap(environment.PassHandle())));
DART_CHECK_VALID(Dart_SetField(fidl_internal, ToDart("_environment"),
ToDart(fidl::dart::Handle::Create(
environment.PassHandle().release()))));

DART_CHECK_VALID(
Dart_SetField(fidl_internal, ToDart("_outgoingServices"),
handle_table.AddAndWrap(outgoing_services_.PassChannel())));
ToDart(fidl::dart::Handle::Create(
outgoing_services_.PassChannel().release()))));
}

void RuntimeHolder::InitMozartInternal() {
Expand All @@ -391,10 +391,9 @@ void RuntimeHolder::InitMozartInternal() {
DartConverter<uint64_t>::ToDart(reinterpret_cast<intptr_t>(
static_cast<mozart::NativesDelegate*>(this)))));

HandleTable& handle_table = HandleTable::Current();
DART_CHECK_VALID(
Dart_SetField(mozart_internal, ToDart("_viewContainer"),
handle_table.AddAndWrap(view_container.PassHandle())));
DART_CHECK_VALID(Dart_SetField(mozart_internal, ToDart("_viewContainer"),
ToDart(fidl::dart::Handle::Create(
view_container.PassHandle().release()))));
}

void RuntimeHolder::InitRootBundle(std::vector<char> bundle) {
Expand Down
1 change: 1 addition & 0 deletions flow/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ source_set("flow") {
deps += [
"//apps/mozart/lib/scene:client",
"//apps/mozart/services/scene",
"//lib/fidl/dart/sdk_ext",
]

public_deps = [
Expand Down
4 changes: 2 additions & 2 deletions flow/export_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

namespace flow {

ExportNode::ExportNode(uint32_t export_token_handle)
: export_token_(export_token_handle) {}
ExportNode::ExportNode(ftl::RefPtr<fidl::dart::Handle> export_token_handle)
: export_token_(export_token_handle->ReleaseHandle()) {}

ExportNode::~ExportNode() {
// TODO(MZ-190): Ensure the node is properly unregistered on the rasterizer
Expand Down
3 changes: 2 additions & 1 deletion flow/export_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "apps/mozart/lib/scene/client/resources.h"
#include "flutter/flow/scene_update_context.h"
#include "lib/fidl/dart/sdk_ext/src/handle.h"
#include "lib/ftl/build_config.h"
#include "lib/ftl/macros.h"
#include "lib/ftl/memory/ref_counted.h"
Expand All @@ -27,7 +28,7 @@ namespace flow {
// Therefore this object is thread-safe.
class ExportNode : public ftl::RefCountedThreadSafe<ExportNode> {
public:
ExportNode(uint32_t export_token_handle);
ExportNode(ftl::RefPtr<fidl::dart::Handle> export_token_handle);

// Binds the export token to the entity node and adds it as a child of
// the specified container.
Expand Down
1 change: 0 additions & 1 deletion lib/snapshot/fuchsia_compilation_trace.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,6 @@ dart:fidl.internal,HandleWaiter,asyncWait
dart:fidl.internal,HandleWaiter,cancelWait
dart:fidl.internal,HandleWaiter,_asyncWait
dart:fidl.internal,HandleWaiter,_cancelWait
dart:fidl.internal,HandleWaiter,onWaitComplete
dart:fidl.internal,HandleWaiter,get:_callback
dart:fidl.internal,HandleWaiter,set:_callback
dart:fidl.internal,MxStartupInfo,takeEnvironment
Expand Down
3 changes: 3 additions & 0 deletions lib/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,7 @@ source_set("ui") {
"//third_party/skia",
"//third_party/skia:gpu",
]
if (is_fuchsia) {
deps += [ "//lib/fidl/dart/sdk_ext" ]
}
}
8 changes: 6 additions & 2 deletions lib/ui/compositing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,15 @@ class SceneHost extends NativeFieldWrapperClass2 {
/// sending the corresponding import token (the other endpoint of the event pair)
/// to the child.
///
/// The export token is a dart:fidl.internal Handle, but that type isn't
/// available here. This is called by ChildViewConnection in
/// //apps/mozart/lib/flutter/.
///
/// The scene host takes ownership of the provided export token handle.
SceneHost(int export_token_handle) {
SceneHost(dynamic export_token_handle) {
_constructor(export_token_handle);
}
void _constructor(int export_token_handle) native "SceneHost_constructor";
void _constructor(dynamic export_token_handle) native "SceneHost_constructor";

/// Releases the resources associated with the child scene host.
///
Expand Down
23 changes: 15 additions & 8 deletions lib/ui/compositing/scene_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
#include "lib/tonic/dart_args.h"
#include "lib/tonic/dart_binding_macros.h"
#include "lib/tonic/dart_library_natives.h"
#include "lib/tonic/dart_wrappable.h"

#if defined(OS_FUCHSIA)
#include "lib/tonic/handle_table.h"
#ifdef OS_FUCHSIA
#include "lib/fidl/dart/sdk_ext/src/handle.h"
#endif

namespace blink {
Expand All @@ -29,16 +30,22 @@ void SceneHost::RegisterNatives(tonic::DartLibraryNatives* natives) {
FOR_EACH_BINDING(DART_REGISTER_NATIVE)});
}

ftl::RefPtr<SceneHost> SceneHost::create(int export_token_handle) {
#if defined(OS_FUCHSIA)
ftl::RefPtr<SceneHost> SceneHost::create(
ftl::RefPtr<fidl::dart::Handle> export_token_handle) {
return ftl::MakeRefCounted<SceneHost>(export_token_handle);
}

SceneHost::SceneHost(int export_token_handle) {
#if defined(OS_FUCHSIA)
export_node_ = ftl::MakeRefCounted<flow::ExportNode>(
tonic::HandleTable::Current().Unwrap(export_token_handle));
#endif
SceneHost::SceneHost(ftl::RefPtr<fidl::dart::Handle> export_token_handle) {
export_node_ = ftl::MakeRefCounted<flow::ExportNode>(export_token_handle);
}
#else
ftl::RefPtr<SceneHost> SceneHost::create(Dart_Handle export_token_handle) {
return ftl::MakeRefCounted<SceneHost>(export_token_handle);
}

SceneHost::SceneHost(Dart_Handle export_token_handle) {}
#endif

SceneHost::~SceneHost() {}

Expand Down
13 changes: 11 additions & 2 deletions lib/ui/compositing/scene_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ class SceneHost : public ftl::RefCountedThreadSafe<SceneHost>,
FRIEND_MAKE_REF_COUNTED(SceneHost);

public:
static ftl::RefPtr<SceneHost> create(int export_token_handle);
#if defined(OS_FUCHSIA)
static ftl::RefPtr<SceneHost> create(
ftl::RefPtr<fidl::dart::Handle> export_token_handle);
#else
static ftl::RefPtr<SceneHost> create(Dart_Handle export_token_handle);
#endif

~SceneHost() override;

Expand All @@ -44,7 +49,11 @@ class SceneHost : public ftl::RefCountedThreadSafe<SceneHost>,
ftl::RefPtr<flow::ExportNode> export_node_;
#endif

explicit SceneHost(int export_token_handle);
#if defined(OS_FUCHSIA)
explicit SceneHost(ftl::RefPtr<fidl::dart::Handle> export_token_handle);
#else
explicit SceneHost(Dart_Handle export_token_handle);
#endif
};

} // namespace blink
Expand Down
1 change: 0 additions & 1 deletion runtime/dart_vm_entry_points_fuchsia.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
dart:fidl.internal,::,_environment
dart:fidl.internal,::,_outgoingServices
dart:fidl.internal,HandleWaiter,onWaitComplete
dart:mozart.internal,::,_viewContainer
dart:mozart.internal,::,_context

0 comments on commit f08b084

Please sign in to comment.