| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/geometry/dip_util.h" | 5 #include "ui/gfx/geometry/dip_util.h" |
| 6 | 6 |
| 7 #include "ui/gfx/geometry/point.h" | 7 #include "ui/gfx/geometry/point.h" |
| 8 #include "ui/gfx/geometry/point_conversions.h" | 8 #include "ui/gfx/geometry/point_conversions.h" |
| 9 #include "ui/gfx/geometry/point_f.h" | 9 #include "ui/gfx/geometry/point_f.h" |
| 10 #include "ui/gfx/geometry/rect.h" | 10 #include "ui/gfx/geometry/rect.h" |
| 11 #include "ui/gfx/geometry/rect_conversions.h" | 11 #include "ui/gfx/geometry/rect_conversions.h" |
| 12 #include "ui/gfx/geometry/size.h" | 12 #include "ui/gfx/geometry/size.h" |
| 13 #include "ui/gfx/geometry/size_conversions.h" | 13 #include "ui/gfx/geometry/size_conversions.h" |
| 14 | 14 |
| 15 namespace gfx { | 15 namespace gfx { |
| 16 | 16 |
| 17 gfx::Point ConvertPointToDIP(float scale_factor, | 17 Point ConvertPointToDIP(float scale_factor, const Point& point_in_pixel) { |
| 18 const gfx::Point& point_in_pixel) { | 18 return ToFlooredPoint(ScalePoint(point_in_pixel, 1.0f / scale_factor)); |
| 19 return gfx::ToFlooredPoint( | |
| 20 gfx::ScalePoint(point_in_pixel, 1.0f / scale_factor)); | |
| 21 } | 19 } |
| 22 | 20 |
| 23 gfx::PointF ConvertPointToDIP(float scale_factor, | 21 PointF ConvertPointToDIP(float scale_factor, const PointF& point_in_pixel) { |
| 24 const gfx::PointF& point_in_pixel) { | 22 return ScalePoint(point_in_pixel, 1.0f / scale_factor); |
| 25 return gfx::ScalePoint(point_in_pixel, 1.0f / scale_factor); | |
| 26 } | 23 } |
| 27 | 24 |
| 28 gfx::Size ConvertSizeToDIP(float scale_factor, const gfx::Size& size_in_pixel) { | 25 Size ConvertSizeToDIP(float scale_factor, const Size& size_in_pixel) { |
| 29 return gfx::ToFlooredSize(gfx::ScaleSize(size_in_pixel, 1.0f / scale_factor)); | 26 return ScaleToFlooredSize(size_in_pixel, 1.0f / scale_factor); |
| 30 } | 27 } |
| 31 | 28 |
| 32 gfx::Rect ConvertRectToDIP(float scale_factor, const gfx::Rect& rect_in_pixel) { | 29 Rect ConvertRectToDIP(float scale_factor, const Rect& rect_in_pixel) { |
| 33 return gfx::ToFlooredRectDeprecated( | 30 return ToFlooredRectDeprecated( |
| 34 gfx::ScaleRect(gfx::RectF(rect_in_pixel), 1.0f / scale_factor)); | 31 ScaleRect(RectF(rect_in_pixel), 1.0f / scale_factor)); |
| 35 } | 32 } |
| 36 | 33 |
| 37 gfx::Point ConvertPointToPixel(float scale_factor, | 34 Point ConvertPointToPixel(float scale_factor, const Point& point_in_dip) { |
| 38 const gfx::Point& point_in_dip) { | 35 return ToFlooredPoint(ScalePoint(point_in_dip, scale_factor)); |
| 39 return gfx::ToFlooredPoint(gfx::ScalePoint(point_in_dip, scale_factor)); | |
| 40 } | 36 } |
| 41 | 37 |
| 42 gfx::Size ConvertSizeToPixel(float scale_factor, const gfx::Size& size_in_dip) { | 38 Size ConvertSizeToPixel(float scale_factor, const Size& size_in_dip) { |
| 43 return gfx::ToFlooredSize(gfx::ScaleSize(size_in_dip, scale_factor)); | 39 return ScaleToFlooredSize(size_in_dip, scale_factor); |
| 44 } | 40 } |
| 45 | 41 |
| 46 gfx::Rect ConvertRectToPixel(float scale_factor, const gfx::Rect& rect_in_dip) { | 42 Rect ConvertRectToPixel(float scale_factor, const Rect& rect_in_dip) { |
| 47 // Use ToEnclosingRect() to ensure we paint all the possible pixels | 43 // Use ToEnclosingRect() to ensure we paint all the possible pixels |
| 48 // touched. ToEnclosingRect() floors the origin, and ceils the max | 44 // touched. ToEnclosingRect() floors the origin, and ceils the max |
| 49 // coordinate. To do otherwise (such as flooring the size) potentially | 45 // coordinate. To do otherwise (such as flooring the size) potentially |
| 50 // results in rounding down and not drawing all the pixels that are | 46 // results in rounding down and not drawing all the pixels that are |
| 51 // touched. | 47 // touched. |
| 52 return gfx::ToEnclosingRect( | 48 return ToEnclosingRect( |
| 53 gfx::RectF(gfx::ScalePoint(rect_in_dip.origin(), scale_factor), | 49 RectF(ScalePoint(rect_in_dip.origin(), scale_factor), |
| 54 gfx::ScaleSize(rect_in_dip.size(), scale_factor))); | 50 ScaleSize(gfx::SizeF(rect_in_dip.size()), scale_factor))); |
| 55 } | 51 } |
| 56 | 52 |
| 57 } // namespace gfx | 53 } // namespace gfx |
| OLD | NEW |