| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/display/win/dpi.h" | 5 #include "ui/display/win/dpi.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include "base/win/scoped_hdc.h" | 9 #include "base/win/scoped_hdc.h" |
| 10 #include "ui/display/display.h" | 10 #include "ui/display/display.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 base::win::ScopedGetDC screen_dc(NULL); | 28 base::win::ScopedGetDC screen_dc(NULL); |
| 29 // This value is safe to cache for the life time of the app since the | 29 // This value is safe to cache for the life time of the app since the |
| 30 // user must logout to change the DPI setting. This value also applies | 30 // user must logout to change the DPI setting. This value also applies |
| 31 // to all screens. | 31 // to all screens. |
| 32 dpi_x = GetDeviceCaps(screen_dc, LOGPIXELSX); | 32 dpi_x = GetDeviceCaps(screen_dc, LOGPIXELSX); |
| 33 dpi_y = GetDeviceCaps(screen_dc, LOGPIXELSY); | 33 dpi_y = GetDeviceCaps(screen_dc, LOGPIXELSY); |
| 34 } | 34 } |
| 35 return gfx::Size(dpi_x, dpi_y); | 35 return gfx::Size(dpi_x, dpi_y); |
| 36 } | 36 } |
| 37 | 37 |
| 38 float GetUnforcedDeviceScaleFactor() { | |
| 39 return g_device_scale_factor | |
| 40 ? g_device_scale_factor | |
| 41 : GetScalingFactorFromDPI(GetDPI().width()); | |
| 42 } | |
| 43 | |
| 44 } // namespace | 38 } // namespace |
| 45 | 39 |
| 46 void SetDefaultDeviceScaleFactor(float scale) { | 40 void SetDefaultDeviceScaleFactor(float scale) { |
| 47 DCHECK_NE(0.f, scale); | 41 DCHECK_NE(0.f, scale); |
| 48 g_device_scale_factor = scale; | 42 g_device_scale_factor = scale; |
| 49 } | 43 } |
| 50 | 44 |
| 51 float GetDPIScale() { | 45 float GetDPIScale() { |
| 52 if (Display::HasForceDeviceScaleFactor()) | 46 if (Display::HasForceDeviceScaleFactor()) |
| 53 return Display::GetForcedDeviceScaleFactor(); | 47 return Display::GetForcedDeviceScaleFactor(); |
| 54 return GetUnforcedDeviceScaleFactor(); | 48 return GetUnforcedDeviceScaleFactor(); |
| 55 } | 49 } |
| 56 | 50 |
| 51 float GetUnforcedDeviceScaleFactor() { |
| 52 return g_device_scale_factor ? g_device_scale_factor |
| 53 : GetScalingFactorFromDPI(GetDPI().width()); |
| 54 } |
| 55 |
| 57 int GetDPIFromScalingFactor(float device_scaling_factor) { | 56 int GetDPIFromScalingFactor(float device_scaling_factor) { |
| 58 return kDefaultDPI * device_scaling_factor; | 57 return kDefaultDPI * device_scaling_factor; |
| 59 } | 58 } |
| 60 | 59 |
| 61 float GetScalingFactorFromDPI(int dpi) { | 60 float GetScalingFactorFromDPI(int dpi) { |
| 62 return static_cast<float>(dpi) / kDefaultDPI; | 61 return static_cast<float>(dpi) / kDefaultDPI; |
| 63 } | 62 } |
| 64 | 63 |
| 65 } // namespace win | 64 } // namespace win |
| 66 } // namespace display | 65 } // namespace display |
| OLD | NEW |