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
2 changes: 1 addition & 1 deletion lib/ui/compositing/scene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void Scene::create(Dart_Handle scene_handle,
auto scene = fml::MakeRefCounted<Scene>(
std::move(rootLayer), rasterizerTracingThreshold,
checkerboardRasterCacheImages, checkerboardOffscreenLayers);
scene->ClaimDartHandle(scene_handle);
scene->AssociateWithDartWrapper(scene_handle);
}

Scene::Scene(std::shared_ptr<flutter::Layer> rootLayer,
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/painting/engine_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class EngineLayer : public RefCountedDartWrappable<EngineLayer> {
static void MakeRetained(Dart_Handle dart_handle,
std::shared_ptr<flutter::ContainerLayer> layer) {
auto engine_layer = fml::MakeRefCounted<EngineLayer>(layer);
engine_layer->ClaimDartHandle(dart_handle);
engine_layer->AssociateWithDartWrapper(dart_handle);
}

static void RegisterNatives(tonic::DartLibraryNatives* natives);
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/painting/picture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fml::RefPtr<Picture> Picture::Create(
flutter::SkiaGPUObject<SkPicture> picture) {
auto canvas_picture = fml::MakeRefCounted<Picture>(std::move(picture));

canvas_picture->ClaimDartHandle(dart_handle);
canvas_picture->AssociateWithDartWrapper(dart_handle);
return canvas_picture;
}

Expand Down
12 changes: 11 additions & 1 deletion third_party/tonic/dart_args.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 1 addition & 24 deletions third_party/tonic/dart_wrappable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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<intptr_t>(this))));
TONIC_CHECK(!LogIfError(Dart_SetNativeInstanceField(
wrapper, kWrapperInfoIndex, reinterpret_cast<intptr_t>(&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_);
Expand Down
6 changes: 3 additions & 3 deletions third_party/tonic/dart_wrappable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }

Expand Down