java.awt.image.VolatileImage#IMAGE_RESTORED源码实例Demo

下面列出了java.awt.image.VolatileImage#IMAGE_RESTORED 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: DisplayChangeVITest.java
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());
}
 
源代码2 项目: openjdk-jdk9   文件: SharedMemoryPixmapsTest.java
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();
    }
}
 
源代码3 项目: jdk8u-dev-jdk   文件: AcceleratedScaleTest.java
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();
    }
}
 
源代码4 项目: openjdk-jdk8u   文件: AcceleratedScaleTest.java
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();
    }
}
 
源代码5 项目: jdk8u-jdk   文件: AcceleratedScaleTest.java
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();
    }
}
 
源代码6 项目: TencentKona-8   文件: AltTabCrashTest.java
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());
}
 
源代码7 项目: jdk8u-jdk   文件: AltTabCrashTest.java
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());
}
 
源代码8 项目: jdk8u-dev-jdk   文件: DisplayChangeVITest.java
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());
}
 
源代码9 项目: openjdk-jdk8u   文件: AltTabCrashTest.java
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());
}
 
源代码10 项目: openjdk-8-source   文件: AcceleratedScaleTest.java
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();
    }
}
 
源代码11 项目: openjdk-8-source   文件: SharedMemoryPixmapsTest.java
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();
    }
}
 
源代码12 项目: openjdk-jdk9   文件: AltTabCrashTest.java
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));
    }
}
 
源代码13 项目: hottub   文件: AltTabCrashTest.java
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));
    }
}
 
源代码14 项目: jdk8u60   文件: AltTabCrashTest.java
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));
    }
}
 
源代码15 项目: jdk8u_jdk   文件: CopyScaledAreaTest.java
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!");
            }
        }
    }
}
 
源代码16 项目: jdk8u-jdk   文件: VolatileSurfaceManager.java
/**
 * 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;
}
 
源代码17 项目: TencentKona-8   文件: VolatileSurfaceManager.java
/**
 * 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;
}
 
源代码18 项目: jdk8u60   文件: VolatileSurfaceManager.java
/**
 * 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;
}
 
/**
 * 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;
}
 
源代码20 项目: jdk8u-jdk   文件: VolatileSurfaceManager.java
/**
 * 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;
}