Flutter Engine
 
Loading...
Searching...
No Matches
flutter::DisplayListStorage Class Reference

#include <dl_storage.h>

Public Member Functions

 DisplayListStorage ()=default
 
 DisplayListStorage (DisplayListStorage &&)
 
uint8_t * base ()
 Returns a pointer to the base of the storage.
 
const uint8_t * base () const
 
size_t size () const
 Returns the currently allocated size.
 
size_t capacity () const
 Returns the maximum currently allocated space.
 
uint8_t * allocate (size_t needed)
 
void trim ()
 
void reset ()
 Resets the storage and allocation of the object to an empty state.
 
DisplayListStorageoperator= (DisplayListStorage &&other)
 

Static Public Member Functions

static size_t NextPowerOfTwoSize (size_t x)
 Compute the next power of two from [x].
 

Static Public Attributes

static const constexpr size_t kDLPageSize = 4096u
 

Detailed Description

Definition at line 15 of file dl_storage.h.

Constructor & Destructor Documentation

◆ DisplayListStorage() [1/2]

flutter::DisplayListStorage::DisplayListStorage ( )
default

◆ DisplayListStorage() [2/2]

flutter::DisplayListStorage::DisplayListStorage ( DisplayListStorage &&  source)

Definition at line 60 of file dl_storage.cc.

60 {
61 ptr_ = std::move(source.ptr_);
62 used_ = source.used_;
63 allocated_ = source.allocated_;
64 source.used_ = 0u;
65 source.allocated_ = 0u;
66}

Member Function Documentation

◆ allocate()

uint8_t * flutter::DisplayListStorage::allocate ( size_t  needed)

Ensures the indicated number of bytes are available and returns a pointer to that memory within the storage while also invalidating any other outstanding pointers into the storage.

Definition at line 39 of file dl_storage.cc.

39 {
40 if (used_ + needed > allocated_) {
41 static_assert(is_power_of_two(kDLPageSize),
42 "This math needs updating for non-pow2.");
43
44 // NPOT, with minimum size of kDLPageSize.
45 size_t new_size = std::max(NextPowerOfTwoSize(used_ + needed), kDLPageSize);
46 size_t old_size = allocated_;
47 realloc(new_size);
48 FML_CHECK(ptr_.get());
49 FML_CHECK(allocated_ == new_size);
50 FML_CHECK(allocated_ >= old_size);
51 FML_CHECK(used_ + needed <= allocated_);
52 memset(ptr_.get() + used_, 0, allocated_ - old_size);
53 }
54 uint8_t* ret = ptr_.get() + used_;
55 used_ += needed;
56 FML_CHECK(used_ <= allocated_);
57 return ret;
58}
static size_t NextPowerOfTwoSize(size_t x)
Compute the next power of two from [x].
Definition dl_storage.cc:14
static const constexpr size_t kDLPageSize
Definition dl_storage.h:17
#define FML_CHECK(condition)
Definition logging.h:104
static constexpr bool is_power_of_two(int value)
Definition dl_storage.cc:9

References FML_CHECK, flutter::is_power_of_two(), kDLPageSize, and NextPowerOfTwoSize().

Referenced by flutter::testing::TEST(), and flutter::testing::TEST().

◆ base() [1/2]

◆ base() [2/2]

const uint8_t * flutter::DisplayListStorage::base ( ) const
inline

Definition at line 24 of file dl_storage.h.

24{ return ptr_.get(); }

◆ capacity()

size_t flutter::DisplayListStorage::capacity ( ) const
inline

Returns the maximum currently allocated space.

Definition at line 30 of file dl_storage.h.

30{ return allocated_; }

Referenced by flutter::testing::TEST(), flutter::testing::TEST(), and flutter::testing::TEST().

◆ NextPowerOfTwoSize()

size_t flutter::DisplayListStorage::NextPowerOfTwoSize ( size_t  x)
static

Compute the next power of two from [x].

Definition at line 14 of file dl_storage.cc.

14 {
15 if (x == 0) {
16 return 1;
17 }
18
19 --x;
20
21 x |= x >> 1;
22 x |= x >> 2;
23 x |= x >> 4;
24 x |= x >> 8;
25 x |= x >> 16;
26 if constexpr (sizeof(size_t) > 4) {
27 x |= x >> 32;
28 }
29
30 return x + 1;
31}
int32_t x

References x.

Referenced by allocate(), and flutter::testing::TEST().

◆ operator=()

DisplayListStorage & flutter::DisplayListStorage::operator= ( DisplayListStorage &&  other)

Definition at line 74 of file dl_storage.cc.

74 {
75 ptr_ = std::move(source.ptr_);
76 used_ = source.used_;
77 allocated_ = source.allocated_;
78 source.used_ = 0u;
79 source.allocated_ = 0u;
80 return *this;
81}

◆ reset()

void flutter::DisplayListStorage::reset ( )

Resets the storage and allocation of the object to an empty state.

Definition at line 68 of file dl_storage.cc.

68 {
69 ptr_.reset();
70 used_ = 0u;
71 allocated_ = 0u;
72}

◆ size()

size_t flutter::DisplayListStorage::size ( ) const
inline

◆ trim()

void flutter::DisplayListStorage::trim ( )
inline

Trims the storage to the currently allocated size and invalidates any outstanding pointers into the storage.

Definition at line 39 of file dl_storage.h.

39{ realloc(used_); }

Referenced by flutter::DisplayListBuilder::Build().

Member Data Documentation

◆ kDLPageSize

const constexpr size_t flutter::DisplayListStorage::kDLPageSize = 4096u
staticconstexpr

Definition at line 17 of file dl_storage.h.

Referenced by allocate(), flutter::testing::TEST(), and flutter::testing::TEST().


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