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 | |
18 void SkBBoxRecord::drawOval(const SkRect& rect, const SkPaint& paint) { | 11 void SkBBoxRecord::drawOval(const SkRect& rect, const SkPaint& paint) { |
19 if (this->transformBounds(rect, &paint)) { | 12 if (this->transformBounds(rect, &paint)) { |
20 INHERITED::drawOval(rect, paint); | 13 INHERITED::drawOval(rect, paint); |
21 } | 14 } |
22 } | 15 } |
23 | 16 |
24 void SkBBoxRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) { | 17 void SkBBoxRecord::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
25 if (this->transformBounds(rrect.rect(), &paint)) { | 18 if (this->transformBounds(rrect.rect(), &paint)) { |
26 INHERITED::drawRRect(rrect, paint); | 19 INHERITED::drawRRect(rrect, paint); |
27 } | 20 } |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 } | 280 } |
288 } | 281 } |
289 | 282 |
290 void SkBBoxRecord::onDrawPicture(const SkPicture* picture) { | 283 void SkBBoxRecord::onDrawPicture(const SkPicture* picture) { |
291 if (picture->width() > 0 && picture->height() > 0 && | 284 if (picture->width() > 0 && picture->height() > 0 && |
292 this->transformBounds(SkRect::MakeWH(picture->width(), picture->height()
), NULL)) { | 285 this->transformBounds(SkRect::MakeWH(picture->width(), picture->height()
), NULL)) { |
293 this->INHERITED::onDrawPicture(picture); | 286 this->INHERITED::onDrawPicture(picture); |
294 } | 287 } |
295 } | 288 } |
296 | 289 |
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 | |
317 bool SkBBoxRecord::transformBounds(const SkRect& bounds, const SkPaint* paint) { | 290 bool SkBBoxRecord::transformBounds(const SkRect& bounds, const SkPaint* paint) { |
318 SkRect outBounds = bounds; | 291 SkRect outBounds = bounds; |
319 outBounds.sort(); | 292 outBounds.sort(); |
320 | 293 |
321 if (paint) { | 294 if (paint) { |
322 // account for stroking, path effects, shadows, etc | 295 // account for stroking, path effects, shadows, etc |
323 if (paint->canComputeFastBounds()) { | 296 if (paint->canComputeFastBounds()) { |
324 SkRect temp; | 297 SkRect temp; |
325 outBounds = paint->computeFastBounds(outBounds, &temp); | 298 outBounds = paint->computeFastBounds(outBounds, &temp); |
326 } else { | 299 } else { |
327 // set bounds to current clip | 300 // set bounds to current clip |
328 if (!this->getClipBounds(&outBounds)) { | 301 if (!this->getClipBounds(&outBounds)) { |
329 // current clip is empty | 302 // current clip is empty |
330 return false; | 303 return false; |
331 } | 304 } |
332 } | 305 } |
333 } | 306 } |
334 | 307 |
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 | |
343 if (!outBounds.isEmpty() && !this->quickReject(outBounds)) { | 308 if (!outBounds.isEmpty() && !this->quickReject(outBounds)) { |
344 this->getTotalMatrix().mapRect(&outBounds); | 309 this->getTotalMatrix().mapRect(&outBounds); |
345 this->handleBBox(outBounds); | 310 this->handleBBox(outBounds); |
346 return true; | 311 return true; |
347 } | 312 } |
348 | 313 |
349 return false; | 314 return false; |
350 } | 315 } |
OLD | NEW |