int getScreenRefreshRate() { int rate = 60; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); for (int i = 0; i < gs.length; i++) { DisplayMode dm = gs[i].getDisplayMode(); // Get refresh rate in Hz int refreshRate = dm.getRefreshRate(); if (refreshRate == DisplayMode.REFRESH_RATE_UNKNOWN) { // log.warning("MotionViewer.getScreenRefreshRate: got unknown refresh rate for screen "+i+", assuming 60"); refreshRate = 60; } else { // log.info("MotionViewer.getScreenRefreshRate: screen "+i+" has refresh rate "+refreshRate); } if (i == 0) { rate = refreshRate; } } return rate; }
int getScreenRefreshRate() { int rate = 60; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); if (ge == null) { return rate; } GraphicsDevice[] gs = ge.getScreenDevices(); for (int i = 0; i < gs.length; i++) { DisplayMode dm = gs[i].getDisplayMode(); // Get refresh rate in Hz if (dm == null) { return rate; } int refreshRate = dm.getRefreshRate(); if (refreshRate == DisplayMode.REFRESH_RATE_UNKNOWN) { log.warning("AEViewer.getScreenRefreshRate: got unknown refresh rate for screen " + i + ", assuming 60"); refreshRate = 60; } else { // log.info("AEViewer.getScreenRefreshRate: screen "+i+" has refresh rate "+refreshRate); } if (i == 0) { rate = refreshRate; } } return rate; }
@Override protected DisplayMode getCurrentDisplayMode(final int screen) { D3DRenderQueue rq = D3DRenderQueue.getInstance(); rq.lock(); try { class Result { DisplayMode dm = null; }; final Result res = new Result(); rq.flushAndInvokeNow(new Runnable() { public void run() { res.dm = getCurrentDisplayModeNative(screen); } }); if (res.dm == null) { return super.getCurrentDisplayMode(screen); } return res.dm; } finally { rq.unlock(); } }
@Override public synchronized void setDisplayMode(DisplayMode dm) { if (!isDisplayChangeSupported()) { super.setDisplayMode(dm); return; } if (dm == null || (dm = getMatchingDisplayMode(dm)) == null) { throw new IllegalArgumentException("Invalid display mode"); } if (getDisplayMode().equals(dm)) { return; } Window w = getFullScreenWindow(); if (w != null) { WWindowPeer peer = (WWindowPeer)w.getPeer(); configDisplayMode(screen, peer, dm.getWidth(), dm.getHeight(), dm.getBitDepth(), dm.getRefreshRate()); // resize the fullscreen window to the dimensions of the new // display mode Rectangle screenBounds = getDefaultConfiguration().getBounds(); w.setBounds(screenBounds.x, screenBounds.y, dm.getWidth(), dm.getHeight()); // Note: no call to replaceSurfaceData is required here since // replacement will be caused by an upcoming display change event } else { throw new IllegalStateException("Must be in fullscreen mode " + "in order to set display mode"); } }
protected synchronized DisplayMode getMatchingDisplayMode(DisplayMode dm) { if (!isDisplayChangeSupported()) { return null; } DisplayMode[] modes = getDisplayModes(); for (DisplayMode mode : modes) { if (dm.equals(mode) || (dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN && dm.getWidth() == mode.getWidth() && dm.getHeight() == mode.getHeight() && dm.getBitDepth() == mode.getBitDepth())) { return mode; } } return null; }
private synchronized DisplayMode getMatchingDisplayMode(DisplayMode dm) { if (!isDisplayChangeSupported()) { return null; } DisplayMode[] modes = getDisplayModes(); for (DisplayMode mode : modes) { if (dm.equals(mode) || (dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN && dm.getWidth() == mode.getWidth() && dm.getHeight() == mode.getHeight() && dm.getBitDepth() == mode.getBitDepth())) { return mode; } } return null; }
public static void main(String[] args) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice graphicDevice = ge.getDefaultScreenDevice(); if (!graphicDevice.isDisplayChangeSupported()) { System.err.println("Display mode change is not supported on this host. Test is considered passed."); return; } DisplayMode defaultDisplayMode = graphicDevice.getDisplayMode(); checkDisplayMode(defaultDisplayMode); graphicDevice.setDisplayMode(defaultDisplayMode); DisplayMode[] displayModes = graphicDevice.getDisplayModes(); boolean isDefaultDisplayModeIncluded = false; for (DisplayMode displayMode : displayModes) { checkDisplayMode(displayMode); graphicDevice.setDisplayMode(displayMode); if (defaultDisplayMode.equals(displayMode)) { isDefaultDisplayModeIncluded = true; } } if (!isDefaultDisplayModeIncluded) { throw new RuntimeException("Default display mode is not included"); } }
/** * Finds a display mode that is different from the current display * mode and is likely to cause a display change event. */ private static DisplayMode findDisplayMode(GraphicsDevice gd) { DisplayMode dms[] = gd.getDisplayModes(); DisplayMode currentDM = gd.getDisplayMode(); for (DisplayMode dm : dms) { if (!dm.equals(currentDM) && dm.getRefreshRate() == currentDM.getRefreshRate()) { // different from the current dm and refresh rate is the same // means that something else is different => more likely to // cause a DM change event return dm; } } return null; }
private static void testWindowBounds(final DisplayMode dm, final Window w) { if (w.getWidth() != dm.getWidth() || w.getHeight() != dm.getHeight()) { System.err.println(" Wrong window bounds:" + " Expected: width = " + dm.getWidth() + ", height = " + dm.getHeight() + " Actual: " + w.getSize()); passed = false; } }
@Override protected void enumDisplayModes(final int screen, final ArrayList<DisplayMode> modes) { D3DRenderQueue rq = D3DRenderQueue.getInstance(); rq.lock(); try { rq.flushAndInvokeNow(new Runnable() { public void run() { enumDisplayModesNative(screen, modes); } }); if (modes.size() == 0) { modes.add(getCurrentDisplayModeNative(screen)); } } finally { rq.unlock(); } }
@Override public synchronized void setDisplayMode(DisplayMode dm) { if (!isDisplayChangeSupported()) { super.setDisplayMode(dm); return; } if (dm == null || (dm = getMatchingDisplayMode(dm)) == null) { throw new IllegalArgumentException("Invalid display mode"); } if (getDisplayMode().equals(dm)) { return; } Window w = getFullScreenWindow(); if (w != null) { WWindowPeer peer = AWTAccessor.getComponentAccessor().getPeer(w); configDisplayMode(screen, peer, dm.getWidth(), dm.getHeight(), dm.getBitDepth(), dm.getRefreshRate()); // resize the fullscreen window to the dimensions of the new // display mode Rectangle screenBounds = getDefaultConfiguration().getBounds(); w.setBounds(screenBounds.x, screenBounds.y, dm.getWidth(), dm.getHeight()); // Note: no call to replaceSurfaceData is required here since // replacement will be caused by an upcoming display change event } else { throw new IllegalStateException("Must be in fullscreen mode " + "in order to set display mode"); } }
/** * Creates new form ShowDisplayModes */ public ShowDisplayModes(Frame parent) { this.parent = parent; initComponents(); jToggleButton1.setSelected(doFullScreen); GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment(); possibleModes = environment.getDefaultScreenDevice().getDisplayModes(); for (DisplayMode mode : possibleModes){ jComboBox1.addItem( mode.getWidth()+ " x; "+mode.getHeight()+" y; " +mode.getBitDepth() +" Bit; "+ mode.getRefreshRate()+" Hz"); } }
public void loadWindowGeometryFromConfig() { final Framework framework = Framework.getInstance(); String maximisedStr = framework.getConfigVar(CONFIG_GUI_MAIN_MAXIMISED, false); String widthStr = framework.getConfigVar(CONFIG_GUI_MAIN_WIDTH, false); String heightStr = framework.getConfigVar(CONFIG_GUI_MAIN_HEIGHT, false); boolean maximised = (maximisedStr == null) ? true : Boolean.parseBoolean(maximisedStr); setExtendedState(maximised ? JFrame.MAXIMIZED_BOTH : JFrame.NORMAL); DisplayMode mode = getDisplayMode(); Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(getGraphicsConfiguration()); int width = mode.getWidth() - insets.right - insets.left; int height = mode.getHeight() - insets.top - insets.bottom; if ((widthStr != null) && (heightStr != null)) { width = Integer.parseInt(widthStr); if (width < MIN_WIDTH) { width = MIN_WIDTH; } height = Integer.parseInt(heightStr); if (height < MIN_HEIGHT) { height = MIN_HEIGHT; } } setSize(width, height); }
private void init(int deviceID) throws Exception { if (deviceID < -1) throw new Exception("Unknown Device Handle"); ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); if (deviceID != -1) { screen = ge.getScreenDevices()[deviceID]; } else { screen = ge.getDefaultScreenDevice(); } DisplayMode mode = screen.getDisplayMode(); refreshRate = mode.getRefreshRate(); bitDepth = mode.getBitDepth(); colors = (int) Math.pow(2, bitDepth); dimensions = new Vector2(mode.getWidth(), mode.getHeight()); }
/** * Finds the best display mode the graphics device supports. Based on the * preferred modes. * * @param device the device being inspected * * @return best display mode the given device supports */ protected DisplayMode getBestDisplayMode(final GraphicsDevice device) { final Iterator itr = getPreferredDisplayModes(device).iterator(); while (itr.hasNext()) { final DisplayMode each = (DisplayMode) itr.next(); final DisplayMode[] modes = device.getDisplayModes(); for (int i = 0; i < modes.length; i++) { if (modes[i].getWidth() == each.getWidth() && modes[i].getHeight() == each.getHeight() && modes[i].getBitDepth() == each.getBitDepth()) { return each; } } } return null; }
/** * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ public int compare(DisplayMode a, DisplayMode b) { // Width if (a.getWidth() != b.getWidth()) { return (a.getWidth() > b.getWidth()) ? 1 : -1; } // Height if (a.getHeight() != b.getHeight()) { return (a.getHeight() > b.getHeight()) ? 1 : -1; } // Bit depth if (a.getBitDepth() != b.getBitDepth()) { return (a.getBitDepth() > b.getBitDepth()) ? 1 : -1; } // Refresh rate if (a.getRefreshRate() != b.getRefreshRate()) { return (a.getRefreshRate() > b.getRefreshRate()) ? 1 : -1; } // All fields are equal return 0; }
public static void updateFullscreen() { if(!ExterminateGame.fullscree) { Gdx.graphics.setDisplayMode(1280, 720, false); } else { // move the window to the right screen GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice primary = env.getDefaultScreenDevice(); DisplayMode pmode = primary.getDisplayMode(); Gdx.graphics.setDisplayMode(pmode.getWidth(), pmode.getHeight(), ExterminateGame.fullscree); } }
public DisplayMode[] getDisplayModes() { if (fixedDisplayMode != null) return new DisplayMode[] { fixedDisplayMode }; synchronized (this) { if (displayModes == null) displayModes = nativeGetDisplayModes(env); } ArrayList<DisplayMode> list = new ArrayList<DisplayMode>(); for(int i=0;i<displayModes.length;i++) for(int j=0;j<displayModes[i].rates.length;j++) list.add(new DisplayMode(displayModes[i].width, displayModes[i].height, DisplayMode.BIT_DEPTH_MULTI, displayModes[i].rates[j])); return list.toArray(new DisplayMode[list.size()]); }