< prev index next >

src/java.desktop/share/classes/sun/java2d/opengl/OGLUtilities.java

Print this page




  64     public static boolean isQueueFlusherThread() {
  65         return OGLRenderQueue.isQueueFlusherThread();
  66     }
  67 
  68     /**
  69      * Invokes the given Runnable on the OGL QueueFlusher thread with the
  70      * OpenGL context corresponding to the given Graphics object made
  71      * current.  It is legal for OpenGL code executed in the given
  72      * Runnable to change the current OpenGL context; it will be reset
  73      * once the Runnable completes.  No guarantees are made as to the
  74      * state of the OpenGL context of the Graphics object; for
  75      * example, calling code must set the scissor box using the return
  76      * value from {@link #getOGLScissorBox} to avoid drawing
  77      * over other Swing components, and must typically set the OpenGL
  78      * viewport using the return value from {@link #getOGLViewport} to
  79      * make the client's OpenGL rendering appear in the correct place
  80      * relative to the scissor region.
  81      *
  82      * In order to avoid deadlock, it is important that the given Runnable
  83      * does not attempt to acquire the AWT lock, as that will be handled
  84      * automatically as part of the <code>rq.flushAndInvokeNow()</code> step.
  85      *
  86      * @param g the Graphics object for the corresponding destination surface;
  87      * if null, the step making a context current to the destination surface
  88      * will be skipped
  89      * @param r the action to be performed on the QFT; cannot be null
  90      * @return true if the operation completed successfully, or false if
  91      * there was any problem making a context current to the surface
  92      * associated with the given Graphics object
  93      */
  94     public static boolean invokeWithOGLContextCurrent(Graphics g, Runnable r) {
  95         OGLRenderQueue rq = OGLRenderQueue.getInstance();
  96         rq.lock();
  97         try {
  98             if (g != null) {
  99                 if (!(g instanceof SunGraphics2D)) {
 100                     return false;
 101                 }
 102                 SurfaceData sData = ((SunGraphics2D)g).surfaceData;
 103                 if (!(sData instanceof OGLSurfaceData)) {
 104                     return false;


 117         } finally {
 118             rq.unlock();
 119         }
 120 
 121         return true;
 122     }
 123 
 124     /**
 125      * Invokes the given Runnable on the OGL QueueFlusher thread with the
 126      * "shared" OpenGL context (corresponding to the given
 127      * GraphicsConfiguration object) made current.  This method is typically
 128      * used when the Runnable needs a current context to complete its
 129      * operation, but does not require that the context be made current to
 130      * a particular surface.  For example, an application may call this
 131      * method so that the given Runnable can query the OpenGL capabilities
 132      * of the given GraphicsConfiguration, without making a context current
 133      * to a dummy surface (or similar hacky techniques).
 134      *
 135      * In order to avoid deadlock, it is important that the given Runnable
 136      * does not attempt to acquire the AWT lock, as that will be handled
 137      * automatically as part of the <code>rq.flushAndInvokeNow()</code> step.
 138      *
 139      * @param config the GraphicsConfiguration object whose "shared"
 140      * context will be made current during this operation; if this value is
 141      * null or if OpenGL is not enabled for the GraphicsConfiguration, this
 142      * method will return false
 143      * @param r the action to be performed on the QFT; cannot be null
 144      * @return true if the operation completed successfully, or false if
 145      * there was any problem making the shared context current
 146      */
 147     public static boolean
 148         invokeWithOGLSharedContextCurrent(GraphicsConfiguration config,
 149                                           Runnable r)
 150     {
 151         if (!(config instanceof OGLGraphicsConfig)) {
 152             return false;
 153         }
 154 
 155         OGLRenderQueue rq = OGLRenderQueue.getInstance();
 156         rq.lock();
 157         try {


 280      * @return an identifier for the surface associated with the given
 281      * Graphics object, or null if the given Graphics object is invalid
 282      */
 283     public static Object getOGLSurfaceIdentifier(Graphics g) {
 284         if (!(g instanceof SunGraphics2D)) {
 285             return null;
 286         }
 287         return ((SunGraphics2D)g).surfaceData;
 288     }
 289 
 290     /**
 291      * Returns one of the OGL-specific surface type constants (defined in
 292      * this class), which describes the surface associated with the given
 293      * Graphics object.
 294      *
 295      * @param g the Graphics object for the corresponding destination surface;
 296      * cannot be null
 297      * @return a constant that describes the surface associated with the
 298      * given Graphics object; if the given Graphics object is invalid (i.e.
 299      * is not associated with an OpenGL surface) this method will return
 300      * <code>OGLUtilities.UNDEFINED</code>
 301      */
 302     public static int getOGLSurfaceType(Graphics g) {
 303         if (!(g instanceof SunGraphics2D)) {
 304             return UNDEFINED;
 305         }
 306         SurfaceData sData = ((SunGraphics2D)g).surfaceData;
 307         if (!(sData instanceof OGLSurfaceData)) {
 308             return UNDEFINED;
 309         }
 310         return ((OGLSurfaceData)sData).getType();
 311     }
 312 
 313     /**
 314      * Returns the OpenGL texture target constant (either GL_TEXTURE_2D
 315      * or GL_TEXTURE_RECTANGLE_ARB) for the surface associated with the
 316      * given Graphics object.  This method is only useful for those surface
 317      * types that are backed by an OpenGL texture, namely {@code TEXTURE},
 318      * {@code FBOBJECT}, and (on Windows only) {@code PBUFFER}.
 319      *
 320      * @param g the Graphics object for the corresponding destination surface;


  64     public static boolean isQueueFlusherThread() {
  65         return OGLRenderQueue.isQueueFlusherThread();
  66     }
  67 
  68     /**
  69      * Invokes the given Runnable on the OGL QueueFlusher thread with the
  70      * OpenGL context corresponding to the given Graphics object made
  71      * current.  It is legal for OpenGL code executed in the given
  72      * Runnable to change the current OpenGL context; it will be reset
  73      * once the Runnable completes.  No guarantees are made as to the
  74      * state of the OpenGL context of the Graphics object; for
  75      * example, calling code must set the scissor box using the return
  76      * value from {@link #getOGLScissorBox} to avoid drawing
  77      * over other Swing components, and must typically set the OpenGL
  78      * viewport using the return value from {@link #getOGLViewport} to
  79      * make the client's OpenGL rendering appear in the correct place
  80      * relative to the scissor region.
  81      *
  82      * In order to avoid deadlock, it is important that the given Runnable
  83      * does not attempt to acquire the AWT lock, as that will be handled
  84      * automatically as part of the {@code rq.flushAndInvokeNow()} step.
  85      *
  86      * @param g the Graphics object for the corresponding destination surface;
  87      * if null, the step making a context current to the destination surface
  88      * will be skipped
  89      * @param r the action to be performed on the QFT; cannot be null
  90      * @return true if the operation completed successfully, or false if
  91      * there was any problem making a context current to the surface
  92      * associated with the given Graphics object
  93      */
  94     public static boolean invokeWithOGLContextCurrent(Graphics g, Runnable r) {
  95         OGLRenderQueue rq = OGLRenderQueue.getInstance();
  96         rq.lock();
  97         try {
  98             if (g != null) {
  99                 if (!(g instanceof SunGraphics2D)) {
 100                     return false;
 101                 }
 102                 SurfaceData sData = ((SunGraphics2D)g).surfaceData;
 103                 if (!(sData instanceof OGLSurfaceData)) {
 104                     return false;


 117         } finally {
 118             rq.unlock();
 119         }
 120 
 121         return true;
 122     }
 123 
 124     /**
 125      * Invokes the given Runnable on the OGL QueueFlusher thread with the
 126      * "shared" OpenGL context (corresponding to the given
 127      * GraphicsConfiguration object) made current.  This method is typically
 128      * used when the Runnable needs a current context to complete its
 129      * operation, but does not require that the context be made current to
 130      * a particular surface.  For example, an application may call this
 131      * method so that the given Runnable can query the OpenGL capabilities
 132      * of the given GraphicsConfiguration, without making a context current
 133      * to a dummy surface (or similar hacky techniques).
 134      *
 135      * In order to avoid deadlock, it is important that the given Runnable
 136      * does not attempt to acquire the AWT lock, as that will be handled
 137      * automatically as part of the {@code rq.flushAndInvokeNow()} step.
 138      *
 139      * @param config the GraphicsConfiguration object whose "shared"
 140      * context will be made current during this operation; if this value is
 141      * null or if OpenGL is not enabled for the GraphicsConfiguration, this
 142      * method will return false
 143      * @param r the action to be performed on the QFT; cannot be null
 144      * @return true if the operation completed successfully, or false if
 145      * there was any problem making the shared context current
 146      */
 147     public static boolean
 148         invokeWithOGLSharedContextCurrent(GraphicsConfiguration config,
 149                                           Runnable r)
 150     {
 151         if (!(config instanceof OGLGraphicsConfig)) {
 152             return false;
 153         }
 154 
 155         OGLRenderQueue rq = OGLRenderQueue.getInstance();
 156         rq.lock();
 157         try {


 280      * @return an identifier for the surface associated with the given
 281      * Graphics object, or null if the given Graphics object is invalid
 282      */
 283     public static Object getOGLSurfaceIdentifier(Graphics g) {
 284         if (!(g instanceof SunGraphics2D)) {
 285             return null;
 286         }
 287         return ((SunGraphics2D)g).surfaceData;
 288     }
 289 
 290     /**
 291      * Returns one of the OGL-specific surface type constants (defined in
 292      * this class), which describes the surface associated with the given
 293      * Graphics object.
 294      *
 295      * @param g the Graphics object for the corresponding destination surface;
 296      * cannot be null
 297      * @return a constant that describes the surface associated with the
 298      * given Graphics object; if the given Graphics object is invalid (i.e.
 299      * is not associated with an OpenGL surface) this method will return
 300      * {@code OGLUtilities.UNDEFINED}
 301      */
 302     public static int getOGLSurfaceType(Graphics g) {
 303         if (!(g instanceof SunGraphics2D)) {
 304             return UNDEFINED;
 305         }
 306         SurfaceData sData = ((SunGraphics2D)g).surfaceData;
 307         if (!(sData instanceof OGLSurfaceData)) {
 308             return UNDEFINED;
 309         }
 310         return ((OGLSurfaceData)sData).getType();
 311     }
 312 
 313     /**
 314      * Returns the OpenGL texture target constant (either GL_TEXTURE_2D
 315      * or GL_TEXTURE_RECTANGLE_ARB) for the surface associated with the
 316      * given Graphics object.  This method is only useful for those surface
 317      * types that are backed by an OpenGL texture, namely {@code TEXTURE},
 318      * {@code FBOBJECT}, and (on Windows only) {@code PBUFFER}.
 319      *
 320      * @param g the Graphics object for the corresponding destination surface;
< prev index next >