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 #include "SkRecorder.h" | 8 #include "SkRecorder.h" |
9 #include "SkPatchUtils.h" | 9 #include "SkPatchUtils.h" |
10 #include "SkPicture.h" | 10 #include "SkPicture.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 public: | 67 public: |
68 Reference(const T& x) : fX(x) {} | 68 Reference(const T& x) : fX(x) {} |
69 operator const T&() const { return fX; } | 69 operator const T&() const { return fX; } |
70 private: | 70 private: |
71 const T& fX; | 71 const T& fX; |
72 }; | 72 }; |
73 | 73 |
74 template <typename T> | 74 template <typename T> |
75 static Reference<T> delay_copy(const T& x) { return Reference<T>(x); } | 75 static Reference<T> delay_copy(const T& x) { return Reference<T>(x); } |
76 | 76 |
77 // SkPath::getBounds() isn't thread safe unless we precache the bounds in a sing
lethreaded context. | |
78 // Recording is a convenient time to do this, but we could delay it to between r
ecord and playback. | |
79 static Reference<SkPath> force_path_bounds(const SkPath& p) { | |
80 p.updateBoundsCache(); | |
81 return Reference<SkPath>(p); | |
82 } | |
83 | |
84 // Use copy() only for optional arguments, to be copied if present or skipped if
not. | 77 // Use copy() only for optional arguments, to be copied if present or skipped if
not. |
85 // (For most types we just pass by value and let copy constructors do their thin
g.) | 78 // (For most types we just pass by value and let copy constructors do their thin
g.) |
86 template <typename T> | 79 template <typename T> |
87 T* SkRecorder::copy(const T* src) { | 80 T* SkRecorder::copy(const T* src) { |
88 if (NULL == src) { | 81 if (NULL == src) { |
89 return NULL; | 82 return NULL; |
90 } | 83 } |
91 return SkNEW_PLACEMENT_ARGS(fRecord->alloc<T>(), T, (*src)); | 84 return SkNEW_PLACEMENT_ARGS(fRecord->alloc<T>(), T, (*src)); |
92 } | 85 } |
93 | 86 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 | 151 |
159 void SkRecorder::onDrawDrawable(SkCanvasDrawable* drawable) { | 152 void SkRecorder::onDrawDrawable(SkCanvasDrawable* drawable) { |
160 if (!fDrawableList) { | 153 if (!fDrawableList) { |
161 fDrawableList.reset(SkNEW(SkCanvasDrawableList)); | 154 fDrawableList.reset(SkNEW(SkCanvasDrawableList)); |
162 } | 155 } |
163 fDrawableList->append(drawable); | 156 fDrawableList->append(drawable); |
164 APPEND(DrawDrawable, drawable->getBounds(), fDrawableList->count() - 1); | 157 APPEND(DrawDrawable, drawable->getBounds(), fDrawableList->count() - 1); |
165 } | 158 } |
166 | 159 |
167 void SkRecorder::drawPath(const SkPath& path, const SkPaint& paint) { | 160 void SkRecorder::drawPath(const SkPath& path, const SkPaint& paint) { |
168 APPEND(DrawPath, delay_copy(paint), force_path_bounds(path)); | 161 APPEND(DrawPath, delay_copy(paint), delay_copy(path)); |
169 } | 162 } |
170 | 163 |
171 void SkRecorder::drawBitmap(const SkBitmap& bitmap, | 164 void SkRecorder::drawBitmap(const SkBitmap& bitmap, |
172 SkScalar left, | 165 SkScalar left, |
173 SkScalar top, | 166 SkScalar top, |
174 const SkPaint* paint) { | 167 const SkPaint* paint) { |
175 APPEND(DrawBitmap, this->copy(paint), delay_copy(bitmap), left, top); | 168 APPEND(DrawBitmap, this->copy(paint), delay_copy(bitmap), left, top); |
176 } | 169 } |
177 | 170 |
178 void SkRecorder::drawBitmapRectToRect(const SkBitmap& bitmap, | 171 void SkRecorder::drawBitmapRectToRect(const SkBitmap& bitmap, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 constY, | 237 constY, |
245 this->copy(xpos, points)); | 238 this->copy(xpos, points)); |
246 } | 239 } |
247 | 240 |
248 void SkRecorder::onDrawTextOnPath(const void* text, size_t byteLength, const SkP
ath& path, | 241 void SkRecorder::onDrawTextOnPath(const void* text, size_t byteLength, const SkP
ath& path, |
249 const SkMatrix* matrix, const SkPaint& paint)
{ | 242 const SkMatrix* matrix, const SkPaint& paint)
{ |
250 APPEND(DrawTextOnPath, | 243 APPEND(DrawTextOnPath, |
251 delay_copy(paint), | 244 delay_copy(paint), |
252 this->copy((const char*)text, byteLength), | 245 this->copy((const char*)text, byteLength), |
253 byteLength, | 246 byteLength, |
254 force_path_bounds(path), | 247 delay_copy(path), |
255 this->copy(matrix)); | 248 matrix ? *matrix : SkMatrix::I()); |
256 } | 249 } |
257 | 250 |
258 void SkRecorder::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, | 251 void SkRecorder::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
259 const SkPaint& paint) { | 252 const SkPaint& paint) { |
260 APPEND(DrawTextBlob, delay_copy(paint), blob, x, y); | 253 APPEND(DrawTextBlob, delay_copy(paint), blob, x, y); |
261 } | 254 } |
262 | 255 |
263 void SkRecorder::onDrawPicture(const SkPicture* pic, const SkMatrix* matrix, con
st SkPaint* paint) { | 256 void SkRecorder::onDrawPicture(const SkPicture* pic, const SkMatrix* matrix, con
st SkPaint* paint) { |
264 APPEND(DrawPicture, this->copy(paint), pic, this->copy(matrix)); | 257 APPEND(DrawPicture, this->copy(paint), pic, matrix ? *matrix : SkMatrix::I()
); |
265 } | 258 } |
266 | 259 |
267 void SkRecorder::drawVertices(VertexMode vmode, | 260 void SkRecorder::drawVertices(VertexMode vmode, |
268 int vertexCount, const SkPoint vertices[], | 261 int vertexCount, const SkPoint vertices[], |
269 const SkPoint texs[], const SkColor colors[], | 262 const SkPoint texs[], const SkColor colors[], |
270 SkXfermode* xmode, | 263 SkXfermode* xmode, |
271 const uint16_t indices[], int indexCount, const Sk
Paint& paint) { | 264 const uint16_t indices[], int indexCount, const Sk
Paint& paint) { |
272 APPEND(DrawVertices, delay_copy(paint), | 265 APPEND(DrawVertices, delay_copy(paint), |
273 vmode, | 266 vmode, |
274 vertexCount, | 267 vertexCount, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 | 334 |
342 void SkRecorder::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyl
e edgeStyle) { | 335 void SkRecorder::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyl
e edgeStyle) { |
343 INHERITED(onClipRRect, rrect, op, edgeStyle); | 336 INHERITED(onClipRRect, rrect, op, edgeStyle); |
344 SkRecords::RegionOpAndAA opAA(op, kSoft_ClipEdgeStyle == edgeStyle); | 337 SkRecords::RegionOpAndAA opAA(op, kSoft_ClipEdgeStyle == edgeStyle); |
345 APPEND(ClipRRect, this->devBounds(), rrect, opAA); | 338 APPEND(ClipRRect, this->devBounds(), rrect, opAA); |
346 } | 339 } |
347 | 340 |
348 void SkRecorder::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle e
dgeStyle) { | 341 void SkRecorder::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle e
dgeStyle) { |
349 INHERITED(onClipPath, path, op, edgeStyle); | 342 INHERITED(onClipPath, path, op, edgeStyle); |
350 SkRecords::RegionOpAndAA opAA(op, kSoft_ClipEdgeStyle == edgeStyle); | 343 SkRecords::RegionOpAndAA opAA(op, kSoft_ClipEdgeStyle == edgeStyle); |
351 APPEND(ClipPath, this->devBounds(), force_path_bounds(path), opAA); | 344 APPEND(ClipPath, this->devBounds(), delay_copy(path), opAA); |
352 } | 345 } |
353 | 346 |
354 void SkRecorder::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { | 347 void SkRecorder::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { |
355 INHERITED(onClipRegion, deviceRgn, op); | 348 INHERITED(onClipRegion, deviceRgn, op); |
356 APPEND(ClipRegion, this->devBounds(), delay_copy(deviceRgn), op); | 349 APPEND(ClipRegion, this->devBounds(), delay_copy(deviceRgn), op); |
357 } | 350 } |
358 | 351 |
359 void SkRecorder::beginCommentGroup(const char* description) { | 352 void SkRecorder::beginCommentGroup(const char* description) { |
360 APPEND(BeginCommentGroup, this->copy(description)); | 353 APPEND(BeginCommentGroup, this->copy(description)); |
361 } | 354 } |
362 | 355 |
363 void SkRecorder::addComment(const char* key, const char* value) { | 356 void SkRecorder::addComment(const char* key, const char* value) { |
364 APPEND(AddComment, this->copy(key), this->copy(value)); | 357 APPEND(AddComment, this->copy(key), this->copy(value)); |
365 } | 358 } |
366 | 359 |
367 void SkRecorder::endCommentGroup() { | 360 void SkRecorder::endCommentGroup() { |
368 APPEND(EndCommentGroup); | 361 APPEND(EndCommentGroup); |
369 } | 362 } |
370 | 363 |
371 bool SkRecorder::isDrawingToLayer() const { | 364 bool SkRecorder::isDrawingToLayer() const { |
372 return fSaveLayerCount > 0; | 365 return fSaveLayerCount > 0; |
373 } | 366 } |
374 | 367 |
375 void SkRecorder::drawData(const void* data, size_t length) { | 368 void SkRecorder::drawData(const void* data, size_t length) { |
376 APPEND(DrawData, copy((const char*)data), length); | 369 APPEND(DrawData, copy((const char*)data), length); |
377 } | 370 } |
OLD | NEW |