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

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

Issue 380373003: Fix for saveLayer() with filters vs. the BBox Hierarchy. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Use SkTDArray::deleteAll() Created 6 years, 5 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/core/SkBBoxRecord.h ('k') | tests/ImageFilterTest.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 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 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 8
9 #include "SkBBoxRecord.h" 9 #include "SkBBoxRecord.h"
10 10
11 SkBBoxRecord::~SkBBoxRecord() {
12 fSaveStack.deleteAll();
13 }
14
11 void SkBBoxRecord::drawOval(const SkRect& rect, const SkPaint& paint) { 15 void SkBBoxRecord::drawOval(const SkRect& rect, const SkPaint& paint) {
12 if (this->transformBounds(rect, &paint)) { 16 if (this->transformBounds(rect, &paint)) {
13 INHERITED::drawOval(rect, paint); 17 INHERITED::drawOval(rect, paint);
14 } 18 }
15 } 19 }
16 20
17 void SkBBoxRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) { 21 void SkBBoxRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
18 if (this->transformBounds(rrect.rect(), &paint)) { 22 if (this->transformBounds(rrect.rect(), &paint)) {
19 INHERITED::drawRRect(rrect, paint); 23 INHERITED::drawRRect(rrect, paint);
20 } 24 }
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 } 284 }
281 } 285 }
282 286
283 void SkBBoxRecord::onDrawPicture(const SkPicture* picture) { 287 void SkBBoxRecord::onDrawPicture(const SkPicture* picture) {
284 if (picture->width() > 0 && picture->height() > 0 && 288 if (picture->width() > 0 && picture->height() > 0 &&
285 this->transformBounds(SkRect::MakeWH(picture->width(), picture->height() ), NULL)) { 289 this->transformBounds(SkRect::MakeWH(picture->width(), picture->height() ), NULL)) {
286 this->INHERITED::onDrawPicture(picture); 290 this->INHERITED::onDrawPicture(picture);
287 } 291 }
288 } 292 }
289 293
294 void SkBBoxRecord::willSave() {
295 fSaveStack.push(NULL);
296 this->INHERITED::willSave();
297 }
298
299 SkCanvas::SaveLayerStrategy SkBBoxRecord::willSaveLayer(const SkRect* bounds,
300 const SkPaint* paint,
301 SaveFlags flags) {
302 // Image filters can affect the effective bounds of primitives drawn inside saveLayer().
303 // Copy the paint so we can compute the modified bounds in transformBounds() .
304 fSaveStack.push(paint && paint->getImageFilter() ? new SkPaint(*paint) : NUL L);
305 return this->INHERITED::willSaveLayer(bounds, paint, flags);
306 }
307
308 void SkBBoxRecord::willRestore() {
309 delete fSaveStack.top();
310 fSaveStack.pop();
311 this->INHERITED::willRestore();
312 }
313
290 bool SkBBoxRecord::transformBounds(const SkRect& bounds, const SkPaint* paint) { 314 bool SkBBoxRecord::transformBounds(const SkRect& bounds, const SkPaint* paint) {
291 SkRect outBounds = bounds; 315 SkRect outBounds = bounds;
292 outBounds.sort(); 316 outBounds.sort();
293 317
294 if (paint) { 318 if (paint) {
295 // account for stroking, path effects, shadows, etc 319 // account for stroking, path effects, shadows, etc
296 if (paint->canComputeFastBounds()) { 320 if (paint->canComputeFastBounds()) {
297 SkRect temp; 321 SkRect temp;
298 outBounds = paint->computeFastBounds(outBounds, &temp); 322 outBounds = paint->computeFastBounds(outBounds, &temp);
299 } else { 323 } else {
300 // set bounds to current clip 324 // set bounds to current clip
301 if (!this->getClipBounds(&outBounds)) { 325 if (!this->getClipBounds(&outBounds)) {
302 // current clip is empty 326 // current clip is empty
303 return false; 327 return false;
304 } 328 }
305 } 329 }
306 } 330 }
307 331
332 for (int i = fSaveStack.count() - 1; i >= 0; --i) {
333 const SkPaint* paint = fSaveStack.getAt(i);
334 if (paint && paint->canComputeFastBounds()) {
335 SkRect temp;
336 outBounds = paint->computeFastBounds(outBounds, &temp);
337 }
338 }
339
308 if (!outBounds.isEmpty() && !this->quickReject(outBounds)) { 340 if (!outBounds.isEmpty() && !this->quickReject(outBounds)) {
309 this->getTotalMatrix().mapRect(&outBounds); 341 this->getTotalMatrix().mapRect(&outBounds);
310 this->handleBBox(outBounds); 342 this->handleBBox(outBounds);
311 return true; 343 return true;
312 } 344 }
313 345
314 return false; 346 return false;
315 } 347 }
OLDNEW
« no previous file with comments | « src/core/SkBBoxRecord.h ('k') | tests/ImageFilterTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698