Java Code Examples for java.awt.image.VolatileImage#IMAGE_INCOMPATIBLE

The following examples show how to use java.awt.image.VolatileImage#IMAGE_INCOMPATIBLE . 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: AcceleratedScaleTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 8 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 2
Source File: DisplayChangeVITest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 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 3
Source File: AltTabCrashTest.java    From openjdk-jdk8u 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 4
Source File: AcceleratedScaleTest.java    From openjdk-jdk8u 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 5
Source File: DisplayChangeVITest.java    From hottub with GNU General Public License v2.0 6 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 6
Source File: AcceleratedXORModeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
void test() {
    createVImg();
    BufferedImage bi = null;
    do {
        int valCode = vImg.validate(getDefaultGC());
        if (valCode == VolatileImage.IMAGE_INCOMPATIBLE) {
            createVImg();
        }
        Graphics2D g = vImg.createGraphics();
        draw(g);
        bi = vImg.getSnapshot();
    } while (vImg.contentsLost());
    if (bi != null) {
        test(bi);
        write(bi);
    }
}
 
Example 7
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 8
Source File: VolatileImageConfigurationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void drawBackingStoreImage(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    GraphicsConfiguration gc = g2d.getDeviceConfiguration();
    if (vImg == null ||
        vImg.validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE) {
        /* Create a new volatile image */
        vImg = createVolatileImage(PANEL_WIDTH, PANEL_HEIGHT / 3);
    }

    Graphics vImgGraphics = vImg.createGraphics();
    vImgGraphics.setColor(Color.WHITE);
    vImgGraphics.fillRect(0, 0, PANEL_WIDTH, PANEL_HEIGHT / 3);
    drawInfo(vImgGraphics,
             PANEL_X,
             PANEL_Y,
             "Backbuffer",
             Color.MAGENTA);
    g.drawImage(vImg, 0, PANEL_Y * 2, this);
}
 
Example 9
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 10
Source File: RepaintManager.java    From jdk1.8-source-analysis with Apache License 2.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 11
Source File: AltTabCrashTest.java    From dragonwell8_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 12
Source File: AcceleratedXORModeTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
void test() {
    createVImg();
    do {
        int valCode = vImg.validate(getDefaultGC());
        if (valCode == VolatileImage.IMAGE_INCOMPATIBLE) {
            createVImg();
        }
        Graphics2D g = vImg.createGraphics();
        draw(g);
        BufferedImage bi = vImg.getSnapshot();
        test(bi);
        write(bi);
    } while (vImg.contentsLost());
}
 
Example 13
Source File: AltTabCrashTest.java    From jdk8u-dev-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 14
Source File: AcceleratedXORModeTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
void test() {
    createVImg();
    do {
        int valCode = vImg.validate(getDefaultGC());
        if (valCode == VolatileImage.IMAGE_INCOMPATIBLE) {
            createVImg();
        }
        Graphics2D g = vImg.createGraphics();
        draw(g);
        BufferedImage bi = vImg.getSnapshot();
        test(bi);
        write(bi);
    } while (vImg.contentsLost());
}
 
Example 15
Source File: RepaintManager.java    From openjdk-jdk9 with GNU General Public License v2.0 4 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;
    int sw = w + 1;
    int sh = h + 1;

    if (repaintManager.useVolatileDoubleBuffer() &&
        (offscreen = getValidImage(repaintManager.
        getVolatileOffscreenBuffer(bufferComponent, sw, sh))) != 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, sw, sh);
                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 16
Source File: VolatileSurfaceManager.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the image ready for rendering.  This method is called to make
 * sure that the accelerated SurfaceData exists and is
 * ready to be used.  Users call this method prior to any set of
 * rendering to or from the image, to make sure the image is ready
 * and compatible with the given GraphicsConfiguration.
 *
 * The image may not be "ready" if either we had problems creating
 * it in the first place (e.g., there was no space in vram) or if
 * the surface became lost (e.g., some other app or the OS caused
 * vram surfaces to be removed).
 *
 * Note that we want to return RESTORED in any situation where the
 * SurfaceData is different than it was last time.  So whether it's
 * software or hardware, if we have a different SurfaceData object,
 * then the contents have been altered and we must reflect that
 * change to the user.
 */
public int validate(GraphicsConfiguration gc) {
    int returnCode = VolatileImage.IMAGE_OK;
    boolean lostSurfaceTmp = lostSurface;
    lostSurface = false;

    if (isAccelerationEnabled()) {
        if (!isConfigValid(gc)) {
            // If we're asked to render to a different device than the
            // one we were created under, return INCOMPATIBLE error code.
            // Note that a null gc simply ignores the incompatibility
            // issue
            returnCode = VolatileImage.IMAGE_INCOMPATIBLE;
        } else if (sdAccel == null) {
            // We either had problems creating the surface or the display
            // mode changed and we nullified the old one.  Try it again.
            sdAccel = initAcceleratedSurface();
            if (sdAccel != null) {
                // set the current SurfaceData to accelerated version
                sdCurrent = sdAccel;
                // we don't need the system memory surface anymore, so
                // let's release it now (it can always be restored later)
                sdBackup = null;
                returnCode = VolatileImage.IMAGE_RESTORED;
            } else {
                sdCurrent = getBackupSurface();
            }
        } else if (sdAccel.isSurfaceLost()) {
            try {
                restoreAcceleratedSurface();
                // set the current SurfaceData to accelerated version
                sdCurrent = sdAccel;
                // restoration successful: accel surface no longer lost
                sdAccel.setSurfaceLost(false);
                // we don't need the system memory surface anymore, so
                // let's release it now (it can always be restored later)
                sdBackup = null;
                returnCode = VolatileImage.IMAGE_RESTORED;
            } catch (sun.java2d.InvalidPipeException e) {
                // Set the current SurfaceData to software version so that
                // drawing can continue.  Note that we still have
                // the lostAccelSurface flag set so that we will continue
                // to attempt to restore the accelerated surface.
                sdCurrent = getBackupSurface();
            }
        } else if (lostSurfaceTmp) {
            // Something else triggered this loss/restoration.  Could
            // be a palette change that didn't require a SurfaceData
            // recreation but merely a re-rendering of the pixels.
            returnCode = VolatileImage.IMAGE_RESTORED;
        }
    } else if (sdAccel != null) {
        // if the "acceleration enabled" state changed to disabled,
        // switch to software surface
        sdCurrent = getBackupSurface();
        sdAccel = null;
        returnCode = VolatileImage.IMAGE_RESTORED;
    }

    if ((returnCode != VolatileImage.IMAGE_INCOMPATIBLE) &&
        (sdCurrent != sdPrevious))
    {
        // contents have changed - return RESTORED to user
        sdPrevious = sdCurrent;
        returnCode = VolatileImage.IMAGE_RESTORED;
    }

    if (returnCode == VolatileImage.IMAGE_RESTORED) {
        // clear the current surface with the background color,
        // only if the surface has been restored
        initContents();
    }

    return returnCode;
}
 
Example 17
Source File: DrawImageBgTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    GraphicsConfiguration gc =
        GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration();

    if (gc.getColorModel().getPixelSize() <= 8) {
        System.out.println("8-bit color model, test considered passed");
        return;
    }

    /*
     * Set up images:
     * 1.) VolatileImge for rendering to,
     * 2.) BufferedImage for reading back the contents of the VI
     * 3.) The image triggering the problem
     */
    VolatileImage vImg = null;
    BufferedImage readBackBImg;

    // create a BITMASK ICM such that the transparent color is
    // tr. black (and it's the first in the color map so a buffered image
    // created with this ICM is transparent
    byte r[] = { 0x00, (byte)0xff};
    byte g[] = { 0x00, (byte)0xff};
    byte b[] = { 0x00, (byte)0xff};
    IndexColorModel icm = new IndexColorModel(8, 2, r, g, b, 0);
    WritableRaster wr = icm.createCompatibleWritableRaster(25, 25);
    BufferedImage tImg = new BufferedImage(icm, wr, false, null);

    do {
        if (vImg == null ||
            vImg.validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE)
        {
            vImg = gc.createCompatibleVolatileImage(tImg.getWidth(),
                                                    tImg.getHeight());
        }

        Graphics viG = vImg.getGraphics();
        viG.setColor(Color.red);
        viG.fillRect(0, 0, vImg.getWidth(), vImg.getHeight());

        viG.drawImage(tImg, 0, 0, Color.green, null);
        viG.fillRect(0, 0, vImg.getWidth(), vImg.getHeight());
        viG.drawImage(tImg, 0, 0, Color.white, null);

        readBackBImg = vImg.getSnapshot();
    } while (vImg.contentsLost());

    for (int x = 0; x < readBackBImg.getWidth(); x++) {
        for (int y = 0; y < readBackBImg.getHeight(); y++) {
            int currPixel = readBackBImg.getRGB(x, y);
            if (currPixel != Color.white.getRGB()) {
                String fileName = "DrawImageBgTest.png";
                try {
                    ImageIO.write(readBackBImg, "png", new File(fileName));
                    System.err.println("Dumped image to " + fileName);
                } catch (IOException ex) {}
                throw new
                    RuntimeException("Test Failed: found wrong color: 0x"+
                                     Integer.toHexString(currPixel));
            }
        }
    }
    System.out.println("Test Passed.");
}
 
Example 18
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 19
Source File: VolatileSurfaceManager.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the image ready for rendering.  This method is called to make
 * sure that the accelerated SurfaceData exists and is
 * ready to be used.  Users call this method prior to any set of
 * rendering to or from the image, to make sure the image is ready
 * and compatible with the given GraphicsConfiguration.
 *
 * The image may not be "ready" if either we had problems creating
 * it in the first place (e.g., there was no space in vram) or if
 * the surface became lost (e.g., some other app or the OS caused
 * vram surfaces to be removed).
 *
 * Note that we want to return RESTORED in any situation where the
 * SurfaceData is different than it was last time.  So whether it's
 * software or hardware, if we have a different SurfaceData object,
 * then the contents have been altered and we must reflect that
 * change to the user.
 */
public int validate(GraphicsConfiguration gc) {
    int returnCode = VolatileImage.IMAGE_OK;
    boolean lostSurfaceTmp = lostSurface;
    lostSurface = false;

    if (isAccelerationEnabled()) {
        if (!isConfigValid(gc)) {
            // If we're asked to render to a different device than the
            // one we were created under, return INCOMPATIBLE error code.
            // Note that a null gc simply ignores the incompatibility
            // issue
            returnCode = VolatileImage.IMAGE_INCOMPATIBLE;
        } else if (sdAccel == null) {
            // We either had problems creating the surface or the display
            // mode changed and we nullified the old one.  Try it again.
            sdAccel = initAcceleratedSurface();
            if (sdAccel != null) {
                // set the current SurfaceData to accelerated version
                sdCurrent = sdAccel;
                // we don't need the system memory surface anymore, so
                // let's release it now (it can always be restored later)
                sdBackup = null;
                returnCode = VolatileImage.IMAGE_RESTORED;
            } else {
                sdCurrent = getBackupSurface();
            }
        } else if (sdAccel.isSurfaceLost()) {
            try {
                restoreAcceleratedSurface();
                // set the current SurfaceData to accelerated version
                sdCurrent = sdAccel;
                // restoration successful: accel surface no longer lost
                sdAccel.setSurfaceLost(false);
                // we don't need the system memory surface anymore, so
                // let's release it now (it can always be restored later)
                sdBackup = null;
                returnCode = VolatileImage.IMAGE_RESTORED;
            } catch (sun.java2d.InvalidPipeException e) {
                // Set the current SurfaceData to software version so that
                // drawing can continue.  Note that we still have
                // the lostAccelSurface flag set so that we will continue
                // to attempt to restore the accelerated surface.
                sdCurrent = getBackupSurface();
            }
        } else if (lostSurfaceTmp) {
            // Something else triggered this loss/restoration.  Could
            // be a palette change that didn't require a SurfaceData
            // recreation but merely a re-rendering of the pixels.
            returnCode = VolatileImage.IMAGE_RESTORED;
        }
    } else if (sdAccel != null) {
        // if the "acceleration enabled" state changed to disabled,
        // switch to software surface
        sdCurrent = getBackupSurface();
        sdAccel = null;
        returnCode = VolatileImage.IMAGE_RESTORED;
    }

    if ((returnCode != VolatileImage.IMAGE_INCOMPATIBLE) &&
        (sdCurrent != sdPrevious))
    {
        // contents have changed - return RESTORED to user
        sdPrevious = sdCurrent;
        returnCode = VolatileImage.IMAGE_RESTORED;
    }

    if (returnCode == VolatileImage.IMAGE_RESTORED) {
        // clear the current surface with the background color,
        // only if the surface has been restored
        initContents();
    }

    return returnCode;
}
 
Example 20
Source File: VolatileSurfaceManager.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the image ready for rendering.  This method is called to make
 * sure that the accelerated SurfaceData exists and is
 * ready to be used.  Users call this method prior to any set of
 * rendering to or from the image, to make sure the image is ready
 * and compatible with the given GraphicsConfiguration.
 *
 * The image may not be "ready" if either we had problems creating
 * it in the first place (e.g., there was no space in vram) or if
 * the surface became lost (e.g., some other app or the OS caused
 * vram surfaces to be removed).
 *
 * Note that we want to return RESTORED in any situation where the
 * SurfaceData is different than it was last time.  So whether it's
 * software or hardware, if we have a different SurfaceData object,
 * then the contents have been altered and we must reflect that
 * change to the user.
 */
public int validate(GraphicsConfiguration gc) {
    int returnCode = VolatileImage.IMAGE_OK;
    boolean lostSurfaceTmp = lostSurface;
    lostSurface = false;

    if (isAccelerationEnabled()) {
        if (!isConfigValid(gc)) {
            // If we're asked to render to a different device than the
            // one we were created under, return INCOMPATIBLE error code.
            // Note that a null gc simply ignores the incompatibility
            // issue
            returnCode = VolatileImage.IMAGE_INCOMPATIBLE;
        } else if (sdAccel == null) {
            // We either had problems creating the surface or the display
            // mode changed and we nullified the old one.  Try it again.
            sdAccel = initAcceleratedSurface();
            if (sdAccel != null) {
                // set the current SurfaceData to accelerated version
                sdCurrent = sdAccel;
                // we don't need the system memory surface anymore, so
                // let's release it now (it can always be restored later)
                sdBackup = null;
                returnCode = VolatileImage.IMAGE_RESTORED;
            } else {
                sdCurrent = getBackupSurface();
            }
        } else if (sdAccel.isSurfaceLost()) {
            try {
                restoreAcceleratedSurface();
                // set the current SurfaceData to accelerated version
                sdCurrent = sdAccel;
                // restoration successful: accel surface no longer lost
                sdAccel.setSurfaceLost(false);
                // we don't need the system memory surface anymore, so
                // let's release it now (it can always be restored later)
                sdBackup = null;
                returnCode = VolatileImage.IMAGE_RESTORED;
            } catch (sun.java2d.InvalidPipeException e) {
                // Set the current SurfaceData to software version so that
                // drawing can continue.  Note that we still have
                // the lostAccelSurface flag set so that we will continue
                // to attempt to restore the accelerated surface.
                sdCurrent = getBackupSurface();
            }
        } else if (lostSurfaceTmp) {
            // Something else triggered this loss/restoration.  Could
            // be a palette change that didn't require a SurfaceData
            // recreation but merely a re-rendering of the pixels.
            returnCode = VolatileImage.IMAGE_RESTORED;
        }
    } else if (sdAccel != null) {
        // if the "acceleration enabled" state changed to disabled,
        // switch to software surface
        sdCurrent = getBackupSurface();
        sdAccel = null;
        returnCode = VolatileImage.IMAGE_RESTORED;
    }

    if ((returnCode != VolatileImage.IMAGE_INCOMPATIBLE) &&
        (sdCurrent != sdPrevious))
    {
        // contents have changed - return RESTORED to user
        sdPrevious = sdCurrent;
        returnCode = VolatileImage.IMAGE_RESTORED;
    }

    if (returnCode == VolatileImage.IMAGE_RESTORED) {
        // clear the current surface with the background color,
        // only if the surface has been restored
        initContents();
    }

    return returnCode;
}