/** * 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()); } }
tracker.removeImage(bgImage, 0); } while (bgImage.contentsLost());
/** * 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()); }
private void render(final Graphics g) { final Graphics2D g2d = (Graphics2D) g.create(); g2d.setRenderingHints(DisplayCanvas.rhints); final GraphicsConfiguration gc = getGraphicsConfiguration(); // outside synch, avoid deadlocks do { final BufferedImage image; synchronized (offscreen_lock) { image = this.image; } // Protect volatileImage while generating it synchronized (volatile_lock) { if (invalid_volatile || null == volatileImage || volatileImage.validate(gc) != VolatileImage.IMAGE_OK) { renderVolatileImage(gc, image); } g2d.drawImage(volatileImage, 0, 0, null); } } while (volatileImage.contentsLost()); g2d.dispose(); // Flush all old offscreen images synchronized (offscreen_lock) { for (final BufferedImage bi : to_flush) { bi.flush(); } to_flush.clear(); } }
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(); }
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()); }
/** * 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()); } }
/** * 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. */ 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()); } }
/** * 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. */ 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()); } }
} while (volatileImage.contentsLost()); } finally { lock.unlock();
painted = !volatileImage.contentsLost(); } else { volatileImage.flush();
g2d.drawImage(volatileImage, 0, 0, null); } while (volatileImage.contentsLost());
painted = !volatileImage.contentsLost(); } else { volatileImage.flush();
tracker.removeImage(bgImage, 0); } while (bgImage.contentsLost());
tracker.removeImage(bgImage, 0); } while (bgImage.contentsLost());
tracker.removeImage(bgImage, 0); } while (bgImage.contentsLost());
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()); }
} while (_backimg.contentsLost());
} while (((VolatileImage) offscreen).contentsLost());