Search in sources :

Example 26 with VolatileImage

use of java.awt.image.VolatileImage in project jdk8u_jdk by JetBrains.

the class OnScreenRenderingResizeTest method main.

public static void main(String[] args) {
    for (String arg : args) {
        if ("-inf".equals(arg)) {
            System.err.println("Test will run indefinitely");
            RUN_TIME = Long.MAX_VALUE;
        } else if ("-nocheck".equals(arg)) {
            System.err.println("Test will not check rendering results");
            nocheck = true;
        } else {
            System.err.println("Usage: OnScreenRenderingResizeTest [-inf][-nocheck]");
        }
    }
    BufferedImage output = new BufferedImage(IMAGE_W, IMAGE_H, BufferedImage.TYPE_INT_RGB);
    output.setAccelerationPriority(0.0f);
    Graphics g = output.getGraphics();
    g.setColor(renderColor);
    g.fillRect(0, 0, output.getWidth(), output.getHeight());
    final Frame frame = new Frame("OnScreenRenderingResizeTest") {

        public void paint(Graphics g) {
        }

        public void update(Graphics g) {
        }
    };
    frame.setBackground(bgColor);
    frame.setUndecorated(true);
    frame.pack();
    GraphicsConfiguration gc = frame.getGraphicsConfiguration();
    Rectangle gcBounds = gc.getBounds();
    frame.setBounds(gcBounds.width / 4, gcBounds.height / 4, FRAME_W, FRAME_H);
    frame.addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent e) {
            done = true;
        }
    });
    try {
        EventQueue.invokeAndWait(new Runnable() {

            public void run() {
                frame.setVisible(true);
            }
        });
        // wait for Vista's effects to complete
        Thread.sleep(2000);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    int maxW = gcBounds.width / 2;
    int maxH = gcBounds.height / 2;
    int minW = frame.getWidth();
    int minH = frame.getHeight();
    int incW = 10, incH = 10, cnt = 0;
    Robot robot = null;
    if (!nocheck && gc.getColorModel().getPixelSize() > 8) {
        try {
            robot = new Robot();
        } catch (AWTException ex) {
            System.err.println("Robot creation failed, continuing.");
        }
    } else {
        System.err.println("No screen rendering checks.");
    }
    VolatileImage vi = gc.createCompatibleVolatileImage(512, 512);
    vi.validate(gc);
    long timeStarted = System.currentTimeMillis();
    while (!done && (System.currentTimeMillis() - timeStarted) < RUN_TIME) {
        if (++cnt > 100) {
            int w = frame.getWidth() + incW;
            int h = frame.getHeight() + incH;
            if (w < minW || w > maxW) {
                incW = -incW;
            }
            if (h < minH || h > maxH) {
                incH = -incH;
            }
            frame.setSize(w, h);
            cnt = 0;
        }
        // try to put the device into non-default state, for example,
        // this operation below will set the transform
        vi.validate(gc);
        Graphics2D vig = (Graphics2D) vi.getGraphics();
        vig.rotate(30.0f, vi.getWidth() / 2, vi.getHeight() / 2);
        vig.drawImage(output, 0, 0, vi.getWidth(), vi.getHeight(), null);
        Insets in = frame.getInsets();
        frame.getGraphics().drawImage(output, in.left, in.top, null);
        if (cnt == 90 && robot != null) {
            robot.waitForIdle();
            // area where we blitted to should be either white or green
            Point p = frame.getLocationOnScreen();
            p.translate(in.left + 10, in.top + 10);
            BufferedImage bi = robot.createScreenCapture(new Rectangle(p.x, p.y, IMAGE_W / 2, IMAGE_H / 2));
            int[] accepted1 = { Color.white.getRGB(), Color.green.getRGB() };
            checkBI(bi, accepted1);
            // the are where we didn't render should stay white
            p = frame.getLocationOnScreen();
            p.translate(in.left, in.top + IMAGE_H + 5);
            bi = robot.createScreenCapture(new Rectangle(p.x, p.y, frame.getWidth() - in.left - in.right, frame.getHeight() - in.top - in.bottom - 5 - IMAGE_H));
            int[] accepted2 = { Color.white.getRGB() };
            checkBI(bi, accepted2);
        }
        Thread.yield();
    }
    frame.dispose();
    System.out.println("Test Passed");
}
Also used : Frame(java.awt.Frame) Insets(java.awt.Insets) Rectangle(java.awt.Rectangle) WindowAdapter(java.awt.event.WindowAdapter) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException) AWTException(java.awt.AWTException) Point(java.awt.Point) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D) Graphics(java.awt.Graphics) VolatileImage(java.awt.image.VolatileImage) WindowEvent(java.awt.event.WindowEvent) Robot(java.awt.Robot) AWTException(java.awt.AWTException)

Example 27 with VolatileImage

use of java.awt.image.VolatileImage in project jdk8u_jdk by JetBrains.

the class OpaqueImageToSurfaceBlitTest method main.

public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(16, 16);
    vi.validate(gc);
    BufferedImage bi = new BufferedImage(2, 2, BufferedImage.TYPE_INT_RGB);
    int[] data = ((DataBufferInt) bi.getRaster().getDataBuffer()).getData();
    data[0] = 0x0000007f;
    data[1] = 0x0000007f;
    data[2] = 0xff00007f;
    data[3] = 0xff00007f;
    Graphics2D g = vi.createGraphics();
    g.setComposite(AlphaComposite.SrcOver.derive(0.999f));
    g.drawImage(bi, 0, 0, null);
    bi = vi.getSnapshot();
    if (bi.getRGB(0, 0) != bi.getRGB(1, 1)) {
        throw new RuntimeException("Test FAILED: color at 0x0 =" + Integer.toHexString(bi.getRGB(0, 0)) + " differs from 1x1 =" + Integer.toHexString(bi.getRGB(1, 1)));
    }
    System.out.println("Test PASSED.");
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) VolatileImage(java.awt.image.VolatileImage) DataBufferInt(java.awt.image.DataBufferInt) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Example 28 with VolatileImage

use of java.awt.image.VolatileImage in project jdk8u_jdk by JetBrains.

the class NonOpaqueDestLCDAATest method initImages.

private void initImages(int w, int h) {
    if (images == null) {
        images = new Image[6];
        GraphicsConfiguration gc = getGraphicsConfiguration();
        for (int i = OPAQUE; i <= TRANSLUCENT; i++) {
            VolatileImage vi = gc.createCompatibleVolatileImage(w, h / images.length, i);
            images[i - 1] = vi;
            vi.validate(gc);
            String s = "LCD AA Text rendered to " + tr[i - 1] + " HW destination";
            render(vi, i, s);
            s = "LCD AA Text rendered to " + tr[i - 1] + " SW destination";
            images[i - 1 + 3] = gc.createCompatibleImage(w, h / images.length, i);
            render(images[i - 1 + 3], i, s);
        }
    }
}
Also used : VolatileImage(java.awt.image.VolatileImage) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 29 with VolatileImage

use of java.awt.image.VolatileImage in project jdk8u_jdk by JetBrains.

the class TransformedPaintTest method runTest.

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.");
}
Also used : VolatileImage(java.awt.image.VolatileImage) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Example 30 with VolatileImage

use of java.awt.image.VolatileImage in project jdk8u_jdk by JetBrains.

the class CustomCompositeTest method testVolatileImage.

private static void testVolatileImage(GraphicsConfiguration cfg, boolean accelerated) {
    VolatileImage dst = null;
    try {
        dst = cfg.createCompatibleVolatileImage(640, 480, new ImageCapabilities(accelerated));
    } catch (AWTException e) {
        System.out.println("Unable to create volatile image, skip the test.");
        return;
    }
    renderToVolatileImage(dst);
}
Also used : VolatileImage(java.awt.image.VolatileImage) ImageCapabilities(java.awt.ImageCapabilities) AWTException(java.awt.AWTException)

Aggregations

VolatileImage (java.awt.image.VolatileImage)53 GraphicsConfiguration (java.awt.GraphicsConfiguration)30 BufferedImage (java.awt.image.BufferedImage)29 Graphics2D (java.awt.Graphics2D)24 GraphicsEnvironment (java.awt.GraphicsEnvironment)21 Graphics (java.awt.Graphics)6 AffineTransform (java.awt.geom.AffineTransform)6 Rectangle (java.awt.Rectangle)5 File (java.io.File)5 GraphicsDevice (java.awt.GraphicsDevice)3 Shape (java.awt.Shape)3 IOException (java.io.IOException)3 DestSurfaceProvider (sun.java2d.DestSurfaceProvider)3 Surface (sun.java2d.Surface)3 AWTException (java.awt.AWTException)2 Font (java.awt.Font)2 GradientPaint (java.awt.GradientPaint)2 Image (java.awt.Image)2 ImageCapabilities (java.awt.ImageCapabilities)2 Paint (java.awt.Paint)2