jdk/src/share/classes/java/awt/GraphicsDevice.java
author tdv
Fri, 18 Jul 2008 10:48:44 -0700
changeset 887 0aab8d3fa11a
parent 2 90ce3da70b43
child 888 c7009cf0001f
permissions -rw-r--r--
6725214: D3D: forward-port the new pipeline from 6u10 Summary: Forward port of the new Direct3D 9 rendering pipeline from 6u10. Also includes fixes for 6690659 6689025 6658398 6596234. Reviewed-by: campbell, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
     2
 * Copyright 1997-2008 Sun Microsystems 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.image.ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.awt.AppContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * The <code>GraphicsDevice</code> class describes the graphics devices
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * that might be available in a particular graphics environment.  These
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * include screen and printer devices. Note that there can be many screens
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * and many printers in an instance of {@link GraphicsEnvironment}. Each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * graphics device has one or more {@link GraphicsConfiguration} objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * associated with it.  These objects specify the different configurations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * in which the <code>GraphicsDevice</code> can be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * In a multi-screen environment, the <code>GraphicsConfiguration</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * objects can be used to render components on multiple screens.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * following code sample demonstrates how to create a <code>JFrame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * object for each <code>GraphicsConfiguration</code> on each screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * device in the <code>GraphicsEnvironment</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *   GraphicsEnvironment ge = GraphicsEnvironment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *   getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *   GraphicsDevice[] gs = ge.getScreenDevices();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *   for (int j = 0; j < gs.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *      GraphicsDevice gd = gs[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *      GraphicsConfiguration[] gc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *      gd.getConfigurations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *      for (int i=0; i < gc.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *         JFrame f = new
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *         JFrame(gs[j].getDefaultConfiguration());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *         Canvas c = new Canvas(gc[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *         Rectangle gcBounds = gc[i].getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *         int xoffs = gcBounds.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *         int yoffs = gcBounds.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *         f.getContentPane().add(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *         f.setLocation((i*50)+xoffs, (i*60)+yoffs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *         f.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * For more information on full-screen exclusive mode API, see the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * <a href="http://java.sun.com/docs/books/tutorial/extra/fullscreen/index.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * Full-Screen Exclusive Mode API Tutorial</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * @see GraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * @see GraphicsConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
public abstract class GraphicsDevice {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private Window fullScreenWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private AppContext fullScreenAppContext; // tracks which AppContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                                             // created the FS window
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    // this lock is used for making synchronous changes to the AppContext's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    // current full screen window
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private final Object fsAppContextLock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private Rectangle windowedModeBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * This is an abstract class that cannot be instantiated directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * Instances must be obtained from a suitable factory or query method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @see GraphicsEnvironment#getScreenDevices
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @see GraphicsEnvironment#getDefaultScreenDevice
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @see GraphicsConfiguration#getDevice
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    protected GraphicsDevice() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Device is a raster screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public final static int TYPE_RASTER_SCREEN          = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Device is a printer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public final static int TYPE_PRINTER                = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Device is an image buffer.  This buffer can reside in device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * or system memory but it is not physically viewable by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public final static int TYPE_IMAGE_BUFFER           = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Returns the type of this <code>GraphicsDevice</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @return the type of this <code>GraphicsDevice</code>, which can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * either be TYPE_RASTER_SCREEN, TYPE_PRINTER or TYPE_IMAGE_BUFFER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @see #TYPE_RASTER_SCREEN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @see #TYPE_PRINTER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @see #TYPE_IMAGE_BUFFER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public abstract int getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * Returns the identification string associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <code>GraphicsDevice</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * A particular program might use more than one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * <code>GraphicsDevice</code> in a <code>GraphicsEnvironment</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * This method returns a <code>String</code> identifying a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * particular <code>GraphicsDevice</code> in the local
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * <code>GraphicsEnvironment</code>.  Although there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * no public method to set this <code>String</code>, a programmer can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * use the <code>String</code> for debugging purposes.  Vendors of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * the Java<sup><font size=-2>TM</font></sup> Runtime Environment can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * format the return value of the <code>String</code>.  To determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * how to interpret the value of the <code>String</code>, contact the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * vendor of your Java Runtime.  To find out who the vendor is, from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * your program, call the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * {@link System#getProperty(String) getProperty} method of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * System class with "java.vendor".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @return a <code>String</code> that is the identification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * of this <code>GraphicsDevice</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public abstract String getIDstring();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * Returns all of the <code>GraphicsConfiguration</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * objects associated with this <code>GraphicsDevice</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @return an array of <code>GraphicsConfiguration</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * objects that are associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * <code>GraphicsDevice</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public abstract GraphicsConfiguration[] getConfigurations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Returns the default <code>GraphicsConfiguration</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * associated with this <code>GraphicsDevice</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @return the default <code>GraphicsConfiguration</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * of this <code>GraphicsDevice</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public abstract GraphicsConfiguration getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Returns the "best" configuration possible that passes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * criteria defined in the {@link GraphicsConfigTemplate}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @param gct the <code>GraphicsConfigTemplate</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * used to obtain a valid <code>GraphicsConfiguration</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @return a <code>GraphicsConfiguration</code> that passes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * the criteria defined in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * <code>GraphicsConfigTemplate</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @see GraphicsConfigTemplate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public GraphicsConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
           getBestConfiguration(GraphicsConfigTemplate gct) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        GraphicsConfiguration[] configs = getConfigurations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return gct.getBestConfiguration(configs);
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
     * Returns <code>true</code> if this <code>GraphicsDevice</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * supports full-screen exclusive mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * If a SecurityManager is installed, its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * <code>checkPermission</code> method will be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * with <code>AWTPermission("fullScreenExclusive")</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * <code>isFullScreenSupported</code> returns true only if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * that permission is granted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @return whether full-screen exclusive mode is available for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * this graphics device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @see java.awt.AWTPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public boolean isFullScreenSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return false;
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
     * Enter full-screen mode, or return to windowed mode.  The entered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * full-screen mode may be either exclusive or simulated.  Exclusive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * mode is only available if <code>isFullScreenSupported</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * returns <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * Exclusive mode implies:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * <li>Windows cannot overlap the full-screen window.  All other application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * windows will always appear beneath the full-screen window in the Z-order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * <li>There can be only one full-screen window on a device at any time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * so calling this method while there is an existing full-screen Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * will cause the existing full-screen window to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * return to windowed mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * <li>Input method windows are disabled.  It is advisable to call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * <code>Component.enableInputMethods(false)</code> to make a component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * a non-client of the input method framework.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Simulated full-screen mode resizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * the window to the size of the screen and positions it at (0,0).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * When entering full-screen mode, if the window to be used as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * full-screen window is not visible, this method will make it visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * It will remain visible when returning to windowed mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * When returning to windowed mode from an exclusive full-screen window, any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * display changes made by calling <code>setDisplayMode</code> are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * automatically restored to their original state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @param w a window to use as the full-screen window; <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * if returning to windowed mode.  Some platforms expect the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * fullscreen window to be a top-level component (i.e., a Frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * therefore it is preferable to use a Frame here rather than a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @see #isFullScreenSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @see #getFullScreenWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @see #setDisplayMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @see Component#enableInputMethods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @see Component#setVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public void setFullScreenWindow(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if (fullScreenWindow != null && windowedModeBounds != null) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   239
            // if the window went into fs mode before it was realized it may
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   240
            // have (0,0) dimensions
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   241
            if (windowedModeBounds.width  == 0) windowedModeBounds.width  = 1;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   242
            if (windowedModeBounds.height == 0) windowedModeBounds.height = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            fullScreenWindow.setBounds(windowedModeBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        // Set the full screen window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        synchronized (fsAppContextLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            // Associate fullscreen window with current AppContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            if (w == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                fullScreenAppContext = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                fullScreenAppContext = AppContext.getAppContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            fullScreenWindow = w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        if (fullScreenWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            windowedModeBounds = fullScreenWindow.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            // Note that we use the graphics configuration of the device,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            // not the window's, because we're setting the fs window for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            // this device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            Rectangle screenBounds = getDefaultConfiguration().getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            fullScreenWindow.setBounds(screenBounds.x, screenBounds.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                                       screenBounds.width, screenBounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            fullScreenWindow.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            fullScreenWindow.toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Returns the <code>Window</code> object representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * full-screen window if the device is in full-screen mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @return the full-screen window, or <code>null</code> if the device is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * not in full-screen mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @see #setFullScreenWindow(Window)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public Window getFullScreenWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        Window returnWindow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        synchronized (fsAppContextLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            // Only return a handle to the current fs window if we are in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            // same AppContext that set the fs window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            if (fullScreenAppContext == AppContext.getAppContext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                returnWindow = fullScreenWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        return returnWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * Returns <code>true</code> if this <code>GraphicsDevice</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * supports low-level display changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * On some platforms low-level display changes may only be allowed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * full-screen exclusive mode (i.e., if {@link #isFullScreenSupported()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * returns {@code true} and the application has already entered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * full-screen mode using {@link #setFullScreenWindow}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * @return whether low-level display changes are supported for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * graphics device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @see #isFullScreenSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @see #setDisplayMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @see #setFullScreenWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    public boolean isDisplayChangeSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * Sets the display mode of this graphics device. This is only allowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * if {@link #isDisplayChangeSupported()} returns {@code true} and may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * require first entering full-screen exclusive mode using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * {@link #setFullScreenWindow} providing that full-screen exclusive mode is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * supported (i.e., {@link #isFullScreenSupported()} returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * {@code true}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * The display mode must be one of the display modes returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * {@link #getDisplayModes()}, with one exception: passing a display mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * with {@link DisplayMode#REFRESH_RATE_UNKNOWN} refresh rate will result in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * selecting a display mode from the list of available display modes with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * matching width, height and bit depth.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * However, passing a display mode with {@link DisplayMode#BIT_DEPTH_MULTI}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * for bit depth is only allowed if such mode exists in the list returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * {@link #getDisplayModes()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * Example code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * <pre><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * Frame frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * DisplayMode newDisplayMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * GraphicsDevice gd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * // create a Frame, select desired DisplayMode from the list of modes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * // returned by gd.getDisplayModes() ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * if (gd.isFullScreenSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *     gd.setFullScreenWindow(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *    // proceed in non-full-screen mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *    frame.setSize(...);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *    frame.setLocation(...);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *    frame.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * if (gd.isDisplayChangeSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *     gd.setDisplayMode(newDisplayMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * </code></pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @param dm The new display mode of this graphics device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * @exception IllegalArgumentException if the <code>DisplayMode</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * supplied is <code>null</code>, or is not available in the array returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * by <code>getDisplayModes</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @exception UnsupportedOperationException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * <code>isDisplayChangeSupported</code> returns <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @see #getDisplayMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @see #getDisplayModes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @see #isDisplayChangeSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public void setDisplayMode(DisplayMode dm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        throw new UnsupportedOperationException("Cannot change display mode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * Returns the current display mode of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * <code>GraphicsDevice</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * The returned display mode is allowed to have a refresh rate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * {@link DisplayMode#REFRESH_RATE_UNKNOWN} if it is indeterminate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * Likewise, the returned display mode is allowed to have a bit depth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * {@link DisplayMode#BIT_DEPTH_MULTI} if it is indeterminate or if multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * bit depths are supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @return the current display mode of this graphics device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @see #setDisplayMode(DisplayMode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    public DisplayMode getDisplayMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        GraphicsConfiguration gc = getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        Rectangle r = gc.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        ColorModel cm = gc.getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        return new DisplayMode(r.width, r.height, cm.getPixelSize(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * Returns all display modes available for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * <code>GraphicsDevice</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * The returned display modes are allowed to have a refresh rate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * {@link DisplayMode#REFRESH_RATE_UNKNOWN} if it is indeterminate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * Likewise, the returned display modes are allowed to have a bit depth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * {@link DisplayMode#BIT_DEPTH_MULTI} if it is indeterminate or if multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * bit depths are supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * @return all of the display modes available for this graphics device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    public DisplayMode[] getDisplayModes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        return new DisplayMode[] { getDisplayMode() };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * This method returns the number of bytes available in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * accelerated memory on this device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * Some images are created or cached
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * in accelerated memory on a first-come,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * first-served basis.  On some operating systems,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * this memory is a finite resource.  Calling this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * and scheduling the creation and flushing of images carefully may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * enable applications to make the most efficient use of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * that finite resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * Note that the number returned is a snapshot of how much
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * memory is available; some images may still have problems
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * being allocated into that memory.  For example, depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * on operating system, driver, memory configuration, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * thread situations, the full extent of the size reported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * may not be available for a given image.  There are further
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * inquiry methods on the {@link ImageCapabilities} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * associated with a VolatileImage that can be used to determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * whether a particular VolatileImage has been created in accelerated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @return number of bytes available in accelerated memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * A negative return value indicates that the amount of accelerated memory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * on this GraphicsDevice is indeterminate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @see java.awt.image.VolatileImage#flush
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @see ImageCapabilities#isAccelerated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    public int getAvailableAcceleratedMemory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
}