Package java.awt.image

Examples of java.awt.image.VolatileImage


    }

    private static final String text =
        "The quick brown fox jumps over the lazy dog 1234567890";
    private static void renderText(Frame frame, Font f1) {
        VolatileImage vi = frame.createVolatileImage(256, 32);
        vi.validate(frame.getGraphicsConfiguration());

        Graphics2D g = vi.createGraphics();
        g.setFont(f1);
        g.drawString(text, 0, vi.getHeight()/2);
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                           RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        g.drawString(text, 0, vi.getHeight()/2);
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                           RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
        g.drawString(text, 0, vi.getHeight()/2);
        Toolkit.getDefaultToolkit().sync();
    }
View Full Code Here


        bmImage = gc.createCompatibleImage(64, 64, Transparency.BITMASK);
        argbImage = gc.createCompatibleImage(64, 64, Transparency.TRANSLUCENT);

        if (gc.getColorModel().getPixelSize() > 8) {
            VolatileImage vi =
                gc.createCompatibleVolatileImage(64, 64, Transparency.OPAQUE);
            do {
                if (vi.validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE) {
                    vi = gc.createCompatibleVolatileImage(64, 64,
                                                          Transparency.OPAQUE);
                    vi.validate(gc);
                }

                int color = testImage(vi, false, false);
                testResult("vi_noclip_notx", vi.getSnapshot(), color);

                color = testImage(vi, true, true);
                testResult("vi_clip_tx", vi.getSnapshot(), color);

                color = testImage(vi, true, false);
                testResult("vi_clip_notx", vi.getSnapshot(), color);

                color = testImage(vi, false, true);
                testResult("vi_noclip_tx", vi.getSnapshot(), color);
            } while (vi.contentsLost());
        }

        BufferedImage bi = new BufferedImage(64, 64, BufferedImage.TYPE_INT_RGB);
        int color = testImage(bi, false, false);
        testResult("bi_noclip_notx", bi, color);
View Full Code Here

        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",
View Full Code Here

        AccelGraphicsConfig agc = (AccelGraphicsConfig) gc;
        printAGC(agc);

        testContext(agc);

        VolatileImage vi = gc.createCompatibleVolatileImage(10, 10);
        vi.validate(gc);
        if (vi instanceof DestSurfaceProvider) {
            System.out.println("Passed: VI is DestSurfaceProvider");
            Surface s = ((DestSurfaceProvider) vi).getDestSurface();
            if (s instanceof AccelSurface) {
                System.out.println("Passed: Obtained Accel Surface");
                printSurface((AccelSurface) s);
            }
            Graphics g = vi.getGraphics();
            if (g instanceof DestSurfaceProvider) {
                System.out.println("Passed: VI graphics is " +
                                   "DestSurfaceProvider");
                printSurface(((DestSurfaceProvider) g).getDestSurface());
            }
View Full Code Here

                                       int transparency, int type)
    {
        int caps = agc.getContextCapabilities().getCaps();
        int w = 11, h = 17;

        VolatileImage vi =
            agc.createCompatibleVolatileImage(w, h, transparency, type);
        if ((cap & caps) != 0) {
            if (vi == null) {
                System.out.printf("Failed: cap=%d is supported but " +
                                  "image wasn't created\n", cap);
                throw new RuntimeException("Failed: image wasn't created " +
                                           "for supported cap");
            } else {
                if (!(vi instanceof DestSurfaceProvider)) {
                    throw new RuntimeException("Failed: created VI is not " +
                                               "DestSurfaceProvider");
                }
                Surface s = ((DestSurfaceProvider) vi).getDestSurface();
                if (s instanceof AccelSurface) {
                    AccelSurface as = (AccelSurface) s;
                    printSurface(as);
                    if (as.getType() != type) {
                        throw new RuntimeException("Failed: returned VI is" +
                                " of incorrect type: " + as.getType() +
                                " requested type=" + type);
                    } else {
                        System.out.printf("Passed: VI of type %d was " +
                                "created for cap=%d\n", type, cap);
                    }
                    if (as.getType() == TEXTURE) {
                        boolean ex = false;
                        try {
                            Graphics g = vi.getGraphics();
                            g.dispose();
                        } catch (UnsupportedOperationException e) {
                            ex = true;
                        }
                        if (!ex) {
View Full Code Here

                (int)(ram / (r.width * r.height * gc.getColorModel().getPixelSize()/8));
            iterations = Math.max(iterations, i);
            System.err.println("iterations="+iterations);
        }
        for (int i = 0; i < iterations; i++) {
            VolatileImage vi =
                agc.createCompatibleVolatileImage(r.width, r.height,
                                                  Transparency.OPAQUE,
                                                  AccelSurface.RT_PLAIN);
            if (vi == null) {
                break;
            }
            vis.add(vi);
        }
        for (VolatileImage vi : vis) {
            vi.flush();
        }
        vis = null;

        System.out.println("Passed: testing for possible NPEs " +
                           "during VI creation");
View Full Code Here

     */
    public void replaceSurfaceData(int newNumBackBuffers,
                                   BufferCapabilities caps)
    {
        SurfaceData oldData = null;
        VolatileImage oldBB = null;
        synchronized(((Component)target).getTreeLock()) {
            synchronized(this) {
                if (pData == 0) {
                    return;
                }
                numBackBuffers = newNumBackBuffers;
                Win32GraphicsConfig gc =
                        (Win32GraphicsConfig)getGraphicsConfiguration();
                ScreenUpdateManager mgr = ScreenUpdateManager.getInstance();
                oldData = surfaceData;
                mgr.dropScreenSurface(oldData);
                surfaceData =
                    mgr.createScreenSurface(gc, this, numBackBuffers, true);
                if (oldData != null) {
                    oldData.invalidate();
                }

                oldBB = backBuffer;
                if (numBackBuffers > 0) {
                    // set the caps first, they're used when creating the bb
                    backBufferCaps = caps;
                    backBuffer = gc.createBackBuffer(this);
                } else if (backBuffer != null) {
                    backBufferCaps = null;
                    backBuffer = null;
                }
            }
        }
        // it would be better to do this before we create new ones,
        // but then we'd run into deadlock issues
        if (oldData != null) {
            oldData.flush();
            // null out the old data to make it collected faster
            oldData = null;
        }
        if (oldBB != null) {
            oldBB.flush();
            // null out the old data to make it collected faster
            oldData = null;
        }
    }
View Full Code Here

    @Override
    public void flip(int x1, int y1, int x2, int y2,
                                  BufferCapabilities.FlipContents flipAction)
    {
        VolatileImage backBuffer = this.backBuffer;
        if (backBuffer == null) {
            throw new IllegalStateException("Buffers have not been created");
        }
        Win32GraphicsConfig gc =
            (Win32GraphicsConfig)getGraphicsConfiguration();
View Full Code Here

public class XGraphics2DRTest extends TestCase {
    public void testNullClip() {
        try {
            GraphicsConfiguration gconf =
                    GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
            VolatileImage vim = gconf.createCompatibleVolatileImage(10, 10);
            Graphics2D g2 = (Graphics2D) vim.getGraphics();
            g2.setClip(null);
        } catch(Exception e) {
            e.printStackTrace();
            fail("Cannot set null clip");
        }
View Full Code Here

    }

    public void testCopyArea() {
        GraphicsConfiguration gconf =
                GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
        VolatileImage vim = gconf.createCompatibleVolatileImage(20, 20);
        Graphics2D g2 = (Graphics2D) vim.getGraphics();
        g2.setColor(Color.WHITE);
        g2.fillRect(0,0,20,20);
        g2.setColor(Color.RED);
        g2.fillRect(2,2,1,1);
        g2.copyArea(2,2,1,1,2,4);
        int pix[] = vim.getSnapshot().getRaster().getPixel(4,6,(int [])null);
        assertEquals("copyArea failed for untranslated graphics", pix[0],255);
        assertEquals("copyArea failed for untranslated graphics", pix[1],0);
        assertEquals("copyArea failed for untranslated graphics", pix[2],0);
        g2.setTransform(AffineTransform.getTranslateInstance(2,2));
        g2.copyArea(0,0,1,1,4,8);
        pix = vim.getSnapshot().getRaster().getPixel(6,10,(int [])null);
        assertEquals("copyArea failed for translated graphics", pix[0],255);
        assertEquals("copyArea failed for translated graphics", pix[1],0);
        assertEquals("copyArea failed for translated graphics", pix[2],0);
    }
View Full Code Here

TOP

Related Classes of java.awt.image.VolatileImage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.