java.awt.image.VolatileImage#getSnapshot()源码实例Demo

下面列出了java.awt.image.VolatileImage#getSnapshot() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdk8u60   文件: TransformedPaintTest.java
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.");
}
 
源代码2 项目: openjdk-8   文件: bug7181438.java
public static void main(final String[] args) {

        final BufferedImage bi = createBufferedImage();
        final VolatileImage vi = createVolatileImage();
        final Graphics s2dVi = vi.getGraphics();

        //sw->texture->surface blit
        s2dVi.drawImage(bi, 0, 0, null);

        final BufferedImage results = vi.getSnapshot();
        for (int i = 0; i < SIZE; ++i) {
            for (int j = 0; j < SIZE; ++j) {
                //Image should be opaque: (black color and alpha = 255)
                if (results.getRGB(i, j) != 0xFF000000) {
                    throw new RuntimeException("Failed: Wrong alpha");
                }
            }
        }
        System.out.println("Passed");
    }
 
源代码3 项目: hottub   文件: DrawHugeImageTest.java
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();
}
 
源代码4 项目: openjdk-jdk8u   文件: DrawHugeImageTest.java
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();
}
 
源代码5 项目: hottub   文件: bug7181438.java
public static void main(final String[] args) {

        final BufferedImage bi = createBufferedImage();
        final VolatileImage vi = createVolatileImage();
        final Graphics s2dVi = vi.getGraphics();

        //sw->texture->surface blit
        s2dVi.drawImage(bi, 0, 0, null);

        final BufferedImage results = vi.getSnapshot();
        for (int i = 0; i < SIZE; ++i) {
            for (int j = 0; j < SIZE; ++j) {
                //Image should be opaque: (black color and alpha = 255)
                if (results.getRGB(i, j) != 0xFF000000) {
                    throw new RuntimeException("Failed: Wrong alpha");
                }
            }
        }
        System.out.println("Passed");
    }
 
源代码6 项目: openjdk-jdk9   文件: bug7181438.java
public static void main(final String[] args) {

        final BufferedImage bi = createBufferedImage();
        final VolatileImage vi = createVolatileImage();
        final Graphics s2dVi = vi.getGraphics();

        //sw->texture->surface blit
        s2dVi.drawImage(bi, 0, 0, null);

        final BufferedImage results = vi.getSnapshot();
        for (int i = 0; i < SIZE; ++i) {
            for (int j = 0; j < SIZE; ++j) {
                //Image should be opaque: (black color and alpha = 255)
                if (results.getRGB(i, j) != 0xFF000000) {
                    throw new RuntimeException("Failed: Wrong alpha");
                }
            }
        }
        System.out.println("Passed");
    }
 
源代码7 项目: jdk8u_jdk   文件: OpaqueImageToSurfaceBlitTest.java
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.");
    }
 
源代码8 项目: jdk8u_jdk   文件: AccelPaintsTest.java
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");
            }
        }
    }
}
 
源代码9 项目: jdk8u-jdk   文件: OpaqueImageToSurfaceBlitTest.java
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.");
    }
 
源代码10 项目: dragonwell8_jdk   文件: AccelPaintsTest.java
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");
            }
        }
    }
}
 
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.");
    }
 
源代码12 项目: jdk8u-jdk   文件: OpaqueImageToSurfaceBlitTest.java
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.");
    }
 
源代码13 项目: TencentKona-8   文件: DashScaleMinWidth.java
public static void main(final String[] args) {
    BufferedImage img = new BufferedImage(200, 40, TYPE_INT_ARGB);
    draw(img);
    validate(img);

    if (GraphicsEnvironment.isHeadless()) {
        return;
    }

    GraphicsConfiguration gc =
            GraphicsEnvironment.getLocalGraphicsEnvironment()
                    .getDefaultScreenDevice().getDefaultConfiguration();

    VolatileImage vi = gc.createCompatibleVolatileImage(200, 40);
    BufferedImage snapshot;
    int attempt = 0;
    while (true) {
        if (++attempt > 10) {
            throw new RuntimeException("Too many attempts: " + attempt);
        }
        vi.validate(gc);
        draw(vi);
        snapshot = vi.getSnapshot();
        if (!vi.contentsLost()) {
            break;
        }
    }
    validate(snapshot);
}
 
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");
    }
}
 
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();
            }
        }
    }
}
 
源代码16 项目: openjdk-8   文件: RSLContextInvalidationTest.java
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.");
}
 
源代码17 项目: openjdk-jdk9   文件: RSLContextInvalidationTest.java
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.");
}
 
源代码18 项目: jdk8u-jdk   文件: DrawImageBgTest.java
public static void main(String[] args) {
    GraphicsConfiguration gc =
        GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration();

    if (gc.getColorModel().getPixelSize() <= 8) {
        System.out.println("8-bit color model, test considered passed");
        return;
    }

    /*
     * Set up images:
     * 1.) VolatileImge for rendering to,
     * 2.) BufferedImage for reading back the contents of the VI
     * 3.) The image triggering the problem
     */
    VolatileImage vImg = null;
    BufferedImage readBackBImg;

    // create a BITMASK ICM such that the transparent color is
    // tr. black (and it's the first in the color map so a buffered image
    // created with this ICM is transparent
    byte r[] = { 0x00, (byte)0xff};
    byte g[] = { 0x00, (byte)0xff};
    byte b[] = { 0x00, (byte)0xff};
    IndexColorModel icm = new IndexColorModel(8, 2, r, g, b, 0);
    WritableRaster wr = icm.createCompatibleWritableRaster(25, 25);
    BufferedImage tImg = new BufferedImage(icm, wr, false, null);

    do {
        if (vImg == null ||
            vImg.validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE)
        {
            vImg = gc.createCompatibleVolatileImage(tImg.getWidth(),
                                                    tImg.getHeight());
        }

        Graphics viG = vImg.getGraphics();
        viG.setColor(Color.red);
        viG.fillRect(0, 0, vImg.getWidth(), vImg.getHeight());

        viG.drawImage(tImg, 0, 0, Color.green, null);
        viG.fillRect(0, 0, vImg.getWidth(), vImg.getHeight());
        viG.drawImage(tImg, 0, 0, Color.white, null);

        readBackBImg = vImg.getSnapshot();
    } while (vImg.contentsLost());

    for (int x = 0; x < readBackBImg.getWidth(); x++) {
        for (int y = 0; y < readBackBImg.getHeight(); y++) {
            int currPixel = readBackBImg.getRGB(x, y);
            if (currPixel != Color.white.getRGB()) {
                String fileName = "DrawImageBgTest.png";
                try {
                    ImageIO.write(readBackBImg, "png", new File(fileName));
                    System.err.println("Dumped image to " + fileName);
                } catch (IOException ex) {}
                throw new
                    RuntimeException("Test Failed: found wrong color: 0x"+
                                     Integer.toHexString(currPixel));
            }
        }
    }
    System.out.println("Test Passed.");
}
 
源代码19 项目: jdk8u60   文件: RSLContextInvalidationTest.java
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.");
}
 
源代码20 项目: jdk8u-dev-jdk   文件: RSLContextInvalidationTest.java
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.");
}