Search in sources :

Example 16 with VolatileImage

use of java.awt.image.VolatileImage in project jdk8u_jdk by JetBrains.

the class IncorrectClipSurface2SW method main.

public static void main(final String[] args) throws IOException {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    AffineTransform at;
    for (final int size : SIZES) {
        for (final int scale : SCALES) {
            final int sw = size * scale;
            at = AffineTransform.getScaleInstance(sw, sw);
            for (Shape clip : SHAPES) {
                clip = at.createTransformedShape(clip);
                for (Shape to : SHAPES) {
                    to = at.createTransformedShape(to);
                    // Prepare test images
                    VolatileImage vi = getVolatileImage(gc, size);
                    BufferedImage bi = getBufferedImage(sw);
                    // Prepare gold images
                    BufferedImage goldvi = getCompatibleImage(gc, size);
                    BufferedImage goldbi = getBufferedImage(sw);
                    draw(clip, to, vi, bi, scale);
                    draw(clip, to, goldvi, goldbi, scale);
                    validate(bi, goldbi);
                }
            }
        }
    }
}
Also used : Shape(java.awt.Shape) VolatileImage(java.awt.image.VolatileImage) AffineTransform(java.awt.geom.AffineTransform) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 17 with VolatileImage

use of java.awt.image.VolatileImage in project jdk8u_jdk by JetBrains.

the class IncorrectClipXorModeSW2Surface method main.

public static void main(final String[] args) throws IOException {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    AffineTransform at;
    for (int size : SIZES) {
        at = AffineTransform.getScaleInstance(size, size);
        for (Shape clip : SHAPES) {
            clip = at.createTransformedShape(clip);
            for (Shape to : SHAPES) {
                to = at.createTransformedShape(to);
                // Prepare test images
                BufferedImage snapshot;
                BufferedImage bi = getBufferedImage(size);
                VolatileImage vi = getVolatileImage(gc, size);
                while (true) {
                    vi.validate(gc);
                    Graphics2D g2d = vi.createGraphics();
                    g2d.setColor(Color.GREEN);
                    g2d.fillRect(0, 0, size, size);
                    g2d.dispose();
                    if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
                        continue;
                    }
                    draw(clip, to, bi, vi);
                    snapshot = vi.getSnapshot();
                    if (vi.contentsLost()) {
                        continue;
                    }
                    break;
                }
                // Prepare gold images
                BufferedImage goldvi = getCompatibleImage(gc, size);
                BufferedImage goldbi = getBufferedImage(size);
                draw(clip, to, goldbi, goldvi);
                validate(snapshot, goldvi);
                vi.flush();
            }
        }
    }
}
Also used : Shape(java.awt.Shape) VolatileImage(java.awt.image.VolatileImage) AffineTransform(java.awt.geom.AffineTransform) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Example 18 with VolatileImage

use of java.awt.image.VolatileImage in project jdk8u_jdk by JetBrains.

the class IncorrectUnmanagedImageSourceOffset method test.

private static void test(BufferedImage bi, int type) throws IOException {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(511, 255, type);
    BufferedImage gold = gc.createCompatibleImage(511, 255, type);
    // draw to compatible Image
    Graphics2D big = gold.createGraphics();
    // force scaled blit
    big.drawImage(bi, 7, 11, 127, 111, 7, 11, 127 * 2, 111, null);
    big.dispose();
    // draw to volatile image
    BufferedImage snapshot;
    while (true) {
        vi.validate(gc);
        if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
            try {
                Thread.sleep(100);
            } catch (final InterruptedException ignored) {
            }
            continue;
        }
        Graphics2D vig = vi.createGraphics();
        // force scaled blit
        vig.drawImage(bi, 7, 11, 127, 111, 7, 11, 127 * 2, 111, null);
        vig.dispose();
        snapshot = vi.getSnapshot();
        if (vi.contentsLost()) {
            try {
                Thread.sleep(100);
            } catch (final InterruptedException ignored) {
            }
            continue;
        }
        break;
    }
    // validate images
    for (int x = 7; x < 127; ++x) {
        for (int y = 11; y < 111; ++y) {
            if (gold.getRGB(x, y) != snapshot.getRGB(x, y)) {
                ImageIO.write(gold, "png", new File("gold.png"));
                ImageIO.write(snapshot, "png", new File("bi.png"));
                throw new RuntimeException("Test failed.");
            }
        }
    }
}
Also used : VolatileImage(java.awt.image.VolatileImage) GraphicsEnvironment(java.awt.GraphicsEnvironment) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Example 19 with VolatileImage

use of java.awt.image.VolatileImage in project jdk8u_jdk by JetBrains.

the class IncorrectUnmanagedImageRotatedClip method test.

private static void test(final BufferedImage bi) throws IOException {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(500, 200, TRANSLUCENT);
    BufferedImage gold = gc.createCompatibleImage(500, 200, TRANSLUCENT);
    // draw to compatible Image
    draw(bi, gold);
    // draw to volatile image
    int attempt = 0;
    BufferedImage snapshot;
    while (true) {
        if (++attempt > 10) {
            throw new RuntimeException("Too many attempts: " + attempt);
        }
        vi.validate(gc);
        if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
            continue;
        }
        draw(bi, vi);
        snapshot = vi.getSnapshot();
        if (vi.contentsLost()) {
            continue;
        }
        break;
    }
    // validate images
    for (int x = 0; x < gold.getWidth(); ++x) {
        for (int y = 0; y < gold.getHeight(); ++y) {
            if (gold.getRGB(x, y) != snapshot.getRGB(x, y)) {
                ImageIO.write(gold, "png", new File("gold.png"));
                ImageIO.write(snapshot, "png", new File("bi.png"));
                throw new RuntimeException("Test failed.");
            }
        }
    }
}
Also used : VolatileImage(java.awt.image.VolatileImage) GraphicsEnvironment(java.awt.GraphicsEnvironment) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 20 with VolatileImage

use of java.awt.image.VolatileImage 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.");
}
Also used : Graphics(java.awt.Graphics) GraphicsDevice(java.awt.GraphicsDevice) VolatileImage(java.awt.image.VolatileImage) DestSurfaceProvider(sun.java2d.DestSurfaceProvider) RenderQueue(sun.java2d.pipe.RenderQueue) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Surface(sun.java2d.Surface)

Aggregations

VolatileImage (java.awt.image.VolatileImage)53 GraphicsConfiguration (java.awt.GraphicsConfiguration)30 BufferedImage (java.awt.image.BufferedImage)29 Graphics2D (java.awt.Graphics2D)24 GraphicsEnvironment (java.awt.GraphicsEnvironment)21 Graphics (java.awt.Graphics)6 AffineTransform (java.awt.geom.AffineTransform)6 Rectangle (java.awt.Rectangle)5 File (java.io.File)5 GraphicsDevice (java.awt.GraphicsDevice)3 Shape (java.awt.Shape)3 IOException (java.io.IOException)3 DestSurfaceProvider (sun.java2d.DestSurfaceProvider)3 Surface (sun.java2d.Surface)3 AWTException (java.awt.AWTException)2 Font (java.awt.Font)2 GradientPaint (java.awt.GradientPaint)2 Image (java.awt.Image)2 ImageCapabilities (java.awt.ImageCapabilities)2 Paint (java.awt.Paint)2