OLD | NEW |
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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 177 |
178 ACT_AS_PTR(fPtr); | 178 ACT_AS_PTR(fPtr); |
179 private: | 179 private: |
180 T* fPtr; | 180 T* fPtr; |
181 }; | 181 }; |
182 | 182 |
183 #undef ACT_AS_PTR | 183 #undef ACT_AS_PTR |
184 | 184 |
185 // Like SkBitmap, but deep copies pixels if they're not immutable. | 185 // Like SkBitmap, but deep copies pixels if they're not immutable. |
186 // Using this, we guarantee the immutability of all bitmaps we record. | 186 // Using this, we guarantee the immutability of all bitmaps we record. |
187 class ImmutableBitmap : SkNoncopyable { | 187 struct ImmutableBitmap : public SkBitmap { |
188 public: | |
189 explicit ImmutableBitmap(const SkBitmap& bitmap) { | 188 explicit ImmutableBitmap(const SkBitmap& bitmap) { |
190 if (bitmap.isImmutable()) { | 189 if (bitmap.isImmutable()) { |
191 fBitmap = bitmap; | 190 *(SkBitmap*)this = bitmap; |
192 } else { | 191 } else { |
193 bitmap.copyTo(&fBitmap); | 192 bitmap.copyTo(this); |
194 } | 193 } |
195 fBitmap.setImmutable(); | 194 this->setImmutable(); |
196 } | 195 } |
| 196 }; |
197 | 197 |
198 operator const SkBitmap& () const { return fBitmap; } | 198 // SkPath::getBounds() isn't thread safe unless we precache the bounds in a sing
lethreaded context. |
| 199 // Recording is a convenient time to do this, but we could delay it to between r
ecord and playback. |
| 200 struct BoundedPath : public SkPath { |
| 201 explicit BoundedPath(const SkPath& path) : SkPath(path) { |
| 202 this->updateBoundsCache(); |
| 203 } |
| 204 }; |
199 | 205 |
200 private: | 206 // Like SkPath::getBounds(), SkMatrix::getType() isn't thread safe unless we pre
cache it. |
201 SkBitmap fBitmap; | 207 // This may not cover all SkMatrices used by the picture (e.g. some could be hid
ing in a shader). |
| 208 struct TypedMatrix : public SkMatrix { |
| 209 explicit TypedMatrix(const SkMatrix& matrix) : SkMatrix(matrix) { |
| 210 (void)this->getType(); |
| 211 } |
202 }; | 212 }; |
203 | 213 |
204 RECORD0(NoOp); | 214 RECORD0(NoOp); |
205 | 215 |
206 RECORD2(Restore, SkIRect, devBounds, SkMatrix, matrix); | 216 RECORD2(Restore, SkIRect, devBounds, TypedMatrix, matrix); |
207 RECORD0(Save); | 217 RECORD0(Save); |
208 RECORD3(SaveLayer, Optional<SkRect>, bounds, Optional<SkPaint>, paint, SkCanvas:
:SaveFlags, flags); | 218 RECORD3(SaveLayer, Optional<SkRect>, bounds, Optional<SkPaint>, paint, SkCanvas:
:SaveFlags, flags); |
209 | 219 |
210 RECORD1(PushCull, SkRect, rect); | 220 RECORD1(PushCull, SkRect, rect); |
211 RECORD0(PopCull); | 221 RECORD0(PopCull); |
212 | 222 |
213 RECORD1(SetMatrix, SkMatrix, matrix); | 223 RECORD1(SetMatrix, TypedMatrix, matrix); |
214 | 224 |
215 struct RegionOpAndAA { | 225 struct RegionOpAndAA { |
216 RegionOpAndAA(SkRegion::Op op, bool aa) : op(op), aa(aa) {} | 226 RegionOpAndAA(SkRegion::Op op, bool aa) : op(op), aa(aa) {} |
217 SkRegion::Op op : 31; // This really only needs to be 3, but there's no win
today to do so. | 227 SkRegion::Op op : 31; // This really only needs to be 3, but there's no win
today to do so. |
218 unsigned aa : 1; // MSVC won't pack an enum with an bool, so we call t
his an unsigned. | 228 unsigned aa : 1; // MSVC won't pack an enum with an bool, so we call t
his an unsigned. |
219 }; | 229 }; |
220 SK_COMPILE_ASSERT(sizeof(RegionOpAndAA) == 4, RegionOpAndAASize); | 230 SK_COMPILE_ASSERT(sizeof(RegionOpAndAA) == 4, RegionOpAndAASize); |
221 | 231 |
222 RECORD3(ClipPath, SkIRect, devBounds, SkPath, path, RegionOpAndAA, opAA); | 232 RECORD3(ClipPath, SkIRect, devBounds, BoundedPath, path, RegionOpAndAA, opAA); |
223 RECORD3(ClipRRect, SkIRect, devBounds, SkRRect, rrect, RegionOpAndAA, opAA); | 233 RECORD3(ClipRRect, SkIRect, devBounds, SkRRect, rrect, RegionOpAndAA, opAA); |
224 RECORD3(ClipRect, SkIRect, devBounds, SkRect, rect, RegionOpAndAA, opAA); | 234 RECORD3(ClipRect, SkIRect, devBounds, SkRect, rect, RegionOpAndAA, opAA); |
225 RECORD3(ClipRegion, SkIRect, devBounds, SkRegion, region, SkRegion::Op, op); | 235 RECORD3(ClipRegion, SkIRect, devBounds, SkRegion, region, SkRegion::Op, op); |
226 | 236 |
227 RECORD1(Clear, SkColor, color); | 237 RECORD1(Clear, SkColor, color); |
228 | 238 |
229 RECORD1(BeginCommentGroup, PODArray<char>, description); | 239 RECORD1(BeginCommentGroup, PODArray<char>, description); |
230 RECORD2(AddComment, PODArray<char>, key, PODArray<char>, value); | 240 RECORD2(AddComment, PODArray<char>, key, PODArray<char>, value); |
231 RECORD0(EndCommentGroup); | 241 RECORD0(EndCommentGroup); |
232 | 242 |
233 // While not strictly required, if you have an SkPaint, it's fastest to put it f
irst. | 243 // While not strictly required, if you have an SkPaint, it's fastest to put it f
irst. |
234 RECORD4(DrawBitmap, Optional<SkPaint>, paint, | 244 RECORD4(DrawBitmap, Optional<SkPaint>, paint, |
235 ImmutableBitmap, bitmap, | 245 ImmutableBitmap, bitmap, |
236 SkScalar, left, | 246 SkScalar, left, |
237 SkScalar, top); | 247 SkScalar, top); |
238 RECORD3(DrawBitmapMatrix, Optional<SkPaint>, paint, ImmutableBitmap, bitmap, SkM
atrix, matrix); | 248 RECORD3(DrawBitmapMatrix, Optional<SkPaint>, paint, ImmutableBitmap, bitmap, Typ
edMatrix, matrix); |
239 RECORD4(DrawBitmapNine, Optional<SkPaint>, paint, | 249 RECORD4(DrawBitmapNine, Optional<SkPaint>, paint, |
240 ImmutableBitmap, bitmap, | 250 ImmutableBitmap, bitmap, |
241 SkIRect, center, | 251 SkIRect, center, |
242 SkRect, dst); | 252 SkRect, dst); |
243 RECORD4(DrawBitmapRectToRect, Optional<SkPaint>, paint, | 253 RECORD4(DrawBitmapRectToRect, Optional<SkPaint>, paint, |
244 ImmutableBitmap, bitmap, | 254 ImmutableBitmap, bitmap, |
245 Optional<SkRect>, src, | 255 Optional<SkRect>, src, |
246 SkRect, dst); | 256 SkRect, dst); |
247 RECORD4(DrawBitmapRectToRectBleed, Optional<SkPaint>, paint, | 257 RECORD4(DrawBitmapRectToRectBleed, Optional<SkPaint>, paint, |
248 ImmutableBitmap, bitmap, | 258 ImmutableBitmap, bitmap, |
249 Optional<SkRect>, src, | 259 Optional<SkRect>, src, |
250 SkRect, dst); | 260 SkRect, dst); |
251 RECORD3(DrawDRRect, SkPaint, paint, SkRRect, outer, SkRRect, inner); | 261 RECORD3(DrawDRRect, SkPaint, paint, SkRRect, outer, SkRRect, inner); |
252 RECORD2(DrawDrawable, SkRect, worstCaseBounds, int32_t, index); | 262 RECORD2(DrawDrawable, SkRect, worstCaseBounds, int32_t, index); |
253 RECORD4(DrawImage, Optional<SkPaint>, paint, | 263 RECORD4(DrawImage, Optional<SkPaint>, paint, |
254 RefBox<const SkImage>, image, | 264 RefBox<const SkImage>, image, |
255 SkScalar, left, | 265 SkScalar, left, |
256 SkScalar, top); | 266 SkScalar, top); |
257 RECORD4(DrawImageRect, Optional<SkPaint>, paint, | 267 RECORD4(DrawImageRect, Optional<SkPaint>, paint, |
258 RefBox<const SkImage>, image, | 268 RefBox<const SkImage>, image, |
259 Optional<SkRect>, src, | 269 Optional<SkRect>, src, |
260 SkRect, dst); | 270 SkRect, dst); |
261 RECORD2(DrawOval, SkPaint, paint, SkRect, oval); | 271 RECORD2(DrawOval, SkPaint, paint, SkRect, oval); |
262 RECORD1(DrawPaint, SkPaint, paint); | 272 RECORD1(DrawPaint, SkPaint, paint); |
263 RECORD2(DrawPath, SkPaint, paint, SkPath, path); | 273 RECORD2(DrawPath, SkPaint, paint, BoundedPath, path); |
264 RECORD3(DrawPicture, Optional<SkPaint>, paint, | 274 RECORD3(DrawPicture, Optional<SkPaint>, paint, |
265 RefBox<const SkPicture>, picture, | 275 RefBox<const SkPicture>, picture, |
266 Optional<SkMatrix>, matrix); | 276 TypedMatrix, matrix); |
267 RECORD4(DrawPoints, SkPaint, paint, SkCanvas::PointMode, mode, unsigned, count,
SkPoint*, pts); | 277 RECORD4(DrawPoints, SkPaint, paint, SkCanvas::PointMode, mode, unsigned, count,
SkPoint*, pts); |
268 RECORD4(DrawPosText, SkPaint, paint, | 278 RECORD4(DrawPosText, SkPaint, paint, |
269 PODArray<char>, text, | 279 PODArray<char>, text, |
270 size_t, byteLength, | 280 size_t, byteLength, |
271 PODArray<SkPoint>, pos); | 281 PODArray<SkPoint>, pos); |
272 RECORD5(DrawPosTextH, SkPaint, paint, | 282 RECORD5(DrawPosTextH, SkPaint, paint, |
273 PODArray<char>, text, | 283 PODArray<char>, text, |
274 unsigned, byteLength, | 284 unsigned, byteLength, |
275 SkScalar, y, | 285 SkScalar, y, |
276 PODArray<SkScalar>, xpos); | 286 PODArray<SkScalar>, xpos); |
277 RECORD2(DrawRRect, SkPaint, paint, SkRRect, rrect); | 287 RECORD2(DrawRRect, SkPaint, paint, SkRRect, rrect); |
278 RECORD2(DrawRect, SkPaint, paint, SkRect, rect); | 288 RECORD2(DrawRect, SkPaint, paint, SkRect, rect); |
279 RECORD4(DrawSprite, Optional<SkPaint>, paint, ImmutableBitmap, bitmap, int, left
, int, top); | 289 RECORD4(DrawSprite, Optional<SkPaint>, paint, ImmutableBitmap, bitmap, int, left
, int, top); |
280 RECORD5(DrawText, SkPaint, paint, | 290 RECORD5(DrawText, SkPaint, paint, |
281 PODArray<char>, text, | 291 PODArray<char>, text, |
282 size_t, byteLength, | 292 size_t, byteLength, |
283 SkScalar, x, | 293 SkScalar, x, |
284 SkScalar, y); | 294 SkScalar, y); |
285 RECORD4(DrawTextBlob, SkPaint, paint, | 295 RECORD4(DrawTextBlob, SkPaint, paint, |
286 RefBox<const SkTextBlob>, blob, | 296 RefBox<const SkTextBlob>, blob, |
287 SkScalar, x, | 297 SkScalar, x, |
288 SkScalar, y); | 298 SkScalar, y); |
289 RECORD5(DrawTextOnPath, SkPaint, paint, | 299 RECORD5(DrawTextOnPath, SkPaint, paint, |
290 PODArray<char>, text, | 300 PODArray<char>, text, |
291 size_t, byteLength, | 301 size_t, byteLength, |
292 SkPath, path, | 302 BoundedPath, path, |
293 Optional<SkMatrix>, matrix); | 303 TypedMatrix, matrix); |
294 | 304 |
295 RECORD2(DrawData, PODArray<char>, data, size_t, length); | 305 RECORD2(DrawData, PODArray<char>, data, size_t, length); |
296 | 306 |
297 RECORD5(DrawPatch, SkPaint, paint, | 307 RECORD5(DrawPatch, SkPaint, paint, |
298 PODArray<SkPoint>, cubics, | 308 PODArray<SkPoint>, cubics, |
299 PODArray<SkColor>, colors, | 309 PODArray<SkColor>, colors, |
300 PODArray<SkPoint>, texCoords, | 310 PODArray<SkPoint>, texCoords, |
301 RefBox<SkXfermode>, xmode); | 311 RefBox<SkXfermode>, xmode); |
302 | 312 |
303 // This guy is so ugly we just write it manually. | 313 // This guy is so ugly we just write it manually. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 #undef RECORD0 | 347 #undef RECORD0 |
338 #undef RECORD1 | 348 #undef RECORD1 |
339 #undef RECORD2 | 349 #undef RECORD2 |
340 #undef RECORD3 | 350 #undef RECORD3 |
341 #undef RECORD4 | 351 #undef RECORD4 |
342 #undef RECORD5 | 352 #undef RECORD5 |
343 | 353 |
344 } // namespace SkRecords | 354 } // namespace SkRecords |
345 | 355 |
346 #endif//SkRecords_DEFINED | 356 #endif//SkRecords_DEFINED |
OLD | NEW |