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


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


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

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



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

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


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

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



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

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