13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
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.GraphicsConfiguration;
29 import java.awt.GraphicsDevice;
30 import java.awt.Window;
31 import java.awt.AWTPermission;
32 import java.awt.DisplayMode;
33
34 import sun.java2d.opengl.CGLGraphicsConfig;
35
36 public final class CGraphicsDevice extends GraphicsDevice {
37
38 // CoreGraphics display ID
39 private final int displayID;
40
41 // Array of all GraphicsConfig instances for this device
42 private final GraphicsConfiguration[] configs;
43
44 // Default config (temporarily hard coded)
45 private final int DEFAULT_CONFIG = 0;
46
47 private static AWTPermission fullScreenExclusivePermission;
48
49 // Save/restore DisplayMode for the Full Screen mode
50 private DisplayMode originalMode;
51
52 public CGraphicsDevice(int displayID) {
105 public double getYResolution() {
106 return nativeGetYResolution(displayID);
107 }
108
109 private static native double nativeGetXResolution(int displayID);
110 private static native double nativeGetYResolution(int displayID);
111
112 /**
113 * Enters full-screen mode, or returns to windowed mode.
114 */
115 @Override
116 public synchronized void setFullScreenWindow(Window w) {
117 Window old = getFullScreenWindow();
118 if (w == old) {
119 return;
120 }
121
122 boolean fsSupported = isFullScreenSupported();
123
124 if (fsSupported && old != null) {
125 // enter windowed mode (and restore original display mode)
126 exitFullScreenExclusive(old);
127 if (originalMode != null) {
128 setDisplayMode(originalMode);
129 originalMode = null;
130 }
131 }
132
133 super.setFullScreenWindow(w);
134
135 if (fsSupported && w != null) {
136 if (isDisplayChangeSupported()) {
137 originalMode = getDisplayMode();
138 }
139 // enter fullscreen mode
140 enterFullScreenExclusive(w);
141 }
142 }
143
144 /**
145 * Returns true if this GraphicsDevice supports
146 * full-screen exclusive mode and false otherwise.
147 */
148 @Override
149 public boolean isFullScreenSupported() {
150 return isFSExclusiveModeAllowed();
169 private static void enterFullScreenExclusive(Window w) {
170 FullScreenCapable peer = (FullScreenCapable)w.getPeer();
171 if (peer != null) {
172 peer.enterFullScreenMode();
173 }
174 }
175
176 private static void exitFullScreenExclusive(Window w) {
177 FullScreenCapable peer = (FullScreenCapable)w.getPeer();
178 if (peer != null) {
179 peer.exitFullScreenMode();
180 }
181 }
182
183 @Override
184 public boolean isDisplayChangeSupported() {
185 return true;
186 }
187
188 @Override
189 public void setDisplayMode(DisplayMode dm) {
190 if (dm == null) {
191 throw new IllegalArgumentException("Invalid display mode");
192 }
193 nativeSetDisplayMode(displayID, dm.getWidth(), dm.getHeight(), dm.getBitDepth(), dm.getRefreshRate());
194 if (isFullScreenSupported() && getFullScreenWindow() != null) {
195 getFullScreenWindow().setSize(dm.getWidth(), dm.getHeight());
196 }
197 }
198
199 @Override
200 public DisplayMode getDisplayMode() {
201 return nativeGetDisplayMode(displayID);
202 }
203
204 @Override
205 public DisplayMode[] getDisplayModes() {
206 return nativeGetDisplayModes(displayID);
207 }
208
209 private native void nativeSetDisplayMode(int displayID, int w, int h, int bpp, int refrate);
210
211 private native DisplayMode nativeGetDisplayMode(int displayID);
212
213 private native DisplayMode[] nativeGetDisplayModes(int displayID);
214 }
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
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.GraphicsConfiguration;
29 import java.awt.GraphicsDevice;
30 import java.awt.Window;
31 import java.awt.AWTPermission;
32 import java.awt.DisplayMode;
33 import java.util.Objects;
34
35 import sun.java2d.opengl.CGLGraphicsConfig;
36
37 public final class CGraphicsDevice extends GraphicsDevice {
38
39 // CoreGraphics display ID
40 private final int displayID;
41
42 // Array of all GraphicsConfig instances for this device
43 private final GraphicsConfiguration[] configs;
44
45 // Default config (temporarily hard coded)
46 private final int DEFAULT_CONFIG = 0;
47
48 private static AWTPermission fullScreenExclusivePermission;
49
50 // Save/restore DisplayMode for the Full Screen mode
51 private DisplayMode originalMode;
52
53 public CGraphicsDevice(int displayID) {
106 public double getYResolution() {
107 return nativeGetYResolution(displayID);
108 }
109
110 private static native double nativeGetXResolution(int displayID);
111 private static native double nativeGetYResolution(int displayID);
112
113 /**
114 * Enters full-screen mode, or returns to windowed mode.
115 */
116 @Override
117 public synchronized void setFullScreenWindow(Window w) {
118 Window old = getFullScreenWindow();
119 if (w == old) {
120 return;
121 }
122
123 boolean fsSupported = isFullScreenSupported();
124
125 if (fsSupported && old != null) {
126 // restore original display mode and enter windowed mode.
127 if (originalMode != null) {
128 setDisplayMode(originalMode);
129 originalMode = null;
130 }
131 exitFullScreenExclusive(old);
132 }
133
134 super.setFullScreenWindow(w);
135
136 if (fsSupported && w != null) {
137 if (isDisplayChangeSupported()) {
138 originalMode = getDisplayMode();
139 }
140 // enter fullscreen mode
141 enterFullScreenExclusive(w);
142 }
143 }
144
145 /**
146 * Returns true if this GraphicsDevice supports
147 * full-screen exclusive mode and false otherwise.
148 */
149 @Override
150 public boolean isFullScreenSupported() {
151 return isFSExclusiveModeAllowed();
170 private static void enterFullScreenExclusive(Window w) {
171 FullScreenCapable peer = (FullScreenCapable)w.getPeer();
172 if (peer != null) {
173 peer.enterFullScreenMode();
174 }
175 }
176
177 private static void exitFullScreenExclusive(Window w) {
178 FullScreenCapable peer = (FullScreenCapable)w.getPeer();
179 if (peer != null) {
180 peer.exitFullScreenMode();
181 }
182 }
183
184 @Override
185 public boolean isDisplayChangeSupported() {
186 return true;
187 }
188
189 @Override
190 public void setDisplayMode(final DisplayMode dm) {
191 if (dm == null) {
192 throw new IllegalArgumentException("Invalid display mode");
193 }
194 if (!Objects.equals(dm, getDisplayMode())) {
195 final Window w = getFullScreenWindow();
196 if (w != null) {
197 exitFullScreenExclusive(w);
198 }
199 nativeSetDisplayMode(displayID, dm.getWidth(), dm.getHeight(),
200 dm.getBitDepth(), dm.getRefreshRate());
201 if (isFullScreenSupported() && w != null) {
202 enterFullScreenExclusive(w);
203 }
204 }
205 }
206
207 @Override
208 public DisplayMode getDisplayMode() {
209 return nativeGetDisplayMode(displayID);
210 }
211
212 @Override
213 public DisplayMode[] getDisplayModes() {
214 return nativeGetDisplayModes(displayID);
215 }
216
217 private native void nativeSetDisplayMode(int displayID, int w, int h, int bpp, int refrate);
218
219 private native DisplayMode nativeGetDisplayMode(int displayID);
220
221 private native DisplayMode[] nativeGetDisplayModes(int displayID);
222 }
|