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

Side by Side Diff: src/core/SkRecorder.cpp

Issue 762313002: Force path bounds in recording. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: unused Created 6 years 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/core/SkPathRef.cpp ('k') | no next file » | 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 #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
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
77 // Use copy() only for optional arguments, to be copied if present or skipped if not. 84 // Use copy() only for optional arguments, to be copied if present or skipped if not.
78 // (For most types we just pass by value and let copy constructors do their thin g.) 85 // (For most types we just pass by value and let copy constructors do their thin g.)
79 template <typename T> 86 template <typename T>
80 T* SkRecorder::copy(const T* src) { 87 T* SkRecorder::copy(const T* src) {
81 if (NULL == src) { 88 if (NULL == src) {
82 return NULL; 89 return NULL;
83 } 90 }
84 return SkNEW_PLACEMENT_ARGS(fRecord->alloc<T>(), T, (*src)); 91 return SkNEW_PLACEMENT_ARGS(fRecord->alloc<T>(), T, (*src));
85 } 92 }
86 93
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 158
152 void SkRecorder::onDrawDrawable(SkCanvasDrawable* drawable) { 159 void SkRecorder::onDrawDrawable(SkCanvasDrawable* drawable) {
153 if (!fDrawableList) { 160 if (!fDrawableList) {
154 fDrawableList.reset(SkNEW(SkCanvasDrawableList)); 161 fDrawableList.reset(SkNEW(SkCanvasDrawableList));
155 } 162 }
156 fDrawableList->append(drawable); 163 fDrawableList->append(drawable);
157 APPEND(DrawDrawable, drawable->getBounds(), fDrawableList->count() - 1); 164 APPEND(DrawDrawable, drawable->getBounds(), fDrawableList->count() - 1);
158 } 165 }
159 166
160 void SkRecorder::drawPath(const SkPath& path, const SkPaint& paint) { 167 void SkRecorder::drawPath(const SkPath& path, const SkPaint& paint) {
161 APPEND(DrawPath, delay_copy(paint), delay_copy(path)); 168 APPEND(DrawPath, delay_copy(paint), force_path_bounds(path));
162 } 169 }
163 170
164 void SkRecorder::drawBitmap(const SkBitmap& bitmap, 171 void SkRecorder::drawBitmap(const SkBitmap& bitmap,
165 SkScalar left, 172 SkScalar left,
166 SkScalar top, 173 SkScalar top,
167 const SkPaint* paint) { 174 const SkPaint* paint) {
168 APPEND(DrawBitmap, this->copy(paint), delay_copy(bitmap), left, top); 175 APPEND(DrawBitmap, this->copy(paint), delay_copy(bitmap), left, top);
169 } 176 }
170 177
171 void SkRecorder::drawBitmapRectToRect(const SkBitmap& bitmap, 178 void SkRecorder::drawBitmapRectToRect(const SkBitmap& bitmap,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 constY, 244 constY,
238 this->copy(xpos, points)); 245 this->copy(xpos, points));
239 } 246 }
240 247
241 void SkRecorder::onDrawTextOnPath(const void* text, size_t byteLength, const SkP ath& path, 248 void SkRecorder::onDrawTextOnPath(const void* text, size_t byteLength, const SkP ath& path,
242 const SkMatrix* matrix, const SkPaint& paint) { 249 const SkMatrix* matrix, const SkPaint& paint) {
243 APPEND(DrawTextOnPath, 250 APPEND(DrawTextOnPath,
244 delay_copy(paint), 251 delay_copy(paint),
245 this->copy((const char*)text, byteLength), 252 this->copy((const char*)text, byteLength),
246 byteLength, 253 byteLength,
247 delay_copy(path), 254 force_path_bounds(path),
248 this->copy(matrix)); 255 this->copy(matrix));
249 } 256 }
250 257
251 void SkRecorder::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, 258 void SkRecorder::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
252 const SkPaint& paint) { 259 const SkPaint& paint) {
253 APPEND(DrawTextBlob, delay_copy(paint), blob, x, y); 260 APPEND(DrawTextBlob, delay_copy(paint), blob, x, y);
254 } 261 }
255 262
256 void SkRecorder::onDrawPicture(const SkPicture* pic, const SkMatrix* matrix, con st SkPaint* paint) { 263 void SkRecorder::onDrawPicture(const SkPicture* pic, const SkMatrix* matrix, con st SkPaint* paint) {
257 APPEND(DrawPicture, this->copy(paint), pic, this->copy(matrix)); 264 APPEND(DrawPicture, this->copy(paint), pic, this->copy(matrix));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 341
335 void SkRecorder::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyl e edgeStyle) { 342 void SkRecorder::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyl e edgeStyle) {
336 INHERITED(onClipRRect, rrect, op, edgeStyle); 343 INHERITED(onClipRRect, rrect, op, edgeStyle);
337 SkRecords::RegionOpAndAA opAA(op, kSoft_ClipEdgeStyle == edgeStyle); 344 SkRecords::RegionOpAndAA opAA(op, kSoft_ClipEdgeStyle == edgeStyle);
338 APPEND(ClipRRect, this->devBounds(), rrect, opAA); 345 APPEND(ClipRRect, this->devBounds(), rrect, opAA);
339 } 346 }
340 347
341 void SkRecorder::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle e dgeStyle) { 348 void SkRecorder::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle e dgeStyle) {
342 INHERITED(onClipPath, path, op, edgeStyle); 349 INHERITED(onClipPath, path, op, edgeStyle);
343 SkRecords::RegionOpAndAA opAA(op, kSoft_ClipEdgeStyle == edgeStyle); 350 SkRecords::RegionOpAndAA opAA(op, kSoft_ClipEdgeStyle == edgeStyle);
344 APPEND(ClipPath, this->devBounds(), delay_copy(path), opAA); 351 APPEND(ClipPath, this->devBounds(), force_path_bounds(path), opAA);
345 } 352 }
346 353
347 void SkRecorder::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { 354 void SkRecorder::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
348 INHERITED(onClipRegion, deviceRgn, op); 355 INHERITED(onClipRegion, deviceRgn, op);
349 APPEND(ClipRegion, this->devBounds(), delay_copy(deviceRgn), op); 356 APPEND(ClipRegion, this->devBounds(), delay_copy(deviceRgn), op);
350 } 357 }
351 358
352 void SkRecorder::beginCommentGroup(const char* description) { 359 void SkRecorder::beginCommentGroup(const char* description) {
353 APPEND(BeginCommentGroup, this->copy(description)); 360 APPEND(BeginCommentGroup, this->copy(description));
354 } 361 }
355 362
356 void SkRecorder::addComment(const char* key, const char* value) { 363 void SkRecorder::addComment(const char* key, const char* value) {
357 APPEND(AddComment, this->copy(key), this->copy(value)); 364 APPEND(AddComment, this->copy(key), this->copy(value));
358 } 365 }
359 366
360 void SkRecorder::endCommentGroup() { 367 void SkRecorder::endCommentGroup() {
361 APPEND(EndCommentGroup); 368 APPEND(EndCommentGroup);
362 } 369 }
363 370
364 bool SkRecorder::isDrawingToLayer() const { 371 bool SkRecorder::isDrawingToLayer() const {
365 return fSaveLayerCount > 0; 372 return fSaveLayerCount > 0;
366 } 373 }
367 374
368 void SkRecorder::drawData(const void* data, size_t length) { 375 void SkRecorder::drawData(const void* data, size_t length) {
369 APPEND(DrawData, copy((const char*)data), length); 376 APPEND(DrawData, copy((const char*)data), length);
370 } 377 }
OLDNEW
« no previous file with comments | « src/core/SkPathRef.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698