jdk/src/solaris/classes/sun/awt/X11GraphicsDevice.java
author lana
Sat, 29 May 2010 23:26:16 -0700
changeset 5580 629274e4c99f
parent 5579 1a5e995a710b
parent 5506 202f599c92aa
child 7668 d4a77089c587
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5275
diff changeset
     2
 * Copyright (c) 1997, 2009, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * This is an implementation of a GraphicsDevice object for a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * X11 screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @see GraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @see GraphicsConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
public class X11GraphicsDevice
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    extends GraphicsDevice
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    implements DisplayChangedListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    int screen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    HashMap x11ProxyKeyMap = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static AWTPermission fullScreenExclusivePermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static Boolean xrandrExtSupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private final Object configLock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private SunDisplayChanger topLevels = new SunDisplayChanger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private DisplayMode origDisplayMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private boolean shutdownHookRegistered;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public X11GraphicsDevice(int screennum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        this.screen = screennum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Initialize JNI field and method IDs for fields that may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * accessed from C.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Returns the X11 screen of the device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public int getScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        return screen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public Object getProxyKeyFor(SurfaceType st) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        synchronized (x11ProxyKeyMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            Object o = x11ProxyKeyMap.get(st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            if (o == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                o = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                x11ProxyKeyMap.put(st, o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            return o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * Returns the X11 Display of this device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * This method is also in MDrawingSurfaceInfo but need it here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * to be able to allow a GraphicsConfigTemplate to get the Display.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public native long getDisplay();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Returns the type of the graphics device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @see #TYPE_RASTER_SCREEN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @see #TYPE_PRINTER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @see #TYPE_IMAGE_BUFFER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public int getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        return TYPE_RASTER_SCREEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Returns the identification string associated with this graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public String getIDstring() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        return ":0."+screen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    GraphicsConfiguration[] configs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    GraphicsConfiguration defaultConfig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    HashSet doubleBufferVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Returns all of the graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * configurations associated with this graphics device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public GraphicsConfiguration[] getConfigurations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (configs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            synchronized (configLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                makeConfigurations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
4204
d8eff41661bf 6822057: X11 and Win32GraphicsDevice don't clone arrays returned from getConfigurations()
bae
parents: 889
diff changeset
   140
        return configs.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private void makeConfigurations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if (configs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            int i = 1;  // Index 0 is always the default config
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            int num = getNumConfigs(screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            GraphicsConfiguration[] ret = new GraphicsConfiguration[num];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            if (defaultConfig == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                ret [0] = getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                ret [0] = defaultConfig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            boolean glxSupported = X11GraphicsEnvironment.isGLXAvailable();
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   156
            boolean xrenderSupported = X11GraphicsEnvironment.isXRenderAvailable();
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   157
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            boolean dbeSupported = isDBESupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            if (dbeSupported && doubleBufferVisuals == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                doubleBufferVisuals = new HashSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                getDoubleBufferVisuals(screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            for ( ; i < num; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                int visNum = getConfigVisualId(i, screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                int depth = getConfigDepth (i, screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                if (glxSupported) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                    ret[i] = GLXGraphicsConfig.getConfig(this, visNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                if (ret[i] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    boolean doubleBuffer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                        (dbeSupported &&
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   172
                         doubleBufferVisuals.contains(Integer.valueOf(visNum)));
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   173
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   174
                    if (xrenderSupported) {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   175
                        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
   176
                                doubleBuffer);
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   177
                    } else {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   178
                       ret[i] = X11GraphicsConfig.getConfig(this, visNum, depth,
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   179
                              getConfigColormap(i, screen),
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   180
                              doubleBuffer);
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   181
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            configs = ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * Returns the number of X11 visuals representable as an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * X11GraphicsConfig object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public native int getNumConfigs(int screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Returns the visualid for the given index of graphics configurations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public native int getConfigVisualId (int index, int screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Returns the depth for the given index of graphics configurations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public native int getConfigDepth (int index, int screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * Returns the colormap for the given index of graphics configurations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public native int getConfigColormap (int index, int screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    // Whether or not double-buffering extension is supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public static native boolean isDBESupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    // Callback for adding a new double buffer visual into our set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    private void addDoubleBufferVisual(int visNum) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   213
        doubleBufferVisuals.add(Integer.valueOf(visNum));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    // Enumerates all visuals that support double buffering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    private native void getDoubleBufferVisuals(int screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Returns the default graphics configuration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * associated with this graphics device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public GraphicsConfiguration getDefaultConfiguration() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (defaultConfig == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            synchronized (configLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                makeDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return defaultConfig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    private void makeDefaultConfiguration() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if (defaultConfig == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            int visNum = getConfigVisualId(0, screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            if (X11GraphicsEnvironment.isGLXAvailable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                defaultConfig = GLXGraphicsConfig.getConfig(this, visNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                if (X11GraphicsEnvironment.isGLXVerbose()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    if (defaultConfig != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                        System.out.print("OpenGL pipeline enabled");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                        System.out.print("Could not enable OpenGL pipeline");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    System.out.println(" for default config on screen " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                                       screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            if (defaultConfig == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                int depth = getConfigDepth(0, screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                boolean doubleBuffer = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                if (isDBESupported() && doubleBufferVisuals == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    doubleBufferVisuals = new HashSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    getDoubleBufferVisuals(screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                    doubleBuffer =
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   253
                        doubleBufferVisuals.contains(Integer.valueOf(visNum));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                }
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   255
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   256
                if (X11GraphicsEnvironment.isXRenderAvailable()) {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   257
                    if (X11GraphicsEnvironment.isXRenderVerbose()) {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   258
                        System.out.println("XRender pipeline enabled");
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   259
                    }
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   260
                    defaultConfig = XRGraphicsConfig.getConfig(this, visNum,
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   261
                            depth, getConfigColormap(0, screen),
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   262
                            doubleBuffer);
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   263
                } else {
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   264
                    defaultConfig = X11GraphicsConfig.getConfig(this, visNum,
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   265
                                        depth, getConfigColormap(0, screen),
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   266
                                        doubleBuffer);
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 5275
diff changeset
   267
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    private static native void enterFullScreenExclusive(long window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    private static native void exitFullScreenExclusive(long window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    private static native boolean initXrandrExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    private static native DisplayMode getCurrentDisplayMode(int screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    private static native void enumDisplayModes(int screen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                                                ArrayList<DisplayMode> modes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    private static native void configDisplayMode(int screen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                                                 int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                                                 int displayMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    private static native void resetNativeData(int screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * Returns true only if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *   - the Xrandr extension is present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *   - the necessary Xrandr functions were loaded successfully
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *   - XINERAMA is not enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    private static synchronized boolean isXrandrExtensionSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if (xrandrExtSupported == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            xrandrExtSupported =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                Boolean.valueOf(initXrandrExtension());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        return xrandrExtSupported.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public boolean isFullScreenSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        // REMIND: for now we will only allow fullscreen exclusive mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        // on the primary screen; we could change this behavior slightly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        // in the future by allowing only one screen to be in fullscreen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        // exclusive mode at any given time...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        boolean fsAvailable = (screen == 0) && isXrandrExtensionSupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        if (fsAvailable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                if (fullScreenExclusivePermission == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                    fullScreenExclusivePermission =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                        new AWTPermission("fullScreenExclusive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                    security.checkPermission(fullScreenExclusivePermission);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                } catch (SecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        return fsAvailable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    public boolean isDisplayChangeSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        return (isFullScreenSupported() && (getFullScreenWindow() != null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    private static void enterFullScreenExclusive(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        X11ComponentPeer peer = (X11ComponentPeer)w.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            enterFullScreenExclusive(peer.getContentWindow());
4256
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 889
diff changeset
   330
            peer.setFullScreenExclusiveModeState(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    private static void exitFullScreenExclusive(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        X11ComponentPeer peer = (X11ComponentPeer)w.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        if (peer != null) {
4256
24d614d4764a 6711717: PIT: Security Icon is hidden for FullScreen apps, WinXP
anthony
parents: 889
diff changeset
   337
            peer.setFullScreenExclusiveModeState(false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            exitFullScreenExclusive(peer.getContentWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    public synchronized void setFullScreenWindow(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        Window old = getFullScreenWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        if (w == old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        boolean fsSupported = isFullScreenSupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        if (fsSupported && old != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            // enter windowed mode (and restore original display mode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            exitFullScreenExclusive(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            setDisplayMode(origDisplayMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        super.setFullScreenWindow(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        if (fsSupported && w != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            // save original display mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            if (origDisplayMode == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                origDisplayMode = getDisplayMode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            // enter fullscreen mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            enterFullScreenExclusive(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    private DisplayMode getDefaultDisplayMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        GraphicsConfiguration gc = getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        Rectangle r = gc.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        return new DisplayMode(r.width, r.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                               DisplayMode.BIT_DEPTH_MULTI,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                               DisplayMode.REFRESH_RATE_UNKNOWN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    public synchronized DisplayMode getDisplayMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        if (isFullScreenSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            return getCurrentDisplayMode(screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            if (origDisplayMode == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                origDisplayMode = getDefaultDisplayMode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            return origDisplayMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    public synchronized DisplayMode[] getDisplayModes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        if (!isFullScreenSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            return super.getDisplayModes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        ArrayList<DisplayMode> modes = new ArrayList<DisplayMode>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        enumDisplayModes(screen, modes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        DisplayMode[] retArray = new DisplayMode[modes.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        return modes.toArray(retArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    public synchronized void setDisplayMode(DisplayMode dm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        if (!isDisplayChangeSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            super.setDisplayMode(dm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        Window w = getFullScreenWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        if (w == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            throw new IllegalStateException("Must be in fullscreen mode " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                                            "in order to set display mode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        }
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 438
diff changeset
   411
        if (getDisplayMode().equals(dm)) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 438
diff changeset
   412
            return;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 438
diff changeset
   413
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        if (dm == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            (dm = getMatchingDisplayMode(dm)) == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            throw new IllegalArgumentException("Invalid display mode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        if (!shutdownHookRegistered) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            // register a shutdown hook so that we return to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            // original DisplayMode when the VM exits (if the application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            // is already in the original DisplayMode at that time, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            // hook will have no effect)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            shutdownHookRegistered = true;
5275
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
   426
            PrivilegedAction<Void> a = new PrivilegedAction<Void>() {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
   427
                public Void run() {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
   428
                    ThreadGroup mainTG = Thread.currentThread().getThreadGroup();
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
   429
                    ThreadGroup parentTG = mainTG.getParent();
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
   430
                    while (parentTG != null) {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
   431
                        mainTG = parentTG;
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
   432
                        parentTG = mainTG.getParent();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    }
5275
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
   434
                    Runnable r = new Runnable() {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
   435
                            public void run() {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
   436
                                Window old = getFullScreenWindow();
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
   437
                                if (old != null) {
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
   438
                                    exitFullScreenExclusive(old);
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
   439
                                    setDisplayMode(origDisplayMode);
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
   440
                                }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
   441
                            }
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
   442
                        };
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
   443
                    Thread t = new Thread(mainTG, r,"Display-Change-Shutdown-Thread-"+screen);
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
   444
                    t.setContextClassLoader(null);
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
   445
                    Runtime.getRuntime().addShutdownHook(t);
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
   446
                    return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            };
5275
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 4285
diff changeset
   449
            AccessController.doPrivileged(a);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        // switch to the new DisplayMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        configDisplayMode(screen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                          dm.getWidth(), dm.getHeight(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                          dm.getRefreshRate());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        // update bounds of the fullscreen window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        w.setBounds(0, 0, dm.getWidth(), dm.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        // configDisplayMode() is synchronous, so the display change will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        // complete by the time we get here (and it is therefore safe to call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        // displayChanged() now)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        ((X11GraphicsEnvironment)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
         GraphicsEnvironment.getLocalGraphicsEnvironment()).displayChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    private synchronized DisplayMode getMatchingDisplayMode(DisplayMode dm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        if (!isDisplayChangeSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        DisplayMode[] modes = getDisplayModes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        for (DisplayMode mode : modes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            if (dm.equals(mode) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                (dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                 dm.getWidth() == mode.getWidth() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                 dm.getHeight() == mode.getHeight() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                 dm.getBitDepth() == mode.getBitDepth()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                return mode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * From the DisplayChangedListener interface; called from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * X11GraphicsEnvironment when the display mode has been changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    public synchronized void displayChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        // reset the list of configs (and default config)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        defaultConfig = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        configs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        doubleBufferVisuals = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        // reset the native data structures associated with this device (they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        // will be reinitialized when the GraphicsConfigs are configured)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        resetNativeData(screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        // pass on to all top-level windows on this screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        topLevels.notifyListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * From the DisplayChangedListener interface; devices do not need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * to react to this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    public void paletteChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * Add a DisplayChangeListener to be notified when the display settings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * are changed.  Typically, only top-level containers need to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * to X11GraphicsDevice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    public void addDisplayChangedListener(DisplayChangedListener client) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        topLevels.add(client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * Remove a DisplayChangeListener from this X11GraphicsDevice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    public void removeDisplayChangedListener(DisplayChangedListener client) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        topLevels.remove(client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        return ("X11GraphicsDevice[screen="+screen+"]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
}