Search in sources :

Example 31 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.

the class IncorrectOffset method main.

public static void main(final String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(width, height);
    BufferedImage bi = new BufferedImage(width / 4, height / 4, BufferedImage.TYPE_INT_ARGB);
    while (true) {
        vi.validate(gc);
        Graphics2D g2d = vi.createGraphics();
        g2d.setColor(Color.black);
        g2d.fillRect(0, 0, width, height);
        g2d.setColor(Color.green);
        g2d.fillRect(width / 4, height / 4, 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);
        // Scale part of VI to BI. Only green area should be copied.
        g.drawImage(vi, 0, 0, width / 4, height / 4, width / 4, height / 4, width / 4 + width / 2, height / 4 + height / 2, null);
        g.dispose();
        if (vi.contentsLost()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ignored) {
            }
            continue;
        }
        for (int x = 0; x < width / 4; ++x) {
            for (int y = 0; y < height / 4; ++y) {
                if (bi.getRGB(x, y) != Color.green.getRGB()) {
                    throw new RuntimeException("Test failed.");
                }
            }
        }
        break;
    }
}
Also used : VolatileImage(java.awt.image.VolatileImage) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Example 32 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration 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 33 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration 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 34 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration 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 35 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration 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)

Aggregations

GraphicsConfiguration (java.awt.GraphicsConfiguration)136 GraphicsEnvironment (java.awt.GraphicsEnvironment)55 BufferedImage (java.awt.image.BufferedImage)46 Rectangle (java.awt.Rectangle)44 GraphicsDevice (java.awt.GraphicsDevice)38 Graphics2D (java.awt.Graphics2D)34 VolatileImage (java.awt.image.VolatileImage)31 Point (java.awt.Point)30 Dimension (java.awt.Dimension)21 Insets (java.awt.Insets)17 File (java.io.File)16 Graphics (java.awt.Graphics)13 IOException (java.io.IOException)13 Frame (java.awt.Frame)11 JFrame (javax.swing.JFrame)8 HeadlessException (java.awt.HeadlessException)7 Window (java.awt.Window)7 ImageIcon (javax.swing.ImageIcon)7 Color (java.awt.Color)6 AffineTransform (java.awt.geom.AffineTransform)6