< prev index next >

src/java.desktop/windows/classes/sun/awt/Win32GraphicsDevice.java

Print this page




  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.GraphicsDevice;
  30 import java.awt.GraphicsConfiguration;
  31 import java.awt.GraphicsEnvironment;
  32 import java.awt.DisplayMode;
  33 import java.awt.EventQueue;
  34 import java.awt.Frame;
  35 import java.awt.Rectangle;
  36 import java.awt.Window;
  37 import java.awt.event.WindowAdapter;
  38 import java.awt.event.WindowEvent;
  39 import java.awt.event.WindowListener;

  40 import java.awt.image.ColorModel;
  41 import java.util.ArrayList;
  42 import java.util.Vector;
  43 import java.awt.peer.WindowPeer;

  44 import sun.awt.windows.WWindowPeer;
  45 import sun.java2d.opengl.WGLGraphicsConfig;
  46 import sun.java2d.windows.WindowsFlags;

  47 
  48 /**
  49  * This is an implementation of a GraphicsDevice object for a single
  50  * Win32 screen.
  51  *
  52  * @see GraphicsEnvironment
  53  * @see GraphicsConfiguration
  54  */
  55 public class Win32GraphicsDevice extends GraphicsDevice implements
  56  DisplayChangedListener {
  57     int screen;
  58     ColorModel dynamicColorModel;   // updated with dev changes
  59     ColorModel colorModel;          // static for device
  60     protected GraphicsConfiguration[] configs;
  61     protected GraphicsConfiguration defaultConfig;
  62 
  63     private final String idString;
  64     protected String descString;
  65     // Note that we do not synchronize access to this variable - it doesn't
  66     // really matter if a thread does an operation on graphics device which is
  67     // about to become invalid (or already become) - we are prepared to deal
  68     // with this on the native level.
  69     private boolean valid;
  70 
  71     // keep track of top-level windows on this display
  72     private SunDisplayChanger topLevels = new SunDisplayChanger();
  73     // REMIND: we may disable the use of pixel formats for some accelerated
  74     // pipelines which are mutually exclusive with opengl, for which
  75     // pixel formats were added in the first place
  76     protected static boolean pfDisabled;
  77     private static AWTPermission fullScreenExclusivePermission;
  78     // the original display mode we had before entering the fullscreen
  79     // mode
  80     private DisplayMode defaultDisplayMode;
  81     // activation/deactivation listener for the full-screen window
  82     private WindowListener fsWindowListener;
  83 






  84     static {
  85 
  86         // 4455041 - Even when ddraw is disabled, ddraw.dll is loaded when
  87         // pixel format calls are made.  This causes problems when a Java app
  88         // is run as an NT service.  To prevent the loading of ddraw.dll
  89         // completely, sun.awt.nopixfmt should be set as well.  Apps which use
  90         // OpenGL w/ Java probably don't want to set this.
  91         String nopixfmt = java.security.AccessController.doPrivileged(
  92             new sun.security.action.GetPropertyAction("sun.awt.nopixfmt"));
  93         pfDisabled = (nopixfmt != null);
  94         initIDs();



















  95     }
  96 
  97     private static native void initIDs();
  98 
  99     native void initDevice(int screen);




 100 
 101     public Win32GraphicsDevice(int screennum) {
 102         this.screen = screennum;
 103         // we cache the strings because we want toString() and getIDstring
 104         // to reflect the original screen number (which may change if the
 105         // device is removed)
 106         idString = "\\Display"+screen;
 107         // REMIND: may be should use class name?
 108         descString = "Win32GraphicsDevice[screen=" + screen;
 109         valid = true;
 110 
 111         initDevice(screennum);

 112     }
 113 
 114     /**
 115      * Returns the type of the graphics device.
 116      * @see #TYPE_RASTER_SCREEN
 117      * @see #TYPE_PRINTER
 118      * @see #TYPE_IMAGE_BUFFER
 119      */
 120     public int getType() {
 121         return TYPE_RASTER_SCREEN;
 122     }
 123 
 124     /**
 125      * Returns the Win32 screen of the device.
 126      */
 127     public int getScreen() {
 128         return screen;
 129     }
 130 




















































 131     /**
 132      * Returns whether this is a valid devicie. Device can become
 133      * invalid as a result of device removal event.
 134      */
 135     public boolean isValid() {
 136         return valid;
 137     }
 138 
 139     /**
 140      * Called from native code when the device was removed.
 141      *
 142      * @param defaultScreen the current default screen
 143      */
 144     protected void invalidate(int defaultScreen) {
 145         valid = false;
 146         screen = defaultScreen;
 147     }
 148 
 149     /**
 150      * Returns the identification string associated with this graphics


 469                  dm.getHeight() == mode.getHeight() &&
 470                  dm.getBitDepth() == mode.getBitDepth()))
 471             {
 472                 return mode;
 473             }
 474         }
 475         return null;
 476     }
 477 
 478     /*
 479      * From the DisplayChangeListener interface.
 480      * Called from Win32GraphicsEnvironment when the display settings have
 481      * changed.
 482      */
 483     public void displayChanged() {
 484         dynamicColorModel = null;
 485         defaultConfig = null;
 486         configs = null;
 487         // pass on to all top-level windows on this display
 488         topLevels.notifyListeners();

 489     }
 490 
 491     /**
 492      * Part of the DisplayChangedListener interface: devices
 493      * do not need to react to this event
 494      */
 495     public void paletteChanged() {
 496     }
 497 
 498     /*
 499      * Add a DisplayChangeListener to be notified when the display settings
 500      * are changed.  Typically, only top-level containers need to be added
 501      * to Win32GraphicsDevice.
 502      */
 503     public void addDisplayChangedListener(DisplayChangedListener client) {
 504         topLevels.add(client);
 505     }
 506 
 507     /*
 508      * Remove a DisplayChangeListener from this Win32GraphicsDevice




  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.GraphicsDevice;
  30 import java.awt.GraphicsConfiguration;
  31 import java.awt.GraphicsEnvironment;
  32 import java.awt.DisplayMode;
  33 import java.awt.EventQueue;
  34 import java.awt.Frame;
  35 import java.awt.Rectangle;
  36 import java.awt.Window;
  37 import java.awt.event.WindowAdapter;
  38 import java.awt.event.WindowEvent;
  39 import java.awt.event.WindowListener;
  40 import java.awt.geom.Point2D;
  41 import java.awt.image.ColorModel;
  42 import java.util.ArrayList;
  43 import java.util.Vector;
  44 import java.awt.peer.WindowPeer;
  45 import java.security.AccessController;
  46 import sun.awt.windows.WWindowPeer;
  47 import sun.java2d.opengl.WGLGraphicsConfig;
  48 import sun.java2d.windows.WindowsFlags;
  49 import sun.security.action.GetPropertyAction;
  50 
  51 /**
  52  * This is an implementation of a GraphicsDevice object for a single
  53  * Win32 screen.
  54  *
  55  * @see GraphicsEnvironment
  56  * @see GraphicsConfiguration
  57  */
  58 public class Win32GraphicsDevice extends GraphicsDevice implements
  59  DisplayChangedListener {
  60     int screen;
  61     ColorModel dynamicColorModel;   // updated with dev changes
  62     ColorModel colorModel;          // static for device
  63     protected GraphicsConfiguration[] configs;
  64     protected GraphicsConfiguration defaultConfig;
  65 
  66     private final String idString;
  67     protected String descString;
  68     // Note that we do not synchronize access to this variable - it doesn't
  69     // really matter if a thread does an operation on graphics device which is
  70     // about to become invalid (or already become) - we are prepared to deal
  71     // with this on the native level.
  72     private boolean valid;
  73 
  74     // keep track of top-level windows on this display
  75     private SunDisplayChanger topLevels = new SunDisplayChanger();
  76     // REMIND: we may disable the use of pixel formats for some accelerated
  77     // pipelines which are mutually exclusive with opengl, for which
  78     // pixel formats were added in the first place
  79     protected static boolean pfDisabled;
  80     private static AWTPermission fullScreenExclusivePermission;
  81     // the original display mode we had before entering the fullscreen
  82     // mode
  83     private DisplayMode defaultDisplayMode;
  84     // activation/deactivation listener for the full-screen window
  85     private WindowListener fsWindowListener;
  86 
  87     private static final boolean uiScaleEnabled;
  88     private static final float propsScaleX;
  89     private static final float propsScaleY;
  90     private float scaleX = 1.0f;
  91     private float scaleY = 1.0f;
  92 
  93     static {
  94 
  95         // 4455041 - Even when ddraw is disabled, ddraw.dll is loaded when
  96         // pixel format calls are made.  This causes problems when a Java app
  97         // is run as an NT service.  To prevent the loading of ddraw.dll
  98         // completely, sun.awt.nopixfmt should be set as well.  Apps which use
  99         // OpenGL w/ Java probably don't want to set this.
 100         String nopixfmt = java.security.AccessController.doPrivileged(
 101             new sun.security.action.GetPropertyAction("sun.awt.nopixfmt"));
 102         pfDisabled = (nopixfmt != null);
 103         initIDs();
 104 
 105         uiScaleEnabled = "true".equals(AccessController.doPrivileged(
 106                 new GetPropertyAction("sun.java2d.uiScale.enabled", "true")));
 107 
 108         if (uiScaleEnabled) {
 109             float sx = getScaleFactor("sun.java2d.win.uiScaleX");
 110             float sy = getScaleFactor("sun.java2d.win.uiScaleY");
 111             if (sx > 0 && sy > 0) {
 112                 propsScaleX = sx;
 113                 propsScaleY = sy;
 114             } else {
 115                 float scale = getScaleFactor("sun.java2d.uiScale");
 116                 propsScaleX = scale;
 117                 propsScaleY = scale;
 118             }
 119         } else {
 120             propsScaleX = -1;
 121             propsScaleY = -1;
 122         }
 123     }
 124 
 125     private static native void initIDs();
 126 
 127     native void initDevice(int screen);
 128     native void initNativeScale(int screen);
 129     native void setNativeScale(int screen, float scaleX, float scaleY);
 130     native float getNativeScaleX(int screen);
 131     native float getNativeScaleY(int screen);
 132 
 133     public Win32GraphicsDevice(int screennum) {
 134         this.screen = screennum;
 135         // we cache the strings because we want toString() and getIDstring
 136         // to reflect the original screen number (which may change if the
 137         // device is removed)
 138         idString = "\\Display"+screen;
 139         // REMIND: may be should use class name?
 140         descString = "Win32GraphicsDevice[screen=" + screen;
 141         valid = true;
 142 
 143         initDevice(screennum);
 144         initScaleFactors();
 145     }
 146 
 147     /**
 148      * Returns the type of the graphics device.
 149      * @see #TYPE_RASTER_SCREEN
 150      * @see #TYPE_PRINTER
 151      * @see #TYPE_IMAGE_BUFFER
 152      */
 153     public int getType() {
 154         return TYPE_RASTER_SCREEN;
 155     }
 156 
 157     /**
 158      * Returns the Win32 screen of the device.
 159      */
 160     public int getScreen() {
 161         return screen;
 162     }
 163 
 164     public float getDefaultScaleX() {
 165         return scaleX;
 166     }
 167 
 168     public float getDefaultScaleY() {
 169         return scaleY;
 170     }
 171 
 172     private void initScaleFactors() {
 173         if (uiScaleEnabled) {
 174             if (propsScaleX > 0 && propsScaleY > 0) {
 175                 scaleX = propsScaleX;
 176                 scaleY = propsScaleY;
 177                 setNativeScale(screen, scaleX, scaleY);
 178             } else {
 179                 initNativeScale(screen);
 180                 scaleX = getNativeScaleX(screen);
 181                 scaleY = getNativeScaleY(screen);
 182             }
 183         }
 184     }
 185 
 186     private static float getScaleFactor(String name) {
 187 
 188         String scaleFactor = AccessController.doPrivileged(
 189                 new GetPropertyAction(name, "-1"));
 190 
 191         if (scaleFactor == null || scaleFactor.equals("-1")) {
 192             return -1;
 193         }
 194         try {
 195 
 196             if (scaleFactor.endsWith("dpi")) {
 197                 scaleFactor = scaleFactor.substring(0, scaleFactor.length() - 3);
 198                 float scale = Float.parseFloat(scaleFactor);
 199                 return scale <= 0 ? -1 : scale / 96;
 200             }
 201 
 202             if (scaleFactor.endsWith("%")) {
 203                 scaleFactor = scaleFactor.substring(0, scaleFactor.length() - 1);
 204                 float scale = Float.parseFloat(scaleFactor);
 205                 return scale <= 0 ? -1 : scale / 100;
 206             }
 207 
 208             float scale = Float.parseFloat(scaleFactor);
 209             return (scale <=0) ? -1 : scale;
 210 
 211         } catch (NumberFormatException ignore) {
 212         }
 213         return -1;
 214     }
 215 
 216     /**
 217      * Returns whether this is a valid devicie. Device can become
 218      * invalid as a result of device removal event.
 219      */
 220     public boolean isValid() {
 221         return valid;
 222     }
 223 
 224     /**
 225      * Called from native code when the device was removed.
 226      *
 227      * @param defaultScreen the current default screen
 228      */
 229     protected void invalidate(int defaultScreen) {
 230         valid = false;
 231         screen = defaultScreen;
 232     }
 233 
 234     /**
 235      * Returns the identification string associated with this graphics


 554                  dm.getHeight() == mode.getHeight() &&
 555                  dm.getBitDepth() == mode.getBitDepth()))
 556             {
 557                 return mode;
 558             }
 559         }
 560         return null;
 561     }
 562 
 563     /*
 564      * From the DisplayChangeListener interface.
 565      * Called from Win32GraphicsEnvironment when the display settings have
 566      * changed.
 567      */
 568     public void displayChanged() {
 569         dynamicColorModel = null;
 570         defaultConfig = null;
 571         configs = null;
 572         // pass on to all top-level windows on this display
 573         topLevels.notifyListeners();
 574         initScaleFactors();
 575     }
 576 
 577     /**
 578      * Part of the DisplayChangedListener interface: devices
 579      * do not need to react to this event
 580      */
 581     public void paletteChanged() {
 582     }
 583 
 584     /*
 585      * Add a DisplayChangeListener to be notified when the display settings
 586      * are changed.  Typically, only top-level containers need to be added
 587      * to Win32GraphicsDevice.
 588      */
 589     public void addDisplayChangedListener(DisplayChangedListener client) {
 590         topLevels.add(client);
 591     }
 592 
 593     /*
 594      * Remove a DisplayChangeListener from this Win32GraphicsDevice


< prev index next >