Path: blob/master/test/jdk/java/awt/GraphicsDevice/DisplayModes/UnknownRefrshRateTest.java
66646 views
/*1* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 826743026* @key headful27* @summary verify setting a display mode with unknow refresh rate works28*/2930import java.awt.DisplayMode;31import java.awt.GraphicsDevice;32import java.awt.GraphicsEnvironment;3334public class UnknownRefrshRateTest {3536public static void main(String[] args) throws Exception {3738GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();39GraphicsDevice[] devices = ge.getScreenDevices();4041for (GraphicsDevice d : devices) {4243if (!d.isDisplayChangeSupported()) {44continue;45}46DisplayMode odm = d.getDisplayMode();47System.out.println("device=" + d + " original mode=" + odm);4849DisplayMode[] modes = d.getDisplayModes();50System.out.println("There are " + modes.length + " modes.");51try {52for (int i=0; i<modes.length; i++) {53DisplayMode mode = modes[i];54System.out.println("copying from mode " + i + " : " + mode);55int w = mode.getWidth();56int h = mode.getHeight();57int bpp = mode.getBitDepth();58int refRate = DisplayMode.REFRESH_RATE_UNKNOWN;59DisplayMode newMode = new DisplayMode(w, h, bpp, refRate);60d.setDisplayMode(newMode);61Thread.sleep(2000);62System.out.println("set " + d.getDisplayMode());63}64} finally {65System.out.println("restoring original mode"+odm);66d.setDisplayMode(odm);67Thread.sleep(10000);68}69}70}71}727374