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

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

Issue 11953054: Fix high-DPI on Windows to make use of DIP scaling in WebKit. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Remove experimental changes to resource handling. Created 7 years, 11 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
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 "ui/gfx/display.h"
11 #include "ui/gfx/point_conversions.h"
12 #include "ui/gfx/rect_conversions.h"
13 #include "ui/gfx/size_conversions.h"
10 14
11 namespace { 15 namespace {
12 16
13 int kDefaultDPIX = 96; 17 int kDefaultDPIX = 96;
14 int kDefaultDPIY = 96; 18 int kDefaultDPIY = 96;
15 19
20
21 float GetDeviceScaleFactorImpl() {
22 #if defined(ENABLE_HIDPI)
23 return gfx::Display::GetForcedDeviceScaleFactor();
24 #else
25 return 1.0f;
26 #endif
27 }
28
16 } // namespace 29 } // namespace
17 30
18 namespace ui { 31 namespace ui {
19 32
20 gfx::Size GetDPI() { 33 gfx::Size GetDPI() {
21 static int dpi_x = 0; 34 static int dpi_x = 0;
22 static int dpi_y = 0; 35 static int dpi_y = 0;
23 static bool should_initialize = true; 36 static bool should_initialize = true;
24 37
25 if (should_initialize) { 38 if (should_initialize) {
(...skipping 19 matching lines...) Expand all
45 } 58 }
46 59
47 void EnableHighDPISupport() { 60 void EnableHighDPISupport() {
48 typedef BOOL(WINAPI *SetProcessDPIAwarePtr)(VOID); 61 typedef BOOL(WINAPI *SetProcessDPIAwarePtr)(VOID);
49 SetProcessDPIAwarePtr set_process_dpi_aware_func = 62 SetProcessDPIAwarePtr set_process_dpi_aware_func =
50 GetProcAddress(GetModuleHandleA("user32.dll"), "SetProcessDPIAware"); 63 GetProcAddress(GetModuleHandleA("user32.dll"), "SetProcessDPIAware");
51 if (set_process_dpi_aware_func) 64 if (set_process_dpi_aware_func)
52 set_process_dpi_aware_func(); 65 set_process_dpi_aware_func();
53 } 66 }
54 67
68 namespace win {
69
70 gfx::Point ScreenToDIPPoint(const gfx::Point& pixel_point) {
71 return gfx::ToFlooredPoint(
72 gfx::ScalePoint(pixel_point, 1.0f / GetDeviceScaleFactorImpl()));
73 }
74
75 gfx::Rect ScreenToDIPRect(const gfx::Rect& pixel_bounds) {
76 return gfx::ToFlooredRectDeprecated(
pkotwicz 2013/01/23 19:39:23 Nit: Add TODO to use gfx::ToNearestRect().
kevers 2013/01/23 21:37:00 Based on description of method, ToNearestRect migh
77 gfx::ScaleRect(pixel_bounds, 1.0f / GetDeviceScaleFactorImpl()));
78 }
79
80 gfx::Rect DIPToScreenRect(const gfx::Rect& dip_bounds) {
81 return gfx::ToFlooredRectDeprecated(
82 gfx::ScaleRect(dip_bounds, GetDeviceScaleFactorImpl()));
83 }
84
85 gfx::Size ScreenToDIPSize(const gfx::Size& size_in_pixels) {
86 return gfx::ToFlooredSize(
87 gfx::ScaleSize(size_in_pixels, 1.0f / GetDeviceScaleFactorImpl()));
88 }
89
90 gfx::Size DIPToScreenSize(const gfx::Size& dip_size) {
91 return gfx::ToFlooredSize(
92 gfx::ScaleSize(dip_size, GetDeviceScaleFactorImpl()));
93 }
94
95 } // namespace win
96
55 } // namespace ui 97 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698