diff options
author | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-29 22:52:18 +0000 |
---|---|---|
committer | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-29 22:52:18 +0000 |
commit | ce112fe17067812a9014c6b10e041435aedf9998 (patch) | |
tree | 45e32fbd98173f5aae7bc2fd417d67d4461570f4 /webkit/plugins/ppapi/ppb_graphics_2d_impl.cc | |
parent | aa1c70d3bc9449db2a3bfd02c15875aafb17caa5 (diff) | |
download | chromium_src-ce112fe17067812a9014c6b10e041435aedf9998.zip chromium_src-ce112fe17067812a9014c6b10e041435aedf9998.tar.gz chromium_src-ce112fe17067812a9014c6b10e041435aedf9998.tar.bz2 |
Add non-member non-mutating methods for common gfx::Rect operations.
This adds non-member methods that return a new Rect (or RectF) object
as their result instead of mutating an existing rect. We add:
Rect gfx::IntersectRects(Rect, Rect)
RectF gfx::IntersectRects(RectF, RectF)
Rect gfx::UnionRects(Rect, Rect)
RectF gfx::UnionRects(RectF, RectF)
Rect gfx::SubtractRects(Rect, Rect)
RectF gfx::SubtractRects(RectF, RectF)
RectF gfx::ScaleRect(RectF, scale)
RectF gfx::ScaleRect(RectF, x_scale, y_scale)
In CL https://codereview.chromium.org/11110004/ we made all
member methods of Rect (and RectF) mutate the existing
object, so these methods are added for cases where we want
the result to create a new object instead.
BUG=147395
R=sky
Review URL: https://codereview.chromium.org/11270042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@164760 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/plugins/ppapi/ppb_graphics_2d_impl.cc')
-rw-r--r-- | webkit/plugins/ppapi/ppb_graphics_2d_impl.cc | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc index 923b88d..aaad035 100644 --- a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc +++ b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc @@ -376,8 +376,7 @@ int32_t PPB_Graphics2D_Impl::Flush(scoped_refptr<TrackedCallback> callback, // Set |no_update_visible| to false if the change overlaps the visible // area. - gfx::Rect visible_changed_rect = clip; - visible_changed_rect.Intersect(op_rect); + gfx::Rect visible_changed_rect = gfx::IntersectRects(clip, op_rect); if (!visible_changed_rect.IsEmpty()) no_update_visible = false; @@ -561,8 +560,7 @@ void PPB_Graphics2D_Impl::Paint(WebKit::WebCanvas* canvas, CGContextDrawImage(canvas, bitmap_rect, image); #else - gfx::Rect invalidate_rect = plugin_rect; - invalidate_rect.Intersect(paint_rect); + gfx::Rect invalidate_rect = gfx::IntersectRects(plugin_rect, paint_rect); SkRect sk_invalidate_rect = gfx::RectToSkRect(invalidate_rect); SkAutoCanvasRestore auto_restore(canvas, true); canvas->clipRect(sk_invalidate_rect); @@ -649,20 +647,20 @@ bool PPB_Graphics2D_Impl::ConvertToLogicalPixels(float scale, // Take the enclosing rectangle after scaling so a rectangle scaled down then // scaled back up by the inverse scale would fully contain the entire area // affected by the original rectangle. - gfx::RectF scaled_rect = *op_rect; - scaled_rect.Scale(scale); - *op_rect = gfx::ToEnclosingRect(scaled_rect); + *op_rect = gfx::ToEnclosingRect(gfx::ScaleRect(*op_rect, scale)); if (delta) { gfx::Point original_delta = *delta; float inverse_scale = 1.0f / scale; *delta = gfx::ToFlooredPoint(delta->Scale(scale)); - gfx::RectF inverse_scaled_rect = *op_rect; - inverse_scaled_rect.Scale(inverse_scale); - if (original_rect != gfx::ToEnclosingRect(inverse_scaled_rect) || - original_delta != gfx::ToFlooredPoint(delta->Scale(inverse_scale))) { + gfx::Rect inverse_scaled_rect = + gfx::ToEnclosingRect(gfx::ScaleRect(*op_rect, inverse_scale)); + if (original_rect != inverse_scaled_rect) + return false; + gfx::Point inverse_scaled_point = + gfx::ToFlooredPoint(delta->Scale(inverse_scale)); + if (original_delta != inverse_scaled_point) return false; - } } return true; |