Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1164)

Side by Side Diff: ui/display/win/dpi.cc

Issue 1889423002: Move Windows DPI Code from ui/gfx to ui/display (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a TODO Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/display/win/dpi.h ('k') | ui/display/win/screen_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 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/gfx/win/dpi.h" 5 #include "ui/display/win/dpi.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8
8 #include "base/win/scoped_hdc.h" 9 #include "base/win/scoped_hdc.h"
9 #include "ui/gfx/display.h" 10 #include "ui/gfx/display.h"
10 11
11 namespace { 12 namespace {
12 13
13 const float kDefaultDPI = 96.f; 14 const float kDefaultDPI = 96.f;
14 15
15 float g_device_scale_factor = 0.f; 16 float g_device_scale_factor = 0.f;
16 17
17 float GetUnforcedDeviceScaleFactor() { 18 float GetUnforcedDeviceScaleFactor() {
18 return g_device_scale_factor ? 19 return g_device_scale_factor ?
19 g_device_scale_factor : 20 g_device_scale_factor :
20 static_cast<float>(gfx::GetDPI().width()) / kDefaultDPI; 21 static_cast<float>(display::win::GetDPI().width()) / kDefaultDPI;
21 } 22 }
22 23
23 } // namespace 24 } // namespace
24 25
25 namespace gfx { 26 namespace display {
27 namespace win {
26 28
27 void SetDefaultDeviceScaleFactor(float scale) { 29 void SetDefaultDeviceScaleFactor(float scale) {
28 DCHECK_NE(0.f, scale); 30 DCHECK_NE(0.f, scale);
29 g_device_scale_factor = scale; 31 g_device_scale_factor = scale;
30 } 32 }
31 33
32 Size GetDPI() { 34 gfx::Size GetDPI() {
33 static int dpi_x = 0; 35 static int dpi_x = 0;
34 static int dpi_y = 0; 36 static int dpi_y = 0;
35 static bool should_initialize = true; 37 static bool should_initialize = true;
36 38
37 if (should_initialize) { 39 if (should_initialize) {
38 should_initialize = false; 40 should_initialize = false;
39 base::win::ScopedGetDC screen_dc(NULL); 41 base::win::ScopedGetDC screen_dc(NULL);
40 // This value is safe to cache for the life time of the app since the 42 // This value is safe to cache for the life time of the app since the
41 // user must logout to change the DPI setting. This value also applies 43 // user must logout to change the DPI setting. This value also applies
42 // to all screens. 44 // to all screens.
43 dpi_x = GetDeviceCaps(screen_dc, LOGPIXELSX); 45 dpi_x = GetDeviceCaps(screen_dc, LOGPIXELSX);
44 dpi_y = GetDeviceCaps(screen_dc, LOGPIXELSY); 46 dpi_y = GetDeviceCaps(screen_dc, LOGPIXELSY);
45 } 47 }
46 return Size(dpi_x, dpi_y); 48 return gfx::Size(dpi_x, dpi_y);
47 } 49 }
48 50
49 float GetDPIScale() { 51 float GetDPIScale() {
50 if (gfx::Display::HasForceDeviceScaleFactor()) 52 if (gfx::Display::HasForceDeviceScaleFactor())
51 return gfx::Display::GetForcedDeviceScaleFactor(); 53 return gfx::Display::GetForcedDeviceScaleFactor();
52 float dpi_scale = GetUnforcedDeviceScaleFactor(); 54 float dpi_scale = GetUnforcedDeviceScaleFactor();
53 return (dpi_scale <= 1.25f) ? 1.f : dpi_scale; 55 return (dpi_scale <= 1.25f) ? 1.f : dpi_scale;
54 } 56 }
55 57
56 namespace win {
57
58 int GetSystemMetricsInDIP(int metric) { 58 int GetSystemMetricsInDIP(int metric) {
59 // The system metrics always reflect the system DPI, not whatever scale we've 59 // The system metrics always reflect the system DPI, not whatever scale we've
60 // forced or decided to use. 60 // forced or decided to use.
61 return static_cast<int>( 61 return static_cast<int>(
62 std::round(GetSystemMetrics(metric) / GetUnforcedDeviceScaleFactor())); 62 std::round(GetSystemMetrics(metric) / GetUnforcedDeviceScaleFactor()));
63 } 63 }
64 64
65 } // namespace win 65 } // namespace win
66 } // namespace gfx 66 } // namespace display
OLDNEW
« no previous file with comments | « ui/display/win/dpi.h ('k') | ui/display/win/screen_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698