< prev index next >

src/java.desktop/unix/classes/sun/java2d/opengl/GLXVolatileSurfaceManager.java

Print this page




  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.X11ComponentPeer;
  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.AccelSurface.*;
  45 import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
  46 
  47 public class GLXVolatileSurfaceManager extends VolatileSurfaceManager {
  48 
  49     private boolean accelerationEnabled;
  50 
  51     public GLXVolatileSurfaceManager(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         GLXGraphicsConfig gc = (GLXGraphicsConfig)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         X11ComponentPeer 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 && peer instanceof BackBufferCapsProvider) {
  91                     BackBufferCapsProvider provider =
  92                         (BackBufferCapsProvider)peer;
  93                     BufferCapabilities caps = provider.getBackBufferCaps();
  94                     if (caps instanceof ExtendedBufferCapabilities) {
  95                         ExtendedBufferCapabilities ebc =
  96                             (ExtendedBufferCapabilities)caps;
  97                         if (ebc.getVSync() == VSYNC_ON &&
  98                             ebc.getFlipContents() == COPIED)
  99                         {
 100                             createVSynced = true;
 101                             forceback = false;
 102                         }
 103                     }
 104                 }
 105             }
 106 
 107             if (forceback) {
 108                 // peer must be non-null in this case
 109                 sData = GLXSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER);
 110             } else {
 111                 GLXGraphicsConfig gc =
 112                     (GLXGraphicsConfig)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                     sData = GLXSurfaceData.createData(peer, vImg, type);
 123                 } else {
 124                     sData = GLXSurfaceData.createData(gc,
 125                                                       vImg.getWidth(),
 126                                                       vImg.getHeight(),
 127                                                       cm, vImg, type);
 128                 }
 129             }
 130         } catch (NullPointerException ex) {
 131             sData = null;
 132         } catch (OutOfMemoryError er) {
 133             sData = null;
 134         }
 135 
 136         return sData;
 137     }
 138 
 139     @Override


  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.X11ComponentPeer;
  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.AccelSurface.*;
  45 import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
  46 
  47 public class GLXVolatileSurfaceManager extends VolatileSurfaceManager {
  48 
  49     private final boolean accelerationEnabled;
  50 
  51     public GLXVolatileSurfaceManager(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 not bitmask AND the GraphicsConfig supports the FBO
  58          *     extension


  59          */
  60         int transparency = vImg.getTransparency();
  61         GLXGraphicsConfig gc = (GLXGraphicsConfig) vImg.getGraphicsConfig();
  62         accelerationEnabled = gc.isCapPresent(CAPS_EXT_FBOBJECT)
  63                 && transparency != Transparency.BITMASK;



  64     }
  65 
  66     protected boolean isAccelerationEnabled() {
  67         return accelerationEnabled;
  68     }
  69 
  70     /**
  71      * Create a FBO-based SurfaceData object (or init the backbuffer
  72      * of an existing window if this is a double buffered GraphicsConfig)
  73      */
  74     protected SurfaceData initAcceleratedSurface() {
  75         SurfaceData sData;
  76         Component comp = vImg.getComponent();
  77         final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
  78         X11ComponentPeer peer = (comp != null) ? acc.getPeer(comp) : null;
  79 
  80         try {
  81             boolean createVSynced = false;
  82             boolean forceback = false;
  83             if (context instanceof Boolean) {
  84                 forceback = ((Boolean)context).booleanValue();
  85                 if (forceback && peer instanceof BackBufferCapsProvider) {
  86                     BackBufferCapsProvider provider =
  87                         (BackBufferCapsProvider)peer;
  88                     BufferCapabilities caps = provider.getBackBufferCaps();
  89                     if (caps instanceof ExtendedBufferCapabilities) {
  90                         ExtendedBufferCapabilities ebc =
  91                             (ExtendedBufferCapabilities)caps;
  92                         if (ebc.getVSync() == VSYNC_ON &&
  93                             ebc.getFlipContents() == COPIED)
  94                         {
  95                             createVSynced = true;
  96                             forceback = false;
  97                         }
  98                     }
  99                 }
 100             }
 101 
 102             if (forceback) {
 103                 // peer must be non-null in this case
 104                 sData = GLXSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER);
 105             } else {
 106                 GLXGraphicsConfig gc =
 107                     (GLXGraphicsConfig)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                     sData = GLXSurfaceData.createData(peer, vImg, type);
 117                 } else {
 118                     sData = GLXSurfaceData.createData(gc,
 119                                                       vImg.getWidth(),
 120                                                       vImg.getHeight(),
 121                                                       cm, vImg, type);
 122                 }
 123             }
 124         } catch (NullPointerException ex) {
 125             sData = null;
 126         } catch (OutOfMemoryError er) {
 127             sData = null;
 128         }
 129 
 130         return sData;
 131     }
 132 
 133     @Override
< prev index next >