Chromium Code Reviews| Index: cc/playback/discardable_image_map.cc |
| diff --git a/cc/playback/discardable_image_map.cc b/cc/playback/discardable_image_map.cc |
| index 840de37a95686e3cd38a9d5066cf0b1646ff868a..0d07f2c6ef279062fbfcea8fd6ebf93d28844e14 100644 |
| --- a/cc/playback/discardable_image_map.cc |
| +++ b/cc/playback/discardable_image_map.cc |
| @@ -24,6 +24,24 @@ SkRect MapRect(const SkMatrix& matrix, const SkRect& src) { |
| return dst; |
| } |
| +gfx::Rect SafeIntersectRects(const SkRect& paint_rect, |
| + const gfx::Rect& max_bounds) { |
| + DCHECK_EQ(0, max_bounds.x()); |
|
enne (OOO)
2016/08/08 21:54:01
How about just passing a gfx::Size? If that makes
vmpstr
2016/08/08 22:25:14
Done.
|
| + DCHECK_EQ(0, max_bounds.y()); |
| + |
| + // bounds_rect.x() + bounds_rect.width() (aka bounds_rect.right()) might |
| + // overflow integer bounds, so do custom intersect, since gfx::Rect::Intersect |
| + // uses bounds_rect.right(). |
| + gfx::RectF bounds_rect = gfx::SkRectToRectF(paint_rect); |
| + bounds_rect.set_x(std::max(0.f, bounds_rect.x())); |
| + bounds_rect.set_y(std::max(0.f, bounds_rect.y())); |
| + bounds_rect.set_width( |
| + std::min(bounds_rect.width(), max_bounds.width() - bounds_rect.x())); |
|
enne (OOO)
2016/08/08 21:54:01
Can this be negative if the paint offset is outsid
vmpstr
2016/08/08 22:25:14
That shouldn't be possible since there's an early
|
| + bounds_rect.set_height( |
| + std::min(bounds_rect.height(), max_bounds.height() - bounds_rect.y())); |
| + return gfx::ToEnclosingRect(bounds_rect); |
| +} |
| + |
| namespace { |
| // We're using an NWay canvas with no added canvases, so in effect |
| @@ -36,7 +54,9 @@ class DiscardableImagesMetadataCanvas : public SkNWayCanvas { |
| std::vector<std::pair<DrawImage, gfx::Rect>>* image_set) |
| : SkNWayCanvas(width, height), |
| image_set_(image_set), |
| - canvas_bounds_(SkRect::MakeIWH(width, height)) {} |
| + canvas_bounds_(SkRect::MakeIWH(width, height)), |
| + int_canvas_bounds_( |
| + gfx::ToEnclosingRect(gfx::SkRectToRectF(canvas_bounds_))) {} |
| protected: |
| // we need to "undo" the behavior of SkNWayCanvas, which will try to forward |
| @@ -146,11 +166,12 @@ class DiscardableImagesMetadataCanvas : public SkNWayCanvas { |
| src_rect.roundOut(&src_irect); |
| image_set_->push_back(std::make_pair( |
| DrawImage(std::move(image), src_irect, filter_quality, matrix), |
| - gfx::ToEnclosingRect(gfx::SkRectToRectF(paint_rect)))); |
| + SafeIntersectRects(paint_rect, int_canvas_bounds_))); |
| } |
| std::vector<std::pair<DrawImage, gfx::Rect>>* image_set_; |
| const SkRect canvas_bounds_; |
| + const gfx::Rect int_canvas_bounds_; |
| std::vector<SkPaint> saved_paints_; |
| }; |