From ce112fe17067812a9014c6b10e041435aedf9998 Mon Sep 17 00:00:00 2001 From: "danakj@chromium.org" Date: Mon, 29 Oct 2012 22:52:18 +0000 Subject: 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 --- webkit/plugins/ppapi/ppapi_plugin_instance.cc | 10 ++++------ webkit/plugins/ppapi/ppb_graphics_2d_impl.cc | 22 ++++++++++------------ 2 files changed, 14 insertions(+), 18 deletions(-) (limited to 'webkit/plugins/ppapi') diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index 0b858c6..c0c6c78 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -1174,14 +1174,12 @@ bool PluginInstance::GetBitmapForOptimizedPluginPaint( gfx::Rect pixel_plugin_backing_store_rect( 0, 0, image_data->width(), image_data->height()); float scale = GetBoundGraphics2D()->GetScale(); - gfx::RectF scaled_backing_store_rect = pixel_plugin_backing_store_rect; - scaled_backing_store_rect.Scale(scale); - gfx::Rect plugin_backing_store_rect = - gfx::ToEnclosedRect(scaled_backing_store_rect); + gfx::Rect plugin_backing_store_rect = gfx::ToEnclosedRect( + gfx::ScaleRect(pixel_plugin_backing_store_rect, scale)); gfx::Rect clip_page = PP_ToGfxRect(view_data_.clip_rect); - gfx::Rect plugin_paint_rect = plugin_backing_store_rect; - plugin_paint_rect.Intersect(clip_page); + gfx::Rect plugin_paint_rect = + gfx::IntersectRects(plugin_backing_store_rect, clip_page); if (!plugin_paint_rect.Contains(relative_paint_bounds)) return false; 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 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; -- cgit v1.1