16 if (new_length < length_) {
19 if (byte_offset < data_size_in_bytes_) {
22 intptr_t mask = (1 << bit_index) - 1;
23 BackingStore()[byte_offset] &= mask;
26 if (byte_offset < data_size_in_bytes_) {
27 memset(&BackingStore()[byte_offset], 0,
28 data_size_in_bytes_ - byte_offset);
36 if (!InRange(bit_offset)) {
41 return (byte_offset < data_size_in_bytes_) && GetBit(bit_offset);
45 if (!InRange(bit_offset)) {
46 length_ = bit_offset + 1;
52 if (!InBackingStore(bit_offset)) {
54 uint8_t* old_data = BackingStore();
55 intptr_t old_size = data_size_in_bytes_;
58 ASSERT(data_size_in_bytes_ > 0);
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;
66 ASSERT(InBackingStore(bit_offset));
70 if (InBackingStore(bit_offset)) {
71 SetBit(bit_offset,
value);
97 intptr_t payload_size;
102 payload_size = data_size_in_bytes_;
103 extra_size =
total_size - data_size_in_bytes_;
114 (BackingStore()[payload_size - 1] & mask));
117 stream->WriteBytes(BackingStore(), payload_size);
118 for (intptr_t
i = 0;
i < extra_size;
i++) {
123bool BitmapBuilder::GetBit(intptr_t bit_offset)
const {
124 if (!InRange(bit_offset)) {
128 ASSERT(byte_offset < data_size_in_bytes_);
129 intptr_t bit_remainder = bit_offset & (
kBitsPerByte - 1);
130 uint8_t mask = 1U << bit_remainder;
131 return ((BackingStore()[byte_offset] & mask) != 0);
134void BitmapBuilder::SetBit(intptr_t bit_offset,
bool value) {
135 if (!InRange(bit_offset)) {
137 "Fatal error in BitmapBuilder::SetBit :"
138 " invalid bit_offset, %" Pd "\n",
142 ASSERT(byte_offset < data_size_in_bytes_);
143 intptr_t bit_remainder = bit_offset & (
kBitsPerByte - 1);
144 uint8_t mask = 1U << bit_remainder;
146 BackingStore()[byte_offset] |= mask;
148 BackingStore()[byte_offset] &= ~mask;
153 const intptr_t payload_size =
155 data_size_in_bytes_);
157 stream->Write<intptr_t>(payload_size);
158 stream->WriteBytes(BackingStore(), payload_size);
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_);
168 memset(BackingStore() + payload_size, 0,
169 data_size_in_bytes_ - payload_size);
171 stream->ReadBytes(BackingStore(), payload_size);
static size_t total_size(SkSBlockAllocator< N > &pool)
#define ASSERT_EQUAL(expected, actual)
void AppendAsBytesTo(BaseWriteStream *stream) const
void Read(ReadStream *stream)
void Write(BaseWriteStream *stream) const
bool Get(intptr_t bit_offset) const
void Set(intptr_t bit_offset, bool value)
void SetRange(intptr_t min, intptr_t max, bool value)
void SetLength(intptr_t length)
static T Minimum(T x, T y)
static constexpr T RoundUp(T x, uintptr_t alignment, uintptr_t offset=0)
#define THR_Print(format,...)
static float max(float r, float g, float b)
static float min(float r, float g, float b)
constexpr intptr_t kBitsPerByteLog2
constexpr intptr_t kBitsPerByte