src/macosx/classes/sun/awt/CGraphicsDevice.java

Print this page

        

@@ -33,14 +33,22 @@
 import java.awt.Window;
 import java.util.Objects;
 
 import sun.java2d.opengl.CGLGraphicsConfig;
 
-public final class CGraphicsDevice extends GraphicsDevice {
+public final class CGraphicsDevice extends GraphicsDevice
+        implements DisplayChangedListener {
 
-    // CoreGraphics display ID
-    private final int displayID;
+    /**
+     * CoreGraphics display ID. This identifier can become non-valid at any time
+     * therefore methods, which is using this id should be ready to it.
+     */
+    private volatile int displayID;
+    private volatile Insets screenInsets;
+    private volatile double xResolution;
+    private volatile double yResolution;
+    private volatile int scale;
 
     // Array of all GraphicsConfig instances for this device
     private final GraphicsConfiguration[] configs;
 
     // Default config (temporarily hard coded)

@@ -49,11 +57,11 @@
     private static AWTPermission fullScreenExclusivePermission;
 
     // Save/restore DisplayMode for the Full Screen mode
     private DisplayMode originalMode;
 
-    public CGraphicsDevice(int displayID) {
+    public CGraphicsDevice(final int displayID) {
         this.displayID = displayID;
         configs = new GraphicsConfiguration[] {
             CGLGraphicsConfig.getConfig(this, 0)
         };
     }

@@ -87,11 +95,11 @@
     /**
      * Return a human-readable screen description.
      */
     @Override
     public String getIDstring() {
-        return "Display " + this.displayID;
+        return "Display " + displayID;
     }
 
     /**
      * Returns the type of the graphics device.
      * @see #TYPE_RASTER_SCREEN

@@ -102,19 +110,41 @@
     public int getType() {
         return TYPE_RASTER_SCREEN;
     }
 
     public double getXResolution() {
-        return nativeGetXResolution(displayID);
+        return xResolution;
     }
 
     public double getYResolution() {
-        return nativeGetYResolution(displayID);
+        return yResolution;
     }
 
     public Insets getScreenInsets() {
-        return nativeGetScreenInsets(displayID);
+        return screenInsets;
+    }
+
+    public int getScaleFactor() {
+        return scale;
+    }
+
+    public void invalidate(final int defaultDisplayID) {
+        displayID = defaultDisplayID;
+    }
+    
+    @Override
+    public void displayChanged() {
+        xResolution = nativeGetXResolution(displayID);
+        yResolution = nativeGetYResolution(displayID);
+        screenInsets = nativeGetScreenInsets(displayID);
+        scale = (int) nativeGetScaleFactor(displayID);
+        //TODO configs/fullscreenWindow/modes?
+    }
+
+    @Override
+    public void paletteChanged() {
+        // devices do not need to react to this event.
     }
 
     /**
      * Enters full-screen mode, or returns to windowed mode.
      */

@@ -217,14 +247,10 @@
     @Override
     public DisplayMode[] getDisplayModes() {
         return nativeGetDisplayModes(displayID);
     }
 
-    public int getScaleFactor() {
-        return (int) nativeGetScaleFactor(displayID);
-    }
-
     private static native double nativeGetScaleFactor(int displayID);
 
     private static native void nativeSetDisplayMode(int displayID, int w, int h, int bpp, int refrate);
 
     private static native DisplayMode nativeGetDisplayMode(int displayID);