< prev index next >

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

Print this page




  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  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 double xResolution;
  47     private volatile double yResolution;
  48     private volatile int scale;
  49 
  50     // Array of all GraphicsConfig instances for this device
  51     private final GraphicsConfiguration[] configs;
  52 
  53     // Default config (temporarily hard coded)
  54     private final int DEFAULT_CONFIG = 0;
  55 


 123         // since there are no Quartz or Cocoa means to receive notifications
 124         // on insets changes (e.g. when the Dock is resized):
 125         // the existing CGDisplayReconfigurationCallBack is not notified
 126         // as well as the NSApplicationDidChangeScreenParametersNotification
 127         // is fired on the Dock location changes only
 128         return nativeGetScreenInsets(displayID);
 129     }
 130 
 131     public int getScaleFactor() {
 132         return scale;
 133     }
 134 
 135     public void invalidate(final int defaultDisplayID) {
 136         displayID = defaultDisplayID;
 137     }
 138 
 139     @Override
 140     public void displayChanged() {
 141         xResolution = nativeGetXResolution(displayID);
 142         yResolution = nativeGetYResolution(displayID);
 143         scale = (int) nativeGetScaleFactor(displayID);
 144         //TODO configs/fullscreenWindow/modes?
 145     }
 146 
 147     @Override
 148     public void paletteChanged() {
 149         // devices do not need to react to this event.
 150     }
 151 
 152     /**
 153      * Enters full-screen mode, or returns to windowed mode.
 154      */
 155     @Override
 156     public synchronized void setFullScreenWindow(Window w) {
 157         Window old = getFullScreenWindow();
 158         if (w == old) {
 159             return;
 160         }
 161 
 162         boolean fsSupported = isFullScreenSupported();
 163 


 232         }
 233         if (!Objects.equals(dm, getDisplayMode())) {
 234             nativeSetDisplayMode(displayID, dm.getWidth(), dm.getHeight(),
 235                     dm.getBitDepth(), dm.getRefreshRate());
 236             if (isFullScreenSupported() && getFullScreenWindow() != null) {
 237                 getFullScreenWindow().setSize(dm.getWidth(), dm.getHeight());
 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 }


  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  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 import sun.java2d.SunGraphicsEnvironment;
  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 double xResolution;
  47     private volatile double yResolution;
  48     private volatile int scale;
  49 
  50     // Array of all GraphicsConfig instances for this device
  51     private final GraphicsConfiguration[] configs;
  52 
  53     // Default config (temporarily hard coded)
  54     private final int DEFAULT_CONFIG = 0;
  55 


 123         // since there are no Quartz or Cocoa means to receive notifications
 124         // on insets changes (e.g. when the Dock is resized):
 125         // the existing CGDisplayReconfigurationCallBack is not notified
 126         // as well as the NSApplicationDidChangeScreenParametersNotification
 127         // is fired on the Dock location changes only
 128         return nativeGetScreenInsets(displayID);
 129     }
 130 
 131     public int getScaleFactor() {
 132         return scale;
 133     }
 134 
 135     public void invalidate(final int defaultDisplayID) {
 136         displayID = defaultDisplayID;
 137     }
 138 
 139     @Override
 140     public void displayChanged() {
 141         xResolution = nativeGetXResolution(displayID);
 142         yResolution = nativeGetYResolution(displayID);
 143         initScaleFactor();
 144         //TODO configs/fullscreenWindow/modes?
 145     }
 146 
 147     @Override
 148     public void paletteChanged() {
 149         // devices do not need to react to this event.
 150     }
 151 
 152     /**
 153      * Enters full-screen mode, or returns to windowed mode.
 154      */
 155     @Override
 156     public synchronized void setFullScreenWindow(Window w) {
 157         Window old = getFullScreenWindow();
 158         if (w == old) {
 159             return;
 160         }
 161 
 162         boolean fsSupported = isFullScreenSupported();
 163 


 232         }
 233         if (!Objects.equals(dm, getDisplayMode())) {
 234             nativeSetDisplayMode(displayID, dm.getWidth(), dm.getHeight(),
 235                     dm.getBitDepth(), dm.getRefreshRate());
 236             if (isFullScreenSupported() && getFullScreenWindow() != null) {
 237                 getFullScreenWindow().setSize(dm.getWidth(), dm.getHeight());
 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 void initScaleFactor() {
 253         if (SunGraphicsEnvironment.isUIScaleEnabled()) {
 254             double debugScale = SunGraphicsEnvironment.getDebugScale();
 255             scale = (int) (debugScale >= 1
 256                     ? Math.round(debugScale)
 257                     : nativeGetScaleFactor(displayID));
 258         } else {
 259             scale = 1;
 260         }
 261     }
 262 
 263     private static native double nativeGetScaleFactor(int displayID);
 264 
 265     private static native void nativeSetDisplayMode(int displayID, int w, int h, int bpp, int refrate);
 266 
 267     private static native DisplayMode nativeGetDisplayMode(int displayID);
 268 
 269     private static native DisplayMode[] nativeGetDisplayModes(int displayID);
 270 
 271     private static native double nativeGetXResolution(int displayID);
 272 
 273     private static native double nativeGetYResolution(int displayID);
 274 
 275     private static native Insets nativeGetScreenInsets(int displayID);
 276 }
< prev index next >