diff options
author | Alexey Ushakov <Alexey.Ushakov@jetbrains.com> | 2017-05-16 16:54:37 +0300 |
---|---|---|
committer | Alexey Ushakov <Alexey.Ushakov@jetbrains.com> | 2017-05-16 16:54:37 +0300 |
commit | fd0210f035199e8612097a2c1d42b90cfd2111f8 (patch) | |
tree | cc00babb29ef023434b83dfdf51d4554bca18d7b /src/macosx | |
parent | 511d7c8ae09a74b15f28b0d7030cdcc05c9aac3b (diff) | |
download | jdk8u_jdk-fd0210f035199e8612097a2c1d42b90cfd2111f8.tar.gz |
JRE-359 CGraphicsEnvironment.getDefaultScreenDevice() returns nulljb8u152-b856
Moved CG api calls to AppKit thread
Diffstat (limited to 'src/macosx')
-rw-r--r-- | src/macosx/classes/sun/awt/CGraphicsEnvironment.java | 57 |
1 files changed, 45 insertions, 12 deletions
diff --git a/src/macosx/classes/sun/awt/CGraphicsEnvironment.java b/src/macosx/classes/sun/awt/CGraphicsEnvironment.java index 77783d14bd..78c6454279 100644 --- a/src/macosx/classes/sun/awt/CGraphicsEnvironment.java +++ b/src/macosx/classes/sun/awt/CGraphicsEnvironment.java @@ -27,8 +27,10 @@ package sun.awt; import java.awt.*; import java.util.*; +import java.util.concurrent.Callable; import sun.java2d.*; +import sun.lwawt.macosx.CThreading; /** * This is an implementation of a GraphicsEnvironment object for the default @@ -128,15 +130,18 @@ public final class CGraphicsEnvironment extends SunGraphicsEnvironment { * @param displayId CoreGraphics displayId * @param removed true if displayId was removed, false otherwise. */ + @SuppressWarnings("unused") void _displayReconfiguration(final int displayId, final boolean removed) { synchronized (this) { + // We don't need to switch to AppKit, we're already there + mainDisplayID = getMainDisplayID(); if (removed && devices.containsKey(displayId)) { final CGraphicsDevice gd = devices.remove(displayId); - gd.invalidate(getMainDisplayID()); + gd.invalidate(mainDisplayID); gd.displayChanged(); } } - initDevices(); + initDevices(mainDisplayID); } @Override @@ -151,30 +156,58 @@ public final class CGraphicsEnvironment extends SunGraphicsEnvironment { /** * (Re)create all CGraphicsDevices, reuses a devices if it is possible. */ - private void initDevices() { + private void initDevices(int mainDisplID) { synchronized (this) { - final Map<Integer, CGraphicsDevice> old = new HashMap<>(devices); - devices.clear(); + mainDisplayID = mainDisplID; + createDevices(); + } + displayChanged(); + } - mainDisplayID = getMainDisplayID(); + private void initDevices() { + synchronized (this) { // initialization of the graphics device may change // list of displays on hybrid systems via an activation // of discrete video. // So, we initialize the main display first, and then // retrieve actual list of displays. - if (!old.containsKey(mainDisplayID)) { - old.put(mainDisplayID, new CGraphicsDevice(mainDisplayID)); - } + final Callable<Integer> command = CGraphicsEnvironment::getMainDisplayID; - for (final int id : getDisplayIDs()) { - devices.put(id, old.containsKey(id) ? old.get(id) - : new CGraphicsDevice(id)); + try { + mainDisplayID = CThreading.executeOnAppKit(command); + } catch (Throwable throwable) { + throw new RuntimeException("Could not get main display ID"); } + + createDevices(); + } displayChanged(); } + private void createDevices() { + final Map<Integer, CGraphicsDevice> old = new HashMap<>(devices); + devices.clear(); + + if (!old.containsKey(mainDisplayID)) { + old.put(mainDisplayID, new CGraphicsDevice(mainDisplayID)); + } + final Callable<int[]> command = CGraphicsEnvironment::getDisplayIDs; + + int[] displayIDs; + try { + displayIDs = CThreading.executeOnAppKit(command); + } catch (Throwable throwable) { + throw new RuntimeException("Could not get main display IDs"); + } + + for (final int id : displayIDs) { + devices.put(id, old.containsKey(id) ? old.get(id) + : new CGraphicsDevice(id)); + } + } + @Override public synchronized GraphicsDevice getDefaultScreenDevice() throws HeadlessException { CGraphicsDevice d = devices.get(mainDisplayID); |