Skip to content

Commit

Permalink
8191406: [hidpi] sun/java2d/SunGraphics2D/DrawImageBilinear.java test…
Browse files Browse the repository at this point in the history
… fails

Reviewed-by: serb
  • Loading branch information
jayathirthrao committed Nov 23, 2022
1 parent 412b436 commit b4bd287
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 85 deletions.
2 changes: 1 addition & 1 deletion test/jdk/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ sun/java2d/DirectX/MultiPaintEventTest/MultiPaintEventTest.java 8284825 windows-
sun/java2d/DirectX/OverriddenInsetsTest/OverriddenInsetsTest.java 8196102 generic-all
sun/java2d/DirectX/RenderingToCachedGraphicsTest/RenderingToCachedGraphicsTest.java 8196180 windows-all,macosx-all
sun/java2d/SunGraphics2D/EmptyClipRenderingTest.java 8144029 macosx-all,linux-all
sun/java2d/SunGraphics2D/DrawImageBilinear.java 8191406 generic-all
sun/java2d/SunGraphics2D/DrawImageBilinear.java 8297175 linux-all
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
Expand Down
135 changes: 51 additions & 84 deletions test/jdk/sun/java2d/SunGraphics2D/DrawImageBilinear.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2022, 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 @@ -25,16 +25,15 @@
* @key headful
* @bug 5009033 6603000 6666362 8159142 8198613
* @summary Verifies that images transformed with bilinear filtering do not
* leave artifacts at the edges.
* leave artifacts at the edges.
* @run main/othervm -Dsun.java2d.uiScale=2.5 DrawImageBilinear
* @run main/othervm -Dsun.java2d.uiScale=2.5 -Dsun.java2d.d3d=false DrawImageBilinear
* @author campbelc
*/

import java.awt.Canvas;
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.Graphics2D;
Expand All @@ -55,28 +54,13 @@ public class DrawImageBilinear extends Canvas {
private static boolean done;
private BufferedImage bimg1, bimg2;
private VolatileImage vimg;
private static volatile BufferedImage capture;
private static void doCapture(Component test) {
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {}
// Grab the screen region
try {
Robot robot = new Robot();
Point pt1 = test.getLocationOnScreen();
Rectangle rect =
new Rectangle(pt1.x, pt1.y, test.getWidth(), test.getHeight());
capture = robot.createScreenCapture(rect);
} catch (Exception e) {
e.printStackTrace();
}
}
private static BufferedImage capture;
private static DrawImageBilinear test;
private static Frame frame;

private void renderPattern(Graphics g) {
g.setColor(Color.red);
g.fillRect(0, 0, SIZE, SIZE);
//g.setColor(Color.green);
//g.drawRect(0, 0, SIZE-1, SIZE-1);
g.dispose();
}

Expand Down Expand Up @@ -108,26 +92,17 @@ public void paint(Graphics g) {

// second time will be a texture->surface blit
g2d.drawImage(bimg2, 80, 10, 40, 40, null);
if (!skipOglTextureTest) {
g2d.drawImage(bimg2, 80, 10, 40, 40, null);
}
g2d.drawImage(bimg2, 80, 10, 40, 40, null);

// third time will be a pbuffer->surface blit
if (vimg.validate(getGraphicsConfiguration()) != VolatileImage.IMAGE_OK) {
if (vimg.validate(getGraphicsConfiguration()) !=
VolatileImage.IMAGE_OK) {
renderPattern(vimg.createGraphics());
}
g2d.drawImage(vimg, 150, 10, 40, 40, null);

Toolkit.getDefaultToolkit().sync();
} while (vimg.contentsLost());

synchronized (this) {
if (!done) {
doCapture(this);
done = true;
}
notifyAll();
}
}

public Dimension getPreferredSize() {
Expand Down Expand Up @@ -156,63 +131,55 @@ private static void testRegion(BufferedImage bi,
}
}

private static boolean skipOglTextureTest = false;

public static void main(String[] args) {
boolean show = false;
for (String arg : args) {
if ("-show".equals(arg)) {
show = true;
}
}

String arch = System.getProperty("os.arch");
boolean isOglEnabled = Boolean.getBoolean("sun.java2d.opengl");
skipOglTextureTest = false;
System.out.println("Skip OpenGL texture test: " + skipOglTextureTest);

DrawImageBilinear test = new DrawImageBilinear();
Frame frame = new Frame();
private static void createAndShowGUI() {
test = new DrawImageBilinear();
frame = new Frame();
frame.add(test);
frame.setUndecorated(true);
frame.setAlwaysOnTop(true);
frame.setLocationRelativeTo(null);
frame.pack();

This comment has been minimized.

Copy link
@prsadhuk

prsadhuk Nov 28, 2022

Contributor

@mrserb I wonder why the issue #11057 (comment) described here was not mentioned in this case.

This comment has been minimized.

Copy link
@mrserb

mrserb Feb 17, 2024

Member

That is a valid point.

frame.setVisible(true);
}

// Wait until the component's been painted
synchronized (test) {
while (!done) {
try {
test.wait();
} catch (InterruptedException e) {
throw new RuntimeException("Failed: Interrupted");
}
public static void main(String[] args) throws Exception {
try {
EventQueue.invokeAndWait(() -> createAndShowGUI());
GraphicsConfiguration gc = frame.getGraphicsConfiguration();
if (gc.getColorModel() instanceof IndexColorModel) {
System.out.println("IndexColorModel detected: " +
"test considered PASSED");
return;
}
Robot robot = new Robot();
robot.setAutoDelay(100);
robot.mouseMove(0,0);
robot.waitForIdle();
Point pt1 = frame.getLocationOnScreen();
Rectangle rect =
new Rectangle(pt1.x, pt1.y,
frame.getWidth(), frame.getHeight());
capture = robot.createScreenCapture(rect);
robot.waitForIdle();
if (capture == null) {
throw new RuntimeException("Failed: capture is null");
}
}

GraphicsConfiguration gc = frame.getGraphicsConfiguration();
if (gc.getColorModel() instanceof IndexColorModel) {
System.out.println("IndexColorModel detected: " +
"test considered PASSED");
frame.dispose();
return;
}

if (!show) {
frame.dispose();
}
if (capture == null) {
throw new RuntimeException("Failed: capture is null");
}
// Test background color
int pixel = capture.getRGB(5, 5);
if (pixel != 0xffffffff) {
throw new RuntimeException("Failed: Incorrect color for " +
"background");
}

// Test background color
int pixel = capture.getRGB(5, 5);
if (pixel != 0xffffffff) {
throw new RuntimeException("Failed: Incorrect color for " +
"background");
// Test pixels
testRegion(capture, new Rectangle(10, 10, 40, 40));
testRegion(capture, new Rectangle(80, 10, 40, 40));
testRegion(capture, new Rectangle(150, 10, 40, 40));
} finally {
if (frame != null) {
frame.dispose();
}
}

// Test pixels
testRegion(capture, new Rectangle(10, 10, 40, 40));
testRegion(capture, new Rectangle(80, 10, 40, 40));
testRegion(capture, new Rectangle(150, 10, 40, 40));
}
}

1 comment on commit b4bd287

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.