Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 while (!fSaveStack.empty()) { | |
| 13 delete fSaveStack.top(); | |
| 14 fSaveStack.pop(); | |
| 15 } | |
| 16 } | |
| 17 | |
| 11 void SkBBoxRecord::drawOval(const SkRect& rect, const SkPaint& paint) { | 18 void SkBBoxRecord::drawOval(const SkRect& rect, const SkPaint& paint) { |
| 12 if (this->transformBounds(rect, &paint)) { | 19 if (this->transformBounds(rect, &paint)) { |
| 13 INHERITED::drawOval(rect, paint); | 20 INHERITED::drawOval(rect, paint); |
| 14 } | 21 } |
| 15 } | 22 } |
| 16 | 23 |
| 17 void SkBBoxRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) { | 24 void SkBBoxRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
| 18 if (this->transformBounds(rrect.rect(), &paint)) { | 25 if (this->transformBounds(rrect.rect(), &paint)) { |
| 19 INHERITED::drawRRect(rrect, paint); | 26 INHERITED::drawRRect(rrect, paint); |
| 20 } | 27 } |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 } | 287 } |
| 281 } | 288 } |
| 282 | 289 |
| 283 void SkBBoxRecord::onDrawPicture(const SkPicture* picture) { | 290 void SkBBoxRecord::onDrawPicture(const SkPicture* picture) { |
| 284 if (picture->width() > 0 && picture->height() > 0 && | 291 if (picture->width() > 0 && picture->height() > 0 && |
| 285 this->transformBounds(SkRect::MakeWH(picture->width(), picture->height() ), NULL)) { | 292 this->transformBounds(SkRect::MakeWH(picture->width(), picture->height() ), NULL)) { |
| 286 this->INHERITED::onDrawPicture(picture); | 293 this->INHERITED::onDrawPicture(picture); |
| 287 } | 294 } |
| 288 } | 295 } |
| 289 | 296 |
| 297 void SkBBoxRecord::willSave() { | |
| 298 fSaveStack.push(NULL); | |
| 299 this->INHERITED::willSave(); | |
| 300 } | |
| 301 | |
| 302 SkCanvas::SaveLayerStrategy SkBBoxRecord::willSaveLayer(const SkRect* bounds, | |
| 303 const SkPaint* paint, | |
| 304 SaveFlags flags) { | |
| 305 // Image filters can affect the effective bounds of primitives drawn inside saveLayer(). | |
| 306 // Copy the paint so we can compute the modified bounds in transformBounds() . | |
| 307 fSaveStack.push(paint && paint->getImageFilter() ? new SkPaint(*paint) : NUL L); | |
| 308 return this->INHERITED::willSaveLayer(bounds, paint, flags); | |
| 309 } | |
| 310 | |
| 311 void SkBBoxRecord::willRestore() { | |
| 312 delete fSaveStack.top(); | |
| 313 fSaveStack.pop(); | |
| 314 this->INHERITED::willRestore(); | |
| 315 } | |
| 316 | |
| 290 bool SkBBoxRecord::transformBounds(const SkRect& bounds, const SkPaint* paint) { | 317 bool SkBBoxRecord::transformBounds(const SkRect& bounds, const SkPaint* paint) { |
| 291 SkRect outBounds = bounds; | 318 SkRect outBounds = bounds; |
| 292 outBounds.sort(); | 319 outBounds.sort(); |
| 293 | 320 |
| 294 if (paint) { | 321 if (paint) { |
| 295 // account for stroking, path effects, shadows, etc | 322 // account for stroking, path effects, shadows, etc |
| 296 if (paint->canComputeFastBounds()) { | 323 if (paint->canComputeFastBounds()) { |
| 297 SkRect temp; | 324 SkRect temp; |
| 298 outBounds = paint->computeFastBounds(outBounds, &temp); | 325 outBounds = paint->computeFastBounds(outBounds, &temp); |
| 299 } else { | 326 } else { |
| 300 // set bounds to current clip | 327 // set bounds to current clip |
| 301 if (!this->getClipBounds(&outBounds)) { | 328 if (!this->getClipBounds(&outBounds)) { |
| 302 // current clip is empty | 329 // current clip is empty |
| 303 return false; | 330 return false; |
| 304 } | 331 } |
| 305 } | 332 } |
| 306 } | 333 } |
| 307 | 334 |
|
robertphillips
2014/07/13 18:57:29
I don't think SkTDStack::index does what you want!
Stephen White
2014/07/14 15:35:13
Yeah; looks like SkTDStack is hopelessly broken. S
| |
| 335 for (int i = fSaveStack.count() - 1; i >= 0; --i) { | |
| 336 const SkPaint* paint = fSaveStack.index(i); | |
| 337 if (paint && paint->canComputeFastBounds()) { | |
| 338 SkRect temp; | |
| 339 outBounds = paint->computeFastBounds(outBounds, &temp); | |
| 340 } | |
| 341 } | |
| 342 | |
| 308 if (!outBounds.isEmpty() && !this->quickReject(outBounds)) { | 343 if (!outBounds.isEmpty() && !this->quickReject(outBounds)) { |
| 309 this->getTotalMatrix().mapRect(&outBounds); | 344 this->getTotalMatrix().mapRect(&outBounds); |
| 310 this->handleBBox(outBounds); | 345 this->handleBBox(outBounds); |
| 311 return true; | 346 return true; |
| 312 } | 347 } |
| 313 | 348 |
| 314 return false; | 349 return false; |
| 315 } | 350 } |
| OLD | NEW |