Search in sources :

Example 11 with GraphicsDevice

use of java.awt.GraphicsDevice in project jmonkeyengine by jMonkeyEngine.

the class VRAppState method stateAttached.

@Override
public void stateAttached(AppStateManager stateManager) {
    //To change body of generated methods, choose Tools | Templates.
    super.stateAttached(stateManager);
    if (settings == null) {
        settings = new AppSettings(true);
        logger.config("Using default settings.");
    } else {
        logger.config("Using given settings.");
    }
    // Attach VR environment to the application
    if (!environment.isInitialized()) {
        environment.initialize();
    }
    if (environment.isInitialized()) {
        environment.atttach(this, stateManager.getApplication());
    } else {
        logger.severe("Cannot attach VR environment to the VR app state as its not initialized.");
    }
    GraphicsDevice defDev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    if (environment.isInVR() && !environment.compositorAllowed()) {
        // "easy extended" mode
        // setup experimental JFrame on external device
        // first, find the VR device
        GraphicsDevice VRdev = null;
        GraphicsDevice[] devs = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
        // pick the display that isn't the default one
        for (GraphicsDevice gd : devs) {
            if (gd != defDev) {
                VRdev = gd;
                break;
            }
        }
        // did we get the VR device?
        if (VRdev != null) {
            // set properties for VR acceleration
            try {
                java.awt.DisplayMode useDM = null;
                int max = 0;
                for (java.awt.DisplayMode dm : VRdev.getDisplayModes()) {
                    int check = dm.getHeight() + dm.getWidth() + dm.getRefreshRate() + dm.getBitDepth();
                    if (check > max) {
                        max = check;
                        useDM = dm;
                    }
                }
                // create a window for the VR device
                settings.setWidth(useDM.getWidth());
                settings.setHeight(useDM.getHeight());
                settings.setBitsPerPixel(useDM.getBitDepth());
                settings.setFrequency(useDM.getRefreshRate());
                settings.setSwapBuffers(true);
                // allow vsync on this display
                settings.setVSync(true);
                stateManager.getApplication().setSettings(settings);
                logger.config("Updated underlying application settings.");
                // make sure we are in the right display mode
                if (VRdev.getDisplayMode().equals(useDM) == false) {
                    VRdev.setDisplayMode(useDM);
                }
                return;
            } catch (Exception e) {
                logger.log(Level.SEVERE, e.getMessage(), e);
            }
        } else {
            logger.config("Cannot access to external screen.");
        }
    } else {
        if (!environment.isInVR()) {
            logger.config("Cannot switch to VR mode (VR disabled by user).");
        } else if (!environment.compositorAllowed()) {
            logger.warning("Cannot switch to VR mode (VR not supported).");
        }
    }
    if (!environment.isInVR()) {
        //FIXME: Handling GLFW workaround on MacOS
        boolean macOs = false;
        if (macOs) {
            // GLFW workaround on macs
            settings.setFrequency(defDev.getDisplayMode().getRefreshRate());
            settings.setDepthBits(24);
            settings.setVSync(true);
            // try and read resolution from file in local dir
            File resfile = new File("resolution.txt");
            if (resfile.exists()) {
                try {
                    BufferedReader br = new BufferedReader(new FileReader(resfile));
                    settings.setWidth(Integer.parseInt(br.readLine()));
                    settings.setHeight(Integer.parseInt(br.readLine()));
                    try {
                        settings.setFullscreen(br.readLine().toLowerCase(Locale.ENGLISH).contains("full"));
                    } catch (Exception e) {
                        settings.setFullscreen(false);
                    }
                    br.close();
                } catch (Exception e) {
                    settings.setWidth(1280);
                    settings.setHeight(720);
                }
            } else {
                settings.setWidth(1280);
                settings.setHeight(720);
                settings.setFullscreen(false);
            }
            settings.setResizable(false);
        }
        settings.setSwapBuffers(true);
    } else {
        // use basic mirroring window, skip settings window
        settings.setSamples(1);
        settings.setWidth(xWin);
        settings.setHeight(yWin);
        settings.setBitsPerPixel(32);
        settings.setFrameRate(0);
        settings.setFrequency(environment.getVRHardware().getDisplayFrequency());
        settings.setFullscreen(false);
        // stop vsyncing on primary monitor!
        settings.setVSync(false);
        settings.setSwapBuffers(environment.isSwapBuffers());
    }
    // Updating application settings
    stateManager.getApplication().setSettings(settings);
    logger.config("Updated underlying application settings.");
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) AppSettings(com.jme3.system.AppSettings) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File)

Example 12 with GraphicsDevice

use of java.awt.GraphicsDevice in project screenbird by adamhub.

the class ScreenUtil method isMultipleScreen.

/**
     * Checks for presence of multiple screens/monitors on the current computer.
     * @return True if more than one screen is detected.
     */
public static boolean isMultipleScreen() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] screens = ge.getScreenDevices();
    return screens.length > 1;
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) GraphicsEnvironment(java.awt.GraphicsEnvironment)

Example 13 with GraphicsDevice

use of java.awt.GraphicsDevice in project screenbird by adamhub.

the class RecorderPanelTest method testGetScreen.

/**
     * Test of getScreen method, of class RecorderPanel.
     */
@Test
public void testGetScreen() {
    System.out.println("getScreen");
    GraphicsConfiguration gd = instance.getGraphicsConfiguration();
    GraphicsDevice expResult = gd.getDevice();
    GraphicsDevice result = instance.getScreen();
    assertNotNull(result);
    assertEquals(expResult, result);
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) GraphicsConfiguration(java.awt.GraphicsConfiguration) Test(org.junit.Test)

Example 14 with GraphicsDevice

use of java.awt.GraphicsDevice in project screenbird by adamhub.

the class RecorderTest method testGetScreen.

/**
     * Test of getScreen method, of class Recorder.
     */
@Test
public void testGetScreen() {
    log("getScreen");
    Recorder instance = new Recorder(null);
    GraphicsDevice expResult = null;
    GraphicsDevice result = instance.getScreen();
    assertEquals(expResult, result);
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) Test(org.junit.Test)

Example 15 with GraphicsDevice

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

the class MultimonFullscreenTest method actionPerformed.

public void actionPerformed(ActionEvent ae) {
    GraphicsDevice dev = deviceMap.get(ae.getSource());
    System.err.println("Setting FS on device:" + dev);
    final Window fsWindow;
    if (useFSWindow) {
        fsWindow = new Window(this, dev.getDefaultConfiguration()) {

            public void paint(Graphics g) {
                renderDimensions(g, getBounds(), this.getGraphicsConfiguration());
            }
        };
    } else if (useFSDialog) {
        fsWindow = new Dialog((Frame) null, "FS Dialog on device " + dev, false, dev.getDefaultConfiguration());
        fsWindow.add(new Component() {

            public void paint(Graphics g) {
                renderDimensions(g, getBounds(), this.getGraphicsConfiguration());
            }
        });
    } else {
        fsWindow = new Frame("FS Frame on device " + dev, dev.getDefaultConfiguration()) {

            public void paint(Graphics g) {
                renderDimensions(g, getBounds(), this.getGraphicsConfiguration());
            }
        };
        if (addHWChildren) {
            fsWindow.add("South", new Panel() {

                public void paint(Graphics g) {
                    g.setColor(Color.red);
                    g.fillRect(0, 0, getWidth(), getHeight());
                }
            });
            fsWindow.add("North", new Button("Button, sucka!"));
        }
    }
    fsWindow.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 1) {
                done = true;
                fsWindow.dispose();
            }
        }
    });
    fsWindow.addWindowListener(new WindowHandler());
    dev.setFullScreenWindow(fsWindow);
    if (dmChange && dev.isDisplayChangeSupported()) {
        DisplayMode[] dms = dev.getDisplayModes();
        DisplayMode myDM = null;
        for (DisplayMode dm : dms) {
            if (dm.getWidth() == 800 && dm.getHeight() == 600 && (dm.getBitDepth() >= 16 || dm.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI) && (dm.getRefreshRate() >= 60 || dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN)) {
                myDM = dm;
                break;
            }
        }
        if (myDM != null) {
            System.err.println("Setting Display Mode: " + myDM.getWidth() + "x" + myDM.getHeight() + "x" + myDM.getBitDepth() + "@" + myDM.getRefreshRate() + "Hz on device" + dev);
            dev.setDisplayMode(myDM);
        } else {
            System.err.println("Can't find suitable display mode.");
        }
    }
    done = false;
    if (runRenderLoop) {
        Thread updateThread = new Thread(new Runnable() {

            public void run() {
                BufferStrategy bs = null;
                if (useBS) {
                    fsWindow.createBufferStrategy(2);
                    bs = fsWindow.getBufferStrategy();
                }
                while (!done) {
                    if (useBS) {
                        Graphics g = bs.getDrawGraphics();
                        renderDimensions(g, fsWindow.getBounds(), fsWindow.getGraphicsConfiguration());
                        bs.show();
                    } else {
                        fsWindow.repaint();
                    }
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                    }
                }
                if (useBS) {
                    bs.dispose();
                }
            }
        });
        updateThread.start();
    }
}
Also used : Window(java.awt.Window) Frame(java.awt.Frame) MouseEvent(java.awt.event.MouseEvent) BufferStrategy(java.awt.image.BufferStrategy) MouseAdapter(java.awt.event.MouseAdapter) Graphics(java.awt.Graphics) DisplayMode(java.awt.DisplayMode) Panel(java.awt.Panel) GraphicsDevice(java.awt.GraphicsDevice) Button(java.awt.Button) Dialog(java.awt.Dialog) Component(java.awt.Component)

Aggregations

GraphicsDevice (java.awt.GraphicsDevice)80 GraphicsEnvironment (java.awt.GraphicsEnvironment)46 GraphicsConfiguration (java.awt.GraphicsConfiguration)25 Point (java.awt.Point)17 Dimension (java.awt.Dimension)15 Frame (java.awt.Frame)13 DisplayMode (java.awt.DisplayMode)12 Rectangle (java.awt.Rectangle)11 Graphics (java.awt.Graphics)7 Insets (java.awt.Insets)7 Toolkit (java.awt.Toolkit)7 BufferedImage (java.awt.image.BufferedImage)7 HeadlessException (java.awt.HeadlessException)5 Window (java.awt.Window)4 JFrame (javax.swing.JFrame)4 Test (org.junit.Test)4 MouseAdapter (java.awt.event.MouseAdapter)3 WindowAdapter (java.awt.event.WindowAdapter)3 WindowEvent (java.awt.event.WindowEvent)3 VolatileImage (java.awt.image.VolatileImage)3