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 | |
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')
-rw-r--r-- | webkit/plugins/npapi/webplugin_delegate_impl_gtk.cc | 3 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.cc | 10 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_graphics_2d_impl.cc | 22 | ||||
-rw-r--r-- | webkit/plugins/webview_plugin.cc | 3 |
4 files changed, 16 insertions, 22 deletions
diff --git a/webkit/plugins/npapi/webplugin_delegate_impl_gtk.cc b/webkit/plugins/npapi/webplugin_delegate_impl_gtk.cc index 869ea9f..382a975 100644 --- a/webkit/plugins/npapi/webplugin_delegate_impl_gtk.cc +++ b/webkit/plugins/npapi/webplugin_delegate_impl_gtk.cc @@ -355,8 +355,7 @@ void WebPluginDelegateImpl::WindowlessPaint(cairo_t* context, // "real" means as seen by Chrome // "apparent" means as seen by the plugin. - gfx::Rect draw_rect = window_rect_; - draw_rect.Intersect(damage_rect); + gfx::Rect draw_rect = gfx::IntersectRects(window_rect_, damage_rect); // clip_rect_ is relative to the plugin gfx::Rect clip_rect_window = clip_rect_; 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<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; diff --git a/webkit/plugins/webview_plugin.cc b/webkit/plugins/webview_plugin.cc index 9888b73..4e5c8c4 100644 --- a/webkit/plugins/webview_plugin.cc +++ b/webkit/plugins/webview_plugin.cc @@ -120,8 +120,7 @@ bool WebViewPlugin::getFormValue(WebString& value) { } void WebViewPlugin::paint(WebCanvas* canvas, const WebRect& rect) { - gfx::Rect paintRect = rect_; - paintRect.Intersect(rect); + gfx::Rect paintRect = gfx::IntersectRects(rect_, rect); if (paintRect.IsEmpty()) return; |