Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/FullScreen/MultimonFullscreenTest/MultimonFullscreenTest.java
38828 views
/*1* Copyright (c) 2005, 2008, 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 504121926* @bug 510156127* @bug 503527228* @bug 509601129* @bug 510171230* @bug 509862431* @summary Here are a few assertions worth verification:32* - the fullscreen window is positioned at 0,033* - the fs window appears on the correct screen34* - if the exclusive FS mode is supported, no other widndow should35* overlap the fs window (including the taskbar).36* You could, however, alt+tab out of a fullscreen window, or at least37* minimize it (if you've entered the fs mode with a Window, you'll need38* to minimize the owner frame).39* Note that there may be issues with FS exclusive mode with ddraw and40* multiple fullscreen windows (one per device).41* - if display mode is supported that it did change42* - that the original display mode is restored once43* the ws window is disposed44* All of the above should work with and w/o DirectDraw45* (-Dsun.java2d.noddraw=true) on windows, and w/ and w/o opengl on X1146* (-Dsun.java2d.opengl=True).47* @run main/manual/othervm -Dsun.java2d.pmoffscreen=true MultimonFullscreenTest48* @run main/manual/othervm -Dsun.java2d.pmoffscreen=false MultimonFullscreenTest49* @run main/manual/othervm -Dsun.java2d.d3d=True MultimonFullscreenTest50* @run main/manual/othervm -Dsun.java2d.noddraw=true MultimonFullscreenTest51* @run main/manual/othervm -Dsun.java2d.opengl=True MultimonFullscreenTest52*/5354import java.awt.Button;55import java.awt.Checkbox;56import java.awt.CheckboxGroup;57import java.awt.Color;58import java.awt.Component;59import java.awt.Dialog;60import java.awt.DisplayMode;61import java.awt.Font;62import java.awt.Frame;63import java.awt.Graphics;64import java.awt.GraphicsConfiguration;65import java.awt.GraphicsDevice;66import java.awt.GraphicsEnvironment;67import java.awt.GridLayout;68import java.awt.Panel;69import java.awt.Rectangle;70import java.awt.Window;71import java.awt.event.ActionEvent;72import java.awt.event.ActionListener;73import java.awt.event.ItemEvent;74import java.awt.event.ItemListener;75import java.awt.event.MouseAdapter;76import java.awt.event.MouseEvent;77import java.awt.event.WindowAdapter;78import java.awt.event.WindowEvent;79import java.awt.image.BufferStrategy;80import java.util.HashMap;81import java.util.Random;8283/**84*/8586public class MultimonFullscreenTest extends Frame implements ActionListener {87GraphicsDevice defDev = GraphicsEnvironment.getLocalGraphicsEnvironment().88getDefaultScreenDevice();89GraphicsDevice gd[] = GraphicsEnvironment.getLocalGraphicsEnvironment().90getScreenDevices();91HashMap<Button, GraphicsDevice> deviceMap;9293private static boolean dmChange = false;94static boolean setNullOnDispose = false;95static boolean useFSFrame = true;96static boolean useFSWindow = false;97static boolean useFSDialog = false;98static boolean useBS = false;99static boolean runRenderLoop = false;100static boolean addHWChildren = false;101static volatile boolean done = true;102103public MultimonFullscreenTest(String title) {104super(title);105addWindowListener(new WindowAdapter() {106public void windowClosing(WindowEvent e) {107System.exit(0);108}109});110Panel p = new Panel();111deviceMap = new HashMap<Button, GraphicsDevice>(gd.length);112int num = 0;113for (GraphicsDevice dev : gd) {114Button b;115if (dev == defDev) {116b = new Button("Primary screen: " + num);117System.out.println("Primary Dev : " + dev + " Bounds: " +118dev.getDefaultConfiguration().getBounds());119} else {120b = new Button("Secondary screen " + num);121System.out.println("Secondary Dev : " + dev + " Bounds: " +122dev.getDefaultConfiguration().getBounds());123}124b.addActionListener(this);125p.add(b);126deviceMap.put(b, dev);127num++;128}129add("South", p);130Panel p1 = new Panel();131p1.setLayout(new GridLayout(2,0));132Checkbox cb = new Checkbox("Change DM on entering FS");133cb.addItemListener(new ItemListener() {134public void itemStateChanged(ItemEvent e) {135dmChange = ((Checkbox)e.getSource()).getState();136}137});138p1.add(cb);139// cb = new Checkbox("Exit FS on window dispose");140// cb.addItemListener(new ItemListener() {141// public void itemStateChanged(ItemEvent e) {142// setNullOnDispose = ((Checkbox)e.getSource()).getState();143// }144// });145// p1.add(cb);146CheckboxGroup cbg = new CheckboxGroup();147cb = new Checkbox("Use Frame to enter FS", cbg, true);148cb.addItemListener(new ItemListener() {149public void itemStateChanged(ItemEvent e) {150useFSFrame = true;151useFSWindow = false;152useFSDialog = false;153}154});155p1.add(cb);156cb = new Checkbox("Use Window to enter FS", cbg, false);157cb.addItemListener(new ItemListener() {158public void itemStateChanged(ItemEvent e) {159useFSFrame = false;160useFSWindow = true;161useFSDialog = false;162}163});164p1.add(cb);165cb = new Checkbox("Use Dialog to enter FS", cbg, false);166cb.addItemListener(new ItemListener() {167public void itemStateChanged(ItemEvent e) {168useFSFrame = false;169useFSWindow = false;170useFSDialog = true;171}172});173p1.add(cb);174cb = new Checkbox("Run render loop");175cb.addItemListener(new ItemListener() {176public void itemStateChanged(ItemEvent e) {177runRenderLoop = ((Checkbox)e.getSource()).getState();178}179});180p1.add(cb);181cb = new Checkbox("Use BufferStrategy in render loop");182cb.addItemListener(new ItemListener() {183public void itemStateChanged(ItemEvent e) {184useBS = ((Checkbox)e.getSource()).getState();185}186});187p1.add(cb);188cb = new Checkbox("Add Children to FS window");189cb.addItemListener(new ItemListener() {190public void itemStateChanged(ItemEvent e) {191addHWChildren = ((Checkbox)e.getSource()).getState();192}193});194p1.add(cb);195add("North", p1);196197pack();198setVisible(true);199}200201Font f = new Font("Dialog", Font.BOLD, 24);202Random rnd = new Random();203public void renderDimensions(Graphics g, Rectangle rectWndBounds,204GraphicsConfiguration gc) {205g.setColor(new Color(rnd.nextInt(0xffffff)));206g.fillRect(0, 0, rectWndBounds.width, rectWndBounds.height);207208g.setColor(new Color(rnd.nextInt(0xffffff)));209Rectangle rectStrBounds;210211g.setFont(f);212213rectStrBounds = g.getFontMetrics().214getStringBounds(rectWndBounds.toString(), g).getBounds();215rectStrBounds.height += 30;216g.drawString(rectWndBounds.toString(), 50, rectStrBounds.height);217int oldHeight = rectStrBounds.height;218String isFSupported = "Exclusive Fullscreen mode supported: " +219gc.getDevice().isFullScreenSupported();220rectStrBounds = g.getFontMetrics().221getStringBounds(isFSupported, g).getBounds();222rectStrBounds.height += (10 + oldHeight);223g.drawString(isFSupported, 50, rectStrBounds.height);224225oldHeight = rectStrBounds.height;226String isDMChangeSupported = "Display Mode Change supported: " +227gc.getDevice().isDisplayChangeSupported();228rectStrBounds = g.getFontMetrics().229getStringBounds(isDMChangeSupported, g).getBounds();230rectStrBounds.height += (10 + oldHeight);231g.drawString(isDMChangeSupported, 50, rectStrBounds.height);232233oldHeight = rectStrBounds.height;234String usingBS = "Using BufferStrategy: " + useBS;235rectStrBounds = g.getFontMetrics().236getStringBounds(usingBS, g).getBounds();237rectStrBounds.height += (10 + oldHeight);238g.drawString(usingBS, 50, rectStrBounds.height);239240final String m_strQuitMsg = "Double-click to dispose FullScreen Window";241rectStrBounds = g.getFontMetrics().242getStringBounds(m_strQuitMsg, g).getBounds();243g.drawString(m_strQuitMsg,244(rectWndBounds.width - rectStrBounds.width) / 2,245(rectWndBounds.height - rectStrBounds.height) / 2);246247248}249250public void actionPerformed(ActionEvent ae) {251GraphicsDevice dev = deviceMap.get(ae.getSource());252System.err.println("Setting FS on device:"+dev);253final Window fsWindow;254255if (useFSWindow) {256fsWindow = new Window(this, dev.getDefaultConfiguration()) {257public void paint(Graphics g) {258renderDimensions(g, getBounds(),259this.getGraphicsConfiguration());260}261};262} else if (useFSDialog) {263fsWindow = new Dialog((Frame)null, "FS Dialog on device "+dev, false,264dev.getDefaultConfiguration());265fsWindow.add(new Component() {266public void paint(Graphics g) {267renderDimensions(g, getBounds(),268this.getGraphicsConfiguration());269}270});271} else {272fsWindow = new Frame("FS Frame on device "+dev,273dev.getDefaultConfiguration())274{275public void paint(Graphics g) {276renderDimensions(g, getBounds(),277this.getGraphicsConfiguration());278}279};280if (addHWChildren) {281fsWindow.add("South", new Panel() {282public void paint(Graphics g) {283g.setColor(Color.red);284g.fillRect(0, 0, getWidth(), getHeight());285}286});287fsWindow.add("North", new Button("Button, sucka!"));288}289}290fsWindow.addMouseListener(new MouseAdapter() {291public void mouseClicked(MouseEvent e) {292if (e.getClickCount() > 1) {293done = true;294fsWindow.dispose();295}296}297});298299fsWindow.addWindowListener(new WindowHandler());300dev.setFullScreenWindow(fsWindow);301if (dmChange && dev.isDisplayChangeSupported()) {302DisplayMode dms[] = dev.getDisplayModes();303DisplayMode myDM = null;304for (DisplayMode dm : dms) {305if (dm.getWidth() == 800 && dm.getHeight() == 600 &&306(dm.getBitDepth() >= 16 ||307dm.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI) &&308(dm.getRefreshRate() >= 60 ||309dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN))310{311myDM = dm;312break;313}314}315if (myDM != null) {316System.err.println("Setting Display Mode: "+317myDM.getWidth() + "x" + myDM.getHeight() + "x" +318myDM.getBitDepth() + "@" + myDM.getRefreshRate() +319"Hz on device" + dev);320dev.setDisplayMode(myDM);321} else {322System.err.println("Can't find suitable display mode.");323}324}325done = false;326if (runRenderLoop) {327Thread updateThread = new Thread(new Runnable() {328public void run() {329BufferStrategy bs = null;330if (useBS) {331fsWindow.createBufferStrategy(2);332bs = fsWindow.getBufferStrategy();333}334while (!done) {335if (useBS) {336Graphics g = bs.getDrawGraphics();337renderDimensions(g, fsWindow.getBounds(),338fsWindow.getGraphicsConfiguration());339bs.show();340} else {341fsWindow.repaint();342}343try {344Thread.sleep(1000);345} catch (InterruptedException e) {}346}347if (useBS) {348bs.dispose();349}350}351});352updateThread.start();353}354}355356public static void main(String args[]) {357for (String s : args) {358if (s.equalsIgnoreCase("-dm")) {359System.err.println("Do Display Change after entering FS mode");360dmChange = true;361} else if (s.equalsIgnoreCase("-usewindow")) {362System.err.println("Using Window to enter FS mode");363useFSWindow = true;364} else if (s.equalsIgnoreCase("-setnull")) {365System.err.println("Setting null FS window on dispose");366setNullOnDispose = true;367} else {368System.err.println("Usage: MultimonFullscreenTest " +369"[-dm][-usewindow][-setnull]");370}371372}373MultimonFullscreenTest fs =374new MultimonFullscreenTest("Test Full Screen");375}376class WindowHandler extends WindowAdapter {377public void windowClosing(WindowEvent we) {378done = true;379Window w = (Window)we.getSource();380if (setNullOnDispose) {381w.getGraphicsConfiguration().getDevice().setFullScreenWindow(null);382}383w.dispose();384}385}386}387388389