diff --git a/lib/ui/compositing/scene.cc b/lib/ui/compositing/scene.cc index b5d3e51b2492e..f5403ecae9a61 100644 --- a/lib/ui/compositing/scene.cc +++ b/lib/ui/compositing/scene.cc @@ -34,7 +34,7 @@ void Scene::create(Dart_Handle scene_handle, auto scene = fml::MakeRefCounted( std::move(rootLayer), rasterizerTracingThreshold, checkerboardRasterCacheImages, checkerboardOffscreenLayers); - scene->ClaimDartHandle(scene_handle); + scene->AssociateWithDartWrapper(scene_handle); } Scene::Scene(std::shared_ptr rootLayer, diff --git a/lib/ui/painting/engine_layer.h b/lib/ui/painting/engine_layer.h index 29dc42844b636..8e402ba9150f5 100644 --- a/lib/ui/painting/engine_layer.h +++ b/lib/ui/painting/engine_layer.h @@ -33,7 +33,7 @@ class EngineLayer : public RefCountedDartWrappable { static void MakeRetained(Dart_Handle dart_handle, std::shared_ptr layer) { auto engine_layer = fml::MakeRefCounted(layer); - engine_layer->ClaimDartHandle(dart_handle); + engine_layer->AssociateWithDartWrapper(dart_handle); } static void RegisterNatives(tonic::DartLibraryNatives* natives); diff --git a/lib/ui/painting/picture.cc b/lib/ui/painting/picture.cc index b030f634322f6..8527b83ec139b 100644 --- a/lib/ui/painting/picture.cc +++ b/lib/ui/painting/picture.cc @@ -31,7 +31,7 @@ fml::RefPtr Picture::Create( flutter::SkiaGPUObject picture) { auto canvas_picture = fml::MakeRefCounted(std::move(picture)); - canvas_picture->ClaimDartHandle(dart_handle); + canvas_picture->AssociateWithDartWrapper(dart_handle); return canvas_picture; } diff --git a/third_party/tonic/dart_args.h b/third_party/tonic/dart_args.h index 3d6f9ddd5908a..96a5b2c5b0f17 100644 --- a/third_party/tonic/dart_args.h +++ b/third_party/tonic/dart_args.h @@ -226,7 +226,17 @@ void DartCallConstructor(Sig func, Dart_NativeArguments args) { return; wrappable = decoder.DispatchCtor(func); } - wrappable->AssociateWithDartWrapper(args); + + Dart_Handle wrapper = Dart_GetNativeArgument(args, 0); + TONIC_CHECK(!LogIfError(wrapper)); + + intptr_t native_fields[DartWrappable::kNumberOfNativeFields]; + TONIC_CHECK(!LogIfError(Dart_GetNativeFieldsOfArgument( + args, 0, DartWrappable::kNumberOfNativeFields, native_fields))); + TONIC_CHECK(!native_fields[DartWrappable::kPeerIndex]); + TONIC_CHECK(!native_fields[DartWrappable::kWrapperInfoIndex]); + + wrappable->AssociateWithDartWrapper(wrapper); } } // namespace tonic diff --git a/third_party/tonic/dart_wrappable.cc b/third_party/tonic/dart_wrappable.cc index 72d264a62fb54..4ebfda7e1a362 100644 --- a/third_party/tonic/dart_wrappable.cc +++ b/third_party/tonic/dart_wrappable.cc @@ -42,7 +42,7 @@ Dart_Handle DartWrappable::CreateDartWrapper(DartState* dart_state) { return wrapper; } -void DartWrappable::ClaimDartHandle(Dart_Handle wrapper) { +void DartWrappable::AssociateWithDartWrapper(Dart_Handle wrapper) { TONIC_DCHECK(!dart_wrapper_); TONIC_CHECK(!LogIfError(wrapper)); @@ -58,29 +58,6 @@ void DartWrappable::ClaimDartHandle(Dart_Handle wrapper) { wrapper, this, GetAllocationSize(), &FinalizeDartWrapper); } -void DartWrappable::AssociateWithDartWrapper(Dart_NativeArguments args) { - TONIC_DCHECK(!dart_wrapper_); - - Dart_Handle wrapper = Dart_GetNativeArgument(args, 0); - TONIC_CHECK(!LogIfError(wrapper)); - - intptr_t native_fields[kNumberOfNativeFields]; - TONIC_CHECK(!LogIfError(Dart_GetNativeFieldsOfArgument( - args, 0, kNumberOfNativeFields, native_fields))); - TONIC_CHECK(!native_fields[kPeerIndex]); - TONIC_CHECK(!native_fields[kWrapperInfoIndex]); - - const DartWrapperInfo& info = GetDartWrapperInfo(); - TONIC_CHECK(!LogIfError(Dart_SetNativeInstanceField( - wrapper, kPeerIndex, reinterpret_cast(this)))); - TONIC_CHECK(!LogIfError(Dart_SetNativeInstanceField( - wrapper, kWrapperInfoIndex, reinterpret_cast(&info)))); - - this->RetainDartWrappableReference(); // Balanced in FinalizeDartWrapper. - dart_wrapper_ = Dart_NewWeakPersistentHandle( - wrapper, this, GetAllocationSize(), &FinalizeDartWrapper); -} - void DartWrappable::ClearDartWrapper() { TONIC_DCHECK(dart_wrapper_); Dart_Handle wrapper = Dart_HandleFromWeakPersistent(dart_wrapper_); diff --git a/third_party/tonic/dart_wrappable.h b/third_party/tonic/dart_wrappable.h index 8d9fb569916b7..1d2e5e75bacb2 100644 --- a/third_party/tonic/dart_wrappable.h +++ b/third_party/tonic/dart_wrappable.h @@ -44,10 +44,10 @@ class DartWrappable { virtual void ReleaseDartWrappableReference() const = 0; // Use this method sparingly. It follows a slower path using Dart_New. - // Prefer constructing the object in Dart code and using ClaimDartHandle. + // Prefer constructing the object in Dart code and using + // AssociateWithDartWrapper. Dart_Handle CreateDartWrapper(DartState* dart_state); - void ClaimDartHandle(Dart_Handle wrappable); - void AssociateWithDartWrapper(Dart_NativeArguments args); + void AssociateWithDartWrapper(Dart_Handle wrappable); void ClearDartWrapper(); // Warning: Might delete this. Dart_WeakPersistentHandle dart_wrapper() const { return dart_wrapper_; }