Skip to content

Commit 240541e

Browse files
committed
8359266: Delete the usage of AppContext in the GraphicsDevice
Reviewed-by: aivanov, azvegint
1 parent a23de2e commit 240541e

File tree

2 files changed

+70
-28
lines changed

2 files changed

+70
-28
lines changed

src/java.desktop/share/classes/java/awt/GraphicsDevice.java

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,7 +27,6 @@
2727

2828
import java.awt.image.ColorModel;
2929

30-
import sun.awt.AppContext;
3130
import sun.awt.SunToolkit;
3231

3332
/**
@@ -75,13 +74,7 @@
7574
*/
7675
public abstract class GraphicsDevice {
7776

78-
private Window fullScreenWindow;
79-
private AppContext fullScreenAppContext; // tracks which AppContext
80-
// created the FS window
81-
// this lock is used for making synchronous changes to the AppContext's
82-
// current full screen window
83-
private final Object fsAppContextLock = new Object();
84-
77+
private volatile Window fullScreenWindow;
8578
private Rectangle windowedModeBounds;
8679

8780
/**
@@ -303,23 +296,15 @@ public void setFullScreenWindow(Window w) {
303296
fullScreenWindow.setBounds(windowedModeBounds);
304297
}
305298
// Set the full screen window
306-
synchronized (fsAppContextLock) {
307-
// Associate fullscreen window with current AppContext
308-
if (w == null) {
309-
fullScreenAppContext = null;
310-
} else {
311-
fullScreenAppContext = AppContext.getAppContext();
312-
}
313-
fullScreenWindow = w;
314-
}
299+
fullScreenWindow = w;
315300
if (fullScreenWindow != null) {
316301
windowedModeBounds = fullScreenWindow.getBounds();
317302
// Note that we use the graphics configuration of the device,
318303
// not the window's, because we're setting the fs window for
319304
// this device.
320305
final GraphicsConfiguration gc = getDefaultConfiguration();
321306
final Rectangle screenBounds = gc.getBounds();
322-
if (SunToolkit.isDispatchThreadForAppContext(fullScreenWindow)) {
307+
if (EventQueue.isDispatchThread()) {
323308
// Update graphics configuration here directly and do not wait
324309
// asynchronous notification from the peer. Note that
325310
// setBounds() will reset a GC, if it was set incorrectly.
@@ -342,15 +327,7 @@ public void setFullScreenWindow(Window w) {
342327
* @since 1.4
343328
*/
344329
public Window getFullScreenWindow() {
345-
Window returnWindow = null;
346-
synchronized (fsAppContextLock) {
347-
// Only return a handle to the current fs window if we are in the
348-
// same AppContext that set the fs window
349-
if (fullScreenAppContext == AppContext.getAppContext()) {
350-
returnWindow = fullScreenWindow;
351-
}
352-
}
353-
return returnWindow;
330+
return fullScreenWindow;
354331
}
355332

356333
/**
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright Amazon.com Inc. 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+
import java.awt.GraphicsDevice;
25+
import java.awt.GraphicsEnvironment;
26+
import java.awt.Window;
27+
28+
/**
29+
* @test
30+
* @key headful
31+
* @bug 8359266
32+
* @summary Tests for a race condition when setting a full-screen window
33+
*/
34+
public final class FullScreenWindowRace {
35+
36+
public static void main(String[] args) throws InterruptedException {
37+
Window window = new Window(null);
38+
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment()
39+
.getDefaultScreenDevice();
40+
41+
Thread thread = new Thread(() -> {
42+
while (gd.getFullScreenWindow() == null) {
43+
// Busy wait - can be optimized away without volatile
44+
}
45+
});
46+
47+
thread.setDaemon(true);
48+
thread.start();
49+
50+
// Give thread some time to start and begin the loop
51+
Thread.sleep(2000);
52+
53+
gd.setFullScreenWindow(window);
54+
55+
thread.join(15000);
56+
57+
boolean alive = thread.isAlive();
58+
59+
gd.setFullScreenWindow(null);
60+
window.dispose();
61+
if (alive) {
62+
throw new RuntimeException("Full screen window is NOT detected!");
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)