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

The following examples show how to use java.awt.image.VolatileImage#flush() . 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: TransformSetGet.java    From openjdk-jdk8u-backup 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 2
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 3
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 4
Source File: TransformSetGet.java    From TencentKona-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: RepaintManager.java    From dragonwell8_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 6
Source File: RepaintManager.java    From openjdk-8-source 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 7
Source File: RepaintManager.java    From Java8CN with Apache License 2.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 8
Source File: RepaintManager.java    From openjdk-jdk8u-backup 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 9
Source File: RepaintManager.java    From openjdk-jdk9 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.
 *
 * @param c the component
 * @param proposedWidth the width of the buffer
 * @param proposedHeight the height of the buffer
 *
 * @return the volatile image
 * @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 10
Source File: SimpleCachedPainter.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
protected void invalidateCache() {
    if (cache != null) {
        VolatileImage image = cache.get();
        if (image != null) {
            image.flush();
        }
        cache = null;
    }
}
 
Example 11
Source File: IncorrectClipXorModeSurface2Surface.java    From hottub 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 12
Source File: WComponentPeer.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Multi-buffer version of replaceSurfaceData.  This version is called
 * by createBuffers(), which needs to acquire the same locks in the same
 * order, but also needs to perform additional functions inside the
 * locks.
 */
public void replaceSurfaceData(int newNumBackBuffers,
                               BufferCapabilities caps)
{
    SurfaceData oldData = null;
    VolatileImage oldBB = null;
    synchronized(((Component)target).getTreeLock()) {
        synchronized(this) {
            if (pData == 0) {
                return;
            }
            numBackBuffers = newNumBackBuffers;
            ScreenUpdateManager mgr = ScreenUpdateManager.getInstance();
            oldData = surfaceData;
            mgr.dropScreenSurface(oldData);
            createScreenSurface(true);
            if (oldData != null) {
                oldData.invalidate();
            }

            oldBB = backBuffer;
            if (numBackBuffers > 0) {
                // set the caps first, they're used when creating the bb
                backBufferCaps = caps;
                Win32GraphicsConfig gc =
                    (Win32GraphicsConfig)getGraphicsConfiguration();
                backBuffer = gc.createBackBuffer(this);
            } else if (backBuffer != null) {
                backBufferCaps = null;
                backBuffer = null;
            }
        }
    }
    // it would be better to do this before we create new ones,
    // but then we'd run into deadlock issues
    if (oldData != null) {
        oldData.flush();
        // null out the old data to make it collected faster
        oldData = null;
    }
    if (oldBB != null) {
        oldBB.flush();
        // null out the old data to make it collected faster
        oldData = null;
    }
}
 
Example 13
Source File: IncorrectClipXorModeSurface2Surface.java    From jdk8u_jdk 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 14
Source File: AbstractRegionPainter.java    From seaglass with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the rendered image for this painter at the requested size, either
 * from cache or create a new one
 *
 * @param  config            the graphics configuration.
 * @param  c                 the component to paint.
 * @param  w                 the component width.
 * @param  h                 the component height.
 * @param  extendedCacheKeys extended cache keys.
 *
 * @return the new image.
 */
private VolatileImage getImage(GraphicsConfiguration config, JComponent c, int w, int h, Object[] extendedCacheKeys) {
    ImageCache imageCache = ImageCache.getInstance();

    // get the buffer for this component
    VolatileImage buffer = (VolatileImage) imageCache.getImage(config, w, h, this, extendedCacheKeys);

    int renderCounter = 0; // to avoid any potential, though unlikely,

    // infinite loop
    do {

        // validate the buffer so we can check for surface loss
        int bufferStatus = VolatileImage.IMAGE_INCOMPATIBLE;

        if (buffer != null) {
            bufferStatus = buffer.validate(config);
        }

        // If the buffer status is incompatible or restored, then we need to
        // re-render to the volatile image
        if (bufferStatus == VolatileImage.IMAGE_INCOMPATIBLE || bufferStatus == VolatileImage.IMAGE_RESTORED) {

            // if the buffer is null (hasn't been created), or isn't the
            // right size, or has lost its contents,
            // then recreate the buffer
            if (buffer == null || buffer.getWidth() != w || buffer.getHeight() != h
                    || bufferStatus == VolatileImage.IMAGE_INCOMPATIBLE) {

                // clear any resources related to the old back buffer
                if (buffer != null) {
                    buffer.flush();
                    buffer = null;
                }

                // recreate the buffer
                buffer = config.createCompatibleVolatileImage(w, h, Transparency.TRANSLUCENT);

                // put in cache for future
                imageCache.setImage(buffer, config, w, h, this, extendedCacheKeys);
            }

            // create the graphics context with which to paint to the buffer
            Graphics2D bg = buffer.createGraphics();

            // clear the background before configuring the graphics
            bg.setComposite(AlphaComposite.Clear);
            bg.fillRect(0, 0, w, h);
            bg.setComposite(AlphaComposite.SrcOver);
            configureGraphics(bg);

            // paint the painter into buffer
            paintDirectly(bg, c, w, h, extendedCacheKeys);

            // close buffer graphics
            bg.dispose();
        }
    } while (buffer.contentsLost() && renderCounter++ < 3);

    // check if we failed
    if (renderCounter == 3)
        return null;

    // return image
    return buffer;
}
 
Example 15
Source File: WComponentPeer.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Multi-buffer version of replaceSurfaceData.  This version is called
 * by createBuffers(), which needs to acquire the same locks in the same
 * order, but also needs to perform additional functions inside the
 * locks.
 */
public void replaceSurfaceData(int newNumBackBuffers,
                               BufferCapabilities caps)
{
    SurfaceData oldData = null;
    VolatileImage oldBB = null;
    synchronized(((Component)target).getTreeLock()) {
        synchronized(this) {
            if (pData == 0) {
                return;
            }
            numBackBuffers = newNumBackBuffers;
            ScreenUpdateManager mgr = ScreenUpdateManager.getInstance();
            oldData = surfaceData;
            mgr.dropScreenSurface(oldData);
            createScreenSurface(true);
            if (oldData != null) {
                oldData.invalidate();
            }

            oldBB = backBuffer;
            if (numBackBuffers > 0) {
                // set the caps first, they're used when creating the bb
                backBufferCaps = caps;
                Win32GraphicsConfig gc =
                    (Win32GraphicsConfig)getGraphicsConfiguration();
                backBuffer = gc.createBackBuffer(this);
            } else if (backBuffer != null) {
                backBufferCaps = null;
                backBuffer = null;
            }
        }
    }
    // it would be better to do this before we create new ones,
    // but then we'd run into deadlock issues
    if (oldData != null) {
        oldData.flush();
        // null out the old data to make it collected faster
        oldData = null;
    }
    if (oldBB != null) {
        oldBB.flush();
        // null out the old data to make it collected faster
        oldData = null;
    }
}
 
Example 16
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 17
Source File: IncorrectClipXorModeSW2Surface.java    From hottub 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 18
Source File: IncorrectClipXorModeSW2Surface.java    From jdk8u-jdk 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: IncorrectClipXorModeSW2Surface.java    From openjdk-jdk8u 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 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();
            }
        }
    }
}