| 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 "SkTemplates.h" |
| 22 #include "SkTypes.h" | 22 #include "SkTypes.h" |
| 23 | 23 |
| 24 class SkWriter32 : SkNoncopyable { | 24 class SkWriter32 : SkNoncopyable { |
| 25 public: | 25 public: |
| 26 /** | 26 /** |
| 27 * The caller can specify an initial block of storage, which the caller man
ages. | 27 * The caller can specify an initial block of storage, which the caller man
ages. |
| 28 * | 28 * |
| 29 * SkWriter32 will try to back reserve and write calls with this external s
torage until the | 29 * 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. | 30 * 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. | 31 * This used to be optional behavior, but pipe now relies on it. |
| 32 */ | 32 */ |
| 33 SkWriter32(void* external = NULL, size_t externalBytes = 0) | 33 SkWriter32(void* external = NULL, size_t externalBytes = 0) { |
| 34 : fData(0) | |
| 35 , fCapacity(0) | |
| 36 , fUsed(0) | |
| 37 , fExternal(0) | |
| 38 { | |
| 39 this->reset(external, externalBytes); | 34 this->reset(external, externalBytes); |
| 40 } | 35 } |
| 41 | 36 |
| 42 // return the current offset (will always be a multiple of 4) | 37 // return the current offset (will always be a multiple of 4) |
| 43 size_t bytesWritten() const { return fUsed; } | 38 size_t bytesWritten() const { return fUsed; } |
| 44 | 39 |
| 45 SK_ATTR_DEPRECATED("use bytesWritten") | 40 SK_ATTR_DEPRECATED("use bytesWritten") |
| 46 size_t size() const { return this->bytesWritten(); } | 41 size_t size() const { return this->bytesWritten(); } |
| 47 | 42 |
| 48 void reset(void* external = NULL, size_t externalBytes = 0) { | 43 void reset(void* external = NULL, size_t externalBytes = 0) { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 | 226 |
| 232 // read from the stream, and write up to length bytes. Return the actual | 227 // read from the stream, and write up to length bytes. Return the actual |
| 233 // number of bytes written. | 228 // number of bytes written. |
| 234 size_t readFromStream(SkStream* stream, size_t length) { | 229 size_t readFromStream(SkStream* stream, size_t length) { |
| 235 return stream->read(this->reservePad(length), length); | 230 return stream->read(this->reservePad(length), length); |
| 236 } | 231 } |
| 237 | 232 |
| 238 private: | 233 private: |
| 239 void growToAtLeast(size_t size); | 234 void growToAtLeast(size_t size); |
| 240 | 235 |
| 241 uint8_t* fData; // Points to either fInternal or fExternal. | 236 uint8_t* fData; // Points to either fInternal or fExterna
l. |
| 242 size_t fCapacity; // Number of bytes we can write to fData. | 237 size_t fCapacity; // Number of bytes we can write to fData. |
| 243 size_t fUsed; // Number of bytes written. | 238 size_t fUsed; // Number of bytes written. |
| 244 void* fExternal; // Unmanaged memory block. | 239 void* fExternal; // Unmanaged memory block. |
| 245 SkTDArray<uint8_t> fInternal; // Managed memory block. | 240 SkAutoTMalloc<uint8_t> fInternal; // Managed memory block. |
| 246 }; | 241 }; |
| 247 | 242 |
| 248 /** | 243 /** |
| 249 * Helper class to allocated SIZE bytes as part of the writer, and to provide | 244 * Helper class to allocated SIZE bytes as part of the writer, and to provide |
| 250 * that storage to the constructor as its initial storage buffer. | 245 * that storage to the constructor as its initial storage buffer. |
| 251 * | 246 * |
| 252 * This wrapper ensures proper alignment rules are met for the storage. | 247 * This wrapper ensures proper alignment rules are met for the storage. |
| 253 */ | 248 */ |
| 254 template <size_t SIZE> class SkSWriter32 : public SkWriter32 { | 249 template <size_t SIZE> class SkSWriter32 : public SkWriter32 { |
| 255 public: | 250 public: |
| 256 SkSWriter32() { this->reset(); } | 251 SkSWriter32() { this->reset(); } |
| 257 | 252 |
| 258 void reset() {this->INHERITED::reset(fData.fStorage, SIZE); } | 253 void reset() {this->INHERITED::reset(fData.fStorage, SIZE); } |
| 259 | 254 |
| 260 private: | 255 private: |
| 261 union { | 256 union { |
| 262 void* fPtrAlignment; | 257 void* fPtrAlignment; |
| 263 double fDoubleAlignment; | 258 double fDoubleAlignment; |
| 264 char fStorage[SIZE]; | 259 char fStorage[SIZE]; |
| 265 } fData; | 260 } fData; |
| 266 | 261 |
| 267 typedef SkWriter32 INHERITED; | 262 typedef SkWriter32 INHERITED; |
| 268 }; | 263 }; |
| 269 | 264 |
| 270 #endif | 265 #endif |
| OLD | NEW |