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

Side by Side Diff: src/core/SkPictureRecord.h

Issue 12545009: Adding option in SkPicture to record device-space bounds of draw commands. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
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 #ifndef SkPictureRecord_DEFINED 8 #ifndef SkPictureRecord_DEFINED
9 #define SkPictureRecord_DEFINED 9 #define SkPictureRecord_DEFINED
10 10
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "SkFlattenable.h" 12 #include "SkFlattenable.h"
13 #include "SkPathHeap.h" 13 #include "SkPathHeap.h"
14 #include "SkPicture.h" 14 #include "SkPicture.h"
15 #include "SkPictureFlat.h" 15 #include "SkPictureFlat.h"
16 #include "SkTemplates.h" 16 #include "SkTemplates.h"
17 #include "SkWriter32.h" 17 #include "SkWriter32.h"
18 18
19 #ifndef SK_RECORD_BOUNDS_IN_PICTURE
20 #define SK_RECORD_BOUNDS_IN_PICTURE 0
21 #endif
22
19 class SkPictureStateTree; 23 class SkPictureStateTree;
20 class SkBBoxHierarchy; 24 class SkBBoxHierarchy;
21 25
22 // These macros help with packing and unpacking a single byte value and 26 // These macros help with packing and unpacking a single byte value and
23 // a 3 byte value into/out of a uint32_t 27 // a 3 byte value into/out of a uint32_t
24 #define MASK_24 0x00FFFFFF 28 #define MASK_24 0x00FFFFFF
25 #define UNPACK_8_24(combined, small, large) \ 29 #define UNPACK_8_24(combined, small, large) \
26 small = (combined >> 24) & 0xFF; \ 30 small = (combined >> 24) & 0xFF; \
27 large = combined & MASK_24; 31 large = combined & MASK_24;
28 #define PACK_8_24(small, large) ((small << 24) | large) 32 #define PACK_8_24(small, large) ((small << 24) | large)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 const SkPaint&) SK_OVERRIDE; 81 const SkPaint&) SK_OVERRIDE;
78 virtual void drawPicture(SkPicture& picture) SK_OVERRIDE; 82 virtual void drawPicture(SkPicture& picture) SK_OVERRIDE;
79 virtual void drawVertices(VertexMode, int vertexCount, 83 virtual void drawVertices(VertexMode, int vertexCount,
80 const SkPoint vertices[], const SkPoint texs[], 84 const SkPoint vertices[], const SkPoint texs[],
81 const SkColor colors[], SkXfermode*, 85 const SkColor colors[], SkXfermode*,
82 const uint16_t indices[], int indexCount, 86 const uint16_t indices[], int indexCount,
83 const SkPaint&) SK_OVERRIDE; 87 const SkPaint&) SK_OVERRIDE;
84 virtual void drawData(const void*, size_t) SK_OVERRIDE; 88 virtual void drawData(const void*, size_t) SK_OVERRIDE;
85 virtual bool isDrawingToLayer() const SK_OVERRIDE; 89 virtual bool isDrawingToLayer() const SK_OVERRIDE;
86 90
91 #if !(SK_RECORD_BOUNDS_IN_PICTURE)
87 void addFontMetricsTopBottom(const SkPaint& paint, const SkFlatData&, 92 void addFontMetricsTopBottom(const SkPaint& paint, const SkFlatData&,
88 SkScalar minY, SkScalar maxY); 93 SkScalar minY, SkScalar maxY);
94 #endif
89 95
90 const SkTDArray<SkPicture* >& getPictureRefs() const { 96 const SkTDArray<SkPicture* >& getPictureRefs() const {
91 return fPictureRefs; 97 return fPictureRefs;
92 } 98 }
93 99
94 void setFlags(uint32_t recordFlags) { 100 void setFlags(uint32_t recordFlags) {
95 fRecordFlags = recordFlags; 101 fRecordFlags = recordFlags;
96 } 102 }
97 103
98 const SkWriter32& writeStream() const { 104 const SkWriter32& writeStream() const {
99 return fWriter; 105 return fWriter;
100 } 106 }
101 107
102 void beginRecording(); 108 void beginRecording();
103 void endRecording(); 109 void endRecording();
104 110
111 static bool canRecordBounds(DrawType op);
105 private: 112 private:
106 bool updateClipConservativelyUsingBounds(const SkRect&, SkRegion::Op, 113 bool updateClipConservativelyUsingBounds(const SkRect&, SkRegion::Op,
107 bool doAA, bool inverseFilled); 114 bool doAA, bool inverseFilled);
108 void handleOptimization(int opt); 115 void handleOptimization(int opt);
109 void recordRestoreOffsetPlaceholder(SkRegion::Op); 116 void recordRestoreOffsetPlaceholder(SkRegion::Op);
110 void fillRestoreOffsetPlaceholdersForCurrentStackLevel( 117 void fillRestoreOffsetPlaceholdersForCurrentStackLevel(
111 uint32_t restoreOffset); 118 uint32_t restoreOffset);
112 119
113 SkTDArray<int32_t> fRestoreOffsetStack; 120 SkTDArray<int32_t> fRestoreOffsetStack;
114 int fFirstSavedLayerIndex; 121 int fFirstSavedLayerIndex;
115 enum { 122 enum {
116 kNoSavedLayerIndex = -1 123 kNoSavedLayerIndex = -1,
117 }; 124 };
125 static const uint32_t kInvalidOffset = ~0;
118 126
119 /* 127 /*
120 * Write the 'drawType' operation and chunk size to the skp. 'size' 128 * Write the 'drawType' operation, chunk size and optionally the draw
121 * can potentially be increased if the chunk size needs its own storage 129 * bounds to the skp. 'size' can potentially be increased if the chunk
122 * location (i.e., it overflows 24 bits). 130 * size needs its own storage location (i.e., it overflows 24 bits).
131 * Bounds are recorded in device space, if canRecordBounds(drawType)
132 * returns true;
Tom Hudson 2013/05/14 17:00:49 Nit: trailing semicolon - did you mean to do more
123 * Returns the start offset of the chunk. This is the location at which 133 * Returns the start offset of the chunk. This is the location at which
124 * the opcode & size are stored. 134 * the opcode & size are stored.
125 * TODO: since we are handing the size into here we could call reserve 135 * TODO: since we are handing the size into here we could call reserve
126 * and then return a pointer to the memory storage. This could decrease 136 * and then return a pointer to the memory storage. This could decrease
127 * allocation overhead but could lead to more wasted space (the tail 137 * allocation overhead but could lead to more wasted space (the tail
128 * end of blocks could go unused). Possibly add a second addDraw that 138 * end of blocks could go unused). Possibly add a second addDraw that
129 * operates in this manner. 139 * operates in this manner.
130 */ 140 */
131 uint32_t addDraw(DrawType drawType, uint32_t* size) { 141 uint32_t addDraw(DrawType drawType, uint32_t* size, const SkPaint* paint = N ULL,
132 uint32_t offset = fWriter.size(); 142 const SkRect* localBounds = NULL);
133
134 this->predrawNotify();
135
136 #ifdef SK_DEBUG_TRACE
137 SkDebugf("add %s\n", DrawTypeToString(drawType));
138 #endif
139
140 SkASSERT(0 != *size);
141 SkASSERT(((uint8_t) drawType) == drawType);
142
143 if (0 != (*size & ~MASK_24) || *size == MASK_24) {
144 fWriter.writeInt(PACK_8_24(drawType, MASK_24));
145 *size += 1;
146 fWriter.writeInt(*size);
147 } else {
148 fWriter.writeInt(PACK_8_24(drawType, *size));
149 }
150
151 return offset;
152 }
153 143
154 void addInt(int value) { 144 void addInt(int value) {
155 fWriter.writeInt(value); 145 fWriter.writeInt(value);
156 } 146 }
157 void addScalar(SkScalar scalar) { 147 void addScalar(SkScalar scalar) {
158 fWriter.writeScalar(scalar); 148 fWriter.writeScalar(scalar);
159 } 149 }
160 150
161 void addBitmap(const SkBitmap& bitmap); 151 void addBitmap(const SkBitmap& bitmap);
162 void addMatrix(const SkMatrix& matrix); 152 void addMatrix(const SkMatrix& matrix);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 205
216 protected: 206 protected:
217 207
218 // These are set to NULL in our constructor, but may be changed by 208 // These are set to NULL in our constructor, but may be changed by
219 // subclasses, in which case they will be SkSafeUnref'd in our destructor. 209 // subclasses, in which case they will be SkSafeUnref'd in our destructor.
220 SkBBoxHierarchy* fBoundingHierarchy; 210 SkBBoxHierarchy* fBoundingHierarchy;
221 SkPictureStateTree* fStateTree; 211 SkPictureStateTree* fStateTree;
222 212
223 // Allocated in the constructor and managed by this class. 213 // Allocated in the constructor and managed by this class.
224 SkBitmapHeap* fBitmapHeap; 214 SkBitmapHeap* fBitmapHeap;
225 215 #if SK_RECORD_BOUNDS_IN_PICTURE
216 SkIRect fLastDrawBounds;
217 #endif
226 private: 218 private:
227 SkChunkFlatController fFlattenableHeap; 219 SkChunkFlatController fFlattenableHeap;
228 220
229 SkMatrixDictionary fMatrices; 221 SkMatrixDictionary fMatrices;
230 SkPaintDictionary fPaints; 222 SkPaintDictionary fPaints;
231 SkRegionDictionary fRegions; 223 SkRegionDictionary fRegions;
232 224
233 SkPathHeap* fPathHeap; // reference counted 225 SkPathHeap* fPathHeap; // reference counted
234 SkWriter32 fWriter; 226 SkWriter32 fWriter;
235 227
236 // we ref each item in these arrays 228 // we ref each item in these arrays
237 SkTDArray<SkPicture*> fPictureRefs; 229 SkTDArray<SkPicture*> fPictureRefs;
238 230
239 uint32_t fRecordFlags; 231 uint32_t fRecordFlags;
240 int fInitialSaveCount; 232 int fInitialSaveCount;
241 233
242 friend class SkPicturePlayback; 234 friend class SkPicturePlayback;
243 friend class SkPictureTester; // for unit testing 235 friend class SkPictureTester; // for unit testing
244 236
245 typedef SkCanvas INHERITED; 237 typedef SkCanvas INHERITED;
246 }; 238 };
247 239
248 #endif 240 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698