summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ash/touch/touch_uma.cc2
-rw-r--r--cc/layer_impl.cc2
-rw-r--r--cc/layer_tree_host_impl.cc16
-rw-r--r--content/browser/renderer_host/dip_util.cc12
-rw-r--r--ui/aura/root_window.cc5
-rw-r--r--ui/base/x/x11_util.cc2
-rw-r--r--ui/compositor/dip_util.cc11
-rw-r--r--ui/gfx/point.h8
-rw-r--r--ui/gfx/point_f.cc7
-rw-r--r--ui/gfx/point_f.h14
-rw-r--r--ui/gfx/point_unittest.cc22
-rw-r--r--ui/gfx/quad_f.cc8
-rw-r--r--ui/gfx/quad_unittest.cc8
-rw-r--r--ui/gfx/rect_f.h3
-rw-r--r--ui/gfx/shadow_value.cc3
-rw-r--r--webkit/glue/webcursor_aurax11.cc6
-rw-r--r--webkit/plugins/ppapi/ppb_graphics_2d_impl.cc4
17 files changed, 81 insertions, 52 deletions
diff --git a/ash/touch/touch_uma.cc b/ash/touch/touch_uma.cc
index a9ca319..d8117b6 100644
--- a/ash/touch/touch_uma.cc
+++ b/ash/touch/touch_uma.cc
@@ -318,7 +318,7 @@ void TouchUMA::RecordTouchEvent(aura::Window* target,
position = ui::EventLocationFromNative(event.native_event());
#endif
position = gfx::ToFlooredPoint(
- position.Scale(1. / target->layer()->device_scale_factor()));
+ gfx::ScalePoint(position, 1. / target->layer()->device_scale_factor()));
}
position.set_x(std::min(bounds.width() - 1, std::max(0, position.x())));
diff --git a/cc/layer_impl.cc b/cc/layer_impl.cc
index 6bb093b..e53f44e 100644
--- a/cc/layer_impl.cc
+++ b/cc/layer_impl.cc
@@ -214,7 +214,7 @@ InputHandlerClient::ScrollStatus LayerImpl::tryScroll(const gfx::PointF& screenS
if (!nonFastScrollableRegion().IsEmpty()) {
bool clipped = false;
gfx::PointF hitTestPointInContentSpace = MathUtil::projectPoint(screenSpaceTransform().inverse(), screenSpacePoint, clipped);
- gfx::PointF hitTestPointInLayerSpace = hitTestPointInContentSpace.Scale(1 / contentsScaleX(), 1 / contentsScaleY());
+ gfx::PointF hitTestPointInLayerSpace = gfx::ScalePoint(hitTestPointInContentSpace, 1 / contentsScaleX(), 1 / contentsScaleY());
if (!clipped && nonFastScrollableRegion().Contains(gfx::ToRoundedPoint(hitTestPointInLayerSpace))) {
TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed nonFastScrollableRegion");
return InputHandlerClient::ScrollOnMainThread;
diff --git a/cc/layer_tree_host_impl.cc b/cc/layer_tree_host_impl.cc
index cdd6995..ead24a4 100644
--- a/cc/layer_tree_host_impl.cc
+++ b/cc/layer_tree_host_impl.cc
@@ -1053,7 +1053,7 @@ InputHandlerClient::ScrollStatus LayerTreeHostImpl::scrollBegin(gfx::Point viewp
if (!ensureRenderSurfaceLayerList())
return ScrollIgnored;
- gfx::PointF deviceViewportPoint = viewportPoint.Scale(m_deviceScaleFactor);
+ gfx::PointF deviceViewportPoint = gfx::ScalePoint(viewportPoint, m_deviceScaleFactor);
// First find out which layer was hit from the saved list of visible layers
// in the most recent frame.
@@ -1103,7 +1103,7 @@ static gfx::Vector2dF scrollLayerWithViewportSpaceDelta(PinchZoomViewport* viewp
DCHECK(layerImpl.screenSpaceTransform().isInvertible());
WebTransformationMatrix inverseScreenSpaceTransform = layerImpl.screenSpaceTransform().inverse();
- gfx::PointF screenSpacePoint = viewportPoint.Scale(scaleFromViewportToScreenSpace);
+ gfx::PointF screenSpacePoint = gfx::ScalePoint(viewportPoint, scaleFromViewportToScreenSpace);
gfx::Vector2dF screenSpaceDelta = viewportDelta;
screenSpaceDelta.Scale(scaleFromViewportToScreenSpace);
@@ -1124,8 +1124,8 @@ static gfx::Vector2dF scrollLayerWithViewportSpaceDelta(PinchZoomViewport* viewp
// localStartPoint and localEndPoint are in content space but we want to move them to layer space for scrolling.
float widthScale = 1 / layerImpl.contentsScaleX();
float heightScale = 1 / layerImpl.contentsScaleY();
- localStartPoint = localStartPoint.Scale(widthScale, heightScale);
- localEndPoint = localEndPoint.Scale(widthScale, heightScale);
+ localStartPoint.Scale(widthScale, heightScale);
+ localEndPoint.Scale(widthScale, heightScale);
// Apply the scroll delta.
gfx::Vector2dF previousDelta = layerImpl.scrollDelta();
@@ -1136,14 +1136,14 @@ static gfx::Vector2dF scrollLayerWithViewportSpaceDelta(PinchZoomViewport* viewp
// Get the end point in the layer's content space so we can apply its screenSpaceTransform.
gfx::PointF actualLocalEndPoint = localStartPoint + layerImpl.scrollDelta() - previousDelta;
- gfx::PointF actualLocalContentEndPoint = actualLocalEndPoint.Scale(1 / widthScale, 1 / heightScale);
+ gfx::PointF actualLocalContentEndPoint = gfx::ScalePoint(actualLocalEndPoint, 1 / widthScale, 1 / heightScale);
// Calculate the applied scroll delta in viewport space coordinates.
gfx::PointF actualScreenSpaceEndPoint = MathUtil::mapPoint(layerImpl.screenSpaceTransform(), actualLocalContentEndPoint, endClipped);
DCHECK(!endClipped);
if (endClipped)
return gfx::Vector2dF();
- gfx::PointF actualViewportEndPoint = actualScreenSpaceEndPoint.Scale(1 / scaleFromViewportToScreenSpace);
+ gfx::PointF actualViewportEndPoint = gfx::ScalePoint(actualScreenSpaceEndPoint, 1 / scaleFromViewportToScreenSpace);
return actualViewportEndPoint - viewportPoint;
}
@@ -1235,10 +1235,10 @@ void LayerTreeHostImpl::pinchGestureUpdate(float magnifyDelta, gfx::Point anchor
// Keep the center-of-pinch anchor specified by (x, y) in a stable
// position over the course of the magnify.
float pageScaleDelta = m_pinchZoomViewport.pageScaleDelta();
- gfx::PointF previousScaleAnchor = m_previousPinchAnchor.Scale(1 / pageScaleDelta);
+ gfx::PointF previousScaleAnchor = gfx::ScalePoint(m_previousPinchAnchor, 1 / pageScaleDelta);
setPageScaleDelta(pageScaleDelta * magnifyDelta);
pageScaleDelta = m_pinchZoomViewport.pageScaleDelta();
- gfx::PointF newScaleAnchor = anchor.Scale(1 / pageScaleDelta);
+ gfx::PointF newScaleAnchor = gfx::ScalePoint(anchor, 1 / pageScaleDelta);
gfx::Vector2dF move = previousScaleAnchor - newScaleAnchor;
m_previousPinchAnchor = anchor;
diff --git a/content/browser/renderer_host/dip_util.cc b/content/browser/renderer_host/dip_util.cc
index 0455020..726241a 100644
--- a/content/browser/renderer_host/dip_util.cc
+++ b/content/browser/renderer_host/dip_util.cc
@@ -9,6 +9,7 @@
#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/screen.h"
#include "ui/gfx/size.h"
#include "ui/gfx/size_conversions.h"
@@ -29,7 +30,7 @@ ui::ScaleFactor GetScaleFactorForView(const RenderWidgetHostView* view) {
gfx::Point ConvertPointToDIP(const RenderWidgetHostView* view,
const gfx::Point& point_in_pixel) {
return gfx::ToFlooredPoint(
- point_in_pixel.Scale(1.0f / GetScaleForView(view)));
+ gfx::ScalePoint(point_in_pixel, 1.0f / GetScaleForView(view)));
}
gfx::Size ConvertSizeToDIP(const RenderWidgetHostView* view,
@@ -41,13 +42,13 @@ gfx::Size ConvertSizeToDIP(const RenderWidgetHostView* view,
gfx::Rect ConvertRectToDIP(const RenderWidgetHostView* view,
const gfx::Rect& rect_in_pixel) {
float scale = 1.0f / GetScaleForView(view);
- return gfx::Rect(gfx::ToFlooredPoint(rect_in_pixel.origin().Scale(scale)),
- gfx::ToFlooredSize(rect_in_pixel.size().Scale(scale)));
+ return gfx::ToFlooredRectDeprecated(gfx::ScaleRect(rect_in_pixel, scale));
}
gfx::Point ConvertPointToPixel(const RenderWidgetHostView* view,
const gfx::Point& point_in_dip) {
- return gfx::ToFlooredPoint(point_in_dip.Scale(GetScaleForView(view)));
+ return gfx::ToFlooredPoint(
+ gfx::ScalePoint(point_in_dip, GetScaleForView(view)));
}
gfx::Size ConvertSizeToPixel(const RenderWidgetHostView* view,
@@ -58,8 +59,7 @@ gfx::Size ConvertSizeToPixel(const RenderWidgetHostView* view,
gfx::Rect ConvertRectToPixel(const RenderWidgetHostView* view,
const gfx::Rect& rect_in_dip) {
float scale = GetScaleForView(view);
- return gfx::Rect(gfx::ToFlooredPoint(rect_in_dip.origin().Scale(scale)),
- gfx::ToFlooredSize(rect_in_dip.size().Scale(scale)));
+ return gfx::ToFlooredRectDeprecated(gfx::ScaleRect(rect_in_dip, scale));
}
} // namespace content
diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc
index 6c08fe6..38ea96d 100644
--- a/ui/aura/root_window.cc
+++ b/ui/aura/root_window.cc
@@ -345,7 +345,8 @@ void RootWindow::PostNativeEvent(const base::NativeEvent& native_event) {
void RootWindow::ConvertPointToNativeScreen(gfx::Point* point) const {
// TODO(oshima): Take the root window's transform into account.
- *point = gfx::ToFlooredPoint(point->Scale(ui::GetDeviceScaleFactor(layer())));
+ *point = gfx::ToFlooredPoint(
+ gfx::ScalePoint(*point, ui::GetDeviceScaleFactor(layer())));
gfx::Point location = host_->GetLocationOnNativeScreen();
point->Offset(location.x(), location.y());
}
@@ -354,7 +355,7 @@ void RootWindow::ConvertPointFromNativeScreen(gfx::Point* point) const {
gfx::Point location = host_->GetLocationOnNativeScreen();
point->Offset(-location.x(), -location.y());
*point = gfx::ToFlooredPoint(
- point->Scale(1 / ui::GetDeviceScaleFactor(layer())));
+ gfx::ScalePoint(*point, 1 / ui::GetDeviceScaleFactor(layer())));
}
void RootWindow::ProcessedTouchEvent(ui::TouchEvent* event,
diff --git a/ui/base/x/x11_util.cc b/ui/base/x/x11_util.cc
index 0c4dc04..d6c9fd8 100644
--- a/ui/base/x/x11_util.cc
+++ b/ui/base/x/x11_util.cc
@@ -471,7 +471,7 @@ XcursorImage* SkBitmapToXcursorImage(const SkBitmap* cursor_image,
skia::ImageOperations::RESIZE_BETTER,
static_cast<int>(cursor_image->width() * scale),
static_cast<int>(cursor_image->height() * scale));
- hotspot_point = gfx::ToFlooredPoint(hotspot.Scale(scale));
+ hotspot_point = gfx::ToFlooredPoint(gfx::ScalePoint(hotspot, scale));
needs_scale = true;
}
diff --git a/ui/compositor/dip_util.cc b/ui/compositor/dip_util.cc
index b7731d4..5adf7c4 100644
--- a/ui/compositor/dip_util.cc
+++ b/ui/compositor/dip_util.cc
@@ -13,6 +13,7 @@
#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.h"
#include "ui/gfx/size_conversions.h"
@@ -25,7 +26,7 @@ float GetDeviceScaleFactor(const Layer* layer) {
gfx::Point ConvertPointToDIP(const Layer* layer,
const gfx::Point& point_in_pixel) {
return gfx::ToFlooredPoint(
- point_in_pixel.Scale(1.0f / GetDeviceScaleFactor(layer)));
+ gfx::ScalePoint(point_in_pixel, 1.0f / GetDeviceScaleFactor(layer)));
}
gfx::Size ConvertSizeToDIP(const Layer* layer,
@@ -37,14 +38,13 @@ gfx::Size ConvertSizeToDIP(const Layer* layer,
gfx::Rect ConvertRectToDIP(const Layer* layer,
const gfx::Rect& rect_in_pixel) {
float scale = 1.0f / GetDeviceScaleFactor(layer);
- return gfx::Rect(gfx::ToFlooredPoint(rect_in_pixel.origin().Scale(scale)),
- gfx::ToFlooredSize(rect_in_pixel.size().Scale(scale)));
+ return gfx::ToFlooredRectDeprecated(gfx::ScaleRect(rect_in_pixel, scale));
}
gfx::Point ConvertPointToPixel(const Layer* layer,
const gfx::Point& point_in_dip) {
return gfx::ToFlooredPoint(
- point_in_dip.Scale(GetDeviceScaleFactor(layer)));
+ gfx::ScalePoint(point_in_dip, GetDeviceScaleFactor(layer)));
}
gfx::Size ConvertSizeToPixel(const Layer* layer,
@@ -55,7 +55,6 @@ gfx::Size ConvertSizeToPixel(const Layer* layer,
gfx::Rect ConvertRectToPixel(const Layer* layer,
const gfx::Rect& rect_in_dip) {
float scale = GetDeviceScaleFactor(layer);
- return gfx::Rect(gfx::ToFlooredPoint(rect_in_dip.origin().Scale(scale)),
- gfx::ToFlooredSize(rect_in_dip.size().Scale(scale)));
+ return gfx::ToFlooredRectDeprecated(gfx::ScaleRect(rect_in_dip, scale));
}
} // namespace ui
diff --git a/ui/gfx/point.h b/ui/gfx/point.h
index 85bd8ac..f81dd90 100644
--- a/ui/gfx/point.h
+++ b/ui/gfx/point.h
@@ -49,14 +49,6 @@ class UI_EXPORT Point : public PointBase<Point, int, Vector2d> {
return PointF(x(), y());
}
- PointF Scale(float scale) const WARN_UNUSED_RESULT {
- return Scale(scale, scale);
- }
-
- PointF Scale(float x_scale, float y_scale) const WARN_UNUSED_RESULT {
- return PointF(x() * x_scale, y() * y_scale);
- }
-
// Returns a string representation of point.
std::string ToString() const;
};
diff --git a/ui/gfx/point_f.cc b/ui/gfx/point_f.cc
index d22693a0..ea683030 100644
--- a/ui/gfx/point_f.cc
+++ b/ui/gfx/point_f.cc
@@ -22,4 +22,11 @@ std::string PointF::ToString() const {
return base::StringPrintf("%f,%f", x(), y());
}
+PointF ScalePoint(const PointF& p, float x_scale, float y_scale) {
+ PointF scaled_p(p);
+ scaled_p.Scale(x_scale, y_scale);
+ return scaled_p;
+}
+
+
} // namespace gfx
diff --git a/ui/gfx/point_f.h b/ui/gfx/point_f.h
index 46bd8e2..9b2e934 100644
--- a/ui/gfx/point_f.h
+++ b/ui/gfx/point_f.h
@@ -20,12 +20,12 @@ class UI_EXPORT PointF : public PointBase<PointF, float, Vector2dF> {
PointF(float x, float y);
~PointF();
- PointF Scale(float scale) const WARN_UNUSED_RESULT {
- return Scale(scale, scale);
+ void Scale(float scale) {
+ Scale(scale, scale);
}
- PointF Scale(float x_scale, float y_scale) const WARN_UNUSED_RESULT {
- return PointF(x() * x_scale, y() * y_scale);
+ void Scale(float x_scale, float y_scale) {
+ SetPoint(x() * x_scale, y() * y_scale);
}
// Returns a string representation of point.
@@ -60,6 +60,12 @@ inline PointF PointAtOffsetFromOrigin(const Vector2dF& offset_from_origin) {
return PointF(offset_from_origin.x(), offset_from_origin.y());
}
+UI_EXPORT PointF ScalePoint(const PointF& p, float x_scale, float y_scale);
+
+inline PointF ScalePoint(const PointF& p, float scale) {
+ return ScalePoint(p, scale, scale);
+}
+
#if !defined(COMPILER_MSVC)
extern template class PointBase<PointF, float, Vector2dF>;
#endif
diff --git a/ui/gfx/point_unittest.cc b/ui/gfx/point_unittest.cc
index 3a58e07..e76bdb5 100644
--- a/ui/gfx/point_unittest.cc
+++ b/ui/gfx/point_unittest.cc
@@ -98,4 +98,26 @@ TEST(PointTest, ToRoundedPoint) {
EXPECT_EQ(Point(-11, -11), ToRoundedPoint(PointF(-10.9999f, -10.9999f)));
}
+TEST(PointTest, Scale) {
+ EXPECT_EQ(PointF().ToString(), ScalePoint(Point(), 2).ToString());
+ EXPECT_EQ(PointF().ToString(), ScalePoint(Point(), 2, 2).ToString());
+
+ EXPECT_EQ(PointF(2, -2).ToString(),
+ ScalePoint(Point(1, -1), 2).ToString());
+ EXPECT_EQ(PointF(2, -2).ToString(),
+ ScalePoint(Point(1, -1), 2, 2).ToString());
+
+ PointF zero;
+ PointF one(1, -1);
+
+ zero.Scale(2);
+ zero.Scale(3, 1.5);
+
+ one.Scale(2);
+ one.Scale(3, 1.5);
+
+ EXPECT_EQ(PointF().ToString(), zero.ToString());
+ EXPECT_EQ(PointF(6, -3).ToString(), one.ToString());
+}
+
} // namespace gfx
diff --git a/ui/gfx/quad_f.cc b/ui/gfx/quad_f.cc
index 0ef7c58..0ca501f 100644
--- a/ui/gfx/quad_f.cc
+++ b/ui/gfx/quad_f.cc
@@ -131,10 +131,10 @@ RectF QuadF::BoundingBox() const {
}
void QuadF::Scale(float x_scale, float y_scale) {
- p1_ = p1_.Scale(x_scale, y_scale);
- p2_ = p2_.Scale(x_scale, y_scale);
- p3_ = p3_.Scale(x_scale, y_scale);
- p4_ = p4_.Scale(x_scale, y_scale);
+ p1_.Scale(x_scale, y_scale);
+ p2_.Scale(x_scale, y_scale);
+ p3_.Scale(x_scale, y_scale);
+ p4_.Scale(x_scale, y_scale);
}
void QuadF::operator+=(const Vector2dF& rhs) {
diff --git a/ui/gfx/quad_unittest.cc b/ui/gfx/quad_unittest.cc
index cb9cef3..8859a0e 100644
--- a/ui/gfx/quad_unittest.cc
+++ b/ui/gfx/quad_unittest.cc
@@ -345,10 +345,10 @@ TEST(QuadTest, Scale) {
QuadF q1(a, b, c, d);
q1.Scale(1.5f);
- PointF a_scaled = a.Scale(1.5f);
- PointF b_scaled = b.Scale(1.5f);
- PointF c_scaled = c.Scale(1.5f);
- PointF d_scaled = d.Scale(1.5f);
+ PointF a_scaled = ScalePoint(a, 1.5f);
+ PointF b_scaled = ScalePoint(b, 1.5f);
+ PointF c_scaled = ScalePoint(c, 1.5f);
+ PointF d_scaled = ScalePoint(d, 1.5f);
EXPECT_EQ(q1.ToString(),
QuadF(a_scaled, b_scaled, c_scaled, d_scaled).ToString());
diff --git a/ui/gfx/rect_f.h b/ui/gfx/rect_f.h
index b3734f9..a86ac9e 100644
--- a/ui/gfx/rect_f.h
+++ b/ui/gfx/rect_f.h
@@ -34,9 +34,10 @@ class UI_EXPORT RectF
}
void Scale(float x_scale, float y_scale) {
+ set_origin(ScalePoint(origin(), x_scale, y_scale));
+
SizeF newSize = size().Scale(x_scale, y_scale);
newSize.ClampToNonNegative();
- set_origin(origin().Scale(x_scale, y_scale));
set_size(newSize);
}
diff --git a/ui/gfx/shadow_value.cc b/ui/gfx/shadow_value.cc
index 0602c2d..adfe0b8 100644
--- a/ui/gfx/shadow_value.cc
+++ b/ui/gfx/shadow_value.cc
@@ -29,7 +29,8 @@ ShadowValue::~ShadowValue() {
}
ShadowValue ShadowValue::Scale(float scale) const {
- gfx::Point scaled_offset = gfx::ToFlooredPoint(offset_.Scale(scale));
+ gfx::Point scaled_offset =
+ gfx::ToFlooredPoint(gfx::ScalePoint(offset_, scale));
return ShadowValue(scaled_offset, blur_ * scale, color_);
}
diff --git a/webkit/glue/webcursor_aurax11.cc b/webkit/glue/webcursor_aurax11.cc
index 584e3ef..d6e01af 100644
--- a/webkit/glue/webcursor_aurax11.cc
+++ b/webkit/glue/webcursor_aurax11.cc
@@ -36,9 +36,9 @@ const ui::PlatformCursor WebCursor::GetPlatformCursor() {
skia::ImageOperations::RESIZE_BETTER,
scaled_size.width(),
scaled_size.height());
- image = ui::SkBitmapToXcursorImage(&scaled_bitmap,
- gfx::ToFlooredPoint(
- hotspot_.Scale(scale_factor_)));
+ gfx::Point hotspot_point = gfx::ToFlooredPoint(
+ gfx::ScalePoint(hotspot_, scale_factor_));
+ image = ui::SkBitmapToXcursorImage(&scaled_bitmap, hotspot_point);
}
platform_cursor_ = ui::CreateReffedCustomXCursor(image);
return platform_cursor_;
diff --git a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
index e6831a7..0c0e30b 100644
--- a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
+++ b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
@@ -649,14 +649,14 @@ bool PPB_Graphics2D_Impl::ConvertToLogicalPixels(float scale,
if (delta) {
gfx::Point original_delta = *delta;
float inverse_scale = 1.0f / scale;
- *delta = gfx::ToFlooredPoint(delta->Scale(scale));
+ *delta = gfx::ToFlooredPoint(gfx::ScalePoint(*delta, 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));
+ gfx::ToFlooredPoint(gfx::ScalePoint(*delta, inverse_scale));
if (original_delta != inverse_scaled_point)
return false;
}