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 fSaveStack.push(paint && paint->getImageFilter() ? new SkPaint(*paint) : NUL L); | |
|
mtklein
2014/07/11 15:37:14
// The only effects that can affect the bounds of
| |
| 306 return this->INHERITED::willSaveLayer(bounds, paint, flags); | |
| 307 } | |
| 308 | |
| 309 void SkBBoxRecord::willRestore() { | |
| 310 delete fSaveStack.top(); | |
| 311 fSaveStack.pop(); | |
| 312 this->INHERITED::willRestore(); | |
| 313 } | |
| 314 | |
| 290 bool SkBBoxRecord::transformBounds(const SkRect& bounds, const SkPaint* paint) { | 315 bool SkBBoxRecord::transformBounds(const SkRect& bounds, const SkPaint* paint) { |
| 291 SkRect outBounds = bounds; | 316 SkRect outBounds = bounds; |
| 292 outBounds.sort(); | 317 outBounds.sort(); |
| 293 | 318 |
| 294 if (paint) { | 319 if (paint) { |
| 295 // account for stroking, path effects, shadows, etc | 320 // account for stroking, path effects, shadows, etc |
| 296 if (paint->canComputeFastBounds()) { | 321 if (paint->canComputeFastBounds()) { |
| 297 SkRect temp; | 322 SkRect temp; |
| 298 outBounds = paint->computeFastBounds(outBounds, &temp); | 323 outBounds = paint->computeFastBounds(outBounds, &temp); |
| 299 } else { | 324 } else { |
| 300 // set bounds to current clip | 325 // set bounds to current clip |
| 301 if (!this->getClipBounds(&outBounds)) { | 326 if (!this->getClipBounds(&outBounds)) { |
| 302 // current clip is empty | 327 // current clip is empty |
| 303 return false; | 328 return false; |
| 304 } | 329 } |
| 305 } | 330 } |
| 306 } | 331 } |
| 307 | 332 |
| 333 for (int i = fSaveStack.count() - 1; i >= 0; --i) { | |
| 334 const SkPaint* paint = fSaveStack.index(i); | |
| 335 if (paint && paint->canComputeFastBounds()) { | |
| 336 SkRect temp; | |
| 337 outBounds = paint->computeFastBounds(outBounds, &temp); | |
| 338 } | |
| 339 } | |
| 340 | |
| 308 if (!outBounds.isEmpty() && !this->quickReject(outBounds)) { | 341 if (!outBounds.isEmpty() && !this->quickReject(outBounds)) { |
| 309 this->getTotalMatrix().mapRect(&outBounds); | 342 this->getTotalMatrix().mapRect(&outBounds); |
| 310 this->handleBBox(outBounds); | 343 this->handleBBox(outBounds); |
| 311 return true; | 344 return true; |
| 312 } | 345 } |
| 313 | 346 |
| 314 return false; | 347 return false; |
| 315 } | 348 } |
| OLD | NEW |