1
1
/*
2
- * Copyright (c) 2007, 2016 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2007, 2021 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
26
26
* @bug 6646411
27
27
* @summary Tests that full screen window and its children receive resize
28
28
event when display mode changes
29
- * @author Dmitri.Trembovetski@sun.com: area=Graphics
30
29
* @run main/othervm NoResizeEventOnDMChangeTest
31
30
* @run main/othervm -Dsun.java2d.d3d=false NoResizeEventOnDMChangeTest
32
31
*/
@@ -151,9 +150,22 @@ public void run() {
151
150
System .err .printf ("----------- Setting DM %dx%d:\n " ,
152
151
dm1 .getWidth (), dm1 .getHeight ());
153
152
try {
153
+ Frame f = fsWin instanceof Frame ? (Frame ) fsWin : (Frame ) fsWin .getOwner ();
154
+ DisplayMode oldMode = f .getGraphicsConfiguration ().getDevice ().getDisplayMode ();
154
155
gd .setDisplayMode (dm1 );
155
- r1 .incDmChanges ();
156
- r2 .incDmChanges ();
156
+ sleep (2000 );
157
+ // Check if setting new display mode actually results in frame being
158
+ // placed onto display with different resolution.
159
+ DisplayMode newMode = f .getGraphicsConfiguration ().getDevice ().getDisplayMode ();
160
+ if (oldMode .getWidth () != newMode .getWidth ()
161
+ || oldMode .getHeight () != newMode .getHeight ()) {
162
+ r1 .incDmChanges ();
163
+ r2 .incDmChanges ();
164
+ } else {
165
+ System .out .println ("Skipping this iteration. Details:" );
166
+ System .out .println ("Requested device = " + gd );
167
+ System .out .println ("Actual device = " + f .getGraphicsConfiguration ().getDevice ());
168
+ }
157
169
} catch (IllegalArgumentException iae ) {}
158
170
}
159
171
});
@@ -166,6 +178,7 @@ public void run() {
166
178
fsWin .removeComponentListener (r1 );
167
179
c .removeComponentListener (r2 );
168
180
}
181
+
169
182
try {
170
183
EventQueue .invokeAndWait (new Runnable () {
171
184
public void run () {
@@ -191,10 +204,14 @@ public void run() {
191
204
}
192
205
193
206
static void sleep (long ms ) {
194
- try {
195
- Thread .sleep (ms );
196
- } catch (InterruptedException ex ) {}
207
+ long targetTime = System .currentTimeMillis () + ms ;
208
+ do {
209
+ try {
210
+ Thread .sleep (targetTime - System .currentTimeMillis ());
211
+ } catch (InterruptedException ex ) {}
212
+ } while (System .currentTimeMillis () < targetTime );
197
213
}
214
+
198
215
static class ResizeEventChecker extends ComponentAdapter {
199
216
int dmChanges ;
200
217
int resizes ;
0 commit comments