summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp/opengl/awt/Java2D.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-02-23 14:51:06 +0100
committerSven Gothel <[email protected]>2014-02-23 14:51:06 +0100
commit3352601e0860584509adf2b76f993d03893ded4b (patch)
tree974fccc8c0eb2f5ad9d4ffd741dfc35869ed67b5 /src/jogl/classes/jogamp/opengl/awt/Java2D.java
parentf51933f0ebe9ae030c26c066e59a728ce08b8559 (diff)
parentc67de337a8aaf52e36104c3f13e273aa19d21f1f (diff)
Merge branch 'master' into stash_glyphcache
Conflicts: make/scripts/tests.sh src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java src/jogl/classes/com/jogamp/graph/curve/Region.java src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java src/jogl/classes/com/jogamp/graph/curve/opengl/Renderer.java src/jogl/classes/com/jogamp/graph/curve/opengl/TextRenderer.java src/jogl/classes/com/jogamp/graph/font/Font.java src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java src/jogl/classes/jogamp/graph/curve/text/GlyphShape.java src/jogl/classes/jogamp/graph/curve/text/GlyphString.java src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java src/jogl/classes/jogamp/graph/font/typecast/TypecastRenderer.java
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/awt/Java2D.java')
-rw-r--r--src/jogl/classes/jogamp/opengl/awt/Java2D.java271
1 files changed, 153 insertions, 118 deletions
diff --git a/src/jogl/classes/jogamp/opengl/awt/Java2D.java b/src/jogl/classes/jogamp/opengl/awt/Java2D.java
index 3dbfefb19..886cd9368 100644
--- a/src/jogl/classes/jogamp/opengl/awt/Java2D.java
+++ b/src/jogl/classes/jogamp/opengl/awt/Java2D.java
@@ -1,21 +1,21 @@
/*
* Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* - Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
- *
+ *
* - Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- *
+ *
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
@@ -28,11 +28,11 @@
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
+ *
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
- *
+ *
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
@@ -69,6 +69,7 @@ public class Java2D {
private static boolean DEBUG = Debug.debug("Java2D");
private static boolean isHeadless;
private static boolean isOGLPipelineActive;
+ private static boolean isOGLPipelineResourceCompatible;
private static Method invokeWithOGLContextCurrentMethod;
private static Method isQueueFlusherThreadMethod;
private static Method getOGLViewportMethod;
@@ -115,6 +116,7 @@ public class Java2D {
static {
AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ @Override
public Object run() {
if (DEBUG) {
System.err.println("Checking for Java2D/OpenGL support");
@@ -124,18 +126,36 @@ public class Java2D {
isHeadless = true;
// Figure out whether the default graphics configuration is an
// OpenGL graphics configuration
- GraphicsConfiguration cfg =
- GraphicsEnvironment.getLocalGraphicsEnvironment().
- getDefaultScreenDevice().
- getDefaultConfiguration();
+ final GraphicsConfiguration cfg;
+ final String cfgName;
+ final boolean java2dOGLDisabledByOS = Platform.OS_TYPE == Platform.OSType.MACOS;
+ final boolean java2dOGLDisabledByProp;
+ {
+ boolean enabled = true;
+ final String sVal = System.getProperty("sun.java2d.opengl");
+ if( null != sVal ) {
+ enabled = Boolean.valueOf(sVal);
+ }
+ java2dOGLDisabledByProp = !enabled;
+ }
+ if( !java2dOGLDisabledByProp && !java2dOGLDisabledByOS ) {
+ cfg = GraphicsEnvironment.getLocalGraphicsEnvironment().
+ getDefaultScreenDevice().getDefaultConfiguration();
+ cfgName = cfg.getClass().getName();
+ } else {
+ if (DEBUG) {
+ System.err.println("Java2D support disabled: by Property "+java2dOGLDisabledByProp+", by OS "+java2dOGLDisabledByOS);
+ }
+ cfg = null;
+ cfgName = "nil";
+ }
// If we get here, we aren't running in headless mode
isHeadless = false;
- String name = cfg.getClass().getName();
if (DEBUG) {
- System.err.println("Java2D support: default GraphicsConfiguration = " + name);
+ System.err.println("Java2D support: default GraphicsConfiguration = " + cfgName);
}
- isOGLPipelineActive = Platform.OS_TYPE != Platform.OSType.MACOS &&
- (name.startsWith("sun.java2d.opengl"));
+ isOGLPipelineActive = cfgName.startsWith("sun.java2d.opengl");
+ isOGLPipelineResourceCompatible = isOGLPipelineActive;
if (isOGLPipelineActive) {
try {
@@ -152,99 +172,101 @@ public class Java2D {
new Class[] {});
isQueueFlusherThreadMethod.setAccessible(true);
- getOGLViewportMethod = utils.getDeclaredMethod("getOGLViewport",
- new Class[] {
- Graphics.class,
- Integer.TYPE,
- Integer.TYPE
- });
- getOGLViewportMethod.setAccessible(true);
-
- getOGLScissorBoxMethod = utils.getDeclaredMethod("getOGLScissorBox",
- new Class[] {
- Graphics.class
- });
- getOGLScissorBoxMethod.setAccessible(true);
-
- getOGLSurfaceIdentifierMethod = utils.getDeclaredMethod("getOGLSurfaceIdentifier",
+ if( isOGLPipelineResourceCompatible ) {
+ getOGLViewportMethod = utils.getDeclaredMethod("getOGLViewport",
+ new Class[] {
+ Graphics.class,
+ Integer.TYPE,
+ Integer.TYPE
+ });
+ getOGLViewportMethod.setAccessible(true);
+
+ getOGLScissorBoxMethod = utils.getDeclaredMethod("getOGLScissorBox",
+ new Class[] {
+ Graphics.class
+ });
+ getOGLScissorBoxMethod.setAccessible(true);
+
+ getOGLSurfaceIdentifierMethod = utils.getDeclaredMethod("getOGLSurfaceIdentifier",
+ new Class[] {
+ Graphics.class
+ });
+ getOGLSurfaceIdentifierMethod.setAccessible(true);
+
+ // Try to get additional methods required for proper FBO support
+ fbObjectSupportInitialized = true;
+ try {
+ invokeWithOGLSharedContextCurrentMethod = utils.getDeclaredMethod("invokeWithOGLSharedContextCurrent",
+ new Class[] {
+ GraphicsConfiguration.class,
+ Runnable.class
+ });
+ invokeWithOGLSharedContextCurrentMethod.setAccessible(true);
+
+ getOGLSurfaceTypeMethod = utils.getDeclaredMethod("getOGLSurfaceType",
new Class[] {
Graphics.class
});
- getOGLSurfaceIdentifierMethod.setAccessible(true);
-
- // Try to get additional methods required for proper FBO support
- fbObjectSupportInitialized = true;
- try {
- invokeWithOGLSharedContextCurrentMethod = utils.getDeclaredMethod("invokeWithOGLSharedContextCurrent",
- new Class[] {
- GraphicsConfiguration.class,
- Runnable.class
- });
- invokeWithOGLSharedContextCurrentMethod.setAccessible(true);
-
- getOGLSurfaceTypeMethod = utils.getDeclaredMethod("getOGLSurfaceType",
- new Class[] {
- Graphics.class
- });
- getOGLSurfaceTypeMethod.setAccessible(true);
- } catch (Exception e) {
- fbObjectSupportInitialized = false;
- if (DEBUG) {
- e.printStackTrace();
- System.err.println("Info: Disabling Java2D/JOGL FBO support");
- }
- }
-
- // Try to get an additional method for FBO support in recent Mustang builds
- try {
- getOGLTextureTypeMethod = utils.getDeclaredMethod("getOGLTextureType",
- new Class[] {
- Graphics.class
- });
- getOGLTextureTypeMethod.setAccessible(true);
- } catch (Exception e) {
- if (DEBUG) {
- e.printStackTrace();
- System.err.println("Info: GL_ARB_texture_rectangle FBO support disabled");
- }
- }
-
- // Try to set up APIs for enabling the bridge on OS X,
- // where it isn't possible to create generalized
- // external GLDrawables
- Class<?> cglSurfaceData = null;
- try {
- cglSurfaceData = Class.forName("sun.java2d.opengl.CGLSurfaceData");
- } catch (Exception e) {
- if (DEBUG) {
- e.printStackTrace();
- System.err.println("Info: Unable to find class sun.java2d.opengl.CGLSurfaceData for OS X");
- }
- }
- if (cglSurfaceData != null) {
- // FIXME: for now, assume that FBO support is not enabled on OS X
- fbObjectSupportInitialized = false;
-
- // We need to find these methods in order to make the bridge work on OS X
- createOGLContextOnSurfaceMethod = cglSurfaceData.getDeclaredMethod("createOGLContextOnSurface",
- new Class[] {
- Graphics.class,
- Long.TYPE
- });
- createOGLContextOnSurfaceMethod.setAccessible(true);
-
- makeOGLContextCurrentOnSurfaceMethod = cglSurfaceData.getDeclaredMethod("makeOGLContextCurrentOnSurface",
- new Class[] {
- Graphics.class,
- Long.TYPE
- });
- makeOGLContextCurrentOnSurfaceMethod.setAccessible(true);
-
- destroyOGLContextMethod = cglSurfaceData.getDeclaredMethod("destroyOGLContext",
- new Class[] {
- Long.TYPE
- });
- destroyOGLContextMethod.setAccessible(true);
+ getOGLSurfaceTypeMethod.setAccessible(true);
+ } catch (Exception e) {
+ fbObjectSupportInitialized = false;
+ if (DEBUG) {
+ e.printStackTrace();
+ System.err.println("Info: Disabling Java2D/JOGL FBO support");
+ }
+ }
+
+ // Try to get an additional method for FBO support in recent Mustang builds
+ try {
+ getOGLTextureTypeMethod = utils.getDeclaredMethod("getOGLTextureType",
+ new Class[] {
+ Graphics.class
+ });
+ getOGLTextureTypeMethod.setAccessible(true);
+ } catch (Exception e) {
+ if (DEBUG) {
+ e.printStackTrace();
+ System.err.println("Info: GL_ARB_texture_rectangle FBO support disabled");
+ }
+ }
+
+ // Try to set up APIs for enabling the bridge on OS X,
+ // where it isn't possible to create generalized
+ // external GLDrawables
+ Class<?> cglSurfaceData = null;
+ try {
+ cglSurfaceData = Class.forName("sun.java2d.opengl.CGLSurfaceData");
+ } catch (Exception e) {
+ if (DEBUG) {
+ e.printStackTrace();
+ System.err.println("Info: Unable to find class sun.java2d.opengl.CGLSurfaceData for OS X");
+ }
+ }
+ if (cglSurfaceData != null) {
+ // FIXME: for now, assume that FBO support is not enabled on OS X
+ fbObjectSupportInitialized = false;
+
+ // We need to find these methods in order to make the bridge work on OS X
+ createOGLContextOnSurfaceMethod = cglSurfaceData.getDeclaredMethod("createOGLContextOnSurface",
+ new Class[] {
+ Graphics.class,
+ Long.TYPE
+ });
+ createOGLContextOnSurfaceMethod.setAccessible(true);
+
+ makeOGLContextCurrentOnSurfaceMethod = cglSurfaceData.getDeclaredMethod("makeOGLContextCurrentOnSurface",
+ new Class[] {
+ Graphics.class,
+ Long.TYPE
+ });
+ makeOGLContextCurrentOnSurfaceMethod.setAccessible(true);
+
+ destroyOGLContextMethod = cglSurfaceData.getDeclaredMethod("destroyOGLContext",
+ new Class[] {
+ Long.TYPE
+ });
+ destroyOGLContextMethod.setAccessible(true);
+ }
}
} catch (Exception e) {
catched = e;
@@ -252,6 +274,7 @@ public class Java2D {
System.err.println("Info: Disabling Java2D/JOGL integration");
}
isOGLPipelineActive = false;
+ isOGLPipelineResourceCompatible = false;
}
}
} catch (HeadlessException e) {
@@ -265,7 +288,7 @@ public class Java2D {
if(null != catched) {
catched.printStackTrace();
}
- System.err.println("JOGL/Java2D integration " + (isOGLPipelineActive ? "enabled" : "disabled"));
+ System.err.println("JOGL/Java2D OGL Pipeline active " + isOGLPipelineActive + ", resourceCompatible "+isOGLPipelineResourceCompatible);
}
return null;
}
@@ -276,6 +299,10 @@ public class Java2D {
return isOGLPipelineActive;
}
+ public static boolean isOGLPipelineResourceCompatible() {
+ return isOGLPipelineResourceCompatible;
+ }
+
public static boolean isFBOEnabled() {
return fbObjectSupportInitialized;
}
@@ -291,7 +318,7 @@ public class Java2D {
throw (InternalError) new InternalError().initCause(e);
}
}
-
+
/** Makes current the OpenGL context associated with the passed
Graphics object and runs the given Runnable on the Queue
Flushing Thread in one atomic action. */
@@ -330,7 +357,7 @@ public class Java2D {
false if the passed GraphicsConfiguration was not an OpenGL
GraphicsConfiguration. */
public static boolean invokeWithOGLSharedContextCurrent(GraphicsConfiguration g, Runnable r) throws GLException {
- checkActive();
+ checkCompatible();
try {
AWTUtil.lockToolkit();
@@ -355,7 +382,7 @@ public class Java2D {
public static Rectangle getOGLViewport(Graphics g,
int componentWidth,
int componentHeight) {
- checkActive();
+ checkCompatible();
try {
return (Rectangle) getOGLViewportMethod.invoke(null, new Object[] {g,
@@ -375,7 +402,7 @@ public class Java2D {
passed to a call to glScissor(). Should only be called from the
Queue Flusher Thread. */
public static Rectangle getOGLScissorBox(Graphics g) {
- checkActive();
+ checkCompatible();
try {
return (Rectangle) getOGLScissorBoxMethod.invoke(null, new Object[] {g});
@@ -393,7 +420,7 @@ public class Java2D {
created (and the old ones destroyed). Should only be called from
the Queue Flusher Thread.*/
public static Object getOGLSurfaceIdentifier(Graphics g) {
- checkActive();
+ checkCompatible();
try {
return getOGLSurfaceIdentifierMethod.invoke(null, new Object[] {g});
@@ -408,7 +435,7 @@ public class Java2D {
object. This indicates, in particular, whether Java2D is
currently rendering into a pbuffer or FBO. */
public static int getOGLSurfaceType(Graphics g) {
- checkActive();
+ checkCompatible();
try {
// FIXME: fallback path for pre-b73 (?) Mustang builds -- remove
@@ -429,7 +456,7 @@ public class Java2D {
object assuming it is rendering to an FBO. Returns either
GL_TEXTURE_2D or GL_TEXTURE_RECTANGLE_ARB. */
public static int getOGLTextureType(Graphics g) {
- checkActive();
+ checkCompatible();
if (getOGLTextureTypeMethod == null) {
return GL.GL_TEXTURE_2D;
@@ -483,7 +510,7 @@ public class Java2D {
associated with the given Graphics object, sharing textures and
display lists with the specified (CGLContextObj) share context. */
public static long createOGLContextOnSurface(Graphics g, long shareCtx) {
- checkActive();
+ checkCompatible();
try {
return ((Long) createOGLContextOnSurfaceMethod.invoke(null, new Object[] { g, new Long(shareCtx) })).longValue();
@@ -497,7 +524,7 @@ public class Java2D {
/** (Mac OS X-specific) Makes the given OpenGL context current on
the surface associated with the given Graphics object. */
public static boolean makeOGLContextCurrentOnSurface(Graphics g, long ctx) {
- checkActive();
+ checkCompatible();
try {
return ((Boolean) makeOGLContextCurrentOnSurfaceMethod.invoke(null, new Object[] { g, new Long(ctx) })).booleanValue();
@@ -510,7 +537,7 @@ public class Java2D {
/** (Mac OS X-specific) Destroys the given OpenGL context. */
public static void destroyOGLContext(long ctx) {
- checkActive();
+ checkCompatible();
try {
destroyOGLContextMethod.invoke(null, new Object[] { new Long(ctx) });
@@ -527,12 +554,19 @@ public class Java2D {
private static void checkActive() {
if (!isOGLPipelineActive()) {
- throw new GLException("Java2D OpenGL pipeline not active (or necessary support not present)");
+ throw new GLException("Java2D OpenGL pipeline not active");
+ }
+ }
+
+ private static void checkCompatible() {
+ if ( !isOGLPipelineResourceCompatible() ) {
+ throw new GLException("Java2D OpenGL pipeline not resource compatible");
}
}
private static int getOGLUtilitiesIntField(final String name) {
Integer i = AccessController.doPrivileged(new PrivilegedAction<Integer>() {
+ @Override
public Integer run() {
try {
Class<?> utils = Class.forName("sun.java2d.opengl.OGLUtilities");
@@ -562,7 +596,7 @@ public class Java2D {
// Note 2: the first execution of this method must not be from the
// Java2D Queue Flusher Thread.
- if (isOGLPipelineActive() &&
+ if (isOGLPipelineResourceCompatible() &&
isFBOEnabled() &&
!initializedJ2DFBOShareContext) {
@@ -576,6 +610,7 @@ public class Java2D {
System.err.println("Starting initialization of J2D FBO share context");
}
invokeWithOGLSharedContextCurrent(device.getDefaultConfiguration(), new Runnable() {
+ @Override
public void run() {
j2dFBOShareContext = GLDrawableFactory.getFactory(GLProfile.getDefault(GLProfile.getDefaultDevice())).createExternalGLContext();
}