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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 fBlock = nullptr; | 174 fBlock = nullptr; |
175 } else { | 175 } else { |
176 fBlock = fBlock->fNext; | 176 fBlock = fBlock->fNext; |
177 } | 177 } |
178 } | 178 } |
179 return fRemaining != 0; | 179 return fRemaining != 0; |
180 } | 180 } |
181 | 181 |
182 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 182 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
183 | 183 |
184 SkRWBuffer::SkRWBuffer(size_t initialCapacity) : fHead(nullptr), fTail(nullptr),
fTotalUsed(0) {} | 184 SkRWBuffer::SkRWBuffer(size_t initialCapacity) : fHead(nullptr), fTail(nullptr),
fTotalUsed(0) { |
| 185 if (initialCapacity) { |
| 186 fHead = SkBufferHead::Alloc(initialCapacity); |
| 187 fTail = &fHead->fBlock; |
| 188 } |
| 189 } |
185 | 190 |
186 SkRWBuffer::~SkRWBuffer() { | 191 SkRWBuffer::~SkRWBuffer() { |
187 this->validate(); | 192 this->validate(); |
188 if (fHead) { | 193 if (fHead) { |
189 fHead->unref(); | 194 fHead->unref(); |
190 } | 195 } |
191 } | 196 } |
192 | 197 |
193 // It is important that we always completely fill the current block before spill
ing over to the | 198 // 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 | 199 // next, since our reader will be using fCapacity (min'd against its total avail
able) to know how |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 const SkROBuffer* fBuffer; | 351 const SkROBuffer* fBuffer; |
347 SkROBuffer::Iter fIter; | 352 SkROBuffer::Iter fIter; |
348 size_t fLocalOffset; | 353 size_t fLocalOffset; |
349 size_t fGlobalOffset; | 354 size_t fGlobalOffset; |
350 }; | 355 }; |
351 | 356 |
352 SkStreamAsset* SkRWBuffer::newStreamSnapshot() const { | 357 SkStreamAsset* SkRWBuffer::newStreamSnapshot() const { |
353 SkAutoTUnref<SkROBuffer> buffer(this->newRBufferSnapshot()); | 358 SkAutoTUnref<SkROBuffer> buffer(this->newRBufferSnapshot()); |
354 return new SkROBufferStreamAsset(buffer); | 359 return new SkROBufferStreamAsset(buffer); |
355 } | 360 } |
OLD | NEW |