jdk/src/java.desktop/unix/classes/sun/awt/X11GraphicsDevice.java
author ssadetsky
Fri, 08 Jul 2016 18:43:12 +0300
changeset 39844 a3cc7e551a48
parent 37550 c8252b8fea3d
child 40996 60d53c39c1b3
permissions -rw-r--r--
8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account Reviewed-by: alexsch, azvegint
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
39844
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 37550
diff changeset
     2
 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5275
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5275
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5275
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5275
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5275
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.AWTPermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.DisplayMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.GraphicsDevice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.GraphicsConfiguration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Window;
5275
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
    35
import java.security.AccessController;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
    36
import java.security.PrivilegedAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.java2d.opengl.GLXGraphicsConfig;
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
    42
import sun.java2d.xr.XRGraphicsConfig;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.java2d.loops.SurfaceType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
24520
e8afd90fcb69 8035169: Move ThreadGroupUtils from the sun.misc package
pchelko
parents: 23900
diff changeset
    45
import sun.awt.util.ThreadGroupUtils;
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32114
diff changeset
    46
import sun.java2d.SunGraphicsEnvironment;
23900
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23010
diff changeset
    47
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * This is an implementation of a GraphicsDevice object for a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * X11 screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @see GraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @see GraphicsConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
30938
35ae5c70d60e 8030087: Avoid public native methods in sun.awt packages
serb
parents: 30486
diff changeset
    55
public final class X11GraphicsDevice extends GraphicsDevice
35ae5c70d60e 8030087: Avoid public native methods in sun.awt packages
serb
parents: 30486
diff changeset
    56
        implements DisplayChangedListener {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    int screen;
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
    58
    HashMap<SurfaceType, Object> x11ProxyKeyMap = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static AWTPermission fullScreenExclusivePermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static Boolean xrandrExtSupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private final Object configLock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private SunDisplayChanger topLevels = new SunDisplayChanger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private DisplayMode origDisplayMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private boolean shutdownHookRegistered;
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32114
diff changeset
    66
    private final int scale;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public X11GraphicsDevice(int screennum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        this.screen = screennum;
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32114
diff changeset
    70
        this.scale = initScaleFactor();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * Initialize JNI field and method IDs for fields that may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * accessed from C.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Returns the X11 screen of the device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public int getScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        return screen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public Object getProxyKeyFor(SurfaceType st) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        synchronized (x11ProxyKeyMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            Object o = x11ProxyKeyMap.get(st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            if (o == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                o = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                x11ProxyKeyMap.put(st, o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            return o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Returns the X11 Display of this device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * This method is also in MDrawingSurfaceInfo but need it here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * to be able to allow a GraphicsConfigTemplate to get the Display.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public native long getDisplay();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Returns the type of the graphics device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @see #TYPE_RASTER_SCREEN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @see #TYPE_PRINTER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @see #TYPE_IMAGE_BUFFER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public int getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        return TYPE_RASTER_SCREEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Returns the identification string associated with this graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public String getIDstring() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        return ":0."+screen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    GraphicsConfiguration[] configs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    GraphicsConfiguration defaultConfig;
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
   131
    HashSet<Integer> doubleBufferVisuals;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * Returns all of the graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * configurations associated with this graphics device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public GraphicsConfiguration[] getConfigurations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        if (configs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            synchronized (configLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                makeConfigurations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
4204
d8eff41661bf 6822057: X11 and Win32GraphicsDevice don't clone arrays returned from getConfigurations()
bae
parents: 889
diff changeset
   143
        return configs.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    private void makeConfigurations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if (configs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            int i = 1;  // Index 0 is always the default config
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            int num = getNumConfigs(screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            GraphicsConfiguration[] ret = new GraphicsConfiguration[num];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            if (defaultConfig == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                ret [0] = getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                ret [0] = defaultConfig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            boolean glxSupported = X11GraphicsEnvironment.isGLXAvailable();
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   159
            boolean xrenderSupported = X11GraphicsEnvironment.isXRenderAvailable();
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   160
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            boolean dbeSupported = isDBESupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            if (dbeSupported && doubleBufferVisuals == null) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
   163
                doubleBufferVisuals = new HashSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                getDoubleBufferVisuals(screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            for ( ; i < num; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                int visNum = getConfigVisualId(i, screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                int depth = getConfigDepth (i, screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                if (glxSupported) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    ret[i] = GLXGraphicsConfig.getConfig(this, visNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                if (ret[i] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    boolean doubleBuffer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                        (dbeSupported &&
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   175
                         doubleBufferVisuals.contains(Integer.valueOf(visNum)));
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   176
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   177
                    if (xrenderSupported) {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   178
                        ret[i] = XRGraphicsConfig.getConfig(this, visNum, depth,                                getConfigColormap(i, screen),
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   179
                                doubleBuffer);
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   180
                    } else {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   181
                       ret[i] = X11GraphicsConfig.getConfig(this, visNum, depth,
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   182
                              getConfigColormap(i, screen),
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   183
                              doubleBuffer);
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   184
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            configs = ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Returns the number of X11 visuals representable as an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * X11GraphicsConfig object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public native int getNumConfigs(int screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Returns the visualid for the given index of graphics configurations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public native int getConfigVisualId (int index, int screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * Returns the depth for the given index of graphics configurations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
30938
35ae5c70d60e 8030087: Avoid public native methods in sun.awt packages
serb
parents: 30486
diff changeset
   204
    private native int getConfigDepth(int index, int screen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * Returns the colormap for the given index of graphics configurations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
30938
35ae5c70d60e 8030087: Avoid public native methods in sun.awt packages
serb
parents: 30486
diff changeset
   209
    private native int getConfigColormap(int index, int screen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    // Whether or not double-buffering extension is supported
30938
35ae5c70d60e 8030087: Avoid public native methods in sun.awt packages
serb
parents: 30486
diff changeset
   212
    static native boolean isDBESupported();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    // Callback for adding a new double buffer visual into our set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    private void addDoubleBufferVisual(int visNum) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   215
        doubleBufferVisuals.add(Integer.valueOf(visNum));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    // Enumerates all visuals that support double buffering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    private native void getDoubleBufferVisuals(int screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * Returns the default graphics configuration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * associated with this graphics device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public GraphicsConfiguration getDefaultConfiguration() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (defaultConfig == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            synchronized (configLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                makeDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return defaultConfig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    private void makeDefaultConfiguration() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        if (defaultConfig == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            int visNum = getConfigVisualId(0, screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            if (X11GraphicsEnvironment.isGLXAvailable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                defaultConfig = GLXGraphicsConfig.getConfig(this, visNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                if (X11GraphicsEnvironment.isGLXVerbose()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    if (defaultConfig != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                        System.out.print("OpenGL pipeline enabled");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                        System.out.print("Could not enable OpenGL pipeline");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                    System.out.println(" for default config on screen " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                                       screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            if (defaultConfig == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                int depth = getConfigDepth(0, screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                boolean doubleBuffer = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                if (isDBESupported() && doubleBufferVisuals == null) {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 24520
diff changeset
   252
                    doubleBufferVisuals = new HashSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                    getDoubleBufferVisuals(screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                    doubleBuffer =
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   255
                        doubleBufferVisuals.contains(Integer.valueOf(visNum));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                }
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   257
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   258
                if (X11GraphicsEnvironment.isXRenderAvailable()) {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   259
                    if (X11GraphicsEnvironment.isXRenderVerbose()) {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   260
                        System.out.println("XRender pipeline enabled");
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   261
                    }
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   262
                    defaultConfig = XRGraphicsConfig.getConfig(this, visNum,
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   263
                            depth, getConfigColormap(0, screen),
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   264
                            doubleBuffer);
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   265
                } else {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   266
                    defaultConfig = X11GraphicsConfig.getConfig(this, visNum,
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   267
                                        depth, getConfigColormap(0, screen),
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   268
                                        doubleBuffer);
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   269
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    private static native void enterFullScreenExclusive(long window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    private static native void exitFullScreenExclusive(long window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    private static native boolean initXrandrExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    private static native DisplayMode getCurrentDisplayMode(int screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    private static native void enumDisplayModes(int screen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                                                ArrayList<DisplayMode> modes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    private static native void configDisplayMode(int screen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                                                 int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                                                 int displayMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    private static native void resetNativeData(int screen);
39844
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 37550
diff changeset
   284
    private static native double getNativeScaleFactor(int screen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * Returns true only if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *   - the Xrandr extension is present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *   - the necessary Xrandr functions were loaded successfully
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    private static synchronized boolean isXrandrExtensionSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        if (xrandrExtSupported == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            xrandrExtSupported =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                Boolean.valueOf(initXrandrExtension());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return xrandrExtSupported.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    public boolean isFullScreenSupported() {
30486
95884a96b883 8051617: Fullscreen mode is not working properly on Xorg
azvegint
parents: 30473
diff changeset
   301
        boolean fsAvailable = isXrandrExtensionSupported();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        if (fsAvailable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                if (fullScreenExclusivePermission == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                    fullScreenExclusivePermission =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                        new AWTPermission("fullScreenExclusive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    security.checkPermission(fullScreenExclusivePermission);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                } catch (SecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        return fsAvailable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    public boolean isDisplayChangeSupported() {
31650
50fa51b5e407 8081371: [PIT] Test closed/java/awt/FullScreen/DisplayMode/CycleDMImage.java switches Linux to the single device mode
azvegint
parents: 30938
diff changeset
   321
        return (isFullScreenSupported()
32114
73945c07ea9f 8131752: [Regression] Test java/awt/GraphicsDevice/CheckDisplayModes.java fails
azvegint
parents: 31653
diff changeset
   322
                && (getFullScreenWindow() != null)
31650
50fa51b5e407 8081371: [PIT] Test closed/java/awt/FullScreen/DisplayMode/CycleDMImage.java switches Linux to the single device mode
azvegint
parents: 30938
diff changeset
   323
                && !((X11GraphicsEnvironment) GraphicsEnvironment
50fa51b5e407 8081371: [PIT] Test closed/java/awt/FullScreen/DisplayMode/CycleDMImage.java switches Linux to the single device mode
azvegint
parents: 30938
diff changeset
   324
                        .getLocalGraphicsEnvironment()).runningXinerama());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    private static void enterFullScreenExclusive(Window w) {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29922
diff changeset
   328
        X11ComponentPeer peer = AWTAccessor.getComponentAccessor().getPeer(w);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        if (peer != null) {
30486
95884a96b883 8051617: Fullscreen mode is not working properly on Xorg
azvegint
parents: 30473
diff changeset
   330
            enterFullScreenExclusive(peer.getWindow());
4256
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 889
diff changeset
   331
            peer.setFullScreenExclusiveModeState(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    private static void exitFullScreenExclusive(Window w) {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29922
diff changeset
   336
        X11ComponentPeer peer = AWTAccessor.getComponentAccessor().getPeer(w);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        if (peer != null) {
4256
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 889
diff changeset
   338
            peer.setFullScreenExclusiveModeState(false);
30486
95884a96b883 8051617: Fullscreen mode is not working properly on Xorg
azvegint
parents: 30473
diff changeset
   339
            exitFullScreenExclusive(peer.getWindow());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    public synchronized void setFullScreenWindow(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        Window old = getFullScreenWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        if (w == old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        boolean fsSupported = isFullScreenSupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        if (fsSupported && old != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            // enter windowed mode (and restore original display mode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            exitFullScreenExclusive(old);
31650
50fa51b5e407 8081371: [PIT] Test closed/java/awt/FullScreen/DisplayMode/CycleDMImage.java switches Linux to the single device mode
azvegint
parents: 30938
diff changeset
   354
            if (isDisplayChangeSupported()) {
50fa51b5e407 8081371: [PIT] Test closed/java/awt/FullScreen/DisplayMode/CycleDMImage.java switches Linux to the single device mode
azvegint
parents: 30938
diff changeset
   355
                setDisplayMode(origDisplayMode);
50fa51b5e407 8081371: [PIT] Test closed/java/awt/FullScreen/DisplayMode/CycleDMImage.java switches Linux to the single device mode
azvegint
parents: 30938
diff changeset
   356
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        super.setFullScreenWindow(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        if (fsSupported && w != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            // save original display mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            if (origDisplayMode == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                origDisplayMode = getDisplayMode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            // enter fullscreen mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            enterFullScreenExclusive(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    private DisplayMode getDefaultDisplayMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        GraphicsConfiguration gc = getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        Rectangle r = gc.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        return new DisplayMode(r.width, r.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                               DisplayMode.BIT_DEPTH_MULTI,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                               DisplayMode.REFRESH_RATE_UNKNOWN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    public synchronized DisplayMode getDisplayMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        if (isFullScreenSupported()) {
30473
e1314bc8c877 7145508: java.awt.GraphicsDevice.get/setDisplayMode behavior is incorrect when no display is present
prr
parents: 30469
diff changeset
   383
            DisplayMode mode = getCurrentDisplayMode(screen);
e1314bc8c877 7145508: java.awt.GraphicsDevice.get/setDisplayMode behavior is incorrect when no display is present
prr
parents: 30469
diff changeset
   384
            if (mode == null) {
e1314bc8c877 7145508: java.awt.GraphicsDevice.get/setDisplayMode behavior is incorrect when no display is present
prr
parents: 30469
diff changeset
   385
                mode = getDefaultDisplayMode();
e1314bc8c877 7145508: java.awt.GraphicsDevice.get/setDisplayMode behavior is incorrect when no display is present
prr
parents: 30469
diff changeset
   386
            }
e1314bc8c877 7145508: java.awt.GraphicsDevice.get/setDisplayMode behavior is incorrect when no display is present
prr
parents: 30469
diff changeset
   387
            return mode;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            if (origDisplayMode == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                origDisplayMode = getDefaultDisplayMode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            return origDisplayMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    public synchronized DisplayMode[] getDisplayModes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        if (!isFullScreenSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            return super.getDisplayModes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        ArrayList<DisplayMode> modes = new ArrayList<DisplayMode>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        enumDisplayModes(screen, modes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        DisplayMode[] retArray = new DisplayMode[modes.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        return modes.toArray(retArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    public synchronized void setDisplayMode(DisplayMode dm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        if (!isDisplayChangeSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            super.setDisplayMode(dm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        Window w = getFullScreenWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        if (w == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            throw new IllegalStateException("Must be in fullscreen mode " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                                            "in order to set display mode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        }
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 438
diff changeset
   418
        if (getDisplayMode().equals(dm)) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 438
diff changeset
   419
            return;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 438
diff changeset
   420
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        if (dm == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            (dm = getMatchingDisplayMode(dm)) == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            throw new IllegalArgumentException("Invalid display mode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        if (!shutdownHookRegistered) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            // register a shutdown hook so that we return to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            // original DisplayMode when the VM exits (if the application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            // is already in the original DisplayMode at that time, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            // hook will have no effect)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            shutdownHookRegistered = true;
23900
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23010
diff changeset
   433
            PrivilegedAction<Void> a = () -> {
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23010
diff changeset
   434
                Runnable r = () -> {
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23010
diff changeset
   435
                    Window old = getFullScreenWindow();
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23010
diff changeset
   436
                    if (old != null) {
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23010
diff changeset
   437
                        exitFullScreenExclusive(old);
31650
50fa51b5e407 8081371: [PIT] Test closed/java/awt/FullScreen/DisplayMode/CycleDMImage.java switches Linux to the single device mode
azvegint
parents: 30938
diff changeset
   438
                        if (isDisplayChangeSupported()) {
50fa51b5e407 8081371: [PIT] Test closed/java/awt/FullScreen/DisplayMode/CycleDMImage.java switches Linux to the single device mode
azvegint
parents: 30938
diff changeset
   439
                            setDisplayMode(origDisplayMode);
50fa51b5e407 8081371: [PIT] Test closed/java/awt/FullScreen/DisplayMode/CycleDMImage.java switches Linux to the single device mode
azvegint
parents: 30938
diff changeset
   440
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                    }
23900
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23010
diff changeset
   442
                };
29922
7b9c1e1532cf 8027771: Enhance thread contexts
serb
parents: 28231
diff changeset
   443
                String name = "Display-Change-Shutdown-Thread-" + screen;
37550
c8252b8fea3d 8147544: Remove sun.misc.ManagedLocalsThread from java.desktop
prr
parents: 34395
diff changeset
   444
                Thread t = new Thread(
c8252b8fea3d 8147544: Remove sun.misc.ManagedLocalsThread from java.desktop
prr
parents: 34395
diff changeset
   445
                      ThreadGroupUtils.getRootThreadGroup(), r, name, 0, false);
23900
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23010
diff changeset
   446
                t.setContextClassLoader(null);
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23010
diff changeset
   447
                Runtime.getRuntime().addShutdownHook(t);
fd98305f0d19 8031477: [macosx] Loading AWT native library fails
pchelko
parents: 23010
diff changeset
   448
                return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            };
5275
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
   450
            AccessController.doPrivileged(a);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        // switch to the new DisplayMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        configDisplayMode(screen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                          dm.getWidth(), dm.getHeight(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                          dm.getRefreshRate());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        // update bounds of the fullscreen window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        w.setBounds(0, 0, dm.getWidth(), dm.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        // configDisplayMode() is synchronous, so the display change will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        // complete by the time we get here (and it is therefore safe to call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        // displayChanged() now)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        ((X11GraphicsEnvironment)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
         GraphicsEnvironment.getLocalGraphicsEnvironment()).displayChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    private synchronized DisplayMode getMatchingDisplayMode(DisplayMode dm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        if (!isDisplayChangeSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        DisplayMode[] modes = getDisplayModes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        for (DisplayMode mode : modes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            if (dm.equals(mode) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                (dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                 dm.getWidth() == mode.getWidth() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                 dm.getHeight() == mode.getHeight() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                 dm.getBitDepth() == mode.getBitDepth()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                return mode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * From the DisplayChangedListener interface; called from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * X11GraphicsEnvironment when the display mode has been changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    public synchronized void displayChanged() {
11083
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 7668
diff changeset
   491
        // On X11 the visuals do not change, and therefore we don't need
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 7668
diff changeset
   492
        // to reset the defaultConfig, config, doubleBufferVisuals,
34aa99149ff2 7045370: Java Statically Determines Display Size on Linux platforms
anthony
parents: 7668
diff changeset
   493
        // neither do we need to reset the native data.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        // pass on to all top-level windows on this screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        topLevels.notifyListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * From the DisplayChangedListener interface; devices do not need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * to react to this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    public void paletteChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * Add a DisplayChangeListener to be notified when the display settings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * are changed.  Typically, only top-level containers need to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * to X11GraphicsDevice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    public void addDisplayChangedListener(DisplayChangedListener client) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        topLevels.add(client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32114
diff changeset
   515
    public int getScaleFactor() {
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32114
diff changeset
   516
        return scale;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32114
diff changeset
   517
    }
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32114
diff changeset
   518
39844
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 37550
diff changeset
   519
    public int getNativeScale() {
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 37550
diff changeset
   520
        isXrandrExtensionSupported();
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 37550
diff changeset
   521
        return (int)Math.round(getNativeScaleFactor(screen));
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 37550
diff changeset
   522
    }
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 37550
diff changeset
   523
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32114
diff changeset
   524
    private int initScaleFactor() {
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32114
diff changeset
   525
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32114
diff changeset
   526
        if (SunGraphicsEnvironment.isUIScaleEnabled()) {
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32114
diff changeset
   527
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32114
diff changeset
   528
            double debugScale = SunGraphicsEnvironment.getDebugScale();
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32114
diff changeset
   529
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32114
diff changeset
   530
            if (debugScale >= 1) {
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32114
diff changeset
   531
                return (int) debugScale;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32114
diff changeset
   532
            }
39844
a3cc7e551a48 8149115: [hidpi] Linux: display-wise scaling factor should probably be taken into account
ssadetsky
parents: 37550
diff changeset
   533
            int nativeScale = getNativeScale();
34395
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32114
diff changeset
   534
            return nativeScale >= 1 ? nativeScale : 1;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32114
diff changeset
   535
        }
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32114
diff changeset
   536
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32114
diff changeset
   537
        return 1;
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32114
diff changeset
   538
    }
2ac7e99f7f4a 8137571: Linux HiDPI Graphics support
alexsch
parents: 32114
diff changeset
   539
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * Remove a DisplayChangeListener from this X11GraphicsDevice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    public void removeDisplayChangedListener(DisplayChangedListener client) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        topLevels.remove(client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        return ("X11GraphicsDevice[screen="+screen+"]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
}