undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com Patches, unit tests, benchmarks, whitepaper, and outreach briefs. Public domain — no copyright claimed. Use freely.
This commit is contained in:
commit
0a580b313d
70422 changed files with 17213626 additions and 0 deletions
107
test/jdk/java/awt/FullScreen/8013581/bug8013581.java
Normal file
107
test/jdk/java/awt/FullScreen/8013581/bug8013581.java
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 8013581
|
||||
* @summary [macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow
|
||||
* @author leonid.romanov@oracle.com
|
||||
* @run main bug8013581
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class bug8013581 {
|
||||
private static Frame frame;
|
||||
private static volatile int listenerCallCounter = 0;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
final GraphicsEnvironment ge = GraphicsEnvironment
|
||||
.getLocalGraphicsEnvironment();
|
||||
final GraphicsDevice[] devices = ge.getScreenDevices();
|
||||
|
||||
final Robot robot = new Robot();
|
||||
robot.setAutoDelay(50);
|
||||
|
||||
createAndShowGUI();
|
||||
robot.waitForIdle();
|
||||
|
||||
Exception error = null;
|
||||
for (final GraphicsDevice device : devices) {
|
||||
if (!device.isFullScreenSupported()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
device.setFullScreenWindow(frame);
|
||||
sleep(robot);
|
||||
|
||||
robot.keyPress(KeyEvent.VK_A);
|
||||
robot.keyRelease(KeyEvent.VK_A);
|
||||
robot.waitForIdle();
|
||||
|
||||
device.setFullScreenWindow(null);
|
||||
sleep(robot);
|
||||
|
||||
if (listenerCallCounter != 2) {
|
||||
error = new Exception("Test failed: KeyListener called " + listenerCallCounter + " times instead of 2!");
|
||||
break;
|
||||
}
|
||||
|
||||
listenerCallCounter = 0;
|
||||
}
|
||||
|
||||
frame.dispose();
|
||||
|
||||
if (error != null) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
private static void createAndShowGUI() {
|
||||
frame = new Frame("Test");
|
||||
frame.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
listenerCallCounter++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
listenerCallCounter++;
|
||||
}
|
||||
});
|
||||
|
||||
frame.setUndecorated(true);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
private static void sleep(Robot robot) {
|
||||
robot.waitForIdle();
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8190767
|
||||
* @key headful
|
||||
* @requires os.family == "mac"
|
||||
* @summary If JFrame is maximized on OS X, all new JFrames will be maximized by default
|
||||
* @compile AllFramesMaximize.java
|
||||
* @run main/manual AllFramesMaximize
|
||||
*/
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.SwingUtilities;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class AllFramesMaximize {
|
||||
private static JButton passButton;
|
||||
private static JButton failButton;
|
||||
private static JTextArea instructions;
|
||||
private static JFrame mainFrame;
|
||||
private static JFrame instructionFrame;
|
||||
public static boolean isProgInterruption = false;
|
||||
static Thread mainThread = null;
|
||||
static int sleepTime = 300000;
|
||||
|
||||
public static void createAndShowJFrame() {
|
||||
passButton = new JButton("Pass");
|
||||
passButton.setEnabled(true);
|
||||
|
||||
failButton = new JButton("Fail");
|
||||
failButton.setEnabled(true);
|
||||
|
||||
instructions = new JTextArea(8, 30);
|
||||
instructions.setText(" This is a manual test\n\n" +
|
||||
" 1) Click on the maximize button, JFrame will enter fullscreen\n" +
|
||||
" 2) Click anywhere on the JFrame\n" +
|
||||
" 3) Press Pass if new JFrame didn't open in fullscreen,\n" +
|
||||
" 4) Press Fail if new JFrame opened in fullscreen");
|
||||
|
||||
instructionFrame = new JFrame("Test Instructions");
|
||||
instructionFrame.setLocationRelativeTo(null);
|
||||
instructionFrame.add(passButton);
|
||||
instructionFrame.add(failButton);
|
||||
instructionFrame.add(instructions);
|
||||
instructionFrame.setSize(200,200);
|
||||
instructionFrame.setLayout(new FlowLayout());
|
||||
instructionFrame.pack();
|
||||
instructionFrame.setVisible(true);
|
||||
|
||||
passButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent ae) {
|
||||
dispose();
|
||||
isProgInterruption = true;
|
||||
mainThread.interrupt();
|
||||
}
|
||||
});
|
||||
|
||||
failButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent ae) {
|
||||
dispose();
|
||||
isProgInterruption = true;
|
||||
mainThread.interrupt();
|
||||
throw new RuntimeException("New JFrame opened on a new window!");
|
||||
}
|
||||
});
|
||||
|
||||
mainFrame = new JFrame();
|
||||
JButton button = new JButton("Open Frame");
|
||||
mainFrame.getContentPane().add(button);
|
||||
button.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFrame f = new JFrame();
|
||||
f.setSize(400, 400);
|
||||
f.setVisible(true);
|
||||
}
|
||||
});
|
||||
mainFrame.setSize(500, 500);
|
||||
mainFrame.setVisible(true);
|
||||
}
|
||||
|
||||
private static void dispose() {
|
||||
mainFrame.dispose();
|
||||
instructionFrame.dispose();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
mainThread = Thread.currentThread();
|
||||
SwingUtilities.invokeAndWait(AllFramesMaximize::createAndShowJFrame);
|
||||
|
||||
try {
|
||||
mainThread.sleep(sleepTime);
|
||||
} catch (InterruptedException e) {
|
||||
if (!isProgInterruption) {
|
||||
throw e;
|
||||
}
|
||||
} finally {
|
||||
SwingUtilities.invokeAndWait(AllFramesMaximize::dispose);
|
||||
}
|
||||
|
||||
if (!isProgInterruption) {
|
||||
throw new RuntimeException("Timed out after " + sleepTime / 1000
|
||||
+ " seconds");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,472 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
@test
|
||||
@key headful
|
||||
@bug 6275887 6429971 6459792 8198613
|
||||
@summary Test that we don't crash when alt+tabbing in and out of
|
||||
fullscreen app
|
||||
@author Dmitri.Trembovetski@sun.com: area=FullScreen
|
||||
@run main/othervm/timeout=100 AltTabCrashTest -auto -changedm
|
||||
@run main/othervm/timeout=100 -Dsun.java2d.d3d=True AltTabCrashTest -auto -changedm
|
||||
@run main/othervm/timeout=100 -Dsun.java2d.d3d=True AltTabCrashTest -auto -usebs -changedm
|
||||
*/
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Color;
|
||||
import java.awt.DisplayMode;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Image;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Robot;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferStrategy;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.VolatileImage;
|
||||
import java.util.Random;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* Note that the alt+tabbing in and out part will most likely only work
|
||||
* on Windows, and only if there are no interventions.
|
||||
*/
|
||||
|
||||
public class AltTabCrashTest extends Frame {
|
||||
public static int width;
|
||||
public static int height;
|
||||
public static volatile boolean autoMode;
|
||||
public static boolean useBS;
|
||||
public static final int NUM_OF_BALLS = 70;
|
||||
// number of times to alt+tab in and out of the app
|
||||
public static int altTabs = 5;
|
||||
private final Vector<Ball> balls = new Vector<>();
|
||||
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment()
|
||||
.getDefaultScreenDevice();
|
||||
VolatileImage vimg = null;
|
||||
BufferStrategy bufferStrategy = null;
|
||||
volatile boolean timeToQuit = false;
|
||||
|
||||
enum SpriteType {
|
||||
OVALS, VIMAGES, BIMAGES, AAOVALS, TEXT
|
||||
}
|
||||
|
||||
private static boolean changeDM = false;
|
||||
private static SpriteType spriteType;
|
||||
static Random rnd = new Random();
|
||||
|
||||
public AltTabCrashTest( ) {
|
||||
addKeyListener(new KeyAdapter() {
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
||||
timeToQuit = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
setIgnoreRepaint(true);
|
||||
addMouseListener(new MouseHandler());
|
||||
for (int i = 0; i < NUM_OF_BALLS; i++) {
|
||||
int x = 50 + rnd.nextInt(550), y = 50 + rnd.nextInt(400);
|
||||
|
||||
balls.addElement(createRandomBall(y, x));
|
||||
}
|
||||
setUndecorated(true);
|
||||
gd.setFullScreenWindow(this);
|
||||
GraphicsDevice gd = getGraphicsConfiguration().getDevice();
|
||||
if (gd.isDisplayChangeSupported() && changeDM) {
|
||||
DisplayMode dm = findDisplayMode();
|
||||
if (dm != null) {
|
||||
try {
|
||||
gd.setDisplayMode(dm);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
System.err.println("Error setting display mode");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (useBS) {
|
||||
createBufferStrategy(2);
|
||||
bufferStrategy = getBufferStrategy();
|
||||
} else {
|
||||
Graphics2D g = (Graphics2D) getGraphics();
|
||||
render(g);
|
||||
g.dispose();
|
||||
}
|
||||
Thread ballThread = new BallThread();
|
||||
ballThread.start();
|
||||
if (autoMode) {
|
||||
Thread tabberThread = new AltTabberThread();
|
||||
tabberThread.start();
|
||||
try {
|
||||
ballThread.join();
|
||||
tabberThread.join();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private Ball createRandomBall(final int y, final int x) {
|
||||
Ball b;
|
||||
SpriteType type;
|
||||
|
||||
if (spriteType == null) {
|
||||
int index = rnd.nextInt(SpriteType.values().length);
|
||||
type = SpriteType.values()[index];
|
||||
} else {
|
||||
type = spriteType;
|
||||
}
|
||||
switch (type) {
|
||||
case VIMAGES: b = new VISpriteBall(x, y); break;
|
||||
case AAOVALS: b = new AAOvalBall(x, y); break;
|
||||
case BIMAGES: b = new BISpriteBall(x, y); break;
|
||||
case TEXT: b = new TextBall(x,y, "Text Sprite!"); break;
|
||||
default: b = new Ball(x, y); break;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
private class MouseHandler extends MouseAdapter {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
synchronized (balls) {
|
||||
balls.addElement(createRandomBall(e.getX(), e.getY()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class AltTabberThread extends Thread {
|
||||
Robot robot;
|
||||
|
||||
void pressAltTab() {
|
||||
robot.keyPress(KeyEvent.VK_ALT);
|
||||
robot.keyPress(KeyEvent.VK_TAB);
|
||||
robot.keyRelease(KeyEvent.VK_TAB);
|
||||
robot.keyRelease(KeyEvent.VK_ALT);
|
||||
}
|
||||
void pressShiftAltTab() {
|
||||
robot.keyPress(KeyEvent.VK_SHIFT);
|
||||
pressAltTab();
|
||||
robot.keyRelease(KeyEvent.VK_SHIFT);
|
||||
}
|
||||
public void run() {
|
||||
try {
|
||||
robot = new Robot();
|
||||
robot.setAutoDelay(200);
|
||||
} catch (AWTException e) {
|
||||
throw new RuntimeException("Can't create robot");
|
||||
}
|
||||
boolean out = true;
|
||||
while (altTabs-- > 0 && !timeToQuit) {
|
||||
System.err.println("Alt+tabber Iteration: "+altTabs);
|
||||
try { Thread.sleep(2500); } catch (InterruptedException ex) {}
|
||||
|
||||
if (out) {
|
||||
System.err.println("Issuing alt+tab");
|
||||
pressAltTab();
|
||||
} else {
|
||||
System.err.println("Issuing shift ");
|
||||
pressShiftAltTab();
|
||||
}
|
||||
out = !out;
|
||||
}
|
||||
System.err.println("Alt+tabber finished.");
|
||||
timeToQuit = true;
|
||||
}
|
||||
}
|
||||
|
||||
private class BallThread extends Thread {
|
||||
public void run() {
|
||||
while (!timeToQuit) {
|
||||
if (useBS) {
|
||||
renderToBS();
|
||||
bufferStrategy.show();
|
||||
} else {
|
||||
Graphics g = AltTabCrashTest.this.getGraphics();
|
||||
render(g);
|
||||
g.dispose();
|
||||
}
|
||||
}
|
||||
gd.setFullScreenWindow(null);
|
||||
AltTabCrashTest.this.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
static class Ball {
|
||||
|
||||
int x, y; // current location
|
||||
int dx, dy; // motion delta
|
||||
int diameter = 40;
|
||||
Color color = Color.red;
|
||||
|
||||
public Ball() {
|
||||
}
|
||||
|
||||
public Ball(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
dx = x % 20 + 1;
|
||||
dy = y % 20 + 1;
|
||||
color = new Color(rnd.nextInt(0x00ffffff));
|
||||
}
|
||||
|
||||
public void move() {
|
||||
if (x < 10 || x >= AltTabCrashTest.width - 20)
|
||||
dx = -dx;
|
||||
if (y < 10 || y > AltTabCrashTest.height - 20)
|
||||
dy = -dy;
|
||||
x += dx;
|
||||
y += dy;
|
||||
}
|
||||
|
||||
public void paint(Graphics g, Color c) {
|
||||
if (c == null) {
|
||||
g.setColor(color);
|
||||
} else {
|
||||
g.setColor(c);
|
||||
}
|
||||
g.fillOval(x, y, diameter, diameter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class TextBall extends Ball {
|
||||
String text;
|
||||
public TextBall(int x, int y, String text) {
|
||||
super(x, y);
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public void paint(Graphics g, Color c) {
|
||||
if (c == null) {
|
||||
g.setColor(color);
|
||||
} else {
|
||||
g.setColor(c);
|
||||
}
|
||||
g.drawString(text, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
static class AAOvalBall extends Ball {
|
||||
public AAOvalBall(int x, int y) {
|
||||
super(x, y);
|
||||
}
|
||||
public void paint(Graphics g, Color c) {
|
||||
if (c == null) {
|
||||
Graphics2D g2d = (Graphics2D)g.create();
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2d.setColor(color);
|
||||
g2d.fillOval(x, y, diameter, diameter);
|
||||
} else {
|
||||
g.setColor(c);
|
||||
g.fillOval(x-2, y-2, diameter+4, diameter+4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static abstract class SpriteBall extends Ball {
|
||||
Image image;
|
||||
public SpriteBall(int x, int y) {
|
||||
super(x, y);
|
||||
image = createSprite();
|
||||
Graphics g = image.getGraphics();
|
||||
g.setColor(color);
|
||||
g.fillRect(0, 0, image.getWidth(null), image.getHeight(null));
|
||||
}
|
||||
public void paint(Graphics g, Color c) {
|
||||
if (c != null) {
|
||||
g.setColor(c);
|
||||
g.fillRect(x, y, image.getWidth(null), image.getHeight(null));
|
||||
} else do {
|
||||
validateSprite();
|
||||
g.drawImage(image, x, y, null);
|
||||
} while (renderingIncomplete());
|
||||
}
|
||||
public abstract Image createSprite();
|
||||
public void validateSprite() {}
|
||||
public boolean renderingIncomplete() { return false; }
|
||||
}
|
||||
class VISpriteBall extends SpriteBall {
|
||||
|
||||
public VISpriteBall(int x, int y) {
|
||||
super(x, y);
|
||||
}
|
||||
public boolean renderingIncomplete() {
|
||||
return ((VolatileImage)image).contentsLost();
|
||||
}
|
||||
|
||||
public Image createSprite() {
|
||||
return gd.getDefaultConfiguration().
|
||||
createCompatibleVolatileImage(20, 20);
|
||||
}
|
||||
public void validateSprite() {
|
||||
int result =
|
||||
((VolatileImage)image).validate(getGraphicsConfiguration());
|
||||
if (result == VolatileImage.IMAGE_INCOMPATIBLE) {
|
||||
image = createSprite();
|
||||
result = VolatileImage.IMAGE_RESTORED;
|
||||
}
|
||||
if (result == VolatileImage.IMAGE_RESTORED) {
|
||||
Graphics g = image.getGraphics();
|
||||
g.setColor(color);
|
||||
g.fillRect(0, 0, image.getWidth(null), image.getHeight(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
class BISpriteBall extends SpriteBall {
|
||||
public BISpriteBall(int x, int y) {
|
||||
super(x, y);
|
||||
}
|
||||
public Image createSprite() {
|
||||
return new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void renderOffscreen() {
|
||||
Graphics2D g2d = (Graphics2D) vimg.getGraphics();
|
||||
synchronized (balls) {
|
||||
for (Ball b : balls) {
|
||||
b.paint(g2d, getBackground());
|
||||
b.move();
|
||||
b.paint(g2d, null);
|
||||
}
|
||||
}
|
||||
g2d.dispose();
|
||||
}
|
||||
|
||||
public void renderToBS() {
|
||||
width = getWidth();
|
||||
height = getHeight();
|
||||
|
||||
do {
|
||||
Graphics2D g2d = (Graphics2D)bufferStrategy.getDrawGraphics();
|
||||
|
||||
g2d.clearRect(0, 0, width, height);
|
||||
synchronized (balls) {
|
||||
for (Ball b : balls) {
|
||||
b.move();
|
||||
b.paint(g2d, null);
|
||||
}
|
||||
}
|
||||
g2d.dispose();
|
||||
} while (bufferStrategy.contentsLost() ||
|
||||
bufferStrategy.contentsRestored());
|
||||
}
|
||||
|
||||
public void render(Graphics g) {
|
||||
do {
|
||||
height = getBounds().height;
|
||||
width = getBounds().width;
|
||||
if (vimg == null) {
|
||||
vimg = createVolatileImage(width, height);
|
||||
renderOffscreen();
|
||||
}
|
||||
int returnCode = vimg.validate(getGraphicsConfiguration());
|
||||
if (returnCode == VolatileImage.IMAGE_RESTORED) {
|
||||
renderOffscreen();
|
||||
} else if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) {
|
||||
vimg = getGraphicsConfiguration().
|
||||
createCompatibleVolatileImage(width, height);
|
||||
renderOffscreen();
|
||||
} else if (returnCode == VolatileImage.IMAGE_OK) {
|
||||
renderOffscreen();
|
||||
}
|
||||
g.drawImage(vimg, 0, 0, this);
|
||||
} while (vimg.contentsLost());
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
for (String arg : args) {
|
||||
if (arg.equalsIgnoreCase("-auto")) {
|
||||
autoMode = true;
|
||||
System.err.println("Running in automatic mode using Robot");
|
||||
} else if (arg.equalsIgnoreCase("-usebs")) {
|
||||
useBS = true;
|
||||
System.err.println("Using BufferStrategy instead of VI");
|
||||
} else if (arg.equalsIgnoreCase("-changedm")) {
|
||||
changeDM= true;
|
||||
System.err.println("The test will change display mode");
|
||||
} else if (arg.equalsIgnoreCase("-vi")) {
|
||||
spriteType = SpriteType.VIMAGES;
|
||||
} else if (arg.equalsIgnoreCase("-bi")) {
|
||||
spriteType = SpriteType.BIMAGES;
|
||||
} else if (arg.equalsIgnoreCase("-ov")) {
|
||||
spriteType = SpriteType.OVALS;
|
||||
} else if (arg.equalsIgnoreCase("-aaov")) {
|
||||
spriteType = SpriteType.AAOVALS;
|
||||
} else if (arg.equalsIgnoreCase("-tx")) {
|
||||
spriteType = SpriteType.TEXT;
|
||||
} else {
|
||||
System.err.println("Usage: AltTabCrashTest [-usebs][-auto]" +
|
||||
"[-changedm][-vi|-bi|-ov|-aaov|-tx]");
|
||||
System.err.println(" -usebs: use BufferStrategy instead of VI");
|
||||
System.err.println(" -auto: automatically alt+tab in and out" +
|
||||
" of the application ");
|
||||
System.err.println(" -changedm: change display mode");
|
||||
System.err.println(" -(vi|bi|ov|tx|aaov) : use only VI, BI, " +
|
||||
"text or [AA] [draw]Oval sprites");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
if (spriteType != null) {
|
||||
System.err.println("The test will only use "+spriteType+" sprites.");
|
||||
}
|
||||
new AltTabCrashTest();
|
||||
}
|
||||
|
||||
private DisplayMode findDisplayMode() {
|
||||
GraphicsDevice gd = getGraphicsConfiguration().getDevice();
|
||||
DisplayMode dms[] = gd.getDisplayModes();
|
||||
DisplayMode currentDM = gd.getDisplayMode();
|
||||
for (DisplayMode dm : dms) {
|
||||
if (dm.getBitDepth() > 8 &&
|
||||
dm.getBitDepth() != DisplayMode.BIT_DEPTH_MULTI &&
|
||||
dm.getBitDepth() != currentDM.getBitDepth() &&
|
||||
dm.getWidth() == currentDM.getWidth() &&
|
||||
dm.getHeight() == currentDM.getHeight())
|
||||
{
|
||||
// found a mode which has the same dimensions but different
|
||||
// depth
|
||||
return dm;
|
||||
}
|
||||
if (dm.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI &&
|
||||
(dm.getWidth() != currentDM.getWidth() ||
|
||||
dm.getHeight() != currentDM.getHeight()))
|
||||
{
|
||||
// found a mode which has the same depth but different
|
||||
// dimensions
|
||||
return dm;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 6366813 6459844 8198613
|
||||
* @summary Tests that no exception is thrown if a frame is resized just
|
||||
* before we create a bufferStrategy
|
||||
* @author Dmitri.Trembovetski area=FullScreen/BufferStrategy
|
||||
* @run main/othervm BufferStrategyExceptionTest
|
||||
*/
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.BufferCapabilities;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.ImageCapabilities;
|
||||
import java.awt.image.BufferStrategy;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* The purpose of this test is to make sure that we do not throw an
|
||||
* IllegalStateException during the creation of BufferStrategy if
|
||||
* a window has been resized just before our creation attempt.
|
||||
*
|
||||
* We test both windowed and fullscreen mode, although the exception has
|
||||
* been observed in full screen mode only.
|
||||
*/
|
||||
public class BufferStrategyExceptionTest {
|
||||
private static final int TEST_REPS = 20;
|
||||
|
||||
public static void main(String[] args) {
|
||||
GraphicsDevice gd =
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment().
|
||||
getDefaultScreenDevice();
|
||||
|
||||
for (int i = 0; i < TEST_REPS; i++) {
|
||||
TestFrame f = new TestFrame();
|
||||
f.pack();
|
||||
f.setSize(400, 400);
|
||||
f.setVisible(true);
|
||||
if (i % 2 == 0) {
|
||||
gd.setFullScreenWindow(f);
|
||||
}
|
||||
// generate a resize event which will invalidate the peer's
|
||||
// surface data and hopefully cause an exception during
|
||||
// BufferStrategy creation in TestFrame.render()
|
||||
Dimension d = f.getSize();
|
||||
d.width -= 5; d.height -= 5;
|
||||
f.setSize(d);
|
||||
|
||||
f.render();
|
||||
gd.setFullScreenWindow(null);
|
||||
sleep(100);
|
||||
f.dispose();
|
||||
}
|
||||
System.out.println("Test passed.");
|
||||
}
|
||||
|
||||
private static void sleep(long msecs) {
|
||||
try {
|
||||
Thread.sleep(msecs);
|
||||
} catch (InterruptedException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static final BufferedImage bi =
|
||||
new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
static class TestFrame extends Frame {
|
||||
TestFrame() {
|
||||
setUndecorated(true);
|
||||
setIgnoreRepaint(true);
|
||||
setSize(400, 400);
|
||||
}
|
||||
|
||||
public void render() {
|
||||
ImageCapabilities imgBackBufCap = new ImageCapabilities(true);
|
||||
ImageCapabilities imgFrontBufCap = new ImageCapabilities(true);
|
||||
BufferCapabilities bufCap =
|
||||
new BufferCapabilities(imgFrontBufCap,
|
||||
imgBackBufCap, BufferCapabilities.FlipContents.COPIED);
|
||||
try {
|
||||
|
||||
createBufferStrategy(2, bufCap);
|
||||
} catch (AWTException ex) {
|
||||
createBufferStrategy(2);
|
||||
}
|
||||
|
||||
BufferStrategy bs = getBufferStrategy();
|
||||
do {
|
||||
Graphics g = bs.getDrawGraphics();
|
||||
g.setColor(Color.green);
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
|
||||
g.setColor(Color.red);
|
||||
g.drawString("Rendering test", 20, 20);
|
||||
|
||||
g.drawImage(bi, 50, 50, null);
|
||||
|
||||
g.dispose();
|
||||
bs.show();
|
||||
} while (bs.contentsLost()||bs.contentsRestored());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 8022810
|
||||
* @summary Device.getDisplayMode() doesn't report refresh rate on Linux in case
|
||||
* of dual screen
|
||||
* @run main CurrentDisplayModeTest
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class CurrentDisplayModeTest {
|
||||
public static void main(String[] args) {
|
||||
GraphicsDevice[] screenDevices = GraphicsEnvironment.
|
||||
getLocalGraphicsEnvironment().getScreenDevices();
|
||||
for (GraphicsDevice screenDevice : screenDevices) {
|
||||
DisplayMode currentMode = screenDevice.getDisplayMode();
|
||||
System.out.println("current mode " + currentMode);
|
||||
Set<DisplayMode> set = new HashSet<>(
|
||||
Arrays.asList(screenDevice.getDisplayModes()));
|
||||
if (!set.contains(currentMode)) {
|
||||
throw new RuntimeException("Mode " + currentMode +
|
||||
" is not found in the modes list " + set);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,245 @@
|
|||
/*
|
||||
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 6366359 8198613
|
||||
* @summary Test that we don't crash when changing from 8 to 16/32 bit modes
|
||||
* @author Dmitri.Trembovetski@Sun.COM area=FullScreen
|
||||
* @run main/othervm/timeout=200 DisplayChangeVITest
|
||||
* @run main/othervm/timeout=200 -Dsun.java2d.d3d=false DisplayChangeVITest
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.DisplayMode;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.VolatileImage;
|
||||
import java.lang.Exception;
|
||||
import java.lang.Thread;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
/**
|
||||
* The test enters fullscreen mode (if it's supported) and then tries
|
||||
* to switch between display moes with different depths and dimensions
|
||||
* while doing both rendering to the screen (via a VolatileImage)
|
||||
* and Swing repainting just to make things more chaotic.
|
||||
*
|
||||
* The procedure is repeated TEST_REPS times (3 by default).
|
||||
*
|
||||
* Don't pay attention to what happens on the screen, it won't be pretty.
|
||||
* If the test doesn't crash or throw exceptions, it passes, otherwise
|
||||
* it fails.
|
||||
*/
|
||||
public class DisplayChangeVITest extends JFrame implements Runnable {
|
||||
|
||||
private final Random rnd = new Random();
|
||||
private VolatileImage bb;
|
||||
private BufferedImage sprite;
|
||||
private VolatileImage volSprite;
|
||||
|
||||
private static boolean done = false;
|
||||
private static final Object lock = new Object();
|
||||
private static final int TEST_REPS = 3;
|
||||
|
||||
private ArrayList<DisplayMode> dms;
|
||||
|
||||
DisplayChangeVITest() {
|
||||
selectDisplayModes();
|
||||
addKeyListener(new KeyAdapter() {
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
||||
synchronized (lock) {
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
sprite = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
|
||||
sprite.getRaster().getDataBuffer();
|
||||
Graphics g = sprite.getGraphics();
|
||||
g.setColor(Color.yellow);
|
||||
g.fillRect(0, 0, sprite.getWidth(), sprite.getHeight());
|
||||
}
|
||||
|
||||
void render(Graphics g) {
|
||||
do {
|
||||
// volatile images validated here
|
||||
initBackbuffer();
|
||||
|
||||
g.setColor(Color.black);
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
|
||||
Graphics gg = bb.getGraphics();
|
||||
gg.setColor(new Color(rnd.nextInt(0x00ffffff)));
|
||||
gg.fillRect(0, 0, bb.getWidth(), bb.getHeight());
|
||||
for (int x = 0; x < 10; x++) {
|
||||
gg.drawImage(sprite, x*200, 0, null);
|
||||
gg.drawImage(volSprite, x*200, 500, null);
|
||||
}
|
||||
|
||||
g.drawImage(bb, 0, 0, null);
|
||||
} while (bb.contentsLost());
|
||||
}
|
||||
|
||||
private static void sleep(long msec) {
|
||||
try { Thread.sleep(msec); } catch (InterruptedException e) {}
|
||||
}
|
||||
|
||||
private int reps = 0;
|
||||
public void run() {
|
||||
GraphicsDevice gd = getGraphicsConfiguration().getDevice();
|
||||
if (gd.isDisplayChangeSupported() && dms.size() > 0) {
|
||||
while (!done && reps++ < TEST_REPS) {
|
||||
for (DisplayMode dm : dms) {
|
||||
System.err.printf("Entering DisplayMode[%dx%dx%d]\n",
|
||||
dm.getWidth(), dm.getHeight(), dm.getBitDepth());
|
||||
gd.setDisplayMode(dm);
|
||||
|
||||
initBackbuffer();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
// render to the screen
|
||||
render(getGraphics());
|
||||
// ask Swing to repaint
|
||||
repaint();
|
||||
sleep(100);
|
||||
}
|
||||
sleep(1500);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System.err.println("Display mode change " +
|
||||
"not supported. Test passed.");
|
||||
}
|
||||
dispose();
|
||||
synchronized (lock) {
|
||||
done = true;
|
||||
lock.notify();
|
||||
}
|
||||
}
|
||||
|
||||
private void createBackbuffer() {
|
||||
if (bb == null ||
|
||||
bb.getWidth() != getWidth() || bb.getHeight() != getHeight())
|
||||
{
|
||||
bb = createVolatileImage(getWidth(), getHeight());
|
||||
}
|
||||
}
|
||||
|
||||
private void initBackbuffer() {
|
||||
createBackbuffer();
|
||||
|
||||
int res = bb.validate(getGraphicsConfiguration());
|
||||
if (res == VolatileImage.IMAGE_INCOMPATIBLE) {
|
||||
bb = null;
|
||||
createBackbuffer();
|
||||
bb.validate(getGraphicsConfiguration());
|
||||
res = VolatileImage.IMAGE_RESTORED;
|
||||
}
|
||||
if (res == VolatileImage.IMAGE_RESTORED) {
|
||||
Graphics g = bb.getGraphics();
|
||||
g.setColor(new Color(rnd.nextInt(0x00ffffff)));
|
||||
g.fillRect(0, 0, bb.getWidth(), bb.getHeight());
|
||||
|
||||
volSprite = createVolatileImage(100, 100);
|
||||
}
|
||||
volSprite.validate(getGraphicsConfiguration());
|
||||
}
|
||||
|
||||
private void selectDisplayModes() {
|
||||
GraphicsDevice gd =
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment().
|
||||
getDefaultScreenDevice();
|
||||
dms = new ArrayList<DisplayMode>();
|
||||
DisplayMode dmArray[] = gd.getDisplayModes();
|
||||
boolean found8 = false, found16 = false,
|
||||
found24 = false, found32 = false;
|
||||
for (DisplayMode dm : dmArray) {
|
||||
if (!found8 &&
|
||||
(dm.getBitDepth() == 8 ||
|
||||
dm.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI) &&
|
||||
(dm.getWidth() >= 800 && dm.getWidth() < 1024))
|
||||
{
|
||||
dms.add(dm);
|
||||
found8 = true;
|
||||
continue;
|
||||
}
|
||||
if (!found32 &&
|
||||
(dm.getBitDepth() == 32 ||
|
||||
dm.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI) &&
|
||||
dm.getWidth() >= 1280)
|
||||
{
|
||||
dms.add(dm);
|
||||
found32 = true;
|
||||
continue;
|
||||
}
|
||||
if (!found16 &&
|
||||
dm.getBitDepth() == 16 &&
|
||||
(dm.getWidth() >= 1024 && dm.getWidth() < 1280))
|
||||
{
|
||||
dms.add(dm);
|
||||
found16 = true;
|
||||
continue;
|
||||
}
|
||||
if (found8 && found16 && found32) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
System.err.println("Found display modes:");
|
||||
for (DisplayMode dm : dms) {
|
||||
System.err.printf("DisplayMode[%dx%dx%d]\n",
|
||||
dm.getWidth(), dm.getHeight(), dm.getBitDepth());
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
DisplayChangeVITest test = new DisplayChangeVITest();
|
||||
GraphicsDevice gd =
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment().
|
||||
getDefaultScreenDevice();
|
||||
if (gd.isFullScreenSupported()) {
|
||||
gd.setFullScreenWindow(test);
|
||||
Thread t = new Thread(test);
|
||||
t.run();
|
||||
synchronized (lock) {
|
||||
while (!done) {
|
||||
try {
|
||||
lock.wait(50);
|
||||
} catch (InterruptedException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
System.err.println("Test Passed.");
|
||||
} else {
|
||||
System.err.println("Full screen not supported. Test passed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
115
test/jdk/java/awt/FullScreen/DisplayModeNoRefreshTest.java
Normal file
115
test/jdk/java/awt/FullScreen/DisplayModeNoRefreshTest.java
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Copyright (c) 2004, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 5041225
|
||||
* @key headful
|
||||
* @summary Tests that we can set a display mode with unknown refresh rate
|
||||
* if corresponding system display mode (with equal w/h/d) is available.
|
||||
* @run main DisplayModeNoRefreshTest
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.DisplayMode;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
|
||||
public class DisplayModeNoRefreshTest extends Frame {
|
||||
|
||||
private static DisplayModeNoRefreshTest fs;
|
||||
|
||||
private static final GraphicsDevice gd =
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment()
|
||||
.getDefaultScreenDevice();
|
||||
|
||||
private static final DisplayMode origMode = gd.getDisplayMode();
|
||||
|
||||
public DisplayModeNoRefreshTest() {
|
||||
super("DisplayModeNoRefreshTest");
|
||||
if (!gd.isFullScreenSupported()) {
|
||||
System.out.println("Full Screen is not supported, test considered passed.");
|
||||
return;
|
||||
}
|
||||
setBackground(Color.green);
|
||||
gd.setFullScreenWindow(this);
|
||||
DisplayMode dlMode = getNoRefreshDisplayMode(gd.getDisplayModes());
|
||||
if (dlMode != null) {
|
||||
System.out.println("Selected Display Mode: " +
|
||||
" Width " + dlMode.getWidth() +
|
||||
" Height " + dlMode.getHeight() +
|
||||
" BitDepth " + dlMode.getBitDepth() +
|
||||
" Refresh Rate " + dlMode.getRefreshRate());
|
||||
try {
|
||||
gd.setDisplayMode(dlMode);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
throw new RuntimeException("Test Failed due to IAE", ex);
|
||||
}
|
||||
} else {
|
||||
System.out.println("No suitable display mode available, test considered passed.");
|
||||
return;
|
||||
}
|
||||
|
||||
try { Thread.sleep(2000); } catch (InterruptedException e) {}
|
||||
|
||||
System.out.println("Test Passed.");
|
||||
}
|
||||
|
||||
public DisplayMode getNoRefreshDisplayMode(DisplayMode dm[]) {
|
||||
DisplayMode mode = new DisplayMode(640, 480, 32, DisplayMode.REFRESH_RATE_UNKNOWN);
|
||||
int i = 0;
|
||||
for (i = 0; i < dm.length; i++) {
|
||||
if (mode.getWidth() == dm[i].getWidth()
|
||||
&& mode.getHeight() == dm[i].getHeight()
|
||||
&& mode.getBitDepth() == dm[i].getBitDepth()) {
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
if (dm.length > 0) {
|
||||
return
|
||||
new DisplayMode(dm[0].getWidth(), dm[0].getHeight(),
|
||||
dm[0].getBitDepth(),
|
||||
DisplayMode.REFRESH_RATE_UNKNOWN);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
try {
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
System.setProperty("sun.java2d.noddraw", "true");
|
||||
fs = new DisplayModeNoRefreshTest();
|
||||
});
|
||||
} finally {
|
||||
gd.setDisplayMode(origMode);
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
if (fs != null) {
|
||||
fs.dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,163 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.DisplayMode;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Robot;
|
||||
import java.awt.Window;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 8003173 7019055
|
||||
* @summary Full-screen windows should have the proper insets.
|
||||
* @author Sergey Bylokhov
|
||||
*/
|
||||
public final class FullScreenInsets {
|
||||
|
||||
private static boolean passed = true;
|
||||
private static Robot robot = null;
|
||||
|
||||
public static void main(final String[] args) {
|
||||
final GraphicsEnvironment ge = GraphicsEnvironment
|
||||
.getLocalGraphicsEnvironment();
|
||||
final GraphicsDevice[] devices = ge.getScreenDevices();
|
||||
|
||||
final Window wGreen = new Frame();
|
||||
wGreen.setBackground(Color.GREEN);
|
||||
wGreen.setSize(300, 300);
|
||||
wGreen.setVisible(true);
|
||||
sleep();
|
||||
final Insets iGreen = wGreen.getInsets();
|
||||
final Dimension sGreen = wGreen.getSize();
|
||||
|
||||
final Window wRed = new Frame();
|
||||
wRed.setBackground(Color.RED);
|
||||
wRed.setSize(300, 300);
|
||||
wRed.setVisible(true);
|
||||
sleep();
|
||||
final Insets iRed = wGreen.getInsets();
|
||||
final Dimension sRed = wGreen.getSize();
|
||||
|
||||
for (final GraphicsDevice device : devices) {
|
||||
if (!device.isFullScreenSupported()) {
|
||||
continue;
|
||||
}
|
||||
device.setFullScreenWindow(wGreen);
|
||||
sleep();
|
||||
testWindowBounds(device.getDisplayMode(), wGreen);
|
||||
testColor(wGreen, Color.GREEN);
|
||||
|
||||
device.setFullScreenWindow(wRed);
|
||||
sleep();
|
||||
testWindowBounds(device.getDisplayMode(), wRed);
|
||||
testColor(wRed, Color.RED);
|
||||
|
||||
device.setFullScreenWindow(null);
|
||||
sleep();
|
||||
testInsets(wGreen.getInsets(), iGreen);
|
||||
testInsets(wRed.getInsets(), iRed);
|
||||
testSize(wGreen.getSize(), sGreen);
|
||||
testSize(wRed.getSize(), sRed);
|
||||
}
|
||||
wGreen.dispose();
|
||||
wRed.dispose();
|
||||
if (!passed) {
|
||||
throw new RuntimeException("Test failed");
|
||||
}
|
||||
}
|
||||
|
||||
private static void testSize(final Dimension actual, final Dimension exp) {
|
||||
if (!exp.equals(actual)) {
|
||||
System.err.println(" Wrong window size:" +
|
||||
" Expected: " + exp + " Actual: " + actual);
|
||||
passed = false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void testInsets(final Insets actual, final Insets exp) {
|
||||
if (!actual.equals(exp)) {
|
||||
System.err.println(" Wrong window insets:" +
|
||||
" Expected: " + exp + " Actual: " + actual);
|
||||
passed = false;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
private static void testColor(final Window w, final Color color) {
|
||||
final Robot r;
|
||||
try {
|
||||
r = new Robot(w.getGraphicsConfiguration().getDevice());
|
||||
} catch (AWTException e) {
|
||||
e.printStackTrace();
|
||||
passed = false;
|
||||
return;
|
||||
}
|
||||
final BufferedImage bi = r.createScreenCapture(w.getBounds());
|
||||
for (int y = 0; y < bi.getHeight(); y++) {
|
||||
for (int x = 0; x < bi.getWidth(); x++) {
|
||||
if (bi.getRGB(x, y) != color.getRGB()) {
|
||||
System.err.println(
|
||||
"Incorrect pixel at " + x + "x" + y + " : " +
|
||||
Integer.toHexString(bi.getRGB(x, y)) +
|
||||
" ,expected : " + Integer.toHexString(
|
||||
color.getRGB()));
|
||||
passed = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void sleep() {
|
||||
if(robot == null) {
|
||||
try {
|
||||
robot = new Robot();
|
||||
}catch(AWTException ae) {
|
||||
ae.printStackTrace();
|
||||
throw new RuntimeException("Cannot create Robot.");
|
||||
}
|
||||
}
|
||||
robot.waitForIdle();
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.DisplayMode;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8211999 8282863
|
||||
* @key headful
|
||||
* @summary verifies the full-screen window bounds and graphics configuration
|
||||
*/
|
||||
public final class FullscreenWindowProps {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
var ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice gd = ge.getDefaultScreenDevice();
|
||||
|
||||
if (!gd.isFullScreenSupported()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Frame frame = new Frame() {
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
g.setColor(Color.GREEN);
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
g.setColor(Color.RED);
|
||||
DisplayMode displayMode =
|
||||
getGraphicsConfiguration().getDevice().getDisplayMode();
|
||||
g.drawString(displayMode.toString(), 100, 100);
|
||||
}
|
||||
};
|
||||
try {
|
||||
frame.setUndecorated(true); // workaround JDK-8256257
|
||||
frame.setBackground(Color.MAGENTA);
|
||||
frame.setVisible(true);
|
||||
gd.setFullScreenWindow(frame);
|
||||
Thread.sleep(4000);
|
||||
|
||||
for (DisplayMode dm : gd.getDisplayModes()) {
|
||||
if (dm.getWidth() == 1024 && dm.getHeight() == 768) {
|
||||
gd.setDisplayMode(dm);
|
||||
Thread.sleep(4000);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GraphicsConfiguration frameGC = frame.getGraphicsConfiguration();
|
||||
Rectangle frameBounds = frame.getBounds();
|
||||
|
||||
GraphicsConfiguration screenGC = gd.getDefaultConfiguration();
|
||||
Rectangle screenBounds = screenGC.getBounds();
|
||||
|
||||
if (frameGC != screenGC) {
|
||||
System.err.println("Expected: " + screenGC);
|
||||
System.err.println("Actual: " + frameGC);
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
checkSize(frameBounds.x, screenBounds.x, "x");
|
||||
checkSize(frameBounds.y, screenBounds.y, "Y");
|
||||
checkSize(frameBounds.width, screenBounds.width, "width");
|
||||
checkSize(frameBounds.height, screenBounds.height, "height");
|
||||
} finally {
|
||||
gd.setFullScreenWindow(null);
|
||||
frame.dispose();
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkSize(int actual, int expected, String prop) {
|
||||
if (Math.abs(actual - expected) > 30) { // let's allow size variation,
|
||||
// the bug is reproduced anyway
|
||||
System.err.println("Expected: " + expected);
|
||||
System.err.println("Actual: " + actual);
|
||||
throw new RuntimeException(prop + " is wrong");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
@test
|
||||
@key headful
|
||||
@bug 8129116
|
||||
@summary Deadlock with multimonitor fullscreen windows.
|
||||
@run main/timeout=20 MultimonDeadlockTest
|
||||
*/
|
||||
import java.awt.*;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class MultimonDeadlockTest {
|
||||
|
||||
public static void main(String argv[]) {
|
||||
final GraphicsDevice[] devices = GraphicsEnvironment
|
||||
.getLocalGraphicsEnvironment()
|
||||
.getScreenDevices();
|
||||
if (devices.length < 2) {
|
||||
System.out.println("It's a multiscreen test... skipping!");
|
||||
return;
|
||||
}
|
||||
|
||||
Frame frames[] = new Frame[devices.length];
|
||||
try {
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
for (int i = 0; i < devices.length; i++) {
|
||||
frames[i] = new Frame();
|
||||
frames[i].setSize(100, 100);
|
||||
frames[i].setBackground(Color.BLUE);
|
||||
devices[i].setFullScreenWindow(frames[i]);
|
||||
}
|
||||
});
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException | InvocationTargetException ex) {
|
||||
} finally {
|
||||
for (int i = 0; i < devices.length; i++) {
|
||||
devices[i].setFullScreenWindow(null);
|
||||
frames[i].dispose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,382 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 5041219 5101561 5035272 5096011 5101712 5098624 8198613
|
||||
* @summary Here are a few assertions worth verification:
|
||||
* - the fullscreen window is positioned at 0,0
|
||||
* - the fs window appears on the correct screen
|
||||
* - if the exclusive FS mode is supported, no other widndow should
|
||||
* overlap the fs window (including the taskbar).
|
||||
* You could, however, alt+tab out of a fullscreen window, or at least
|
||||
* minimize it (if you've entered the fs mode with a Window, you'll need
|
||||
* to minimize the owner frame).
|
||||
* Note that there may be issues with FS exclusive mode with ddraw and
|
||||
* multiple fullscreen windows (one per device).
|
||||
* - if display mode is supported that it did change
|
||||
* - that the original display mode is restored once
|
||||
* the ws window is disposed
|
||||
* All of the above should work with and w/o DirectDraw
|
||||
* (-Dsun.java2d.noddraw=true) on windows, and w/ and w/o opengl on X11
|
||||
* (-Dsun.java2d.opengl=True).
|
||||
* @run main/manual/othervm -Dsun.java2d.pmoffscreen=true MultimonFullscreenTest
|
||||
* @run main/manual/othervm -Dsun.java2d.pmoffscreen=false MultimonFullscreenTest
|
||||
* @run main/manual/othervm -Dsun.java2d.d3d=True MultimonFullscreenTest
|
||||
* @run main/manual/othervm -Dsun.java2d.noddraw=true MultimonFullscreenTest
|
||||
* @run main/manual/othervm MultimonFullscreenTest
|
||||
*/
|
||||
|
||||
import java.awt.Button;
|
||||
import java.awt.Checkbox;
|
||||
import java.awt.CheckboxGroup;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.DisplayMode;
|
||||
import java.awt.Font;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Panel;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.image.BufferStrategy;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
public class MultimonFullscreenTest extends Frame implements ActionListener {
|
||||
GraphicsDevice defDev = GraphicsEnvironment.getLocalGraphicsEnvironment().
|
||||
getDefaultScreenDevice();
|
||||
GraphicsDevice gd[] = GraphicsEnvironment.getLocalGraphicsEnvironment().
|
||||
getScreenDevices();
|
||||
HashMap<Button, GraphicsDevice> deviceMap;
|
||||
|
||||
private static boolean dmChange = false;
|
||||
static boolean setNullOnDispose = false;
|
||||
static boolean useFSFrame = true;
|
||||
static boolean useFSWindow = false;
|
||||
static boolean useFSDialog = false;
|
||||
static boolean useBS = false;
|
||||
static boolean runRenderLoop = false;
|
||||
static boolean addHWChildren = false;
|
||||
static volatile boolean done = true;
|
||||
|
||||
public MultimonFullscreenTest(String title) {
|
||||
super(title);
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
Panel p = new Panel();
|
||||
deviceMap = new HashMap<Button, GraphicsDevice>(gd.length);
|
||||
int num = 0;
|
||||
for (GraphicsDevice dev : gd) {
|
||||
Button b;
|
||||
if (dev == defDev) {
|
||||
b = new Button("Primary screen: " + num);
|
||||
System.out.println("Primary Dev : " + dev + " Bounds: " +
|
||||
dev.getDefaultConfiguration().getBounds());
|
||||
} else {
|
||||
b = new Button("Secondary screen " + num);
|
||||
System.out.println("Secondary Dev : " + dev + " Bounds: " +
|
||||
dev.getDefaultConfiguration().getBounds());
|
||||
}
|
||||
b.addActionListener(this);
|
||||
p.add(b);
|
||||
deviceMap.put(b, dev);
|
||||
num++;
|
||||
}
|
||||
add("South", p);
|
||||
Panel p1 = new Panel();
|
||||
p1.setLayout(new GridLayout(2,0));
|
||||
Checkbox cb = new Checkbox("Change DM on entering FS");
|
||||
cb.addItemListener(new ItemListener() {
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
dmChange = ((Checkbox)e.getSource()).getState();
|
||||
}
|
||||
});
|
||||
p1.add(cb);
|
||||
// cb = new Checkbox("Exit FS on window dispose");
|
||||
// cb.addItemListener(new ItemListener() {
|
||||
// public void itemStateChanged(ItemEvent e) {
|
||||
// setNullOnDispose = ((Checkbox)e.getSource()).getState();
|
||||
// }
|
||||
// });
|
||||
// p1.add(cb);
|
||||
CheckboxGroup cbg = new CheckboxGroup();
|
||||
cb = new Checkbox("Use Frame to enter FS", cbg, true);
|
||||
cb.addItemListener(new ItemListener() {
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
useFSFrame = true;
|
||||
useFSWindow = false;
|
||||
useFSDialog = false;
|
||||
}
|
||||
});
|
||||
p1.add(cb);
|
||||
cb = new Checkbox("Use Window to enter FS", cbg, false);
|
||||
cb.addItemListener(new ItemListener() {
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
useFSFrame = false;
|
||||
useFSWindow = true;
|
||||
useFSDialog = false;
|
||||
}
|
||||
});
|
||||
p1.add(cb);
|
||||
cb = new Checkbox("Use Dialog to enter FS", cbg, false);
|
||||
cb.addItemListener(new ItemListener() {
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
useFSFrame = false;
|
||||
useFSWindow = false;
|
||||
useFSDialog = true;
|
||||
}
|
||||
});
|
||||
p1.add(cb);
|
||||
cb = new Checkbox("Run render loop");
|
||||
cb.addItemListener(new ItemListener() {
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
runRenderLoop = ((Checkbox)e.getSource()).getState();
|
||||
}
|
||||
});
|
||||
p1.add(cb);
|
||||
cb = new Checkbox("Use BufferStrategy in render loop");
|
||||
cb.addItemListener(new ItemListener() {
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
useBS = ((Checkbox)e.getSource()).getState();
|
||||
}
|
||||
});
|
||||
p1.add(cb);
|
||||
cb = new Checkbox("Add Children to FS window");
|
||||
cb.addItemListener(new ItemListener() {
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
addHWChildren = ((Checkbox)e.getSource()).getState();
|
||||
}
|
||||
});
|
||||
p1.add(cb);
|
||||
add("North", p1);
|
||||
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
Font f = new Font("Dialog", Font.BOLD, 24);
|
||||
Random rnd = new Random();
|
||||
public void renderDimensions(Graphics g, Rectangle rectWndBounds,
|
||||
GraphicsConfiguration gc) {
|
||||
g.setColor(new Color(rnd.nextInt(0xffffff)));
|
||||
g.fillRect(0, 0, rectWndBounds.width, rectWndBounds.height);
|
||||
|
||||
g.setColor(new Color(rnd.nextInt(0xffffff)));
|
||||
Rectangle rectStrBounds;
|
||||
|
||||
g.setFont(f);
|
||||
|
||||
rectStrBounds = g.getFontMetrics().
|
||||
getStringBounds(rectWndBounds.toString(), g).getBounds();
|
||||
rectStrBounds.height += 30;
|
||||
g.drawString(rectWndBounds.toString(), 50, rectStrBounds.height);
|
||||
int oldHeight = rectStrBounds.height;
|
||||
String isFSupported = "Exclusive Fullscreen mode supported: " +
|
||||
gc.getDevice().isFullScreenSupported();
|
||||
rectStrBounds = g.getFontMetrics().
|
||||
getStringBounds(isFSupported, g).getBounds();
|
||||
rectStrBounds.height += (10 + oldHeight);
|
||||
g.drawString(isFSupported, 50, rectStrBounds.height);
|
||||
|
||||
oldHeight = rectStrBounds.height;
|
||||
String isDMChangeSupported = "Display Mode Change supported: " +
|
||||
gc.getDevice().isDisplayChangeSupported();
|
||||
rectStrBounds = g.getFontMetrics().
|
||||
getStringBounds(isDMChangeSupported, g).getBounds();
|
||||
rectStrBounds.height += (10 + oldHeight);
|
||||
g.drawString(isDMChangeSupported, 50, rectStrBounds.height);
|
||||
|
||||
oldHeight = rectStrBounds.height;
|
||||
String usingBS = "Using BufferStrategy: " + useBS;
|
||||
rectStrBounds = g.getFontMetrics().
|
||||
getStringBounds(usingBS, g).getBounds();
|
||||
rectStrBounds.height += (10 + oldHeight);
|
||||
g.drawString(usingBS, 50, rectStrBounds.height);
|
||||
|
||||
final String m_strQuitMsg = "Double-click to dispose FullScreen Window";
|
||||
rectStrBounds = g.getFontMetrics().
|
||||
getStringBounds(m_strQuitMsg, g).getBounds();
|
||||
g.drawString(m_strQuitMsg,
|
||||
(rectWndBounds.width - rectStrBounds.width) / 2,
|
||||
(rectWndBounds.height - rectStrBounds.height) / 2);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent ae) {
|
||||
GraphicsDevice dev = deviceMap.get(ae.getSource());
|
||||
System.err.println("Setting FS on device:"+dev);
|
||||
final Window fsWindow;
|
||||
|
||||
if (useFSWindow) {
|
||||
fsWindow = new Window(this, dev.getDefaultConfiguration()) {
|
||||
public void paint(Graphics g) {
|
||||
renderDimensions(g, getBounds(),
|
||||
this.getGraphicsConfiguration());
|
||||
}
|
||||
};
|
||||
} else if (useFSDialog) {
|
||||
fsWindow = new Dialog((Frame)null, "FS Dialog on device "+dev, false,
|
||||
dev.getDefaultConfiguration());
|
||||
fsWindow.add(new Component() {
|
||||
public void paint(Graphics g) {
|
||||
renderDimensions(g, getBounds(),
|
||||
this.getGraphicsConfiguration());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
fsWindow = new Frame("FS Frame on device "+dev,
|
||||
dev.getDefaultConfiguration())
|
||||
{
|
||||
public void paint(Graphics g) {
|
||||
renderDimensions(g, getBounds(),
|
||||
this.getGraphicsConfiguration());
|
||||
}
|
||||
};
|
||||
if (addHWChildren) {
|
||||
fsWindow.add("South", new Panel() {
|
||||
public void paint(Graphics g) {
|
||||
g.setColor(Color.red);
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
}
|
||||
});
|
||||
fsWindow.add("North", new Button("Button, sucka!"));
|
||||
}
|
||||
}
|
||||
fsWindow.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.getClickCount() > 1) {
|
||||
done = true;
|
||||
fsWindow.dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
fsWindow.addWindowListener(new WindowHandler());
|
||||
dev.setFullScreenWindow(fsWindow);
|
||||
if (dmChange && dev.isDisplayChangeSupported()) {
|
||||
DisplayMode dms[] = dev.getDisplayModes();
|
||||
DisplayMode myDM = null;
|
||||
for (DisplayMode dm : dms) {
|
||||
if (dm.getWidth() == 800 && dm.getHeight() == 600 &&
|
||||
(dm.getBitDepth() >= 16 ||
|
||||
dm.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI) &&
|
||||
(dm.getRefreshRate() >= 60 ||
|
||||
dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN))
|
||||
{
|
||||
myDM = dm;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (myDM != null) {
|
||||
System.err.println("Setting Display Mode: "+
|
||||
myDM.getWidth() + "x" + myDM.getHeight() + "x" +
|
||||
myDM.getBitDepth() + "@" + myDM.getRefreshRate() +
|
||||
"Hz on device" + dev);
|
||||
dev.setDisplayMode(myDM);
|
||||
} else {
|
||||
System.err.println("Can't find suitable display mode.");
|
||||
}
|
||||
}
|
||||
done = false;
|
||||
if (runRenderLoop) {
|
||||
Thread updateThread = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
BufferStrategy bs = null;
|
||||
if (useBS) {
|
||||
fsWindow.createBufferStrategy(2);
|
||||
bs = fsWindow.getBufferStrategy();
|
||||
}
|
||||
while (!done) {
|
||||
if (useBS) {
|
||||
Graphics g = bs.getDrawGraphics();
|
||||
renderDimensions(g, fsWindow.getBounds(),
|
||||
fsWindow.getGraphicsConfiguration());
|
||||
bs.show();
|
||||
} else {
|
||||
fsWindow.repaint();
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
if (useBS) {
|
||||
bs.dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
updateThread.start();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
for (String s : args) {
|
||||
if (s.equalsIgnoreCase("-dm")) {
|
||||
System.err.println("Do Display Change after entering FS mode");
|
||||
dmChange = true;
|
||||
} else if (s.equalsIgnoreCase("-usewindow")) {
|
||||
System.err.println("Using Window to enter FS mode");
|
||||
useFSWindow = true;
|
||||
} else if (s.equalsIgnoreCase("-setnull")) {
|
||||
System.err.println("Setting null FS window on dispose");
|
||||
setNullOnDispose = true;
|
||||
} else {
|
||||
System.err.println("Usage: MultimonFullscreenTest " +
|
||||
"[-dm][-usewindow][-setnull]");
|
||||
}
|
||||
|
||||
}
|
||||
MultimonFullscreenTest fs =
|
||||
new MultimonFullscreenTest("Test Full Screen");
|
||||
}
|
||||
class WindowHandler extends WindowAdapter {
|
||||
public void windowClosing(WindowEvent we) {
|
||||
done = true;
|
||||
Window w = (Window)we.getSource();
|
||||
if (setNullOnDispose) {
|
||||
w.getGraphicsConfiguration().getDevice().setFullScreenWindow(null);
|
||||
}
|
||||
w.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,278 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 6646411
|
||||
* @summary Tests that full screen window and its children receive resize
|
||||
event when display mode changes
|
||||
* @library /test/lib
|
||||
* @build jdk.test.lib.Platform jtreg.SkippedException
|
||||
* @run main/othervm NoResizeEventOnDMChangeTest
|
||||
* @run main/othervm -Dsun.java2d.d3d=false NoResizeEventOnDMChangeTest
|
||||
*/
|
||||
|
||||
import java.awt.Canvas;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.DisplayMode;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import jdk.test.lib.Platform;
|
||||
import jtreg.SkippedException;
|
||||
|
||||
public class NoResizeEventOnDMChangeTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (Platform.isOnWayland() && !isFixDelivered()) {
|
||||
throw new SkippedException("Test skipped because fix was not" +
|
||||
"delivered in current GnomeShell version");
|
||||
}
|
||||
|
||||
final GraphicsDevice gd = GraphicsEnvironment.
|
||||
getLocalGraphicsEnvironment().getDefaultScreenDevice();
|
||||
|
||||
if (!gd.isFullScreenSupported()) {
|
||||
System.out.println("Full screen not supported, test passed");
|
||||
return;
|
||||
}
|
||||
|
||||
DisplayMode dm = gd.getDisplayMode();
|
||||
final DisplayMode dms[] = new DisplayMode[2];
|
||||
for (DisplayMode dm1 : gd.getDisplayModes()) {
|
||||
if (dm1.getWidth() != dm.getWidth() ||
|
||||
dm1.getHeight() != dm.getHeight())
|
||||
{
|
||||
dms[0] = dm1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (dms[0] == null) {
|
||||
System.out.println("Test Passed: all DMs have same dimensions");
|
||||
return;
|
||||
}
|
||||
dms[1] = dm;
|
||||
|
||||
Frame f = new Frame() {
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
g.setColor(Color.red);
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
g.setColor(Color.green);
|
||||
g.drawRect(0, 0, getWidth()-1, getHeight()-1);
|
||||
}
|
||||
};
|
||||
f.setUndecorated(true);
|
||||
testFSWindow(gd, dms, f);
|
||||
|
||||
Window w = new Window(f) {
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
g.setColor(Color.magenta);
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
g.setColor(Color.cyan);
|
||||
g.drawRect(0, 0, getWidth()-1, getHeight()-1);
|
||||
}
|
||||
};
|
||||
testFSWindow(gd, dms, w);
|
||||
System.out.println("Test Passed.");
|
||||
}
|
||||
|
||||
private static void testFSWindow(final GraphicsDevice gd,
|
||||
final DisplayMode dms[],
|
||||
final Window fsWin)
|
||||
{
|
||||
System.out.println("Testing FS window: "+fsWin);
|
||||
Component c = new Canvas() {
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
g.setColor(Color.blue);
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
g.setColor(Color.magenta);
|
||||
g.drawRect(0, 0, getWidth()-1, getHeight()-1);
|
||||
g.setColor(Color.red);
|
||||
g.drawString("FS Window : " + fsWin, 50, 50);
|
||||
DisplayMode dm =
|
||||
getGraphicsConfiguration().getDevice().getDisplayMode();
|
||||
g.drawString("Display Mode: " +
|
||||
dm.getWidth() + "x" + dm.getHeight(), 50, 75);
|
||||
}
|
||||
};
|
||||
fsWin.add("Center", c);
|
||||
fsWin.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
fsWin.dispose();
|
||||
if (fsWin.getOwner() != null) {
|
||||
fsWin.getOwner().dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
EventQueue.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
gd.setFullScreenWindow(fsWin);
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {}
|
||||
|
||||
sleep(1000);
|
||||
|
||||
final ResizeEventChecker r1 = new ResizeEventChecker();
|
||||
final ResizeEventChecker r2 = new ResizeEventChecker();
|
||||
|
||||
if (gd.isDisplayChangeSupported()) {
|
||||
fsWin.addComponentListener(r1);
|
||||
c.addComponentListener(r2);
|
||||
for (final DisplayMode dm1 : dms) {
|
||||
try {
|
||||
EventQueue.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
System.err.printf("----------- Setting DM %dx%d:\n",
|
||||
dm1.getWidth(), dm1.getHeight());
|
||||
try {
|
||||
Frame f = fsWin instanceof Frame ? (Frame) fsWin : (Frame) fsWin.getOwner();
|
||||
DisplayMode oldMode = f.getGraphicsConfiguration().getDevice().getDisplayMode();
|
||||
gd.setDisplayMode(dm1);
|
||||
sleep(2000);
|
||||
// Check if setting new display mode actually results in frame being
|
||||
// placed onto display with different resolution.
|
||||
DisplayMode newMode = f.getGraphicsConfiguration().getDevice().getDisplayMode();
|
||||
if (oldMode.getWidth() != newMode.getWidth()
|
||||
|| oldMode.getHeight() != newMode.getHeight()) {
|
||||
r1.incDmChanges();
|
||||
r2.incDmChanges();
|
||||
} else {
|
||||
System.out.println("Skipping this iteration. Details:");
|
||||
System.out.println("Requested device = " + gd);
|
||||
System.out.println("Actual device = " + f.getGraphicsConfiguration().getDevice());
|
||||
}
|
||||
} catch (IllegalArgumentException iae) {}
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {}
|
||||
for (int i = 0; i < 3; i++) {
|
||||
fsWin.repaint();
|
||||
sleep(1000);
|
||||
}
|
||||
}
|
||||
fsWin.removeComponentListener(r1);
|
||||
c.removeComponentListener(r2);
|
||||
}
|
||||
|
||||
try {
|
||||
EventQueue.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
gd.setFullScreenWindow(null);
|
||||
fsWin.dispose();
|
||||
if (fsWin.getOwner() != null) {
|
||||
fsWin.getOwner().dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Exception ex) {}
|
||||
|
||||
System.out.printf("FS Window: resizes=%d, dm changes=%d\n",
|
||||
r1.getResizes(), r1.getDmChanges());
|
||||
System.out.printf("Component: resizes=%d, dm changes=%d\n",
|
||||
r2.getResizes(), r2.getDmChanges());
|
||||
if (r1.getResizes() < r1.getDmChanges()) {
|
||||
throw new RuntimeException("FS Window didn't receive all resizes!");
|
||||
}
|
||||
if (r2.getResizes() < r2.getDmChanges()) {
|
||||
throw new RuntimeException("Component didn't receive all resizes!");
|
||||
}
|
||||
}
|
||||
|
||||
static void sleep(long ms) {
|
||||
long targetTime = System.currentTimeMillis() + ms;
|
||||
do {
|
||||
try {
|
||||
Thread.sleep(targetTime - System.currentTimeMillis());
|
||||
} catch (InterruptedException ex) {}
|
||||
} while (System.currentTimeMillis() < targetTime);
|
||||
}
|
||||
|
||||
static class ResizeEventChecker extends ComponentAdapter {
|
||||
int dmChanges;
|
||||
int resizes;
|
||||
|
||||
@Override
|
||||
public synchronized void componentResized(ComponentEvent e) {
|
||||
System.out.println("Received resize event for "+e.getSource());
|
||||
resizes++;
|
||||
}
|
||||
public synchronized int getResizes() {
|
||||
return resizes;
|
||||
}
|
||||
public synchronized void incDmChanges() {
|
||||
dmChanges++;
|
||||
}
|
||||
public synchronized int getDmChanges() {
|
||||
return dmChanges;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isFixDelivered() {
|
||||
try {
|
||||
Process process =
|
||||
new ProcessBuilder("/usr/bin/gnome-shell", "--version")
|
||||
.start();
|
||||
|
||||
try (BufferedReader reader = process.inputReader()) {
|
||||
if (process.waitFor(2, SECONDS) && process.exitValue() == 0) {
|
||||
String line = reader.readLine();
|
||||
if (line != null) {
|
||||
System.out.println("Gnome shell version: " + line);
|
||||
String[] versionComponents = line
|
||||
.replaceAll("[^\\d.]", "")
|
||||
.split("\\.");
|
||||
|
||||
if (versionComponents.length >= 1) {
|
||||
return Integer.parseInt(versionComponents[0]) > 42;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException
|
||||
| InterruptedException
|
||||
| IllegalThreadStateException
|
||||
| NumberFormatException ignored) {
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.awt.DisplayMode;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
import static java.awt.DisplayMode.REFRESH_RATE_UNKNOWN;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 6430607 8198613
|
||||
* @summary Test that we throw an exception for incorrect display modes
|
||||
* @author Dmitri.Trembovetski@Sun.COM area=FullScreen
|
||||
* @run main/othervm NonExistentDisplayModeTest
|
||||
* @run main/othervm -Dsun.java2d.noddraw=true NonExistentDisplayModeTest
|
||||
*/
|
||||
public class NonExistentDisplayModeTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new NonExistentDisplayModeTest().start();
|
||||
}
|
||||
|
||||
private void start() {
|
||||
Frame f = new Frame("Testing, please wait..");
|
||||
f.pack();
|
||||
GraphicsDevice gd = f.getGraphicsConfiguration().getDevice();
|
||||
if (!gd.isFullScreenSupported()) {
|
||||
System.out.println("Exclusive FS mode not supported, test passed.");
|
||||
f.dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
gd.setFullScreenWindow(f);
|
||||
if (!gd.isDisplayChangeSupported()) {
|
||||
System.out.println("DisplayMode change not supported, test passed.");
|
||||
f.dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
DisplayMode dms[] = gd.getDisplayModes();
|
||||
ArrayList<DisplayMode> dmList = new ArrayList<DisplayMode>(dms.length);
|
||||
for (DisplayMode dm : dms) {
|
||||
dmList.add(dm);
|
||||
}
|
||||
|
||||
ArrayList<DisplayMode> nonExistentDms = createNonExistentDMList(dmList);
|
||||
|
||||
for (DisplayMode dm : nonExistentDms) {
|
||||
boolean exThrown = false;
|
||||
try {
|
||||
System.out.printf("Testing mode: (%4dx%4d) depth=%3d rate=%d\n",
|
||||
dm.getWidth(), dm.getHeight(),
|
||||
dm.getBitDepth(), dm.getRefreshRate());
|
||||
gd.setDisplayMode(dm);
|
||||
} catch (IllegalArgumentException e) {
|
||||
exThrown = true;
|
||||
}
|
||||
if (!exThrown) {
|
||||
gd.setFullScreenWindow(null);
|
||||
f.dispose();
|
||||
throw new
|
||||
RuntimeException("Failed: No exception thrown for dm "+dm);
|
||||
}
|
||||
}
|
||||
gd.setFullScreenWindow(null);
|
||||
f.dispose();
|
||||
System.out.println("Test passed.");
|
||||
}
|
||||
|
||||
private static final Random rnd = new Random();
|
||||
private ArrayList<DisplayMode>
|
||||
createNonExistentDMList(ArrayList<DisplayMode> dmList)
|
||||
{
|
||||
ArrayList<DisplayMode> newList =
|
||||
new ArrayList<DisplayMode>(dmList.size());
|
||||
// vary one parameter at a time
|
||||
int param = 0;
|
||||
for (DisplayMode dm : dmList) {
|
||||
param = ++param % 3;
|
||||
switch (param) {
|
||||
case 0: {
|
||||
DisplayMode newDM = deriveSize(dm);
|
||||
if (!dmList.contains(newDM)) {
|
||||
newList.add(newDM);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
DisplayMode newDM = deriveDepth(dm);
|
||||
if (!dmList.contains(newDM)) {
|
||||
newList.add(newDM);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
if (dm.getRefreshRate() != REFRESH_RATE_UNKNOWN) {
|
||||
DisplayMode newDM = deriveRR(dm);
|
||||
if (!dmList.contains(newDM)) {
|
||||
newList.add(newDM);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return newList;
|
||||
}
|
||||
|
||||
private static DisplayMode deriveSize(DisplayMode dm) {
|
||||
int w = dm.getWidth() / 7;
|
||||
int h = dm.getHeight() / 3;
|
||||
return new DisplayMode(w, h, dm.getBitDepth(), dm.getRefreshRate());
|
||||
}
|
||||
private static DisplayMode deriveRR(DisplayMode dm) {
|
||||
return new DisplayMode(dm.getWidth(), dm.getHeight(),
|
||||
dm.getBitDepth(), 777);
|
||||
}
|
||||
private static DisplayMode deriveDepth(DisplayMode dm) {
|
||||
int depth;
|
||||
if (dm.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI) {
|
||||
depth = 77;
|
||||
} else {
|
||||
depth = DisplayMode.BIT_DEPTH_MULTI;
|
||||
}
|
||||
return new DisplayMode(dm.getWidth(), dm.getHeight(),
|
||||
depth, dm.getRefreshRate());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Button;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6225472 6682536
|
||||
* @requires (os.family != "linux")
|
||||
* @summary Tests that non-focusable Frame in full-screen mode overlaps the task bar.
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual NonfocusableFrameFullScreenTest
|
||||
*/
|
||||
|
||||
public class NonfocusableFrameFullScreenTest extends JPanel {
|
||||
boolean fullscreen = false;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
final String INSTRUCTIONS = """
|
||||
1. Press "Show Frame" button to show a Frame with two buttons.
|
||||
|
||||
2. Press the button "To Full Screen" to bring the frame to
|
||||
full-screen mode:
|
||||
|
||||
The frame should overlap the taskbar
|
||||
|
||||
3. Press "To Windowed" button:
|
||||
The frame should return to its original size.
|
||||
The frame shouldn't be alwaysOnTop.
|
||||
|
||||
4. Press "Set Always On Top" button and make sure the frame
|
||||
is alwaysOnTop, then press "To Full Screen" button
|
||||
and then "To Windowed" button:
|
||||
|
||||
The frame should return to its original size keeping alwaysOnTop
|
||||
state on.
|
||||
|
||||
Press Pass if everything is as expected.""";
|
||||
|
||||
PassFailJFrame.builder()
|
||||
.instructions(INSTRUCTIONS)
|
||||
.columns(45)
|
||||
.testUI(NonfocusableFrameFullScreenTest::new)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
private NonfocusableFrameFullScreenTest() {
|
||||
Button b = new Button("Show Frame");
|
||||
b.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
showFrame();
|
||||
}
|
||||
});
|
||||
setLayout(new BorderLayout());
|
||||
add(b, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(200, 100);
|
||||
}
|
||||
|
||||
public void showFrame() {
|
||||
Frame frame = new Frame("Test Frame");
|
||||
|
||||
Button button = new Button("To Full Screen");
|
||||
button.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (fullscreen) {
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().
|
||||
setFullScreenWindow(null);
|
||||
button.setLabel("To Full Screen");
|
||||
fullscreen = false;
|
||||
} else {
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().
|
||||
setFullScreenWindow(frame);
|
||||
button.setLabel("To Windowed");
|
||||
fullscreen = true;
|
||||
}
|
||||
frame.validate();
|
||||
}
|
||||
});
|
||||
|
||||
Button button2 = new Button("Set Always On Top");
|
||||
button2.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (frame.isAlwaysOnTop()) {
|
||||
button2.setLabel("Set Always On Top");
|
||||
frame.setAlwaysOnTop(false);
|
||||
} else {
|
||||
button2.setLabel("Set Not Always On Top");
|
||||
frame.setAlwaysOnTop(true);
|
||||
}
|
||||
frame.validate();
|
||||
}
|
||||
});
|
||||
|
||||
frame.setLayout(new BorderLayout());
|
||||
frame.add(button, BorderLayout.WEST);
|
||||
frame.add(button2, BorderLayout.EAST);
|
||||
frame.setBounds(400, 200, 350, 100);
|
||||
frame.setFocusableWindowState(false);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
202
test/jdk/java/awt/FullScreen/SetFSWindow/FSFrame.java
Normal file
202
test/jdk/java/awt/FullScreen/SetFSWindow/FSFrame.java
Normal file
|
|
@ -0,0 +1,202 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 6240507 6662642
|
||||
* @summary verify that isFullScreenSupported and getFullScreenWindow work
|
||||
* correctly. Note that the test may fail on older Gnome versions (see bug 6500686).
|
||||
* @run main FSFrame
|
||||
* @run main/othervm -Dsun.java2d.noddraw=true FSFrame
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Robot;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class FSFrame extends Frame implements Runnable {
|
||||
|
||||
// Don't start the test until the window is visible
|
||||
boolean visible = false;
|
||||
Robot robot = null;
|
||||
static volatile boolean done = false;
|
||||
|
||||
public void paint(Graphics g) {
|
||||
if (!visible && getWidth() != 0 && getHeight() != 0) {
|
||||
visible = true;
|
||||
try {
|
||||
GraphicsDevice gd = getGraphicsConfiguration().getDevice();
|
||||
robot = new Robot(gd);
|
||||
} catch (Exception e) {
|
||||
System.out.println("Problem creating robot: cannot verify FS " +
|
||||
"window display");
|
||||
}
|
||||
}
|
||||
g.setColor(Color.green);
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Graphics g) {
|
||||
paint(g);
|
||||
}
|
||||
|
||||
boolean checkColor(int x, int y, BufferedImage bImg) {
|
||||
int pixelColor;
|
||||
int correctColor = Color.green.getRGB();
|
||||
pixelColor = bImg.getRGB(x, y);
|
||||
if (pixelColor != correctColor) {
|
||||
System.out.println("FAILURE: pixelColor " +
|
||||
Integer.toHexString(pixelColor) +
|
||||
" != correctColor " +
|
||||
Integer.toHexString(correctColor) +
|
||||
" at coordinates (" + x + ", " + y + ")");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void checkFSDisplay(boolean fsSupported) {
|
||||
GraphicsConfiguration gc = getGraphicsConfiguration();
|
||||
GraphicsDevice gd = gc.getDevice();
|
||||
Rectangle r = gc.getBounds();
|
||||
Insets in = null;
|
||||
if (!fsSupported) {
|
||||
in = Toolkit.getDefaultToolkit().getScreenInsets(gc);
|
||||
r = new Rectangle(in.left, in.top,
|
||||
r.width - (in.left + in.right),
|
||||
r.height - (in.top + in.bottom));
|
||||
}
|
||||
BufferedImage bImg = robot.createScreenCapture(r);
|
||||
// Check that all four corners and middle pixel match the window's
|
||||
// fill color
|
||||
if (robot == null) {
|
||||
return;
|
||||
}
|
||||
boolean colorCorrect = true;
|
||||
colorCorrect &= checkColor(0, 0, bImg);
|
||||
colorCorrect &= checkColor(0, bImg.getHeight() - 1, bImg);
|
||||
colorCorrect &= checkColor(bImg.getWidth() - 1, 0, bImg);
|
||||
colorCorrect &= checkColor(bImg.getWidth() - 1, bImg.getHeight() - 1, bImg);
|
||||
colorCorrect &= checkColor(bImg.getWidth() / 2, bImg.getHeight() / 2, bImg);
|
||||
if (!colorCorrect) {
|
||||
System.err.println("Test failed for mode: fsSupported="+fsSupported);
|
||||
if (in != null) {
|
||||
System.err.println("screen insets : " + in);
|
||||
}
|
||||
System.err.println("screen shot rect: " + r);
|
||||
String name = "FSFrame_fs_"+
|
||||
(fsSupported?"supported":"not_supported")+".png";
|
||||
try {
|
||||
ImageIO.write(bImg, "png", new File(name));
|
||||
System.out.println("Dumped screen shot to "+name);
|
||||
} catch (IOException ex) {}
|
||||
throw new Error("Some pixel colors not correct; FS window may not" +
|
||||
" have been displayed correctly");
|
||||
}
|
||||
}
|
||||
|
||||
void checkFSFunctionality() {
|
||||
GraphicsDevice gd = getGraphicsConfiguration().getDevice();
|
||||
try {
|
||||
// None of these should throw an exception
|
||||
final boolean fs = gd.isFullScreenSupported();
|
||||
System.out.println("FullscreenSupported: " + (fs ? "yes" : "no"));
|
||||
gd.setFullScreenWindow(this);
|
||||
try {
|
||||
// Give the system time to set the FS window and display it
|
||||
// properly
|
||||
Thread.sleep(2000);
|
||||
} catch (Exception e) {}
|
||||
// See if FS window got displayed correctly
|
||||
try {
|
||||
EventQueue.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
repaint();
|
||||
checkFSDisplay(fs);
|
||||
}
|
||||
});
|
||||
} catch (InvocationTargetException | InterruptedException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
// reset window
|
||||
gd.setFullScreenWindow(null);
|
||||
try {
|
||||
// Give the system time to set the FS window and display it
|
||||
// properly
|
||||
Thread.sleep(2000);
|
||||
} catch (Exception e) {}
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
throw new Error("Failure: should not get an exception when " +
|
||||
"calling isFSSupported or setFSWindow");
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
boolean firstTime = true;
|
||||
while (!done) {
|
||||
if (visible) {
|
||||
checkFSFunctionality();
|
||||
done = true;
|
||||
} else {
|
||||
// sleep while we wait
|
||||
try {
|
||||
// Give the system time to set the FS window and display it
|
||||
// properly
|
||||
Thread.sleep(100);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
System.out.println("PASS");
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
FSFrame frame = new FSFrame();
|
||||
frame.setUndecorated(true);
|
||||
Thread t = new Thread(frame);
|
||||
frame.setSize(500, 500);
|
||||
frame.setVisible(true);
|
||||
t.start();
|
||||
while (!done) {
|
||||
try {
|
||||
// Do not exit the main thread until the test is finished
|
||||
Thread.sleep(1000);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
frame.dispose();
|
||||
}
|
||||
}
|
||||
89
test/jdk/java/awt/FullScreen/SetFullScreenTest.java
Normal file
89
test/jdk/java/awt/FullScreen/SetFullScreenTest.java
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Robot;
|
||||
import jtreg.SkippedException;
|
||||
|
||||
import static java.awt.EventQueue.invokeAndWait;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 8312518
|
||||
* @library /test/lib
|
||||
* @summary Setting fullscreen window using setFullScreenWindow() shows up
|
||||
* as black screen on newer macOS versions (13 & 14).
|
||||
*/
|
||||
|
||||
public class SetFullScreenTest {
|
||||
private static Frame frame;
|
||||
private static GraphicsDevice gd;
|
||||
private static Robot robot;
|
||||
private static volatile int width;
|
||||
private static volatile int height;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
try {
|
||||
robot = new Robot();
|
||||
invokeAndWait(() -> {
|
||||
gd = GraphicsEnvironment.getLocalGraphicsEnvironment().
|
||||
getDefaultScreenDevice();
|
||||
if (!gd.isFullScreenSupported()) {
|
||||
throw new SkippedException("Full Screen mode not supported");
|
||||
}
|
||||
});
|
||||
|
||||
invokeAndWait(() -> {
|
||||
frame = new Frame("Test FullScreen mode");
|
||||
frame.setBackground(Color.RED);
|
||||
frame.setSize(100, 100);
|
||||
frame.setLocation(10, 10);
|
||||
frame.setVisible(true);
|
||||
});
|
||||
robot.delay(1000);
|
||||
|
||||
invokeAndWait(() -> gd.setFullScreenWindow(frame));
|
||||
robot.waitForIdle();
|
||||
robot.delay(300);
|
||||
|
||||
invokeAndWait(() -> {
|
||||
width = gd.getFullScreenWindow().getWidth();
|
||||
height = gd.getFullScreenWindow().getHeight();
|
||||
});
|
||||
|
||||
if (!robot.getPixelColor(width / 2, height / 2).equals(Color.RED)) {
|
||||
System.err.println("Actual color: " + robot.getPixelColor(width / 2, height / 2)
|
||||
+ " Expected color: " + Color.RED);
|
||||
throw new RuntimeException("Test Failed! Window not in full screen mode");
|
||||
}
|
||||
} finally {
|
||||
if (frame != null) {
|
||||
frame.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 6837004
|
||||
* @summary Checks that non-opaque window can be made a fullscreen window
|
||||
* @author Artem Ananiev
|
||||
* @run main TranslucentWindow
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.*;
|
||||
|
||||
import static java.awt.GraphicsDevice.WindowTranslucency.*;
|
||||
|
||||
|
||||
public class TranslucentWindow {
|
||||
public static void main(String args[]) {
|
||||
Robot robot;
|
||||
try {
|
||||
robot = new Robot();
|
||||
}catch(Exception ex) {
|
||||
ex.printStackTrace();
|
||||
throw new RuntimeException("Unexpected failure");
|
||||
}
|
||||
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice gd = ge.getDefaultScreenDevice();
|
||||
|
||||
Frame f = new Frame("Test frame");
|
||||
f.setUndecorated(true);
|
||||
f.setBounds(100, 100, 320, 240);
|
||||
|
||||
// First, check it can be made fullscreen window without any effects applied
|
||||
gd.setFullScreenWindow(f);
|
||||
robot.waitForIdle();
|
||||
|
||||
gd.setFullScreenWindow(null);
|
||||
robot.waitForIdle();
|
||||
|
||||
// Second, check if it applying any effects doesn't prevent the window
|
||||
// from going into the fullscreen mode
|
||||
if (gd.isWindowTranslucencySupported(PERPIXEL_TRANSPARENT)) {
|
||||
f.setShape(new Ellipse2D.Float(0, 0, f.getWidth(), f.getHeight()));
|
||||
}
|
||||
if (gd.isWindowTranslucencySupported(TRANSLUCENT)) {
|
||||
f.setOpacity(0.5f);
|
||||
}
|
||||
if (gd.isWindowTranslucencySupported(PERPIXEL_TRANSLUCENT)) {
|
||||
f.setBackground(new Color(0, 0, 0, 128));
|
||||
}
|
||||
gd.setFullScreenWindow(f);
|
||||
robot.waitForIdle();
|
||||
|
||||
// Third, make sure all the effects are unset when entering the fullscreen mode
|
||||
if (f.getShape() != null) {
|
||||
throw new RuntimeException("Test FAILED: fullscreen window shape is not null");
|
||||
}
|
||||
if (Math.abs(f.getOpacity() - 1.0f) > 1e-4) {
|
||||
throw new RuntimeException("Test FAILED: fullscreen window opacity is not 1.0f");
|
||||
}
|
||||
Color bgColor = f.getBackground();
|
||||
if ((bgColor != null) && (bgColor.getAlpha() != 255)) {
|
||||
throw new RuntimeException("Test FAILED: fullscreen window background color is not opaque");
|
||||
}
|
||||
|
||||
f.dispose();
|
||||
System.out.println("Test PASSED");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.awt.DisplayMode;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
/**
|
||||
* Used by the UninitializedDisplayModeChangeTest to change the
|
||||
* display mode.
|
||||
*/
|
||||
public class DisplayModeChanger {
|
||||
|
||||
public static void main(String[] args)
|
||||
throws InterruptedException, InvocationTargetException
|
||||
{
|
||||
final GraphicsDevice gd =
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment().
|
||||
getDefaultScreenDevice();
|
||||
|
||||
EventQueue.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
Frame f = null;
|
||||
if (gd.isFullScreenSupported()) {
|
||||
try {
|
||||
f = new Frame("DisplayChanger Frame");
|
||||
gd.setFullScreenWindow(f);
|
||||
if (gd.isDisplayChangeSupported()) {
|
||||
DisplayMode dm = findDisplayMode(gd);
|
||||
if (gd != null) {
|
||||
gd.setDisplayMode(dm);
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
gd.setFullScreenWindow(null);
|
||||
} finally {
|
||||
if (f != null) {
|
||||
f.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 6358034 6568560 8198613 8198335
|
||||
* @key headful
|
||||
* @summary Tests that no exception is thrown when display mode is changed
|
||||
* externally
|
||||
* @compile UninitializedDisplayModeChangeTest.java DisplayModeChanger.java
|
||||
* @run main/othervm UninitializedDisplayModeChangeTest
|
||||
* @run main/othervm -Djava.awt.headless=true UninitializedDisplayModeChangeTest
|
||||
*/
|
||||
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Toolkit;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class UninitializedDisplayModeChangeTest {
|
||||
public static volatile boolean failed = false;
|
||||
public static void main(String[] args) {
|
||||
Toolkit.getDefaultToolkit();
|
||||
try {
|
||||
EventQueue.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
Thread.currentThread().setDefaultUncaughtExceptionHandler(
|
||||
new Thread.UncaughtExceptionHandler() {
|
||||
public void uncaughtException(Thread t,
|
||||
Throwable e)
|
||||
{
|
||||
System.err.println("Exception Detected:");
|
||||
e.printStackTrace();
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
} catch (InterruptedException ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (InvocationTargetException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
Process childProc;
|
||||
String classPath = System.getProperty("java.class.path" , ".");
|
||||
String cmd = new String(System.getProperty("java.home") +
|
||||
File.separator +
|
||||
"bin" +
|
||||
File.separator +
|
||||
"java -cp " + classPath +
|
||||
" DisplayModeChanger");
|
||||
|
||||
System.out.println("Launching the display mode changer process");
|
||||
System.out.println("cmd="+cmd);
|
||||
try {
|
||||
childProc = Runtime.getRuntime().exec(cmd);
|
||||
StreamProcessor err =
|
||||
new StreamProcessor("stderr", childProc.getErrorStream());
|
||||
StreamProcessor out =
|
||||
new StreamProcessor("stdout", childProc.getInputStream());
|
||||
err.start();
|
||||
out.start();
|
||||
|
||||
childProc.waitFor();
|
||||
} catch (Exception e) {
|
||||
failed = true;
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (failed) {
|
||||
throw new RuntimeException("Test Failed: exception detected");
|
||||
}
|
||||
System.out.println("Test Passed.");
|
||||
}
|
||||
|
||||
static class StreamProcessor extends Thread {
|
||||
InputStream is;
|
||||
String inputType;
|
||||
StreamProcessor(String inputType, InputStream is) {
|
||||
this.inputType = inputType;
|
||||
this.is = is;
|
||||
}
|
||||
public void run() {
|
||||
try {
|
||||
InputStreamReader isr = new InputStreamReader(is);
|
||||
BufferedReader br = new BufferedReader(isr);
|
||||
String line = null;
|
||||
while ( (line = br.readLine()) != null) {
|
||||
System.out.println("Display Changer "+inputType+
|
||||
" output > " + line);
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue