@Override protected Graphics2D createGraphics () { return _backimg.createGraphics(); }
/** * Paints the image at the specified location. This method assumes * scaling has already been done, and simply paints the background * image "as-is." * * @param g The graphics context. * @param x The x-coordinate at which to paint. * @param y The y-coordinate at which to paint. */ @Override protected void paintImage(Graphics g, int x, int y) { if (bgImage != null) { do { int rc = bgImage.validate(null);//getGraphicsConfiguration()); if (rc==VolatileImage.IMAGE_RESTORED) { // FIXME: If the image needs to be restored are its width // and height still valid?? If not, we'll need to cache // these values... renderImage(bgImage.getWidth(), bgImage.getHeight(), getScalingHint()); } g.drawImage(bgImage, x,y, null); } while (bgImage.contentsLost()); } }
/** * Clears a volatile image */ public static void clearVolatileImage(@Nonnull VolatileImage volatileImage) { Graphics2D graphics = (Graphics2D) volatileImage.getGraphics(); try { graphics.setComposite(AlphaComposite.DstOut); graphics.fillRect(0, 0, volatileImage.getWidth(), volatileImage.getHeight()); } finally { graphics.dispose(); } }
|| (stretchedImage != null && stretchedImage.validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE)) stretchedGraphics = (Graphics2D) stretchedImage.getGraphics();
tracker.removeImage(i, 1); bgImage.getGraphics().drawImage(i, 0,0, null); tracker.addImage(bgImage, 0); try { tracker.removeImage(bgImage, 0); } while (bgImage.contentsLost());
if (volatileImage == null || volatileImageGC != gc) { if (volatileImage != null) { volatileImage.flush(); int valid = volatileImage.validate(gc); Graphics2D volatileImageGraphics = volatileImage.createGraphics(); volatileImageGraphics.setClip(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height); painted = !volatileImage.contentsLost(); } else { volatileImage.flush(); volatileImage = null;
private VolatileImage vImg; @Override public void paint(Graphics g) { if (gc==null) gc = this.getGraphicsConfiguration(); do { boolean sizeChanged = false; sizeChanged = (vImg!=null&&(vImg.getWidth()!=getWidth()|| vImg.getHeight()!=getHeight())); if (vImg == null || vImg.validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE || sizeChanged) { vImg = gc.createCompatibleVolatileImage(getWidth(), getHeight()); vImg.setAccelerationPriority(1); } final Graphics gimg = vImg.getGraphics(); if (gimg instanceof Graphics2D) { renderContents((Graphics2D) gimg); gimg.dispose(); g.drawImage(vImg, 0, 0, null); } else { throw new UnsupportedOperationException("Rendering impossible, graphics are not of Graphics2D class"); } } while (vImg.contentsLost()); updateAnimationNo(); }
if (img == null) img = gc.createCompatibleVolatileImage(PIC_WIDTH, PIC_HEIGHT); Graphics2D g2 = img.createGraphics(); int valStatus = img.validate(gc); if (valStatus == VolatileImage.IMAGE_OK) g2.drawImage(backImg,0,0,null); } while (img.contentsLost()); time = NANO*(System.nanoTime()-begin); count++;
int quadrantClockwise) { quadrantClockwise = quadrantClockwise % 4; int width = bi.getWidth(); int height = bi.getHeight(); if ((quadrantClockwise == 1) || (quadrantClockwise == 3)) { width = bi.getHeight(); height = bi.getWidth(); at.rotate(-Math.PI / 2); Graphics2D rotg = biRot.createGraphics(); if (at != null) rotg.setTransform(at);
/** * Renders to a volatile image, and then paints that to the screen. * This helps with scaling performance on accelerated surfaces (e.g. OpenGL) * * @param g the graphics to paint the image to * @param x the left coordinate to start painting at. * @param y the top coordinate to start painting at. * @param w the width of the paint area * @param h the height of the paint area */ private void volatileRender(Graphics g, int x, int y, int w, int h) { do { if (updatePending || volatileImage == null || volatileImage.validate(getGraphicsConfiguration()) != VolatileImage.IMAGE_OK) { bufferLock.lock(); try { updatePending = false; renderVolatileImage(currentImage); } finally { bufferLock.unlock(); } } g.drawImage(volatileImage, x, y, w, h, null); } while (volatileImage.contentsLost()); }
public void validateVolatileImage() { int valCode = volatileImage.validate(configuration); // This means the device doesn't match up to this hardware accelerated image. if (valCode == VolatileImage.IMAGE_INCOMPATIBLE) { volatileImage = createBackBuffer(width, height); // recreate the hardware accelerated image. graphic.setScreen(volatileImage.createGraphics()); } }
GraphicsConfiguration deviceConfiguration = g2d.getDeviceConfiguration(); int validationResult = volatileImage.validate(deviceConfiguration); if (validationResult == VolatileImage.IMAGE_INCOMPATIBLE) { volatileImage.flush(); } while (volatileImage.contentsLost()); } finally { lock.unlock();
/** * Returns a new volatile image. * * @param width the image width * @param height the image height * @return the volatile image */ public static VolatileImage createVolatileImage( int width, int height) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration(); VolatileImage image = null; image = gc.createCompatibleVolatileImage(width, height, Transparency.TRANSLUCENT); int valid = image.validate(gc); // if (valid == VolatileImage.IMAGE_INCOMPATIBLE) { // image = createVolatileImage(width, height, Transparency.TRANSLUCENT); // return image; // } return image; }
/** * 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 + "]."); }
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; } };
} while (((VolatileImage) offscreen).contentsLost());
void mergeBuffers() { VolatileImage vi = createBackBuffer(); Graphics2D g2d = (Graphics2D) vi.getGraphics(); MapLayer[] layers = getContext().getLayers(); for (int i = 0, max = layers.length; i < max; i++) { // for (int i= layers.length-1; i>=0; i--){ MapLayer layer = layers[i]; BufferedImage img = stock.get(layer); if (img != null) { g2d.drawImage(img, null, 0, 0); } } comp.setBuffer(vi); }
public BufferedImage getBuffer() { if (img != null) { return img.getSnapshot(); } else { return null; } }
if (volatileImage == null || volatileImageGC != gc) { if (volatileImage != null) { volatileImage.flush(); int valid = volatileImage.validate(gc); Graphics2D volatileImageGraphics = volatileImage.createGraphics(); volatileImageGraphics.setClip(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height); painted = !volatileImage.contentsLost(); } else { volatileImage.flush(); volatileImage = null;