java.awt.image.VolatileImage Java Examples

The following examples show how to use java.awt.image.VolatileImage. 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: DisplayChangeVITest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 7 votes vote down vote up
private void initBackbuffer() {
    createBackbuffer();

    int res = bb.validate(getGraphicsConfiguration());
    if (res == VolatileImage.IMAGE_INCOMPATIBLE) {
        bb = null;
        createBackbuffer();
        bb.validate(getGraphicsConfiguration());
        res = VolatileImage.IMAGE_RESTORED;
    }
    if (res == VolatileImage.IMAGE_RESTORED) {
        Graphics g = bb.getGraphics();
        g.setColor(new Color(rnd.nextInt(0x00ffffff)));
        g.fillRect(0, 0, bb.getWidth(), bb.getHeight());

        volSprite = createVolatileImage(100, 100);
    }
    volSprite.validate(getGraphicsConfiguration());
}
 
Example #2
Source File: AcceleratedScaleTest.java    From openjdk-8-source 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 #3
Source File: DrawHugeImageTest.java    From TencentKona-8 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 #4
Source File: PathGraphics.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
protected BufferedImage getBufferedImage(Image img) {
    if (img instanceof BufferedImage) {
        // Otherwise we expect a BufferedImage to behave as a standard BI
        return (BufferedImage)img;
    } else if (img instanceof ToolkitImage) {
        // This can be null if the image isn't loaded yet.
        // This is fine as in that case our caller will return
        // as it will only draw a fully loaded image
        return ((ToolkitImage)img).getBufferedImage();
    } else if (img instanceof VolatileImage) {
        // VI needs to make a new BI: this is unavoidable but
        // I don't expect VI's to be "huge" in any case.
        return ((VolatileImage)img).getSnapshot();
    } else {
        // may be null or may be some non-standard Image which
        // shouldn't happen as Image is implemented by the platform
        // not by applications
        // If you add a new Image implementation to the platform you
        // will need to support it here similarly to VI.
        return null;
    }
}
 
Example #5
Source File: TransformedPaintTest.java    From jdk8u-dev-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: PathGraphics.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
protected BufferedImage getBufferedImage(Image img) {
    if (img instanceof BufferedImage) {
        // Otherwise we expect a BufferedImage to behave as a standard BI
        return (BufferedImage)img;
    } else if (img instanceof ToolkitImage) {
        // This can be null if the image isn't loaded yet.
        // This is fine as in that case our caller will return
        // as it will only draw a fully loaded image
        return ((ToolkitImage)img).getBufferedImage();
    } else if (img instanceof VolatileImage) {
        // VI needs to make a new BI: this is unavoidable but
        // I don't expect VI's to be "huge" in any case.
        return ((VolatileImage)img).getSnapshot();
    } else {
        // may be null or may be some non-standard Image which
        // shouldn't happen as Image is implemented by the platform
        // not by applications
        // If you add a new Image implementation to the platform you
        // will need to support it here similarly to VI.
        return null;
    }
}
 
Example #7
Source File: TransformSetGet.java    From jdk8u60 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 #8
Source File: TransformSetGet.java    From jdk8u_jdk 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 #9
Source File: AcceleratedScaleTest.java    From openjdk-jdk8u-backup 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 #10
Source File: AltTabCrashTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void render(Graphics g)  {
    do {
        height = getBounds().height;
        width = getBounds().width;
        if (vimg == null) {
            vimg = createVolatileImage(width, height);
            renderOffscreen();
        }
        int returnCode = vimg.validate(getGraphicsConfiguration());
        if (returnCode == VolatileImage.IMAGE_RESTORED) {
            renderOffscreen();
        } else if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) {
            vimg = getGraphicsConfiguration().
                createCompatibleVolatileImage(width, height);
            renderOffscreen();
        } else if (returnCode == VolatileImage.IMAGE_OK) {
            renderOffscreen();
        }
        g.drawImage(vimg, 0, 0, this);
    } while (vimg.contentsLost());
}
 
Example #11
Source File: BufferedCanvasComponent.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private int updateOffscreenImage() {
    // Update offscreen image reference
    if (offscreenImage == null) offscreenImage = offscreenImageReference.get();
    
    // Offscreen image not available
    if (offscreenImage == null) return VolatileImage.IMAGE_INCOMPATIBLE;
    
    // Buffered image is always valid
    if (bufferType != BUFFER_VOLATILE_IMAGE) return VolatileImage.IMAGE_OK;
    
    // Determine GraphicsConfiguration context
    GraphicsConfiguration gConfiguration = getGraphicsConfiguration();
    if (gConfiguration == null) return VolatileImage.IMAGE_INCOMPATIBLE;
    
    // Return Volatile image state
    return ((VolatileImage)offscreenImage).validate(gConfiguration);
}
 
Example #12
Source File: AltTabCrashTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void render(Graphics g)  {
    do {
        height = getBounds().height;
        width = getBounds().width;
        if (vimg == null) {
            vimg = createVolatileImage(width, height);
            renderOffscreen();
        }
        int returnCode = vimg.validate(getGraphicsConfiguration());
        if (returnCode == VolatileImage.IMAGE_RESTORED) {
            renderOffscreen();
        } else if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) {
            vimg = getGraphicsConfiguration().
                createCompatibleVolatileImage(width, height);
            renderOffscreen();
        } else if (returnCode == VolatileImage.IMAGE_OK) {
            renderOffscreen();
        }
        g.drawImage(vimg, 0, 0, this);
    } while (vimg.contentsLost());
}
 
Example #13
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 #14
Source File: IncorrectClipSurface2SW.java    From TencentKona-8 with GNU General Public License v2.0 5 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 (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);
                }
            }
        }
    }
}
 
Example #15
Source File: IncorrectClipSurface2SW.java    From openjdk-jdk9 with GNU General Public License v2.0 5 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 (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);
                }
            }
        }
    }
}
 
Example #16
Source File: UnmanagedDrawImagePerformance.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) {
    for (final AffineTransform atfm : TRANSFORMS) {
        for (final int viType : TRANSPARENCIES) {
            for (final int biType : TYPES) {
                final BufferedImage bi = makeUnmanagedBI(biType);
                final VolatileImage vi = makeVI(viType);
                final long time = test(bi, vi, atfm) / 1000000000;
                if (time > 1) {
                    throw new RuntimeException(String.format(
                            "drawImage is slow: %d seconds", time));
                }
            }
        }
    }
}
 
Example #17
Source File: CustomCompositeTest.java    From jdk8u60 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 #18
Source File: UnmanagedDrawImagePerformance.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static VolatileImage makeVI(final int type) {
    final GraphicsEnvironment ge = GraphicsEnvironment
            .getLocalGraphicsEnvironment();
    final GraphicsDevice gd = ge.getDefaultScreenDevice();
    final GraphicsConfiguration gc = gd.getDefaultConfiguration();
    return gc.createCompatibleVolatileImage(SIZE, SIZE, type);
}
 
Example #19
Source File: RepaintManager.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Paints a region of a component
 *
 * @param paintingComponent Component to paint
 * @param bufferComponent Component to obtain buffer for
 * @param g Graphics to paint to
 * @param x X-coordinate
 * @param y Y-coordinate
 * @param w Width
 * @param h Height
 * @return true if painting was successful.
 */
public boolean paint(JComponent paintingComponent,
                     JComponent bufferComponent, Graphics g,
                     int x, int y, int w, int h) {
    // First attempt to use VolatileImage buffer for performance.
    // If this fails (which should rarely occur), fallback to a
    // standard Image buffer.
    boolean paintCompleted = false;
    Image offscreen;
    if (repaintManager.useVolatileDoubleBuffer() &&
        (offscreen = getValidImage(repaintManager.
        getVolatileOffscreenBuffer(bufferComponent, w, h))) != null) {
        VolatileImage vImage = (java.awt.image.VolatileImage)offscreen;
        GraphicsConfiguration gc = bufferComponent.
                                    getGraphicsConfiguration();
        for (int i = 0; !paintCompleted &&
                 i < RepaintManager.VOLATILE_LOOP_MAX; i++) {
            if (vImage.validate(gc) ==
                           VolatileImage.IMAGE_INCOMPATIBLE) {
                repaintManager.resetVolatileDoubleBuffer(gc);
                offscreen = repaintManager.getVolatileOffscreenBuffer(
                    bufferComponent,w, h);
                vImage = (java.awt.image.VolatileImage)offscreen;
            }
            paintDoubleBuffered(paintingComponent, vImage, g, x, y,
                                w, h);
            paintCompleted = !vImage.contentsLost();
        }
    }
    // VolatileImage painting loop failed, fallback to regular
    // offscreen buffer
    if (!paintCompleted && (offscreen = getValidImage(
              repaintManager.getOffscreenBuffer(
              bufferComponent, w, h))) != null) {
        paintDoubleBuffered(paintingComponent, offscreen, g, x, y, w,
                            h);
        paintCompleted = true;
    }
    return paintCompleted;
}
 
Example #20
Source File: RepaintManager.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Paints a region of a component
 *
 * @param paintingComponent Component to paint
 * @param bufferComponent Component to obtain buffer for
 * @param g Graphics to paint to
 * @param x X-coordinate
 * @param y Y-coordinate
 * @param w Width
 * @param h Height
 * @return true if painting was successful.
 */
public boolean paint(JComponent paintingComponent,
                     JComponent bufferComponent, Graphics g,
                     int x, int y, int w, int h) {
    // First attempt to use VolatileImage buffer for performance.
    // If this fails (which should rarely occur), fallback to a
    // standard Image buffer.
    boolean paintCompleted = false;
    Image offscreen;
    if (repaintManager.useVolatileDoubleBuffer() &&
        (offscreen = getValidImage(repaintManager.
        getVolatileOffscreenBuffer(bufferComponent, w, h))) != null) {
        VolatileImage vImage = (java.awt.image.VolatileImage)offscreen;
        GraphicsConfiguration gc = bufferComponent.
                                    getGraphicsConfiguration();
        for (int i = 0; !paintCompleted &&
                 i < RepaintManager.VOLATILE_LOOP_MAX; i++) {
            if (vImage.validate(gc) ==
                           VolatileImage.IMAGE_INCOMPATIBLE) {
                repaintManager.resetVolatileDoubleBuffer(gc);
                offscreen = repaintManager.getVolatileOffscreenBuffer(
                    bufferComponent,w, h);
                vImage = (java.awt.image.VolatileImage)offscreen;
            }
            paintDoubleBuffered(paintingComponent, vImage, g, x, y,
                                w, h);
            paintCompleted = !vImage.contentsLost();
        }
    }
    // VolatileImage painting loop failed, fallback to regular
    // offscreen buffer
    if (!paintCompleted && (offscreen = getValidImage(
              repaintManager.getOffscreenBuffer(
              bufferComponent, w, h))) != null) {
        paintDoubleBuffered(paintingComponent, offscreen, g, x, y, w,
                            h);
        paintCompleted = true;
    }
    return paintCompleted;
}
 
Example #21
Source File: DrawCachedImageAndTransform.java    From dragonwell8_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 #22
Source File: RepaintManager.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
* Return a volatile offscreen buffer that should be used as a
* double buffer with the specified component <code>c</code>.
* The image returned will be an instance of VolatileImage, or null
* if a VolatileImage object could not be instantiated.
* This buffer might be smaller than <code>(proposedWidth,proposedHeight)</code>.
* This happens when the maximum double buffer size has been set for this
* repaint manager.
*
* @see java.awt.image.VolatileImage
* @since 1.4
*/
 public Image getVolatileOffscreenBuffer(Component c,
                                         int proposedWidth,int proposedHeight) {
     RepaintManager delegate = getDelegate(c);
     if (delegate != null) {
         return delegate.getVolatileOffscreenBuffer(c, proposedWidth,
                                                     proposedHeight);
     }

     // If the window is non-opaque, it's double-buffered at peer's level
     Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c);
     if (!w.isOpaque()) {
         Toolkit tk = Toolkit.getDefaultToolkit();
         if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) {
             return null;
         }
     }

     GraphicsConfiguration config = c.getGraphicsConfiguration();
     if (config == null) {
         config = GraphicsEnvironment.getLocalGraphicsEnvironment().
                         getDefaultScreenDevice().getDefaultConfiguration();
     }
     Dimension maxSize = getDoubleBufferMaximumSize();
     int width = proposedWidth < 1 ? 1 :
         (proposedWidth > maxSize.width? maxSize.width : proposedWidth);
     int height = proposedHeight < 1 ? 1 :
         (proposedHeight > maxSize.height? maxSize.height : proposedHeight);
     VolatileImage image = volatileMap.get(config);
     if (image == null || image.getWidth() < width ||
                          image.getHeight() < height) {
         if (image != null) {
             image.flush();
         }
         image = config.createCompatibleVolatileImage(width, height,
                                                      volatileBufferType);
         volatileMap.put(config, image);
     }
     return image;
 }
 
Example #23
Source File: AltTabCrashTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void validateSprite() {
    int result =
        ((VolatileImage)image).validate(getGraphicsConfiguration());
    if (result == VolatileImage.IMAGE_INCOMPATIBLE) {
        image = createSprite();
        result = VolatileImage.IMAGE_RESTORED;
    }
    if (result == VolatileImage.IMAGE_RESTORED) {
        Graphics g = image.getGraphics();
        g.setColor(color);
        g.fillRect(0, 0, image.getWidth(null), image.getHeight(null));
    }
}
 
Example #24
Source File: RepaintManager.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
* Return a volatile offscreen buffer that should be used as a
* double buffer with the specified component <code>c</code>.
* The image returned will be an instance of VolatileImage, or null
* if a VolatileImage object could not be instantiated.
* This buffer might be smaller than <code>(proposedWidth,proposedHeight)</code>.
* This happens when the maximum double buffer size has been set for this
* repaint manager.
*
* @see java.awt.image.VolatileImage
* @since 1.4
*/
 public Image getVolatileOffscreenBuffer(Component c,
                                         int proposedWidth,int proposedHeight) {
     RepaintManager delegate = getDelegate(c);
     if (delegate != null) {
         return delegate.getVolatileOffscreenBuffer(c, proposedWidth,
                                                     proposedHeight);
     }

     // If the window is non-opaque, it's double-buffered at peer's level
     Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c);
     if (!w.isOpaque()) {
         Toolkit tk = Toolkit.getDefaultToolkit();
         if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) {
             return null;
         }
     }

     GraphicsConfiguration config = c.getGraphicsConfiguration();
     if (config == null) {
         config = GraphicsEnvironment.getLocalGraphicsEnvironment().
                         getDefaultScreenDevice().getDefaultConfiguration();
     }
     Dimension maxSize = getDoubleBufferMaximumSize();
     int width = proposedWidth < 1 ? 1 :
         (proposedWidth > maxSize.width? maxSize.width : proposedWidth);
     int height = proposedHeight < 1 ? 1 :
         (proposedHeight > maxSize.height? maxSize.height : proposedHeight);
     VolatileImage image = volatileMap.get(config);
     if (image == null || image.getWidth() < width ||
                          image.getHeight() < height) {
         if (image != null) {
             image.flush();
         }
         image = config.createCompatibleVolatileImage(width, height,
                                                      volatileBufferType);
         volatileMap.put(config, image);
     }
     return image;
 }
 
Example #25
Source File: IncorrectClipSurface2SW.java    From TencentKona-8 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 #26
Source File: AccelPaintsTest.java    From openjdk-jdk9 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 #27
Source File: SourceClippingBlitTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static VolatileImage getVImage(GraphicsConfiguration gc,
                               int w, int h)
{
    VolatileImage image =
        gc.createCompatibleVolatileImage(w, h, Transparency.OPAQUE);
    image.validate(gc);
    initImage(gc, image);
    return image;
}
 
Example #28
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 #29
Source File: CustomCompositeTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void renderToVolatileImage(VolatileImage dst) {
    Graphics2D g = dst.createGraphics();
    do {
        System.out.println("Render to volatile image..");
        try {
            MyComp.renderTest(g, dst.getHeight(), dst.getHeight());
        } catch (Throwable e) {
            throw new RuntimeException("Test FAILED.", e);
        }
    } while (dst.contentsLost());
    System.out.println("Done.");
}
 
Example #30
Source File: RSLAPITest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void testGC(GraphicsConfiguration gc) {
    if (!(gc instanceof AccelGraphicsConfig)) {
        System.out.println("Test passed: no hw accelerated configs found.");
        return;
    }
    System.out.println("AccelGraphicsConfig exists, testing.");
    AccelGraphicsConfig agc = (AccelGraphicsConfig) gc;
    printAGC(agc);

    testContext(agc);

    VolatileImage vi = gc.createCompatibleVolatileImage(10, 10);
    vi.validate(gc);
    if (vi instanceof DestSurfaceProvider) {
        System.out.println("Passed: VI is DestSurfaceProvider");
        Surface s = ((DestSurfaceProvider) vi).getDestSurface();
        if (s instanceof AccelSurface) {
            System.out.println("Passed: Obtained Accel Surface");
            printSurface((AccelSurface) s);
        }
        Graphics g = vi.getGraphics();
        if (g instanceof DestSurfaceProvider) {
            System.out.println("Passed: VI graphics is " +
                               "DestSurfaceProvider");
            printSurface(((DestSurfaceProvider) g).getDestSurface());
        }
    } else {
        System.out.println("VI is not DestSurfaceProvider");
    }
    testVICreation(agc, CAPS_RT_TEXTURE_ALPHA, TRANSLUCENT, RT_TEXTURE);
    testVICreation(agc, CAPS_RT_TEXTURE_OPAQUE, OPAQUE, RT_TEXTURE);
    testVICreation(agc, CAPS_RT_PLAIN_ALPHA, TRANSLUCENT, RT_PLAIN);
    testVICreation(agc, agc.getContextCapabilities().getCaps(), OPAQUE,
                   TEXTURE);
    testForNPEDuringCreation(agc);
}