Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/EmbeddedFrame/GraphicsConfigTest/GraphicsConfigTest.java
38821 views
1
/*
2
* Copyright (c) 2007, 2015, 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 6356322
27
* @summary Tests that embedded frame's graphics configuration is updated
28
* correctly when it is moved to another screen in multiscreen system,
29
* XToolkit
30
* @author [email protected]: area=awt.multiscreen
31
* @requires (os.family == "linux") | (os.family == "solaris")
32
* @run main GraphicsConfigTest
33
*/
34
35
import java.awt.*;
36
import java.awt.peer.*;
37
import java.lang.reflect.*;
38
import java.util.*;
39
import sun.awt.*;
40
import sun.awt.X11.*;
41
42
public class GraphicsConfigTest {
43
44
private static void init()
45
throws InterruptedException, AWTException {
46
if (!isXToolkit()) {
47
System.err.println("The test should be run only on XToolkit");
48
return;
49
}
50
51
GraphicsEnvironment ge =
52
GraphicsEnvironment.getLocalGraphicsEnvironment();
53
GraphicsDevice[] gds = ge.getScreenDevices();
54
if (gds.length < 2) {
55
System.err.println("The test should be run only in"
56
+ " multiscreen configuration");
57
return;
58
}
59
60
boolean xinerama = Arrays.stream(gds)
61
.map((gd) -> gd.getDefaultConfiguration().getBounds())
62
.filter((r) -> r.x != 0 || r.y != 0).findFirst().isPresent();
63
64
if (!xinerama) {
65
System.err.println("The test should be run only with Xinerama ON");
66
return;
67
}
68
69
Rectangle r0 = gds[0].getDefaultConfiguration().getBounds();
70
Rectangle r1 = gds[1].getDefaultConfiguration().getBounds();
71
72
System.setProperty("sun.awt.xembedserver", "true");
73
Frame f = new Frame("F");
74
try {
75
final Robot robot = new Robot();
76
77
f.setBounds(r0.x + 100, r0.y + 100, 200, 200);
78
f.setVisible(true);
79
robot.waitForIdle();
80
Thread.sleep(1000);
81
82
Canvas c = new Canvas();
83
f.add(c);
84
AWTAccessor.ComponentAccessor acc =
85
AWTAccessor.getComponentAccessor();
86
WindowIDProvider wip = (XEmbedCanvasPeer)acc.getPeer(c);
87
long h = wip.getWindow();
88
89
EmbeddedFrame e = createEmbeddedFrame(h);
90
((FramePeer)acc.getPeer(e)).setBoundsPrivate(0, 0, 100,
91
100); // triggers XConfigureEvent
92
e.registerListeners();
93
e.setVisible(true);
94
robot.waitForIdle();
95
Thread.sleep(1000);
96
97
if (!checkGC(f, e)) {
98
throw new RuntimeException("Failed at checkpoint 1");
99
}
100
101
f.setLocation(r1.x + 100, r1.y + 100);
102
Thread.sleep(100);
103
((FramePeer)acc.getPeer(e)).setBoundsPrivate(0, 0, 101,
104
101); // triggers XConfigureEvent
105
robot.waitForIdle();
106
Thread.sleep(1000);
107
108
if (!checkGC(f, e)) {
109
throw new RuntimeException("Failed at checkpoint 2");
110
}
111
112
f.setLocation(r0.x + 100, r0.y + 100);
113
Thread.sleep(100);
114
((FramePeer)acc.getPeer(e)).setBoundsPrivate(0, 0, 102,
115
102); // triggers XConfigureEvent
116
robot.waitForIdle();
117
Thread.sleep(1000);
118
119
if (!checkGC(f, e)) {
120
throw new RuntimeException("Failed at checkpoint 3");
121
}
122
123
} finally {
124
f.dispose();
125
}
126
}
127
128
private static boolean isXToolkit() {
129
return Toolkit.getDefaultToolkit().getClass()
130
.getName().equals("sun.awt.X11.XToolkit");
131
}
132
133
private static EmbeddedFrame createEmbeddedFrame(long window) {
134
try {
135
Class cl = Class.forName("sun.awt.X11.XEmbeddedFrame");
136
Constructor cons = cl.getConstructor(
137
new Class[]{Long.TYPE, Boolean.TYPE});
138
return (EmbeddedFrame) cons.newInstance(new Object[]{window, true});
139
} catch (Exception e) {
140
e.printStackTrace();
141
throw new RuntimeException("Can't create embedded frame");
142
}
143
}
144
145
private static boolean checkGC(Component c, Component d) {
146
GraphicsConfiguration g1 = c.getGraphicsConfiguration();
147
System.err.println(g1);
148
GraphicsConfiguration g2 = d.getGraphicsConfiguration();
149
System.err.println(g2);
150
151
return g1.equals(g2);
152
}
153
154
public static void main(String args[]) throws InterruptedException, AWTException {
155
init();
156
}
157
}
158
159