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

The following examples show how to use java.awt.image.VolatileImage#IMAGE_RESTORED . 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 jdk8u-dev-jdk with GNU General Public License v2.0 7 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: DisplayChangeVITest.java    From dragonwell8_jdk 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 4
Source File: SharedMemoryPixmapsTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
void initVI() {
    int res;
    if (vi == null) {
        res = VolatileImage.IMAGE_INCOMPATIBLE;
    } else {
        res = vi.validate(getGraphicsConfiguration());
    }
    if (res == VolatileImage.IMAGE_INCOMPATIBLE) {
        if (vi != null) vi.flush();
        vi = createVolatileImage(IMAGE_SIZE, IMAGE_SIZE);
        vi.validate(getGraphicsConfiguration());
        res = VolatileImage.IMAGE_RESTORED;
    }
    if (res == VolatileImage.IMAGE_RESTORED) {
        Graphics vig = vi.getGraphics();
        vig.setColor(Color.red);
        vig.fillRect(0, 0, vi.getWidth(), vi.getHeight());
        vig.dispose();
    }
}
 
Example 5
Source File: AcceleratedScaleTest.java    From openjdk-8-source 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 6
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 7
Source File: AltTabCrashTest.java    From jdk8u-jdk 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 8
Source File: AltTabCrashTest.java    From TencentKona-8 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 9
Source File: AcceleratedScaleTest.java    From jdk8u-jdk 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 10
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 11
Source File: SharedMemoryPixmapsTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
void initVI() {
    int res;
    if (vi == null) {
        res = VolatileImage.IMAGE_INCOMPATIBLE;
    } else {
        res = vi.validate(getGraphicsConfiguration());
    }
    if (res == VolatileImage.IMAGE_INCOMPATIBLE) {
        if (vi != null) vi.flush();
        vi = createVolatileImage(IMAGE_SIZE, IMAGE_SIZE);
        vi.validate(getGraphicsConfiguration());
        res = VolatileImage.IMAGE_RESTORED;
    }
    if (res == VolatileImage.IMAGE_RESTORED) {
        Graphics vig = vi.getGraphics();
        vig.setColor(Color.red);
        vig.fillRect(0, 0, vi.getWidth(), vi.getHeight());
        vig.dispose();
    }
}
 
Example 12
Source File: AltTabCrashTest.java    From hottub 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 13
Source File: AltTabCrashTest.java    From jdk8u60 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: AltTabCrashTest.java    From openjdk-jdk9 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 15
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 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: VolatileSurfaceManager.java    From jdk8u60 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 18
Source File: VolatileSurfaceManager.java    From openjdk-jdk8u-backup 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 19
Source File: CopyScaledAreaTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void testScale(double scaleX, double scaleY,
                              GraphicsConfiguration gc) throws Exception
{

    BufferedImage buffImage = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT,
                                                BufferedImage.TYPE_INT_RGB);
    Graphics g = buffImage.createGraphics();

    VolatileImage vImg = createVolatileImage(gc);

    int attempts = 0;
    do {

        if (attempts > 10) {
            throw new RuntimeException("Too many attempts!");
        }

        int returnCode = vImg.validate(gc);
        if (returnCode == VolatileImage.IMAGE_RESTORED) {
            // Contents need to be restored
            renderOffscreen(vImg, gc, scaleX, scaleY); // restore contents
        } else if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) {
            // old vImg doesn't work with new GraphicsConfig; re-create it
            vImg = createVolatileImage(gc);
            renderOffscreen(vImg, gc, scaleX, scaleY);
        }
        g.drawImage(vImg, 0, 0, null);
        attempts++;
    } while (vImg.contentsLost());

    g.dispose();

    int x = scale(X + N * DX, scaleX) + 1;
    int y = scale(Y + N * DY, scaleY) + 1;
    int w = scale(W, scaleX) - 2;
    int h = scale(H, scaleY) - 2;

    for (int i = x; i < x + w; i++) {
        for (int j = y; j < y + h; j++) {
            if (buffImage.getRGB(i, j) != FILL_COLOR.getRGB()) {
                throw new RuntimeException("Wrong rectangle color!");
            }
        }
    }
}
 
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;
}