001: /*
002: * Copyright 2004-2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.java2d.opengl;
027:
028: import java.awt.Component;
029: import java.awt.GraphicsConfiguration;
030: import java.awt.ImageCapabilities;
031: import java.awt.Rectangle;
032: import java.awt.Transparency;
033: import java.awt.image.ColorModel;
034: import sun.awt.image.SunVolatileImage;
035: import sun.awt.image.VolatileSurfaceManager;
036: import sun.awt.windows.WComponentPeer;
037: import sun.java2d.SurfaceData;
038:
039: public class WGLVolatileSurfaceManager extends VolatileSurfaceManager {
040: private boolean accelerationEnabled;
041:
042: public WGLVolatileSurfaceManager(SunVolatileImage vImg,
043: Object context) {
044: super (vImg, context);
045:
046: /*
047: * We will attempt to accelerate this image only under the
048: * following conditions:
049: * - the image is opaque OR
050: * - the image is translucent AND
051: * - the GraphicsConfig supports the FBO extension OR
052: * - the GraphicsConfig has a stored alpha channel
053: */
054: int transparency = vImg.getTransparency();
055: WGLGraphicsConfig gc = (WGLGraphicsConfig) vImg
056: .getGraphicsConfig();
057: accelerationEnabled = (transparency == Transparency.OPAQUE)
058: || ((transparency == Transparency.TRANSLUCENT) && (gc
059: .isCapPresent(OGLContext.CAPS_EXT_FBOBJECT) || gc
060: .isCapPresent(OGLContext.CAPS_STORED_ALPHA)));
061: }
062:
063: protected boolean isAccelerationEnabled() {
064: return accelerationEnabled;
065: }
066:
067: /**
068: * Create a pbuffer-based SurfaceData object (or init the backbuffer
069: * of an existing window if this is a double buffered GraphicsConfig).
070: */
071: protected SurfaceData initAcceleratedSurface() {
072: SurfaceData sData;
073: Component comp = vImg.getComponent();
074: WComponentPeer peer = (comp != null) ? (WComponentPeer) comp
075: .getPeer() : null;
076:
077: try {
078: boolean forceback = false;
079: if (context instanceof Boolean) {
080: forceback = ((Boolean) context).booleanValue();
081: }
082:
083: if (forceback) {
084: // peer must be non-null in this case
085: sData = WGLSurfaceData.createData(peer, vImg);
086: } else {
087: WGLGraphicsConfig gc = (WGLGraphicsConfig) vImg
088: .getGraphicsConfig();
089: ColorModel cm = gc
090: .getColorModel(vImg.getTransparency());
091: int type = gc
092: .isCapPresent(OGLContext.CAPS_EXT_FBOBJECT) ? OGLSurfaceData.FBOBJECT
093: : OGLSurfaceData.PBUFFER;
094: sData = WGLSurfaceData.createData(gc, vImg.getWidth(),
095: vImg.getHeight(), cm, vImg, type);
096: }
097: } catch (NullPointerException ex) {
098: sData = null;
099: } catch (OutOfMemoryError er) {
100: sData = null;
101: }
102:
103: return sData;
104: }
105:
106: protected boolean isConfigValid(GraphicsConfiguration gc) {
107: return ((gc == null) || (gc == vImg.getGraphicsConfig()));
108: }
109: }
|