< prev index next >

src/java.desktop/windows/classes/sun/java2d/opengl/WGLSurfaceData.java

Print this page




  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.Component;
  29 import java.awt.GraphicsConfiguration;
  30 import java.awt.GraphicsDevice;
  31 import java.awt.GraphicsEnvironment;
  32 import java.awt.Image;
  33 import java.awt.Rectangle;

  34 import java.awt.image.ColorModel;
  35 import sun.awt.SunToolkit;

  36 import sun.awt.windows.WComponentPeer;
  37 import sun.java2d.SurfaceData;
  38 
  39 public abstract class WGLSurfaceData extends OGLSurfaceData {
  40 
  41     protected WComponentPeer peer;
  42     private WGLGraphicsConfig graphicsConfig;


  43 
  44     private native void initOps(long pConfigInfo, WComponentPeer peer,
  45                                 long hwnd);
  46 
  47     protected WGLSurfaceData(WComponentPeer peer, WGLGraphicsConfig gc,
  48                              ColorModel cm, int type)
  49     {
  50         super(gc, cm, type);
  51         this.peer = peer;
  52         this.graphicsConfig = gc;



  53 
  54         long pConfigInfo = gc.getNativeConfigInfo();
  55         long hwnd = peer != null ? peer.getHWnd() : 0L;
  56 
  57         initOps(pConfigInfo, peer, hwnd);
  58     }
  59 










  60     public GraphicsConfiguration getDeviceConfiguration() {
  61         return graphicsConfig;
  62     }
  63 
  64     /**
  65      * Creates a SurfaceData object representing the primary (front) buffer
  66      * of an on-screen Window.
  67      */
  68     public static WGLWindowSurfaceData createData(WComponentPeer peer) {
  69         // the OGL pipeline can render directly to the screen and interfere
  70         // with layered windows, which is why we don't allow accelerated
  71         // surfaces in this case
  72         if (!peer.isAccelCapable() ||
  73             !SunToolkit.isContainingTopLevelOpaque((Component)peer.getTarget()))
  74         {
  75             return null;
  76         }
  77         WGLGraphicsConfig gc = getGC(peer);
  78         return new WGLWindowSurfaceData(peer, gc);
  79     }


 131             GraphicsDevice gd = env.getDefaultScreenDevice();
 132             return (WGLGraphicsConfig)gd.getDefaultConfiguration();
 133         }
 134     }
 135 
 136     public static class WGLWindowSurfaceData extends WGLSurfaceData {
 137 
 138         public WGLWindowSurfaceData(WComponentPeer peer,
 139                                     WGLGraphicsConfig gc)
 140         {
 141             super(peer, gc, peer.getColorModel(), WINDOW);
 142         }
 143 
 144         public SurfaceData getReplacement() {
 145             return peer.getSurfaceData();
 146         }
 147 
 148         public Rectangle getBounds() {
 149             Rectangle r = peer.getBounds();
 150             r.x = r.y = 0;


 151             return r;
 152         }
 153 
 154         /**
 155          * Returns destination Component associated with this SurfaceData.
 156          */
 157         public Object getDestination() {
 158             return peer.getTarget();
 159         }
 160     }
 161 
 162     /**
 163      * A surface which implements a v-synced flip back-buffer with COPIED
 164      * FlipContents.
 165      *
 166      * This surface serves as a back-buffer to the outside world, while
 167      * it is actually an offscreen surface. When the BufferStrategy this surface
 168      * belongs to is showed, it is first copied to the real private
 169      * FLIP_BACKBUFFER, which is then flipped.
 170      */


 191         public void flush() {
 192             flipSurface.flush();
 193             super.flush();
 194         }
 195 
 196     }
 197 
 198     public static class WGLOffScreenSurfaceData extends WGLSurfaceData {
 199 
 200         private Image offscreenImage;
 201         private int width, height;
 202 
 203         public WGLOffScreenSurfaceData(WComponentPeer peer,
 204                                        WGLGraphicsConfig gc,
 205                                        int width, int height,
 206                                        Image image, ColorModel cm,
 207                                        int type)
 208         {
 209             super(peer, gc, cm, type);
 210 
 211             this.width = width;
 212             this.height = height;
 213             offscreenImage = image;
 214 
 215             initSurface(width, height);
 216         }
 217 
 218         public SurfaceData getReplacement() {
 219             return restoreContents(offscreenImage);
 220         }
 221 
 222         public Rectangle getBounds() {
 223             if (type == FLIP_BACKBUFFER) {
 224                 Rectangle r = peer.getBounds();


 225                 r.x = r.y = 0;
 226                 return r;
 227             } else {
 228                 return new Rectangle(width, height);
 229             }
 230         }
 231 
 232         /**
 233          * Returns destination Image associated with this SurfaceData.
 234          */
 235         public Object getDestination() {
 236             return offscreenImage;
 237         }
 238     }
 239 
 240     /**
 241      * Updates the layered window with the contents of the surface.
 242      *
 243      * @param psdops pointer to the native ogl sd structure
 244      * @param peer pointer to the AwtWindow peer data


  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.Component;
  29 import java.awt.GraphicsConfiguration;
  30 import java.awt.GraphicsDevice;
  31 import java.awt.GraphicsEnvironment;
  32 import java.awt.Image;
  33 import java.awt.Rectangle;
  34 import java.awt.geom.AffineTransform;
  35 import java.awt.image.ColorModel;
  36 import sun.awt.SunToolkit;
  37 import sun.awt.Win32GraphicsDevice;
  38 import sun.awt.windows.WComponentPeer;
  39 import sun.java2d.SurfaceData;
  40 
  41 public abstract class WGLSurfaceData extends OGLSurfaceData {
  42 
  43     protected WComponentPeer peer;
  44     private WGLGraphicsConfig graphicsConfig;
  45     protected double scaleX = 1;
  46     protected double scaleY = 1;
  47 
  48     private native void initOps(long pConfigInfo, WComponentPeer peer,
  49                                 long hwnd);
  50 
  51     protected WGLSurfaceData(WComponentPeer peer, WGLGraphicsConfig gc,
  52                              ColorModel cm, int type)
  53     {
  54         super(gc, cm, type);
  55         this.peer = peer;
  56         this.graphicsConfig = gc;
  57         Win32GraphicsDevice device = gc.getDevice();
  58         this.scaleX = type == TEXTURE ? 1 : device.getDefaultScaleX();
  59         this.scaleY = type == TEXTURE ? 1 : device.getDefaultScaleY();
  60 
  61         long pConfigInfo = gc.getNativeConfigInfo();
  62         long hwnd = peer != null ? peer.getHWnd() : 0L;
  63 
  64         initOps(pConfigInfo, peer, hwnd);
  65     }
  66 
  67     @Override
  68     public double getDefaultScaleX() {
  69         return scaleX;
  70     }
  71 
  72     @Override
  73     public double getDefaultScaleY() {
  74         return scaleY;
  75     }
  76 
  77     public GraphicsConfiguration getDeviceConfiguration() {
  78         return graphicsConfig;
  79     }
  80 
  81     /**
  82      * Creates a SurfaceData object representing the primary (front) buffer
  83      * of an on-screen Window.
  84      */
  85     public static WGLWindowSurfaceData createData(WComponentPeer peer) {
  86         // the OGL pipeline can render directly to the screen and interfere
  87         // with layered windows, which is why we don't allow accelerated
  88         // surfaces in this case
  89         if (!peer.isAccelCapable() ||
  90             !SunToolkit.isContainingTopLevelOpaque((Component)peer.getTarget()))
  91         {
  92             return null;
  93         }
  94         WGLGraphicsConfig gc = getGC(peer);
  95         return new WGLWindowSurfaceData(peer, gc);
  96     }


 148             GraphicsDevice gd = env.getDefaultScreenDevice();
 149             return (WGLGraphicsConfig)gd.getDefaultConfiguration();
 150         }
 151     }
 152 
 153     public static class WGLWindowSurfaceData extends WGLSurfaceData {
 154 
 155         public WGLWindowSurfaceData(WComponentPeer peer,
 156                                     WGLGraphicsConfig gc)
 157         {
 158             super(peer, gc, peer.getColorModel(), WINDOW);
 159         }
 160 
 161         public SurfaceData getReplacement() {
 162             return peer.getSurfaceData();
 163         }
 164 
 165         public Rectangle getBounds() {
 166             Rectangle r = peer.getBounds();
 167             r.x = r.y = 0;
 168             r.width = (int) Math.ceil(r.width * scaleX);
 169             r.height = (int) Math.ceil(r.height * scaleY);
 170             return r;
 171         }
 172 
 173         /**
 174          * Returns destination Component associated with this SurfaceData.
 175          */
 176         public Object getDestination() {
 177             return peer.getTarget();
 178         }
 179     }
 180 
 181     /**
 182      * A surface which implements a v-synced flip back-buffer with COPIED
 183      * FlipContents.
 184      *
 185      * This surface serves as a back-buffer to the outside world, while
 186      * it is actually an offscreen surface. When the BufferStrategy this surface
 187      * belongs to is showed, it is first copied to the real private
 188      * FLIP_BACKBUFFER, which is then flipped.
 189      */


 210         public void flush() {
 211             flipSurface.flush();
 212             super.flush();
 213         }
 214 
 215     }
 216 
 217     public static class WGLOffScreenSurfaceData extends WGLSurfaceData {
 218 
 219         private Image offscreenImage;
 220         private int width, height;
 221 
 222         public WGLOffScreenSurfaceData(WComponentPeer peer,
 223                                        WGLGraphicsConfig gc,
 224                                        int width, int height,
 225                                        Image image, ColorModel cm,
 226                                        int type)
 227         {
 228             super(peer, gc, cm, type);
 229 
 230             this.width = (int) Math.ceil(width * scaleX);
 231             this.height = (int) Math.ceil(height * scaleY);
 232             offscreenImage = image;
 233 
 234             initSurface(this.width, this.height);
 235         }
 236 
 237         public SurfaceData getReplacement() {
 238             return restoreContents(offscreenImage);
 239         }
 240 
 241         public Rectangle getBounds() {
 242             if (type == FLIP_BACKBUFFER) {
 243                 Rectangle r = peer.getBounds();
 244                 r.width = (int) Math.ceil(r.width * scaleX);
 245                 r.height = (int) Math.ceil(r.height * scaleY);
 246                 r.x = r.y = 0;
 247                 return r;
 248             } else {
 249                 return new Rectangle(width, height);
 250             }
 251         }
 252 
 253         /**
 254          * Returns destination Image associated with this SurfaceData.
 255          */
 256         public Object getDestination() {
 257             return offscreenImage;
 258         }
 259     }
 260 
 261     /**
 262      * Updates the layered window with the contents of the surface.
 263      *
 264      * @param psdops pointer to the native ogl sd structure
 265      * @param peer pointer to the AwtWindow peer data
< prev index next >