Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(753)

Side by Side Diff: include/core/SkWriter32.h

Issue 155863005: Adding release method to SkWriter32 and using it to not copy the ops data from SkPictureRecord to S… (Closed) Base URL: https://skia.googlesource.com/skia.git@array_growth
Patch Set: Rename to detatchAsData Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/core/SkPicturePlayback.h » ('j') | src/core/SkWriter32.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 * This also clears the writer to empty as if you had called reset().
238 */
239 SkData* detatchAsData();
240
232 private: 241 private:
233 void growToAtLeast(size_t size); 242 void growToAtLeast(size_t size);
234 243
235 uint8_t* fData; // Points to either fInternal or fExternal. 244 uint8_t* fData; // Points to either fInternal or fExternal.
236 size_t fCapacity; // Number of bytes we can write to fData. 245 size_t fCapacity; // Number of bytes we can write to fData.
237 size_t fUsed; // Number of bytes written. 246 size_t fUsed; // Number of bytes written.
238 void* fExternal; // Unmanaged memory block. 247 void* fExternal; // Unmanaged memory block.
239 SkTDArray<uint8_t> fInternal; // Managed memory block. 248 SkTDArray<uint8_t> fInternal; // Managed memory block.
240 }; 249 };
241 250
242 /** 251 /**
243 * Helper class to allocated SIZE bytes as part of the writer, and to provide 252 * 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. 253 * that storage to the constructor as its initial storage buffer.
245 * 254 *
246 * This wrapper ensures proper alignment rules are met for the storage. 255 * This wrapper ensures proper alignment rules are met for the storage.
247 */ 256 */
248 template <size_t SIZE> class SkSWriter32 : public SkWriter32 { 257 template <size_t SIZE> class SkSWriter32 : public SkWriter32 {
249 public: 258 public:
250 SkSWriter32() : SkWriter32(fData.fStorage, SIZE) {} 259 SkSWriter32() : SkWriter32(fData.fStorage, SIZE) {}
251 260
252 private: 261 private:
253 union { 262 union {
254 void* fPtrAlignment; 263 void* fPtrAlignment;
255 double fDoubleAlignment; 264 double fDoubleAlignment;
256 char fStorage[SIZE]; 265 char fStorage[SIZE];
257 } fData; 266 } fData;
258 }; 267 };
259 268
260 #endif 269 #endif
OLDNEW
« no previous file with comments | « no previous file | src/core/SkPicturePlayback.h » ('j') | src/core/SkWriter32.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698