use of java.awt.image.VolatileImage in project javatari by ppeccin.
the class SwingHelper method asCompatibleVolatileImage.
public static VolatileImage asCompatibleVolatileImage(Image img) {
VolatileImage ret = defaultScreenDeviceConfiguration().createCompatibleVolatileImage(img.getWidth(null), img.getHeight(null));
Graphics2D gc = ret.createGraphics();
gc.drawImage(img, 0, 0, null);
gc.dispose();
return ret;
}
use of java.awt.image.VolatileImage in project jdk8u_jdk by JetBrains.
the class PixelTests method initTest.
public Object initTest(TestEnvironment env, Result result) {
Context ctx = new Context();
ctx.bimg = ((BufImg) env.getModifier(bufimgsrcroot)).getImage();
if (env.isEnabled(doRenderTo)) {
Graphics2D g2d = ctx.bimg.createGraphics();
g2d.setColor(Color.white);
g2d.fillRect(3, 0, 1, 1);
g2d.dispose();
}
if (env.isEnabled(doRenderFrom)) {
GraphicsConfiguration cfg = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
VolatileImage vimg = cfg.createCompatibleVolatileImage(8, 1);
vimg.validate(cfg);
Graphics2D g2d = vimg.createGraphics();
for (int i = 0; i < 100; i++) {
g2d.drawImage(ctx.bimg, 0, 0, null);
}
g2d.dispose();
vimg.flush();
}
result.setUnits(1);
result.setUnitName(getUnitName());
return ctx;
}
use of java.awt.image.VolatileImage in project jdk8u_jdk by JetBrains.
the class TextRenderingTest method main.
public static void main(final String[] args) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
VolatileImage vi = gc.createCompatibleVolatileImage(width, height);
while (true) {
vi.validate(gc);
Graphics2D g2d = vi.createGraphics();
g2d.setColor(Color.white);
g2d.fillRect(0, 0, width, height);
g2d.setPaint(new GradientPaint(new Point2D.Float(0, height / 2), Color.white, new Point2D.Float(width, height / 2), Color.black));
g2d.fillRect(0, 0, width, height);
String fnt = g2d.getFont().getFamily();
g2d.setFont(new Font(fnt, Font.PLAIN, 100));
// draw text with offset
g2d.drawString("IIIIIIIIII", 100, 100);
g2d.dispose();
if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
continue;
}
if (vi.contentsLost()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
continue;
}
break;
}
BufferedImage bi = vi.getSnapshot();
// the text shifted shouldn't be visible onto a painted rectangle!
// so the check: color component (blue) must decrease monotonously
int prev = Integer.MAX_VALUE;
for (int x = 0; x < width; ++x) {
int color = bi.getRGB(x, height / 2);
int b = color & 0xFF;
if (b > prev) {
throw new RuntimeException("test failed: can see the text rendered!");
}
prev = b;
}
}
use of java.awt.image.VolatileImage in project jdk8u_jdk by JetBrains.
the class IncorrectClipSurface2SW method getVolatileImage.
private static VolatileImage getVolatileImage(GraphicsConfiguration gc, int size) {
VolatileImage vi = gc.createCompatibleVolatileImage(size, size);
Graphics2D g2d = vi.createGraphics();
g2d.setColor(Color.GREEN);
g2d.fillRect(0, 0, size, size);
return vi;
}
use of java.awt.image.VolatileImage in project jdk8u_jdk by JetBrains.
the class IncorrectAlphaSurface2SW method main.
public static void main(final String[] args) throws IOException {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
BufferedImage destVI;
BufferedImage destBI;
BufferedImage sourceBI;
VolatileImage sourceVI;
for (final int s : SIZES) {
for (final int srcType : srcTypes) {
for (final int dstType : dstTypes) {
for (final int scale : SCALES) {
int sw = s * scale;
destVI = new BufferedImage(sw, sw, dstType);
destBI = new BufferedImage(sw, sw, dstType);
sourceBI = gc.createCompatibleImage(sw, sw, srcType);
sourceVI = gc.createCompatibleVolatileImage(s, s, srcType);
// draw to dest BI using compatible image
fill(sourceBI, s);
Graphics2D big = destBI.createGraphics();
big.setComposite(AlphaComposite.Src);
big.drawImage(sourceBI, 0, 0, sw, sw, null);
big.dispose();
// draw to dest BI using compatible image
fill(sourceVI, s);
drawVItoBI(gc, destVI, sourceVI);
validate(destVI, destBI);
sourceVI.flush();
}
}
}
}
System.out.println("Test PASSED");
}
Aggregations