Search in sources :

Example 21 with GraphicsDevice

use of java.awt.GraphicsDevice in project jdk8u_jdk by JetBrains.

the class bug8071705 method main.

public static void main(String[] args) throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    final boolean[] result = new boolean[1];
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            JFrame frame = createGUI();
            GraphicsDevice[] devices = checkScreens();
            // check if we have more than one and if they are stacked
            // vertically
            GraphicsDevice device = checkConfigs(devices);
            if (device == null) {
                // just pass the test
                frame.dispose();
                result[0] = true;
                latch.countDown();
            } else {
                FrameListener listener = new FrameListener(device, latch, result);
                frame.addComponentListener(listener);
                frame.setVisible(true);
            }
        }
    });
    latch.await();
    if (result[0] == false) {
        throw new RuntimeException("popup menu rendered in wrong position");
    }
    System.out.println("OK");
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) JFrame(javax.swing.JFrame) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 22 with GraphicsDevice

use of java.awt.GraphicsDevice 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 23 with GraphicsDevice

use of java.awt.GraphicsDevice in project jdk8u_jdk by JetBrains.

the class TSFrame method createGui.

public static Frame createGui(final boolean useSwing, final boolean useShape, final boolean useTransl, final boolean useNonOpaque, final float factor) {
    Frame frame;
    done = false;
    if (useNonOpaque) {
        if (useSwing) {
            frame = new NonOpaqueJFrame();
        //                frame = new NonOpaqueJAppletFrame(gc);
        } else {
            frame = new NonOpaqueFrame();
        }
        animateComponent(frame);
    } else if (useSwing) {
        frame = new JFrame("Swing Frame");
        JComponent p = new JButton("Swing!");
        p.setPreferredSize(new Dimension(200, 100));
        frame.add("North", p);
        p = new MyJPanel();
        animateComponent(p);
        frame.add("Center", p);
    } else {
        frame = new Frame("AWT Frame") {

            public void paint(Graphics g) {
                g.setColor(Color.red);
                g.fillRect(0, 0, 100, 100);
            }
        };
        frame.setLayout(new BorderLayout());
        Canvas c = new MyCanvas();
        frame.add("North", c);
        animateComponent(c);
        c = new MyCanvas();
        frame.add("Center", c);
        animateComponent(c);
        c = new MyCanvas();
        frame.add("South", c);
        animateComponent(c);
    }
    final Frame finalFrame = frame;
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            finalFrame.dispose();
            done = true;
        }
    });
    frame.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            finalFrame.dispose();
            done = true;
        }
    });
    frame.setPreferredSize(new Dimension(800, 600));
    if (useShape) {
        frame.setUndecorated(true);
    }
    frame.setLocation(450, 10);
    frame.pack();
    GraphicsDevice gd = frame.getGraphicsConfiguration().getDevice();
    if (useShape) {
        if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSPARENT)) {
            System.out.println("applying PERPIXEL_TRANSPARENT");
            frame.setShape(new Ellipse2D.Double(0, 0, frame.getWidth(), frame.getHeight() / 3));
            frame.setTitle("PERPIXEL_TRANSPARENT");
        } else {
            System.out.println("Passed: PERPIXEL_TRANSPARENT unsupported");
        }
    }
    if (useTransl) {
        if (gd.isWindowTranslucencySupported(WindowTranslucency.TRANSLUCENT)) {
            System.out.println("applying TRANSLUCENT");
            frame.setOpacity(factor);
            frame.setTitle("TRANSLUCENT");
        } else {
            System.out.println("Passed: TRANSLUCENT unsupported");
        }
    }
    if (useNonOpaque) {
        if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSLUCENT)) {
            System.out.println("applying PERPIXEL_TRANSLUCENT");
            frame.setBackground(new Color(0, 0, 0, 0));
            frame.setTitle("PERPIXEL_TRANSLUCENT");
        } else {
            System.out.println("Passed: PERPIXEL_TRANSLUCENT unsupported");
        }
    }
    frame.setVisible(true);
    return frame;
}
Also used : JFrame(javax.swing.JFrame) Frame(java.awt.Frame) MouseEvent(java.awt.event.MouseEvent) Canvas(java.awt.Canvas) Color(java.awt.Color) JButton(javax.swing.JButton) JComponent(javax.swing.JComponent) MouseAdapter(java.awt.event.MouseAdapter) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension) Ellipse2D(java.awt.geom.Ellipse2D) Graphics(java.awt.Graphics) GraphicsDevice(java.awt.GraphicsDevice) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent)

Example 24 with GraphicsDevice

use of java.awt.GraphicsDevice in project jdk8u_jdk by JetBrains.

the class UnmanagedDrawImagePerformance method makeVI.

private static VolatileImage makeVI(final int type) {
    final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsDevice gd = ge.getDefaultScreenDevice();
    final GraphicsConfiguration gc = gd.getDefaultConfiguration();
    return gc.createCompatibleVolatileImage(SIZE, SIZE, type);
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) GraphicsEnvironment(java.awt.GraphicsEnvironment) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 25 with GraphicsDevice

use of java.awt.GraphicsDevice in project jdk8u_jdk by JetBrains.

the class RSLContextInvalidationTest method main.

public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(100, 100);
    vi.validate(gc);
    VolatileImage vi1 = gc.createCompatibleVolatileImage(100, 100);
    vi1.validate(gc);
    if (!(vi instanceof DestSurfaceProvider)) {
        System.out.println("Test considered PASSED: no HW acceleration");
        return;
    }
    DestSurfaceProvider p = (DestSurfaceProvider) vi;
    Surface s = p.getDestSurface();
    if (!(s instanceof AccelSurface)) {
        System.out.println("Test considered PASSED: no HW acceleration");
        return;
    }
    AccelSurface dst = (AccelSurface) s;
    Graphics g = vi.createGraphics();
    g.drawImage(vi1, 95, 95, null);
    g.setColor(Color.red);
    g.fillRect(0, 0, 100, 100);
    g.setColor(Color.black);
    g.fillRect(0, 0, 100, 100);
    // after this the validated context color is black
    RenderQueue rq = dst.getContext().getRenderQueue();
    rq.lock();
    try {
        dst.getContext().saveState();
        dst.getContext().restoreState();
    } finally {
        rq.unlock();
    }
    // this will cause ResetPaint (it will set color to extended EA=ff,
    // which is ffffffff==Color.white)
    g.drawImage(vi1, 95, 95, null);
    // now try filling with black again, but it will come up as white
    // because this fill rect won't validate the color properly
    g.setColor(Color.black);
    g.fillRect(0, 0, 100, 100);
    BufferedImage bi = vi.getSnapshot();
    if (bi.getRGB(50, 50) != Color.black.getRGB()) {
        throw new RuntimeException("Test FAILED: found color=" + Integer.toHexString(bi.getRGB(50, 50)) + " instead of " + Integer.toHexString(Color.black.getRGB()));
    }
    System.out.println("Test PASSED.");
}
Also used : Graphics(java.awt.Graphics) GraphicsDevice(java.awt.GraphicsDevice) VolatileImage(java.awt.image.VolatileImage) DestSurfaceProvider(sun.java2d.DestSurfaceProvider) RenderQueue(sun.java2d.pipe.RenderQueue) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Surface(sun.java2d.Surface)

Aggregations

GraphicsDevice (java.awt.GraphicsDevice)75 GraphicsEnvironment (java.awt.GraphicsEnvironment)44 GraphicsConfiguration (java.awt.GraphicsConfiguration)23 Point (java.awt.Point)15 Frame (java.awt.Frame)13 Dimension (java.awt.Dimension)12 DisplayMode (java.awt.DisplayMode)12 Rectangle (java.awt.Rectangle)11 Insets (java.awt.Insets)7 Toolkit (java.awt.Toolkit)7 Graphics (java.awt.Graphics)6 BufferedImage (java.awt.image.BufferedImage)6 HeadlessException (java.awt.HeadlessException)4 Window (java.awt.Window)4 JFrame (javax.swing.JFrame)4 Test (org.junit.Test)4 MouseAdapter (java.awt.event.MouseAdapter)3 MouseEvent (java.awt.event.MouseEvent)3 WindowAdapter (java.awt.event.WindowAdapter)3 WindowEvent (java.awt.event.WindowEvent)3