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.SunGraphicsEnvironment;
48 import sun.java2d.opengl.WGLGraphicsConfig;
49 import sun.java2d.windows.WindowsFlags;
50 import sun.security.action.GetPropertyAction;
51 import static sun.awt.Win32GraphicsEnvironment.debugScaleX;
52 import static sun.awt.Win32GraphicsEnvironment.debugScaleY;
53
54 /**
55 * This is an implementation of a GraphicsDevice object for a single
56 * Win32 screen.
57 *
58 * @see GraphicsEnvironment
59 * @see GraphicsConfiguration
60 */
61 public class Win32GraphicsDevice extends GraphicsDevice implements
62 DisplayChangedListener {
63 int screen;
64 ColorModel dynamicColorModel; // updated with dev changes
65 ColorModel colorModel; // static for device
66 protected GraphicsConfiguration[] configs;
67 protected GraphicsConfiguration defaultConfig;
68
69 private final String idString;
70 protected String descString;
71 // Note that we do not synchronize access to this variable - it doesn't
72 // really matter if a thread does an operation on graphics device which is
73 // about to become invalid (or already become) - we are prepared to deal
74 // with this on the native level.
75 private boolean valid;
76
77 // keep track of top-level windows on this display
78 private SunDisplayChanger topLevels = new SunDisplayChanger();
79 // REMIND: we may disable the use of pixel formats for some accelerated
80 // pipelines which are mutually exclusive with opengl, for which
81 // pixel formats were added in the first place
82 protected static boolean pfDisabled;
83 private static AWTPermission fullScreenExclusivePermission;
84 // the original display mode we had before entering the fullscreen
85 // mode
86 private DisplayMode defaultDisplayMode;
87 // activation/deactivation listener for the full-screen window
88 private WindowListener fsWindowListener;
89
90 private float scaleX;
91 private float scaleY;
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
106 private static native void initIDs();
107
108 native void initDevice(int screen);
109 native void initNativeScale(int screen);
110 native void setNativeScale(int screen, float scaleX, float scaleY);
111 native float getNativeScaleX(int screen);
112 native float getNativeScaleY(int screen);
113
114 public Win32GraphicsDevice(int screennum) {
115 this.screen = screennum;
116 // we cache the strings because we want toString() and getIDstring
117 // to reflect the original screen number (which may change if the
118 // device is removed)
119 idString = "\\Display"+screen;
120 // REMIND: may be should use class name?
121 descString = "Win32GraphicsDevice[screen=" + screen;
122 valid = true;
123
124 initDevice(screennum);
125 initScaleFactors();
126 }
127
128 /**
129 * Returns the type of the graphics device.
130 * @see #TYPE_RASTER_SCREEN
131 * @see #TYPE_PRINTER
132 * @see #TYPE_IMAGE_BUFFER
133 */
134 public int getType() {
135 return TYPE_RASTER_SCREEN;
136 }
137
138 /**
139 * Returns the Win32 screen of the device.
140 */
141 public int getScreen() {
142 return screen;
143 }
144
145 public float getDefaultScaleX() {
146 return scaleX;
147 }
148
149 public float getDefaultScaleY() {
150 return scaleY;
151 }
152
153 private void initScaleFactors() {
154 if (SunGraphicsEnvironment.isUIScaleEnabled()) {
155 if (debugScaleX > 0 && debugScaleY > 0) {
156 scaleX = debugScaleX;
157 scaleY = debugScaleY;
158 setNativeScale(screen, scaleX, scaleY);
159 } else {
160 initNativeScale(screen);
161 scaleX = getNativeScaleX(screen);
162 scaleY = getNativeScaleY(screen);
163 }
164 } else {
165 scaleX = 1;
166 scaleY = 1;
167 }
168 }
169
170 /**
171 * Returns whether this is a valid devicie. Device can become
172 * invalid as a result of device removal event.
173 */
174 public boolean isValid() {
175 return valid;
176 }
177
178 /**
179 * Called from native code when the device was removed.
180 *
181 * @param defaultScreen the current default screen
182 */
183 protected void invalidate(int defaultScreen) {
184 valid = false;
185 screen = defaultScreen;
186 }
187
188 /**
189 * Returns the identification string associated with this graphics
508 dm.getHeight() == mode.getHeight() &&
509 dm.getBitDepth() == mode.getBitDepth()))
510 {
511 return mode;
512 }
513 }
514 return null;
515 }
516
517 /*
518 * From the DisplayChangeListener interface.
519 * Called from Win32GraphicsEnvironment when the display settings have
520 * changed.
521 */
522 public void displayChanged() {
523 dynamicColorModel = null;
524 defaultConfig = null;
525 configs = null;
526 // pass on to all top-level windows on this display
527 topLevels.notifyListeners();
528 initScaleFactors();
529 }
530
531 /**
532 * Part of the DisplayChangedListener interface: devices
533 * do not need to react to this event
534 */
535 public void paletteChanged() {
536 }
537
538 /*
539 * Add a DisplayChangeListener to be notified when the display settings
540 * are changed. Typically, only top-level containers need to be added
541 * to Win32GraphicsDevice.
542 */
543 public void addDisplayChangedListener(DisplayChangedListener client) {
544 topLevels.add(client);
545 }
546
547 /*
548 * Remove a DisplayChangeListener from this Win32GraphicsDevice
|