当前位置: 首页>>代码示例>>Java>>正文


Java VolatileImage.contentsLost方法代码示例

本文整理汇总了Java中java.awt.image.VolatileImage.contentsLost方法的典型用法代码示例。如果您正苦于以下问题:Java VolatileImage.contentsLost方法的具体用法?Java VolatileImage.contentsLost怎么用?Java VolatileImage.contentsLost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.image.VolatileImage的用法示例。


在下文中一共展示了VolatileImage.contentsLost方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: accelerateImage

import java.awt.image.VolatileImage; //导入方法依赖的package包/类
public VolatileImage accelerateImage(BufferedImage bi) {
    VolatileImage testVI = f.createVolatileImage(TEST_W, TEST_H);
    do {
        if (testVI.validate(f.getGraphicsConfiguration()) ==
            VolatileImage.IMAGE_INCOMPATIBLE)
        {
            testVI = f.createVolatileImage(TEST_W, TEST_H);
        }
        Graphics2D g = testVI.createGraphics();
        g.setComposite(AlphaComposite.Src);
        g.setColor(Color.green);
        g.fillRect(0, 0, TEST_W, TEST_H);

        g.drawImage(bi, 0, 0, null);
        g.drawImage(bi, 0, 0, null);
        g.drawImage(bi, 0, 0, null);
        g.dispose();
    } while (testVI.contentsLost());

    return testVI;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:JPEGsNotAcceleratedTest.java

示例2: runTest

import java.awt.image.VolatileImage; //导入方法依赖的package包/类
private void runTest() {
    GraphicsConfiguration gc = GraphicsEnvironment.
        getLocalGraphicsEnvironment().getDefaultScreenDevice().
            getDefaultConfiguration();

    if (gc.getColorModel().getPixelSize() < 16) {
        System.out.println("8-bit desktop depth found, test passed");
        return;
    }

    VolatileImage vi = gc.createCompatibleVolatileImage(R_WIDTH, R_HEIGHT);
    BufferedImage bi = null;
    do {
        vi.validate(gc);
        Graphics2D g = vi.createGraphics();
        render(g, vi.getWidth(), vi.getHeight());
        bi = vi.getSnapshot();
    } while (vi.contentsLost());

    checkBI(bi);
    System.out.println("Test PASSED.");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:TransformedPaintTest.java

示例3: render

import java.awt.image.VolatileImage; //导入方法依赖的package包/类
private static boolean render(BufferedImage src, VolatileImage dst) {
    int cnt = 5;
    do {
        Graphics2D g = dst.createGraphics();
        g.setColor(dstColor);
        g.fillRect(0, 0, dst.getWidth(), dst.getHeight());
        g.drawImage(src, 0, 0, null);
        g.dispose();
    } while (dst.contentsLost() && (--cnt > 0));

    if (cnt == 0) {
        System.err.println("Test failed: unable to render to volatile destination");
        return false;
    }

    BufferedImage s = dst.getSnapshot();

    return s.getRGB(1,1) == srcColor.getRGB();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:DrawHugeImageTest.java

示例4: main

import java.awt.image.VolatileImage; //导入方法依赖的package包/类
public static void main(final String[] args) {
    GraphicsConfiguration gc =
            GraphicsEnvironment.getLocalGraphicsEnvironment()
                    .getDefaultScreenDevice().getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(S, S, BITMASK);
    BufferedImage ci = gc.createCompatibleImage(S, S, BITMASK);

    int attempt = 0;
    do {
        if (++attempt > 10) {
            throw new RuntimeException("Too many attempts: " + attempt);
        }
        vi.validate(gc);
        test(vi, ci, gc);
    } while (vi.contentsLost());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:BitmaskVolatileImage.java

示例5: paint

import java.awt.image.VolatileImage; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:52,代码来源:RepaintManager.java

示例6: main

import java.awt.image.VolatileImage; //导入方法依赖的package包/类
public static void main(final String[] args) {
    final GraphicsEnvironment ge =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsDevice gd = ge.getDefaultScreenDevice();
    final GraphicsConfiguration gc = gd.getDefaultConfiguration();
    final VolatileImage vi =
            gc.createCompatibleVolatileImage(SIZE, SIZE, TRANSLUCENT);
    final BufferedImage bi = makeUnmanagedBI(gc, TRANSLUCENT);
    final int expected = bi.getRGB(2, 2);

    int attempt = 0;
    BufferedImage snapshot;
    while (true) {
        if (++attempt > 10) {
            throw new RuntimeException("Too many attempts: " + attempt);
        }
        vi.validate(gc);
        final Graphics2D g2d = vi.createGraphics();
        g2d.setComposite(AlphaComposite.Src);
        g2d.scale(2, 2);
        g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                             RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g2d.drawImage(bi, 0, 0, null);
        g2d.dispose();

        snapshot = vi.getSnapshot();
        if (vi.contentsLost()) {
            continue;
        }
        break;
    }
    final int actual = snapshot.getRGB(2, 2);
    if (actual != expected) {
        System.err.println("Actual: " + Integer.toHexString(actual));
        System.err.println("Expected: " + Integer.toHexString(expected));
        throw new RuntimeException("Test failed");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:39,代码来源:IncorrectAlphaConversionBicubic.java

示例7: test

import java.awt.image.VolatileImage; //导入方法依赖的package包/类
private static void test(final BufferedImage bi) throws IOException {
    GraphicsEnvironment ge = GraphicsEnvironment
            .getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice()
                                 .getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(500, 200,
                                                        TRANSLUCENT);
    BufferedImage gold = gc.createCompatibleImage(500, 200, TRANSLUCENT);
    // draw to compatible Image
    draw(bi, gold);
    // draw to volatile image
    int attempt = 0;
    BufferedImage snapshot;
    while (true) {
        if (++attempt > 10) {
            throw new RuntimeException("Too many attempts: " + attempt);
        }
        vi.validate(gc);
        if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
            continue;
        }
        draw(bi, vi);
        snapshot = vi.getSnapshot();
        if (vi.contentsLost()) {
            continue;
        }
        break;
    }
    // validate images
    for (int x = 0; x < gold.getWidth(); ++x) {
        for (int y = 0; y < gold.getHeight(); ++y) {
            if (gold.getRGB(x, y) != snapshot.getRGB(x, y)) {
                ImageIO.write(gold, "png", new File("gold.png"));
                ImageIO.write(snapshot, "png", new File("bi.png"));
                throw new RuntimeException("Test failed.");
            }
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:40,代码来源:IncorrectUnmanagedImageRotatedClip.java

示例8: test

import java.awt.image.VolatileImage; //导入方法依赖的package包/类
private void test() {
    GraphicsConfiguration gc =
        GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration();
    if (gc.getColorModel().getPixelSize() < 16) {
        System.out.println("<16 bit depth detected, test passed");
        return;
    }

    VolatileImage vi =
        gc.createCompatibleVolatileImage(250, 4*120, Transparency.OPAQUE);
    BufferedImage res;
    do {
        vi.validate(gc);
        Graphics2D g2d = vi.createGraphics();
        g2d.setColor(Color.white);
        g2d.fillRect(0, 0, vi.getWidth(), vi.getHeight());

        render(g2d);

        res = vi.getSnapshot();
    } while (vi.contentsLost());

    for (int y = 0; y < bi.getHeight(); y++) {
        for (int x = 0; x < bi.getWidth(); x++) {
            if (res.getRGB(x, y) == Color.black.getRGB()) {
                System.err.printf("Test FAILED: found black at %d,%d\n",
                                  x, y);
                try {
                    String fileName = "AccelPaintsTest.png";
                    ImageIO.write(res, "png", new File(fileName));
                    System.err.println("Dumped rendering to " + fileName);
                } catch (IOException e) {}
                throw new RuntimeException("Test FAILED: found black");
            }
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:39,代码来源:AccelPaintsTest.java

示例9: renderOffscreen

import java.awt.image.VolatileImage; //导入方法依赖的package包/类
private static void renderOffscreen(VolatileImage vImg,
                                    GraphicsConfiguration conf,
                                    double scaleX,
                                    double scaleY)
{
    int attempts = 0;
    do {

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

        if (vImg.validate(conf) == VolatileImage.IMAGE_INCOMPATIBLE) {
            // old vImg doesn't work with new GraphicsConfig; re-create it
            vImg = createVolatileImage(conf);
        }
        Graphics2D g = vImg.createGraphics();
        //
        // miscellaneous rendering commands...
        //
        g.setColor(BACKGROUND_COLOR);
        g.fillRect(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT);
        g.scale(scaleX, scaleY);

        g.setColor(FILL_COLOR);
        g.fillRect(X, Y, W, H);

        for (int i = 0; i < N; i++) {
            g.copyArea(X + i * DX, Y + i * DY, W, H, DX, DY);
        }
        g.dispose();
        attempts++;
    } while (vImg.contentsLost());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:CopyScaledAreaTest.java

示例10: renderToVolatileImage

import java.awt.image.VolatileImage; //导入方法依赖的package包/类
private static void renderToVolatileImage(VolatileImage dst) {
    Graphics2D g = dst.createGraphics();
    do {
        System.out.println("Render to volatile image..");
        try {
            MyComp.renderTest(g, dst.getHeight(), dst.getHeight());
        } catch (Throwable e) {
            throw new RuntimeException("Test FAILED.", e);
        }
    } while (dst.contentsLost());
    System.out.println("Done.");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:CustomCompositeTest.java

示例11: main

import java.awt.image.VolatileImage; //导入方法依赖的package包/类
public static void main(final String[] args) throws IOException {
    GraphicsEnvironment ge = GraphicsEnvironment
            .getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice()
                                 .getDefaultConfiguration();
    AffineTransform at;
    for (int size : SIZES) {
        at = AffineTransform.getScaleInstance(size, size);
        for (Shape clip : SHAPES) {
            clip = at.createTransformedShape(clip);
            for (Shape to : SHAPES) {
                to = at.createTransformedShape(to);
                // Prepare test images
                BufferedImage snapshot;
                BufferedImage bi = getBufferedImage(size);
                VolatileImage vi = getVolatileImage(gc, size);
                while (true) {
                    vi.validate(gc);
                    Graphics2D g2d = vi.createGraphics();
                    g2d.setColor(Color.GREEN);
                    g2d.fillRect(0, 0, size, size);
                    g2d.dispose();
                    if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
                        continue;
                    }
                    draw(clip, to, bi, vi);
                    snapshot = vi.getSnapshot();
                    if (vi.contentsLost()) {
                        continue;
                    }
                    break;
                }
                // Prepare gold images
                BufferedImage goldvi = getCompatibleImage(gc, size);
                BufferedImage goldbi = getBufferedImage(size);
                draw(clip, to, goldbi, goldvi);
                validate(snapshot, goldvi);
                vi.flush();
            }
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:43,代码来源:IncorrectClipXorModeSW2Surface.java

示例12: main

import java.awt.image.VolatileImage; //导入方法依赖的package包/类
public static void main(final String[] args) throws IOException {
    GraphicsEnvironment ge = GraphicsEnvironment
            .getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice()
            .getDefaultConfiguration();
    AffineTransform at;
    for (int size : SIZES) {
        at = AffineTransform.getScaleInstance(size, size);
        for (Shape clip : SHAPES) {
            clip = at.createTransformedShape(clip);
            for (Shape to : SHAPES) {
                to = at.createTransformedShape(to);
                // Prepare test images
                BufferedImage snapshot;
                VolatileImage source = getVolatileImage(gc, size);
                VolatileImage target = getVolatileImage(gc, size);
                int attempt = 0;
                while (true) {
                    if (++attempt > 10) {
                        throw new RuntimeException("Too many attempts: " + attempt);
                    }
                    // Prepare source images
                    source.validate(gc);
                    Graphics2D g2d = source.createGraphics();
                    g2d.setColor(Color.RED);
                    g2d.fillRect(0, 0, size, size);
                    g2d.dispose();
                    if (source.validate(gc) != VolatileImage.IMAGE_OK) {
                        continue;
                    }
                    // Prepare target images
                    target.validate(gc);
                    g2d = target.createGraphics();
                    g2d.setColor(Color.GREEN);
                    g2d.fillRect(0, 0, size, size);
                    g2d.dispose();
                    if (target.validate(gc) != VolatileImage.IMAGE_OK) {
                        continue;
                    }

                    draw(clip, to, source, target);
                    snapshot = target.getSnapshot();
                    if (source.contentsLost() || target.contentsLost()) {
                        continue;
                    }
                    break;
                }
                // Prepare gold images
                BufferedImage goldS = getSourceGold(gc, size);
                BufferedImage goldT = getTargetGold(gc, size);
                draw(clip, to, goldS, goldT);
                validate(snapshot, goldT);
                source.flush();
                target.flush();
            }
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:59,代码来源:IncorrectClipXorModeSurface2Surface.java

示例13: main

import java.awt.image.VolatileImage; //导入方法依赖的package包/类
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.");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:66,代码来源:DrawImageBgTest.java

示例14: paint

import java.awt.image.VolatileImage; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:55,代码来源:RepaintManager.java

示例15: retrieveFromCache

import java.awt.image.VolatileImage; //导入方法依赖的package包/类
/**
 * Retrieves a character image from the cache.
 *
 * If no image could be found, then one is created, inserted into the cache,
 * and then returned.
 *
 * @param character
 *        The character.
 *
 * @return
 *        The character image.
 *
 * @throws NullPointerException
 *         If the character is null.
 */
public VolatileImage retrieveFromCache(final @NonNull AsciiCharacter character) {
    final int hash = character.getCacheHash();

    VolatileImage image = cachedImages.getIfPresent(hash);

    if (image == null || image.contentsLost()) {
        image = loadIntoCache(character);
    }

    return image;
}
 
开发者ID:Valkryst,项目名称:VTerminal,代码行数:27,代码来源:ImageCache.java


注:本文中的java.awt.image.VolatileImage.contentsLost方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。