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< Paragraph > flutter::RefCountedDartWrappable< ParagraphBuilder > flutter::RefCountedDartWrappable< Picture > flutter::RefCountedDartWrappable< PictureRecorder > flutter::RefCountedDartWrappable< Scene > flutter::RefCountedDartWrappable< SceneBuilder > flutter::RefCountedDartWrappable< SceneHost > flutter::RefCountedDartWrappable< SemanticsUpdate > flutter::RefCountedDartWrappable< SemanticsUpdateBuilder > flutter::RefCountedDartWrappable< Shader > flutter::RefCountedDartWrappable< Vertices > zircon::dart::Handle zircon::dart::HandleWaiter zircon::dart::System

Public Types

enum  DartNativeFields {
  kPeerIndex,
  kWrapperInfoIndex,
  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 21 of file dart_wrappable.h.

Member Enumeration Documentation

◆ DartNativeFields

Enumerator
kPeerIndex 
kWrapperInfoIndex 
kNumberOfNativeFields 

Definition at line 23 of file dart_wrappable.h.

Constructor & Destructor Documentation

◆ DartWrappable()

tonic::DartWrappable::DartWrappable ( )
inline

◆ ~DartWrappable()

tonic::DartWrappable::~DartWrappable ( )
protectedvirtual

Definition at line 14 of file dart_wrappable.cc.

References TONIC_CHECK.

Referenced by dart_wrapper().

14  {
15  TONIC_CHECK(!dart_wrapper_);
16 }
#define TONIC_CHECK(condition)
Definition: macros.h:23

Member Function Documentation

◆ AssociateWithDartWrapper()

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

Definition at line 45 of file dart_wrappable.cc.

References GetAllocationSize(), GetDartWrapperInfo(), kPeerIndex, kWrapperInfoIndex, tonic::LogIfError(), RetainDartWrappableReference(), TONIC_CHECK, and TONIC_DCHECK.

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

45  {
46  TONIC_DCHECK(!dart_wrapper_);
47  TONIC_CHECK(!LogIfError(wrapper));
48 
49  const DartWrapperInfo& info = GetDartWrapperInfo();
50 
51  TONIC_CHECK(!LogIfError(Dart_SetNativeInstanceField(
52  wrapper, kPeerIndex, reinterpret_cast<intptr_t>(this))));
53  TONIC_CHECK(!LogIfError(Dart_SetNativeInstanceField(
54  wrapper, kWrapperInfoIndex, reinterpret_cast<intptr_t>(&info))));
55 
56  this->RetainDartWrappableReference(); // Balanced in FinalizeDartWrapper.
57  dart_wrapper_ = Dart_NewWeakPersistentHandle(
58  wrapper, this, GetAllocationSize(), &FinalizeDartWrapper);
59 }
virtual const DartWrapperInfo & GetDartWrapperInfo() const =0
#define TONIC_DCHECK
Definition: macros.h:32
virtual void RetainDartWrappableReference() const =0
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 61 of file dart_wrappable.cc.

References kPeerIndex, kWrapperInfoIndex, tonic::LogIfError(), ReleaseDartWrappableReference(), TONIC_CHECK, and TONIC_DCHECK.

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

61  {
62  TONIC_DCHECK(dart_wrapper_);
63  Dart_Handle wrapper = Dart_HandleFromWeakPersistent(dart_wrapper_);
64  TONIC_CHECK(!LogIfError(Dart_SetNativeInstanceField(wrapper, kPeerIndex, 0)));
66  !LogIfError(Dart_SetNativeInstanceField(wrapper, kWrapperInfoIndex, 0)));
67  Dart_DeleteWeakPersistentHandle(dart_wrapper_);
68  dart_wrapper_ = nullptr;
70 }
#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(), GetAllocationSize(), tonic::DartClassLibrary::GetClass(), GetDartWrapperInfo(), kPeerIndex, kWrapperInfoIndex, tonic::LogIfError(), tonic::DartState::private_constructor_name(), RetainDartWrappableReference(), and TONIC_DCHECK.

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  TONIC_DCHECK(!dart_wrapper_);
21  const DartWrapperInfo& info = GetDartWrapperInfo();
22 
23  Dart_PersistentHandle type = dart_state->class_library().GetClass(info);
24  TONIC_DCHECK(!LogIfError(type));
25 
26  Dart_Handle wrapper =
27  Dart_New(type, dart_state->private_constructor_name(), 0, nullptr);
28 
29  TONIC_DCHECK(!LogIfError(wrapper));
30 
31  Dart_Handle res = Dart_SetNativeInstanceField(
32  wrapper, kPeerIndex, reinterpret_cast<intptr_t>(this));
33  TONIC_DCHECK(!LogIfError(res));
34  res = Dart_SetNativeInstanceField(wrapper, kWrapperInfoIndex,
35  reinterpret_cast<intptr_t>(&info));
36  TONIC_DCHECK(!LogIfError(res));
37 
38  this->RetainDartWrappableReference(); // Balanced in FinalizeDartWrapper.
39  dart_wrapper_ = Dart_NewWeakPersistentHandle(
40  wrapper, this, GetAllocationSize(), &FinalizeDartWrapper);
41 
42  return wrapper;
43 }
virtual const DartWrapperInfo & GetDartWrapperInfo() const =0
#define TONIC_DCHECK
Definition: macros.h:32
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:58

◆ ReleaseDartWrappableReference()

◆ RetainDartWrappableReference()


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