Search in sources :

Example 21 with VolatileImage

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

the class RSLAPITest method testGC.

private static void testGC(GraphicsConfiguration gc) {
    if (!(gc instanceof AccelGraphicsConfig)) {
        System.out.println("Test passed: no hw accelerated configs found.");
        return;
    }
    System.out.println("AccelGraphicsConfig exists, testing.");
    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());
        }
    } else {
        System.out.println("VI is not DestSurfaceProvider");
    }
    testVICreation(agc, CAPS_RT_TEXTURE_ALPHA, TRANSLUCENT, RT_TEXTURE);
    testVICreation(agc, CAPS_RT_TEXTURE_OPAQUE, OPAQUE, RT_TEXTURE);
    testVICreation(agc, CAPS_RT_PLAIN_ALPHA, TRANSLUCENT, RT_PLAIN);
    testVICreation(agc, agc.getContextCapabilities().getCaps(), OPAQUE, TEXTURE);
    testForNPEDuringCreation(agc);
}
Also used : Graphics(java.awt.Graphics) AccelSurface(sun.java2d.pipe.hw.AccelSurface) VolatileImage(java.awt.image.VolatileImage) AccelGraphicsConfig(sun.java2d.pipe.hw.AccelGraphicsConfig) DestSurfaceProvider(sun.java2d.DestSurfaceProvider) Surface(sun.java2d.Surface) AccelSurface(sun.java2d.pipe.hw.AccelSurface)

Example 22 with VolatileImage

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

the class RSLAPITest method testForNPEDuringCreation.

private static void testForNPEDuringCreation(AccelGraphicsConfig agc) {
    int iterations = 100;
    HashSet<VolatileImage> vis = new HashSet<VolatileImage>();
    GraphicsConfiguration gc = (GraphicsConfiguration) agc;
    Rectangle r = gc.getBounds();
    long ram = gc.getDevice().getAvailableAcceleratedMemory();
    if (ram > 0) {
        // guesstimate the number of iterations needed to exhaust vram
        int i = 2 * (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");
}
Also used : VolatileImage(java.awt.image.VolatileImage) Rectangle(java.awt.Rectangle) HashSet(java.util.HashSet) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 23 with VolatileImage

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

the class RSLAPITest method testVICreation.

private static void testVICreation(AccelGraphicsConfig agc, int cap, 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) {
                        throw new RuntimeException("Failed: " + "texture.getGraphics() didn't throw exception");
                    } else {
                        System.out.println("Passed: VI.getGraphics()" + " threw exception for texture-based VI");
                    }
                }
            } else {
                System.out.printf("Passed: VI of type %d was " + "created for cap=%d but accel surface is null\n", type, cap);
            }
        }
    } else {
        if (vi != null) {
            throw new RuntimeException("Failed: created VI for " + "unsupported cap=" + cap);
        }
    }
}
Also used : Graphics(java.awt.Graphics) AccelSurface(sun.java2d.pipe.hw.AccelSurface) VolatileImage(java.awt.image.VolatileImage) DestSurfaceProvider(sun.java2d.DestSurfaceProvider) Surface(sun.java2d.Surface) AccelSurface(sun.java2d.pipe.hw.AccelSurface)

Example 24 with VolatileImage

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

the class ClassCastExceptionForInvalidSurface method main.

public static void main(final String[] args) throws InterruptedException {
    // Catch all uncaught exceptions and treat them as test failure
    Thread.setDefaultUncaughtExceptionHandler((t, e) -> failed = e);
    // Data for rendering
    BufferedImage bi = new BufferedImage(10, 10, TYPE_INT_ARGB);
    FontRenderContext frc = new FontRenderContext(null, false, false);
    Font font = new Font("Serif", Font.PLAIN, 12);
    GlyphVector gv = font.createGlyphVector(frc, new char[] { 'a', '1' });
    Thread t1 = new Thread(() -> {
        while (!isComplete()) {
            vi = gc.createCompatibleVolatileImage(10, 10);
            if (!list.offer(vi)) {
                vi.flush();
            }
        }
        list.forEach(Image::flush);
    });
    Thread t2 = new Thread(() -> {
        while (!isComplete()) {
            VolatileImage vi = list.poll();
            if (vi != null) {
                vi.flush();
            }
        }
    });
    Thread t3 = new Thread(() -> {
        while (!isComplete()) {
            vi.createGraphics().drawImage(bi, 1, 1, null);
        }
    });
    Thread t4 = new Thread(() -> {
        while (!isComplete()) {
            vi.createGraphics().drawGlyphVector(gv, 0, 0);
            vi.createGraphics().drawOval(0, 0, 10, 10);
            vi.createGraphics().drawLine(0, 0, 10, 10);
            vi.createGraphics().drawString("123", 1, 1);
            vi.createGraphics().draw(new Rectangle(0, 0, 10, 10));
            vi.createGraphics().fillOval(0, 0, 10, 10);
            final Graphics2D graphics = vi.createGraphics();
            graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            graphics.fillPolygon(new int[] { 0, 10, 10, 0 }, new int[] { 0, 0, 10, 10 }, 4);
        }
    });
    t1.start();
    t2.start();
    t3.start();
    t4.start();
    t1.join();
    t2.join();
    t3.join();
    t4.join();
    if (failed != null) {
        System.err.println("Test failed");
        failed.printStackTrace();
    }
}
Also used : GlyphVector(java.awt.font.GlyphVector) VolatileImage(java.awt.image.VolatileImage) Rectangle(java.awt.Rectangle) FontRenderContext(java.awt.font.FontRenderContext) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) VolatileImage(java.awt.image.VolatileImage) BufferedImage(java.awt.image.BufferedImage) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D)

Example 25 with VolatileImage

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

the class AccelPaintsTest method test.

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");
            }
        }
    }
}
Also used : VolatileImage(java.awt.image.VolatileImage) IOException(java.io.IOException) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) TexturePaint(java.awt.TexturePaint) RadialGradientPaint(java.awt.RadialGradientPaint) LinearGradientPaint(java.awt.LinearGradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

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