< prev index next >

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

Print this page




  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.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) {


  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


  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.X11ComponentPeer;
  37 import sun.awt.image.SunVolatileImage;
  38 import sun.awt.image.VolatileSurfaceManager;
  39 import sun.java2d.BackBufferCapsProvider;
  40 import sun.java2d.SurfaceData;
  41 import static sun.java2d.opengl.OGLContext.OGLContextCaps.*;
  42 import sun.java2d.pipe.hw.ExtendedBufferCapabilities;
  43 import static sun.java2d.pipe.hw.AccelSurface.*;
  44 import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
  45 
  46 public class GLXVolatileSurfaceManager extends VolatileSurfaceManager {
  47 
  48     private final boolean accelerationEnabled;
  49 
  50     public GLXVolatileSurfaceManager(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 GraphicsConfig supports the FBO extension



  57          */

  58         GLXGraphicsConfig gc = (GLXGraphicsConfig)vImg.getGraphicsConfig();
  59         accelerationEnabled = gc.isCapPresent(CAPS_EXT_FBOBJECT);




  60     }
  61 
  62     protected boolean isAccelerationEnabled() {
  63         return accelerationEnabled;
  64     }
  65 
  66     /**
  67      * Create a pbuffer-based SurfaceData object (or init the backbuffer
  68      * of an existing window if this is a double buffered GraphicsConfig)
  69      */
  70     protected SurfaceData initAcceleratedSurface() {
  71         SurfaceData sData;
  72         Component comp = vImg.getComponent();
  73         final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
  74         X11ComponentPeer peer = (comp != null) ? acc.getPeer(comp) : null;
  75 
  76         try {
  77             boolean createVSynced = false;
  78             boolean forceback = false;
  79             if (context instanceof Boolean) {


  87                             (ExtendedBufferCapabilities)caps;
  88                         if (ebc.getVSync() == VSYNC_ON &&
  89                             ebc.getFlipContents() == COPIED)
  90                         {
  91                             createVSynced = true;
  92                             forceback = false;
  93                         }
  94                     }
  95                 }
  96             }
  97 
  98             if (forceback) {
  99                 // peer must be non-null in this case
 100                 sData = GLXSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER);
 101             } else {
 102                 GLXGraphicsConfig gc =
 103                     (GLXGraphicsConfig)vImg.getGraphicsConfig();
 104                 ColorModel cm = gc.getColorModel(vImg.getTransparency());
 105                 int type = vImg.getForcedAccelSurfaceType();
 106                 // if acceleration type is forced (type != UNDEFINED) then
 107                 // use the forced type, otherwise choose FBOBJECT
 108                 if (type == OGLSurfaceData.UNDEFINED) {
 109                     type = OGLSurfaceData.FBOBJECT;

 110                 }
 111                 if (createVSynced) {
 112                     sData = GLXSurfaceData.createData(peer, vImg, type);
 113                 } else {
 114                     sData = GLXSurfaceData.createData(gc,
 115                                                       vImg.getWidth(),
 116                                                       vImg.getHeight(),
 117                                                       cm, vImg, type);
 118                 }
 119             }
 120         } catch (NullPointerException ex) {
 121             sData = null;
 122         } catch (OutOfMemoryError er) {
 123             sData = null;
 124         }
 125 
 126         return sData;
 127     }
 128 
 129     @Override
< prev index next >