| Index: ui/gfx/win/dpi.cc
|
| diff --git a/ui/gfx/win/dpi.cc b/ui/gfx/win/dpi.cc
|
| index a958de4d1f3c2d6a1edb1807cab6ee9441902218..10de983df1efa2e75eb50e845f3c6a246711c0fe 100644
|
| --- a/ui/gfx/win/dpi.cc
|
| +++ b/ui/gfx/win/dpi.cc
|
| @@ -17,22 +17,7 @@ const float kDefaultDPI = 96.f;
|
|
|
| float g_device_scale_factor = 0.f;
|
|
|
| -float GetUnforcedDeviceScaleFactor() {
|
| - return g_device_scale_factor ?
|
| - g_device_scale_factor :
|
| - static_cast<float>(gfx::GetDPI().width()) / kDefaultDPI;
|
| -}
|
| -
|
| -} // namespace
|
| -
|
| -namespace gfx {
|
| -
|
| -void SetDefaultDeviceScaleFactor(float scale) {
|
| - DCHECK_NE(0.f, scale);
|
| - g_device_scale_factor = scale;
|
| -}
|
| -
|
| -Size GetDPI() {
|
| +gfx::Size GetDPI() {
|
| static int dpi_x = 0;
|
| static int dpi_y = 0;
|
| static bool should_initialize = true;
|
| @@ -46,51 +31,36 @@ Size GetDPI() {
|
| dpi_x = GetDeviceCaps(screen_dc, LOGPIXELSX);
|
| dpi_y = GetDeviceCaps(screen_dc, LOGPIXELSY);
|
| }
|
| - return Size(dpi_x, dpi_y);
|
| + return gfx::Size(dpi_x, dpi_y);
|
| }
|
|
|
| -float GetDPIScale() {
|
| - if (gfx::Display::HasForceDeviceScaleFactor())
|
| - return gfx::Display::GetForcedDeviceScaleFactor();
|
| - float dpi_scale = GetUnforcedDeviceScaleFactor();
|
| - return (dpi_scale <= 1.25f) ? 1.f : dpi_scale;
|
| +float GetUnforcedDeviceScaleFactor() {
|
| + return g_device_scale_factor ?
|
| + g_device_scale_factor :
|
| + static_cast<float>(GetDPI().width()) / kDefaultDPI;
|
| }
|
|
|
| -namespace win {
|
| -
|
| -Point ScreenToDIPPoint(const Point& pixel_point) {
|
| - return ScaleToFlooredPoint(pixel_point, 1.0f / GetDPIScale());
|
| -}
|
| +} // namespace
|
|
|
| -Point DIPToScreenPoint(const Point& dip_point) {
|
| - return ScaleToFlooredPoint(dip_point, GetDPIScale());
|
| -}
|
| +namespace gfx {
|
|
|
| -Rect ScreenToDIPRect(const Rect& pixel_bounds) {
|
| - // It's important we scale the origin and size separately. If we instead
|
| - // calculated the size from the floored origin and ceiled right the size could
|
| - // vary depending upon where the two points land. That would cause problems
|
| - // for the places this code is used (in particular mapping from native window
|
| - // bounds to DIPs).
|
| - return Rect(ScreenToDIPPoint(pixel_bounds.origin()),
|
| - ScreenToDIPSize(pixel_bounds.size()));
|
| +void SetDefaultDeviceScaleFactor(float scale) {
|
| + DCHECK_NE(0.f, scale);
|
| + g_device_scale_factor = scale;
|
| }
|
|
|
| -Rect DIPToScreenRect(const Rect& dip_bounds) {
|
| - // See comment in ScreenToDIPRect for why we calculate size like this.
|
| - return Rect(DIPToScreenPoint(dip_bounds.origin()),
|
| - DIPToScreenSize(dip_bounds.size()));
|
| +float GetDPIScale() {
|
| + if (gfx::Display::HasForceDeviceScaleFactor())
|
| + return gfx::Display::GetForcedDeviceScaleFactor();
|
| + float dpi_scale = GetUnforcedDeviceScaleFactor();
|
| + return (dpi_scale <= 1.25f) ? 1.f : dpi_scale;
|
| }
|
|
|
| -Size ScreenToDIPSize(const Size& size_in_pixels) {
|
| - // Always ceil sizes. Otherwise we may be leaving off part of the bounds.
|
| - return ScaleToCeiledSize(size_in_pixels, 1.0f / GetDPIScale());
|
| +int GetDPIFromScalingFactor(float device_scaling_factor) {
|
| + return kDefaultDPI * device_scaling_factor;
|
| }
|
|
|
| -Size DIPToScreenSize(const Size& dip_size) {
|
| - // Always ceil sizes. Otherwise we may be leaving off part of the bounds.
|
| - return ScaleToCeiledSize(dip_size, GetDPIScale());
|
| -}
|
| +namespace win {
|
|
|
| int GetSystemMetricsInDIP(int metric) {
|
| // The system metrics always reflect the system DPI, not whatever scale we've
|
|
|