001: /*
002: * Copyright 2003-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.X11ComponentPeer;
035: import sun.awt.image.SunVolatileImage;
036: import sun.awt.image.VolatileSurfaceManager;
037: import sun.java2d.SurfaceData;
038:
039: public class GLXVolatileSurfaceManager extends VolatileSurfaceManager {
040:
041: private boolean accelerationEnabled;
042:
043: public GLXVolatileSurfaceManager(SunVolatileImage vImg,
044: Object context) {
045: super (vImg, context);
046:
047: /*
048: * We will attempt to accelerate this image only under the
049: * following conditions:
050: * - the image is opaque OR
051: * - the image is translucent AND
052: * - the GraphicsConfig supports the FBO extension OR
053: * - the GraphicsConfig has a stored alpha channel
054: */
055: int transparency = vImg.getTransparency();
056: GLXGraphicsConfig gc = (GLXGraphicsConfig) vImg
057: .getGraphicsConfig();
058: accelerationEnabled = (transparency == Transparency.OPAQUE)
059: || ((transparency == Transparency.TRANSLUCENT) && (gc
060: .isCapPresent(OGLContext.CAPS_EXT_FBOBJECT) || gc
061: .isCapPresent(OGLContext.CAPS_STORED_ALPHA)));
062: }
063:
064: protected boolean isAccelerationEnabled() {
065: return accelerationEnabled;
066: }
067:
068: /**
069: * Create a pbuffer-based SurfaceData object (or init the backbuffer
070: * of an existing window if this is a double buffered GraphicsConfig)
071: */
072: protected SurfaceData initAcceleratedSurface() {
073: SurfaceData sData;
074: Component comp = vImg.getComponent();
075: X11ComponentPeer peer = (comp != null) ? (X11ComponentPeer) comp
076: .getPeer()
077: : null;
078:
079: try {
080: boolean forceback = false;
081: if (context instanceof Boolean) {
082: forceback = ((Boolean) context).booleanValue();
083: }
084:
085: if (forceback) {
086: // peer must be non-null in this case
087: sData = GLXSurfaceData.createData(peer, vImg);
088: } else {
089: GLXGraphicsConfig gc = (GLXGraphicsConfig) vImg
090: .getGraphicsConfig();
091: ColorModel cm = gc
092: .getColorModel(vImg.getTransparency());
093: int type = gc
094: .isCapPresent(OGLContext.CAPS_EXT_FBOBJECT) ? OGLSurfaceData.FBOBJECT
095: : OGLSurfaceData.PBUFFER;
096: sData = GLXSurfaceData.createData(gc, vImg.getWidth(),
097: vImg.getHeight(), cm, vImg, type);
098: }
099: } catch (NullPointerException ex) {
100: sData = null;
101: } catch (OutOfMemoryError er) {
102: sData = null;
103: }
104:
105: return sData;
106: }
107:
108: protected boolean isConfigValid(GraphicsConfiguration gc) {
109: return ((gc == null) || (gc == vImg.getGraphicsConfig()));
110: }
111: }
|