jdk/src/windows/classes/sun/awt/Win32GraphicsDevice.java
author anthony
Fri, 20 Feb 2009 17:34:16 +0300
changeset 2459 08f3416ff334
parent 888 c7009cf0001f
child 4256 24d614d4764a
child 4204 d8eff41661bf
permissions -rw-r--r--
6804747: Ensure consistent graphicsConfig member across components hierarchy Reviewed-by: art, dcherepanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
888
c7009cf0001f 6728492: typo in copyrights in some files touched by the d3d pipeline port
tdv
parents: 887
diff changeset
     2
 * Copyright 1997-2008 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.GraphicsDevice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.GraphicsConfiguration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.DisplayMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Window;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    36
import java.awt.event.WindowAdapter;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    37
import java.awt.event.WindowEvent;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    38
import java.awt.event.WindowListener;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.image.ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.peer.WindowPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.awt.windows.WWindowPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import sun.java2d.opengl.WGLGraphicsConfig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.java2d.windows.WindowsFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * This is an implementation of a GraphicsDevice object for a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Win32 screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @see GraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @see GraphicsConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
public class Win32GraphicsDevice extends GraphicsDevice implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 DisplayChangedListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    int screen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    ColorModel dynamicColorModel;   // updated with dev changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    ColorModel colorModel;          // static for device
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    59
    protected GraphicsConfiguration[] configs;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    60
    protected GraphicsConfiguration defaultConfig;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private final String idString;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    63
    protected String descString;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // Note that we do not synchronize access to this variable - it doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    // really matter if a thread does an operation on graphics device which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    // about to become invalid (or already become) - we are prepared to deal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // with this on the native level.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private boolean valid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    // keep track of top-level windows on this display
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private SunDisplayChanger topLevels = new SunDisplayChanger();
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    72
    // REMIND: we may disable the use of pixel formats for some accelerated
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    73
    // pipelines which are mutually exclusive with opengl, for which
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    74
    // pixel formats were added in the first place
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    75
    protected static boolean pfDisabled;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private static AWTPermission fullScreenExclusivePermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    // the original display mode we had before entering the fullscreen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    // mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private DisplayMode defaultDisplayMode;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    80
    // activation/deactivation listener for the full-screen window
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    81
    private WindowListener fsWindowListener;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        // 4455041 - Even when ddraw is disabled, ddraw.dll is loaded when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        // pixel format calls are made.  This causes problems when a Java app
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        // is run as an NT service.  To prevent the loading of ddraw.dll
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        // completely, sun.awt.nopixfmt should be set as well.  Apps which use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        // OpenGL w/ Java probably don't want to set this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        String nopixfmt = (String)java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            new sun.security.action.GetPropertyAction("sun.awt.nopixfmt"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        pfDisabled = (nopixfmt != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    native void initDevice(int screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public Win32GraphicsDevice(int screennum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        this.screen = screennum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        // we cache the strings because we want toString() and getIDstring
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        // to reflect the original screen number (which may change if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        // device is removed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        idString = "\\Display"+screen;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   106
        // REMIND: may be should use class name?
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        descString = "Win32GraphicsDevice[screen=" + screen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        valid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        initDevice(screennum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Returns the type of the graphics device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @see #TYPE_RASTER_SCREEN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @see #TYPE_PRINTER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @see #TYPE_IMAGE_BUFFER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public int getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return TYPE_RASTER_SCREEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Returns the Win32 screen of the device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public int getScreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        return screen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
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 whether this is a valid devicie. Device can become
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * invalid as a result of device removal event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   134
    public boolean isValid() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        return valid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Called from native code when the device was removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @param defaultScreen the current default screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   143
    protected void invalidate(int defaultScreen) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        valid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        screen = defaultScreen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Returns the identification string associated with this graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public String getIDstring() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        return idString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * Returns all of the graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * configurations associated with this graphics device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public GraphicsConfiguration[] getConfigurations() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        if (configs==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            if (WindowsFlags.isOGLEnabled() && isDefaultDevice()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                defaultConfig = getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                if (defaultConfig != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    configs = new GraphicsConfiguration[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                    configs[0] = defaultConfig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    return configs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            int max = getMaxConfigs(screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            int defaultPixID = getDefaultPixID(screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            Vector v = new Vector( max );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            if (defaultPixID == 0) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   176
                // Workaround for failing GDI calls
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                defaultConfig = Win32GraphicsConfig.getConfig(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                                                              defaultPixID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                v.addElement(defaultConfig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                for (int i = 1; i <= max; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    if (isPixFmtSupported(i, screen)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                        if (i == defaultPixID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                            defaultConfig = Win32GraphicsConfig.getConfig(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                             this, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                            v.addElement(defaultConfig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                            v.addElement(Win32GraphicsConfig.getConfig(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                             this, i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            configs = new GraphicsConfiguration[v.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            v.copyInto(configs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        return configs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * Returns the maximum number of graphics configurations available, or 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * if PixelFormat calls fail or are disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * This number is less than or equal to the number of graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * configurations supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    protected int getMaxConfigs(int screen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        if (pfDisabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            return getMaxConfigsImpl(screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    private native int getMaxConfigsImpl(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 whether or not the PixelFormat indicated by index is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * supported.  Supported PixelFormats support drawing to a Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * (PFD_DRAW_TO_WINDOW), support GDI (PFD_SUPPORT_GDI), and in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * case of an 8-bit format (cColorBits <= 8) uses indexed colors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * (iPixelType == PFD_TYPE_COLORINDEX).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * We use the index 0 to indicate that PixelFormat calls don't work, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * are disabled.  Do not call this function with an index of 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @param index a PixelFormat index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    protected native boolean isPixFmtSupported(int index, int screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Returns the PixelFormatID of the default graphics configuration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * associated with this graphics device, or 0 if PixelFormats calls fail or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * are disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    protected int getDefaultPixID(int screen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        if (pfDisabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            return getDefaultPixIDImpl(screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * Returns the default PixelFormat ID from GDI.  Do not call if PixelFormats
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * are disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    private native int getDefaultPixIDImpl(int screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Returns the default graphics configuration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * associated with this graphics device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public GraphicsConfiguration getDefaultConfiguration() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        if (defaultConfig == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            // first try to create a WGLGraphicsConfig if OGL is enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            // REMIND: the WGL code does not yet work properly in multimon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            // situations, so we will fallback on GDI if we are not on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            // default device...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            if (WindowsFlags.isOGLEnabled() && isDefaultDevice()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                int defPixID = WGLGraphicsConfig.getDefaultPixFmt(screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                defaultConfig = WGLGraphicsConfig.getConfig(this, defPixID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                if (WindowsFlags.isOGLVerbose()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                    if (defaultConfig != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                        System.out.print("OpenGL pipeline enabled");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                        System.out.print("Could not enable OpenGL pipeline");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    System.out.println(" for default config on screen " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                                       screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            // Fix for 4669614.  Most apps are not concerned with PixelFormats,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            // yet we ALWAYS used them for determining ColorModels and such.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            // By passing in 0 as the PixelFormatID here, we signal that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            // PixelFormats should not be used, thus avoid loading the opengl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            // library.  Apps concerned with PixelFormats can still use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            // GraphicsConfiguration.getConfigurations().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            // Note that calling native pixel format functions tends to cause
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            // problems between those functions (which are OpenGL-related)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            // and our use of DirectX.  For example, some Matrox boards will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            // crash or hang calling these functions when any app is running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            // in DirectX fullscreen mode.  So avoiding these calls unless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            // absolutely necessary is preferable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            if (defaultConfig == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                defaultConfig = Win32GraphicsConfig.getConfig(this, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return defaultConfig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return valid ? descString + "]" : descString + ", removed]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * Returns true if this is the default GraphicsDevice for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * GraphicsEnvironment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    private boolean isDefaultDevice() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        return (this ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                GraphicsEnvironment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                    getLocalGraphicsEnvironment().getDefaultScreenDevice());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    private static boolean isFSExclusiveModeAllowed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            if (fullScreenExclusivePermission == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                fullScreenExclusivePermission =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                    new AWTPermission("fullScreenExclusive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                security.checkPermission(fullScreenExclusivePermission);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            } catch (SecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   323
     * returns true unless we're not allowed to use fullscreen mode.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   325
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public boolean isFullScreenSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        return isFSExclusiveModeAllowed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   330
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    public synchronized void setFullScreenWindow(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        Window old = getFullScreenWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        if (w == old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        if (!isFullScreenSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            super.setFullScreenWindow(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        // Enter windowed mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        if (old != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            // restore the original display mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            if (defaultDisplayMode != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                setDisplayMode(defaultDisplayMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                // we set the default display mode to null here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                // because the default mode could change during
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                // the life of the application (user can change it through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                // the desktop properties dialog, for example), so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                // we need to record it every time prior to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                // entering the fullscreen mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                defaultDisplayMode = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            WWindowPeer peer = (WWindowPeer)old.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            if (peer != null) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   356
                // we used to destroy the buffers on exiting fs mode, this
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   357
                // is no longer needed since fs change will cause a surface
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   358
                // data replacement
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                synchronized(peer) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   360
                    exitFullScreenExclusive(screen, peer);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            }
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   363
            removeFSWindowListener(old);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        super.setFullScreenWindow(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        if (w != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            // always record the default display mode prior to going
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            // fullscreen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            defaultDisplayMode = getDisplayMode();
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   370
            addFSWindowListener(w);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            // Enter full screen exclusive mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            WWindowPeer peer = (WWindowPeer)w.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            synchronized(peer) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   374
                enterFullScreenExclusive(screen, peer);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                // Note: removed replaceSurfaceData() call because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                // changing the window size or making it visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                // will cause this anyway, and both of these events happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                // as part of switching into fullscreen mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            // fix for 4868278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            peer.updateGC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    // Entering and exiting full-screen mode are done within a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    // tree-lock and should never lock on any resources which are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    // required by other threads which may have them and may require
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    // the tree-lock.
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   390
    // REMIND: in the future these methods may need to become protected so that
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   391
    // subclasses could override them and use appropriate api other than GDI
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   392
    // for implementing these functions.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   393
    protected native void enterFullScreenExclusive(int screen, WindowPeer w);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   394
    protected native void exitFullScreenExclusive(int screen, WindowPeer w);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   396
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    public boolean isDisplayChangeSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        return (isFullScreenSupported() && getFullScreenWindow() != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   401
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    public synchronized void setDisplayMode(DisplayMode dm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        if (!isDisplayChangeSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            super.setDisplayMode(dm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        if (dm == null || (dm = getMatchingDisplayMode(dm)) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            throw new IllegalArgumentException("Invalid display mode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        if (getDisplayMode().equals(dm)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        Window w = getFullScreenWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        if (w != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            WWindowPeer peer = (WWindowPeer)w.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            configDisplayMode(screen, peer, dm.getWidth(), dm.getHeight(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                dm.getBitDepth(), dm.getRefreshRate());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            // resize the fullscreen window to the dimensions of the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            // display mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            Rectangle screenBounds = getDefaultConfiguration().getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            w.setBounds(screenBounds.x, screenBounds.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                        dm.getWidth(), dm.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            // Note: no call to replaceSurfaceData is required here since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            // replacement will be caused by an upcoming display change event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            throw new IllegalStateException("Must be in fullscreen mode " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                                            "in order to set display mode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   431
    protected native DisplayMode getCurrentDisplayMode(int screen);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   432
    protected native void configDisplayMode(int screen, WindowPeer w, int width,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                                          int height, int bitDepth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                                          int refreshRate);
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   435
    protected native void enumDisplayModes(int screen, ArrayList modes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   437
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    public synchronized DisplayMode getDisplayMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        DisplayMode res = getCurrentDisplayMode(screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   443
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    public synchronized DisplayMode[] getDisplayModes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        ArrayList modes = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        enumDisplayModes(screen, modes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        int listSize = modes.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        DisplayMode[] retArray = new DisplayMode[listSize];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        for (int i = 0; i < listSize; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            retArray[i] = (DisplayMode)modes.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        return retArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   455
    protected synchronized DisplayMode getMatchingDisplayMode(DisplayMode dm) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        if (!isDisplayChangeSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   459
        DisplayMode[] modes = getDisplayModes();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   460
        for (DisplayMode mode : modes) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   461
            if (dm.equals(mode) ||
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   462
                (dm.getRefreshRate() == DisplayMode.REFRESH_RATE_UNKNOWN &&
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   463
                 dm.getWidth() == mode.getWidth() &&
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   464
                 dm.getHeight() == mode.getHeight() &&
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   465
                 dm.getBitDepth() == mode.getBitDepth()))
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   466
            {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   467
                return mode;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        }
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   470
        return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * From the DisplayChangeListener interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * Called from Win32GraphicsEnvironment when the display settings have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    public void displayChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        dynamicColorModel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        defaultConfig = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        configs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        // pass on to all top-level windows on this display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        topLevels.notifyListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * Part of the DisplayChangedListener interface: devices
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * do not need to react to this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    public void paletteChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * Add a DisplayChangeListener to be notified when the display settings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * are changed.  Typically, only top-level containers need to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * to Win32GraphicsDevice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    public void addDisplayChangedListener(DisplayChangedListener client) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        topLevels.add(client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * Remove a DisplayChangeListener from this Win32GraphicsDevice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     public void removeDisplayChangedListener(DisplayChangedListener client) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        topLevels.remove(client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * Creates and returns the color model associated with this device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    private native ColorModel makeColorModel (int screen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                                              boolean dynamic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * Returns a dynamic ColorModel which is updated when there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * are any changes (e.g., palette changes) in the device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    public ColorModel getDynamicColorModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        if (dynamicColorModel == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            dynamicColorModel = makeColorModel(screen, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        return dynamicColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * Returns the non-dynamic ColorModel associated with this device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    public ColorModel getColorModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        if (colorModel == null)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            colorModel = makeColorModel(screen, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        return colorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   536
    /**
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   537
     * WindowAdapter class responsible for de/iconifying full-screen window
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   538
     * of this device.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   539
     *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   540
     * The listener restores the default display mode when window is iconified
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   541
     * and sets it back to the one set by the user on de-iconification.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   542
     */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   543
    private static class Win32FSWindowAdapter extends WindowAdapter {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   544
        private Win32GraphicsDevice device;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   545
        private DisplayMode dm;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   546
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   547
        Win32FSWindowAdapter(Win32GraphicsDevice device) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   548
            this.device = device;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   549
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   550
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   551
        private void setFSWindowsState(Window other, int state) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   552
            GraphicsDevice gds[] =
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   553
                    GraphicsEnvironment.getLocalGraphicsEnvironment().
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   554
                    getScreenDevices();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   555
            // check if the de/activation was caused by other
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   556
            // fs window and ignore the event if that's the case
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   557
            if (other != null) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   558
                for (GraphicsDevice gd : gds) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   559
                    if (other == gd.getFullScreenWindow()) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   560
                        return;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   561
                    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   562
                }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   563
            }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   564
            // otherwise apply state to all fullscreen windows
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   565
            for (GraphicsDevice gd : gds) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   566
                Window fsw = gd.getFullScreenWindow();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   567
                if (fsw instanceof Frame) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   568
                    ((Frame)fsw).setExtendedState(state);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   569
                }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   570
            }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   571
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   572
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   573
        @Override
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   574
        public void windowDeactivated(WindowEvent e) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   575
            setFSWindowsState(e.getOppositeWindow(), Frame.ICONIFIED);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   576
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   577
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   578
        @Override
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   579
        public void windowActivated(WindowEvent e) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   580
            setFSWindowsState(e.getOppositeWindow(), Frame.NORMAL);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   581
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   582
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   583
        @Override
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   584
        public void windowIconified(WindowEvent e) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   585
            // restore the default display mode for this device
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   586
            DisplayMode ddm = device.defaultDisplayMode;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   587
            if (ddm != null) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   588
                dm = device.getDisplayMode();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   589
                device.setDisplayMode(ddm);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   590
            }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   591
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   592
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   593
        @Override
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   594
        public void windowDeiconified(WindowEvent e) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   595
            // restore the user-set display mode for this device
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   596
            if (dm != null) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   597
                device.setDisplayMode(dm);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   598
                dm = null;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   599
            }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   600
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   601
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    /**
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   604
     * Adds a WindowListener to be used as
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   605
     * activation/deactivation listener for the current full-screen window.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   606
     *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   607
     * @param w full-screen window
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     */
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   609
    protected void addFSWindowListener(Window w) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   610
        // Note: even though we create a listener for Window instances of
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   611
        // fs windows they will not receive window events.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   612
        fsWindowListener = new Win32FSWindowAdapter(this);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   613
        w.addWindowListener(fsWindowListener);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   614
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   615
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   616
    /**
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   617
     * Removes the fs window listener.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   618
     *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   619
     * @param w full-screen window
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   620
     */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   621
    protected void removeFSWindowListener(Window w) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   622
        w.removeWindowListener(fsWindowListener);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   623
        fsWindowListener = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
}