OLD | NEW |
---|---|
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 #define SK_RECORD_BOUNDS_IN_PICTURE 0 | |
20 | |
19 class SkPictureStateTree; | 21 class SkPictureStateTree; |
20 class SkBBoxHierarchy; | 22 class SkBBoxHierarchy; |
21 | 23 |
22 // These macros help with packing and unpacking a single byte value and | 24 // These macros help with packing and unpacking a single byte value and |
23 // a 3 byte value into/out of a uint32_t | 25 // a 3 byte value into/out of a uint32_t |
24 #define MASK_24 0x00FFFFFF | 26 #define MASK_24 0x00FFFFFF |
25 #define UNPACK_8_24(combined, small, large) \ | 27 #define UNPACK_8_24(combined, small, large) \ |
26 small = (combined >> 24) & 0xFF; \ | 28 small = (combined >> 24) & 0xFF; \ |
27 large = combined & MASK_24; | 29 large = combined & MASK_24; |
28 #define PACK_8_24(small, large) ((small << 24) | large) | 30 #define PACK_8_24(small, large) ((small << 24) | large) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 const SkPaint&) SK_OVERRIDE; | 79 const SkPaint&) SK_OVERRIDE; |
78 virtual void drawPicture(SkPicture& picture) SK_OVERRIDE; | 80 virtual void drawPicture(SkPicture& picture) SK_OVERRIDE; |
79 virtual void drawVertices(VertexMode, int vertexCount, | 81 virtual void drawVertices(VertexMode, int vertexCount, |
80 const SkPoint vertices[], const SkPoint texs[], | 82 const SkPoint vertices[], const SkPoint texs[], |
81 const SkColor colors[], SkXfermode*, | 83 const SkColor colors[], SkXfermode*, |
82 const uint16_t indices[], int indexCount, | 84 const uint16_t indices[], int indexCount, |
83 const SkPaint&) SK_OVERRIDE; | 85 const SkPaint&) SK_OVERRIDE; |
84 virtual void drawData(const void*, size_t) SK_OVERRIDE; | 86 virtual void drawData(const void*, size_t) SK_OVERRIDE; |
85 virtual bool isDrawingToLayer() const SK_OVERRIDE; | 87 virtual bool isDrawingToLayer() const SK_OVERRIDE; |
86 | 88 |
89 #if !(SK_RECORD_BOUNDS_IN_PICTURE) | |
87 void addFontMetricsTopBottom(const SkPaint& paint, const SkFlatData&, | 90 void addFontMetricsTopBottom(const SkPaint& paint, const SkFlatData&, |
88 SkScalar minY, SkScalar maxY); | 91 SkScalar minY, SkScalar maxY); |
92 #endif | |
89 | 93 |
90 const SkTDArray<SkPicture* >& getPictureRefs() const { | 94 const SkTDArray<SkPicture* >& getPictureRefs() const { |
91 return fPictureRefs; | 95 return fPictureRefs; |
92 } | 96 } |
93 | 97 |
94 void setFlags(uint32_t recordFlags) { | 98 void setFlags(uint32_t recordFlags) { |
95 fRecordFlags = recordFlags; | 99 fRecordFlags = recordFlags; |
96 } | 100 } |
97 | 101 |
98 const SkWriter32& writeStream() const { | 102 const SkWriter32& writeStream() const { |
99 return fWriter; | 103 return fWriter; |
100 } | 104 } |
101 | 105 |
102 void beginRecording(); | 106 void beginRecording(); |
103 void endRecording(); | 107 void endRecording(); |
104 | 108 |
109 static bool canRecordBounds(DrawType op); | |
105 private: | 110 private: |
106 void recordRestoreOffsetPlaceholder(SkRegion::Op); | 111 void recordRestoreOffsetPlaceholder(SkRegion::Op); |
107 void fillRestoreOffsetPlaceholdersForCurrentStackLevel( | 112 void fillRestoreOffsetPlaceholdersForCurrentStackLevel( |
108 uint32_t restoreOffset); | 113 uint32_t restoreOffset); |
109 | 114 |
110 SkTDArray<int32_t> fRestoreOffsetStack; | 115 SkTDArray<int32_t> fRestoreOffsetStack; |
111 int fFirstSavedLayerIndex; | 116 int fFirstSavedLayerIndex; |
112 enum { | 117 enum { |
113 kNoSavedLayerIndex = -1 | 118 kNoSavedLayerIndex = -1, |
114 }; | 119 }; |
120 static const uint32_t kInvalidOffset = ~0; | |
115 | 121 |
116 /* | 122 /* |
117 * Write the 'drawType' operation and chunk size to the skp. 'size' | 123 * Write the 'drawType' operation, chunk size and optionally the draw |
118 * can potentially be increased if the chunk size needs its own storage | 124 * bounds to the skp. 'size' can potentially be increased if the chunk |
119 * location (i.e., it overflows 24 bits). | 125 * size needs its own storage location (i.e., it overflows 24 bits). |
robertphillips
2013/03/08 20:40:04
Ignore if you want, I would have the two return va
Justin Novosad
2013/03/08 22:35:42
Done.
| |
120 * Returns the start offset of the chunk. This is the location at which | 126 * Returns the start offset of the chunk. This is the location at which |
121 * the opcode & size are stored. | 127 * the opcode & size are stored. |
128 * Bounds are recorded in device space, if canRecordBounds(drawType) | |
129 * returns true; | |
122 * TODO: since we are handing the size into here we could call reserve | 130 * TODO: since we are handing the size into here we could call reserve |
123 * and then return a pointer to the memory storage. This could decrease | 131 * and then return a pointer to the memory storage. This could decrease |
124 * allocation overhead but could lead to more wasted space (the tail | 132 * allocation overhead but could lead to more wasted space (the tail |
125 * end of blocks could go unused). Possibly add a second addDraw that | 133 * end of blocks could go unused). Possibly add a second addDraw that |
126 * operates in this manner. | 134 * operates in this manner. |
127 */ | 135 */ |
128 uint32_t addDraw(DrawType drawType, uint32_t* size) { | 136 uint32_t addDraw(DrawType drawType, uint32_t* size, const SkPaint* paint = N ULL, |
129 uint32_t offset = fWriter.size(); | 137 const SkRect* localBounds = NULL); |
130 | |
131 this->predrawNotify(); | |
132 | |
133 #ifdef SK_DEBUG_TRACE | |
134 SkDebugf("add %s\n", DrawTypeToString(drawType)); | |
135 #endif | |
136 | |
137 SkASSERT(0 != *size); | |
138 SkASSERT(((uint8_t) drawType) == drawType); | |
139 | |
140 if (0 != (*size & ~MASK_24) || *size == MASK_24) { | |
141 fWriter.writeInt(PACK_8_24(drawType, MASK_24)); | |
142 *size += 1; | |
143 fWriter.writeInt(*size); | |
144 } else { | |
145 fWriter.writeInt(PACK_8_24(drawType, *size)); | |
146 } | |
147 | |
148 return offset; | |
149 } | |
150 | 138 |
151 void addInt(int value) { | 139 void addInt(int value) { |
152 fWriter.writeInt(value); | 140 fWriter.writeInt(value); |
153 } | 141 } |
154 void addScalar(SkScalar scalar) { | 142 void addScalar(SkScalar scalar) { |
155 fWriter.writeScalar(scalar); | 143 fWriter.writeScalar(scalar); |
156 } | 144 } |
157 | 145 |
158 void addBitmap(const SkBitmap& bitmap); | 146 void addBitmap(const SkBitmap& bitmap); |
159 void addMatrix(const SkMatrix& matrix); | 147 void addMatrix(const SkMatrix& matrix); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 uint32_t fRecordFlags; | 224 uint32_t fRecordFlags; |
237 int fInitialSaveCount; | 225 int fInitialSaveCount; |
238 | 226 |
239 friend class SkPicturePlayback; | 227 friend class SkPicturePlayback; |
240 friend class SkPictureTester; // for unit testing | 228 friend class SkPictureTester; // for unit testing |
241 | 229 |
242 typedef SkCanvas INHERITED; | 230 typedef SkCanvas INHERITED; |
243 }; | 231 }; |
244 | 232 |
245 #endif | 233 #endif |
OLD | NEW |