public void actionPerformed(ActionEvent arg0) { if (!frameRendered) { if (volatileImage != null) { volatileImage.flush(); volatileImage = null; } // Stop the timer so we don't wakeup needlessly resourceTimer.stop(); } frameRendered = false; } };
@AnyThread public void flush() { lock.lock(); try { volatileImage.flush(); } finally { lock.unlock(); } }
@Override public void removeNotify() { super.removeNotify(); if (drawingBufferNV != null) { drawingBufferNV.flush(); drawingBufferNV = null; } if (drawingBufferV != null) { drawingBufferV.flush(); drawingBufferV = null; } }
/** Sets whether the drawing is double buffered. * <p> * The default value is true. * <p> * This is a bound property. * <p> * If the drawing view is used for editing, you should leave this to true. * If the drawing view is used for viewing only, you should set this to false. */ public void setDrawingDoubleBuffered(boolean newValue) { boolean oldValue = isDrawingDoubleBuffered; isDrawingDoubleBuffered = newValue; if (!isDrawingDoubleBuffered && drawingBufferV != null) { drawingBufferV.flush(); drawingBufferV = null; } if (!isDrawingDoubleBuffered && drawingBufferNV != null) { drawingBufferNV.flush(); drawingBufferNV = null; } firePropertyChange(DRAWING_DOUBLE_BUFFERED_PROPERTY, oldValue, newValue); }
/** * Creates the off-screen buffer used to perform double buffered rendering of the animated * panel. */ protected void createBackBuffer (GraphicsConfiguration gc) { // if we have an old image, clear it out if (_backimg != null) { _backimg.flush(); _bgfx.dispose(); } // create the offscreen buffer int width = _window.getWidth(), height = _window.getHeight(); _backimg = gc.createCompatibleVolatileImage(width, height); // fill the back buffer with white _bgfx = (Graphics2D)_backimg.getGraphics(); _bgfx.fillRect(0, 0, width, height); // clear out our frame graphics in case that became invalid for // the same reasons our back buffer became invalid if (_fgfx != null) { _fgfx.dispose(); _fgfx = null; } // Log.info("Created back buffer [" + width + "x" + height + "]."); }
/** * Creates the off-screen buffer used to perform double buffered rendering of the animated * panel. */ protected void createBackBuffer (GraphicsConfiguration gc) { // if we have an old image, clear it out if (_backimg != null) { _backimg.flush(); _bgfx.dispose(); } // create the offscreen buffer int width = _window.getWidth(), height = _window.getHeight(); _backimg = gc.createCompatibleVolatileImage(width, height); // fill the back buffer with white _bgfx = (Graphics2D)_backimg.getGraphics(); _bgfx.fillRect(0, 0, width, height); // clear out our frame graphics in case that became invalid for // the same reasons our back buffer became invalid if (_fgfx != null) { _fgfx.dispose(); _fgfx = null; } // Log.info("Created back buffer [" + width + "x" + height + "]."); }
private void renderVolatileImage(BufferedImage bufferedImage) { do { int w = bufferedImage.getWidth(), h = bufferedImage.getHeight(); GraphicsConfiguration gc = getGraphicsConfiguration(); if (volatileImage == null || volatileImage.getWidth() != w || volatileImage.getHeight() != h || volatileImage.validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE) { if (volatileImage != null) { volatileImage.flush(); } volatileImage = gc.createCompatibleVolatileImage(w, h); volatileImage.setAccelerationPriority(1.0f); } // // Now paint the BufferedImage into the accelerated image // Graphics2D g = volatileImage.createGraphics(); g.drawImage(bufferedImage, 0, 0, null); g.dispose(); } while (volatileImage.contentsLost()); }
private void renderVolatileImage(final GraphicsConfiguration gc, final BufferedImage image) { do { if (volatileImage == null || volatileImage.getWidth() != SIDE || volatileImage.getHeight() != SIDE || volatileImage.validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE) { if (volatileImage != null) { volatileImage.flush(); } volatileImage = gc.createCompatibleVolatileImage(SIDE, SIDE); volatileImage.setAccelerationPriority(1.0f); invalid_volatile = false; } // // Now paint the BufferedImage into the accelerated image // final Graphics2D g = volatileImage.createGraphics(); if (null != image) g.drawImage(image, 0, 0, SIDE, SIDE, null); // paint red rectangle indicating srcRect final Rectangle srcRect = display.getCanvas().getSrcRect(); g.setColor(Color.red); g.setStroke(new BasicStroke(2.0f)); int gw = (int)(srcRect.width * scale) -2; int gh = (int)(srcRect.height * scale) -2; if (gw < 5) gw = 5; if (gh < 5) gh = 5; g.drawRect((int)(srcRect.x * scale) +1, (int)(srcRect.y * scale) +1, gw, gh); } while (volatileImage.contentsLost()); }
volatileImage.flush();
if (null == volatileImage || volatileImage.getWidth() != w || volatileImage.getHeight() != h || volatileImage.validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE) { if (null != volatileImage) volatileImage.flush(); volatileImage = gc.createCompatibleVolatileImage(w, h); volatileImage.setAccelerationPriority(1.0f);
private synchronized void paintBuffered(Graphics g) { do { GraphicsConfiguration config = getGraphicsConfiguration(); int width = getWidth(); int height = getHeight(); if (backBuffer == null || width != backBuffer.getWidth() || height != backBuffer.getHeight() || backBuffer.validate(config) == VolatileImage.IMAGE_INCOMPATIBLE) { if (backBuffer != null) { backBufferGraphics.dispose(); backBufferGraphics = null; backBuffer.flush(); backBuffer = null; } backBuffer = config.createCompatibleVolatileImage(width, height); backBufferGraphics = backBuffer.createGraphics(); } backBufferGraphics.setClip(g.getClip()); paintUnbuffered(backBufferGraphics); g.drawImage(backBuffer, 0, 0, this); } while (backBuffer.contentsLost()); }
drawingBufferV.flush(); drawingBufferV = null;
buffer.flush(); buffer = null;