J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2004-2005 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package sun.java2d.opengl; |
| 27 | |
| 28 | import java.awt.Component; |
| 29 | import java.awt.GraphicsConfiguration; |
| 30 | import java.awt.ImageCapabilities; |
| 31 | import java.awt.Rectangle; |
| 32 | import java.awt.Transparency; |
| 33 | import java.awt.image.ColorModel; |
| 34 | import sun.awt.image.SunVolatileImage; |
| 35 | import sun.awt.image.VolatileSurfaceManager; |
| 36 | import sun.awt.windows.WComponentPeer; |
| 37 | import sun.java2d.SurfaceData; |
| 38 | |
| 39 | public class WGLVolatileSurfaceManager |
| 40 | extends VolatileSurfaceManager |
| 41 | { |
| 42 | private boolean accelerationEnabled; |
| 43 | |
| 44 | public WGLVolatileSurfaceManager(SunVolatileImage vImg, Object context) { |
| 45 | super(vImg, context); |
| 46 | |
| 47 | /* |
| 48 | * We will attempt to accelerate this image only under the |
| 49 | * following conditions: |
| 50 | * - the image is opaque OR |
| 51 | * - the image is translucent AND |
| 52 | * - the GraphicsConfig supports the FBO extension OR |
| 53 | * - the GraphicsConfig has a stored alpha channel |
| 54 | */ |
| 55 | int transparency = vImg.getTransparency(); |
| 56 | WGLGraphicsConfig gc = (WGLGraphicsConfig)vImg.getGraphicsConfig(); |
| 57 | accelerationEnabled = |
| 58 | (transparency == Transparency.OPAQUE) || |
| 59 | ((transparency == Transparency.TRANSLUCENT) && |
| 60 | (gc.isCapPresent(OGLContext.CAPS_EXT_FBOBJECT) || |
| 61 | gc.isCapPresent(OGLContext.CAPS_STORED_ALPHA))); |
| 62 | } |
| 63 | |
| 64 | protected boolean isAccelerationEnabled() { |
| 65 | return accelerationEnabled; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Create a pbuffer-based SurfaceData object (or init the backbuffer |
| 70 | * of an existing window if this is a double buffered GraphicsConfig). |
| 71 | */ |
| 72 | protected SurfaceData initAcceleratedSurface() { |
| 73 | SurfaceData sData; |
| 74 | Component comp = vImg.getComponent(); |
| 75 | WComponentPeer peer = |
| 76 | (comp != null) ? (WComponentPeer)comp.getPeer() : null; |
| 77 | |
| 78 | try { |
| 79 | boolean forceback = false; |
| 80 | if (context instanceof Boolean) { |
| 81 | forceback = ((Boolean)context).booleanValue(); |
| 82 | } |
| 83 | |
| 84 | if (forceback) { |
| 85 | // peer must be non-null in this case |
| 86 | sData = WGLSurfaceData.createData(peer, vImg); |
| 87 | } else { |
| 88 | WGLGraphicsConfig gc = |
| 89 | (WGLGraphicsConfig)vImg.getGraphicsConfig(); |
| 90 | ColorModel cm = gc.getColorModel(vImg.getTransparency()); |
| 91 | int type = gc.isCapPresent(OGLContext.CAPS_EXT_FBOBJECT) ? |
| 92 | OGLSurfaceData.FBOBJECT : OGLSurfaceData.PBUFFER; |
| 93 | sData = WGLSurfaceData.createData(gc, |
| 94 | vImg.getWidth(), |
| 95 | vImg.getHeight(), |
| 96 | cm, vImg, type); |
| 97 | } |
| 98 | } catch (NullPointerException ex) { |
| 99 | sData = null; |
| 100 | } catch (OutOfMemoryError er) { |
| 101 | sData = null; |
| 102 | } |
| 103 | |
| 104 | return sData; |
| 105 | } |
| 106 | |
| 107 | protected boolean isConfigValid(GraphicsConfiguration gc) { |
| 108 | return ((gc == null) || (gc == vImg.getGraphicsConfig())); |
| 109 | } |
| 110 | } |