Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
tonic::DartByteData Class Reference

#include <dart_byte_data.h>

Public Member Functions

 DartByteData (Dart_Handle list)
 
 DartByteData (DartByteData &&other)
 
 DartByteData ()
 
 ~DartByteData ()
 
const void * data () const
 
void * data ()
 
size_t length_in_bytes () const
 
Dart_Handle dart_handle () const
 
std::vector< char > Copy () const
 
void Release () const
 
 operator bool () const
 

Static Public Member Functions

static Dart_Handle Create (const void *data, size_t length)
 

Static Public Attributes

static const size_t kExternalSizeThreshold = 1000
 

Detailed Description

Definition at line 15 of file dart_byte_data.h.

Constructor & Destructor Documentation

◆ DartByteData() [1/3]

tonic::DartByteData::DartByteData ( Dart_Handle  list)
explicit

Definition at line 57 of file dart_byte_data.cc.

58 : data_(nullptr), length_in_bytes_(0), dart_handle_(list) {
59 if (Dart_IsNull(list))
60 return;
61
63 Dart_TypedDataAcquireData(list, &type, &data_, &length_in_bytes_);
66 Dart_ThrowException(ToDart("Non-genuine ByteData passed to engine."));
67}
GLenum type
DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object, Dart_TypedData_Type *type, void **data, intptr_t *len)
DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception)
Dart_TypedData_Type
Definition: dart_api.h:2612
@ Dart_TypedData_kByteData
Definition: dart_api.h:2613
DART_EXPORT bool Dart_IsNull(Dart_Handle object)
Dart_Handle ToDart(const T &object)
bool CheckAndHandleError(Dart_Handle handle)
Definition: dart_error.cc:33
#define TONIC_DCHECK
Definition: macros.h:32

◆ DartByteData() [2/3]

tonic::DartByteData::DartByteData ( DartByteData &&  other)

Definition at line 69 of file dart_byte_data.cc.

70 : data_(other.data_),
71 length_in_bytes_(other.length_in_bytes_),
72 dart_handle_(other.dart_handle_) {
73 other.data_ = nullptr;
74 other.dart_handle_ = nullptr;
75}

◆ DartByteData() [3/3]

tonic::DartByteData::DartByteData ( )

Definition at line 39 of file dart_byte_data.cc.

40 : data_(nullptr), length_in_bytes_(0), dart_handle_(nullptr) {}

◆ ~DartByteData()

tonic::DartByteData::~DartByteData ( )

Definition at line 77 of file dart_byte_data.cc.

77 {
78 Release();
79}
void Release() const

Member Function Documentation

◆ Copy()

std::vector< char > tonic::DartByteData::Copy ( ) const

Definition at line 81 of file dart_byte_data.cc.

81 {
82 const char* ptr = static_cast<const char*>(data_);
83 return std::vector<char>(ptr, ptr + length_in_bytes_);
84}

◆ Create()

Dart_Handle tonic::DartByteData::Create ( const void *  data,
size_t  length 
)
static

Definition at line 25 of file dart_byte_data.cc.

25 {
27 auto handle = DartByteData{data, length}.dart_handle();
28 // The destructor should release the typed data.
29 return handle;
30 } else {
31 void* buf = ::malloc(length);
32 TONIC_DCHECK(buf);
33 ::memcpy(buf, data, length);
36 }
37}
static const size_t kExternalSizeThreshold
const void * data() const
DART_EXPORT Dart_Handle Dart_NewExternalTypedDataWithFinalizer(Dart_TypedData_Type type, void *data, intptr_t length, void *peer, intptr_t external_allocation_size, Dart_HandleFinalizer callback)
size_t length
void * malloc(size_t size)
Definition: allocation.cc:19
DART_EXPORT void FreeFinalizer(void *, void *value)

◆ dart_handle()

Dart_Handle tonic::DartByteData::dart_handle ( ) const
inline

Definition at line 28 of file dart_byte_data.h.

28{ return dart_handle_; }

◆ data() [1/2]

void * tonic::DartByteData::data ( )
inline

Definition at line 26 of file dart_byte_data.h.

26{ return data_; }

◆ data() [2/2]

const void * tonic::DartByteData::data ( ) const
inline

Definition at line 25 of file dart_byte_data.h.

25{ return data_; }

◆ length_in_bytes()

size_t tonic::DartByteData::length_in_bytes ( ) const
inline

Definition at line 27 of file dart_byte_data.h.

27{ return length_in_bytes_; }

◆ operator bool()

tonic::DartByteData::operator bool ( ) const
inlineexplicit

Definition at line 33 of file dart_byte_data.h.

33{ return data_ != nullptr; }

◆ Release()

void tonic::DartByteData::Release ( ) const

Definition at line 86 of file dart_byte_data.cc.

86 {
87 if (data_) {
88 Dart_TypedDataReleaseData(dart_handle_);
89 data_ = nullptr;
90 }
91}
DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object)

Member Data Documentation

◆ kExternalSizeThreshold

const size_t tonic::DartByteData::kExternalSizeThreshold = 1000
static

Definition at line 17 of file dart_byte_data.h.


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