< prev index next >

src/java.desktop/unix/classes/sun/awt/X11GraphicsDevice.java

Print this page




  27 
  28 import java.awt.AWTPermission;
  29 import java.awt.DisplayMode;
  30 import java.awt.GraphicsEnvironment;
  31 import java.awt.GraphicsDevice;
  32 import java.awt.GraphicsConfiguration;
  33 import java.awt.Rectangle;
  34 import java.awt.Window;
  35 import java.security.AccessController;
  36 import java.security.PrivilegedAction;
  37 import java.util.ArrayList;
  38 import java.util.HashSet;
  39 import java.util.HashMap;
  40 
  41 import sun.java2d.opengl.GLXGraphicsConfig;
  42 import sun.java2d.xr.XRGraphicsConfig;
  43 import sun.java2d.loops.SurfaceType;
  44 
  45 import sun.awt.util.ThreadGroupUtils;
  46 import sun.java2d.SunGraphicsEnvironment;
  47 import sun.misc.ManagedLocalsThread;
  48 
  49 /**
  50  * This is an implementation of a GraphicsDevice object for a single
  51  * X11 screen.
  52  *
  53  * @see GraphicsEnvironment
  54  * @see GraphicsConfiguration
  55  */
  56 public final class X11GraphicsDevice extends GraphicsDevice
  57         implements DisplayChangedListener {
  58     int screen;
  59     HashMap<SurfaceType, Object> x11ProxyKeyMap = new HashMap<>();
  60 
  61     private static AWTPermission fullScreenExclusivePermission;
  62     private static Boolean xrandrExtSupported;
  63     private final Object configLock = new Object();
  64     private SunDisplayChanger topLevels = new SunDisplayChanger();
  65     private DisplayMode origDisplayMode;
  66     private boolean shutdownHookRegistered;
  67     private final int scale;


 425             throw new IllegalArgumentException("Invalid display mode");
 426         }
 427 
 428         if (!shutdownHookRegistered) {
 429             // register a shutdown hook so that we return to the
 430             // original DisplayMode when the VM exits (if the application
 431             // is already in the original DisplayMode at that time, this
 432             // hook will have no effect)
 433             shutdownHookRegistered = true;
 434             PrivilegedAction<Void> a = () -> {
 435                 Runnable r = () -> {
 436                     Window old = getFullScreenWindow();
 437                     if (old != null) {
 438                         exitFullScreenExclusive(old);
 439                         if (isDisplayChangeSupported()) {
 440                             setDisplayMode(origDisplayMode);
 441                         }
 442                     }
 443                 };
 444                 String name = "Display-Change-Shutdown-Thread-" + screen;
 445                 Thread t = new ManagedLocalsThread(
 446                         ThreadGroupUtils.getRootThreadGroup(), r, name);
 447                 t.setContextClassLoader(null);
 448                 Runtime.getRuntime().addShutdownHook(t);
 449                 return null;
 450             };
 451             AccessController.doPrivileged(a);
 452         }
 453 
 454         // switch to the new DisplayMode
 455         configDisplayMode(screen,
 456                           dm.getWidth(), dm.getHeight(),
 457                           dm.getRefreshRate());
 458 
 459         // update bounds of the fullscreen window
 460         w.setBounds(0, 0, dm.getWidth(), dm.getHeight());
 461 
 462         // configDisplayMode() is synchronous, so the display change will be
 463         // complete by the time we get here (and it is therefore safe to call
 464         // displayChanged() now)
 465         ((X11GraphicsEnvironment)
 466          GraphicsEnvironment.getLocalGraphicsEnvironment()).displayChanged();




  27 
  28 import java.awt.AWTPermission;
  29 import java.awt.DisplayMode;
  30 import java.awt.GraphicsEnvironment;
  31 import java.awt.GraphicsDevice;
  32 import java.awt.GraphicsConfiguration;
  33 import java.awt.Rectangle;
  34 import java.awt.Window;
  35 import java.security.AccessController;
  36 import java.security.PrivilegedAction;
  37 import java.util.ArrayList;
  38 import java.util.HashSet;
  39 import java.util.HashMap;
  40 
  41 import sun.java2d.opengl.GLXGraphicsConfig;
  42 import sun.java2d.xr.XRGraphicsConfig;
  43 import sun.java2d.loops.SurfaceType;
  44 
  45 import sun.awt.util.ThreadGroupUtils;
  46 import sun.java2d.SunGraphicsEnvironment;

  47 
  48 /**
  49  * This is an implementation of a GraphicsDevice object for a single
  50  * X11 screen.
  51  *
  52  * @see GraphicsEnvironment
  53  * @see GraphicsConfiguration
  54  */
  55 public final class X11GraphicsDevice extends GraphicsDevice
  56         implements DisplayChangedListener {
  57     int screen;
  58     HashMap<SurfaceType, Object> x11ProxyKeyMap = new HashMap<>();
  59 
  60     private static AWTPermission fullScreenExclusivePermission;
  61     private static Boolean xrandrExtSupported;
  62     private final Object configLock = new Object();
  63     private SunDisplayChanger topLevels = new SunDisplayChanger();
  64     private DisplayMode origDisplayMode;
  65     private boolean shutdownHookRegistered;
  66     private final int scale;


 424             throw new IllegalArgumentException("Invalid display mode");
 425         }
 426 
 427         if (!shutdownHookRegistered) {
 428             // register a shutdown hook so that we return to the
 429             // original DisplayMode when the VM exits (if the application
 430             // is already in the original DisplayMode at that time, this
 431             // hook will have no effect)
 432             shutdownHookRegistered = true;
 433             PrivilegedAction<Void> a = () -> {
 434                 Runnable r = () -> {
 435                     Window old = getFullScreenWindow();
 436                     if (old != null) {
 437                         exitFullScreenExclusive(old);
 438                         if (isDisplayChangeSupported()) {
 439                             setDisplayMode(origDisplayMode);
 440                         }
 441                     }
 442                 };
 443                 String name = "Display-Change-Shutdown-Thread-" + screen;
 444                 Thread t = new Thread(
 445                       ThreadGroupUtils.getRootThreadGroup(), r, name, 0, false);
 446                 t.setContextClassLoader(null);
 447                 Runtime.getRuntime().addShutdownHook(t);
 448                 return null;
 449             };
 450             AccessController.doPrivileged(a);
 451         }
 452 
 453         // switch to the new DisplayMode
 454         configDisplayMode(screen,
 455                           dm.getWidth(), dm.getHeight(),
 456                           dm.getRefreshRate());
 457 
 458         // update bounds of the fullscreen window
 459         w.setBounds(0, 0, dm.getWidth(), dm.getHeight());
 460 
 461         // configDisplayMode() is synchronous, so the display change will be
 462         // complete by the time we get here (and it is therefore safe to call
 463         // displayChanged() now)
 464         ((X11GraphicsEnvironment)
 465          GraphicsEnvironment.getLocalGraphicsEnvironment()).displayChanged();


< prev index next >