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

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

Issue 12379040: Revert 185474 -- speculative. browser_tests stopped starting up on all (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « ui/base/win/dpi.h ('k') | ui/base/win/hwnd_subclass.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 (c) 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/base/win/dpi.h" 5 #include "ui/base/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 "base/win/registry.h"
11 #include "ui/gfx/display.h" 10 #include "ui/gfx/display.h"
12 #include "ui/gfx/point_conversions.h" 11 #include "ui/gfx/point_conversions.h"
13 #include "ui/gfx/rect_conversions.h" 12 #include "ui/gfx/rect_conversions.h"
14 #include "ui/gfx/size_conversions.h" 13 #include "ui/gfx/size_conversions.h"
15 14
16 namespace { 15 namespace {
17 16
18 int kDefaultDPIX = 96; 17 int kDefaultDPIX = 96;
19 int kDefaultDPIY = 96; 18 int kDefaultDPIY = 96;
20 19
21 20
22 float GetDeviceScaleFactorImpl() { 21 float GetDeviceScaleFactorImpl() {
23 #if defined(ENABLE_HIDPI) 22 #if defined(ENABLE_HIDPI)
24 return gfx::Display::HasForceDeviceScaleFactor() ? 23 return gfx::Display::HasForceDeviceScaleFactor() ?
25 gfx::Display::GetForcedDeviceScaleFactor() : ui::GetDPIScale(); 24 gfx::Display::GetForcedDeviceScaleFactor() : ui::GetDPIScale();
26 #else 25 #else
27 return 1.0f; 26 return 1.0f;
28 #endif 27 #endif
29 } 28 }
30 29
31 BOOL IsProcessDPIAwareWrapper() {
32 typedef BOOL(WINAPI *IsProcessDPIAwarePtr)(VOID);
33 IsProcessDPIAwarePtr is_process_dpi_aware_func =
34 reinterpret_cast<IsProcessDPIAwarePtr>(
35 GetProcAddress(GetModuleHandleA("user32.dll"), "IsProcessDPIAware"));
36 if (is_process_dpi_aware_func)
37 return is_process_dpi_aware_func();
38 return FALSE;
39 }
40
41 } // namespace 30 } // namespace
42 31
43 namespace ui { 32 namespace ui {
44 33
45 gfx::Size GetDPI() { 34 gfx::Size GetDPI() {
46 static int dpi_x = 0; 35 static int dpi_x = 0;
47 static int dpi_y = 0; 36 static int dpi_y = 0;
48 static bool should_initialize = true; 37 static bool should_initialize = true;
49 38
50 if (should_initialize) { 39 if (should_initialize) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 93
105 gfx::Size ScreenToDIPSize(const gfx::Size& size_in_pixels) { 94 gfx::Size ScreenToDIPSize(const gfx::Size& size_in_pixels) {
106 return gfx::ToFlooredSize( 95 return gfx::ToFlooredSize(
107 gfx::ScaleSize(size_in_pixels, 1.0f / GetDeviceScaleFactor())); 96 gfx::ScaleSize(size_in_pixels, 1.0f / GetDeviceScaleFactor()));
108 } 97 }
109 98
110 gfx::Size DIPToScreenSize(const gfx::Size& dip_size) { 99 gfx::Size DIPToScreenSize(const gfx::Size& dip_size) {
111 return gfx::ToFlooredSize(gfx::ScaleSize(dip_size, GetDeviceScaleFactor())); 100 return gfx::ToFlooredSize(gfx::ScaleSize(dip_size, GetDeviceScaleFactor()));
112 } 101 }
113 102
114 double GetDPIScaleFromRegistry() {
115 static double scale = -1.0;
116 if (scale == -1.0) {
117 double result = 1.0;
118 if (!IsProcessDPIAwareWrapper()) {
119 //HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics\AppliedDPI
120 base::win::RegKey key(HKEY_CURRENT_USER,
121 L"Control Panel\\Desktop\\WindowMetrics",
122 KEY_QUERY_VALUE);
123
124 if (key.Valid()) {
125 DWORD value = 0;
126 if (key.ReadValueDW(L"AppliedDPI", &value) == ERROR_SUCCESS) {
127 result = ((double)value) / kDefaultDPIX;
128 }
129 }
130 }
131 scale = result;
132 }
133 return scale;
134 }
135
136 } // namespace win 103 } // namespace win
137 104
138 } // namespace ui 105 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/win/dpi.h ('k') | ui/base/win/hwnd_subclass.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698