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 float scaleX = 1.0f;
88 private float scaleY = 1.0f;
89
90 static {
91
92 // 4455041 - Even when ddraw is disabled, ddraw.dll is loaded when
93 // pixel format calls are made. This causes problems when a Java app
94 // is run as an NT service. To prevent the loading of ddraw.dll
95 // completely, sun.awt.nopixfmt should be set as well. Apps which use
96 // OpenGL w/ Java probably don't want to set this.
97 String nopixfmt = java.security.AccessController.doPrivileged(
98 new sun.security.action.GetPropertyAction("sun.awt.nopixfmt"));
99 pfDisabled = (nopixfmt != null);
100 initIDs();
101 }
102
103 private static native void initIDs();
104
105 native void initDevice(int screen);
106 native void initNativeScale(int screen);
107 native void setNativeScale(int screen, float scaleX, float scaleY);
108 native float getNativeScaleX(int screen);
109 native float getNativeScaleY(int screen);
110
111 public Win32GraphicsDevice(int screennum) {
112 this.screen = screennum;
113 // we cache the strings because we want toString() and getIDstring
114 // to reflect the original screen number (which may change if the
115 // device is removed)
116 idString = "\\Display"+screen;
117 // REMIND: may be should use class name?
118 descString = "Win32GraphicsDevice[screen=" + screen;
119 valid = true;
120
121 initDevice(screennum);
122 initScaleFactors();
123 }
124
125 /**
126 * Returns the type of the graphics device.
127 * @see #TYPE_RASTER_SCREEN
128 * @see #TYPE_PRINTER
129 * @see #TYPE_IMAGE_BUFFER
130 */
131 public int getType() {
132 return TYPE_RASTER_SCREEN;
133 }
134
135 /**
136 * Returns the Win32 screen of the device.
137 */
138 public int getScreen() {
139 return screen;
140 }
141
142 public float getDefaultScaleX() {
143 return scaleX;
144 }
145
146 public float getDefaultScaleY() {
147 return scaleY;
148 }
149
150 private void initScaleFactors() {
151 boolean dpiEnabled = "true".equals(AccessController.doPrivileged(
152 new GetPropertyAction("sun.java2d.uiScale.enabled", "true")));
153
154 if (!dpiEnabled) {
155 return;
156 }
157
158 scaleX = getScaleFactor("sun.java2d.win.uiScaleX");
159 scaleY = getScaleFactor("sun.java2d.win.uiScaleY");
160
161 if (scaleX > 0 && scaleY > 0) {
162 setNativeScale(screen, scaleX, scaleY);
163 return;
164 }
165
166 float scale = getScaleFactor("sun.java2d.win.uiScale");
167
168 if (scale > 0) {
169 scaleX = scale;
170 scaleY = scale;
171 setNativeScale(screen, scaleX, scaleY);
172 return;
173 }
174
175 initNativeScale(screen);
176 scaleX = getNativeScaleX(screen);
177 scaleY = getNativeScaleY(screen);
178 }
179
180 private static float getScaleFactor(String name) {
181
182 String scaleFactor = AccessController.doPrivileged(
183 new GetPropertyAction(name, "-1"));
184
185 if (scaleFactor == null || scaleFactor.equals("-1")) {
186 return -1;
187 }
188 try {
189
190 if (scaleFactor.endsWith("dpi")) {
191 scaleFactor = scaleFactor.substring(0, scaleFactor.length() - 3);
192 float scale = Float.parseFloat(scaleFactor);
193 return scale <= 0 ? -1 : scale / 96;
194 }
195
196 if (scaleFactor.endsWith("%")) {
197 scaleFactor = scaleFactor.substring(0, scaleFactor.length() - 1);
198 float scale = Float.parseFloat(scaleFactor);
199 return scale <= 0 ? -1 : scale / 100;
200 }
201
202 float scale = Float.parseFloat(scaleFactor);
203 return (scale <=0) ? -1 : scale;
204
205 } catch (NumberFormatException ignore) {
206 }
207 return -1;
208 }
209
210 /**
211 * Returns whether this is a valid devicie. Device can become
212 * invalid as a result of device removal event.
213 */
214 public boolean isValid() {
215 return valid;
216 }
217
218 /**
219 * Called from native code when the device was removed.
220 *
221 * @param defaultScreen the current default screen
222 */
223 protected void invalidate(int defaultScreen) {
224 valid = false;
225 screen = defaultScreen;
226 }
227
228 /**
229 * Returns the identification string associated with this graphics
548 dm.getHeight() == mode.getHeight() &&
549 dm.getBitDepth() == mode.getBitDepth()))
550 {
551 return mode;
552 }
553 }
554 return null;
555 }
556
557 /*
558 * From the DisplayChangeListener interface.
559 * Called from Win32GraphicsEnvironment when the display settings have
560 * changed.
561 */
562 public void displayChanged() {
563 dynamicColorModel = null;
564 defaultConfig = null;
565 configs = null;
566 // pass on to all top-level windows on this display
567 topLevels.notifyListeners();
568 initScaleFactors();
569 }
570
571 /**
572 * Part of the DisplayChangedListener interface: devices
573 * do not need to react to this event
574 */
575 public void paletteChanged() {
576 }
577
578 /*
579 * Add a DisplayChangeListener to be notified when the display settings
580 * are changed. Typically, only top-level containers need to be added
581 * to Win32GraphicsDevice.
582 */
583 public void addDisplayChangedListener(DisplayChangedListener client) {
584 topLevels.add(client);
585 }
586
587 /*
588 * Remove a DisplayChangeListener from this Win32GraphicsDevice
|