JRE-359 CGraphicsEnvironment.getDefaultScreenDevice() returns null

Moved CG api calls to AppKit thread

(cherry picked from commit fd0210f035199e8612097a2c1d42b90cfd2111f8)
(cherry picked from commit 5e99e376d9dfe477401121878704630c3c13f9f7)

(cherry picked from commit 6d73b25130)
This commit is contained in:
Alexey Ushakov
2017-05-16 16:54:37 +03:00
committed by Vitaly Provodin
parent eb6f1ab945
commit 8a1e3fa9a2

View File

@@ -40,6 +40,7 @@ import java.util.Map;
import sun.java2d.MacosxSurfaceManagerFactory;
import sun.java2d.SunGraphicsEnvironment;
import sun.java2d.SurfaceManagerFactory;
import sun.lwawt.macosx.CThreading;
/**
* This is an implementation of a GraphicsEnvironment object for the default
@@ -159,7 +160,15 @@ public final class CGraphicsEnvironment extends SunGraphicsEnvironment {
private synchronized void initDevices() {
Map<Integer, CGraphicsDevice> old = new HashMap<>(devices);
devices.clear();
mainDisplayID = getMainDisplayID();
try {
mainDisplayID = CThreading.privilegedExecuteOnAppKit(
CGraphicsEnvironment::getMainDisplayID);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("Could not get main display ID: " +
e.getMessage() );
}
// initialization of the graphics device may change list of displays on
// hybrid systems via an activation of discrete video.
@@ -169,7 +178,17 @@ public final class CGraphicsEnvironment extends SunGraphicsEnvironment {
old.put(mainDisplayID, new CGraphicsDevice(mainDisplayID));
}
int[] displayIDs = getDisplayIDs();
int[] displayIDs;
try {
displayIDs = CThreading.privilegedExecuteOnAppKit(
CGraphicsEnvironment::getDisplayIDs);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("Could not get display IDs: " +
e.getMessage());
}
if (displayIDs.length == 0) {
// we could throw AWTError in this case.
displayIDs = new int[]{mainDisplayID};