equal
deleted
inserted
replaced
31 import java.awt.GraphicsDevice; |
31 import java.awt.GraphicsDevice; |
32 import java.awt.Insets; |
32 import java.awt.Insets; |
33 import java.awt.Rectangle; |
33 import java.awt.Rectangle; |
34 import java.awt.Window; |
34 import java.awt.Window; |
35 import java.awt.geom.Rectangle2D; |
35 import java.awt.geom.Rectangle2D; |
|
36 import java.awt.peer.WindowPeer; |
36 import java.util.Objects; |
37 import java.util.Objects; |
37 |
38 |
38 import sun.java2d.SunGraphicsEnvironment; |
39 import sun.java2d.SunGraphicsEnvironment; |
39 import sun.java2d.opengl.CGLGraphicsConfig; |
40 import sun.java2d.opengl.CGLGraphicsConfig; |
|
41 |
|
42 import static java.awt.peer.ComponentPeer.SET_BOUNDS; |
40 |
43 |
41 public final class CGraphicsDevice extends GraphicsDevice |
44 public final class CGraphicsDevice extends GraphicsDevice |
42 implements DisplayChangedListener { |
45 implements DisplayChangedListener { |
43 |
46 |
44 /** |
47 /** |
127 public int getScaleFactor() { |
130 public int getScaleFactor() { |
128 return scale; |
131 return scale; |
129 } |
132 } |
130 |
133 |
131 public void invalidate(final int defaultDisplayID) { |
134 public void invalidate(final int defaultDisplayID) { |
|
135 //TODO do we need to restore the full-screen window/modes on old device? |
132 displayID = defaultDisplayID; |
136 displayID = defaultDisplayID; |
133 } |
137 } |
134 |
138 |
135 @Override |
139 @Override |
136 public void displayChanged() { |
140 public void displayChanged() { |
137 xResolution = nativeGetXResolution(displayID); |
141 xResolution = nativeGetXResolution(displayID); |
138 yResolution = nativeGetYResolution(displayID); |
142 yResolution = nativeGetYResolution(displayID); |
139 bounds = nativeGetBounds(displayID).getBounds(); //does integer rounding |
143 bounds = nativeGetBounds(displayID).getBounds(); //does integer rounding |
140 initScaleFactor(); |
144 initScaleFactor(); |
141 //TODO configs/fullscreenWindow/modes? |
145 resizeFSWindow(getFullScreenWindow(), bounds); |
|
146 //TODO configs? |
142 } |
147 } |
143 |
148 |
144 @Override |
149 @Override |
145 public void paletteChanged() { |
150 public void paletteChanged() { |
146 // devices do not need to react to this event. |
151 // devices do not need to react to this event. |
215 if (peer != null) { |
220 if (peer != null) { |
216 peer.exitFullScreenMode(); |
221 peer.exitFullScreenMode(); |
217 } |
222 } |
218 } |
223 } |
219 |
224 |
|
225 /** |
|
226 * Reapplies the size of this device to the full-screen window. |
|
227 */ |
|
228 private static void resizeFSWindow(final Window w, final Rectangle b) { |
|
229 if (w != null) { |
|
230 WindowPeer peer = AWTAccessor.getComponentAccessor().getPeer(w); |
|
231 if (peer != null) { |
|
232 peer.setBounds(b.x, b.y, b.width, b.height, SET_BOUNDS); |
|
233 } |
|
234 } |
|
235 } |
|
236 |
220 @Override |
237 @Override |
221 public boolean isDisplayChangeSupported() { |
238 public boolean isDisplayChangeSupported() { |
222 return true; |
239 return true; |
223 } |
240 } |
224 |
241 |
227 if (dm == null) { |
244 if (dm == null) { |
228 throw new IllegalArgumentException("Invalid display mode"); |
245 throw new IllegalArgumentException("Invalid display mode"); |
229 } |
246 } |
230 if (!Objects.equals(dm, getDisplayMode())) { |
247 if (!Objects.equals(dm, getDisplayMode())) { |
231 nativeSetDisplayMode(displayID, dm.getWidth(), dm.getHeight(), |
248 nativeSetDisplayMode(displayID, dm.getWidth(), dm.getHeight(), |
232 dm.getBitDepth(), dm.getRefreshRate()); |
249 dm.getBitDepth(), dm.getRefreshRate()); |
233 if (isFullScreenSupported() && getFullScreenWindow() != null) { |
|
234 getFullScreenWindow().setSize(dm.getWidth(), dm.getHeight()); |
|
235 } |
|
236 } |
250 } |
237 } |
251 } |
238 |
252 |
239 @Override |
253 @Override |
240 public DisplayMode getDisplayMode() { |
254 public DisplayMode getDisplayMode() { |