author | ssadetsky |
Fri, 08 Jul 2016 18:43:12 +0300 | |
changeset 39844 | a3cc7e551a48 |
parent 37550 | c8252b8fea3d |
child 40996 | 60d53c39c1b3 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
39844
a3cc7e551a48
8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents:
37550
diff
changeset
|
2 |
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.awt; |
|
27 |
||
28 |
import java.awt.AWTPermission; |
|
29 |
import java.awt.DisplayMode; |
|
30 |
import java.awt.GraphicsEnvironment; |
|
31 |
import java.awt.GraphicsDevice; |
|
32 |
import java.awt.GraphicsConfiguration; |
|
33 |
import java.awt.Rectangle; |
|
34 |
import java.awt.Window; |
|
5275
fa9f5ce2006e
6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
4285
diff
changeset
|
35 |
import java.security.AccessController; |
fa9f5ce2006e
6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
4285
diff
changeset
|
36 |
import java.security.PrivilegedAction; |
2 | 37 |
import java.util.ArrayList; |
38 |
import java.util.HashSet; |
|
39 |
import java.util.HashMap; |
|
40 |
||
41 |
import sun.java2d.opengl.GLXGraphicsConfig; |
|
5579
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
42 |
import sun.java2d.xr.XRGraphicsConfig; |
2 | 43 |
import sun.java2d.loops.SurfaceType; |
44 |
||
24520
e8afd90fcb69
8035169: Move ThreadGroupUtils from the sun.misc package
pchelko
parents:
23900
diff
changeset
|
45 |
import sun.awt.util.ThreadGroupUtils; |
34395 | 46 |
import sun.java2d.SunGraphicsEnvironment; |
23900
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23010
diff
changeset
|
47 |
|
2 | 48 |
/** |
49 |
* This is an implementation of a GraphicsDevice object for a single |
|
50 |
* X11 screen. |
|
51 |
* |
|
52 |
* @see GraphicsEnvironment |
|
53 |
* @see GraphicsConfiguration |
|
54 |
*/ |
|
30938
35ae5c70d60e
8030087: Avoid public native methods in sun.awt packages
serb
parents:
30486
diff
changeset
|
55 |
public final class X11GraphicsDevice extends GraphicsDevice |
35ae5c70d60e
8030087: Avoid public native methods in sun.awt packages
serb
parents:
30486
diff
changeset
|
56 |
implements DisplayChangedListener { |
2 | 57 |
int screen; |
24538
25bf8153fbfe
8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents:
24520
diff
changeset
|
58 |
HashMap<SurfaceType, Object> x11ProxyKeyMap = new HashMap<>(); |
2 | 59 |
|
60 |
private static AWTPermission fullScreenExclusivePermission; |
|
61 |
private static Boolean xrandrExtSupported; |
|
62 |
private final Object configLock = new Object(); |
|
63 |
private SunDisplayChanger topLevels = new SunDisplayChanger(); |
|
64 |
private DisplayMode origDisplayMode; |
|
65 |
private boolean shutdownHookRegistered; |
|
34395 | 66 |
private final int scale; |
2 | 67 |
|
68 |
public X11GraphicsDevice(int screennum) { |
|
69 |
this.screen = screennum; |
|
34395 | 70 |
this.scale = initScaleFactor(); |
2 | 71 |
} |
72 |
||
73 |
/* |
|
74 |
* Initialize JNI field and method IDs for fields that may be |
|
75 |
* accessed from C. |
|
76 |
*/ |
|
77 |
private static native void initIDs(); |
|
78 |
||
79 |
static { |
|
80 |
if (!GraphicsEnvironment.isHeadless()) { |
|
81 |
initIDs(); |
|
82 |
} |
|
83 |
} |
|
84 |
||
85 |
/** |
|
86 |
* Returns the X11 screen of the device. |
|
87 |
*/ |
|
88 |
public int getScreen() { |
|
89 |
return screen; |
|
90 |
} |
|
91 |
||
92 |
public Object getProxyKeyFor(SurfaceType st) { |
|
93 |
synchronized (x11ProxyKeyMap) { |
|
94 |
Object o = x11ProxyKeyMap.get(st); |
|
95 |
if (o == null) { |
|
96 |
o = new Object(); |
|
97 |
x11ProxyKeyMap.put(st, o); |
|
98 |
} |
|
99 |
return o; |
|
100 |
} |
|
101 |
} |
|
102 |
||
103 |
/** |
|
104 |
* Returns the X11 Display of this device. |
|
105 |
* This method is also in MDrawingSurfaceInfo but need it here |
|
106 |
* to be able to allow a GraphicsConfigTemplate to get the Display. |
|
107 |
*/ |
|
108 |
public native long getDisplay(); |
|
109 |
||
110 |
/** |
|
111 |
* Returns the type of the graphics device. |
|
112 |
* @see #TYPE_RASTER_SCREEN |
|
113 |
* @see #TYPE_PRINTER |
|
114 |
* @see #TYPE_IMAGE_BUFFER |
|
115 |
*/ |
|
116 |
public int getType() { |
|
117 |
return TYPE_RASTER_SCREEN; |
|
118 |
} |
|
119 |
||
120 |
/** |
|
121 |
* Returns the identification string associated with this graphics |
|
122 |
* device. |
|
123 |
*/ |
|
124 |
public String getIDstring() { |
|
125 |
return ":0."+screen; |
|
126 |
} |
|
127 |
||
128 |
||
129 |
GraphicsConfiguration[] configs; |
|
130 |
GraphicsConfiguration defaultConfig; |
|
24538
25bf8153fbfe
8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents:
24520
diff
changeset
|
131 |
HashSet<Integer> doubleBufferVisuals; |
2 | 132 |
|
133 |
/** |
|
134 |
* Returns all of the graphics |
|
135 |
* configurations associated with this graphics device. |
|
136 |
*/ |
|
137 |
public GraphicsConfiguration[] getConfigurations() { |
|
138 |
if (configs == null) { |
|
139 |
synchronized (configLock) { |
|
140 |
makeConfigurations(); |
|
141 |
} |
|
142 |
} |
|
4204
d8eff41661bf
6822057: X11 and Win32GraphicsDevice don't clone arrays returned from getConfigurations()
bae
parents:
889
diff
changeset
|
143 |
return configs.clone(); |
2 | 144 |
} |
145 |
||
146 |
private void makeConfigurations() { |
|
147 |
if (configs == null) { |
|
148 |
int i = 1; // Index 0 is always the default config |
|
149 |
int num = getNumConfigs(screen); |
|
150 |
GraphicsConfiguration[] ret = new GraphicsConfiguration[num]; |
|
151 |
if (defaultConfig == null) { |
|
152 |
ret [0] = getDefaultConfiguration(); |
|
153 |
} |
|
154 |
else { |
|
155 |
ret [0] = defaultConfig; |
|
156 |
} |
|
157 |
||
158 |
boolean glxSupported = X11GraphicsEnvironment.isGLXAvailable(); |
|
5579
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
159 |
boolean xrenderSupported = X11GraphicsEnvironment.isXRenderAvailable(); |
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
160 |
|
2 | 161 |
boolean dbeSupported = isDBESupported(); |
162 |
if (dbeSupported && doubleBufferVisuals == null) { |
|
24538
25bf8153fbfe
8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents:
24520
diff
changeset
|
163 |
doubleBufferVisuals = new HashSet<>(); |
2 | 164 |
getDoubleBufferVisuals(screen); |
165 |
} |
|
166 |
for ( ; i < num; i++) { |
|
167 |
int visNum = getConfigVisualId(i, screen); |
|
168 |
int depth = getConfigDepth (i, screen); |
|
169 |
if (glxSupported) { |
|
170 |
ret[i] = GLXGraphicsConfig.getConfig(this, visNum); |
|
171 |
} |
|
172 |
if (ret[i] == null) { |
|
173 |
boolean doubleBuffer = |
|
174 |
(dbeSupported && |
|
438
2ae294e4518c
6613529: Avoid duplicate object creation within JDK packages
dav
parents:
2
diff
changeset
|
175 |
doubleBufferVisuals.contains(Integer.valueOf(visNum))); |
5579
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
176 |
|
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
177 |
if (xrenderSupported) { |
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
178 |
ret[i] = XRGraphicsConfig.getConfig(this, visNum, depth, getConfigColormap(i, screen), |
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
179 |
doubleBuffer); |
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
180 |
} else { |
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
181 |
ret[i] = X11GraphicsConfig.getConfig(this, visNum, depth, |
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
182 |
getConfigColormap(i, screen), |
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
183 |
doubleBuffer); |
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
184 |
} |
2 | 185 |
} |
186 |
} |
|
187 |
configs = ret; |
|
188 |
} |
|
189 |
} |
|
190 |
||
191 |
/* |
|
192 |
* Returns the number of X11 visuals representable as an |
|
193 |
* X11GraphicsConfig object. |
|
194 |
*/ |
|
195 |
public native int getNumConfigs(int screen); |
|
196 |
||
197 |
/* |
|
198 |
* Returns the visualid for the given index of graphics configurations. |
|
199 |
*/ |
|
200 |
public native int getConfigVisualId (int index, int screen); |
|
201 |
/* |
|
202 |
* Returns the depth for the given index of graphics configurations. |
|
203 |
*/ |
|
30938
35ae5c70d60e
8030087: Avoid public native methods in sun.awt packages
serb
parents:
30486
diff
changeset
|
204 |
private native int getConfigDepth(int index, int screen); |
2 | 205 |
|
206 |
/* |
|
207 |
* Returns the colormap for the given index of graphics configurations. |
|
208 |
*/ |
|
30938
35ae5c70d60e
8030087: Avoid public native methods in sun.awt packages
serb
parents:
30486
diff
changeset
|
209 |
private native int getConfigColormap(int index, int screen); |
2 | 210 |
|
211 |
// Whether or not double-buffering extension is supported |
|
30938
35ae5c70d60e
8030087: Avoid public native methods in sun.awt packages
serb
parents:
30486
diff
changeset
|
212 |
static native boolean isDBESupported(); |
2 | 213 |
// Callback for adding a new double buffer visual into our set |
214 |
private void addDoubleBufferVisual(int visNum) { |
|
438
2ae294e4518c
6613529: Avoid duplicate object creation within JDK packages
dav
parents:
2
diff
changeset
|
215 |
doubleBufferVisuals.add(Integer.valueOf(visNum)); |
2 | 216 |
} |
217 |
// Enumerates all visuals that support double buffering |
|
218 |
private native void getDoubleBufferVisuals(int screen); |
|
219 |
||
220 |
/** |
|
221 |
* Returns the default graphics configuration |
|
222 |
* associated with this graphics device. |
|
223 |
*/ |
|
224 |
public GraphicsConfiguration getDefaultConfiguration() { |
|
225 |
if (defaultConfig == null) { |
|
226 |
synchronized (configLock) { |
|
227 |
makeDefaultConfiguration(); |
|
228 |
} |
|
229 |
} |
|
230 |
return defaultConfig; |
|
231 |
} |
|
232 |
||
233 |
private void makeDefaultConfiguration() { |
|
234 |
if (defaultConfig == null) { |
|
235 |
int visNum = getConfigVisualId(0, screen); |
|
236 |
if (X11GraphicsEnvironment.isGLXAvailable()) { |
|
237 |
defaultConfig = GLXGraphicsConfig.getConfig(this, visNum); |
|
238 |
if (X11GraphicsEnvironment.isGLXVerbose()) { |
|
239 |
if (defaultConfig != null) { |
|
240 |
System.out.print("OpenGL pipeline enabled"); |
|
241 |
} else { |
|
242 |
System.out.print("Could not enable OpenGL pipeline"); |
|
243 |
} |
|
244 |
System.out.println(" for default config on screen " + |
|
245 |
screen); |
|
246 |
} |
|
247 |
} |
|
248 |
if (defaultConfig == null) { |
|
249 |
int depth = getConfigDepth(0, screen); |
|
250 |
boolean doubleBuffer = false; |
|
251 |
if (isDBESupported() && doubleBufferVisuals == null) { |
|
24538
25bf8153fbfe
8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents:
24520
diff
changeset
|
252 |
doubleBufferVisuals = new HashSet<>(); |
2 | 253 |
getDoubleBufferVisuals(screen); |
254 |
doubleBuffer = |
|
438
2ae294e4518c
6613529: Avoid duplicate object creation within JDK packages
dav
parents:
2
diff
changeset
|
255 |
doubleBufferVisuals.contains(Integer.valueOf(visNum)); |
2 | 256 |
} |
5579
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
257 |
|
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
258 |
if (X11GraphicsEnvironment.isXRenderAvailable()) { |
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
259 |
if (X11GraphicsEnvironment.isXRenderVerbose()) { |
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
260 |
System.out.println("XRender pipeline enabled"); |
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
261 |
} |
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
262 |
defaultConfig = XRGraphicsConfig.getConfig(this, visNum, |
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
263 |
depth, getConfigColormap(0, screen), |
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
264 |
doubleBuffer); |
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
265 |
} else { |
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
266 |
defaultConfig = X11GraphicsConfig.getConfig(this, visNum, |
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
267 |
depth, getConfigColormap(0, screen), |
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
268 |
doubleBuffer); |
1a5e995a710b
6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents:
5275
diff
changeset
|
269 |
} |
2 | 270 |
} |
271 |
} |
|
272 |
} |
|
273 |
||
274 |
private static native void enterFullScreenExclusive(long window); |
|
275 |
private static native void exitFullScreenExclusive(long window); |
|
276 |
private static native boolean initXrandrExtension(); |
|
277 |
private static native DisplayMode getCurrentDisplayMode(int screen); |
|
278 |
private static native void enumDisplayModes(int screen, |
|
279 |
ArrayList<DisplayMode> modes); |
|
280 |
private static native void configDisplayMode(int screen, |
|
281 |
int width, int height, |
|
282 |
int displayMode); |
|
283 |
private static native void resetNativeData(int screen); |
|
39844
a3cc7e551a48
8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents:
37550
diff
changeset
|
284 |
private static native double getNativeScaleFactor(int screen); |
2 | 285 |
|
286 |
/** |
|
287 |
* Returns true only if: |
|
288 |
* - the Xrandr extension is present |
|
289 |
* - the necessary Xrandr functions were loaded successfully |
|
290 |
*/ |
|
291 |
private static synchronized boolean isXrandrExtensionSupported() { |
|
292 |
if (xrandrExtSupported == null) { |
|
293 |
xrandrExtSupported = |
|
294 |
Boolean.valueOf(initXrandrExtension()); |
|
295 |
} |
|
296 |
return xrandrExtSupported.booleanValue(); |
|
297 |
} |
|
298 |
||
299 |
@Override |
|
300 |
public boolean isFullScreenSupported() { |
|
30486
95884a96b883
8051617: Fullscreen mode is not working properly on Xorg
azvegint
parents:
30473
diff
changeset
|
301 |
boolean fsAvailable = isXrandrExtensionSupported(); |
2 | 302 |
if (fsAvailable) { |
303 |
SecurityManager security = System.getSecurityManager(); |
|
304 |
if (security != null) { |
|
305 |
if (fullScreenExclusivePermission == null) { |
|
306 |
fullScreenExclusivePermission = |
|
307 |
new AWTPermission("fullScreenExclusive"); |
|
308 |
} |
|
309 |
try { |
|
310 |
security.checkPermission(fullScreenExclusivePermission); |
|
311 |
} catch (SecurityException e) { |
|
312 |
return false; |
|
313 |
} |
|
314 |
} |
|
315 |
} |
|
316 |
return fsAvailable; |
|
317 |
} |
|
318 |
||
319 |
@Override |
|
320 |
public boolean isDisplayChangeSupported() { |
|
31650
50fa51b5e407
8081371: [PIT] Test closed/java/awt/FullScreen/DisplayMode/CycleDMImage.java switches Linux to the single device mode
azvegint
parents:
30938
diff
changeset
|
321 |
return (isFullScreenSupported() |
32114
73945c07ea9f
8131752: [Regression] Test java/awt/GraphicsDevice/CheckDisplayModes.java fails
azvegint
parents:
31653
diff
changeset
|
322 |
&& (getFullScreenWindow() != null) |
31650
50fa51b5e407
8081371: [PIT] Test closed/java/awt/FullScreen/DisplayMode/CycleDMImage.java switches Linux to the single device mode
azvegint
parents:
30938
diff
changeset
|
323 |
&& !((X11GraphicsEnvironment) GraphicsEnvironment |
50fa51b5e407
8081371: [PIT] Test closed/java/awt/FullScreen/DisplayMode/CycleDMImage.java switches Linux to the single device mode
azvegint
parents:
30938
diff
changeset
|
324 |
.getLocalGraphicsEnvironment()).runningXinerama()); |
2 | 325 |
} |
326 |
||
327 |
private static void enterFullScreenExclusive(Window w) { |
|
30469 | 328 |
X11ComponentPeer peer = AWTAccessor.getComponentAccessor().getPeer(w); |
2 | 329 |
if (peer != null) { |
30486
95884a96b883
8051617: Fullscreen mode is not working properly on Xorg
azvegint
parents:
30473
diff
changeset
|
330 |
enterFullScreenExclusive(peer.getWindow()); |
4256
24d614d4764a
6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents:
889
diff
changeset
|
331 |
peer.setFullScreenExclusiveModeState(true); |
2 | 332 |
} |
333 |
} |
|
334 |
||
335 |
private static void exitFullScreenExclusive(Window w) { |
|
30469 | 336 |
X11ComponentPeer peer = AWTAccessor.getComponentAccessor().getPeer(w); |
2 | 337 |
if (peer != null) { |
4256
24d614d4764a
6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents:
889
diff
changeset
|
338 |
peer.setFullScreenExclusiveModeState(false); |
30486
95884a96b883
8051617: Fullscreen mode is not working properly on Xorg
azvegint
parents:
30473
diff
changeset
|
339 |
exitFullScreenExclusive(peer.getWindow()); |
2 | 340 |
} |
341 |
} |
|
342 |
||
343 |
@Override |
|
344 |
public synchronized void setFullScreenWindow(Window w) { |
|
345 |
Window old = getFullScreenWindow(); |
|
346 |
if (w == old) { |
|
347 |
return; |
|
348 |
} |
|
349 |
||
350 |
boolean fsSupported = isFullScreenSupported(); |
|
351 |
if (fsSupported && old != null) { |
|
352 |
// enter windowed mode (and restore original display mode) |
|
353 |
exitFullScreenExclusive(old); |
|
31650
50fa51b5e407
8081371: [PIT] Test closed/java/awt/FullScreen/DisplayMode/CycleDMImage.java switches Linux to the single device mode
azvegint
parents:
30938
diff
changeset
|
354 |
if (isDisplayChangeSupported()) { |
50fa51b5e407
8081371: [PIT] Test closed/java/awt/FullScreen/DisplayMode/CycleDMImage.java switches Linux to the single device mode
azvegint
parents:
30938
diff
changeset
|
355 |
setDisplayMode(origDisplayMode); |
50fa51b5e407
8081371: [PIT] Test closed/java/awt/FullScreen/DisplayMode/CycleDMImage.java switches Linux to the single device mode
azvegint
parents:
30938
diff
changeset
|
356 |
} |
2 | 357 |
} |
358 |
||
359 |
super.setFullScreenWindow(w); |
|
360 |
||
361 |
if (fsSupported && w != null) { |
|
362 |
// save original display mode |
|
363 |
if (origDisplayMode == null) { |
|
364 |
origDisplayMode = getDisplayMode(); |
|
365 |
} |
|
366 |
||
367 |
// enter fullscreen mode |
|
368 |
enterFullScreenExclusive(w); |
|
369 |
} |
|
370 |
} |
|
371 |
||
372 |
private DisplayMode getDefaultDisplayMode() { |
|
373 |
GraphicsConfiguration gc = getDefaultConfiguration(); |
|
374 |
Rectangle r = gc.getBounds(); |
|
375 |
return new DisplayMode(r.width, r.height, |
|
376 |
DisplayMode.BIT_DEPTH_MULTI, |
|
377 |
DisplayMode.REFRESH_RATE_UNKNOWN); |
|
378 |
} |
|
379 |
||
380 |
@Override |
|
381 |
public synchronized DisplayMode getDisplayMode() { |
|
382 |
if (isFullScreenSupported()) { |
|
30473
e1314bc8c877
7145508: java.awt.GraphicsDevice.get/setDisplayMode behavior is incorrect when no display is present
prr
parents:
30469
diff
changeset
|
383 |
DisplayMode mode = getCurrentDisplayMode(screen); |
e1314bc8c877
7145508: java.awt.GraphicsDevice.get/setDisplayMode behavior is incorrect when no display is present
prr
parents:
30469
diff
changeset
|
384 |
if (mode == null) { |
e1314bc8c877
7145508: java.awt.GraphicsDevice.get/setDisplayMode behavior is incorrect when no display is present
prr
parents:
30469
diff
changeset
|
385 |
mode = getDefaultDisplayMode(); |
e1314bc8c877
7145508: java.awt.GraphicsDevice.get/setDisplayMode behavior is incorrect when no display is present
prr
parents:
30469
diff
changeset
|
386 |
} |
e1314bc8c877
7145508: java.awt.GraphicsDevice.get/setDisplayMode behavior is incorrect when no display is present
prr
parents:
30469
diff
changeset
|
387 |
return mode; |
2 | 388 |
} else { |
389 |
if (origDisplayMode == null) { |
|
390 |
origDisplayMode = getDefaultDisplayMode(); |
|
391 |
} |
|
392 |
return origDisplayMode; |
|
393 |
} |
|
394 |
} |
|
395 |
||
396 |
@Override |
|
397 |
public synchronized DisplayMode[] getDisplayModes() { |
|
398 |
if (!isFullScreenSupported()) { |
|
399 |
return super.getDisplayModes(); |
|
400 |
} |
|
401 |
ArrayList<DisplayMode> modes = new ArrayList<DisplayMode>(); |
|
402 |
enumDisplayModes(screen, modes); |
|
403 |
DisplayMode[] retArray = new DisplayMode[modes.size()]; |
|
404 |
return modes.toArray(retArray); |
|
405 |
} |
|
406 |
||
407 |
@Override |
|
408 |
public synchronized void setDisplayMode(DisplayMode dm) { |
|
409 |
if (!isDisplayChangeSupported()) { |
|
410 |
super.setDisplayMode(dm); |
|
411 |
return; |
|
412 |
} |
|
413 |
Window w = getFullScreenWindow(); |
|
414 |
if (w == null) { |
|
415 |
throw new IllegalStateException("Must be in fullscreen mode " + |
|
416 |
"in order to set display mode"); |
|
417 |
} |
|
887 | 418 |
if (getDisplayMode().equals(dm)) { |
419 |
return; |
|
420 |
} |
|
2 | 421 |
if (dm == null || |
422 |
(dm = getMatchingDisplayMode(dm)) == null) |
|
423 |
{ |
|
424 |
throw new IllegalArgumentException("Invalid display mode"); |
|
425 |
} |
|
426 |
||
427 |
if (!shutdownHookRegistered) { |
|
428 |
// register a shutdown hook so that we return to the |
|
429 |
// original DisplayMode when the VM exits (if the application |
|
430 |
// is already in the original DisplayMode at that time, this |
|
431 |
// hook will have no effect) |
|
432 |
shutdownHookRegistered = true; |
|
23900
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23010
diff
changeset
|
433 |
PrivilegedAction<Void> a = () -> { |
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23010
diff
changeset
|
434 |
Runnable r = () -> { |
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23010
diff
changeset
|
435 |
Window old = getFullScreenWindow(); |
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23010
diff
changeset
|
436 |
if (old != null) { |
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23010
diff
changeset
|
437 |
exitFullScreenExclusive(old); |
31650
50fa51b5e407
8081371: [PIT] Test closed/java/awt/FullScreen/DisplayMode/CycleDMImage.java switches Linux to the single device mode
azvegint
parents:
30938
diff
changeset
|
438 |
if (isDisplayChangeSupported()) { |
50fa51b5e407
8081371: [PIT] Test closed/java/awt/FullScreen/DisplayMode/CycleDMImage.java switches Linux to the single device mode
azvegint
parents:
30938
diff
changeset
|
439 |
setDisplayMode(origDisplayMode); |
50fa51b5e407
8081371: [PIT] Test closed/java/awt/FullScreen/DisplayMode/CycleDMImage.java switches Linux to the single device mode
azvegint
parents:
30938
diff
changeset
|
440 |
} |
2 | 441 |
} |
23900
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23010
diff
changeset
|
442 |
}; |
29922 | 443 |
String name = "Display-Change-Shutdown-Thread-" + screen; |
37550
c8252b8fea3d
8147544: Remove sun.misc.ManagedLocalsThread from java.desktop
prr
parents:
34395
diff
changeset
|
444 |
Thread t = new Thread( |
c8252b8fea3d
8147544: Remove sun.misc.ManagedLocalsThread from java.desktop
prr
parents:
34395
diff
changeset
|
445 |
ThreadGroupUtils.getRootThreadGroup(), r, name, 0, false); |
23900
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23010
diff
changeset
|
446 |
t.setContextClassLoader(null); |
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23010
diff
changeset
|
447 |
Runtime.getRuntime().addShutdownHook(t); |
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23010
diff
changeset
|
448 |
return null; |
2 | 449 |
}; |
5275
fa9f5ce2006e
6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents:
4285
diff
changeset
|
450 |
AccessController.doPrivileged(a); |
2 | 451 |
} |
452 |
||
453 |
// switch to the new DisplayMode |
|
454 |
configDisplayMode(screen, |
|
455 |
dm.getWidth(), dm.getHeight(), |
|
456 |
dm.getRefreshRate()); |
|
457 |
||
458 |
// update bounds of the fullscreen window |
|
459 |
w.setBounds(0, 0, dm.getWidth(), dm.getHeight()); |
|
460 |
||
461 |
// configDisplayMode() is synchronous, so the display change will be |
|
462 |
// complete by the time we get here (and it is therefore safe to call |
|
463 |
// displayChanged() now) |
|
464 |
((X11GraphicsEnvironment) |
|
465 |
GraphicsEnvironment.getLocalGraphicsEnvironment()).displayChanged(); |
|
466 |
} |
|
467 |
||
468 |
private synchronized DisplayMode getMatchingDisplayMode(DisplayMode dm) { |
|
469 |
if (!isDisplayChangeSupported()) { |
|
470 |
return null; |
|
471 |
} |
|
472 |
DisplayMode[] modes = getDisplayModes(); |
|
473 |
for (DisplayMode mode : modes) { |
|
474 |
if (dm.equals(mode) || |
|
475 |
(dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN && |
|
476 |
dm.getWidth() == mode.getWidth() && |
|
477 |
dm.getHeight() == mode.getHeight() && |
|
478 |
dm.getBitDepth() == mode.getBitDepth())) |
|
479 |
{ |
|
480 |
return mode; |
|
481 |
} |
|
482 |
} |
|
483 |
return null; |
|
484 |
} |
|
485 |
||
486 |
/** |
|
487 |
* From the DisplayChangedListener interface; called from |
|
488 |
* X11GraphicsEnvironment when the display mode has been changed. |
|
489 |
*/ |
|
490 |
public synchronized void displayChanged() { |
|
11083
34aa99149ff2
7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents:
7668
diff
changeset
|
491 |
// On X11 the visuals do not change, and therefore we don't need |
34aa99149ff2
7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents:
7668
diff
changeset
|
492 |
// to reset the defaultConfig, config, doubleBufferVisuals, |
34aa99149ff2
7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents:
7668
diff
changeset
|
493 |
// neither do we need to reset the native data. |
2 | 494 |
|
495 |
// pass on to all top-level windows on this screen |
|
496 |
topLevels.notifyListeners(); |
|
497 |
} |
|
498 |
||
499 |
/** |
|
500 |
* From the DisplayChangedListener interface; devices do not need |
|
501 |
* to react to this event. |
|
502 |
*/ |
|
503 |
public void paletteChanged() { |
|
504 |
} |
|
505 |
||
506 |
/** |
|
507 |
* Add a DisplayChangeListener to be notified when the display settings |
|
508 |
* are changed. Typically, only top-level containers need to be added |
|
509 |
* to X11GraphicsDevice. |
|
510 |
*/ |
|
511 |
public void addDisplayChangedListener(DisplayChangedListener client) { |
|
512 |
topLevels.add(client); |
|
513 |
} |
|
514 |
||
34395 | 515 |
public int getScaleFactor() { |
516 |
return scale; |
|
517 |
} |
|
518 |
||
39844
a3cc7e551a48
8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents:
37550
diff
changeset
|
519 |
public int getNativeScale() { |
a3cc7e551a48
8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents:
37550
diff
changeset
|
520 |
isXrandrExtensionSupported(); |
a3cc7e551a48
8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents:
37550
diff
changeset
|
521 |
return (int)Math.round(getNativeScaleFactor(screen)); |
a3cc7e551a48
8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents:
37550
diff
changeset
|
522 |
} |
a3cc7e551a48
8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents:
37550
diff
changeset
|
523 |
|
34395 | 524 |
private int initScaleFactor() { |
525 |
||
526 |
if (SunGraphicsEnvironment.isUIScaleEnabled()) { |
|
527 |
||
528 |
double debugScale = SunGraphicsEnvironment.getDebugScale(); |
|
529 |
||
530 |
if (debugScale >= 1) { |
|
531 |
return (int) debugScale; |
|
532 |
} |
|
39844
a3cc7e551a48
8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents:
37550
diff
changeset
|
533 |
int nativeScale = getNativeScale(); |
34395 | 534 |
return nativeScale >= 1 ? nativeScale : 1; |
535 |
} |
|
536 |
||
537 |
return 1; |
|
538 |
} |
|
539 |
||
2 | 540 |
/** |
541 |
* Remove a DisplayChangeListener from this X11GraphicsDevice. |
|
542 |
*/ |
|
543 |
public void removeDisplayChangedListener(DisplayChangedListener client) { |
|
544 |
topLevels.remove(client); |
|
545 |
} |
|
546 |
||
547 |
public String toString() { |
|
548 |
return ("X11GraphicsDevice[screen="+screen+"]"); |
|
549 |
} |
|
550 |
} |