OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkAtomics.h" | 8 #include "SkAtomics.h" |
9 #include "SkRWBuffer.h" | 9 #include "SkRWBuffer.h" |
10 #include "SkStream.h" | 10 #include "SkStream.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 this->validate(); | 187 this->validate(); |
188 if (fHead) { | 188 if (fHead) { |
189 fHead->unref(); | 189 fHead->unref(); |
190 } | 190 } |
191 } | 191 } |
192 | 192 |
193 // It is important that we always completely fill the current block before spill
ing over to the | 193 // It is important that we always completely fill the current block before spill
ing over to the |
194 // next, since our reader will be using fCapacity (min'd against its total avail
able) to know how | 194 // next, since our reader will be using fCapacity (min'd against its total avail
able) to know how |
195 // many bytes to read from a given block. | 195 // many bytes to read from a given block. |
196 // | 196 // |
197 void SkRWBuffer::append(const void* src, size_t length) { | 197 void SkRWBuffer::append(const void* src, size_t length, size_t reserve) { |
198 this->validate(); | 198 this->validate(); |
199 if (0 == length) { | 199 if (0 == length) { |
200 return; | 200 return; |
201 } | 201 } |
202 | 202 |
203 fTotalUsed += length; | 203 fTotalUsed += length; |
204 | 204 |
205 if (nullptr == fHead) { | 205 if (nullptr == fHead) { |
206 fHead = SkBufferHead::Alloc(length); | 206 fHead = SkBufferHead::Alloc(length + reserve); |
207 fTail = &fHead->fBlock; | 207 fTail = &fHead->fBlock; |
208 } | 208 } |
209 | 209 |
210 size_t written = fTail->append(src, length); | 210 size_t written = fTail->append(src, length); |
211 SkASSERT(written <= length); | 211 SkASSERT(written <= length); |
212 src = (const char*)src + written; | 212 src = (const char*)src + written; |
213 length -= written; | 213 length -= written; |
214 | 214 |
215 if (length) { | 215 if (length) { |
216 SkBufferBlock* block = SkBufferBlock::Alloc(length); | 216 SkBufferBlock* block = SkBufferBlock::Alloc(length + reserve); |
217 fTail->fNext = block; | 217 fTail->fNext = block; |
218 fTail = block; | 218 fTail = block; |
219 written = fTail->append(src, length); | 219 written = fTail->append(src, length); |
220 SkASSERT(written == length); | 220 SkASSERT(written == length); |
221 } | 221 } |
222 this->validate(); | 222 this->validate(); |
223 } | 223 } |
224 | 224 |
225 #ifdef SK_DEBUG | 225 #ifdef SK_DEBUG |
226 void SkRWBuffer::validate() const { | 226 void SkRWBuffer::validate() const { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 const SkROBuffer* fBuffer; | 346 const SkROBuffer* fBuffer; |
347 SkROBuffer::Iter fIter; | 347 SkROBuffer::Iter fIter; |
348 size_t fLocalOffset; | 348 size_t fLocalOffset; |
349 size_t fGlobalOffset; | 349 size_t fGlobalOffset; |
350 }; | 350 }; |
351 | 351 |
352 SkStreamAsset* SkRWBuffer::newStreamSnapshot() const { | 352 SkStreamAsset* SkRWBuffer::newStreamSnapshot() const { |
353 SkAutoTUnref<SkROBuffer> buffer(this->newRBufferSnapshot()); | 353 SkAutoTUnref<SkROBuffer> buffer(this->newRBufferSnapshot()); |
354 return new SkROBufferStreamAsset(buffer); | 354 return new SkROBufferStreamAsset(buffer); |
355 } | 355 } |
OLD | NEW |