Java Code Examples for java.awt.GraphicsConfiguration#createCompatibleVolatileImage()

The following examples show how to use java.awt.GraphicsConfiguration#createCompatibleVolatileImage() . 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: VolatileImageBug.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {

        boolean iaeThrown = false;
        GraphicsEnvironment ge = GraphicsEnvironment.
                                      getLocalGraphicsEnvironment();
        GraphicsConfiguration gc = ge.getDefaultScreenDevice().
                                           getDefaultConfiguration();
        try {
            VolatileImage volatileImage = gc.createCompatibleVolatileImage(0, 0);
        } catch (IllegalArgumentException iae) {
            iaeThrown = true;
        }
        if (!iaeThrown) {
            throw new RuntimeException ("IllegalArgumentException not thrown " +
                                        "for createCompatibleVolatileImage(0,0)");
        }
    }
 
Example 2
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 3
Source File: AcceleratedScaleTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void initVI(GraphicsConfiguration gc) {
    int res;
    if (destVI == null) {
        res = VolatileImage.IMAGE_INCOMPATIBLE;
    } else {
        res = destVI.validate(gc);
    }
    if (res == VolatileImage.IMAGE_INCOMPATIBLE) {
        if (destVI != null) destVI.flush();
        destVI = gc.createCompatibleVolatileImage(IMAGE_SIZE, IMAGE_SIZE);
        destVI.validate(gc);
        res = VolatileImage.IMAGE_RESTORED;
    }
    if (res == VolatileImage.IMAGE_RESTORED) {
        Graphics vig = destVI.getGraphics();
        vig.setColor(Color.red);
        vig.fillRect(0, 0, destVI.getWidth(), destVI.getHeight());
        vig.dispose();
    }
}
 
Example 4
Source File: NonOpaqueDestLCDAATest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private void initImages(int w, int h) {
    if (images == null) {
        images = new Image[6];
        GraphicsConfiguration gc = getGraphicsConfiguration();
        for (int i = OPAQUE; i <= TRANSLUCENT; i++) {
            VolatileImage vi =
                gc.createCompatibleVolatileImage(w,h/images.length,i);
            images[i-1] = vi;
            vi.validate(gc);
            String s = "LCD AA Text rendered to " + tr[i - 1] + " HW destination";
            render(vi, i, s);

            s = "LCD AA Text rendered to " + tr[i - 1] + " SW destination";
            images[i-1+3] = gc.createCompatibleImage(w, h/images.length, i);
            render(images[i-1+3], i, s);
        }
    }
}
 
Example 5
Source File: TranslucentWindowPainter.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected Image getBackBuffer(boolean clear) {
    int w = window.getWidth();
    int h = window.getHeight();
    GraphicsConfiguration gc = peer.getGraphicsConfiguration();

    if (viBB == null || viBB.getWidth() != w || viBB.getHeight() != h ||
        viBB.validate(gc) == IMAGE_INCOMPATIBLE)
    {
        flush();

        if (gc instanceof AccelGraphicsConfig) {
            AccelGraphicsConfig agc = ((AccelGraphicsConfig)gc);
            viBB = agc.createCompatibleVolatileImage(w, h,
                                                     TRANSLUCENT,
                                                     RT_PLAIN);
        }
        if (viBB == null) {
            viBB = gc.createCompatibleVolatileImage(w, h, TRANSLUCENT);
        }
        viBB.validate(gc);
    }

    return clear ? clearImage(viBB) : viBB;
}
 
Example 6
Source File: IncorrectClipSurface2SW.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: CustomCompositeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void testVolatileImage(GraphicsConfiguration cfg,
        boolean accelerated)
{
    VolatileImage dst = null;
    try {
        dst = cfg.createCompatibleVolatileImage(640, 480,
            new ImageCapabilities(accelerated));
    } catch (AWTException e) {
        System.out.println("Unable to create volatile image, skip the test.");
        return;
    }
    renderToVolatileImage(dst);
}
 
Example 8
Source File: InfiniteValidationLoopTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void runTest(Graphics g) {
    int status = IMAGE_OK;
    int count1 = 0;
    do {
        GraphicsConfiguration gc = getGraphicsConfiguration();
        int count2 = 0;
        while (vi == null || (status = vi.validate(gc)) != IMAGE_OK) {
            if (++count2 > LOOP_THRESHOLD) {
                System.err.println("Infinite loop detected: count2="+count2);
                failed = true;
                return;
            }
            if (vi == null || status == IMAGE_INCOMPATIBLE) {
                if (vi != null) { vi.flush(); vi = null; }
                vi = gc.createCompatibleVolatileImage(100, 100);
                continue;
            }
            if (status == IMAGE_RESTORED) {
                Graphics gg = vi.getGraphics();
                gg.setColor(Color.green);
                gg.fillRect(0, 0, vi.getWidth(), vi.getHeight());
                break;
            }
        }
        g.drawImage(vi, getInsets().left, getInsets().top, null);
        if (++count1 > LOOP_THRESHOLD) {
            System.err.println("Infinite loop detected: count1="+count1);
            failed = true;
            return;
        }
    } while (vi.contentsLost());
}
 
Example 9
Source File: DashScaleMinWidth.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 10
Source File: DrawCachedImageAndTransform.java    From jdk8u_jdk 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 11
Source File: ScaledImageAlphaTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static VolatileImage createVolatileImage(int width, int height,
                                                 int transparency) {
    GraphicsEnvironment ge = GraphicsEnvironment.
                             getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().
                               getDefaultConfiguration();

    VolatileImage image = gc.createCompatibleVolatileImage(width, height,
                                                           transparency);
    return image;
}
 
Example 12
Source File: AccelPaintsTest.java    From hottub 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 13
Source File: IncorrectClipSurface2SW.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 14
Source File: DashScaleMinWidth.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 15
Source File: OpaqueImageToSurfaceBlitTest.java    From openjdk-jdk8u 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 16
Source File: DrawHugeImageTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static VolatileImage createDst() {
    GraphicsConfiguration gc =
            GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();

    return gc.createCompatibleVolatileImage(200, 200);
}
 
Example 17
Source File: bug7181438.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static VolatileImage createVolatileImage() {
    final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    return gc.createCompatibleVolatileImage(SIZE, SIZE,
                                            Transparency.TRANSLUCENT);
}
 
Example 18
Source File: DrawImageBgTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
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.");
}
 
Example 19
Source File: IncorrectClipXorModeSW2Surface.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static VolatileImage getVolatileImage(GraphicsConfiguration gc,
                                              int size) {
    return gc.createCompatibleVolatileImage(size, size);
}
 
Example 20
Source File: DrawImageBgTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
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.");
}