Flutter Engine
tonic::DartWrappable Class Referenceabstract

#include <dart_wrappable.h>

Inheritance diagram for tonic::DartWrappable:
flutter::RefCountedDartWrappable< T > flutter::RefCountedDartWrappable< Canvas > flutter::RefCountedDartWrappable< CanvasImage > flutter::RefCountedDartWrappable< CanvasPath > flutter::RefCountedDartWrappable< CanvasPathMeasure > flutter::RefCountedDartWrappable< Codec > flutter::RefCountedDartWrappable< ColorFilter > flutter::RefCountedDartWrappable< EngineLayer > flutter::RefCountedDartWrappable< ImageDescriptor > flutter::RefCountedDartWrappable< ImageFilter > flutter::RefCountedDartWrappable< ImmutableBuffer > flutter::RefCountedDartWrappable< NativeStringAttribute > flutter::RefCountedDartWrappable< Paragraph > flutter::RefCountedDartWrappable< ParagraphBuilder > flutter::RefCountedDartWrappable< Picture > flutter::RefCountedDartWrappable< PictureRecorder > flutter::RefCountedDartWrappable< Scene > flutter::RefCountedDartWrappable< SceneBuilder > flutter::RefCountedDartWrappable< SemanticsUpdate > flutter::RefCountedDartWrappable< SemanticsUpdateBuilder > flutter::RefCountedDartWrappable< Shader > flutter::RefCountedDartWrappable< Vertices > zircon::dart::Handle zircon::dart::HandleDisposition zircon::dart::HandleWaiter zircon::dart::System

Public Types

enum  DartNativeFields {
  kPeerIndex,
  kNumberOfNativeFields
}
 

Public Member Functions

 DartWrappable ()
 
virtual const DartWrapperInfoGetDartWrapperInfo () const =0
 
virtual size_t GetAllocationSize () const
 
virtual void RetainDartWrappableReference () const =0
 
virtual void ReleaseDartWrappableReference () const =0
 
Dart_Handle CreateDartWrapper (DartState *dart_state)
 
void AssociateWithDartWrapper (Dart_Handle wrappable)
 
void ClearDartWrapper ()
 
Dart_WeakPersistentHandle dart_wrapper () const
 

Protected Member Functions

virtual ~DartWrappable ()
 

Static Protected Member Functions

static Dart_PersistentHandle GetTypeForWrapper (tonic::DartState *dart_state, const tonic::DartWrapperInfo &wrapper_info)
 

Detailed Description

Definition at line 22 of file dart_wrappable.h.

Member Enumeration Documentation

◆ DartNativeFields

Enumerator
kPeerIndex 
kNumberOfNativeFields 

Definition at line 24 of file dart_wrappable.h.

24  {
25  kPeerIndex, // Must be first to work with Dart_GetNativeReceiver.
27  };

Constructor & Destructor Documentation

◆ DartWrappable()

tonic::DartWrappable::DartWrappable ( )
inline

◆ ~DartWrappable()

tonic::DartWrappable::~DartWrappable ( )
protectedvirtual

Definition at line 14 of file dart_wrappable.cc.

Referenced by dart_wrapper().

14  {
15  // Calls the destructor of dart_wrapper_ to delete WeakPersistentHandle.
16 }

Member Function Documentation

◆ AssociateWithDartWrapper()

void tonic::DartWrappable::AssociateWithDartWrapper ( Dart_Handle  wrappable)

Definition at line 47 of file dart_wrappable.cc.

References tonic::DartWeakPersistentValue::Clear(), tonic::DartState::Current(), tonic::DartWeakPersistentValue::Get(), GetAllocationSize(), tonic::DartWeakPersistentValue::is_empty(), kPeerIndex, tonic::LogIfError(), RetainDartWrappableReference(), tonic::DartWeakPersistentValue::Set(), TONIC_CHECK, and TONIC_DCHECK.

Referenced by flutter::SemanticsUpdate::create(), flutter::Scene::create(), flutter::Picture::Create(), and DartWrappable().

47  {
48  if (!dart_wrapper_.is_empty()) {
49  // Any previously given out wrapper must have been GCed.
50  TONIC_DCHECK(Dart_IsNull(dart_wrapper_.Get()));
51  dart_wrapper_.Clear();
52  }
53 
54  TONIC_CHECK(!LogIfError(wrapper));
55 
56  TONIC_CHECK(!LogIfError(Dart_SetNativeInstanceField(
57  wrapper, kPeerIndex, reinterpret_cast<intptr_t>(this))));
58 
59  this->RetainDartWrappableReference(); // Balanced in FinalizeDartWrapper.
60 
61  DartState* dart_state = DartState::Current();
62  dart_wrapper_.Set(dart_state, wrapper, this, GetAllocationSize(),
63  &FinalizeDartWrapper);
64 }
#define TONIC_DCHECK
Definition: macros.h:32
void Set(DartState *dart_state, Dart_Handle object, void *peer, intptr_t external_allocation_size, Dart_HandleFinalizer callback)
virtual void RetainDartWrappableReference() const =0
static DartState * Current()
Definition: dart_state.cc:56
virtual size_t GetAllocationSize() const
#define TONIC_CHECK(condition)
Definition: macros.h:23
bool LogIfError(Dart_Handle handle)
Definition: dart_error.cc:15

◆ ClearDartWrapper()

void tonic::DartWrappable::ClearDartWrapper ( )

Definition at line 66 of file dart_wrappable.cc.

References tonic::DartWeakPersistentValue::Clear(), tonic::DartWeakPersistentValue::Get(), tonic::DartWeakPersistentValue::is_empty(), kPeerIndex, tonic::LogIfError(), ReleaseDartWrappableReference(), TONIC_CHECK, and TONIC_DCHECK.

Referenced by flutter::SceneBuilder::build(), DartWrappable(), flutter::SemanticsUpdate::dispose(), flutter::CanvasImage::dispose(), flutter::Scene::dispose(), flutter::Picture::dispose(), flutter::ImmutableBuffer::dispose(), flutter::ImageDescriptor::dispose(), flutter::PictureRecorder::endRecording(), and flutter::Canvas::Invalidate().

66  {
67  TONIC_DCHECK(!dart_wrapper_.is_empty());
68  Dart_Handle wrapper = dart_wrapper_.Get();
69  TONIC_CHECK(!LogIfError(Dart_SetNativeInstanceField(wrapper, kPeerIndex, 0)));
70  dart_wrapper_.Clear();
72 }
#define TONIC_DCHECK
Definition: macros.h:32
#define TONIC_CHECK(condition)
Definition: macros.h:23
bool LogIfError(Dart_Handle handle)
Definition: dart_error.cc:15
virtual void ReleaseDartWrappableReference() const =0

◆ CreateDartWrapper()

Dart_Handle tonic::DartWrappable::CreateDartWrapper ( DartState dart_state)

Definition at line 19 of file dart_wrappable.cc.

References tonic::DartState::class_library(), tonic::DartWeakPersistentValue::Clear(), tonic::DartWeakPersistentValue::Get(), GetAllocationSize(), tonic::DartClassLibrary::GetClass(), GetDartWrapperInfo(), tonic::DartWeakPersistentValue::is_empty(), kPeerIndex, tonic::LogIfError(), tonic::DartState::private_constructor_name(), RetainDartWrappableReference(), tonic::DartWeakPersistentValue::Set(), TONIC_DCHECK, and type.

Referenced by DartWrappable(), tonic::DartConverter< T *, typename std::enable_if< std::is_convertible< T *, const DartWrappable * >::value >::type >::SetReturnValue(), and tonic::DartConverter< T *, typename std::enable_if< std::is_convertible< T *, const DartWrappable * >::value >::type >::ToDart().

19  {
20  if (!dart_wrapper_.is_empty()) {
21  // Any previously given out wrapper must have been GCed.
22  TONIC_DCHECK(Dart_IsNull(dart_wrapper_.Get()));
23  dart_wrapper_.Clear();
24  }
25 
26  const DartWrapperInfo& info = GetDartWrapperInfo();
27 
28  Dart_PersistentHandle type = dart_state->class_library().GetClass(info);
29  TONIC_DCHECK(!LogIfError(type));
30 
31  Dart_Handle wrapper =
32  Dart_New(type, dart_state->private_constructor_name(), 0, nullptr);
33 
34  TONIC_DCHECK(!LogIfError(wrapper));
35 
36  Dart_Handle res = Dart_SetNativeInstanceField(
37  wrapper, kPeerIndex, reinterpret_cast<intptr_t>(this));
38  TONIC_DCHECK(!LogIfError(res));
39 
40  this->RetainDartWrappableReference(); // Balanced in FinalizeDartWrapper.
41  dart_wrapper_.Set(dart_state, wrapper, this, GetAllocationSize(),
42  &FinalizeDartWrapper);
43 
44  return wrapper;
45 }
KeyCallType type
virtual const DartWrapperInfo & GetDartWrapperInfo() const =0
#define TONIC_DCHECK
Definition: macros.h:32
void Set(DartState *dart_state, Dart_Handle object, void *peer, intptr_t external_allocation_size, Dart_HandleFinalizer callback)
virtual void RetainDartWrappableReference() const =0
virtual size_t GetAllocationSize() const
bool LogIfError(Dart_Handle handle)
Definition: dart_error.cc:15

◆ dart_wrapper()

◆ GetAllocationSize()

size_t tonic::DartWrappable::GetAllocationSize ( ) const
virtual

◆ GetDartWrapperInfo()

virtual const DartWrapperInfo& tonic::DartWrappable::GetDartWrapperInfo ( ) const
pure virtual

◆ GetTypeForWrapper()

Dart_PersistentHandle tonic::DartWrappable::GetTypeForWrapper ( tonic::DartState dart_state,
const tonic::DartWrapperInfo wrapper_info 
)
staticprotected

Definition at line 84 of file dart_wrappable.cc.

References tonic::DartState::class_library(), and tonic::DartClassLibrary::GetClass().

Referenced by dart_wrapper().

86  {
87  return dart_state->class_library().GetClass(wrapper_info);
88 }
Dart_PersistentHandle GetClass(const DartWrapperInfo &info)
DartClassLibrary & class_library()
Definition: dart_state.h:59

◆ ReleaseDartWrappableReference()

◆ RetainDartWrappableReference()


The documentation for this class was generated from the following files: