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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.java2d.opengl; 27 28 import java.awt.BufferCapabilities; 29 import static java.awt.BufferCapabilities.FlipContents.*; 30 import java.awt.Component; 31 import java.awt.GraphicsConfiguration; 32 import java.awt.Transparency; 33 import java.awt.image.ColorModel; 34 35 import sun.awt.AWTAccessor; 36 import sun.awt.AWTAccessor.ComponentAccessor; 37 import sun.awt.image.SunVolatileImage; 38 import sun.awt.image.VolatileSurfaceManager; 39 import sun.awt.windows.WComponentPeer; 40 import sun.java2d.SurfaceData; 41 import static sun.java2d.opengl.OGLContext.OGLContextCaps.*; 42 import static sun.java2d.pipe.hw.AccelSurface.*; 43 import sun.java2d.pipe.hw.ExtendedBufferCapabilities; 44 import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*; 45 46 public class WGLVolatileSurfaceManager 47 extends VolatileSurfaceManager 48 { 49 private boolean accelerationEnabled; 50 51 public WGLVolatileSurfaceManager(SunVolatileImage vImg, Object context) { 52 super(vImg, context); 53 54 /* 55 * We will attempt to accelerate this image only under the 56 * following conditions: 57 * - the image is opaque OR 58 * - the image is translucent AND 59 * - the GraphicsConfig supports the FBO extension OR 60 * - the GraphicsConfig has a stored alpha channel 61 */ 62 int transparency = vImg.getTransparency(); 63 WGLGraphicsConfig gc = (WGLGraphicsConfig)vImg.getGraphicsConfig(); 64 accelerationEnabled = 65 (transparency == Transparency.OPAQUE) || 66 ((transparency == Transparency.TRANSLUCENT) && 67 (gc.isCapPresent(CAPS_EXT_FBOBJECT) || 68 gc.isCapPresent(CAPS_STORED_ALPHA))); 69 } 70 71 protected boolean isAccelerationEnabled() { 72 return accelerationEnabled; 73 } 74 75 /** 76 * Create a pbuffer-based SurfaceData object (or init the backbuffer 77 * of an existing window if this is a double buffered GraphicsConfig). 78 */ 79 protected SurfaceData initAcceleratedSurface() { 80 SurfaceData sData; 81 Component comp = vImg.getComponent(); 82 final ComponentAccessor acc = AWTAccessor.getComponentAccessor(); 83 WComponentPeer peer = (comp != null) ? acc.getPeer(comp) : null; 84 85 try { 86 boolean createVSynced = false; 87 boolean forceback = false; 88 if (context instanceof Boolean) { 94 (ExtendedBufferCapabilities)caps; 95 if (ebc.getVSync() == VSYNC_ON && 96 ebc.getFlipContents() == COPIED) 97 { 98 createVSynced = true; 99 forceback = false; 100 } 101 } 102 } 103 } 104 105 if (forceback) { 106 // peer must be non-null in this case 107 sData = WGLSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER); 108 } else { 109 WGLGraphicsConfig gc = 110 (WGLGraphicsConfig)vImg.getGraphicsConfig(); 111 ColorModel cm = gc.getColorModel(vImg.getTransparency()); 112 int type = vImg.getForcedAccelSurfaceType(); 113 // if acceleration type is forced (type != UNDEFINED) then 114 // use the forced type, otherwise choose one based on caps 115 if (type == OGLSurfaceData.UNDEFINED) { 116 type = gc.isCapPresent(CAPS_EXT_FBOBJECT) ? 117 OGLSurfaceData.FBOBJECT : OGLSurfaceData.PBUFFER; 118 } 119 if (createVSynced) { 120 sData = WGLSurfaceData.createData(peer, vImg, type); 121 } else { 122 sData = WGLSurfaceData.createData(gc, 123 vImg.getWidth(), 124 vImg.getHeight(), 125 cm, vImg, type); 126 } 127 } 128 } catch (NullPointerException ex) { 129 sData = null; 130 } catch (OutOfMemoryError er) { 131 sData = null; 132 } 133 134 return sData; 135 } 136 137 @Override | 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.java2d.opengl; 27 28 import java.awt.BufferCapabilities; 29 import static java.awt.BufferCapabilities.FlipContents.*; 30 import java.awt.Component; 31 import java.awt.GraphicsConfiguration; 32 import java.awt.image.ColorModel; 33 34 import sun.awt.AWTAccessor; 35 import sun.awt.AWTAccessor.ComponentAccessor; 36 import sun.awt.image.SunVolatileImage; 37 import sun.awt.image.VolatileSurfaceManager; 38 import sun.awt.windows.WComponentPeer; 39 import sun.java2d.SurfaceData; 40 import static sun.java2d.opengl.OGLContext.OGLContextCaps.*; 41 import static sun.java2d.pipe.hw.AccelSurface.*; 42 import sun.java2d.pipe.hw.ExtendedBufferCapabilities; 43 import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*; 44 45 public class WGLVolatileSurfaceManager extends VolatileSurfaceManager { 46 47 private final boolean accelerationEnabled; 48 49 public WGLVolatileSurfaceManager(SunVolatileImage vImg, Object context) { 50 super(vImg, context); 51 52 /* 53 * We will attempt to accelerate this image only under the 54 * following conditions: 55 * - the GraphicsConfig supports the FBO extension 56 */ 57 WGLGraphicsConfig gc = (WGLGraphicsConfig)vImg.getGraphicsConfig(); 58 accelerationEnabled = gc.isCapPresent(CAPS_EXT_FBOBJECT); 59 } 60 61 protected boolean isAccelerationEnabled() { 62 return accelerationEnabled; 63 } 64 65 /** 66 * Create a pbuffer-based SurfaceData object (or init the backbuffer 67 * of an existing window if this is a double buffered GraphicsConfig). 68 */ 69 protected SurfaceData initAcceleratedSurface() { 70 SurfaceData sData; 71 Component comp = vImg.getComponent(); 72 final ComponentAccessor acc = AWTAccessor.getComponentAccessor(); 73 WComponentPeer peer = (comp != null) ? acc.getPeer(comp) : null; 74 75 try { 76 boolean createVSynced = false; 77 boolean forceback = false; 78 if (context instanceof Boolean) { 84 (ExtendedBufferCapabilities)caps; 85 if (ebc.getVSync() == VSYNC_ON && 86 ebc.getFlipContents() == COPIED) 87 { 88 createVSynced = true; 89 forceback = false; 90 } 91 } 92 } 93 } 94 95 if (forceback) { 96 // peer must be non-null in this case 97 sData = WGLSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER); 98 } else { 99 WGLGraphicsConfig gc = 100 (WGLGraphicsConfig)vImg.getGraphicsConfig(); 101 ColorModel cm = gc.getColorModel(vImg.getTransparency()); 102 int type = vImg.getForcedAccelSurfaceType(); 103 // if acceleration type is forced (type != UNDEFINED) then 104 // use the forced type, otherwise choose FBOBJECT 105 if (type == OGLSurfaceData.UNDEFINED) { 106 type = OGLSurfaceData.FBOBJECT; 107 } 108 if (createVSynced) { 109 sData = WGLSurfaceData.createData(peer, vImg, type); 110 } else { 111 sData = WGLSurfaceData.createData(gc, 112 vImg.getWidth(), 113 vImg.getHeight(), 114 cm, vImg, type); 115 } 116 } 117 } catch (NullPointerException ex) { 118 sData = null; 119 } catch (OutOfMemoryError er) { 120 sData = null; 121 } 122 123 return sData; 124 } 125 126 @Override |