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