Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion test/jdk/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ sun/java2d/SunGraphics2D/PolyVertTest.java 6986565 generic-all
sun/java2d/SunGraphics2D/SimplePrimQuality.java 6992007 generic-all
sun/java2d/SunGraphics2D/SourceClippingBlitTest/SourceClippingBlitTest.java 8196185 generic-all

sun/java2d/X11SurfaceData/SharedMemoryPixmapsTest/SharedMemoryPixmapsTest.sh 7184899,8221451 linux-all,macosx-aarch64
java/awt/FullScreen/DisplayChangeVITest/DisplayChangeVITest.java 8169469,8273617 windows-all,macosx-aarch64
java/awt/FullScreen/UninitializedDisplayModeChangeTest/UninitializedDisplayModeChangeTest.java 8273617 macosx-all
java/awt/print/PrinterJob/PSQuestionMark.java 7003378 generic-all
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
* 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
Expand All @@ -21,10 +21,10 @@
* questions.
*/

import java.awt.AWTException;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Point;
Expand All @@ -42,18 +42,18 @@
* make sure the pixels on the screen are red.
*
* Note that we force the use of shared memory pixmaps in the shell script.
*
* @author Dmitri.Trembovetski
*/

public class SharedMemoryPixmapsTest {
static final int IMAGE_SIZE = 100;
static boolean show = false;
final Frame testFrame;
/** Creates a new instance of SharedMemoryPixmapsTest */
public SharedMemoryPixmapsTest() {
static final int IMAGE_SIZE = 200;
static volatile boolean show = false;
static volatile Frame testFrame;
static volatile TestComponent testComponent;

static void createUI() {
testFrame = new Frame("SharedMemoryPixmapsTest");
testFrame.add(new TestComponent());
testComponent = new TestComponent();
testFrame.add(testComponent);
testFrame.setUndecorated(true);
testFrame.setResizable(false);
testFrame.pack();
Expand All @@ -62,20 +62,51 @@ public SharedMemoryPixmapsTest() {
testFrame.toFront();
}

public static void main(String[] args) {
public static void main(String[] args) throws Exception {
for (String s : args) {
if ("-show".equals(s)) {
show = true;
} else {
System.err.println("Usage: SharedMemoryPixmapsTest [-show]");
}
}
new SharedMemoryPixmapsTest();
EventQueue.invokeAndWait(SharedMemoryPixmapsTest::createUI);
if (testRendering()) {
System.err.println("Test Passed");
} else {
System.err.println("Test Failed");
}
if (!show && testFrame != null) {
EventQueue.invokeAndWait(testFrame::dispose);
}
}

static boolean testRendering() throws Exception {
Robot r = new Robot();
r.waitForIdle();
r.delay(2000);
Point p = testComponent.getLocationOnScreen();
BufferedImage b =
r.createScreenCapture(new Rectangle(p, testComponent.getPreferredSize()));
for (int y = 20; y < b.getHeight() - 40; y++) {
for (int x = 20; x < b.getWidth() - 40; x++) {
if (b.getRGB(x, y) != Color.red.getRGB()) {
System.err.println("Incorrect pixel at "
+ x + "x" + y + " : " +
Integer.toHexString(b.getRGB(x, y)));
if (show) {
return false;
}
System.err.println("Test Failed");
System.exit(1);
}
}
}
return true;
}

private class TestComponent extends Component {
static class TestComponent extends Component {
VolatileImage vi = null;
boolean tested = false;

void initVI() {
int res;
Expand Down Expand Up @@ -104,60 +135,15 @@ public synchronized void paint(Graphics g) {
g.setColor(Color.green);
g.fillRect(0, 0, getWidth(), getHeight());

vi = null;
initVI();
g.drawImage(vi, 0, 0, null);
} while (vi.contentsLost());

Toolkit.getDefaultToolkit().sync();
if (!tested) {
if (testRendering()) {
System.err.println("Test Passed");
} else {
System.err.println("Test Failed");
}
tested = true;
}
if (!show) {
testFrame.setVisible(false);
testFrame.dispose();
}
}

private boolean testRendering() throws RuntimeException {
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {}
Robot r = null;
try {
r = new Robot();
} catch (AWTException ex) {
ex.printStackTrace();
throw new RuntimeException("Can't create Robot");
}
Point p = getLocationOnScreen();
BufferedImage b =
r.createScreenCapture(new Rectangle(p, getPreferredSize()));
for (int y = 0; y < b.getHeight(); y++) {
for (int x = 0; x < b.getWidth(); x++) {
if (b.getRGB(x, y) != Color.red.getRGB()) {
System.err.println("Incorrect pixel" + " at "
+ x + "x" + y + " : " +
Integer.toHexString(b.getRGB(x, y)));
if (show) {
return false;
}
System.err.println("Test Failed");
System.exit(1);
}
}
}
return true;
}

@Override
public Dimension getPreferredSize() {
return new Dimension(IMAGE_SIZE, IMAGE_SIZE);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#
# Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
# 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
Expand Down Expand Up @@ -29,7 +29,6 @@
# by filling a VolatileImage with red color and copying it
# to the screen.
# Note that we force the use of shared memory pixmaps.
# @author Dmitri.Trembovetski

echo "TESTJAVA=${TESTJAVA}"
echo "TESTSRC=${TESTSRC}"
Expand Down