Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/FullScreen/MultimonFullscreenTest/MultimonFullscreenTest.java
41153 views
1
/*
2
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
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
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/**
25
* @test
26
* @bug 5041219 5101561 5035272 5096011 5101712 5098624 8198613
27
* @summary Here are a few assertions worth verification:
28
* - the fullscreen window is positioned at 0,0
29
* - the fs window appears on the correct screen
30
* - if the exclusive FS mode is supported, no other widndow should
31
* overlap the fs window (including the taskbar).
32
* You could, however, alt+tab out of a fullscreen window, or at least
33
* minimize it (if you've entered the fs mode with a Window, you'll need
34
* to minimize the owner frame).
35
* Note that there may be issues with FS exclusive mode with ddraw and
36
* multiple fullscreen windows (one per device).
37
* - if display mode is supported that it did change
38
* - that the original display mode is restored once
39
* the ws window is disposed
40
* All of the above should work with and w/o DirectDraw
41
* (-Dsun.java2d.noddraw=true) on windows, and w/ and w/o opengl on X11
42
* (-Dsun.java2d.opengl=True).
43
* @run main/manual/othervm -Dsun.java2d.pmoffscreen=true MultimonFullscreenTest
44
* @run main/manual/othervm -Dsun.java2d.pmoffscreen=false MultimonFullscreenTest
45
* @run main/manual/othervm -Dsun.java2d.d3d=True MultimonFullscreenTest
46
* @run main/manual/othervm -Dsun.java2d.noddraw=true MultimonFullscreenTest
47
* @run main/manual/othervm MultimonFullscreenTest
48
*/
49
50
import java.awt.Button;
51
import java.awt.Checkbox;
52
import java.awt.CheckboxGroup;
53
import java.awt.Color;
54
import java.awt.Component;
55
import java.awt.Dialog;
56
import java.awt.DisplayMode;
57
import java.awt.Font;
58
import java.awt.Frame;
59
import java.awt.Graphics;
60
import java.awt.GraphicsConfiguration;
61
import java.awt.GraphicsDevice;
62
import java.awt.GraphicsEnvironment;
63
import java.awt.GridLayout;
64
import java.awt.Panel;
65
import java.awt.Rectangle;
66
import java.awt.Window;
67
import java.awt.event.ActionEvent;
68
import java.awt.event.ActionListener;
69
import java.awt.event.ItemEvent;
70
import java.awt.event.ItemListener;
71
import java.awt.event.MouseAdapter;
72
import java.awt.event.MouseEvent;
73
import java.awt.event.WindowAdapter;
74
import java.awt.event.WindowEvent;
75
import java.awt.image.BufferStrategy;
76
import java.util.HashMap;
77
import java.util.Random;
78
79
/**
80
*/
81
82
public class MultimonFullscreenTest extends Frame implements ActionListener {
83
GraphicsDevice defDev = GraphicsEnvironment.getLocalGraphicsEnvironment().
84
getDefaultScreenDevice();
85
GraphicsDevice gd[] = GraphicsEnvironment.getLocalGraphicsEnvironment().
86
getScreenDevices();
87
HashMap<Button, GraphicsDevice> deviceMap;
88
89
private static boolean dmChange = false;
90
static boolean setNullOnDispose = false;
91
static boolean useFSFrame = true;
92
static boolean useFSWindow = false;
93
static boolean useFSDialog = false;
94
static boolean useBS = false;
95
static boolean runRenderLoop = false;
96
static boolean addHWChildren = false;
97
static volatile boolean done = true;
98
99
public MultimonFullscreenTest(String title) {
100
super(title);
101
addWindowListener(new WindowAdapter() {
102
public void windowClosing(WindowEvent e) {
103
System.exit(0);
104
}
105
});
106
Panel p = new Panel();
107
deviceMap = new HashMap<Button, GraphicsDevice>(gd.length);
108
int num = 0;
109
for (GraphicsDevice dev : gd) {
110
Button b;
111
if (dev == defDev) {
112
b = new Button("Primary screen: " + num);
113
System.out.println("Primary Dev : " + dev + " Bounds: " +
114
dev.getDefaultConfiguration().getBounds());
115
} else {
116
b = new Button("Secondary screen " + num);
117
System.out.println("Secondary Dev : " + dev + " Bounds: " +
118
dev.getDefaultConfiguration().getBounds());
119
}
120
b.addActionListener(this);
121
p.add(b);
122
deviceMap.put(b, dev);
123
num++;
124
}
125
add("South", p);
126
Panel p1 = new Panel();
127
p1.setLayout(new GridLayout(2,0));
128
Checkbox cb = new Checkbox("Change DM on entering FS");
129
cb.addItemListener(new ItemListener() {
130
public void itemStateChanged(ItemEvent e) {
131
dmChange = ((Checkbox)e.getSource()).getState();
132
}
133
});
134
p1.add(cb);
135
// cb = new Checkbox("Exit FS on window dispose");
136
// cb.addItemListener(new ItemListener() {
137
// public void itemStateChanged(ItemEvent e) {
138
// setNullOnDispose = ((Checkbox)e.getSource()).getState();
139
// }
140
// });
141
// p1.add(cb);
142
CheckboxGroup cbg = new CheckboxGroup();
143
cb = new Checkbox("Use Frame to enter FS", cbg, true);
144
cb.addItemListener(new ItemListener() {
145
public void itemStateChanged(ItemEvent e) {
146
useFSFrame = true;
147
useFSWindow = false;
148
useFSDialog = false;
149
}
150
});
151
p1.add(cb);
152
cb = new Checkbox("Use Window to enter FS", cbg, false);
153
cb.addItemListener(new ItemListener() {
154
public void itemStateChanged(ItemEvent e) {
155
useFSFrame = false;
156
useFSWindow = true;
157
useFSDialog = false;
158
}
159
});
160
p1.add(cb);
161
cb = new Checkbox("Use Dialog to enter FS", cbg, false);
162
cb.addItemListener(new ItemListener() {
163
public void itemStateChanged(ItemEvent e) {
164
useFSFrame = false;
165
useFSWindow = false;
166
useFSDialog = true;
167
}
168
});
169
p1.add(cb);
170
cb = new Checkbox("Run render loop");
171
cb.addItemListener(new ItemListener() {
172
public void itemStateChanged(ItemEvent e) {
173
runRenderLoop = ((Checkbox)e.getSource()).getState();
174
}
175
});
176
p1.add(cb);
177
cb = new Checkbox("Use BufferStrategy in render loop");
178
cb.addItemListener(new ItemListener() {
179
public void itemStateChanged(ItemEvent e) {
180
useBS = ((Checkbox)e.getSource()).getState();
181
}
182
});
183
p1.add(cb);
184
cb = new Checkbox("Add Children to FS window");
185
cb.addItemListener(new ItemListener() {
186
public void itemStateChanged(ItemEvent e) {
187
addHWChildren = ((Checkbox)e.getSource()).getState();
188
}
189
});
190
p1.add(cb);
191
add("North", p1);
192
193
pack();
194
setVisible(true);
195
}
196
197
Font f = new Font("Dialog", Font.BOLD, 24);
198
Random rnd = new Random();
199
public void renderDimensions(Graphics g, Rectangle rectWndBounds,
200
GraphicsConfiguration gc) {
201
g.setColor(new Color(rnd.nextInt(0xffffff)));
202
g.fillRect(0, 0, rectWndBounds.width, rectWndBounds.height);
203
204
g.setColor(new Color(rnd.nextInt(0xffffff)));
205
Rectangle rectStrBounds;
206
207
g.setFont(f);
208
209
rectStrBounds = g.getFontMetrics().
210
getStringBounds(rectWndBounds.toString(), g).getBounds();
211
rectStrBounds.height += 30;
212
g.drawString(rectWndBounds.toString(), 50, rectStrBounds.height);
213
int oldHeight = rectStrBounds.height;
214
String isFSupported = "Exclusive Fullscreen mode supported: " +
215
gc.getDevice().isFullScreenSupported();
216
rectStrBounds = g.getFontMetrics().
217
getStringBounds(isFSupported, g).getBounds();
218
rectStrBounds.height += (10 + oldHeight);
219
g.drawString(isFSupported, 50, rectStrBounds.height);
220
221
oldHeight = rectStrBounds.height;
222
String isDMChangeSupported = "Display Mode Change supported: " +
223
gc.getDevice().isDisplayChangeSupported();
224
rectStrBounds = g.getFontMetrics().
225
getStringBounds(isDMChangeSupported, g).getBounds();
226
rectStrBounds.height += (10 + oldHeight);
227
g.drawString(isDMChangeSupported, 50, rectStrBounds.height);
228
229
oldHeight = rectStrBounds.height;
230
String usingBS = "Using BufferStrategy: " + useBS;
231
rectStrBounds = g.getFontMetrics().
232
getStringBounds(usingBS, g).getBounds();
233
rectStrBounds.height += (10 + oldHeight);
234
g.drawString(usingBS, 50, rectStrBounds.height);
235
236
final String m_strQuitMsg = "Double-click to dispose FullScreen Window";
237
rectStrBounds = g.getFontMetrics().
238
getStringBounds(m_strQuitMsg, g).getBounds();
239
g.drawString(m_strQuitMsg,
240
(rectWndBounds.width - rectStrBounds.width) / 2,
241
(rectWndBounds.height - rectStrBounds.height) / 2);
242
243
244
}
245
246
public void actionPerformed(ActionEvent ae) {
247
GraphicsDevice dev = deviceMap.get(ae.getSource());
248
System.err.println("Setting FS on device:"+dev);
249
final Window fsWindow;
250
251
if (useFSWindow) {
252
fsWindow = new Window(this, dev.getDefaultConfiguration()) {
253
public void paint(Graphics g) {
254
renderDimensions(g, getBounds(),
255
this.getGraphicsConfiguration());
256
}
257
};
258
} else if (useFSDialog) {
259
fsWindow = new Dialog((Frame)null, "FS Dialog on device "+dev, false,
260
dev.getDefaultConfiguration());
261
fsWindow.add(new Component() {
262
public void paint(Graphics g) {
263
renderDimensions(g, getBounds(),
264
this.getGraphicsConfiguration());
265
}
266
});
267
} else {
268
fsWindow = new Frame("FS Frame on device "+dev,
269
dev.getDefaultConfiguration())
270
{
271
public void paint(Graphics g) {
272
renderDimensions(g, getBounds(),
273
this.getGraphicsConfiguration());
274
}
275
};
276
if (addHWChildren) {
277
fsWindow.add("South", new Panel() {
278
public void paint(Graphics g) {
279
g.setColor(Color.red);
280
g.fillRect(0, 0, getWidth(), getHeight());
281
}
282
});
283
fsWindow.add("North", new Button("Button, sucka!"));
284
}
285
}
286
fsWindow.addMouseListener(new MouseAdapter() {
287
public void mouseClicked(MouseEvent e) {
288
if (e.getClickCount() > 1) {
289
done = true;
290
fsWindow.dispose();
291
}
292
}
293
});
294
295
fsWindow.addWindowListener(new WindowHandler());
296
dev.setFullScreenWindow(fsWindow);
297
if (dmChange && dev.isDisplayChangeSupported()) {
298
DisplayMode dms[] = dev.getDisplayModes();
299
DisplayMode myDM = null;
300
for (DisplayMode dm : dms) {
301
if (dm.getWidth() == 800 && dm.getHeight() == 600 &&
302
(dm.getBitDepth() >= 16 ||
303
dm.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI) &&
304
(dm.getRefreshRate() >= 60 ||
305
dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN))
306
{
307
myDM = dm;
308
break;
309
}
310
}
311
if (myDM != null) {
312
System.err.println("Setting Display Mode: "+
313
myDM.getWidth() + "x" + myDM.getHeight() + "x" +
314
myDM.getBitDepth() + "@" + myDM.getRefreshRate() +
315
"Hz on device" + dev);
316
dev.setDisplayMode(myDM);
317
} else {
318
System.err.println("Can't find suitable display mode.");
319
}
320
}
321
done = false;
322
if (runRenderLoop) {
323
Thread updateThread = new Thread(new Runnable() {
324
public void run() {
325
BufferStrategy bs = null;
326
if (useBS) {
327
fsWindow.createBufferStrategy(2);
328
bs = fsWindow.getBufferStrategy();
329
}
330
while (!done) {
331
if (useBS) {
332
Graphics g = bs.getDrawGraphics();
333
renderDimensions(g, fsWindow.getBounds(),
334
fsWindow.getGraphicsConfiguration());
335
bs.show();
336
} else {
337
fsWindow.repaint();
338
}
339
try {
340
Thread.sleep(1000);
341
} catch (InterruptedException e) {}
342
}
343
if (useBS) {
344
bs.dispose();
345
}
346
}
347
});
348
updateThread.start();
349
}
350
}
351
352
public static void main(String args[]) {
353
for (String s : args) {
354
if (s.equalsIgnoreCase("-dm")) {
355
System.err.println("Do Display Change after entering FS mode");
356
dmChange = true;
357
} else if (s.equalsIgnoreCase("-usewindow")) {
358
System.err.println("Using Window to enter FS mode");
359
useFSWindow = true;
360
} else if (s.equalsIgnoreCase("-setnull")) {
361
System.err.println("Setting null FS window on dispose");
362
setNullOnDispose = true;
363
} else {
364
System.err.println("Usage: MultimonFullscreenTest " +
365
"[-dm][-usewindow][-setnull]");
366
}
367
368
}
369
MultimonFullscreenTest fs =
370
new MultimonFullscreenTest("Test Full Screen");
371
}
372
class WindowHandler extends WindowAdapter {
373
public void windowClosing(WindowEvent we) {
374
done = true;
375
Window w = (Window)we.getSource();
376
if (setNullOnDispose) {
377
w.getGraphicsConfiguration().getDevice().setFullScreenWindow(null);
378
}
379
w.dispose();
380
}
381
}
382
}
383
384