use of java.awt.image.VolatileImage in project jdk8u_jdk by JetBrains.
the class FillTexturePaint method main.
public static void main(final String[] args) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
VolatileImage vi = gc.createCompatibleVolatileImage(size, size);
while (true) {
vi.validate(gc);
Graphics2D g2d = vi.createGraphics();
g2d.setComposite(AlphaComposite.Src);
g2d.setPaint(shape);
g2d.fill(new Rectangle(0, 0, size, size));
g2d.dispose();
if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
try {
Thread.sleep(100);
} catch (InterruptedException ignored) {
}
continue;
}
BufferedImage bi = vi.getSnapshot();
if (vi.contentsLost()) {
try {
Thread.sleep(100);
} catch (InterruptedException ignored) {
}
continue;
}
for (int x = 0; x < size; ++x) {
for (int y = 0; y < size; ++y) {
if (bi.getRGB(x, y) != Color.GREEN.getRGB()) {
throw new RuntimeException("Test failed.");
}
}
}
break;
}
}
use of java.awt.image.VolatileImage in project jdk8u_jdk by JetBrains.
the class FlipDrawImage method main.
public static void main(final String[] args) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
VolatileImage vi = gc.createCompatibleVolatileImage(width, height);
final BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
while (true) {
vi.validate(gc);
Graphics2D g2d = vi.createGraphics();
g2d.setColor(Color.red);
g2d.fillRect(0, 0, width, height);
g2d.setColor(Color.green);
g2d.fillRect(0, 0, width / 2, height / 2);
g2d.dispose();
if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
try {
Thread.sleep(100);
} catch (InterruptedException ignored) {
}
continue;
}
Graphics2D g = bi.createGraphics();
g.setComposite(AlphaComposite.Src);
g.setColor(Color.BLUE);
g.fillRect(0, 0, width, height);
// destination width and height are flipped and scale is used.
g.drawImage(vi, width / 2, height / 2, -width / 2, -height / 2, null, null);
g.dispose();
if (vi.contentsLost()) {
try {
Thread.sleep(100);
} catch (InterruptedException ignored) {
}
continue;
}
for (int x = 0; x < width; ++x) {
for (int y = 0; y < height; ++y) {
if (x < width / 2 && y < height / 2) {
if (x >= width / 4 && y >= height / 4) {
if (bi.getRGB(x, y) != Color.green.getRGB()) {
throw new RuntimeException("Test failed.");
}
} else if (bi.getRGB(x, y) != Color.red.getRGB()) {
throw new RuntimeException("Test failed.");
}
} else {
if (bi.getRGB(x, y) != Color.BLUE.getRGB()) {
throw new RuntimeException("Test failed.");
}
}
}
}
break;
}
}
use of java.awt.image.VolatileImage in project jdk8u_jdk by JetBrains.
the class TransformSetGet method main.
public static void main(final String[] args) {
final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
final VolatileImage vi = gc.createCompatibleVolatileImage(200, 200);
final SunGraphics2D sg2d = (SunGraphics2D) vi.createGraphics();
sg2d.constrain(0, 61, 100, 100);
final AffineTransform expected = sg2d.cloneTransform();
sg2d.setTransform(sg2d.getTransform());
final AffineTransform actual = sg2d.cloneTransform();
sg2d.dispose();
vi.flush();
if (!expected.equals(actual)) {
System.out.println("Expected = " + expected);
System.out.println("Actual = " + actual);
throw new RuntimeException("Wrong transform");
}
}
use of java.awt.image.VolatileImage in project jdk8u_jdk by JetBrains.
the class IncorrectAlphaConversionBicubic method main.
public static void main(final String[] args) {
final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsDevice gd = ge.getDefaultScreenDevice();
final GraphicsConfiguration gc = gd.getDefaultConfiguration();
final VolatileImage vi = gc.createCompatibleVolatileImage(SIZE, SIZE, TRANSLUCENT);
final BufferedImage bi = makeUnmanagedBI(gc, TRANSLUCENT);
final int expected = bi.getRGB(2, 2);
int attempt = 0;
BufferedImage snapshot;
while (true) {
if (++attempt > 10) {
throw new RuntimeException("Too many attempts: " + attempt);
}
vi.validate(gc);
final Graphics2D g2d = vi.createGraphics();
g2d.setComposite(AlphaComposite.Src);
g2d.scale(2, 2);
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g2d.drawImage(bi, 0, 0, null);
g2d.dispose();
snapshot = vi.getSnapshot();
if (vi.contentsLost()) {
continue;
}
break;
}
final int actual = snapshot.getRGB(2, 2);
if (actual != expected) {
System.err.println("Actual: " + Integer.toHexString(actual));
System.err.println("Expected: " + Integer.toHexString(expected));
throw new RuntimeException("Test failed");
}
}
use of java.awt.image.VolatileImage in project jdk8u_jdk by JetBrains.
the class IncorrectBounds method main.
public static void main(final String[] args) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
VolatileImage vi = gc.createCompatibleVolatileImage(width / 4, height / 4);
final BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
while (true) {
vi.validate(gc);
Graphics2D g2d = vi.createGraphics();
g2d.setColor(Color.green);
g2d.fillRect(0, 0, width / 4, height / 4);
g2d.dispose();
if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
try {
Thread.sleep(100);
} catch (InterruptedException ignored) {
}
continue;
}
Graphics2D g = bi.createGraphics();
g.setComposite(AlphaComposite.Src);
g.setColor(Color.red);
g.fillRect(0, 0, width, height);
// Use sx and sy outside of VI bounds.
g.drawImage(vi, 0, 0, width / 2, height / 2, 0, 0, width * 2, height * 2, null);
g.dispose();
if (vi.contentsLost()) {
try {
Thread.sleep(100);
} catch (InterruptedException ignored) {
}
continue;
}
for (int x = 0; x < width; ++x) {
for (int y = 0; y < height; ++y) {
if (x < width / 16 && y < height / 16) {
if (bi.getRGB(x, y) != Color.green.getRGB()) {
throw new RuntimeException("Test failed.");
}
} else {
if (bi.getRGB(x, y) != Color.red.getRGB()) {
throw new RuntimeException("Test failed.");
}
}
}
}
break;
}
}
Aggregations