|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #include "nsScreenWin.h" |
|
7 #include "nsCoord.h" |
|
8 #include "gfxWindowsPlatform.h" |
|
9 #include "nsIWidget.h" |
|
10 |
|
11 |
|
12 nsScreenWin :: nsScreenWin ( HMONITOR inScreen ) |
|
13 : mScreen(inScreen) |
|
14 { |
|
15 #ifdef DEBUG |
|
16 HDC hDCScreen = ::GetDC(nullptr); |
|
17 NS_ASSERTION(hDCScreen,"GetDC Failure"); |
|
18 NS_ASSERTION ( ::GetDeviceCaps(hDCScreen, TECHNOLOGY) == DT_RASDISPLAY, "Not a display screen"); |
|
19 ::ReleaseDC(nullptr,hDCScreen); |
|
20 #endif |
|
21 |
|
22 // nothing else to do. I guess we could cache a bunch of information |
|
23 // here, but we want to ask the device at runtime in case anything |
|
24 // has changed. |
|
25 } |
|
26 |
|
27 |
|
28 nsScreenWin :: ~nsScreenWin() |
|
29 { |
|
30 // nothing to see here. |
|
31 } |
|
32 |
|
33 |
|
34 NS_IMETHODIMP |
|
35 nsScreenWin :: GetRect(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight) |
|
36 { |
|
37 BOOL success = FALSE; |
|
38 if ( mScreen ) { |
|
39 MONITORINFO info; |
|
40 info.cbSize = sizeof(MONITORINFO); |
|
41 success = ::GetMonitorInfoW( mScreen, &info ); |
|
42 if ( success ) { |
|
43 *outLeft = info.rcMonitor.left; |
|
44 *outTop = info.rcMonitor.top; |
|
45 *outWidth = info.rcMonitor.right - info.rcMonitor.left; |
|
46 *outHeight = info.rcMonitor.bottom - info.rcMonitor.top; |
|
47 } |
|
48 } |
|
49 if (!success) { |
|
50 HDC hDCScreen = ::GetDC(nullptr); |
|
51 NS_ASSERTION(hDCScreen,"GetDC Failure"); |
|
52 |
|
53 *outTop = *outLeft = 0; |
|
54 *outWidth = ::GetDeviceCaps(hDCScreen, HORZRES); |
|
55 *outHeight = ::GetDeviceCaps(hDCScreen, VERTRES); |
|
56 |
|
57 ::ReleaseDC(nullptr, hDCScreen); |
|
58 } |
|
59 return NS_OK; |
|
60 |
|
61 } // GetRect |
|
62 |
|
63 |
|
64 NS_IMETHODIMP |
|
65 nsScreenWin :: GetAvailRect(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight) |
|
66 { |
|
67 BOOL success = FALSE; |
|
68 |
|
69 if ( mScreen ) { |
|
70 MONITORINFO info; |
|
71 info.cbSize = sizeof(MONITORINFO); |
|
72 success = ::GetMonitorInfoW( mScreen, &info ); |
|
73 if ( success ) { |
|
74 *outLeft = info.rcWork.left; |
|
75 *outTop = info.rcWork.top; |
|
76 *outWidth = info.rcWork.right - info.rcWork.left; |
|
77 *outHeight = info.rcWork.bottom - info.rcWork.top; |
|
78 } |
|
79 } |
|
80 if (!success) { |
|
81 RECT workArea; |
|
82 ::SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0); |
|
83 *outLeft = workArea.left; |
|
84 *outTop = workArea.top; |
|
85 *outWidth = workArea.right - workArea.left; |
|
86 *outHeight = workArea.bottom - workArea.top; |
|
87 } |
|
88 |
|
89 return NS_OK; |
|
90 |
|
91 } // GetAvailRect |
|
92 |
|
93 static double |
|
94 GetDPIScale() |
|
95 { |
|
96 double dpiScale= nsIWidget::DefaultScaleOverride(); |
|
97 if (dpiScale <= 0.0) { |
|
98 dpiScale = gfxWindowsPlatform::GetPlatform()->GetDPIScale(); |
|
99 } |
|
100 return dpiScale; |
|
101 } |
|
102 |
|
103 NS_IMETHODIMP |
|
104 nsScreenWin::GetRectDisplayPix(int32_t *outLeft, int32_t *outTop, |
|
105 int32_t *outWidth, int32_t *outHeight) |
|
106 { |
|
107 int32_t left, top, width, height; |
|
108 nsresult rv = GetRect(&left, &top, &width, &height); |
|
109 if (NS_FAILED(rv)) { |
|
110 return rv; |
|
111 } |
|
112 double scaleFactor = 1.0 / GetDPIScale(); |
|
113 *outLeft = NSToIntRound(left * scaleFactor); |
|
114 *outTop = NSToIntRound(top * scaleFactor); |
|
115 *outWidth = NSToIntRound(width * scaleFactor); |
|
116 *outHeight = NSToIntRound(height * scaleFactor); |
|
117 return NS_OK; |
|
118 } |
|
119 |
|
120 NS_IMETHODIMP |
|
121 nsScreenWin::GetAvailRectDisplayPix(int32_t *outLeft, int32_t *outTop, |
|
122 int32_t *outWidth, int32_t *outHeight) |
|
123 { |
|
124 int32_t left, top, width, height; |
|
125 nsresult rv = GetAvailRect(&left, &top, &width, &height); |
|
126 if (NS_FAILED(rv)) { |
|
127 return rv; |
|
128 } |
|
129 double scaleFactor = 1.0 / GetDPIScale(); |
|
130 *outLeft = NSToIntRound(left * scaleFactor); |
|
131 *outTop = NSToIntRound(top * scaleFactor); |
|
132 *outWidth = NSToIntRound(width * scaleFactor); |
|
133 *outHeight = NSToIntRound(height * scaleFactor); |
|
134 return NS_OK; |
|
135 } |
|
136 |
|
137 |
|
138 NS_IMETHODIMP |
|
139 nsScreenWin :: GetPixelDepth(int32_t *aPixelDepth) |
|
140 { |
|
141 //XXX not sure how to get this info for multiple monitors, this might be ok... |
|
142 HDC hDCScreen = ::GetDC(nullptr); |
|
143 NS_ASSERTION(hDCScreen,"GetDC Failure"); |
|
144 |
|
145 int32_t depth = ::GetDeviceCaps(hDCScreen, BITSPIXEL); |
|
146 if (depth == 32) { |
|
147 // If a device uses 32 bits per pixel, it's still only using 8 bits |
|
148 // per color component, which is what our callers want to know. |
|
149 // (Some devices report 32 and some devices report 24.) |
|
150 depth = 24; |
|
151 } |
|
152 *aPixelDepth = depth; |
|
153 |
|
154 ::ReleaseDC(nullptr, hDCScreen); |
|
155 return NS_OK; |
|
156 |
|
157 } // GetPixelDepth |
|
158 |
|
159 |
|
160 NS_IMETHODIMP |
|
161 nsScreenWin :: GetColorDepth(int32_t *aColorDepth) |
|
162 { |
|
163 return GetPixelDepth(aColorDepth); |
|
164 |
|
165 } // GetColorDepth |
|
166 |
|
167 |