| Index: ui/gfx/win/dpi.cc
|
| diff --git a/ui/gfx/win/dpi.cc b/ui/gfx/win/dpi.cc
|
| index a958de4d1f3c2d6a1edb1807cab6ee9441902218..cd34ee108c258ca89767e128590d6c118152d847 100644
|
| --- a/ui/gfx/win/dpi.cc
|
| +++ b/ui/gfx/win/dpi.cc
|
| @@ -7,9 +7,6 @@
|
| #include <windows.h>
|
| #include "base/win/scoped_hdc.h"
|
| #include "ui/gfx/display.h"
|
| -#include "ui/gfx/geometry/point_conversions.h"
|
| -#include "ui/gfx/geometry/rect_conversions.h"
|
| -#include "ui/gfx/geometry/size_conversions.h"
|
|
|
| namespace {
|
|
|
| @@ -18,9 +15,17 @@ 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;
|
| + if (g_device_scale_factor)
|
| + return g_device_scale_factor;
|
| +
|
| + static float device_scale_factor = 0.0f;
|
| + if (!device_scale_factor) {
|
| + base::win::ScopedGetDC screen_dc(NULL);
|
| + int dpi_x = GetDeviceCaps(screen_dc, LOGPIXELSX);
|
| + DCHECK(dpi_x == GetDeviceCaps(screen_dc, LOGPIXELSY));
|
| + device_scale_factor = static_cast<float>(dpi_x) / kDefaultDPI;
|
| + }
|
| + return device_scale_factor;
|
| }
|
|
|
| } // namespace
|
| @@ -32,21 +37,8 @@ void SetDefaultDeviceScaleFactor(float scale) {
|
| g_device_scale_factor = scale;
|
| }
|
|
|
| -Size GetDPI() {
|
| - static int dpi_x = 0;
|
| - static int dpi_y = 0;
|
| - static bool should_initialize = true;
|
| -
|
| - if (should_initialize) {
|
| - should_initialize = false;
|
| - base::win::ScopedGetDC screen_dc(NULL);
|
| - // This value is safe to cache for the life time of the app since the
|
| - // user must logout to change the DPI setting. This value also applies
|
| - // to all screens.
|
| - dpi_x = GetDeviceCaps(screen_dc, LOGPIXELSX);
|
| - dpi_y = GetDeviceCaps(screen_dc, LOGPIXELSY);
|
| - }
|
| - return Size(dpi_x, dpi_y);
|
| +int GetDPIFromScalingFactor(float device_scaling_factor) {
|
| + return kDefaultDPI * device_scaling_factor;
|
| }
|
|
|
| float GetDPIScale() {
|
| @@ -58,40 +50,6 @@ float GetDPIScale() {
|
|
|
| namespace win {
|
|
|
| -Point ScreenToDIPPoint(const Point& pixel_point) {
|
| - return ScaleToFlooredPoint(pixel_point, 1.0f / GetDPIScale());
|
| -}
|
| -
|
| -Point DIPToScreenPoint(const Point& dip_point) {
|
| - return ScaleToFlooredPoint(dip_point, GetDPIScale());
|
| -}
|
| -
|
| -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()));
|
| -}
|
| -
|
| -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()));
|
| -}
|
| -
|
| -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());
|
| -}
|
| -
|
| -Size DIPToScreenSize(const Size& dip_size) {
|
| - // Always ceil sizes. Otherwise we may be leaving off part of the bounds.
|
| - return ScaleToCeiledSize(dip_size, GetDPIScale());
|
| -}
|
| -
|
| int GetSystemMetricsInDIP(int metric) {
|
| // The system metrics always reflect the system DPI, not whatever scale we've
|
| // forced or decided to use.
|
|
|