mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Refactor of ClaimDartHandle -> AssociateWithDartWrapper (#16720)
This commit is contained in:
parent
4aaafe0d28
commit
e18aba3321
@ -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,
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
12
third_party/tonic/dart_args.h
vendored
12
third_party/tonic/dart_args.h
vendored
@ -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
|
||||
|
||||
25
third_party/tonic/dart_wrappable.cc
vendored
25
third_party/tonic/dart_wrappable.cc
vendored
@ -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<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_);
|
||||
|
||||
6
third_party/tonic/dart_wrappable.h
vendored
6
third_party/tonic/dart_wrappable.h
vendored
@ -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_; }
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user