Flutter Engine
flutter::ImmutableBuffer Class Reference

#include <immutable_buffer.h>

Inheritance diagram for flutter::ImmutableBuffer:
flutter::RefCountedDartWrappable< ImmutableBuffer > fml::RefCountedThreadSafe< ImmutableBuffer > tonic::DartWrappable fml::internal::RefCountedThreadSafeBase

Public Member Functions

 ~ImmutableBuffer () override
size_t length () const
 The length of the data in bytes. More...
sk_sp< SkData > data () const
 Callers should not modify the returned data. This is not exposed to Dart. More...
void dispose ()
size_t GetAllocationSize () const override
- Public Member Functions inherited from flutter::RefCountedDartWrappable< ImmutableBuffer >
virtual void RetainDartWrappableReference () const override
virtual void ReleaseDartWrappableReference () const override
- Public Member Functions inherited from fml::RefCountedThreadSafe< ImmutableBuffer >
void Release () const
- Public Member Functions inherited from fml::internal::RefCountedThreadSafeBase
void AddRef () const
bool HasOneRef () const
void AssertHasOneRef () const
- Public Member Functions inherited from tonic::DartWrappable
 DartWrappable ()
virtual const DartWrapperInfoGetDartWrapperInfo () const =0
Dart_Handle CreateDartWrapper (DartState *dart_state)
void AssociateWithDartWrapper (Dart_Handle wrappable)
void ClearDartWrapper ()
Dart_WeakPersistentHandle dart_wrapper () const

Static Public Member Functions

static void init (Dart_NativeArguments args)
static void RegisterNatives (tonic::DartLibraryNatives *natives)

Additional Inherited Members

- Public Types inherited from tonic::DartWrappable
enum  DartNativeFields {
- Protected Member Functions inherited from fml::RefCountedThreadSafe< ImmutableBuffer >
 RefCountedThreadSafe ()
 ~RefCountedThreadSafe ()
- Protected Member Functions inherited from fml::internal::RefCountedThreadSafeBase
 RefCountedThreadSafeBase ()
 ~RefCountedThreadSafeBase ()
bool Release () const
void Adopt ()
- Protected Member Functions inherited from tonic::DartWrappable
virtual ~DartWrappable ()
- Static Protected Member Functions inherited from tonic::DartWrappable
static Dart_PersistentHandle GetTypeForWrapper (tonic::DartState *dart_state, const tonic::DartWrapperInfo &wrapper_info)

Detailed Description

A simple opaque handle to an immutable byte buffer suitable for use internally by the engine.

This data is not known by the Dart VM.

It is expected that C++ users of this object will not modify the data argument. No Dart side calls are provided to do so.

Definition at line 27 of file immutable_buffer.h.

Constructor & Destructor Documentation

◆ ~ImmutableBuffer()

flutter::ImmutableBuffer::~ImmutableBuffer ( )

Definition at line 28 of file immutable_buffer.cc.

28 {}

Member Function Documentation

◆ data()

sk_sp<SkData> flutter::ImmutableBuffer::data ( ) const

Callers should not modify the returned data. This is not exposed to Dart.

Definition at line 49 of file immutable_buffer.h.

Referenced by dispose(), GetAllocationSize(), init(), and flutter::ImageDescriptor::initEncoded().

49 { return data_; }

◆ dispose()

void flutter::ImmutableBuffer::dispose ( )

Clears the Dart native fields and removes the reference to the underlying byte buffer.

The byte buffer will continue to live if other objects hold a reference to it.

Definition at line 56 of file immutable_buffer.h.

References tonic::DartWrappable::ClearDartWrapper(), data(), GetAllocationSize(), length(), and RegisterNatives().

56  {
58  data_.reset();
59  }

◆ GetAllocationSize()

size_t flutter::ImmutableBuffer::GetAllocationSize ( ) const

Reimplemented from tonic::DartWrappable.

Definition at line 52 of file immutable_buffer.cc.

References data(), FML_DCHECK, FML_LOG, and length().

Referenced by dispose().

52  {
53  return sizeof(ImmutableBuffer) + data_->size();
54 }

◆ init()

void flutter::ImmutableBuffer::init ( Dart_NativeArguments  args)

Initializes a new ImmutableData from a Dart Uint8List.

The zero indexed argument is the the caller that will be registered as the Dart peer of the native ImmutableBuffer object.

The first indexed argumented is a tonic::Uint8List of bytes to copy.

The second indexed argument is expected to be a void callback to signal when the copy has completed.

Definition at line 35 of file immutable_buffer.cc.

References tonic::DartInvoke(), data(), and tonic::ToDart().

Referenced by RegisterNatives().

35  {
36  Dart_Handle callback_handle = Dart_GetNativeArgument(args, 2);
37  if (!Dart_IsClosure(callback_handle)) {
38  Dart_SetReturnValue(args, tonic::ToDart("Callback must be a function"));
39  return;
40  }
42  Dart_Handle buffer_handle = Dart_GetNativeArgument(args, 0);
43  tonic::Uint8List data = tonic::Uint8List(Dart_GetNativeArgument(args, 1));
45  auto sk_data = MakeSkDataWithCopy(data.data(), data.num_elements());
46  data.Release();
47  auto buffer = fml::MakeRefCounted<ImmutableBuffer>(sk_data);
48  buffer->AssociateWithDartWrapper(buffer_handle);
49  tonic::DartInvoke(callback_handle, {Dart_TypeVoid()});
50 }
G_BEGIN_DECLS FlValue * args
sk_sp< SkData > data() const
Callers should not modify the returned data. This is not exposed to Dart.
Dart_Handle DartInvoke(Dart_Handle closure, std::initializer_list< Dart_Handle > args)
Definition: dart_invoke.cc:20
Dart_Handle ToDart(const T &object)

◆ length()

size_t flutter::ImmutableBuffer::length ( ) const

The length of the data in bytes.

Definition at line 43 of file immutable_buffer.h.

References FML_DCHECK.

Referenced by dispose(), and GetAllocationSize().

43  {
44  FML_DCHECK(data_);
45  return data_->size();
46  }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ RegisterNatives()

void flutter::ImmutableBuffer::RegisterNatives ( tonic::DartLibraryNatives natives)

Definition at line 30 of file immutable_buffer.cc.

References DART_REGISTER_NATIVE, FOR_EACH_BINDING, init(), and tonic::DartLibraryNatives::Register().

Referenced by dispose(), and flutter::DartUI::InitForGlobal().

30  {
31  natives->Register({{"ImmutableBuffer_init", ImmutableBuffer::init, 3, true},
33 }
void Register(std::initializer_list< Entry > entries)
static void init(Dart_NativeArguments args)

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