Java Code Examples for java.awt.image.VolatileImage#createGraphics()

The following examples show how to use java.awt.image.VolatileImage#createGraphics() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransformedPaintTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void runTest() {
    GraphicsConfiguration gc = GraphicsEnvironment.
        getLocalGraphicsEnvironment().getDefaultScreenDevice().
            getDefaultConfiguration();

    if (gc.getColorModel().getPixelSize() < 16) {
        System.out.println("8-bit desktop depth found, test passed");
        return;
    }

    VolatileImage vi = gc.createCompatibleVolatileImage(R_WIDTH, R_HEIGHT);
    BufferedImage bi = null;
    do {
        vi.validate(gc);
        Graphics2D g = vi.createGraphics();
        render(g, vi.getWidth(), vi.getHeight());
        bi = vi.getSnapshot();
    } while (vi.contentsLost());

    checkBI(bi);
    System.out.println("Test PASSED.");
}
 
Example 2
Source File: TransformSetGet.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
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");
    }
}
 
Example 3
Source File: TransformedPaintTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void runTest() {
    GraphicsConfiguration gc = GraphicsEnvironment.
        getLocalGraphicsEnvironment().getDefaultScreenDevice().
            getDefaultConfiguration();

    if (gc.getColorModel().getPixelSize() < 16) {
        System.out.println("8-bit desktop depth found, test passed");
        return;
    }

    VolatileImage vi = gc.createCompatibleVolatileImage(R_WIDTH, R_HEIGHT);
    BufferedImage bi = null;
    do {
        vi.validate(gc);
        Graphics2D g = vi.createGraphics();
        render(g, vi.getWidth(), vi.getHeight());
        bi = vi.getSnapshot();
    } while (vi.contentsLost());

    checkBI(bi);
    System.out.println("Test PASSED.");
}
 
Example 4
Source File: TransformSetGet.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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");
    }
}
 
Example 5
Source File: TransformedPaintTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void runTest() {
    GraphicsConfiguration gc = GraphicsEnvironment.
        getLocalGraphicsEnvironment().getDefaultScreenDevice().
            getDefaultConfiguration();

    if (gc.getColorModel().getPixelSize() < 16) {
        System.out.println("8-bit desktop depth found, test passed");
        return;
    }

    VolatileImage vi = gc.createCompatibleVolatileImage(R_WIDTH, R_HEIGHT);
    BufferedImage bi = null;
    do {
        vi.validate(gc);
        Graphics2D g = vi.createGraphics();
        render(g, vi.getWidth(), vi.getHeight());
        bi = vi.getSnapshot();
    } while (vi.contentsLost());

    checkBI(bi);
    System.out.println("Test PASSED.");
}
 
Example 6
Source File: TransformedPaintTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void runTest() {
    GraphicsConfiguration gc = GraphicsEnvironment.
        getLocalGraphicsEnvironment().getDefaultScreenDevice().
            getDefaultConfiguration();

    if (gc.getColorModel().getPixelSize() < 16) {
        System.out.println("8-bit desktop depth found, test passed");
        return;
    }

    VolatileImage vi = gc.createCompatibleVolatileImage(R_WIDTH, R_HEIGHT);
    BufferedImage bi = null;
    do {
        vi.validate(gc);
        Graphics2D g = vi.createGraphics();
        render(g, vi.getWidth(), vi.getHeight());
        bi = vi.getSnapshot();
    } while (vi.contentsLost());

    checkBI(bi);
    System.out.println("Test PASSED.");
}
 
Example 7
Source File: DrawHugeImageTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static boolean render(BufferedImage src, VolatileImage dst) {
    int cnt = 5;
    do {
        Graphics2D g = dst.createGraphics();
        g.setColor(dstColor);
        g.fillRect(0, 0, dst.getWidth(), dst.getHeight());
        g.drawImage(src, 0, 0, null);
        g.dispose();
    } while (dst.contentsLost() && (--cnt > 0));

    if (cnt == 0) {
        System.err.println("Test failed: unable to render to volatile destination");
        return false;
    }

    BufferedImage s = dst.getSnapshot();

    return s.getRGB(1,1) == srcColor.getRGB();
}
 
Example 8
Source File: IncorrectAlphaConversionBicubic.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example 9
Source File: DrawCachedImageAndTransform.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment
            .getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice()
                                 .getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(100, 100);

    Graphics2D g2d = vi.createGraphics();
    g2d.scale(2, 2);
    BufferedImage img = new BufferedImage(50, 50,
                                          BufferedImage.TYPE_INT_ARGB);

    g2d.drawImage(img, 10, 25, Color.blue, null);
    g2d.dispose();
}
 
Example 10
Source File: OpaqueImageToSurfaceBlitTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {

        GraphicsEnvironment ge =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        VolatileImage vi = gc.createCompatibleVolatileImage(16, 16);
        vi.validate(gc);

        BufferedImage bi =
            new BufferedImage(2, 2, BufferedImage.TYPE_INT_RGB);
        int data[] = ((DataBufferInt)bi.getRaster().getDataBuffer()).getData();
        data[0] = 0x0000007f;
        data[1] = 0x0000007f;
        data[2] = 0xff00007f;
        data[3] = 0xff00007f;
        Graphics2D g = vi.createGraphics();
        g.setComposite(AlphaComposite.SrcOver.derive(0.999f));
        g.drawImage(bi, 0, 0, null);

        bi = vi.getSnapshot();
        if (bi.getRGB(0, 0) != bi.getRGB(1, 1)) {
            throw new RuntimeException("Test FAILED: color at 0x0 ="+
                Integer.toHexString(bi.getRGB(0, 0))+" differs from 1x1 ="+
                Integer.toHexString(bi.getRGB(1,1)));
        }

        System.out.println("Test PASSED.");
    }
 
Example 11
Source File: AccelPaintsTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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");
            }
        }
    }
}
 
Example 12
Source File: IncorrectAlphaConversionBicubic.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example 13
Source File: IncorrectAlphaConversionBicubic.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example 14
Source File: IncorrectAlphaConversionBicubic.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example 15
Source File: StrikeDisposalCrashTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void renderText(Frame frame, Font f1) {
    VolatileImage vi = frame.createVolatileImage(256, 32);
    vi.validate(frame.getGraphicsConfiguration());

    Graphics2D g = vi.createGraphics();
    g.setFont(f1);
    g.drawString(text, 0, vi.getHeight()/2);
    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                       RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g.drawString(text, 0, vi.getHeight()/2);
    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                       RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
    g.drawString(text, 0, vi.getHeight()/2);
    Toolkit.getDefaultToolkit().sync();
}
 
Example 16
Source File: DrawCachedImageAndTransform.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment
            .getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice()
                                 .getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(100, 100);

    Graphics2D g2d = vi.createGraphics();
    g2d.scale(2, 2);
    BufferedImage img = new BufferedImage(50, 50,
                                          BufferedImage.TYPE_INT_ARGB);

    g2d.drawImage(img, 10, 25, Color.blue, null);
    g2d.dispose();
}
 
Example 17
Source File: IncorrectAlphaConversionBicubic.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example 18
Source File: IncorrectClipXorModeSW2Surface.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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();
            }
        }
    }
}
 
Example 19
Source File: IncorrectClipXorModeSurface2Surface.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
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;
                VolatileImage source = getVolatileImage(gc, size);
                VolatileImage target = getVolatileImage(gc, size);
                int attempt = 0;
                while (true) {
                    if (++attempt > 10) {
                        throw new RuntimeException("Too many attempts: " + attempt);
                    }
                    // Prepare source images
                    source.validate(gc);
                    Graphics2D g2d = source.createGraphics();
                    g2d.setColor(Color.RED);
                    g2d.fillRect(0, 0, size, size);
                    g2d.dispose();
                    if (source.validate(gc) != VolatileImage.IMAGE_OK) {
                        continue;
                    }
                    // Prepare target images
                    target.validate(gc);
                    g2d = target.createGraphics();
                    g2d.setColor(Color.GREEN);
                    g2d.fillRect(0, 0, size, size);
                    g2d.dispose();
                    if (target.validate(gc) != VolatileImage.IMAGE_OK) {
                        continue;
                    }

                    draw(clip, to, source, target);
                    snapshot = target.getSnapshot();
                    if (source.contentsLost() || target.contentsLost()) {
                        continue;
                    }
                    break;
                }
                // Prepare gold images
                BufferedImage goldS = getSourceGold(gc, size);
                BufferedImage goldT = getTargetGold(gc, size);
                draw(clip, to, goldS, goldT);
                validate(snapshot, goldT);
                source.flush();
                target.flush();
            }
        }
    }
}
 
Example 20
Source File: IncorrectClipXorModeSurface2Surface.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
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;
                VolatileImage source = getVolatileImage(gc, size);
                VolatileImage target = getVolatileImage(gc, size);
                int attempt = 0;
                while (true) {
                    if (++attempt > 10) {
                        throw new RuntimeException("Too many attempts: " + attempt);
                    }
                    // Prepare source images
                    source.validate(gc);
                    Graphics2D g2d = source.createGraphics();
                    g2d.setColor(Color.RED);
                    g2d.fillRect(0, 0, size, size);
                    g2d.dispose();
                    if (source.validate(gc) != VolatileImage.IMAGE_OK) {
                        continue;
                    }
                    // Prepare target images
                    target.validate(gc);
                    g2d = target.createGraphics();
                    g2d.setColor(Color.GREEN);
                    g2d.fillRect(0, 0, size, size);
                    g2d.dispose();
                    if (target.validate(gc) != VolatileImage.IMAGE_OK) {
                        continue;
                    }

                    draw(clip, to, source, target);
                    snapshot = target.getSnapshot();
                    if (source.contentsLost() || target.contentsLost()) {
                        continue;
                    }
                    break;
                }
                // Prepare gold images
                BufferedImage goldS = getSourceGold(gc, size);
                BufferedImage goldT = getTargetGold(gc, size);
                draw(clip, to, goldS, goldT);
                validate(snapshot, goldT);
                source.flush();
                target.flush();
            }
        }
    }
}