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) { 89 forceback = ((Boolean)context).booleanValue(); 90 if (forceback) { 91 BufferCapabilities caps = peer.getBackBufferCaps(); 92 if (caps instanceof ExtendedBufferCapabilities) { 93 ExtendedBufferCapabilities ebc = 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 | 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 extends VolatileSurfaceManager { 47 48 private final boolean accelerationEnabled; 49 50 public WGLVolatileSurfaceManager(SunVolatileImage vImg, Object context) { 51 super(vImg, context); 52 53 /* 54 * We will attempt to accelerate this image only under the 55 * following conditions: 56 * - the image is not bitmask AND the GraphicsConfig supports the FBO 57 * extension 58 */ 59 int transparency = vImg.getTransparency(); 60 WGLGraphicsConfig gc = (WGLGraphicsConfig) vImg.getGraphicsConfig(); 61 accelerationEnabled = gc.isCapPresent(CAPS_EXT_FBOBJECT) 62 && transparency != Transparency.BITMASK; 63 } 64 65 protected boolean isAccelerationEnabled() { 66 return accelerationEnabled; 67 } 68 69 /** 70 * Create a FBO-based SurfaceData object (or init the backbuffer 71 * of an existing window if this is a double buffered GraphicsConfig). 72 */ 73 protected SurfaceData initAcceleratedSurface() { 74 SurfaceData sData; 75 Component comp = vImg.getComponent(); 76 final ComponentAccessor acc = AWTAccessor.getComponentAccessor(); 77 WComponentPeer peer = (comp != null) ? acc.getPeer(comp) : null; 78 79 try { 80 boolean createVSynced = false; 81 boolean forceback = false; 82 if (context instanceof Boolean) { 83 forceback = ((Boolean)context).booleanValue(); 84 if (forceback) { 85 BufferCapabilities caps = peer.getBackBufferCaps(); 86 if (caps instanceof ExtendedBufferCapabilities) { 87 ExtendedBufferCapabilities ebc = 88 (ExtendedBufferCapabilities)caps; 89 if (ebc.getVSync() == VSYNC_ON && 90 ebc.getFlipContents() == COPIED) 91 { 92 createVSynced = true; 93 forceback = false; 94 } 95 } 96 } 97 } 98 99 if (forceback) { 100 // peer must be non-null in this case 101 sData = WGLSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER); 102 } else { 103 WGLGraphicsConfig gc = 104 (WGLGraphicsConfig)vImg.getGraphicsConfig(); 105 ColorModel cm = gc.getColorModel(vImg.getTransparency()); 106 int type = vImg.getForcedAccelSurfaceType(); 107 // if acceleration type is forced (type != UNDEFINED) then 108 // use the forced type, otherwise choose FBOBJECT 109 if (type == OGLSurfaceData.UNDEFINED) { 110 type = OGLSurfaceData.FBOBJECT; 111 } 112 if (createVSynced) { 113 sData = WGLSurfaceData.createData(peer, vImg, type); 114 } else { 115 sData = WGLSurfaceData.createData(gc, 116 vImg.getWidth(), 117 vImg.getHeight(), 118 cm, vImg, type); 119 } 120 } 121 } catch (NullPointerException ex) { 122 sData = null; 123 } catch (OutOfMemoryError er) { 124 sData = null; 125 } 126 127 return sData; 128 } 129 130 @Override |