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

Side by Side Diff: src/record/SkRecords.h

Issue 235983015: SkRecord bug fixes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tomments Created 6 years, 8 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 | « src/record/SkRecordDraw.cpp ('k') | tests/RecorderTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkRecords_DEFINED 8 #ifndef SkRecords_DEFINED
9 #define SkRecords_DEFINED 9 #define SkRecords_DEFINED
10 10
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 }; 100 };
101 101
102 #define RECORD5(T, A, a, B, b, C, c, D, d, E, e) \ 102 #define RECORD5(T, A, a, B, b, C, c, D, d, E, e) \
103 struct T { \ 103 struct T { \
104 static const Type kType = T##_Type; \ 104 static const Type kType = T##_Type; \
105 template <typename Z, typename Y, typename X, typename W, typename V> \ 105 template <typename Z, typename Y, typename X, typename W, typename V> \
106 T(Z a, Y b, X c, W d, V e) : a(a), b(b), c(c), d(d), e(e) {} \ 106 T(Z a, Y b, X c, W d, V e) : a(a), b(b), c(c), d(d), e(e) {} \
107 A a; B b; C c; D d; E e; \ 107 A a; B b; C c; D d; E e; \
108 }; 108 };
109 109
110 // An Optional doesn't own the pointer's memory, but may need to destroy non-POD data.
111 template <typename T>
112 class Optional : SkNoncopyable {
113 public:
114 Optional(T* ptr) : fPtr(ptr) {}
115 ~Optional() { if (fPtr) fPtr->~T(); }
116
117 operator T*() { return fPtr; }
118 operator const T*() const { return fPtr; }
119 private:
120 T* fPtr;
121 };
122
123 // PODArray doesn't own the pointer's memory, and we assume the data is POD.
124 template <typename T>
125 class PODArray : SkNoncopyable {
126 public:
127 PODArray(T* ptr) : fPtr(ptr) {}
128
129 operator T*() { return fPtr; }
130 operator const T*() const { return fPtr; }
131 private:
132 T* fPtr;
133 };
134
110 // Like SkBitmap, but deep copies pixels if they're not immutable. 135 // Like SkBitmap, but deep copies pixels if they're not immutable.
111 // Using this, we guarantee the immutability of all bitmaps we record. 136 // Using this, we guarantee the immutability of all bitmaps we record.
112 class ImmutableBitmap { 137 class ImmutableBitmap {
113 public: 138 public:
114 explicit ImmutableBitmap(const SkBitmap& bitmap) { 139 explicit ImmutableBitmap(const SkBitmap& bitmap) {
115 if (bitmap.isImmutable()) { 140 if (bitmap.isImmutable()) {
116 fBitmap = bitmap; 141 fBitmap = bitmap;
117 } else { 142 } else {
118 bitmap.copyTo(&fBitmap); 143 bitmap.copyTo(&fBitmap);
119 } 144 }
120 fBitmap.setImmutable(); 145 fBitmap.setImmutable();
121 } 146 }
122 147
123 operator const SkBitmap& () const { return fBitmap; } 148 operator const SkBitmap& () const { return fBitmap; }
124 149
125 private: 150 private:
126 SkBitmap fBitmap; 151 SkBitmap fBitmap;
127 }; 152 };
128 153
129 // Pointers here represent either an optional value or an array if accompanied b y a count.
130 // None of these records manages the lifetimes of pointers, except for DrawVerti ces handling its 154 // None of these records manages the lifetimes of pointers, except for DrawVerti ces handling its
131 // Xfermode specially. 155 // Xfermode specially.
132 156
133 RECORD0(Restore); 157 RECORD0(Restore);
134 RECORD1(Save, SkCanvas::SaveFlags, flags); 158 RECORD1(Save, SkCanvas::SaveFlags, flags);
135 RECORD3(SaveLayer, SkRect*, bounds, SkPaint*, paint, SkCanvas::SaveFlags, flags) ; 159 RECORD3(SaveLayer, Optional<SkRect>, bounds, Optional<SkPaint>, paint, SkCanvas: :SaveFlags, flags);
136 160
137 static const unsigned kUnsetPopOffset = 0; 161 static const unsigned kUnsetPopOffset = 0;
138 RECORD2(PushCull, SkRect, rect, unsigned, popOffset); 162 RECORD2(PushCull, SkRect, rect, unsigned, popOffset);
139 RECORD0(PopCull); 163 RECORD0(PopCull);
140 164
141 RECORD1(Concat, SkMatrix, matrix); 165 RECORD1(Concat, SkMatrix, matrix);
142 RECORD1(SetMatrix, SkMatrix, matrix); 166 RECORD1(SetMatrix, SkMatrix, matrix);
143 167
144 RECORD3(ClipPath, SkPath, path, SkRegion::Op, op, bool, doAA); 168 RECORD3(ClipPath, SkPath, path, SkRegion::Op, op, bool, doAA);
145 RECORD3(ClipRRect, SkRRect, rrect, SkRegion::Op, op, bool, doAA); 169 RECORD3(ClipRRect, SkRRect, rrect, SkRegion::Op, op, bool, doAA);
146 RECORD3(ClipRect, SkRect, rect, SkRegion::Op, op, bool, doAA); 170 RECORD3(ClipRect, SkRect, rect, SkRegion::Op, op, bool, doAA);
147 RECORD2(ClipRegion, SkRegion, region, SkRegion::Op, op); 171 RECORD2(ClipRegion, SkRegion, region, SkRegion::Op, op);
148 172
149 RECORD1(Clear, SkColor, color); 173 RECORD1(Clear, SkColor, color);
150 RECORD4(DrawBitmap, ImmutableBitmap, bitmap, SkScalar, left, SkScalar, top, SkPa int*, paint); 174 RECORD4(DrawBitmap, ImmutableBitmap, bitmap,
151 RECORD3(DrawBitmapMatrix, ImmutableBitmap, bitmap, SkMatrix, matrix, SkPaint*, p aint); 175 SkScalar, left,
152 RECORD4(DrawBitmapNine, ImmutableBitmap, bitmap, SkIRect, center, SkRect, dst, S kPaint*, paint); 176 SkScalar, top,
177 Optional<SkPaint>, paint);
178 RECORD3(DrawBitmapMatrix, ImmutableBitmap, bitmap, SkMatrix, matrix, Optional<Sk Paint>, paint);
179 RECORD4(DrawBitmapNine, ImmutableBitmap, bitmap,
180 SkIRect, center,
181 SkRect, dst,
182 Optional<SkPaint>, paint);
153 RECORD5(DrawBitmapRectToRect, ImmutableBitmap, bitmap, 183 RECORD5(DrawBitmapRectToRect, ImmutableBitmap, bitmap,
154 SkRect*, src, 184 Optional<SkRect>, src,
155 SkRect, dst, 185 SkRect, dst,
156 SkPaint*, paint, 186 Optional<SkPaint>, paint,
157 SkCanvas::DrawBitmapRectFlags, flags); 187 SkCanvas::DrawBitmapRectFlags, flags);
158 RECORD3(DrawDRRect, SkRRect, outer, SkRRect, inner, SkPaint, paint); 188 RECORD3(DrawDRRect, SkRRect, outer, SkRRect, inner, SkPaint, paint);
159 RECORD2(DrawOval, SkRect, oval, SkPaint, paint); 189 RECORD2(DrawOval, SkRect, oval, SkPaint, paint);
160 RECORD1(DrawPaint, SkPaint, paint); 190 RECORD1(DrawPaint, SkPaint, paint);
161 RECORD2(DrawPath, SkPath, path, SkPaint, paint); 191 RECORD2(DrawPath, SkPath, path, SkPaint, paint);
162 RECORD4(DrawPoints, SkCanvas::PointMode, mode, size_t, count, SkPoint*, pts, SkP aint, paint); 192 RECORD4(DrawPoints, SkCanvas::PointMode, mode, size_t, count, SkPoint*, pts, SkP aint, paint);
163 RECORD4(DrawPosText, char*, text, size_t, byteLength, SkPoint*, pos, SkPaint, pa int); 193 RECORD4(DrawPosText, PODArray<char>, text,
164 RECORD5(DrawPosTextH, char*, text, 194 size_t, byteLength,
195 PODArray<SkPoint>, pos,
196 SkPaint, paint);
197 RECORD5(DrawPosTextH, PODArray<char>, text,
165 size_t, byteLength, 198 size_t, byteLength,
166 SkScalar*, xpos, 199 PODArray<SkScalar>, xpos,
167 SkScalar, y, 200 SkScalar, y,
168 SkPaint, paint); 201 SkPaint, paint);
169 RECORD2(DrawRRect, SkRRect, rrect, SkPaint, paint); 202 RECORD2(DrawRRect, SkRRect, rrect, SkPaint, paint);
170 RECORD2(DrawRect, SkRect, rect, SkPaint, paint); 203 RECORD2(DrawRect, SkRect, rect, SkPaint, paint);
171 RECORD4(DrawSprite, ImmutableBitmap, bitmap, int, left, int, top, SkPaint*, pain t); 204 RECORD4(DrawSprite, ImmutableBitmap, bitmap, int, left, int, top, Optional<SkPai nt>, paint);
172 RECORD5(DrawText, char*, text, size_t, byteLength, SkScalar, x, SkScalar, y, SkP aint, paint); 205 RECORD5(DrawText, PODArray<char>, text,
173 RECORD5(DrawTextOnPath, char*, text, 206 size_t, byteLength,
207 SkScalar, x,
208 SkScalar, y,
209 SkPaint, paint);
210 RECORD5(DrawTextOnPath, PODArray<char>, text,
174 size_t, byteLength, 211 size_t, byteLength,
175 SkPath, path, 212 SkPath, path,
176 SkMatrix*, matrix, 213 Optional<SkMatrix>, matrix,
177 SkPaint, paint); 214 SkPaint, paint);
178 215
179 // This guy is so ugly we just write it manually. 216 // This guy is so ugly we just write it manually.
180 struct DrawVertices { 217 struct DrawVertices {
181 static const Type kType = DrawVertices_Type; 218 static const Type kType = DrawVertices_Type;
182 219
183 DrawVertices(SkCanvas::VertexMode vmode, 220 DrawVertices(SkCanvas::VertexMode vmode,
184 int vertexCount, 221 int vertexCount,
185 SkPoint* vertices, 222 SkPoint* vertices,
186 SkPoint* texs, 223 SkPoint* texs,
187 SkColor* colors, 224 SkColor* colors,
188 SkXfermode* xmode, 225 SkXfermode* xmode,
189 uint16_t* indices, 226 uint16_t* indices,
190 int indexCount, 227 int indexCount,
191 const SkPaint& paint) 228 const SkPaint& paint)
192 : vmode(vmode) 229 : vmode(vmode)
193 , vertexCount(vertexCount) 230 , vertexCount(vertexCount)
194 , vertices(vertices) 231 , vertices(vertices)
195 , texs(texs) 232 , texs(texs)
196 , colors(colors) 233 , colors(colors)
197 , xmode(SkSafeRef(xmode)) 234 , xmode(SkSafeRef(xmode))
198 , indices(indices) 235 , indices(indices)
199 , indexCount(indexCount) 236 , indexCount(indexCount)
200 , paint(paint) {} 237 , paint(paint) {}
201 238
202 SkCanvas::VertexMode vmode; 239 SkCanvas::VertexMode vmode;
203 int vertexCount; 240 int vertexCount;
204 SkPoint* vertices; 241 PODArray<SkPoint> vertices;
205 SkPoint* texs; 242 PODArray<SkPoint> texs;
206 SkColor* colors; 243 PODArray<SkColor> colors;
207 SkAutoTUnref<SkXfermode> xmode; 244 SkAutoTUnref<SkXfermode> xmode;
208 uint16_t* indices; 245 PODArray<uint16_t> indices;
209 int indexCount; 246 int indexCount;
210 SkPaint paint; 247 SkPaint paint;
211 }; 248 };
212 249
213 #undef RECORD0 250 #undef RECORD0
214 #undef RECORD1 251 #undef RECORD1
215 #undef RECORD2 252 #undef RECORD2
216 #undef RECORD3 253 #undef RECORD3
217 #undef RECORD4 254 #undef RECORD4
218 #undef RECORD5 255 #undef RECORD5
219 256
220 } // namespace SkRecords 257 } // namespace SkRecords
221 258
222 #endif//SkRecords_DEFINED 259 #endif//SkRecords_DEFINED
OLDNEW
« no previous file with comments | « src/record/SkRecordDraw.cpp ('k') | tests/RecorderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698