Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(566)

Unified Diff: cc/playback/discardable_image_map.cc

Issue 2229603002: cc: Do a safe intersect when gathering images. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | cc/playback/discardable_image_map_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_;
};
« no previous file with comments | « no previous file | cc/playback/discardable_image_map_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698