use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.
the class RSLContextInvalidationTest method main.
public static void main(String[] args) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
VolatileImage vi = gc.createCompatibleVolatileImage(100, 100);
vi.validate(gc);
VolatileImage vi1 = gc.createCompatibleVolatileImage(100, 100);
vi1.validate(gc);
if (!(vi instanceof DestSurfaceProvider)) {
System.out.println("Test considered PASSED: no HW acceleration");
return;
}
DestSurfaceProvider p = (DestSurfaceProvider) vi;
Surface s = p.getDestSurface();
if (!(s instanceof AccelSurface)) {
System.out.println("Test considered PASSED: no HW acceleration");
return;
}
AccelSurface dst = (AccelSurface) s;
Graphics g = vi.createGraphics();
g.drawImage(vi1, 95, 95, null);
g.setColor(Color.red);
g.fillRect(0, 0, 100, 100);
g.setColor(Color.black);
g.fillRect(0, 0, 100, 100);
// after this the validated context color is black
RenderQueue rq = dst.getContext().getRenderQueue();
rq.lock();
try {
dst.getContext().saveState();
dst.getContext().restoreState();
} finally {
rq.unlock();
}
// this will cause ResetPaint (it will set color to extended EA=ff,
// which is ffffffff==Color.white)
g.drawImage(vi1, 95, 95, null);
// now try filling with black again, but it will come up as white
// because this fill rect won't validate the color properly
g.setColor(Color.black);
g.fillRect(0, 0, 100, 100);
BufferedImage bi = vi.getSnapshot();
if (bi.getRGB(50, 50) != Color.black.getRGB()) {
throw new RuntimeException("Test FAILED: found color=" + Integer.toHexString(bi.getRGB(50, 50)) + " instead of " + Integer.toHexString(Color.black.getRGB()));
}
System.out.println("Test PASSED.");
}
use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.
the class RSLAPITest method testForNPEDuringCreation.
private static void testForNPEDuringCreation(AccelGraphicsConfig agc) {
int iterations = 100;
HashSet<VolatileImage> vis = new HashSet<VolatileImage>();
GraphicsConfiguration gc = (GraphicsConfiguration) agc;
Rectangle r = gc.getBounds();
long ram = gc.getDevice().getAvailableAcceleratedMemory();
if (ram > 0) {
// guesstimate the number of iterations needed to exhaust vram
int i = 2 * (int) (ram / (r.width * r.height * gc.getColorModel().getPixelSize() / 8));
iterations = Math.max(iterations, i);
System.err.println("iterations=" + iterations);
}
for (int i = 0; i < iterations; i++) {
VolatileImage vi = agc.createCompatibleVolatileImage(r.width, r.height, Transparency.OPAQUE, AccelSurface.RT_PLAIN);
if (vi == null) {
break;
}
vis.add(vi);
}
for (VolatileImage vi : vis) {
vi.flush();
}
vis = null;
System.out.println("Passed: testing for possible NPEs " + "during VI creation");
}
use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.
the class RSLAPITest method main.
public static void main(String[] args) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
testGC(gc);
if (failed) {
throw new RuntimeException("Test FAILED. See err output for more");
}
System.out.println("Test PASSED.");
}
use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.
the class AccelPaintsTest method test.
private void test() {
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
if (gc.getColorModel().getPixelSize() < 16) {
System.out.println("<16 bit depth detected, test passed");
return;
}
VolatileImage vi = gc.createCompatibleVolatileImage(250, 4 * 120, Transparency.OPAQUE);
BufferedImage res;
do {
vi.validate(gc);
Graphics2D g2d = vi.createGraphics();
g2d.setColor(Color.white);
g2d.fillRect(0, 0, vi.getWidth(), vi.getHeight());
render(g2d);
res = vi.getSnapshot();
} while (vi.contentsLost());
for (int y = 0; y < bi.getHeight(); y++) {
for (int x = 0; x < bi.getWidth(); x++) {
if (res.getRGB(x, y) == Color.black.getRGB()) {
System.err.printf("Test FAILED: found black at %d,%d\n", x, y);
try {
String fileName = "AccelPaintsTest.png";
ImageIO.write(res, "png", new File(fileName));
System.err.println("Dumped rendering to " + fileName);
} catch (IOException e) {
}
throw new RuntimeException("Test FAILED: found black");
}
}
}
}
use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.
the class OnScreenRenderingResizeTest method main.
public static void main(String[] args) {
for (String arg : args) {
if ("-inf".equals(arg)) {
System.err.println("Test will run indefinitely");
RUN_TIME = Long.MAX_VALUE;
} else if ("-nocheck".equals(arg)) {
System.err.println("Test will not check rendering results");
nocheck = true;
} else {
System.err.println("Usage: OnScreenRenderingResizeTest [-inf][-nocheck]");
}
}
BufferedImage output = new BufferedImage(IMAGE_W, IMAGE_H, BufferedImage.TYPE_INT_RGB);
output.setAccelerationPriority(0.0f);
Graphics g = output.getGraphics();
g.setColor(renderColor);
g.fillRect(0, 0, output.getWidth(), output.getHeight());
final Frame frame = new Frame("OnScreenRenderingResizeTest") {
public void paint(Graphics g) {
}
public void update(Graphics g) {
}
};
frame.setBackground(bgColor);
frame.setUndecorated(true);
frame.pack();
GraphicsConfiguration gc = frame.getGraphicsConfiguration();
Rectangle gcBounds = gc.getBounds();
frame.setBounds(gcBounds.width / 4, gcBounds.height / 4, FRAME_W, FRAME_H);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
done = true;
}
});
try {
EventQueue.invokeAndWait(new Runnable() {
public void run() {
frame.setVisible(true);
}
});
// wait for Vista's effects to complete
Thread.sleep(2000);
} catch (Exception ex) {
ex.printStackTrace();
}
int maxW = gcBounds.width / 2;
int maxH = gcBounds.height / 2;
int minW = frame.getWidth();
int minH = frame.getHeight();
int incW = 10, incH = 10, cnt = 0;
Robot robot = null;
if (!nocheck && gc.getColorModel().getPixelSize() > 8) {
try {
robot = new Robot();
} catch (AWTException ex) {
System.err.println("Robot creation failed, continuing.");
}
} else {
System.err.println("No screen rendering checks.");
}
VolatileImage vi = gc.createCompatibleVolatileImage(512, 512);
vi.validate(gc);
long timeStarted = System.currentTimeMillis();
while (!done && (System.currentTimeMillis() - timeStarted) < RUN_TIME) {
if (++cnt > 100) {
int w = frame.getWidth() + incW;
int h = frame.getHeight() + incH;
if (w < minW || w > maxW) {
incW = -incW;
}
if (h < minH || h > maxH) {
incH = -incH;
}
frame.setSize(w, h);
cnt = 0;
}
// try to put the device into non-default state, for example,
// this operation below will set the transform
vi.validate(gc);
Graphics2D vig = (Graphics2D) vi.getGraphics();
vig.rotate(30.0f, vi.getWidth() / 2, vi.getHeight() / 2);
vig.drawImage(output, 0, 0, vi.getWidth(), vi.getHeight(), null);
Insets in = frame.getInsets();
frame.getGraphics().drawImage(output, in.left, in.top, null);
if (cnt == 90 && robot != null) {
robot.waitForIdle();
// area where we blitted to should be either white or green
Point p = frame.getLocationOnScreen();
p.translate(in.left + 10, in.top + 10);
BufferedImage bi = robot.createScreenCapture(new Rectangle(p.x, p.y, IMAGE_W / 2, IMAGE_H / 2));
int[] accepted1 = { Color.white.getRGB(), Color.green.getRGB() };
checkBI(bi, accepted1);
// the are where we didn't render should stay white
p = frame.getLocationOnScreen();
p.translate(in.left, in.top + IMAGE_H + 5);
bi = robot.createScreenCapture(new Rectangle(p.x, p.y, frame.getWidth() - in.left - in.right, frame.getHeight() - in.top - in.bottom - 5 - IMAGE_H));
int[] accepted2 = { Color.white.getRGB() };
checkBI(bi, accepted2);
}
Thread.yield();
}
frame.dispose();
System.out.println("Test Passed");
}
Aggregations