src/macosx/classes/sun/java2d/opengl/CGLSurfaceData.java

Print this page




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

  35 import java.awt.image.ColorModel;
  36 
  37 import sun.java2d.SunGraphics2D;
  38 import sun.java2d.SurfaceData;
  39 

  40 import sun.lwawt.macosx.CPlatformView;
  41 
  42 public abstract class CGLSurfaceData extends OGLSurfaceData {
  43 



  44     protected CPlatformView pView;
  45     private CGLGraphicsConfig graphicsConfig;
  46 
  47     native void validate(int xoff, int yoff, int width, int height, boolean isOpaque);
  48 
  49     private native void initOps(long pConfigInfo, long pPeerData, long layerPtr,
  50                                 int xoff, int yoff, boolean isOpaque);
  51 
  52     protected native boolean initPbuffer(long pData, long pConfigInfo,
  53             boolean isOpaque, int width, int height);
  54 








  55     protected CGLSurfaceData(CPlatformView pView, CGLGraphicsConfig gc,
  56                              ColorModel cm, int type)
  57     {
  58         super(gc, cm, type);
  59         this.pView = pView;
  60         this.graphicsConfig = gc;
  61 
  62         long pConfigInfo = gc.getNativeConfigInfo();
  63         long pPeerData = 0L;
  64         boolean isOpaque = true;
  65         if (pView != null) {
  66             pPeerData = pView.getAWTView();
  67             isOpaque = pView.isOpaque();
  68         }
  69         initOps(pConfigInfo, pPeerData, 0, 0, 0, isOpaque);
  70     }
  71 
  72     protected CGLSurfaceData(CGLLayer layer, CGLGraphicsConfig gc,
  73                              ColorModel cm, int type)
  74     {
  75         super(gc, cm, type);
  76         this.graphicsConfig = gc;
  77 
  78         long pConfigInfo = gc.getNativeConfigInfo();
  79         long layerPtr = 0L;
  80         boolean isOpaque = true;
  81         if (layer != null) {
  82             layerPtr = layer.getPointer();
  83             isOpaque = layer.isOpaque();
  84         }
  85         initOps(pConfigInfo, 0, layerPtr, 0, 0, isOpaque);
  86     }
  87 
  88     @Override //SurfaceData
  89     public GraphicsConfiguration getDeviceConfiguration() {
  90         return graphicsConfig;
  91     }
  92 
  93     /**
  94      * Creates a SurfaceData object representing the primary (front) buffer of
  95      * an on-screen Window.


 140         if (pView != null) {
 141             return (CGLGraphicsConfig)pView.getGraphicsConfiguration();
 142         } else {
 143             // REMIND: this should rarely (never?) happen, but what if
 144             // default config is not CGL?
 145             GraphicsEnvironment env = GraphicsEnvironment
 146                 .getLocalGraphicsEnvironment();
 147             GraphicsDevice gd = env.getDefaultScreenDevice();
 148             return (CGLGraphicsConfig) gd.getDefaultConfiguration();
 149         }
 150     }
 151 
 152     public static CGLGraphicsConfig getGC(CGLLayer layer) {
 153         return (CGLGraphicsConfig)layer.getGraphicsConfiguration();
 154     }
 155 
 156     public void validate() {
 157         // Overridden in CGLWindowSurfaceData below
 158     }
 159 






























 160     protected native void clearWindow();
 161 
 162     public static class CGLWindowSurfaceData extends CGLSurfaceData {
 163 
 164         public CGLWindowSurfaceData(CPlatformView pView,
 165                 CGLGraphicsConfig gc) {
 166             super(pView, gc, gc.getColorModel(), WINDOW);
 167         }
 168 
 169         @Override
 170         public SurfaceData getReplacement() {
 171             return pView.getSurfaceData();
 172         }
 173 
 174         @Override
 175         public Rectangle getBounds() {
 176             Rectangle r = pView.getBounds();
 177             return new Rectangle(0, 0, r.width, r.height);
 178         }
 179 
 180         /**
 181          * Returns destination Component associated with this SurfaceData.
 182          */
 183         @Override
 184         public Object getDestination() {
 185             return pView.getDestination();
 186         }


 200             }
 201         }
 202 
 203         @Override
 204         public void invalidate() {
 205             super.invalidate();
 206             clearWindow();
 207         }
 208     }
 209 
 210     /**
 211      * A surface which implements an intermediate buffer between
 212      * the Java2D flusher thread and the AppKit thread.
 213      *
 214      * This surface serves as a buffer attached to a CGLLayer and
 215      * the layer redirects all painting to the buffer's graphics.
 216      */
 217     public static class CGLLayerSurfaceData extends CGLSurfaceData {
 218 
 219         private CGLLayer layer;
 220         private int width, height;
 221 
 222         public CGLLayerSurfaceData(CGLLayer layer, CGLGraphicsConfig gc,
 223                                    int width, int height) {
 224             super(layer, gc, gc.getColorModel(), FBOBJECT);
 225 
 226             this.width = width;
 227             this.height = height;
 228             this.layer = layer;
 229 
 230             initSurface(width, height);
 231         }
 232 
 233         @Override
 234         public SurfaceData getReplacement() {
 235             return layer.getSurfaceData();
 236         }
 237 
 238         @Override
 239         boolean isOnScreen() {
 240             return true;
 241         }
 242 
 243         @Override
 244         public Rectangle getBounds() {
 245             return new Rectangle(width, height);
 246         }
 247 
 248         @Override
 249         public Object getDestination() {
 250             return layer.getDestination();


 279                 CGLGraphicsConfig gc, int width, int height, Image image,
 280                 ColorModel cm, int type) {
 281             super(pView, gc, width, height, image, cm, type);
 282             flipSurface = CGLSurfaceData.createData(pView, image,
 283                     FLIP_BACKBUFFER);
 284         }
 285 
 286         public SurfaceData getFlipSurface() {
 287             return flipSurface;
 288         }
 289 
 290         @Override
 291         public void flush() {
 292             flipSurface.flush();
 293             super.flush();
 294         }
 295     }
 296 
 297     public static class CGLOffScreenSurfaceData extends CGLSurfaceData {
 298         private Image offscreenImage;
 299         private int width, height;
 300 
 301         public CGLOffScreenSurfaceData(CPlatformView pView,
 302                                        CGLGraphicsConfig gc, int width, int height, Image image,
 303                                        ColorModel cm, int type) {
 304             super(pView, gc, cm, type);
 305 
 306             this.width = width;
 307             this.height = height;
 308             offscreenImage = image;
 309 
 310             initSurface(width, height);
 311         }
 312 
 313         @Override
 314         public SurfaceData getReplacement() {
 315             return restoreContents(offscreenImage);
 316         }
 317 
 318         @Override
 319         public Rectangle getBounds() {
 320             if (type == FLIP_BACKBUFFER) {
 321                 Rectangle r = pView.getBounds();
 322                 return new Rectangle(0, 0, r.width, r.height);
 323             } else {
 324                 return new Rectangle(width, height);
 325             }
 326         }
 327 
 328         /**
 329          * Returns destination Image associated with this SurfaceData.
 330          */




  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.Graphics;
  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 
  37 import sun.java2d.SunGraphics2D;
  38 import sun.java2d.SurfaceData;
  39 
  40 import sun.java2d.pipe.Region;
  41 import sun.lwawt.macosx.CPlatformView;
  42 
  43 public abstract class CGLSurfaceData extends OGLSurfaceData {
  44 
  45     protected final int scale;
  46     protected final int width;
  47     protected final int height;
  48     protected CPlatformView pView;
  49     private CGLGraphicsConfig graphicsConfig;
  50 
  51     native void validate(int xoff, int yoff, int width, int height, boolean isOpaque);
  52 
  53     private native void initOps(long pConfigInfo, long pPeerData, long layerPtr,
  54                                 int xoff, int yoff, boolean isOpaque);
  55 
  56     protected native boolean initPbuffer(long pData, long pConfigInfo,
  57             boolean isOpaque, int width, int height);
  58 
  59     protected CGLSurfaceData(CGLGraphicsConfig gc, ColorModel cm, int type,
  60                              int width, int height) {
  61         super(gc, cm, type);
  62         scale = gc.getDevice().getScaleFactor();
  63         this.width = width * scale;
  64         this.height = height * scale;
  65     }
  66 
  67     protected CGLSurfaceData(CPlatformView pView, CGLGraphicsConfig gc,
  68                              ColorModel cm, int type,int width, int height)
  69     {
  70         this(gc, cm, type, width, height);
  71         this.pView = pView;
  72         this.graphicsConfig = gc;
  73 
  74         long pConfigInfo = gc.getNativeConfigInfo();
  75         long pPeerData = 0L;
  76         boolean isOpaque = true;
  77         if (pView != null) {
  78             pPeerData = pView.getAWTView();
  79             isOpaque = pView.isOpaque();
  80         }
  81         initOps(pConfigInfo, pPeerData, 0, 0, 0, isOpaque);
  82     }
  83 
  84     protected CGLSurfaceData(CGLLayer layer, CGLGraphicsConfig gc,
  85                              ColorModel cm, int type,int width, int height)
  86     {
  87         this(gc, cm, type, width, height);
  88         this.graphicsConfig = gc;
  89 
  90         long pConfigInfo = gc.getNativeConfigInfo();
  91         long layerPtr = 0L;
  92         boolean isOpaque = true;
  93         if (layer != null) {
  94             layerPtr = layer.getPointer();
  95             isOpaque = layer.isOpaque();
  96         }
  97         initOps(pConfigInfo, 0, layerPtr, 0, 0, isOpaque);
  98     }
  99 
 100     @Override //SurfaceData
 101     public GraphicsConfiguration getDeviceConfiguration() {
 102         return graphicsConfig;
 103     }
 104 
 105     /**
 106      * Creates a SurfaceData object representing the primary (front) buffer of
 107      * an on-screen Window.


 152         if (pView != null) {
 153             return (CGLGraphicsConfig)pView.getGraphicsConfiguration();
 154         } else {
 155             // REMIND: this should rarely (never?) happen, but what if
 156             // default config is not CGL?
 157             GraphicsEnvironment env = GraphicsEnvironment
 158                 .getLocalGraphicsEnvironment();
 159             GraphicsDevice gd = env.getDefaultScreenDevice();
 160             return (CGLGraphicsConfig) gd.getDefaultConfiguration();
 161         }
 162     }
 163 
 164     public static CGLGraphicsConfig getGC(CGLLayer layer) {
 165         return (CGLGraphicsConfig)layer.getGraphicsConfiguration();
 166     }
 167 
 168     public void validate() {
 169         // Overridden in CGLWindowSurfaceData below
 170     }
 171 
 172     @Override
 173     public int getDefaultScale() {
 174         return scale;
 175     }
 176 
 177     @Override
 178     public boolean copyArea(SunGraphics2D sg2d, int x, int y, int w, int h,
 179                             int dx, int dy) {
 180         final int state = sg2d.transformState;
 181         if (state > SunGraphics2D.TRANSFORM_TRANSLATESCALE
 182             || sg2d.compositeState >= SunGraphics2D.COMP_XOR) {
 183             return false;
 184         }
 185         if (state <= SunGraphics2D.TRANSFORM_ANY_TRANSLATE) {
 186             x += sg2d.transX;
 187             y += sg2d.transY;
 188         } else if (state == SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
 189             final double[] coords = {x, y, x + w, y + h, x + dx, y + dy};
 190             sg2d.transform.transform(coords, 0, coords, 0, 3);
 191             x = (int) Math.ceil(coords[0] - 0.5);
 192             y = (int) Math.ceil(coords[1] - 0.5);
 193             w = ((int) Math.ceil(coords[2] - 0.5)) - x;
 194             h = ((int) Math.ceil(coords[3] - 0.5)) - y;
 195             dx = ((int) Math.ceil(coords[4] - 0.5)) - x;
 196             dy = ((int) Math.ceil(coords[5] - 0.5)) - y;
 197         }
 198         oglRenderPipe.copyArea(sg2d, x, y, w, h, dx, dy);
 199         return true;
 200     }
 201 
 202     protected native void clearWindow();
 203 
 204     public static class CGLWindowSurfaceData extends CGLSurfaceData {
 205 
 206         public CGLWindowSurfaceData(CPlatformView pView,
 207                 CGLGraphicsConfig gc) {
 208             super(pView, gc, gc.getColorModel(), WINDOW, 0, 0);
 209         }
 210 
 211         @Override
 212         public SurfaceData getReplacement() {
 213             return pView.getSurfaceData();
 214         }
 215 
 216         @Override
 217         public Rectangle getBounds() {
 218             Rectangle r = pView.getBounds();
 219             return new Rectangle(0, 0, r.width, r.height);
 220         }
 221 
 222         /**
 223          * Returns destination Component associated with this SurfaceData.
 224          */
 225         @Override
 226         public Object getDestination() {
 227             return pView.getDestination();
 228         }


 242             }
 243         }
 244 
 245         @Override
 246         public void invalidate() {
 247             super.invalidate();
 248             clearWindow();
 249         }
 250     }
 251 
 252     /**
 253      * A surface which implements an intermediate buffer between
 254      * the Java2D flusher thread and the AppKit thread.
 255      *
 256      * This surface serves as a buffer attached to a CGLLayer and
 257      * the layer redirects all painting to the buffer's graphics.
 258      */
 259     public static class CGLLayerSurfaceData extends CGLSurfaceData {
 260 
 261         private CGLLayer layer;

 262 
 263         public CGLLayerSurfaceData(CGLLayer layer, CGLGraphicsConfig gc,
 264                                    int width, int height) {
 265             super(layer, gc, gc.getColorModel(), FBOBJECT, width, height);



 266             this.layer = layer;
 267             initSurface(this.width, this.height);

 268         }
 269 
 270         @Override
 271         public SurfaceData getReplacement() {
 272             return layer.getSurfaceData();
 273         }
 274 
 275         @Override
 276         boolean isOnScreen() {
 277             return true;
 278         }
 279 
 280         @Override
 281         public Rectangle getBounds() {
 282             return new Rectangle(width, height);
 283         }
 284 
 285         @Override
 286         public Object getDestination() {
 287             return layer.getDestination();


 316                 CGLGraphicsConfig gc, int width, int height, Image image,
 317                 ColorModel cm, int type) {
 318             super(pView, gc, width, height, image, cm, type);
 319             flipSurface = CGLSurfaceData.createData(pView, image,
 320                     FLIP_BACKBUFFER);
 321         }
 322 
 323         public SurfaceData getFlipSurface() {
 324             return flipSurface;
 325         }
 326 
 327         @Override
 328         public void flush() {
 329             flipSurface.flush();
 330             super.flush();
 331         }
 332     }
 333 
 334     public static class CGLOffScreenSurfaceData extends CGLSurfaceData {
 335         private Image offscreenImage;

 336 
 337         public CGLOffScreenSurfaceData(CPlatformView pView,
 338                                        CGLGraphicsConfig gc, int width, int height, Image image,
 339                                        ColorModel cm, int type) {
 340             super(pView, gc, cm, type, width, height);



 341             offscreenImage = image;
 342             initSurface(this.width, this.height);

 343         }
 344 
 345         @Override
 346         public SurfaceData getReplacement() {
 347             return restoreContents(offscreenImage);
 348         }
 349 
 350         @Override
 351         public Rectangle getBounds() {
 352             if (type == FLIP_BACKBUFFER) {
 353                 Rectangle r = pView.getBounds();
 354                 return new Rectangle(0, 0, r.width, r.height);
 355             } else {
 356                 return new Rectangle(width, height);
 357             }
 358         }
 359 
 360         /**
 361          * Returns destination Image associated with this SurfaceData.
 362          */