< prev index next >

src/java.desktop/macosx/classes/sun/java2d/opengl/CGLVolatileSurfaceManager.java

Print this page




  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 import java.awt.peer.ComponentPeer;
  35 
  36 import sun.awt.AWTAccessor;
  37 import sun.awt.AWTAccessor.ComponentAccessor;
  38 import sun.awt.image.SunVolatileImage;
  39 import sun.awt.image.VolatileSurfaceManager;
  40 import sun.java2d.BackBufferCapsProvider;
  41 import sun.java2d.SurfaceData;
  42 import static sun.java2d.opengl.OGLContext.OGLContextCaps.*;
  43 import sun.java2d.pipe.hw.ExtendedBufferCapabilities;
  44 import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
  45 
  46 public class CGLVolatileSurfaceManager extends VolatileSurfaceManager {
  47 
  48     private boolean accelerationEnabled;
  49 
  50     public CGLVolatileSurfaceManager(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 opaque OR
  57          *   - the image is translucent AND
  58          *       - the GraphicsConfig supports the FBO extension OR
  59          *       - the GraphicsConfig has a stored alpha channel
  60          */
  61         int transparency = vImg.getTransparency();
  62         CGLGraphicsConfig gc = (CGLGraphicsConfig)vImg.getGraphicsConfig();
  63         accelerationEnabled =
  64             (transparency == Transparency.OPAQUE) ||
  65             ((transparency == Transparency.TRANSLUCENT) &&
  66              (gc.isCapPresent(CAPS_EXT_FBOBJECT) ||
  67               gc.isCapPresent(CAPS_STORED_ALPHA)));
  68     }
  69 
  70     protected boolean isAccelerationEnabled() {
  71         return accelerationEnabled;
  72     }
  73 
  74     /**
  75      * Create a pbuffer-based SurfaceData object (or init the backbuffer
  76      * of an existing window if this is a double buffered GraphicsConfig)
  77      */
  78     protected SurfaceData initAcceleratedSurface() {
  79         SurfaceData sData = null;
  80         Component comp = vImg.getComponent();
  81         final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
  82         final ComponentPeer peer = (comp != null) ? acc.getPeer(comp) : null;
  83 
  84         try {
  85             boolean createVSynced = false;
  86             boolean forceback = false;
  87             if (context instanceof Boolean) {
  88                 forceback = ((Boolean)context).booleanValue();
  89                 if (forceback && peer instanceof BackBufferCapsProvider) {
  90                     BackBufferCapsProvider provider =
  91                         (BackBufferCapsProvider)peer;
  92                     BufferCapabilities caps = provider.getBackBufferCaps();
  93                     if (caps instanceof ExtendedBufferCapabilities) {
  94                         ExtendedBufferCapabilities ebc =
  95                             (ExtendedBufferCapabilities)caps;
  96                         if (ebc.getVSync() == VSYNC_ON &&
  97                             ebc.getFlipContents() == COPIED)
  98                         {
  99                             createVSynced = true;
 100                             forceback = false;
 101                         }
 102                     }
 103                 }
 104             }
 105 
 106             if (forceback) {
 107                 // peer must be non-null in this case
 108                 // TODO: modify parameter to delegate
 109                 //                sData = CGLSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER);
 110             } else {
 111                 CGLGraphicsConfig gc =
 112                     (CGLGraphicsConfig)vImg.getGraphicsConfig();
 113                 ColorModel cm = gc.getColorModel(vImg.getTransparency());
 114                 int type = vImg.getForcedAccelSurfaceType();
 115                 // if acceleration type is forced (type != UNDEFINED) then
 116                 // use the forced type, otherwise choose one based on caps
 117                 if (type == OGLSurfaceData.UNDEFINED) {
 118                     type = gc.isCapPresent(CAPS_EXT_FBOBJECT) ?
 119                         OGLSurfaceData.FBOBJECT : OGLSurfaceData.PBUFFER;
 120                 }
 121                 if (createVSynced) {
 122                     // TODO: modify parameter to delegate
 123 //                  sData = CGLSurfaceData.createData(peer, vImg, type);
 124                 } else {
 125                     sData = CGLSurfaceData.createData(gc,
 126                                                       vImg.getWidth(),
 127                                                       vImg.getHeight(),
 128                                                       cm, vImg, type);
 129                 }
 130             }
 131         } catch (NullPointerException ex) {
 132             sData = null;
 133         } catch (OutOfMemoryError er) {
 134             sData = null;
 135         }
 136 
 137         return sData;
 138     }
 139 


  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 import java.awt.peer.ComponentPeer;
  35 
  36 import sun.awt.AWTAccessor;
  37 import sun.awt.AWTAccessor.ComponentAccessor;
  38 import sun.awt.image.SunVolatileImage;
  39 import sun.awt.image.VolatileSurfaceManager;
  40 import sun.java2d.BackBufferCapsProvider;
  41 import sun.java2d.SurfaceData;
  42 import static sun.java2d.opengl.OGLContext.OGLContextCaps.*;
  43 import sun.java2d.pipe.hw.ExtendedBufferCapabilities;
  44 import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
  45 
  46 public class CGLVolatileSurfaceManager extends VolatileSurfaceManager {
  47 
  48     private final boolean accelerationEnabled;
  49 
  50     public CGLVolatileSurfaceManager(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         CGLGraphicsConfig gc = (CGLGraphicsConfig) 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 = null;
  75         Component comp = vImg.getComponent();
  76         final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
  77         final ComponentPeer 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 && peer instanceof BackBufferCapsProvider) {
  85                     BackBufferCapsProvider provider =
  86                         (BackBufferCapsProvider)peer;
  87                     BufferCapabilities caps = provider.getBackBufferCaps();
  88                     if (caps instanceof ExtendedBufferCapabilities) {
  89                         ExtendedBufferCapabilities ebc =
  90                             (ExtendedBufferCapabilities)caps;
  91                         if (ebc.getVSync() == VSYNC_ON &&
  92                             ebc.getFlipContents() == COPIED)
  93                         {
  94                             createVSynced = true;
  95                             forceback = false;
  96                         }
  97                     }
  98                 }
  99             }
 100 
 101             if (forceback) {
 102                 // peer must be non-null in this case
 103                 // TODO: modify parameter to delegate
 104                 //                sData = CGLSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER);
 105             } else {
 106                 CGLGraphicsConfig gc =
 107                     (CGLGraphicsConfig)vImg.getGraphicsConfig();
 108                 ColorModel cm = gc.getColorModel(vImg.getTransparency());
 109                 int type = vImg.getForcedAccelSurfaceType();
 110                 // if acceleration type is forced (type != UNDEFINED) then
 111                 // use the forced type, otherwise choose FBOBJECT
 112                 if (type == OGLSurfaceData.UNDEFINED) {
 113                     type = OGLSurfaceData.FBOBJECT;

 114                 }
 115                 if (createVSynced) {
 116                     // TODO: modify parameter to delegate
 117 //                  sData = CGLSurfaceData.createData(peer, vImg, type);
 118                 } else {
 119                     sData = CGLSurfaceData.createData(gc,
 120                                                       vImg.getWidth(),
 121                                                       vImg.getHeight(),
 122                                                       cm, vImg, type);
 123                 }
 124             }
 125         } catch (NullPointerException ex) {
 126             sData = null;
 127         } catch (OutOfMemoryError er) {
 128             sData = null;
 129         }
 130 
 131         return sData;
 132     }
 133 
< prev index next >