Commit 8c8c4211 authored by danakj's avatar danakj Committed by Commit Bot

Remove ConvertPointToPixel() methods.

The Convert*ToDIP() and Convert*ToPixel() functions are problematic in
that they hide what decision is being taken in the underlying code
when moving from floating point to integer, and consumers should be
thinking about what they want for correctness. They also act in
inconsistent ways when converting a Rect vs its components. This
removes the functions that perform float->int conversions in order to
have callers show what they intend to happen and make it clear that
data is being lost in some fashion.

R=sky@chromium.org

Bug: 1130050
Change-Id: I2bbe5ff2b85cc4c643ec66fe09a8208e643c3329
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2418568
Commit-Queue: danakj <danakj@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809815}
parent 7193c70b
...@@ -172,9 +172,7 @@ class ASH_EXPORT MagnificationController : public ui::EventHandler, ...@@ -172,9 +172,7 @@ class ASH_EXPORT MagnificationController : public ui::EventHandler,
// given scale. Returns true if the window is changed; otherwise, false. // given scale. Returns true if the window is changed; otherwise, false.
// These methods should be called internally just after the scale and/or // These methods should be called internally just after the scale and/or
// the position are changed to redraw the window. // the position are changed to redraw the window.
bool Redraw(const gfx::PointF& position_in_physical_pixels, bool Redraw(const gfx::PointF& position_in_pixels, float scale, bool animate);
float scale,
bool animate);
// Redraws the magnification window with the given origin position in dip and // Redraws the magnification window with the given origin position in dip and
// the given scale. Returns true if the window is changed; otherwise, false. // the given scale. Returns true if the window is changed; otherwise, false.
......
...@@ -556,7 +556,7 @@ RenderWidgetTargetResult RenderWidgetHostInputEventRouter::FindViewAtLocation( ...@@ -556,7 +556,7 @@ RenderWidgetTargetResult RenderWidgetHostInputEventRouter::FindViewAtLocation(
float device_scale_factor = root_view->GetDeviceScaleFactor(); float device_scale_factor = root_view->GetDeviceScaleFactor();
DCHECK_GT(device_scale_factor, 0.0f); DCHECK_GT(device_scale_factor, 0.0f);
gfx::PointF point_in_pixels = gfx::PointF point_in_pixels =
gfx::ConvertPointToPixel(device_scale_factor, point); gfx::ConvertPointToPixels(point, device_scale_factor);
viz::Target target = query->FindTargetForLocationStartingFrom( viz::Target target = query->FindTargetForLocationStartingFrom(
source, point_in_pixels, root_view->GetFrameSinkId()); source, point_in_pixels, root_view->GetFrameSinkId());
frame_sink_id = target.frame_sink_id; frame_sink_id = target.frame_sink_id;
......
...@@ -793,8 +793,8 @@ bool RenderWidgetHostViewBase::TransformPointToTargetCoordSpace( ...@@ -793,8 +793,8 @@ bool RenderWidgetHostViewBase::TransformPointToTargetCoordSpace(
float device_scale_factor = original_view->GetDeviceScaleFactor(); float device_scale_factor = original_view->GetDeviceScaleFactor();
DCHECK_GT(device_scale_factor, 0.0f); DCHECK_GT(device_scale_factor, 0.0f);
gfx::Point3F point_in_pixels( gfx::Point3F point_in_pixels =
gfx::ConvertPointToPixel(device_scale_factor, point)); gfx::Point3F(gfx::ConvertPointToPixels(point, device_scale_factor));
// TODO(crbug.com/966995): Optimize so that |point_in_pixels| doesn't need to // TODO(crbug.com/966995): Optimize so that |point_in_pixels| doesn't need to
// be in the coordinate space of the root surface in HitTestQuery. // be in the coordinate space of the root surface in HitTestQuery.
gfx::Transform transform_root_to_original; gfx::Transform transform_root_to_original;
......
...@@ -33,11 +33,6 @@ gfx::Rect ConvertRectToDIP(const Layer* layer, ...@@ -33,11 +33,6 @@ gfx::Rect ConvertRectToDIP(const Layer* layer,
return gfx::ConvertRectToDIP(layer->device_scale_factor(), rect_in_pixel); return gfx::ConvertRectToDIP(layer->device_scale_factor(), rect_in_pixel);
} }
gfx::Point ConvertPointToPixel(const Layer* layer,
const gfx::Point& point_in_dip) {
return gfx::ConvertPointToPixel(layer->device_scale_factor(), point_in_dip);
}
gfx::Size ConvertSizeToPixel(const Layer* layer, gfx::Size ConvertSizeToPixel(const Layer* layer,
const gfx::Size& size_in_dip) { const gfx::Size& size_in_dip) {
return gfx::ConvertSizeToPixel(layer->device_scale_factor(), size_in_dip); return gfx::ConvertSizeToPixel(layer->device_scale_factor(), size_in_dip);
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "ui/gfx/geometry/point_f.h" #include "ui/gfx/geometry/point_f.h"
namespace gfx { namespace gfx {
class Point;
class Size; class Size;
class Rect; class Rect;
} // namespace gfx } // namespace gfx
...@@ -25,9 +24,6 @@ COMPOSITOR_EXPORT gfx::Size ConvertSizeToDIP( ...@@ -25,9 +24,6 @@ COMPOSITOR_EXPORT gfx::Size ConvertSizeToDIP(
COMPOSITOR_EXPORT gfx::Rect ConvertRectToDIP( COMPOSITOR_EXPORT gfx::Rect ConvertRectToDIP(
const Layer* layer, const Layer* layer,
const gfx::Rect& rect_in_pixel); const gfx::Rect& rect_in_pixel);
COMPOSITOR_EXPORT gfx::Point ConvertPointToPixel(
const Layer* layer,
const gfx::Point& point_in_dip);
COMPOSITOR_EXPORT gfx::Size ConvertSizeToPixel( COMPOSITOR_EXPORT gfx::Size ConvertSizeToPixel(
const Layer* layer, const Layer* layer,
const gfx::Size& size_in_dip); const gfx::Size& size_in_dip);
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "ui/gfx/geometry/insets.h" #include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/geometry/point_f.h" #include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_conversions.h" #include "ui/gfx/geometry/rect_conversions.h"
...@@ -25,6 +24,16 @@ PointF ConvertPointToDips(const PointF& point_in_pixels, ...@@ -25,6 +24,16 @@ PointF ConvertPointToDips(const PointF& point_in_pixels,
return ScalePoint(point_in_pixels, 1.f / device_scale_factor); return ScalePoint(point_in_pixels, 1.f / device_scale_factor);
} }
PointF ConvertPointToPixels(const Point& point_in_dips,
float device_scale_factor) {
return ScalePoint(PointF(point_in_dips), device_scale_factor);
}
PointF ConvertPointToPixels(const PointF& point_in_dips,
float device_scale_factor) {
return ScalePoint(point_in_dips, device_scale_factor);
}
Insets ConvertInsetsToDIP(float scale_factor, Insets ConvertInsetsToDIP(float scale_factor,
const gfx::Insets& insets_in_pixel) { const gfx::Insets& insets_in_pixel) {
if (scale_factor == 1.f) if (scale_factor == 1.f)
...@@ -52,18 +61,6 @@ Insets ConvertInsetsToPixel(float scale_factor, ...@@ -52,18 +61,6 @@ Insets ConvertInsetsToPixel(float scale_factor,
return insets_in_dip.Scale(scale_factor); return insets_in_dip.Scale(scale_factor);
} }
Point ConvertPointToPixel(float scale_factor, const Point& point_in_dip) {
if (scale_factor == 1.f)
return point_in_dip;
return ScaleToFlooredPoint(point_in_dip, scale_factor);
}
PointF ConvertPointToPixel(float scale_factor, const PointF& point_in_dip) {
if (scale_factor == 1.f)
return point_in_dip;
return ScalePoint(point_in_dip, scale_factor);
}
Size ConvertSizeToPixel(float scale_factor, const Size& size_in_dip) { Size ConvertSizeToPixel(float scale_factor, const Size& size_in_dip) {
if (scale_factor == 1.f) if (scale_factor == 1.f)
return size_in_dip; return size_in_dip;
......
...@@ -26,6 +26,7 @@ class Size; ...@@ -26,6 +26,7 @@ class Size;
// point values, which can itself be a lossy operation for large integers. The // point values, which can itself be a lossy operation for large integers. The
// intention of these methods is to be used for UI values which are relatively // intention of these methods is to be used for UI values which are relatively
// small. // small.
GEOMETRY_EXPORT gfx::PointF ConvertPointToDips( GEOMETRY_EXPORT gfx::PointF ConvertPointToDips(
const gfx::Point& point_in_pixels, const gfx::Point& point_in_pixels,
float device_scale_factor); float device_scale_factor);
...@@ -33,6 +34,13 @@ GEOMETRY_EXPORT gfx::PointF ConvertPointToDips( ...@@ -33,6 +34,13 @@ GEOMETRY_EXPORT gfx::PointF ConvertPointToDips(
const gfx::PointF& point_in_pixels, const gfx::PointF& point_in_pixels,
float device_scale_factor); float device_scale_factor);
GEOMETRY_EXPORT gfx::PointF ConvertPointToPixels(
const gfx::Point& point_in_dips,
float device_scale_factor);
GEOMETRY_EXPORT gfx::PointF ConvertPointToPixels(
const gfx::PointF& point_in_dips,
float device_scale_factor);
GEOMETRY_EXPORT gfx::Insets ConvertInsetsToDIP( GEOMETRY_EXPORT gfx::Insets ConvertInsetsToDIP(
float scale_factor, float scale_factor,
const gfx::Insets& insets_in_pixel); const gfx::Insets& insets_in_pixel);
...@@ -44,11 +52,6 @@ GEOMETRY_EXPORT gfx::Rect ConvertRectToDIP(float scale_factor, ...@@ -44,11 +52,6 @@ GEOMETRY_EXPORT gfx::Rect ConvertRectToDIP(float scale_factor,
GEOMETRY_EXPORT gfx::Insets ConvertInsetsToPixel( GEOMETRY_EXPORT gfx::Insets ConvertInsetsToPixel(
float scale_factor, float scale_factor,
const gfx::Insets& insets_in_dip); const gfx::Insets& insets_in_dip);
GEOMETRY_EXPORT gfx::Point ConvertPointToPixel(float scale_factor,
const gfx::Point& point_in_dip);
GEOMETRY_EXPORT gfx::PointF ConvertPointToPixel(
float scale_factor,
const gfx::PointF& point_in_dip);
GEOMETRY_EXPORT gfx::Size ConvertSizeToPixel(float scale_factor, GEOMETRY_EXPORT gfx::Size ConvertSizeToPixel(float scale_factor,
const gfx::Size& size_in_dip); const gfx::Size& size_in_dip);
GEOMETRY_EXPORT gfx::Rect ConvertRectToPixel(float scale_factor, GEOMETRY_EXPORT gfx::Rect ConvertRectToPixel(float scale_factor,
......
...@@ -69,8 +69,11 @@ bool DesktopScreenX11::IsWindowUnderCursor(gfx::NativeWindow window) { ...@@ -69,8 +69,11 @@ bool DesktopScreenX11::IsWindowUnderCursor(gfx::NativeWindow window) {
gfx::NativeWindow DesktopScreenX11::GetWindowAtScreenPoint( gfx::NativeWindow DesktopScreenX11::GetWindowAtScreenPoint(
const gfx::Point& point) { const gfx::Point& point) {
// TODO(danakj): Should this be rounded?
gfx::Point point_in_pixels = gfx::ToFlooredPoint(
gfx::ConvertPointToPixels(point, GetXDisplayScaleFactor()));
auto window = ui::X11TopmostWindowFinder().FindLocalProcessWindowAt( auto window = ui::X11TopmostWindowFinder().FindLocalProcessWindowAt(
gfx::ConvertPointToPixel(GetXDisplayScaleFactor(), point), {}); point_in_pixels, {});
return window != x11::Window::None return window != x11::Window::None
? views::DesktopWindowTreeHostPlatform::GetContentWindowForWidget( ? views::DesktopWindowTreeHostPlatform::GetContentWindowForWidget(
static_cast<gfx::AcceleratedWidget>(window)) static_cast<gfx::AcceleratedWidget>(window))
...@@ -83,9 +86,11 @@ gfx::NativeWindow DesktopScreenX11::GetLocalProcessWindowAtPoint( ...@@ -83,9 +86,11 @@ gfx::NativeWindow DesktopScreenX11::GetLocalProcessWindowAtPoint(
std::set<gfx::AcceleratedWidget> ignore_widgets; std::set<gfx::AcceleratedWidget> ignore_widgets;
for (auto* const window : ignore) for (auto* const window : ignore)
ignore_widgets.emplace(window->GetHost()->GetAcceleratedWidget()); ignore_widgets.emplace(window->GetHost()->GetAcceleratedWidget());
// TODO(danakj): Should this be rounded?
gfx::Point point_in_pixels = gfx::ToFlooredPoint(
gfx::ConvertPointToPixels(point, GetXDisplayScaleFactor()));
auto window = ui::X11TopmostWindowFinder().FindLocalProcessWindowAt( auto window = ui::X11TopmostWindowFinder().FindLocalProcessWindowAt(
gfx::ConvertPointToPixel(GetXDisplayScaleFactor(), point), point_in_pixels, ignore_widgets);
ignore_widgets);
return window != x11::Window::None return window != x11::Window::None
? views::DesktopWindowTreeHostPlatform::GetContentWindowForWidget( ? views::DesktopWindowTreeHostPlatform::GetContentWindowForWidget(
static_cast<gfx::AcceleratedWidget>(window)) static_cast<gfx::AcceleratedWidget>(window))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment