Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
dart::BitmapBuilder Class Reference

#include <bitmap.h>

Inheritance diagram for dart::BitmapBuilder:
dart::ZoneAllocated

Public Member Functions

 BitmapBuilder ()
 
 BitmapBuilder (const BitmapBuilder &other)
 
intptr_t Length () const
 
void SetLength (intptr_t length)
 
bool Get (intptr_t bit_offset) const
 
void Set (intptr_t bit_offset, bool value)
 
intptr_t Maximum () const
 
intptr_t Minimum () const
 
void SetRange (intptr_t min, intptr_t max, bool value)
 
void Print () const
 
void AppendAsBytesTo (BaseWriteStream *stream) const
 
void Write (BaseWriteStream *stream) const
 
void Read (ReadStream *stream)
 
- Public Member Functions inherited from dart::ZoneAllocated
 ZoneAllocated ()
 
void * operator new (size_t size)
 
void * operator new (size_t size, Zone *zone)
 
void operator delete (void *pointer)
 

Detailed Description

Definition at line 18 of file bitmap.h.

Constructor & Destructor Documentation

◆ BitmapBuilder() [1/2]

dart::BitmapBuilder::BitmapBuilder ( )
inline

Definition at line 20 of file bitmap.h.

20 : length_(0), data_size_in_bytes_(kInlineCapacityInBytes) {
21 memset(data_.inline_, 0, data_size_in_bytes_);
22 }

◆ BitmapBuilder() [2/2]

dart::BitmapBuilder::BitmapBuilder ( const BitmapBuilder other)
inline

Definition at line 24 of file bitmap.h.

25 : ZoneAllocated(),
26 length_(other.length_),
27 data_size_in_bytes_(other.data_size_in_bytes_) {
28 if (data_size_in_bytes_ == kInlineCapacityInBytes) {
29 memmove(data_.inline_, other.data_.inline_, kInlineCapacityInBytes);
30 } else {
31 data_.ptr_ = AllocBackingStore(data_size_in_bytes_);
32 memmove(data_.ptr_, other.data_.ptr_, data_size_in_bytes_);
33 }
34 }

Member Function Documentation

◆ AppendAsBytesTo()

void dart::BitmapBuilder::AppendAsBytesTo ( BaseWriteStream stream) const

Definition at line 91 of file bitmap.cc.

91 {
92 // Early return if there are no bits in the payload to copy.
93 if (Length() == 0) return;
94
95 const intptr_t total_size =
97 intptr_t payload_size;
98 intptr_t extra_size;
99 if (total_size > data_size_in_bytes_) {
100 // A [BitmapBuilder] does not allocate storage for the trailing 0 bits in
101 // the backing store, so we need to add additional empty bytes here.
102 payload_size = data_size_in_bytes_;
103 extra_size = total_size - data_size_in_bytes_;
104 } else {
105 payload_size = total_size;
106 extra_size = 0;
107 }
108#if defined(DEBUG)
109 // Make sure any bits in the payload beyond the bit length if we're not
110 // appending trailing zeroes are cleared to ensure deterministic snapshots.
111 if (extra_size == 0 && Length() % kBitsPerByte != 0) {
112 const int8_t mask = (1 << (Length() % kBitsPerByte)) - 1;
113 ASSERT_EQUAL(BackingStore()[payload_size - 1],
114 (BackingStore()[payload_size - 1] & mask));
115 }
116#endif
117 stream->WriteBytes(BackingStore(), payload_size);
118 for (intptr_t i = 0; i < extra_size; i++) {
119 stream->WriteByte(0U);
120 }
121}
static size_t total_size(SkSBlockAllocator< N > &pool)
#define ASSERT_EQUAL(expected, actual)
Definition assert.h:309
intptr_t Length() const
Definition bitmap.h:36
static constexpr T RoundUp(T x, uintptr_t alignment, uintptr_t offset=0)
Definition utils.h:105
constexpr intptr_t kBitsPerByte
Definition globals.h:463

◆ Get()

bool dart::BitmapBuilder::Get ( intptr_t  bit_offset) const

Definition at line 35 of file bitmap.cc.

35 {
36 if (!InRange(bit_offset)) {
37 return false;
38 }
39 intptr_t byte_offset = bit_offset >> kBitsPerByteLog2;
40 // Bits not covered by the backing store are implicitly false.
41 return (byte_offset < data_size_in_bytes_) && GetBit(bit_offset);
42}
constexpr intptr_t kBitsPerByteLog2
Definition globals.h:462

◆ Length()

intptr_t dart::BitmapBuilder::Length ( ) const
inline

Definition at line 36 of file bitmap.h.

36{ return length_; }

◆ Maximum()

intptr_t dart::BitmapBuilder::Maximum ( ) const

◆ Minimum()

intptr_t dart::BitmapBuilder::Minimum ( ) const

◆ Print()

void dart::BitmapBuilder::Print ( ) const

Definition at line 81 of file bitmap.cc.

81 {
82 for (intptr_t i = 0; i < Length(); i++) {
83 if (Get(i)) {
84 THR_Print("1");
85 } else {
86 THR_Print("0");
87 }
88 }
89}
bool Get(intptr_t bit_offset) const
Definition bitmap.cc:35
#define THR_Print(format,...)
Definition log.h:20

◆ Read()

void dart::BitmapBuilder::Read ( ReadStream stream)

Definition at line 161 of file bitmap.cc.

161 {
162 length_ = stream->Read<intptr_t>();
163 const intptr_t payload_size = stream->Read<intptr_t>();
164 if (payload_size > data_size_in_bytes_) {
165 data_size_in_bytes_ = payload_size;
166 data_.ptr_ = AllocBackingStore(data_size_in_bytes_);
167 } else {
168 memset(BackingStore() + payload_size, 0,
169 data_size_in_bytes_ - payload_size);
170 }
171 stream->ReadBytes(BackingStore(), payload_size);
172}

◆ Set()

void dart::BitmapBuilder::Set ( intptr_t  bit_offset,
bool  value 
)

Definition at line 44 of file bitmap.cc.

44 {
45 if (!InRange(bit_offset)) {
46 length_ = bit_offset + 1;
47 }
48
49 // Bits not covered by the backing store are implicitly false.
50 // Grow the backing store if necessary.
51 if (value) {
52 if (!InBackingStore(bit_offset)) {
53 intptr_t byte_offset = bit_offset >> kBitsPerByteLog2;
54 uint8_t* old_data = BackingStore();
55 intptr_t old_size = data_size_in_bytes_;
56 data_size_in_bytes_ =
57 Utils::RoundUp(byte_offset + 1, kIncrementSizeInBytes);
58 ASSERT(data_size_in_bytes_ > 0);
59 // Note: do not update data_ yet because it might overwrite old_data
60 // contents.
61 uint8_t* new_data = AllocBackingStore(data_size_in_bytes_);
62 memmove(new_data, old_data, old_size);
63 memset(&new_data[old_size], 0, (data_size_in_bytes_ - old_size));
64 data_.ptr_ = new_data;
65 }
66 ASSERT(InBackingStore(bit_offset));
67 }
68
69 // Set bit if in backing store.
70 if (InBackingStore(bit_offset)) {
71 SetBit(bit_offset, value);
72 }
73}
#define ASSERT(E)

◆ SetLength()

void dart::BitmapBuilder::SetLength ( intptr_t  length)

Definition at line 13 of file bitmap.cc.

13 {
14 // When this function is used to shorten the length, affected bits in the
15 // backing store need to be cleared because the implementation assumes it.
16 if (new_length < length_) {
17 // Byte offset containing the first bit to be cleared.
18 intptr_t byte_offset = new_length >> kBitsPerByteLog2;
19 if (byte_offset < data_size_in_bytes_) {
20 // First bit index (in the byte) to be cleared.
21 intptr_t bit_index = new_length & (kBitsPerByte - 1);
22 intptr_t mask = (1 << bit_index) - 1;
23 BackingStore()[byte_offset] &= mask;
24 // Clear the rest.
25 ++byte_offset;
26 if (byte_offset < data_size_in_bytes_) {
27 memset(&BackingStore()[byte_offset], 0,
28 data_size_in_bytes_ - byte_offset);
29 }
30 }
31 }
32 length_ = new_length;
33}

◆ SetRange()

void dart::BitmapBuilder::SetRange ( intptr_t  min,
intptr_t  max,
bool  value 
)

Definition at line 75 of file bitmap.cc.

75 {
76 for (intptr_t i = min; i <= max; i++) {
77 Set(i, value);
78 }
79}
void Set(intptr_t bit_offset, bool value)
Definition bitmap.cc:44
static float max(float r, float g, float b)
Definition hsl.cpp:49
static float min(float r, float g, float b)
Definition hsl.cpp:48

◆ Write()

void dart::BitmapBuilder::Write ( BaseWriteStream stream) const

Definition at line 152 of file bitmap.cc.

152 {
153 const intptr_t payload_size =
155 data_size_in_bytes_);
156 stream->Write<intptr_t>(Length());
157 stream->Write<intptr_t>(payload_size);
158 stream->WriteBytes(BackingStore(), payload_size);
159}
static T Minimum(T x, T y)
Definition utils.h:21

Member Data Documentation

◆ inline_

uint8_t dart::BitmapBuilder::inline_[kInlineCapacityInBytes]

Definition at line 104 of file bitmap.h.

◆ ptr_

uint8_t* dart::BitmapBuilder::ptr_

Definition at line 103 of file bitmap.h.


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