< prev index next >

src/java.desktop/macosx/classes/sun/java2d/opengl/CGLVolatileSurfaceManager.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 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) {


  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 


  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 import java.awt.peer.ComponentPeer;
  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.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.ExtendedBufferCapabilities.VSyncType.*;
  44 
  45 public class CGLVolatileSurfaceManager extends VolatileSurfaceManager {
  46 
  47     private final boolean accelerationEnabled;
  48 
  49     public CGLVolatileSurfaceManager(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         CGLGraphicsConfig gc = (CGLGraphicsConfig)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 = null;
  71         Component comp = vImg.getComponent();
  72         final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
  73         final ComponentPeer peer = (comp != null) ? acc.getPeer(comp) : null;
  74 
  75         try {
  76             boolean createVSynced = false;
  77             boolean forceback = false;
  78             if (context instanceof Boolean) {


  87                         if (ebc.getVSync() == VSYNC_ON &&
  88                             ebc.getFlipContents() == COPIED)
  89                         {
  90                             createVSynced = true;
  91                             forceback = false;
  92                         }
  93                     }
  94                 }
  95             }
  96 
  97             if (forceback) {
  98                 // peer must be non-null in this case
  99                 // TODO: modify parameter to delegate
 100                 //                sData = CGLSurfaceData.createData(peer, vImg, FLIP_BACKBUFFER);
 101             } else {
 102                 CGLGraphicsConfig gc =
 103                     (CGLGraphicsConfig)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                     // TODO: modify parameter to delegate
 113 //                  sData = CGLSurfaceData.createData(peer, vImg, type);
 114                 } else {
 115                     sData = CGLSurfaceData.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 
< prev index next >