summaryrefslogtreecommitdiffstats
path: root/webkit/plugins/ppapi
diff options
context:
space:
mode:
authordanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-09 23:17:35 +0000
committerdanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-09 23:17:35 +0000
commit4b01b9680e67ba802e8a16027ffe4b4d435fc1e8 (patch)
tree675aa1ca07fa8f0d3bb1f0f4249822a6bf4e817d /webkit/plugins/ppapi
parent0c77646718f41510a03905f1ed31cd382109a6c4 (diff)
downloadchromium_src-4b01b9680e67ba802e8a16027ffe4b4d435fc1e8.zip
chromium_src-4b01b9680e67ba802e8a16027ffe4b4d435fc1e8.tar.gz
chromium_src-4b01b9680e67ba802e8a16027ffe4b4d435fc1e8.tar.bz2
Remove implicit flooring Scale() method from Point and Size.
When scaling an integer point or size, return a floating point result. Implicitly flooring hides design problems and bugs. Add conversion functions to floor or ceil a SizeF or PointF into an integer format again. All existing behaviour has been preserved by replacing uses of foo.Scale() with ToFlooredFoo(foo.Scale()). R=sky BUG=147395 Review URL: https://chromiumcodereview.appspot.com/11081007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@160970 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/plugins/ppapi')
-rw-r--r--webkit/plugins/ppapi/ppb_graphics_2d_impl.cc27
1 files changed, 11 insertions, 16 deletions
diff --git a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
index ff5c523..85c27d9 100644
--- a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
+++ b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
@@ -21,7 +21,10 @@
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/blit.h"
#include "ui/gfx/point.h"
+#include "ui/gfx/point_conversions.h"
#include "ui/gfx/rect.h"
+#include "ui/gfx/rect_conversions.h"
+#include "ui/gfx/size_conversions.h"
#include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
#include "ui/gfx/skia_util.h"
#include "webkit/plugins/ppapi/common.h"
@@ -77,17 +80,6 @@ bool ValidateAndConvertRect(const PP_Rect* rect,
return true;
}
-// Scale the rectangle, taking care to round coordinates outward 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::Rect ScaleRectBounds(const gfx::Rect& rect, float scale) {
- int left = static_cast<int>(floorf(rect.x() * scale));
- int top = static_cast<int>(floorf(rect.y() * scale));
- int right = static_cast<int>(ceilf((rect.x() + rect.width()) * scale));
- int bottom = static_cast<int>(ceilf((rect.y() + rect.height()) * scale));
- return gfx::Rect(left, top, right - left, bottom - top);
-}
-
// Converts BGRA <-> RGBA.
void ConvertBetweenBGRAandRGBA(const uint32_t* input,
int pixel_length,
@@ -573,7 +565,7 @@ void PPB_Graphics2D_Impl::Paint(WebKit::WebCanvas* canvas,
SkAutoCanvasRestore auto_restore(canvas, true);
canvas->clipRect(sk_invalidate_rect);
gfx::Size pixel_image_size(image_data_->width(), image_data_->height());
- gfx::Size image_size = pixel_image_size.Scale(scale_);
+ gfx::Size image_size = gfx::ToFlooredSize(pixel_image_size.Scale(scale_));
PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
if (!plugin_instance)
@@ -652,13 +644,16 @@ bool PPB_Graphics2D_Impl::ConvertToLogicalPixels(float scale,
return true;
gfx::Rect original_rect = *op_rect;
- *op_rect = ScaleRectBounds(*op_rect, 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.
+ *op_rect = gfx::ToEnclosingRect(op_rect->Scale(scale));
if (delta) {
gfx::Point original_delta = *delta;
float inverse_scale = 1.0f / scale;
- *delta = delta->Scale(scale);
- if (original_rect != ScaleRectBounds(*op_rect, inverse_scale) ||
- original_delta != delta->Scale(inverse_scale)) {
+ *delta = gfx::ToFlooredPoint(delta->Scale(scale));
+ if (original_rect != gfx::ToEnclosingRect(op_rect->Scale(inverse_scale)) ||
+ original_delta != gfx::ToFlooredPoint(delta->Scale(inverse_scale))) {
return false;
}
}