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

Print this page




  63 import sun.java2d.pipe.hw.AccelDeviceEventNotifier;
  64 
  65 import sun.lwawt.LWComponentPeer;
  66 import sun.lwawt.macosx.CPlatformView;
  67 
  68 public final class CGLGraphicsConfig extends CGraphicsConfig
  69     implements OGLGraphicsConfig
  70 {
  71     //private static final int kOpenGLSwapInterval =
  72     // RuntimeOptions.getCurrentOptions().OpenGLSwapInterval;
  73     private static final int kOpenGLSwapInterval = 0; // TODO
  74     private static boolean cglAvailable;
  75     private static ImageCapabilities imageCaps = new CGLImageCaps();
  76 
  77     private int pixfmt;
  78     private BufferCapabilities bufferCaps;
  79     private long pConfigInfo;
  80     private ContextCapabilities oglCaps;
  81     private OGLContext context;
  82     private final Object disposerReferent = new Object();
  83 
  84     public static native int getDefaultPixFmt(int screennum);
  85     private static native boolean initCGL();
  86     private static native long getCGLConfigInfo(int screennum, int visualnum,
  87                                                 int swapInterval);
  88     private static native int getOGLCapabilities(long configInfo);
  89 
  90     static {
  91         cglAvailable = initCGL();
  92     }
  93 
  94     private CGLGraphicsConfig(CGraphicsDevice device, int pixfmt,
  95                                 long configInfo, ContextCapabilities oglCaps)
  96     {
  97         super(device);
  98 
  99         this.pixfmt = pixfmt;
 100         this.pConfigInfo = configInfo;
 101         this.oglCaps = oglCaps;
 102         context = new OGLContext(OGLRenderQueue.getInstance(), this);
 103 
 104         // add a record to the Disposer so that we destroy the native
 105         // CGLGraphicsConfigInfo data when this object goes away
 106         Disposer.addRecord(disposerReferent,


 120                                          OGLSurfaceData.TEXTURE);
 121     }
 122 
 123     public static CGLGraphicsConfig getConfig(CGraphicsDevice device,
 124                                               int pixfmt)
 125     {
 126         if (!cglAvailable) {
 127             return null;
 128         }
 129 
 130         long cfginfo = 0;
 131         final String ids[] = new String[1];
 132         OGLRenderQueue rq = OGLRenderQueue.getInstance();
 133         rq.lock();
 134         try {
 135             // getCGLConfigInfo() creates and destroys temporary
 136             // surfaces/contexts, so we should first invalidate the current
 137             // Java-level context and flush the queue...
 138             OGLContext.invalidateCurrentContext();
 139 
 140             cfginfo = getCGLConfigInfo(device.getCoreGraphicsScreen(), pixfmt,
 141                                        kOpenGLSwapInterval);
 142 
 143             OGLContext.setScratchSurface(cfginfo);
 144             rq.flushAndInvokeNow(new Runnable() {
 145                 public void run() {
 146                     ids[0] = OGLContext.getOGLIdString();
 147                 }
 148             });

 149         } finally {
 150             rq.unlock();
 151         }
 152         if (cfginfo == 0) {
 153             return null;
 154         }
 155 
 156         int oglCaps = getOGLCapabilities(cfginfo);
 157         ContextCapabilities caps = new OGLContextCaps(oglCaps, ids[0]);
 158 
 159         return new CGLGraphicsConfig(device, pixfmt, cfginfo, caps);
 160     }
 161 
 162     public static boolean isCGLAvailable() {
 163         return cglAvailable;
 164     }
 165 
 166     /**
 167      * Returns true if the provided capability bit is present for this config.
 168      * See OGLContext.java for a list of supported capabilities.


 236     //@Override
 237     public synchronized void displayChanged() {
 238         //super.displayChanged();
 239 
 240         // the context could hold a reference to a CGLSurfaceData, which in
 241         // turn has a reference back to this CGLGraphicsConfig, so in order
 242         // for this instance to be disposed we need to break the connection
 243         OGLRenderQueue rq = OGLRenderQueue.getInstance();
 244         rq.lock();
 245         try {
 246             OGLContext.invalidateCurrentContext();
 247         } finally {
 248             rq.unlock();
 249         }
 250 
 251         updateTotalDisplayBounds();
 252     }
 253 
 254     @Override
 255     public String toString() {
 256         int screen = getDevice().getCoreGraphicsScreen();
 257         return ("CGLGraphicsConfig[dev="+screen+",pixfmt="+pixfmt+"]");
 258     }
 259 
 260     @Override
 261     public SurfaceData createSurfaceData(CPlatformView pView) {
 262         return CGLSurfaceData.createData(pView);
 263     }
 264 
 265     @Override
 266     public SurfaceData createSurfaceData(CGLLayer layer) {
 267         return CGLSurfaceData.createData(layer);
 268     }
 269 
 270     @Override
 271     public Image createAcceleratedImage(Component target,
 272                                         int width, int height)
 273     {
 274         ColorModel model = getColorModel(Transparency.OPAQUE);
 275         WritableRaster wr = model.createCompatibleWritableRaster(width, height);
 276         return new OffScreenImage(target, model, wr,
 277                                   model.isAlphaPremultiplied());


 396         {
 397             vi.flush();
 398             vi = null;
 399         }
 400 
 401         return vi;
 402     }
 403 
 404     /**
 405      * {@inheritDoc}
 406      *
 407      * @see sun.java2d.pipe.hw.AccelGraphicsConfig#getContextCapabilities
 408      */
 409     @Override
 410     public ContextCapabilities getContextCapabilities() {
 411         return oglCaps;
 412     }
 413 
 414     @Override
 415     public void addDeviceEventListener(AccelDeviceEventListener l) {
 416         int screen = getDevice().getCoreGraphicsScreen();
 417         AccelDeviceEventNotifier.addListener(l, screen);
 418     }
 419 
 420     @Override
 421     public void removeDeviceEventListener(AccelDeviceEventListener l) {
 422         AccelDeviceEventNotifier.removeListener(l);
 423     }
 424 
 425     private static final Rectangle totalDisplayBounds = new Rectangle();
 426 
 427     private static void updateTotalDisplayBounds() {
 428         synchronized (totalDisplayBounds) {
 429             Rectangle virtualBounds = new Rectangle();
 430             for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
 431                 for (GraphicsConfiguration gc : gd.getConfigurations()) {
 432                     virtualBounds = virtualBounds.union(gc.getBounds());
 433                 }
 434             }
 435             totalDisplayBounds.setBounds(virtualBounds);
 436         }
 437     }




  63 import sun.java2d.pipe.hw.AccelDeviceEventNotifier;
  64 
  65 import sun.lwawt.LWComponentPeer;
  66 import sun.lwawt.macosx.CPlatformView;
  67 
  68 public final class CGLGraphicsConfig extends CGraphicsConfig
  69     implements OGLGraphicsConfig
  70 {
  71     //private static final int kOpenGLSwapInterval =
  72     // RuntimeOptions.getCurrentOptions().OpenGLSwapInterval;
  73     private static final int kOpenGLSwapInterval = 0; // TODO
  74     private static boolean cglAvailable;
  75     private static ImageCapabilities imageCaps = new CGLImageCaps();
  76 
  77     private int pixfmt;
  78     private BufferCapabilities bufferCaps;
  79     private long pConfigInfo;
  80     private ContextCapabilities oglCaps;
  81     private OGLContext context;
  82     private final Object disposerReferent = new Object();


  83     private static native boolean initCGL();
  84     private static native long getCGLConfigInfo(int displayID, int visualnum,
  85                                                 int swapInterval);
  86     private static native int getOGLCapabilities(long configInfo);
  87 
  88     static {
  89         cglAvailable = initCGL();
  90     }
  91 
  92     private CGLGraphicsConfig(CGraphicsDevice device, int pixfmt,
  93                                 long configInfo, ContextCapabilities oglCaps)
  94     {
  95         super(device);
  96 
  97         this.pixfmt = pixfmt;
  98         this.pConfigInfo = configInfo;
  99         this.oglCaps = oglCaps;
 100         context = new OGLContext(OGLRenderQueue.getInstance(), this);
 101 
 102         // add a record to the Disposer so that we destroy the native
 103         // CGLGraphicsConfigInfo data when this object goes away
 104         Disposer.addRecord(disposerReferent,


 118                                          OGLSurfaceData.TEXTURE);
 119     }
 120 
 121     public static CGLGraphicsConfig getConfig(CGraphicsDevice device,
 122                                               int pixfmt)
 123     {
 124         if (!cglAvailable) {
 125             return null;
 126         }
 127 
 128         long cfginfo = 0;
 129         final String ids[] = new String[1];
 130         OGLRenderQueue rq = OGLRenderQueue.getInstance();
 131         rq.lock();
 132         try {
 133             // getCGLConfigInfo() creates and destroys temporary
 134             // surfaces/contexts, so we should first invalidate the current
 135             // Java-level context and flush the queue...
 136             OGLContext.invalidateCurrentContext();
 137 
 138             cfginfo = getCGLConfigInfo(device.getCGDisplayID(), pixfmt,
 139                                        kOpenGLSwapInterval);
 140             if (cfginfo != 0L) {
 141                 OGLContext.setScratchSurface(cfginfo);
 142                 rq.flushAndInvokeNow(new Runnable() {
 143                     public void run() {
 144                         ids[0] = OGLContext.getOGLIdString();
 145                     }
 146                 });
 147             }
 148         } finally {
 149             rq.unlock();
 150         }
 151         if (cfginfo == 0) {
 152             return null;
 153         }
 154 
 155         int oglCaps = getOGLCapabilities(cfginfo);
 156         ContextCapabilities caps = new OGLContextCaps(oglCaps, ids[0]);
 157 
 158         return new CGLGraphicsConfig(device, pixfmt, cfginfo, caps);
 159     }
 160 
 161     public static boolean isCGLAvailable() {
 162         return cglAvailable;
 163     }
 164 
 165     /**
 166      * Returns true if the provided capability bit is present for this config.
 167      * See OGLContext.java for a list of supported capabilities.


 235     //@Override
 236     public synchronized void displayChanged() {
 237         //super.displayChanged();
 238 
 239         // the context could hold a reference to a CGLSurfaceData, which in
 240         // turn has a reference back to this CGLGraphicsConfig, so in order
 241         // for this instance to be disposed we need to break the connection
 242         OGLRenderQueue rq = OGLRenderQueue.getInstance();
 243         rq.lock();
 244         try {
 245             OGLContext.invalidateCurrentContext();
 246         } finally {
 247             rq.unlock();
 248         }
 249 
 250         updateTotalDisplayBounds();
 251     }
 252 
 253     @Override
 254     public String toString() {
 255         int displayID = getDevice().getCGDisplayID();
 256         return ("CGLGraphicsConfig[dev="+displayID+",pixfmt="+pixfmt+"]");
 257     }
 258 
 259     @Override
 260     public SurfaceData createSurfaceData(CPlatformView pView) {
 261         return CGLSurfaceData.createData(pView);
 262     }
 263 
 264     @Override
 265     public SurfaceData createSurfaceData(CGLLayer layer) {
 266         return CGLSurfaceData.createData(layer);
 267     }
 268 
 269     @Override
 270     public Image createAcceleratedImage(Component target,
 271                                         int width, int height)
 272     {
 273         ColorModel model = getColorModel(Transparency.OPAQUE);
 274         WritableRaster wr = model.createCompatibleWritableRaster(width, height);
 275         return new OffScreenImage(target, model, wr,
 276                                   model.isAlphaPremultiplied());


 395         {
 396             vi.flush();
 397             vi = null;
 398         }
 399 
 400         return vi;
 401     }
 402 
 403     /**
 404      * {@inheritDoc}
 405      *
 406      * @see sun.java2d.pipe.hw.AccelGraphicsConfig#getContextCapabilities
 407      */
 408     @Override
 409     public ContextCapabilities getContextCapabilities() {
 410         return oglCaps;
 411     }
 412 
 413     @Override
 414     public void addDeviceEventListener(AccelDeviceEventListener l) {
 415         int displayID = getDevice().getCGDisplayID();
 416         AccelDeviceEventNotifier.addListener(l, displayID);
 417     }
 418 
 419     @Override
 420     public void removeDeviceEventListener(AccelDeviceEventListener l) {
 421         AccelDeviceEventNotifier.removeListener(l);
 422     }
 423 
 424     private static final Rectangle totalDisplayBounds = new Rectangle();
 425 
 426     private static void updateTotalDisplayBounds() {
 427         synchronized (totalDisplayBounds) {
 428             Rectangle virtualBounds = new Rectangle();
 429             for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
 430                 for (GraphicsConfiguration gc : gd.getConfigurations()) {
 431                     virtualBounds = virtualBounds.union(gc.getBounds());
 432                 }
 433             }
 434             totalDisplayBounds.setBounds(virtualBounds);
 435         }
 436     }