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

Print this page




  31 import java.awt.AWTPermission;
  32 import java.awt.DisplayMode;
  33 
  34 import sun.java2d.opengl.CGLGraphicsConfig;
  35 
  36 import sun.awt.FullScreenCapable;
  37 
  38 public class CGraphicsDevice extends GraphicsDevice {
  39 
  40     // CoreGraphics display ID
  41     private final int displayID;
  42 
  43     // Array of all GraphicsConfig instances for this device
  44     private final GraphicsConfiguration[] configs;
  45 
  46     // Default config (temporarily hard coded)
  47     private final int DEFAULT_CONFIG = 0;
  48 
  49     private static AWTPermission fullScreenExclusivePermission;
  50 



  51     public CGraphicsDevice(int displayID) {
  52         this.displayID = displayID;
  53         configs = new GraphicsConfiguration[] {
  54             CGLGraphicsConfig.getConfig(this, 0)
  55         };
  56     }
  57 
  58     /**
  59      * @return CoreGraphics display id.
  60      */
  61     public int getCoreGraphicsScreen() {
  62         return displayID;
  63     }
  64 
  65     /**
  66      * Return a list of all configurations.
  67      */
  68     @Override
  69     public GraphicsConfiguration[] getConfigurations() {
  70         return configs.clone();


 107 
 108     public int getScreenResolution() {
 109         // TODO: report non-72 value when HiDPI is turned on
 110         return 72;
 111     }
 112 
 113     private static native double nativeGetXResolution(int displayID);
 114     private static native double nativeGetYResolution(int displayID);
 115 
 116     /**
 117      * Enters full-screen mode, or returns to windowed mode.
 118      */
 119     @Override
 120     public synchronized void setFullScreenWindow(Window w) {
 121         Window old = getFullScreenWindow();
 122         if (w == old) {
 123             return;
 124         }
 125 
 126         boolean fsSupported = isFullScreenSupported();


 127         if (fsSupported && old != null) {
 128             // enter windowed mode (and restore original display mode)
 129             exitFullScreenExclusive(old);
 130 
 131             // TODO: restore display mode



 132         }


 133 
 134         super.setFullScreenWindow(w);
 135 
 136         if (fsSupported && w != null) {
 137             // TODO: save current display mode
 138 

 139             // enter fullscreen mode
 140             enterFullScreenExclusive(w);
 141         }
 142     }
 143 
 144     /**
 145      * Returns true if this GraphicsDevice supports
 146      * full-screen exclusive mode and false otherwise.
 147      */
 148     @Override
 149     public boolean isFullScreenSupported() {
 150         return isFSExclusiveModeAllowed();
 151     }
 152 
 153     private static boolean isFSExclusiveModeAllowed() {
 154         SecurityManager security = System.getSecurityManager();
 155         if (security != null) {
 156             if (fullScreenExclusivePermission == null) {
 157                 fullScreenExclusivePermission =
 158                     new AWTPermission("fullScreenExclusive");




  31 import java.awt.AWTPermission;
  32 import java.awt.DisplayMode;
  33 
  34 import sun.java2d.opengl.CGLGraphicsConfig;
  35 
  36 import sun.awt.FullScreenCapable;
  37 
  38 public class CGraphicsDevice extends GraphicsDevice {
  39 
  40     // CoreGraphics display ID
  41     private final int displayID;
  42 
  43     // Array of all GraphicsConfig instances for this device
  44     private final GraphicsConfiguration[] configs;
  45 
  46     // Default config (temporarily hard coded)
  47     private final int DEFAULT_CONFIG = 0;
  48 
  49     private static AWTPermission fullScreenExclusivePermission;
  50 
  51     // Save/restore DisplayMode for the Full Screen mode
  52     private DisplayMode originalMode;
  53 
  54     public CGraphicsDevice(int displayID) {
  55         this.displayID = displayID;
  56         configs = new GraphicsConfiguration[] {
  57             CGLGraphicsConfig.getConfig(this, 0)
  58         };
  59     }
  60 
  61     /**
  62      * @return CoreGraphics display id.
  63      */
  64     public int getCoreGraphicsScreen() {
  65         return displayID;
  66     }
  67 
  68     /**
  69      * Return a list of all configurations.
  70      */
  71     @Override
  72     public GraphicsConfiguration[] getConfigurations() {
  73         return configs.clone();


 110 
 111     public int getScreenResolution() {
 112         // TODO: report non-72 value when HiDPI is turned on
 113         return 72;
 114     }
 115 
 116     private static native double nativeGetXResolution(int displayID);
 117     private static native double nativeGetYResolution(int displayID);
 118 
 119     /**
 120      * Enters full-screen mode, or returns to windowed mode.
 121      */
 122     @Override
 123     public synchronized void setFullScreenWindow(Window w) {
 124         Window old = getFullScreenWindow();
 125         if (w == old) {
 126             return;
 127         }
 128 
 129         boolean fsSupported = isFullScreenSupported();
 130         boolean dcSupported = isDisplayChangeSupported();
 131 
 132         if (fsSupported && old != null) {
 133             // enter windowed mode (and restore original display mode)
 134             exitFullScreenExclusive(old);
 135             if (originalMode != null) {
 136                 if (dcSupported) {
 137                     setDisplayMode(originalMode);
 138                 }
 139                 originalMode = null;
 140             }
 141         }
 142 
 143 
 144         super.setFullScreenWindow(w);
 145 
 146         if (fsSupported && w != null) {
 147             if (dcSupported) {
 148                 originalMode = getDisplayMode();
 149             }
 150             // enter fullscreen mode
 151             enterFullScreenExclusive(w);
 152         }
 153     }
 154 
 155     /**
 156      * Returns true if this GraphicsDevice supports
 157      * full-screen exclusive mode and false otherwise.
 158      */
 159     @Override
 160     public boolean isFullScreenSupported() {
 161         return isFSExclusiveModeAllowed();
 162     }
 163 
 164     private static boolean isFSExclusiveModeAllowed() {
 165         SecurityManager security = System.getSecurityManager();
 166         if (security != null) {
 167             if (fullScreenExclusivePermission == null) {
 168                 fullScreenExclusivePermission =
 169                     new AWTPermission("fullScreenExclusive");