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() { | |
mtklein
2014/07/14 16:43:12
Consider just calling fSaveStack.deleteAll() ?
Stephen White
2014/07/14 16:55:00
Done.
| |
12 for (int i = fSaveStack.count() - 1; i >= 0; --i) { | |
13 delete fSaveStack.getAt(i); | |
14 } | |
15 } | |
16 | |
11 void SkBBoxRecord::drawOval(const SkRect& rect, const SkPaint& paint) { | 17 void SkBBoxRecord::drawOval(const SkRect& rect, const SkPaint& paint) { |
12 if (this->transformBounds(rect, &paint)) { | 18 if (this->transformBounds(rect, &paint)) { |
13 INHERITED::drawOval(rect, paint); | 19 INHERITED::drawOval(rect, paint); |
14 } | 20 } |
15 } | 21 } |
16 | 22 |
17 void SkBBoxRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) { | 23 void SkBBoxRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
18 if (this->transformBounds(rrect.rect(), &paint)) { | 24 if (this->transformBounds(rrect.rect(), &paint)) { |
19 INHERITED::drawRRect(rrect, paint); | 25 INHERITED::drawRRect(rrect, paint); |
20 } | 26 } |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 } | 286 } |
281 } | 287 } |
282 | 288 |
283 void SkBBoxRecord::onDrawPicture(const SkPicture* picture) { | 289 void SkBBoxRecord::onDrawPicture(const SkPicture* picture) { |
284 if (picture->width() > 0 && picture->height() > 0 && | 290 if (picture->width() > 0 && picture->height() > 0 && |
285 this->transformBounds(SkRect::MakeWH(picture->width(), picture->height() ), NULL)) { | 291 this->transformBounds(SkRect::MakeWH(picture->width(), picture->height() ), NULL)) { |
286 this->INHERITED::onDrawPicture(picture); | 292 this->INHERITED::onDrawPicture(picture); |
287 } | 293 } |
288 } | 294 } |
289 | 295 |
296 void SkBBoxRecord::willSave() { | |
297 *fSaveStack.append() = NULL; | |
298 this->INHERITED::willSave(); | |
299 } | |
300 | |
301 SkCanvas::SaveLayerStrategy SkBBoxRecord::willSaveLayer(const SkRect* bounds, | |
302 const SkPaint* paint, | |
303 SaveFlags flags) { | |
304 // Image filters can affect the effective bounds of primitives drawn inside saveLayer(). | |
305 // Copy the paint so we can compute the modified bounds in transformBounds() . | |
306 *fSaveStack.append() = paint && paint->getImageFilter() ? new SkPaint(*paint ) : NULL; | |
mtklein
2014/07/14 16:43:12
Completely fine, but consider
fSaveStack.push(pai
Stephen White
2014/07/14 16:55:00
Ha! Didn't notice those, thanks!
Done.
| |
307 return this->INHERITED::willSaveLayer(bounds, paint, flags); | |
308 } | |
309 | |
310 void SkBBoxRecord::willRestore() { | |
311 int last = fSaveStack.count() - 1; | |
mtklein
2014/07/14 16:43:12
delete fSaveStack.top();
fSaveStack.pop();
?
Stephen White
2014/07/14 16:55:00
Done.
| |
312 delete fSaveStack.getAt(last); | |
313 fSaveStack.setCount(last); | |
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 |
335 for (int i = fSaveStack.count() - 1; i >= 0; --i) { | |
336 const SkPaint* paint = fSaveStack.getAt(i); | |
mtklein
2014/07/14 16:43:12
fSaveStack[i] ?
Stephen White
2014/07/14 16:55:00
Think I'll stick with the explicit version here (o
| |
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 |