18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.awt; 27 28 import java.awt.AWTPermission; 29 import java.awt.DisplayMode; 30 import java.awt.GraphicsConfiguration; 31 import java.awt.GraphicsDevice; 32 import java.awt.Insets; 33 import java.awt.Window; 34 import java.util.Objects; 35 36 import sun.java2d.opengl.CGLGraphicsConfig; 37 38 public final 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 * Returns CGDirectDisplayID, which is the same id as @"NSScreenNumber" in 63 * NSScreen. 64 * 65 * @return CoreGraphics display id. 66 */ 67 public int getCGDisplayID() { 68 return displayID; 69 } 70 71 /** 72 * Return a list of all configurations. 73 */ 74 @Override 75 public GraphicsConfiguration[] getConfigurations() { 76 return configs.clone(); 77 } 78 79 /** 80 * Return the default configuration. 81 */ 82 @Override 83 public GraphicsConfiguration getDefaultConfiguration() { 84 return configs[DEFAULT_CONFIG]; 85 } 86 87 /** 88 * Return a human-readable screen description. 89 */ 90 @Override 91 public String getIDstring() { 92 return "Display " + this.displayID; 93 } 94 95 /** 96 * Returns the type of the graphics device. 97 * @see #TYPE_RASTER_SCREEN 98 * @see #TYPE_PRINTER 99 * @see #TYPE_IMAGE_BUFFER 100 */ 101 @Override 102 public int getType() { 103 return TYPE_RASTER_SCREEN; 104 } 105 106 public double getXResolution() { 107 return nativeGetXResolution(displayID); 108 } 109 110 public double getYResolution() { 111 return nativeGetYResolution(displayID); 112 } 113 114 public Insets getScreenInsets() { 115 return nativeGetScreenInsets(displayID); 116 } 117 118 /** 119 * Enters full-screen mode, or returns to windowed mode. 120 */ 121 @Override 122 public synchronized void setFullScreenWindow(Window w) { 123 Window old = getFullScreenWindow(); 124 if (w == old) { 125 return; 126 } 127 128 boolean fsSupported = isFullScreenSupported(); 129 130 if (fsSupported && old != null) { 131 // restore original display mode and enter windowed mode. 132 if (originalMode != null) { 133 setDisplayMode(originalMode); 134 originalMode = null; 135 } 200 final Window w = getFullScreenWindow(); 201 if (w != null) { 202 exitFullScreenExclusive(w); 203 } 204 nativeSetDisplayMode(displayID, dm.getWidth(), dm.getHeight(), 205 dm.getBitDepth(), dm.getRefreshRate()); 206 if (isFullScreenSupported() && w != null) { 207 enterFullScreenExclusive(w); 208 } 209 } 210 } 211 212 @Override 213 public DisplayMode getDisplayMode() { 214 return nativeGetDisplayMode(displayID); 215 } 216 217 @Override 218 public DisplayMode[] getDisplayModes() { 219 return nativeGetDisplayModes(displayID); 220 } 221 222 public int getScaleFactor() { 223 return (int) nativeGetScaleFactor(displayID); 224 } 225 226 private static native double nativeGetScaleFactor(int displayID); 227 228 private static native void nativeSetDisplayMode(int displayID, int w, int h, int bpp, int refrate); 229 230 private static native DisplayMode nativeGetDisplayMode(int displayID); 231 232 private static native DisplayMode[] nativeGetDisplayModes(int displayID); 233 234 private static native double nativeGetXResolution(int displayID); 235 236 private static native double nativeGetYResolution(int displayID); 237 238 private static native Insets nativeGetScreenInsets(int displayID); 239 } | 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.awt; 27 28 import java.awt.AWTPermission; 29 import java.awt.DisplayMode; 30 import java.awt.GraphicsConfiguration; 31 import java.awt.GraphicsDevice; 32 import java.awt.Insets; 33 import java.awt.Window; 34 import java.util.Objects; 35 36 import sun.java2d.opengl.CGLGraphicsConfig; 37 38 public final class CGraphicsDevice extends GraphicsDevice 39 implements DisplayChangedListener { 40 41 /** 42 * CoreGraphics display ID. This identifier can become non-valid at any time 43 * therefore methods, which is using this id should be ready to it. 44 */ 45 private volatile int displayID; 46 private volatile Insets screenInsets; 47 private volatile double xResolution; 48 private volatile double yResolution; 49 private volatile int scale; 50 51 // Array of all GraphicsConfig instances for this device 52 private final GraphicsConfiguration[] configs; 53 54 // Default config (temporarily hard coded) 55 private final int DEFAULT_CONFIG = 0; 56 57 private static AWTPermission fullScreenExclusivePermission; 58 59 // Save/restore DisplayMode for the Full Screen mode 60 private DisplayMode originalMode; 61 62 public CGraphicsDevice(final int displayID) { 63 this.displayID = displayID; 64 configs = new GraphicsConfiguration[] { 65 CGLGraphicsConfig.getConfig(this, 0) 66 }; 67 } 68 69 /** 70 * Returns CGDirectDisplayID, which is the same id as @"NSScreenNumber" in 71 * NSScreen. 72 * 73 * @return CoreGraphics display id. 74 */ 75 public int getCGDisplayID() { 76 return displayID; 77 } 78 79 /** 80 * Return a list of all configurations. 81 */ 82 @Override 83 public GraphicsConfiguration[] getConfigurations() { 84 return configs.clone(); 85 } 86 87 /** 88 * Return the default configuration. 89 */ 90 @Override 91 public GraphicsConfiguration getDefaultConfiguration() { 92 return configs[DEFAULT_CONFIG]; 93 } 94 95 /** 96 * Return a human-readable screen description. 97 */ 98 @Override 99 public String getIDstring() { 100 return "Display " + displayID; 101 } 102 103 /** 104 * Returns the type of the graphics device. 105 * @see #TYPE_RASTER_SCREEN 106 * @see #TYPE_PRINTER 107 * @see #TYPE_IMAGE_BUFFER 108 */ 109 @Override 110 public int getType() { 111 return TYPE_RASTER_SCREEN; 112 } 113 114 public double getXResolution() { 115 return xResolution; 116 } 117 118 public double getYResolution() { 119 return yResolution; 120 } 121 122 public Insets getScreenInsets() { 123 return screenInsets; 124 } 125 126 public int getScaleFactor() { 127 return scale; 128 } 129 130 public void invalidate(final int defaultDisplayID) { 131 displayID = defaultDisplayID; 132 } 133 134 @Override 135 public void displayChanged() { 136 xResolution = nativeGetXResolution(displayID); 137 yResolution = nativeGetYResolution(displayID); 138 screenInsets = nativeGetScreenInsets(displayID); 139 scale = (int) nativeGetScaleFactor(displayID); 140 //TODO configs/fullscreenWindow/modes? 141 } 142 143 @Override 144 public void paletteChanged() { 145 // devices do not need to react to this event. 146 } 147 148 /** 149 * Enters full-screen mode, or returns to windowed mode. 150 */ 151 @Override 152 public synchronized void setFullScreenWindow(Window w) { 153 Window old = getFullScreenWindow(); 154 if (w == old) { 155 return; 156 } 157 158 boolean fsSupported = isFullScreenSupported(); 159 160 if (fsSupported && old != null) { 161 // restore original display mode and enter windowed mode. 162 if (originalMode != null) { 163 setDisplayMode(originalMode); 164 originalMode = null; 165 } 230 final Window w = getFullScreenWindow(); 231 if (w != null) { 232 exitFullScreenExclusive(w); 233 } 234 nativeSetDisplayMode(displayID, dm.getWidth(), dm.getHeight(), 235 dm.getBitDepth(), dm.getRefreshRate()); 236 if (isFullScreenSupported() && w != null) { 237 enterFullScreenExclusive(w); 238 } 239 } 240 } 241 242 @Override 243 public DisplayMode getDisplayMode() { 244 return nativeGetDisplayMode(displayID); 245 } 246 247 @Override 248 public DisplayMode[] getDisplayModes() { 249 return nativeGetDisplayModes(displayID); 250 } 251 252 private static native double nativeGetScaleFactor(int displayID); 253 254 private static native void nativeSetDisplayMode(int displayID, int w, int h, int bpp, int refrate); 255 256 private static native DisplayMode nativeGetDisplayMode(int displayID); 257 258 private static native DisplayMode[] nativeGetDisplayModes(int displayID); 259 260 private static native double nativeGetXResolution(int displayID); 261 262 private static native double nativeGetYResolution(int displayID); 263 264 private static native Insets nativeGetScreenInsets(int displayID); 265 } |