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..ab49d855fe10509dce4a9a92308b2014939ce5cc 100644 |
| --- a/cc/playback/discardable_image_map.cc |
| +++ b/cc/playback/discardable_image_map.cc |
| @@ -24,6 +24,23 @@ SkRect MapRect(const SkMatrix& matrix, const SkRect& src) { |
| return dst; |
| } |
| +// Returns a rect clamped to |max_size|. Note that |paint_rect| should intersect |
|
enne (OOO)
2016/08/09 18:23:42
Can you DCHECK this too just for sanity's sake?
A
|
| +// a rect defined by (0, 0) and |max_size|. |
| +gfx::Rect SafeClampPaintRectToSize(const SkRect& paint_rect, |
| + const gfx::Size& max_size) { |
| + // 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_size.width() - bounds_rect.x())); |
| + bounds_rect.set_height( |
| + std::min(bounds_rect.height(), max_size.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 +53,8 @@ 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)), |
| + canvas_size_(width, height) {} |
| protected: |
| // we need to "undo" the behavior of SkNWayCanvas, which will try to forward |
| @@ -146,11 +164,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)))); |
| + SafeClampPaintRectToSize(paint_rect, canvas_size_))); |
| } |
| std::vector<std::pair<DrawImage, gfx::Rect>>* image_set_; |
| const SkRect canvas_bounds_; |
| + const gfx::Size canvas_size_; |
| std::vector<SkPaint> saved_paints_; |
| }; |