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

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

Issue 167113003: Add capture snapshot as data to SkWriter32, use it to optimise record->playback. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Mutex protect snapshot creation Created 6 years, 9 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.cpp » ('j') | src/core/SkPicturePlayback.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 "SkData.h"
13 #include "SkMatrix.h" 14 #include "SkMatrix.h"
14 #include "SkPath.h" 15 #include "SkPath.h"
15 #include "SkPoint.h" 16 #include "SkPoint.h"
16 #include "SkRRect.h" 17 #include "SkRRect.h"
17 #include "SkRect.h" 18 #include "SkRect.h"
18 #include "SkRegion.h" 19 #include "SkRegion.h"
19 #include "SkScalar.h" 20 #include "SkScalar.h"
20 #include "SkStream.h" 21 #include "SkStream.h"
21 #include "SkTemplates.h" 22 #include "SkTemplates.h"
22 #include "SkTypes.h" 23 #include "SkTypes.h"
(...skipping 14 matching lines...) Expand all
37 // return the current offset (will always be a multiple of 4) 38 // return the current offset (will always be a multiple of 4)
38 size_t bytesWritten() const { return fUsed; } 39 size_t bytesWritten() const { return fUsed; }
39 40
40 SK_ATTR_DEPRECATED("use bytesWritten") 41 SK_ATTR_DEPRECATED("use bytesWritten")
41 size_t size() const { return this->bytesWritten(); } 42 size_t size() const { return this->bytesWritten(); }
42 43
43 void reset(void* external = NULL, size_t externalBytes = 0) { 44 void reset(void* external = NULL, size_t externalBytes = 0) {
44 SkASSERT(SkIsAlign4((uintptr_t)external)); 45 SkASSERT(SkIsAlign4((uintptr_t)external));
45 SkASSERT(SkIsAlign4(externalBytes)); 46 SkASSERT(SkIsAlign4(externalBytes));
46 47
48 fSnapshot.reset(NULL);
47 fData = (uint8_t*)external; 49 fData = (uint8_t*)external;
48 fCapacity = externalBytes; 50 fCapacity = externalBytes;
49 fUsed = 0; 51 fUsed = 0;
50 fExternal = external; 52 fExternal = external;
51 } 53 }
52 54
53 // Returns the current buffer. 55 // Returns the current buffer.
54 // The pointer may be invalidated by any future write calls. 56 // The pointer may be invalidated by any future write calls.
55 const uint32_t* contiguousArray() const { 57 const uint32_t* contiguousArray() const {
56 return (uint32_t*)fData; 58 return (uint32_t*)fData;
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 bool writeToStream(SkWStream* stream) const { 225 bool writeToStream(SkWStream* stream) const {
224 return stream->write(fData, fUsed); 226 return stream->write(fData, fUsed);
225 } 227 }
226 228
227 // read from the stream, and write up to length bytes. Return the actual 229 // read from the stream, and write up to length bytes. Return the actual
228 // number of bytes written. 230 // number of bytes written.
229 size_t readFromStream(SkStream* stream, size_t length) { 231 size_t readFromStream(SkStream* stream, size_t length) {
230 return stream->read(this->reservePad(length), length); 232 return stream->read(this->reservePad(length), length);
231 } 233 }
232 234
235 /**
236 * Captures a snapshot of the data as it is right now, and return it.
237 * Multiple calls without intervening writes may return the same SkData,
238 * but this is not guaranteed.
239 * Future appends will not affect the returned buffer, but future writes
240 * without an intervening append may.
reed1 2014/03/06 19:20:31 "may" -- does this mean future writes *will* appea
iancottrell 2014/03/06 21:31:52 Undefined but predictable. For instance, if the cu
241 * Callers must unref the returned SkData.
242 */
243 SkData* snapshotAsData() const;
233 private: 244 private:
234 void growToAtLeast(size_t size); 245 void growToAtLeast(size_t size);
235 246
236 uint8_t* fData; // Points to either fInternal or fExterna l. 247 uint8_t* fData; // Points to either fInternal or fExterna l.
237 size_t fCapacity; // Number of bytes we can write to fData. 248 size_t fCapacity; // Number of bytes we can write to fData.
238 size_t fUsed; // Number of bytes written. 249 size_t fUsed; // Number of bytes written.
239 void* fExternal; // Unmanaged memory block. 250 void* fExternal; // Unmanaged memory block.
240 SkAutoTMalloc<uint8_t> fInternal; // Managed memory block. 251 SkAutoTMalloc<uint8_t> fInternal; // Managed memory block.
252 SkAutoTUnref<SkData> fSnapshot; // Holds the result of last asData.
241 }; 253 };
242 254
243 /** 255 /**
244 * Helper class to allocated SIZE bytes as part of the writer, and to provide 256 * Helper class to allocated SIZE bytes as part of the writer, and to provide
245 * that storage to the constructor as its initial storage buffer. 257 * that storage to the constructor as its initial storage buffer.
246 * 258 *
247 * This wrapper ensures proper alignment rules are met for the storage. 259 * This wrapper ensures proper alignment rules are met for the storage.
248 */ 260 */
249 template <size_t SIZE> class SkSWriter32 : public SkWriter32 { 261 template <size_t SIZE> class SkSWriter32 : public SkWriter32 {
250 public: 262 public:
251 SkSWriter32() { this->reset(); } 263 SkSWriter32() { this->reset(); }
252 264
253 void reset() {this->INHERITED::reset(fData.fStorage, SIZE); } 265 void reset() {this->INHERITED::reset(fData.fStorage, SIZE); }
254 266
255 private: 267 private:
256 union { 268 union {
257 void* fPtrAlignment; 269 void* fPtrAlignment;
258 double fDoubleAlignment; 270 double fDoubleAlignment;
259 char fStorage[SIZE]; 271 char fStorage[SIZE];
260 } fData; 272 } fData;
261 273
262 typedef SkWriter32 INHERITED; 274 typedef SkWriter32 INHERITED;
263 }; 275 };
264 276
265 #endif 277 #endif
OLDNEW
« no previous file with comments | « no previous file | src/core/SkPicturePlayback.cpp » ('j') | src/core/SkPicturePlayback.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698