OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2008 The Android Open Source Project | 3 * Copyright 2008 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkWriter32_DEFINED | 10 #ifndef SkWriter32_DEFINED |
11 #define SkWriter32_DEFINED | 11 #define SkWriter32_DEFINED |
12 | 12 |
13 #include "SkMatrix.h" | 13 #include "SkMatrix.h" |
14 #include "SkPath.h" | 14 #include "SkPath.h" |
15 #include "SkPoint.h" | 15 #include "SkPoint.h" |
16 #include "SkRRect.h" | 16 #include "SkRRect.h" |
17 #include "SkRect.h" | 17 #include "SkRect.h" |
18 #include "SkRegion.h" | 18 #include "SkRegion.h" |
19 #include "SkScalar.h" | 19 #include "SkScalar.h" |
20 #include "SkStream.h" | 20 #include "SkStream.h" |
21 #include "SkTDArray.h" | 21 #include "SkTDArray.h" |
22 #include "SkTypes.h" | 22 #include "SkTypes.h" |
23 | 23 |
24 class SkData; | |
25 | |
24 class SkWriter32 : SkNoncopyable { | 26 class SkWriter32 : SkNoncopyable { |
25 public: | 27 public: |
26 /** | 28 /** |
27 * The caller can specify an initial block of storage, which the caller man ages. | 29 * The caller can specify an initial block of storage, which the caller man ages. |
28 * | 30 * |
29 * SkWriter32 will try to back reserve and write calls with this external s torage until the | 31 * SkWriter32 will try to back reserve and write calls with this external s torage until the |
30 * first time an allocation doesn't fit. From then it will use dynamically allocated storage. | 32 * first time an allocation doesn't fit. From then it will use dynamically allocated storage. |
31 * This used to be optional behavior, but pipe now relies on it. | 33 * This used to be optional behavior, but pipe now relies on it. |
32 */ | 34 */ |
33 SkWriter32(void* external = NULL, size_t externalBytes = 0) | 35 SkWriter32(void* external = NULL, size_t externalBytes = 0) |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 bool writeToStream(SkWStream* stream) const { | 224 bool writeToStream(SkWStream* stream) const { |
223 return stream->write(fData, fUsed); | 225 return stream->write(fData, fUsed); |
224 } | 226 } |
225 | 227 |
226 // read from the stream, and write up to length bytes. Return the actual | 228 // read from the stream, and write up to length bytes. Return the actual |
227 // number of bytes written. | 229 // number of bytes written. |
228 size_t readFromStream(SkStream* stream, size_t length) { | 230 size_t readFromStream(SkStream* stream, size_t length) { |
229 return stream->read(this->reservePad(length), length); | 231 return stream->read(this->reservePad(length), length); |
230 } | 232 } |
231 | 233 |
234 /** | |
235 * Release the internal buffer to the caller in an SkData. | |
236 * The caller must call unref() when it is finished using the data. | |
237 */ | |
238 SkData* release(); | |
reed1
2014/02/07 16:06:49
Modest vote for a more explicit name :
e.g.
rele
iancottrell
2014/02/07 17:01:47
Done.
| |
239 | |
232 private: | 240 private: |
233 void growToAtLeast(size_t size); | 241 void growToAtLeast(size_t size); |
234 | 242 |
235 uint8_t* fData; // Points to either fInternal or fExternal. | 243 uint8_t* fData; // Points to either fInternal or fExternal. |
236 size_t fCapacity; // Number of bytes we can write to fData. | 244 size_t fCapacity; // Number of bytes we can write to fData. |
237 size_t fUsed; // Number of bytes written. | 245 size_t fUsed; // Number of bytes written. |
238 void* fExternal; // Unmanaged memory block. | 246 void* fExternal; // Unmanaged memory block. |
239 SkTDArray<uint8_t> fInternal; // Managed memory block. | 247 SkTDArray<uint8_t> fInternal; // Managed memory block. |
240 }; | 248 }; |
241 | 249 |
242 /** | 250 /** |
243 * Helper class to allocated SIZE bytes as part of the writer, and to provide | 251 * Helper class to allocated SIZE bytes as part of the writer, and to provide |
244 * that storage to the constructor as its initial storage buffer. | 252 * that storage to the constructor as its initial storage buffer. |
245 * | 253 * |
246 * This wrapper ensures proper alignment rules are met for the storage. | 254 * This wrapper ensures proper alignment rules are met for the storage. |
247 */ | 255 */ |
248 template <size_t SIZE> class SkSWriter32 : public SkWriter32 { | 256 template <size_t SIZE> class SkSWriter32 : public SkWriter32 { |
249 public: | 257 public: |
250 SkSWriter32() : SkWriter32(fData.fStorage, SIZE) {} | 258 SkSWriter32() : SkWriter32(fData.fStorage, SIZE) {} |
251 | 259 |
252 private: | 260 private: |
253 union { | 261 union { |
254 void* fPtrAlignment; | 262 void* fPtrAlignment; |
255 double fDoubleAlignment; | 263 double fDoubleAlignment; |
256 char fStorage[SIZE]; | 264 char fStorage[SIZE]; |
257 } fData; | 265 } fData; |
258 }; | 266 }; |
259 | 267 |
260 #endif | 268 #endif |
OLD | NEW |