< prev index next >

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

Print this page




  26 package sun.awt;
  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.misc.ManagedLocalsThread;
  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 
  67     public X11GraphicsDevice(int screennum) {
  68         this.screen = screennum;

  69     }
  70 
  71     /*
  72      * Initialize JNI field and method IDs for fields that may be
  73      * accessed from C.
  74      */
  75     private static native void initIDs();
  76 
  77     static {
  78         if (!GraphicsEnvironment.isHeadless()) {
  79             initIDs();
  80         }
  81     }
  82 
  83     /**
  84      * Returns the X11 screen of the device.
  85      */
  86     public int getScreen() {
  87         return screen;
  88     }


 262                             doubleBuffer);
 263                 } else {
 264                     defaultConfig = X11GraphicsConfig.getConfig(this, visNum,
 265                                         depth, getConfigColormap(0, screen),
 266                                         doubleBuffer);
 267                 }
 268             }
 269         }
 270     }
 271 
 272     private static native void enterFullScreenExclusive(long window);
 273     private static native void exitFullScreenExclusive(long window);
 274     private static native boolean initXrandrExtension();
 275     private static native DisplayMode getCurrentDisplayMode(int screen);
 276     private static native void enumDisplayModes(int screen,
 277                                                 ArrayList<DisplayMode> modes);
 278     private static native void configDisplayMode(int screen,
 279                                                  int width, int height,
 280                                                  int displayMode);
 281     private static native void resetNativeData(int screen);

 282 
 283     /**
 284      * Returns true only if:
 285      *   - the Xrandr extension is present
 286      *   - the necessary Xrandr functions were loaded successfully
 287      */
 288     private static synchronized boolean isXrandrExtensionSupported() {
 289         if (xrandrExtSupported == null) {
 290             xrandrExtSupported =
 291                 Boolean.valueOf(initXrandrExtension());
 292         }
 293         return xrandrExtSupported.booleanValue();
 294     }
 295 
 296     @Override
 297     public boolean isFullScreenSupported() {
 298         boolean fsAvailable = isXrandrExtensionSupported();
 299         if (fsAvailable) {
 300             SecurityManager security = System.getSecurityManager();
 301             if (security != null) {


 490         // neither do we need to reset the native data.
 491 
 492         // pass on to all top-level windows on this screen
 493         topLevels.notifyListeners();
 494     }
 495 
 496     /**
 497      * From the DisplayChangedListener interface; devices do not need
 498      * to react to this event.
 499      */
 500     public void paletteChanged() {
 501     }
 502 
 503     /**
 504      * Add a DisplayChangeListener to be notified when the display settings
 505      * are changed.  Typically, only top-level containers need to be added
 506      * to X11GraphicsDevice.
 507      */
 508     public void addDisplayChangedListener(DisplayChangedListener client) {
 509         topLevels.add(client);





















 510     }
 511 
 512     /**
 513      * Remove a DisplayChangeListener from this X11GraphicsDevice.
 514      */
 515     public void removeDisplayChangedListener(DisplayChangedListener client) {
 516         topLevels.remove(client);
 517     }
 518 
 519     public String toString() {
 520         return ("X11GraphicsDevice[screen="+screen+"]");
 521     }
 522 }


  26 package sun.awt;
  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;
  68 
  69     public X11GraphicsDevice(int screennum) {
  70         this.screen = screennum;
  71         this.scale = initScaleFactor();
  72     }
  73 
  74     /*
  75      * Initialize JNI field and method IDs for fields that may be
  76      * accessed from C.
  77      */
  78     private static native void initIDs();
  79 
  80     static {
  81         if (!GraphicsEnvironment.isHeadless()) {
  82             initIDs();
  83         }
  84     }
  85 
  86     /**
  87      * Returns the X11 screen of the device.
  88      */
  89     public int getScreen() {
  90         return screen;
  91     }


 265                             doubleBuffer);
 266                 } else {
 267                     defaultConfig = X11GraphicsConfig.getConfig(this, visNum,
 268                                         depth, getConfigColormap(0, screen),
 269                                         doubleBuffer);
 270                 }
 271             }
 272         }
 273     }
 274 
 275     private static native void enterFullScreenExclusive(long window);
 276     private static native void exitFullScreenExclusive(long window);
 277     private static native boolean initXrandrExtension();
 278     private static native DisplayMode getCurrentDisplayMode(int screen);
 279     private static native void enumDisplayModes(int screen,
 280                                                 ArrayList<DisplayMode> modes);
 281     private static native void configDisplayMode(int screen,
 282                                                  int width, int height,
 283                                                  int displayMode);
 284     private static native void resetNativeData(int screen);
 285     private static native int getNativeScaleFactor(int screen);
 286 
 287     /**
 288      * Returns true only if:
 289      *   - the Xrandr extension is present
 290      *   - the necessary Xrandr functions were loaded successfully
 291      */
 292     private static synchronized boolean isXrandrExtensionSupported() {
 293         if (xrandrExtSupported == null) {
 294             xrandrExtSupported =
 295                 Boolean.valueOf(initXrandrExtension());
 296         }
 297         return xrandrExtSupported.booleanValue();
 298     }
 299 
 300     @Override
 301     public boolean isFullScreenSupported() {
 302         boolean fsAvailable = isXrandrExtensionSupported();
 303         if (fsAvailable) {
 304             SecurityManager security = System.getSecurityManager();
 305             if (security != null) {


 494         // neither do we need to reset the native data.
 495 
 496         // pass on to all top-level windows on this screen
 497         topLevels.notifyListeners();
 498     }
 499 
 500     /**
 501      * From the DisplayChangedListener interface; devices do not need
 502      * to react to this event.
 503      */
 504     public void paletteChanged() {
 505     }
 506 
 507     /**
 508      * Add a DisplayChangeListener to be notified when the display settings
 509      * are changed.  Typically, only top-level containers need to be added
 510      * to X11GraphicsDevice.
 511      */
 512     public void addDisplayChangedListener(DisplayChangedListener client) {
 513         topLevels.add(client);
 514     }
 515 
 516     public int getScaleFactor() {
 517         return scale;
 518     }
 519 
 520     private int initScaleFactor() {
 521 
 522         if (SunGraphicsEnvironment.isUIScaleEnabled()) {
 523 
 524             double debugScale = SunGraphicsEnvironment.getDebugScale();
 525 
 526             if (debugScale >= 1) {
 527                 return (int) debugScale;
 528             }
 529 
 530             int nativeScale = getNativeScaleFactor(screen);
 531             return nativeScale >= 1 ? nativeScale : 1;
 532         }
 533 
 534         return 1;
 535     }
 536 
 537     /**
 538      * Remove a DisplayChangeListener from this X11GraphicsDevice.
 539      */
 540     public void removeDisplayChangedListener(DisplayChangedListener client) {
 541         topLevels.remove(client);
 542     }
 543 
 544     public String toString() {
 545         return ("X11GraphicsDevice[screen="+screen+"]");
 546     }
 547 }
< prev index next >