Win32GraphicsDevice.java revision 0
0N/A * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. Sun designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/A * by Sun in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A * This is an implementation of a GraphicsDevice object for a single 0N/A * @see GraphicsEnvironment 0N/A * @see GraphicsConfiguration 0N/A // Note that we do not synchronize access to this variable - it doesn't 0N/A // really matter if a thread does an operation on graphics device which is 0N/A // about to become invalid (or already become) - we are prepared to deal 0N/A // with this on the native level. 0N/A // keep track of top-level windows on this display 0N/A // the original display mode we had before entering the fullscreen 0N/A // 4455041 - Even when ddraw is disabled, ddraw.dll is loaded when 0N/A // pixel format calls are made. This causes problems when a Java app 0N/A // is run as an NT service. To prevent the loading of ddraw.dll 0N/A // completely, sun.awt.nopixfmt should be set as well. Apps which use 0N/A // OpenGL w/ Java probably don't want to set this. 0N/A * Acceleration can be disabled due to capabilities of the display 0N/A * device discovered during ddraw initialization. This is not the 0N/A * same as isDDEnabledOnDevice(), which returns false when ddraw 0N/A * was disabled by the user or had problems initializing. 0N/A // we cache the strings because we want toString() and getIDstring 0N/A // to reflect the original screen number (which may change if the 0N/A // device is removed) 0N/A * Returns the type of the graphics device. 0N/A * @see #TYPE_RASTER_SCREEN 0N/A * @see #TYPE_PRINTER 0N/A * @see #TYPE_IMAGE_BUFFER 0N/A * Returns the Win32 screen of the device. 0N/A * Returns whether this is a valid devicie. Device can become 0N/A * invalid as a result of device removal event. 0N/A * Called from native code when the device was removed. 0N/A * @param defaultScreen the current default screen 0N/A * Returns the identification string associated with this graphics 0N/A * Returns all of the graphics 0N/A * configurations associated with this graphics device. 0N/A // Workaround for failing GDI calls, or if DirectDraw 0N/A for (
int i =
1; i <=
max; i++) {
0N/A * Returns the maximum number of graphics configurations available, or 1 0N/A * if PixelFormat calls fail or are disabled. 0N/A * This number is less than or equal to the number of graphics 0N/A * configurations supported. 0N/A * Returns whether or not the PixelFormat indicated by index is 0N/A * supported. Supported PixelFormats support drawing to a Window 0N/A * (PFD_DRAW_TO_WINDOW), support GDI (PFD_SUPPORT_GDI), and in the 0N/A * case of an 8-bit format (cColorBits <= 8) uses indexed colors 0N/A * (iPixelType == PFD_TYPE_COLORINDEX). 0N/A * We use the index 0 to indicate that PixelFormat calls don't work, or 0N/A * are disabled. Do not call this function with an index of 0. 0N/A * @param index a PixelFormat index 0N/A * Returns the PixelFormatID of the default graphics configuration 0N/A * associated with this graphics device, or 0 if PixelFormats calls fail or 0N/A * Returns the default PixelFormat ID from GDI. Do not call if PixelFormats 0N/A * Returns the default graphics configuration 0N/A * associated with this graphics device. 0N/A // first try to create a WGLGraphicsConfig if OGL is enabled 0N/A // REMIND: the WGL code does not yet work properly in multimon 0N/A // situations, so we will fallback on GDI if we are not on the 0N/A // default device... 0N/A // Fix for 4669614. Most apps are not concerned with PixelFormats, 0N/A // yet we ALWAYS used them for determining ColorModels and such. 0N/A // By passing in 0 as the PixelFormatID here, we signal that 0N/A // PixelFormats should not be used, thus avoid loading the opengl 0N/A // library. Apps concerned with PixelFormats can still use 0N/A // GraphicsConfiguration.getConfigurations(). 0N/A // Note that calling native pixel format functions tends to cause 0N/A // problems between those functions (which are OpenGL-related) 0N/A // and our use of DirectX. For example, some Matrox boards will 0N/A // crash or hang calling these functions when any app is running 0N/A // in DirectX fullscreen mode. So avoiding these calls unless 0N/A // absolutely necessary is preferable. 0N/A * Returns true if this is the default GraphicsDevice for the 0N/A * GraphicsEnvironment. 0N/A // The conditions under which we enable the D3D pipeline for the device: 0N/A // - d3d is not disabled via a flag 0N/A // - either d3d is forced via property or we're in fullscreen mode 0N/A * We support the exclusive fullscreen mode in both ddraw and 0N/A * noddraw modes, so we return true unless we're not allowed to use 0N/A * Return the owning Frame for a given Window. Used in setFSWindow below 0N/A * to set the properties of the owning Frame when a Window goes 0N/A * into fullscreen mode. 0N/A // Should not get here, but return something intelligent just in case 0N/A // Enter windowed mode. 0N/A // restore the original display mode 0N/A // we set the default display mode to null here 0N/A // because the default mode could change during 0N/A // the life of the application (user can change it through 0N/A // the desktop properties dialog, for example), so 0N/A // we need to record it every time prior to 0N/A // entering the fullscreen mode. 0N/A * Bug 4933099: There is some funny-business to deal with when this 0N/A * method is called with a Window instead of a Frame. See 4836744 0N/A * for more information on this. One side-effect of our workaround 0N/A * for the problem is that the owning Frame of a Window may end 0N/A * up getting resized during the fullscreen process. When we 0N/A * return from fullscreen mode, we should resize the Frame to 0N/A * its original size (just like the Window is being resized 0N/A * to its original size in GraphicsDevice). 0N/A // always record the default display mode prior to going 0N/A // These will get set for the native window in 0N/A // any case. Set them here so that resetting them 0N/A // later actually does the right thing 0N/A // Enter full screen exclusive mode. 0N/A // Note: removed replaceSurfaceData() call because 0N/A // changing the window size or making it visible 0N/A // will cause this anyway, and both of these events happen 0N/A // as part of switching into fullscreen mode. 0N/A // Entering and exiting full-screen mode are done within a 0N/A // tree-lock and should never lock on any resources which are 0N/A // required by other threads which may have them and may require 0N/A // resize the fullscreen window to the dimensions of the new 0N/A // Note: no call to replaceSurfaceData is required here since 0N/A // replacement will be caused by an upcoming display change event 0N/A "in order to set display mode");
0N/A // This function is only available if DirectDraw is enabled, otherwise we 0N/A // have to do the work the hard way (enumerating all of the display modes 0N/A // and checking each one) 0N/A // The function isDisplayModeAvailable is only available if 0N/A // DirectDraw is enabled, otherwise we have to do the work the 0N/A // hard way (enumerating all of the display modes 0N/A // and checking each one) 0N/A * From the DisplayChangeListener interface. 0N/A * Called from Win32GraphicsEnvironment when the display settings have 0N/A // pass on to all top-level windows on this display 0N/A * Part of the DisplayChangedListener interface: devices 0N/A * do not need to react to this event 0N/A * Add a DisplayChangeListener to be notified when the display settings 0N/A * are changed. Typically, only top-level containers need to be added 0N/A * to Win32GraphicsDevice. 0N/A * Remove a DisplayChangeListener from this Win32GraphicsDevice 0N/A * Creates and returns the color model associated with this device 0N/A * Returns a dynamic ColorModel which is updated when there 0N/A * are any changes (e.g., palette changes) in the device 0N/A * Returns the non-dynamic ColorModel associated with this device 0N/A * Returns number of bytes available in VRAM on this device. 0N/A // when OGL is enabled, there is no way to determine the amount 0N/A // of accelerated memory, so just return the default value