aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-08-30 11:59:13 +0200
committerSven Gothel <[email protected]>2014-08-30 11:59:13 +0200
commit011e13e22fd52d2e82697ffee6b4c9ca8f3d549a (patch)
tree980d50a1f4ae441f38ce27708a408fb2ffe31778 /src
parent11347ad39059836f3e2a4f1fc592dc1e3fab6a09 (diff)
Bug 1055 - Access and query shared master GLContext in a deterministic fashion ; Don't use arbitrary shared context as 'master'.
GLContext* passes the shared-master to GLContextShareSet, which only creates a sets of shared contexts without differentiating the master context. GLContext*'s shared-slave attempts to lock the realized shared-master's surface at creation. Currently only an arbitrary shared context is selected due to the missing 'master' identity. The arbitrary shared context's surface is locked and its shared context handle used to create the slave context. Lacking of using the user given shared-master can lead to deadlock situations - and locking a 'wrong' surface. +++ The patch: - Allows query the user given shared-master! - Use the user given shared-master for locking and it's context handle for the slave's creation. - The shared-context mapping maps each shared-master to a shared-slave within one shared-context-set, allowing deterministic and individual shared-master queries.
Diffstat (limited to 'src')
-rw-r--r--src/jogl/classes/javax/media/opengl/GLContext.java10
-rw-r--r--src/jogl/classes/jogamp/opengl/GLContextImpl.java39
-rw-r--r--src/jogl/classes/jogamp/opengl/GLContextShareSet.java129
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES1NEWT.java9
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2AWT3.java18
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2AWT3b.java18
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT0.java45
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT1.java16
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT2.java95
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT3.java84
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT4.java231
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2SWT3.java18
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java10
13 files changed, 486 insertions, 236 deletions
diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java
index 9389ccabb..f4ba3c0b7 100644
--- a/src/jogl/classes/javax/media/opengl/GLContext.java
+++ b/src/jogl/classes/javax/media/opengl/GLContext.java
@@ -250,6 +250,16 @@ public abstract class GLContext {
return GLContextShareSet.isShared(this);
}
+ /**
+ * Returns the shared master GLContext of this GLContext if shared, otherwise return <code>null</code>.
+ * <p>
+ * Returns this GLContext, if it is a shared master.
+ * </p>
+ */
+ public final GLContext getSharedMaster() {
+ return GLContextShareSet.getSharedMaster(this);
+ }
+
/** Returns a new list of created GLContext shared with this GLContext. */
public final List<GLContext> getCreatedShares() {
return GLContextShareSet.getCreatedShares(this);
diff --git a/src/jogl/classes/jogamp/opengl/GLContextImpl.java b/src/jogl/classes/jogamp/opengl/GLContextImpl.java
index e278afc92..9280d9830 100644
--- a/src/jogl/classes/jogamp/opengl/GLContextImpl.java
+++ b/src/jogl/classes/jogamp/opengl/GLContextImpl.java
@@ -151,7 +151,9 @@ public abstract class GLContextImpl extends GLContext {
if ( null != shareWith ) {
GLContextShareSet.registerSharing(this, shareWith);
bufferObjectTracker = ((GLContextImpl)shareWith).getBufferObjectTracker();
- assert (bufferObjectTracker != null) : "shared context hash null GLBufferObjectTracker: "+shareWith;
+ if( null == bufferObjectTracker ) {
+ throw new InternalError("shared-master context hash null GLBufferObjectTracker: "+toHexString(shareWith.hashCode()));
+ }
} else {
bufferObjectTracker = new GLBufferObjectTracker();
}
@@ -661,6 +663,10 @@ public abstract class GLContextImpl extends GLContext {
return res;
}
+ private final GLContextImpl getOtherSharedMaster() {
+ final GLContextImpl sharedMaster = (GLContextImpl) GLContextShareSet.getSharedMaster(this);
+ return this != sharedMaster ? sharedMaster : null;
+ }
private final int makeCurrentWithinLock(final int surfaceLockRes) throws GLException {
if (!isCreated()) {
if( 0 >= drawable.getSurfaceWidth() || 0 >= drawable.getSurfaceHeight() ) {
@@ -675,22 +681,23 @@ public abstract class GLContextImpl extends GLContext {
additionalCtxCreationFlags |= GLContext.CTX_OPTION_DEBUG ;
}
- final GLContextImpl shareWith = (GLContextImpl) GLContextShareSet.getCreatedShare(this);
- final long shareWithHandle;
- if (null != shareWith) {
- if ( NativeSurface.LOCK_SURFACE_NOT_READY >= shareWith.drawable.lockSurface() ) {
- throw new GLException("GLContextShareSet could not lock surface: "+shareWith.drawable);
- }
- shareWithHandle = shareWith.getHandle();
- if (0 == shareWithHandle) {
- throw new GLException("GLContextShareSet returned an invalid OpenGL context: "+this);
+ final boolean created;
+ final GLContextImpl sharedMaster = getOtherSharedMaster();
+ if ( null != sharedMaster ) {
+ if ( NativeSurface.LOCK_SURFACE_NOT_READY >= sharedMaster.drawable.lockSurface() ) {
+ throw new GLException("GLContextShareSet could not lock sharedMaster surface: "+sharedMaster.drawable);
}
- } else {
- shareWithHandle = 0;
}
- final boolean created;
try {
- created = createImpl(shareWithHandle); // may throws exception if fails
+ if ( null != sharedMaster ) {
+ final long sharedMasterHandle = sharedMaster.getHandle();
+ if ( 0 == sharedMasterHandle ) {
+ throw new GLException("GLContextShareSet returned an invalid sharedMaster context: "+sharedMaster);
+ }
+ created = createImpl(sharedMasterHandle); // may throws exception if fails
+ } else {
+ created = createImpl(0); // may throws exception if fails
+ }
if( created && hasNoDefaultVAO() ) {
final int[] tmp = new int[1];
final GL rootGL = gl.getRootGL();
@@ -702,8 +709,8 @@ public abstract class GLContextImpl extends GLContext {
}
}
} finally {
- if (null != shareWith) {
- shareWith.drawable.unlockSurface();
+ if ( null != sharedMaster ) {
+ sharedMaster.drawable.unlockSurface();
}
}
if ( DEBUG_TRACE_SWITCH ) {
diff --git a/src/jogl/classes/jogamp/opengl/GLContextShareSet.java b/src/jogl/classes/jogamp/opengl/GLContextShareSet.java
index 209707f33..aed611edd 100644
--- a/src/jogl/classes/jogamp/opengl/GLContextShareSet.java
+++ b/src/jogl/classes/jogamp/opengl/GLContextShareSet.java
@@ -61,21 +61,33 @@ public class GLContextShareSet {
// to a share set, containing all shared contexts itself.
private static final Map<GLContext, ShareSet> shareMap = new IdentityHashMap<GLContext, ShareSet>();
- private static final Object dummyValue = new Object();
private static class ShareSet {
- private final Map<GLContext, Object> allShares = new IdentityHashMap<GLContext, Object>();
- private final Map<GLContext, Object> createdShares = new IdentityHashMap<GLContext, Object>();
- private final Map<GLContext, Object> destroyedShares = new IdentityHashMap<GLContext, Object>();
+ private final Map<GLContext, GLContext> createdShares = new IdentityHashMap<GLContext, GLContext>();
+ private final Map<GLContext, GLContext> destroyedShares = new IdentityHashMap<GLContext, GLContext>();
- public void add(final GLContext ctx) {
- if (allShares.put(ctx, dummyValue) == null) {
- if (ctx.isCreated()) {
- createdShares.put(ctx, dummyValue);
+ public final void addNew(final GLContext slave, final GLContext master) {
+ final GLContext preMaster;
+ if ( slave.isCreated() ) {
+ preMaster = createdShares.put(slave, master);
} else {
- destroyedShares.put(ctx, dummyValue);
+ preMaster= destroyedShares.put(slave, master);
+ }
+ if( null != preMaster ) {
+ throw new InternalError("State of ShareSet corrupted: Slave "+toHexString(slave.hashCode())+
+ " is not new w/ master "+toHexString(preMaster.hashCode()));
+ }
+ }
+ public final void addIfNew(final GLContext slave, final GLContext master) {
+ final GLContext preMaster = getMaster(master);
+ if( null == preMaster ) {
+ addNew(slave, master);
}
- }
+ }
+
+ public final GLContext getMaster(final GLContext ctx) {
+ final GLContext c = createdShares.get(ctx);
+ return null != c ? c : destroyedShares.get(ctx);
}
public Set<GLContext> getCreatedShares() {
@@ -86,57 +98,55 @@ public class GLContextShareSet {
return destroyedShares.keySet();
}
- public GLContext getCreatedShare(final GLContext ignore) {
- for (final Iterator<GLContext> iter = createdShares.keySet().iterator(); iter.hasNext(); ) {
- final GLContext ctx = iter.next();
- if (ctx != ignore) {
- return ctx;
- }
- }
- return null;
- }
-
public void contextCreated(final GLContext ctx) {
- final Object res = destroyedShares.remove(ctx);
- assert res != null : "State of ShareSet corrupted; thought context " +
- ctx + " should have been in destroyed set but wasn't";
- final Object res2 = createdShares.put(ctx, dummyValue);
- assert res2 == null : "State of ShareSet corrupted; thought context " +
- ctx + " shouldn't have been in created set but was";
+ final GLContext ctxMaster = destroyedShares.remove(ctx);
+ if( null == ctxMaster ) {
+ throw new InternalError("State of ShareSet corrupted: Context "+toHexString(ctx.hashCode())+
+ " should have been in destroyed-set");
+ }
+ final GLContext delMaster = createdShares.put(ctx, ctxMaster);
+ if( null != delMaster ) {
+ throw new InternalError("State of ShareSet corrupted: Context "+toHexString(ctx.hashCode())+
+ " shouldn't have been in created-set");
+ }
}
public void contextDestroyed(final GLContext ctx) {
- final Object res = createdShares.remove(ctx);
- assert res != null : "State of ShareSet corrupted; thought context " +
- ctx + " should have been in created set but wasn't";
- final Object res2 = destroyedShares.put(ctx, dummyValue);
- assert res2 == null : "State of ShareSet corrupted; thought context " +
- ctx + " shouldn't have been in destroyed set but was";
+ final GLContext ctxMaster = createdShares.remove(ctx);
+ if( null == ctxMaster ) {
+ throw new InternalError("State of ShareSet corrupted: Context "+toHexString(ctx.hashCode())+
+ " should have been in created-set");
+ }
+ final GLContext delMaster = destroyedShares.put(ctx, ctxMaster);
+ if( null != delMaster ) {
+ throw new InternalError("State of ShareSet corrupted: Context "+toHexString(ctx.hashCode())+
+ " shouldn't have been in destroyed-set");
+ }
}
}
- /** Indicate that contexts <code>share1</code> and
- <code>share2</code> will share textures and display lists. Both
+ /** Indicate that contexts <code>slave</code> and
+ <code>master</code> will share textures and display lists. Both
must be non-null. */
- public static synchronized void registerSharing(final GLContext share1, final GLContext share2) {
- if (share1 == null || share2 == null) {
- throw new IllegalArgumentException("Both share1 and share2 must be non-null");
- }
- ShareSet share = entryFor(share1);
- if (share == null) {
- share = entryFor(share2);
- }
- if (share == null) {
- share = new ShareSet();
- }
- share.add(share1);
- share.add(share2);
- addEntry(share1, share);
- addEntry(share2, share);
- if (DEBUG) {
- System.err.println("GLContextShareSet: registereSharing: 1: " +
- toHexString(share1.getHandle()) + ", 2: " + toHexString(share2.getHandle()));
- }
+ public static synchronized void registerSharing(final GLContext slave, final GLContext master) {
+ if (slave == null || master == null) {
+ throw new IllegalArgumentException("Both slave and master must be non-null");
+ }
+ ShareSet share = entryFor(slave);
+ if ( null == share ) {
+ share = entryFor(master);
+ }
+ if ( null == share ) {
+ share = new ShareSet();
+ }
+ share.addNew(slave, master);
+ share.addIfNew(master, master); // this master could have a different master shared registered earlier!
+ addEntry(slave, share);
+ addEntry(master, share);
+ if (DEBUG) {
+ System.err.println("GLContextShareSet: registereSharing: 1: " +
+ toHexString(slave.hashCode()) + ", 2: " + toHexString(master.hashCode()));
+ }
}
public static synchronized void unregisterSharing(final GLContext lastContext) {
@@ -157,7 +167,7 @@ public class GLContextShareSet {
}
if (DEBUG) {
System.err.println("GLContextShareSet: unregisterSharing: " +
- toHexString(lastContext.getHandle())+", entries: "+s.size());
+ toHexString(lastContext.hashCode())+", entries: "+s.size());
}
for(final Iterator<GLContext> iter = s.iterator() ; iter.hasNext() ; ) {
final GLContext ctx = iter.next();
@@ -176,13 +186,18 @@ public class GLContextShareSet {
return share != null;
}
- /** Returns one created GLContext shared with the given <code>context</code>, otherwise return <code>null</code>. */
- public static synchronized GLContext getCreatedShare(final GLContext context) {
+ /**
+ * Returns the shared master GLContext of the given <code>context</code> if shared, otherwise return <code>null</code>.
+ * <p>
+ * Returns the given <code>context</code>, if it is a shared master.
+ * </p>
+ */
+ public static synchronized GLContext getSharedMaster(final GLContext context) {
final ShareSet share = entryFor(context);
if (share == null) {
return null;
}
- return share.getCreatedShare(context);
+ return share.getMaster(context);
}
private static synchronized Set<GLContext> getCreatedSharesImpl(final GLContext context) {
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES1NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES1NEWT.java
index 8f84e293d..f1c72cf57 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES1NEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES1NEWT.java
@@ -138,12 +138,13 @@ public class TestSharedContextVBOES1NEWT extends UITestCase {
Assert.assertTrue(AWTRobotUtil.waitForVisible(glWindow, true));
Assert.assertTrue(AWTRobotUtil.waitForContextCreated(glWindow, true));
- System.err.println("Master Context: ");
- MiscUtils.dumpSharedGLContext(sharedDrawable.getContext());
- System.err.println("New Context: ");
- MiscUtils.dumpSharedGLContext(glWindow.getContext());
+ MiscUtils.dumpSharedGLContext("Master Context", sharedDrawable.getContext());
+ MiscUtils.dumpSharedGLContext("New Context", glWindow.getContext());
if( useShared ) {
Assert.assertEquals("Master Context not shared as expected", true, sharedDrawable.getContext().isShared());
+ Assert.assertEquals("Master Context is different", sharedDrawable.getContext(), glWindow.getContext().getSharedMaster());
+ } else {
+
}
Assert.assertEquals("New Context not shared as expected", useShared, glWindow.getContext().isShared());
Assert.assertEquals("Gears is not shared as expected", useShared, gears.usesSharedGears());
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2AWT3.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2AWT3.java
index a5b5653c0..fcbfcb19b 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2AWT3.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2AWT3.java
@@ -157,12 +157,9 @@ public class TestSharedContextVBOES2AWT3 extends UITestCase {
final List<GLContext> ctx1Shares = ctx1.getCreatedShares();
final List<GLContext> ctx2Shares = ctx2.getCreatedShares();
final List<GLContext> ctx3Shares = ctx3.getCreatedShares();
- System.err.println("XXX-C-3.1:");
- MiscUtils.dumpSharedGLContext(ctx1);
- System.err.println("XXX-C-3.2:");
- MiscUtils.dumpSharedGLContext(ctx2);
- System.err.println("XXX-C-3.3:");
- MiscUtils.dumpSharedGLContext(ctx3);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.1", ctx1);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.2", ctx2);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.3", ctx3);
Assert.assertTrue("Ctx1 is not shared", ctx1.isShared());
Assert.assertTrue("Ctx2 is not shared", ctx2.isShared());
@@ -307,12 +304,9 @@ public class TestSharedContextVBOES2AWT3 extends UITestCase {
final List<GLContext> ctx1Shares = ctx1.getCreatedShares();
final List<GLContext> ctx2Shares = ctx2.getCreatedShares();
final List<GLContext> ctx3Shares = ctx3.getCreatedShares();
- System.err.println("XXX-C-3.1:");
- MiscUtils.dumpSharedGLContext(ctx1);
- System.err.println("XXX-C-3.2:");
- MiscUtils.dumpSharedGLContext(ctx2);
- System.err.println("XXX-C-3.3:");
- MiscUtils.dumpSharedGLContext(ctx3);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.1", ctx1);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.2", ctx2);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.3", ctx3);
Assert.assertTrue("Ctx1 is not shared", ctx1.isShared());
Assert.assertTrue("Ctx2 is not shared", ctx2.isShared());
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2AWT3b.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2AWT3b.java
index 4c9cb7253..bac84d4fb 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2AWT3b.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2AWT3b.java
@@ -148,12 +148,9 @@ public class TestSharedContextVBOES2AWT3b extends UITestCase {
final List<GLContext> ctx1Shares = ctx1.getCreatedShares();
final List<GLContext> ctx2Shares = ctx2.getCreatedShares();
final List<GLContext> ctx3Shares = ctx3.getCreatedShares();
- System.err.println("XXX-C-3.1:");
- MiscUtils.dumpSharedGLContext(ctx1);
- System.err.println("XXX-C-3.2:");
- MiscUtils.dumpSharedGLContext(ctx2);
- System.err.println("XXX-C-3.3:");
- MiscUtils.dumpSharedGLContext(ctx3);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.1", ctx1);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.2", ctx2);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.3", ctx3);
Assert.assertTrue("Ctx1 is not shared", ctx1.isShared());
Assert.assertTrue("Ctx2 is not shared", ctx2.isShared());
@@ -260,12 +257,9 @@ public class TestSharedContextVBOES2AWT3b extends UITestCase {
final List<GLContext> ctx1Shares = ctx1.getCreatedShares();
final List<GLContext> ctx2Shares = ctx2.getCreatedShares();
final List<GLContext> ctx3Shares = ctx3.getCreatedShares();
- System.err.println("XXX-C-3.1:");
- MiscUtils.dumpSharedGLContext(ctx1);
- System.err.println("XXX-C-3.2:");
- MiscUtils.dumpSharedGLContext(ctx2);
- System.err.println("XXX-C-3.3:");
- MiscUtils.dumpSharedGLContext(ctx3);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.1", ctx1);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.2", ctx2);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.3", ctx3);
Assert.assertTrue("Ctx1 is not shared", ctx1.isShared());
Assert.assertTrue("Ctx2 is not shared", ctx2.isShared());
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT0.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT0.java
index d2d1384e4..eeab0869a 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT0.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT0.java
@@ -122,8 +122,7 @@ public class TestSharedContextVBOES2NEWT0 extends UITestCase {
Assert.assertTrue("Ctx is shared before shared creation", !ctx1.isShared());
final InsetsImmutable insets = f1.getInsets();
- System.err.println("XXX-C-2.1:");
- MiscUtils.dumpSharedGLContext(ctx1);
+ MiscUtils.dumpSharedGLContext("XXX-C-1.1", ctx1);
//
// 2nd
@@ -139,10 +138,8 @@ public class TestSharedContextVBOES2NEWT0 extends UITestCase {
{
final List<GLContext> ctx1Shares = ctx1.getCreatedShares();
final List<GLContext> ctx2Shares = ctx2.getCreatedShares();
- System.err.println("XXX-C-2.1:");
- MiscUtils.dumpSharedGLContext(ctx1);
- System.err.println("XXX-C-2.2:");
- MiscUtils.dumpSharedGLContext(ctx2);
+ MiscUtils.dumpSharedGLContext("XXX-C-2.1", ctx1);
+ MiscUtils.dumpSharedGLContext("XXX-C-2.2", ctx2);
Assert.assertEquals("Ctx1 has unexpected number of created shares", 1, ctx1Shares.size());
Assert.assertEquals("Ctx2 has unexpected number of created shares", 1, ctx2Shares.size());
@@ -165,12 +162,9 @@ public class TestSharedContextVBOES2NEWT0 extends UITestCase {
final List<GLContext> ctx1Shares = ctx1.getCreatedShares();
final List<GLContext> ctx2Shares = ctx2.getCreatedShares();
final List<GLContext> ctx3Shares = ctx3.getCreatedShares();
- System.err.println("XXX-C-3.1:");
- MiscUtils.dumpSharedGLContext(ctx1);
- System.err.println("XXX-C-3.2:");
- MiscUtils.dumpSharedGLContext(ctx2);
- System.err.println("XXX-C-3.3:");
- MiscUtils.dumpSharedGLContext(ctx3);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.1", ctx1);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.2", ctx2);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.3", ctx3);
Assert.assertEquals("Ctx1 has unexpected number of created shares", 2, ctx1Shares.size());
Assert.assertEquals("Ctx2 has unexpected number of created shares", 2, ctx2Shares.size());
@@ -197,12 +191,9 @@ public class TestSharedContextVBOES2NEWT0 extends UITestCase {
final List<GLContext> ctx1Shares = ctx1.getCreatedShares();
final List<GLContext> ctx2Shares = ctx2.getCreatedShares();
final List<GLContext> ctx3Shares = ctx3.getCreatedShares();
- System.err.println("XXX-D-0.1:");
- MiscUtils.dumpSharedGLContext(ctx1);
- System.err.println("XXX-D-0.2:");
- MiscUtils.dumpSharedGLContext(ctx2);
- System.err.println("XXX-D-0.3:");
- MiscUtils.dumpSharedGLContext(ctx3);
+ MiscUtils.dumpSharedGLContext("XXX-D-0.1", ctx1);
+ MiscUtils.dumpSharedGLContext("XXX-D-0.2", ctx2);
+ MiscUtils.dumpSharedGLContext("XXX-D-0.3", ctx3);
Assert.assertTrue("Ctx1 is shared", ctx1.isShared());
Assert.assertTrue("Ctx2 is shared", ctx2.isShared());
@@ -221,12 +212,9 @@ public class TestSharedContextVBOES2NEWT0 extends UITestCase {
final List<GLContext> ctx1Shares = ctx1.getCreatedShares();
final List<GLContext> ctx2Shares = ctx2.getCreatedShares();
final List<GLContext> ctx3Shares = ctx3.getCreatedShares();
- System.err.println("XXX-D-1.1:");
- MiscUtils.dumpSharedGLContext(ctx1);
- System.err.println("XXX-D-1.2:");
- MiscUtils.dumpSharedGLContext(ctx2);
- System.err.println("XXX-D-1.3:");
- MiscUtils.dumpSharedGLContext(ctx3);
+ MiscUtils.dumpSharedGLContext("XXX-D-1.1", ctx1);
+ MiscUtils.dumpSharedGLContext("XXX-D-1.2", ctx2);
+ MiscUtils.dumpSharedGLContext("XXX-D-1.3", ctx3);
Assert.assertTrue("Ctx1 is not shared", ctx1.isShared());
Assert.assertTrue("Ctx2 is not shared", ctx2.isShared());
@@ -245,12 +233,9 @@ public class TestSharedContextVBOES2NEWT0 extends UITestCase {
final List<GLContext> ctx1Shares = ctx1.getCreatedShares();
final List<GLContext> ctx2Shares = ctx2.getCreatedShares();
final List<GLContext> ctx3Shares = ctx3.getCreatedShares();
- System.err.println("XXX-D-2.1:");
- MiscUtils.dumpSharedGLContext(ctx1);
- System.err.println("XXX-D-2.2:");
- MiscUtils.dumpSharedGLContext(ctx2);
- System.err.println("XXX-D-2.3:");
- MiscUtils.dumpSharedGLContext(ctx3);
+ MiscUtils.dumpSharedGLContext("XXX-D-2.1", ctx1);
+ MiscUtils.dumpSharedGLContext("XXX-D-2.2", ctx2);
+ MiscUtils.dumpSharedGLContext("XXX-D-2.3", ctx3);
Assert.assertTrue("Ctx1 is not shared", !ctx1.isShared());
Assert.assertTrue("Ctx2 is not shared", !ctx2.isShared());
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT1.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT1.java
index fb15509d0..e98957464 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT1.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT1.java
@@ -153,12 +153,14 @@ public class TestSharedContextVBOES2NEWT1 extends UITestCase {
Assert.assertTrue(AWTRobotUtil.waitForVisible(glWindow, true));
Assert.assertTrue(AWTRobotUtil.waitForContextCreated(glWindow, true));
- System.err.println("Master Context: ");
- MiscUtils.dumpSharedGLContext(sharedDrawable.getContext());
- System.err.println("New Context: ");
- MiscUtils.dumpSharedGLContext(glWindow.getContext());
+ final GLContext sharedMasterContext = sharedDrawable.getContext();
+ MiscUtils.dumpSharedGLContext("Master Context", sharedMasterContext);
+ MiscUtils.dumpSharedGLContext("New Context", glWindow.getContext());
if( useShared ) {
- Assert.assertEquals("Master Context not shared as expected", true, sharedDrawable.getContext().isShared());
+ Assert.assertEquals("Master Context not shared as expected", true, sharedMasterContext.isShared());
+ Assert.assertEquals("Master Context is different", sharedMasterContext, glWindow.getContext().getSharedMaster());
+ } else {
+ Assert.assertEquals("Master Context is not null", null, glWindow.getContext().getSharedMaster());
}
Assert.assertEquals("New Context not shared as expected", useShared, glWindow.getContext().isShared());
@@ -169,7 +171,7 @@ public class TestSharedContextVBOES2NEWT1 extends UITestCase {
return glWindow;
}
- @Test
+ // @Test
public void test01CommonAnimatorSharedOnscreen() throws InterruptedException {
initShared(true);
final Animator animator = new Animator();
@@ -202,7 +204,7 @@ public class TestSharedContextVBOES2NEWT1 extends UITestCase {
releaseShared();
}
- @Test
+ // @Test
public void test02CommonAnimatorSharedOffscreen() throws InterruptedException {
initShared(false);
final Animator animator = new Animator();
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT2.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT2.java
index a101c05d0..fb09e86ef 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT2.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT2.java
@@ -55,9 +55,8 @@ import org.junit.runners.MethodSorters;
* Sharing the VBO of 3 GearsES2 instances, each in their own GLWindow.
* <p>
* This is achieved by using the 1st GLWindow's GLContext as the <i>master</i>
- * and manually triggering creation of the 2nd and 3rd GLWindow when the 1st GLWindow's
- * GLContext becomes created. The trigger is performed by simply
- * inserting a GLRunnable in the 1st GLWindow, which makes the other visible.
+ * and synchronizing via GLSharedContextSetter to postpone creation
+ * of the 2nd and 3rd GLWindow until the 1st GLWindow's GLContext becomes created.
* </p>
* <p>
* Above method allows random creation of the 1st GLWindow, which triggers
@@ -107,6 +106,8 @@ public class TestSharedContextVBOES2NEWT2 extends UITestCase {
public void syncedOneAnimator(final boolean destroyCleanOrder) throws InterruptedException {
final Animator animator = new Animator();
+ animator.start();
+
final GearsES2 g1 = new GearsES2(0);
final GLWindow f1 = createGLWindow(0, 0, g1);
animator.add(f1);
@@ -116,31 +117,31 @@ public class TestSharedContextVBOES2NEWT2 extends UITestCase {
g2.setSharedGears(g1);
final GLWindow f2 = createGLWindow(f1.getX()+width+insets.getTotalWidth(),
f1.getY()+0, g2);
+ f2.setSharedAutoDrawable(f1);
animator.add(f2);
+ f2.setVisible(true);
final GearsES2 g3 = new GearsES2(0);
g3.setSharedGears(g1);
final GLWindow f3 = createGLWindow(f1.getX()+0,
f1.getY()+height+insets.getTotalHeight(), g3);
+ f3.setSharedAutoDrawable(f1);
animator.add(f3);
+ f3.setVisible(true);
- // f1's shared GLContext is ready !
- f1.invoke(false, new GLRunnable() {
- @Override
- public boolean run(final GLAutoDrawable drawable) {
- Assert.assertTrue("Ctx is shared before shared creation", !f1.getContext().isShared());
- f2.setSharedAutoDrawable(f1);
- f2.setVisible(true);
- f2.display(); // kick off GLContext ..
- f3.setSharedAutoDrawable(f1);
- f3.setVisible(true);
- f3.display(); // kick off GLContext ..
- return true;
- }
- });
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(f1, false));
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(f1, false));
+ Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f1, false));
- f1.setVisible(true);
- f1.display(); // kick off GLContext .. and hence f2 + f3 creation
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(f2, true));
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(f2, true));
+ Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f2, false));
+
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(f3, true));
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(f3, true));
+ Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f3, false));
+
+ f1.setVisible(true); // kick off f1 GLContext .. and hence allow f2 + f3 creation
Assert.assertTrue(AWTRobotUtil.waitForRealized(f1, true));
Assert.assertTrue(AWTRobotUtil.waitForVisible(f1, true));
@@ -157,8 +158,6 @@ public class TestSharedContextVBOES2NEWT2 extends UITestCase {
Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f3, true));
Assert.assertTrue("Gears3 not initialized", g3.waitForInit(true));
- animator.start(); // post start animator, otherwise display will be suppressed
-
final GLContext ctx1 = f1.getContext();
final GLContext ctx2 = f2.getContext();
final GLContext ctx3 = f3.getContext();
@@ -166,12 +165,9 @@ public class TestSharedContextVBOES2NEWT2 extends UITestCase {
final List<GLContext> ctx1Shares = ctx1.getCreatedShares();
final List<GLContext> ctx2Shares = ctx2.getCreatedShares();
final List<GLContext> ctx3Shares = ctx3.getCreatedShares();
- System.err.println("XXX-C-3.1:");
- MiscUtils.dumpSharedGLContext(ctx1);
- System.err.println("XXX-C-3.2:");
- MiscUtils.dumpSharedGLContext(ctx2);
- System.err.println("XXX-C-3.3:");
- MiscUtils.dumpSharedGLContext(ctx3);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.1", ctx1);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.2", ctx2);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.3", ctx3);
Assert.assertTrue("Ctx1 is not shared", ctx1.isShared());
Assert.assertTrue("Ctx2 is not shared", ctx2.isShared());
@@ -179,6 +175,9 @@ public class TestSharedContextVBOES2NEWT2 extends UITestCase {
Assert.assertEquals("Ctx1 has unexpected number of created shares", 2, ctx1Shares.size());
Assert.assertEquals("Ctx2 has unexpected number of created shares", 2, ctx2Shares.size());
Assert.assertEquals("Ctx3 has unexpected number of created shares", 2, ctx3Shares.size());
+ Assert.assertEquals("Ctx1 Master Context is different", ctx1, ctx1.getSharedMaster());
+ Assert.assertEquals("Ctx2 Master Context is different", ctx1, ctx2.getSharedMaster());
+ Assert.assertEquals("Ctx3 Master Context is different", ctx1, ctx3.getSharedMaster());
}
Assert.assertTrue("Gears1 is shared", !g1.usesSharedGears());
@@ -228,7 +227,6 @@ public class TestSharedContextVBOES2NEWT2 extends UITestCase {
final GLWindow f1 = createGLWindow(0, 0, g1);
a1.add(f1);
a1.start();
- f1.setVisible(true);
final InsetsImmutable insets = f1.getInsets();
@@ -237,29 +235,34 @@ public class TestSharedContextVBOES2NEWT2 extends UITestCase {
g2.setSharedGears(g1);
final GLWindow f2 = createGLWindow(f1.getX()+width+insets.getTotalWidth(),
f1.getY()+0, g2);
+ f2.setSharedAutoDrawable(f1);
a2.add(f2);
a2.start();
+ f2.setVisible(true);
final Animator a3 = new Animator();
final GearsES2 g3 = new GearsES2(0);
g3.setSharedGears(g1);
final GLWindow f3 = createGLWindow(f1.getX()+0,
f1.getY()+height+insets.getTotalHeight(), g3);
+ f3.setSharedAutoDrawable(f1);
a3.add(f3);
a3.start();
+ f3.setVisible(true);
- // f1's shared GLContext is ready !
- f1.invoke(false, new GLRunnable() {
- @Override
- public boolean run(final GLAutoDrawable drawable) {
- Assert.assertTrue("Ctx is shared before shared creation", !f1.getContext().isShared());
- f2.setSharedAutoDrawable(f1);
- f2.setVisible(true);
- f3.setSharedAutoDrawable(f1);
- f3.setVisible(true);
- return true;
- }
- });
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(f1, false));
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(f1, false));
+ Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f1, false));
+
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(f2, true));
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(f2, true));
+ Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f2, false));
+
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(f3, true));
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(f3, true));
+ Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f3, false));
+
+ f1.setVisible(true); // kicks off f1 GLContext .. and hence gears of f2 + f3 completion
Assert.assertTrue(AWTRobotUtil.waitForRealized(f1, true));
Assert.assertTrue(AWTRobotUtil.waitForVisible(f1, true));
@@ -282,12 +285,9 @@ public class TestSharedContextVBOES2NEWT2 extends UITestCase {
final List<GLContext> ctx1Shares = ctx1.getCreatedShares();
final List<GLContext> ctx2Shares = ctx2.getCreatedShares();
final List<GLContext> ctx3Shares = ctx3.getCreatedShares();
- System.err.println("XXX-C-3.1:");
- MiscUtils.dumpSharedGLContext(ctx1);
- System.err.println("XXX-C-3.2:");
- MiscUtils.dumpSharedGLContext(ctx2);
- System.err.println("XXX-C-3.3:");
- MiscUtils.dumpSharedGLContext(ctx3);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.1", ctx1);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.2", ctx2);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.3", ctx3);
Assert.assertTrue("Ctx1 is not shared", ctx1.isShared());
Assert.assertTrue("Ctx2 is not shared", ctx2.isShared());
@@ -295,6 +295,9 @@ public class TestSharedContextVBOES2NEWT2 extends UITestCase {
Assert.assertEquals("Ctx1 has unexpected number of created shares", 2, ctx1Shares.size());
Assert.assertEquals("Ctx2 has unexpected number of created shares", 2, ctx2Shares.size());
Assert.assertEquals("Ctx3 has unexpected number of created shares", 2, ctx3Shares.size());
+ Assert.assertEquals("Ctx1 Master Context is different", ctx1, ctx1.getSharedMaster());
+ Assert.assertEquals("Ctx2 Master Context is different", ctx1, ctx2.getSharedMaster());
+ Assert.assertEquals("Ctx3 Master Context is different", ctx1, ctx3.getSharedMaster());
}
Assert.assertTrue("Gears1 is shared", !g1.usesSharedGears());
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT3.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT3.java
index bfd1a92ce..852b7193e 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT3.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT3.java
@@ -53,7 +53,7 @@ import org.junit.runners.MethodSorters;
* Sharing the VBO of 3 GearsES2 instances, each in their own GLWindow.
* <p>
* This is achieved by using the 1st GLWindow as the <i>master</i>
- * and using the build-in blocking mechanism to postpone creation
+ * and synchronizing via GLSharedContextSetter to postpone creation
* of the 2nd and 3rd GLWindow until the 1st GLWindow's GLContext becomes created.
* </p>
* <p>
@@ -112,6 +112,8 @@ public class TestSharedContextVBOES2NEWT3 extends UITestCase {
public void syncedOneAnimator(final boolean destroyCleanOrder, final boolean useMappedBuffers) throws InterruptedException {
final Animator animator = new Animator();
+ animator.start();
+
final GearsES2 g1 = new GearsES2(0);
g1.setUseMappedBuffers(useMappedBuffers);
g1.setValidateBuffers(true);
@@ -125,20 +127,17 @@ public class TestSharedContextVBOES2NEWT3 extends UITestCase {
f1.getY()+0, g2);
f2.setSharedAutoDrawable(f1);
animator.add(f2);
+ f2.setVisible(true); // shall wait until f1 is ready
- final GearsES2 g3 = new GearsES2(0);
- g3.setSharedGears(g1);
- final GLWindow f3 = createGLWindow(f1.getX()+0,
- f1.getY()+height+insets.getTotalHeight(), g3);
- f3.setSharedAutoDrawable(f1);
- animator.add(f3);
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(f1, false));
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(f1, false));
+ Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f1, false));
- f2.setVisible(true); // shall wait until f1 is ready
- f1.setVisible(true); // master ..
- f3.setVisible(true); // shall wait until f1 is ready
- animator.start(); // kicks off GLContext .. and hence gears of f2 + f3 completion
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(f2, true));
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(f2, true));
+ Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f2, false));
- Thread.sleep(1000/60*10); // wait ~10 frames giving a chance to create (blocking until master share is valid)
+ f1.setVisible(true); // kicks off f1 GLContext .. and hence gears of f2 + f3 completion
Assert.assertTrue(AWTRobotUtil.waitForRealized(f1, true));
Assert.assertTrue(AWTRobotUtil.waitForVisible(f1, true));
@@ -150,6 +149,14 @@ public class TestSharedContextVBOES2NEWT3 extends UITestCase {
Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f2, true));
Assert.assertTrue("Gears2 not initialized", g2.waitForInit(true));
+ final GearsES2 g3 = new GearsES2(0);
+ g3.setSharedGears(g1);
+ final GLWindow f3 = createGLWindow(f1.getX()+0,
+ f1.getY()+height+insets.getTotalHeight(), g3);
+ f3.setSharedAutoDrawable(f1);
+ animator.add(f3);
+ f3.setVisible(true); // shall wait until f1 is ready
+
Assert.assertTrue(AWTRobotUtil.waitForRealized(f3, true));
Assert.assertTrue(AWTRobotUtil.waitForVisible(f3, true));
Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f3, true));
@@ -162,12 +169,9 @@ public class TestSharedContextVBOES2NEWT3 extends UITestCase {
final List<GLContext> ctx1Shares = ctx1.getCreatedShares();
final List<GLContext> ctx2Shares = ctx2.getCreatedShares();
final List<GLContext> ctx3Shares = ctx3.getCreatedShares();
- System.err.println("XXX-C-3.1:");
- MiscUtils.dumpSharedGLContext(ctx1);
- System.err.println("XXX-C-3.2:");
- MiscUtils.dumpSharedGLContext(ctx2);
- System.err.println("XXX-C-3.3:");
- MiscUtils.dumpSharedGLContext(ctx3);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.1", ctx1);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.2", ctx2);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.3", ctx3);
Assert.assertTrue("Ctx1 is not shared", ctx1.isShared());
Assert.assertTrue("Ctx2 is not shared", ctx2.isShared());
@@ -175,6 +179,9 @@ public class TestSharedContextVBOES2NEWT3 extends UITestCase {
Assert.assertEquals("Ctx1 has unexpected number of created shares", 2, ctx1Shares.size());
Assert.assertEquals("Ctx2 has unexpected number of created shares", 2, ctx2Shares.size());
Assert.assertEquals("Ctx3 has unexpected number of created shares", 2, ctx3Shares.size());
+ Assert.assertEquals("Ctx1 Master Context is different", ctx1, ctx1.getSharedMaster());
+ Assert.assertEquals("Ctx2 Master Context is different", ctx1, ctx2.getSharedMaster());
+ Assert.assertEquals("Ctx3 Master Context is different", ctx1, ctx3.getSharedMaster());
}
Assert.assertTrue("Gears1 is shared", !g1.usesSharedGears());
@@ -246,7 +253,6 @@ public class TestSharedContextVBOES2NEWT3 extends UITestCase {
final GLWindow f1 = createGLWindow(0, 0, g1);
a1.add(f1);
a1.start();
- // f1.setVisible(true); // we do this post f2 .. to test pending creation!
final InsetsImmutable insets = f1.getInsets();
@@ -260,19 +266,15 @@ public class TestSharedContextVBOES2NEWT3 extends UITestCase {
a2.start();
f2.setVisible(true);
- f1.setVisible(true); // test pending creation of f2
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(f1, false));
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(f1, false));
+ Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f1, false));
- final Animator a3 = new Animator();
- final GearsES2 g3 = new GearsES2(0);
- g3.setSharedGears(g1);
- final GLWindow f3 = createGLWindow(f1.getX()+0,
- f1.getY()+height+insets.getTotalHeight(), g3);
- f3.setSharedAutoDrawable(f1);
- a3.add(f3);
- a3.start();
- f3.setVisible(true);
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(f2, true));
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(f2, true));
+ Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f2, false));
- Thread.sleep(1000/60*10); // wait ~10 frames giving a chance to create (blocking until master share is valid)
+ f1.setVisible(true); // test pending creation of f2
Assert.assertTrue(AWTRobotUtil.waitForRealized(f1, true));
Assert.assertTrue(AWTRobotUtil.waitForVisible(f1, true));
@@ -284,6 +286,16 @@ public class TestSharedContextVBOES2NEWT3 extends UITestCase {
Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f2, true));
Assert.assertTrue("Gears2 not initialized", g2.waitForInit(true));
+ final Animator a3 = new Animator();
+ final GearsES2 g3 = new GearsES2(0);
+ g3.setSharedGears(g1);
+ final GLWindow f3 = createGLWindow(f1.getX()+0,
+ f1.getY()+height+insets.getTotalHeight(), g3);
+ f3.setSharedAutoDrawable(f1);
+ a3.add(f3);
+ a3.start();
+ f3.setVisible(true);
+
Assert.assertTrue(AWTRobotUtil.waitForRealized(f3, true));
Assert.assertTrue(AWTRobotUtil.waitForVisible(f3, true));
Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f3, true));
@@ -296,12 +308,9 @@ public class TestSharedContextVBOES2NEWT3 extends UITestCase {
final List<GLContext> ctx1Shares = ctx1.getCreatedShares();
final List<GLContext> ctx2Shares = ctx2.getCreatedShares();
final List<GLContext> ctx3Shares = ctx3.getCreatedShares();
- System.err.println("XXX-C-3.1:");
- MiscUtils.dumpSharedGLContext(ctx1);
- System.err.println("XXX-C-3.2:");
- MiscUtils.dumpSharedGLContext(ctx2);
- System.err.println("XXX-C-3.3:");
- MiscUtils.dumpSharedGLContext(ctx3);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.1", ctx1);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.2", ctx2);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.3", ctx3);
Assert.assertTrue("Ctx1 is not shared", ctx1.isShared());
Assert.assertTrue("Ctx2 is not shared", ctx2.isShared());
@@ -309,6 +318,9 @@ public class TestSharedContextVBOES2NEWT3 extends UITestCase {
Assert.assertEquals("Ctx1 has unexpected number of created shares", 2, ctx1Shares.size());
Assert.assertEquals("Ctx2 has unexpected number of created shares", 2, ctx2Shares.size());
Assert.assertEquals("Ctx3 has unexpected number of created shares", 2, ctx3Shares.size());
+ Assert.assertEquals("Ctx1 Master Context is different", ctx1, ctx1.getSharedMaster());
+ Assert.assertEquals("Ctx2 Master Context is different", ctx1, ctx2.getSharedMaster());
+ Assert.assertEquals("Ctx3 Master Context is different", ctx1, ctx3.getSharedMaster());
}
Assert.assertTrue("Gears1 is shared", !g1.usesSharedGears());
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT4.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT4.java
new file mode 100644
index 000000000..804badbc3
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT4.java
@@ -0,0 +1,231 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.acore;
+
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import com.jogamp.newt.opengl.GLWindow;
+
+import javax.media.nativewindow.util.InsetsImmutable;
+import javax.media.opengl.GLAnimatorControl;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLContext;
+import javax.media.opengl.GLProfile;
+
+import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.FixMethodOrder;
+import org.junit.runners.MethodSorters;
+
+/**
+ * Test sharing w/ different shared-master context.
+ * <p>
+ * This is achieved by using the 1st GLWindow as the <i>master</i>
+ * and synchronizing via GLSharedContextSetter to postpone creation
+ * of the 2nd and 3rd GLWindow until the 1st GLWindow's GLContext becomes created.
+ * </p>
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestSharedContextVBOES2NEWT4 extends UITestCase {
+ static GLProfile glp;
+ static GLCapabilities caps;
+ static int width, height;
+
+ @BeforeClass
+ public static void initClass() {
+ if(GLProfile.isAvailable(GLProfile.GL2ES2)) {
+ glp = GLProfile.get(GLProfile.GL2ES2);
+ Assert.assertNotNull(glp);
+ caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ width = 256;
+ height = 256;
+ } else {
+ setTestSupported(false);
+ }
+ }
+
+ protected GLWindow createGLWindow(final int x, final int y, final GearsES2 gears) throws InterruptedException {
+ final GLWindow glWindow = GLWindow.create(caps);
+ Assert.assertNotNull(glWindow);
+ glWindow.setPosition(x, y);
+ glWindow.setTitle("Shared Gears NEWT Test: "+x+"/"+y+" shared true");
+ glWindow.setSize(width, height);
+ glWindow.addGLEventListener(gears);
+
+ return glWindow;
+ }
+
+ @Test
+ public void test01() throws InterruptedException {
+ final Animator animator = new Animator();
+ animator.start();
+
+ final GearsES2 g1 = new GearsES2(0);
+ final GLWindow f1 = createGLWindow(0, 0, g1);
+ animator.add(f1);
+ final InsetsImmutable insets = f1.getInsets();
+
+ final GearsES2 g2 = new GearsES2(0);
+ g2.setSharedGears(g1);
+ final GLWindow f2 = createGLWindow(f1.getX()+width+insets.getTotalWidth(),
+ f1.getY()+0, g2);
+ f2.setSharedAutoDrawable(f1);
+ animator.add(f2);
+ f2.setVisible(true);
+
+ final GearsES2 g3 = new GearsES2(0);
+ g3.setSharedGears(g1);
+ final GLWindow f3 = createGLWindow(f1.getX()+0,
+ f1.getY()+height+insets.getTotalHeight(), g3);
+ f3.setSharedAutoDrawable(f2); // Mixed master!
+ animator.add(f3);
+ final AtomicBoolean gotAnimException = new AtomicBoolean(false);
+ final AtomicBoolean gotOtherException = new AtomicBoolean(false);
+ animator.setUncaughtExceptionHandler(new GLAnimatorControl.UncaughtExceptionHandler() {
+ @Override
+ public void uncaughtException(final GLAnimatorControl _animator, final GLAutoDrawable _drawable, final Throwable _cause) {
+ if( _animator == animator && _drawable == f3 && _cause instanceof RuntimeException ) {
+ System.err.println("Caught expected exception: "+_cause.getMessage());
+ gotAnimException.set(true);
+ } else {
+ System.err.println("Caught unexpected exception: "+_cause.getMessage());
+ _cause.printStackTrace();
+ gotOtherException.set(true);
+ }
+ }
+ });
+ f3.setVisible(true);
+
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(f1, false));
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(f1, false));
+ Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f1, false));
+
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(f2, true));
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(f2, true));
+ Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f2, false));
+
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(f3, true));
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(f3, true));
+ Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f3, false));
+
+ f1.setVisible(true); // kick off f1 GLContext .. and hence allow f2 + f3 creation
+
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(f1, true));
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(f1, true));
+ Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f1, true));
+ Assert.assertTrue("Gears1 not initialized", g1.waitForInit(true));
+
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(f2, true));
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(f2, true));
+ Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f2, true));
+ Assert.assertTrue("Gears2 not initialized", g2.waitForInit(true));
+
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(f3, true));
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(f3, true));
+ Assert.assertTrue(AWTRobotUtil.waitForContextCreated(f3, true));
+ Assert.assertTrue("Gears3 not initialized", g3.waitForInit(true));
+
+ Assert.assertFalse("Unexpected exception (animator) caught", gotAnimException.get());
+ Assert.assertFalse("Unexpected exception (other) caught", gotOtherException.get());
+
+ final GLContext ctx1 = f1.getContext();
+ final GLContext ctx2 = f2.getContext();
+ final GLContext ctx3 = f3.getContext();
+ {
+ final List<GLContext> ctx1Shares = ctx1.getCreatedShares();
+ final List<GLContext> ctx2Shares = ctx2.getCreatedShares();
+ final List<GLContext> ctx3Shares = ctx3.getCreatedShares();
+ MiscUtils.dumpSharedGLContext("XXX-C-3.1", ctx1);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.2", ctx2);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.3", ctx3);
+
+ Assert.assertTrue("Ctx1 is not shared", ctx1.isShared());
+ Assert.assertTrue("Ctx2 is not shared", ctx2.isShared());
+ Assert.assertTrue("Ctx3 is not shared", ctx3.isShared());
+ Assert.assertEquals("Ctx1 has unexpected number of created shares", 2, ctx1Shares.size());
+ Assert.assertEquals("Ctx2 has unexpected number of created shares", 2, ctx2Shares.size());
+ Assert.assertEquals("Ctx3 has unexpected number of created shares", 2, ctx3Shares.size());
+ Assert.assertEquals("Ctx1 Master Context is different", ctx1, ctx1.getSharedMaster());
+ Assert.assertEquals("Ctx2 Master Context is different", ctx1, ctx2.getSharedMaster());
+ Assert.assertEquals("Ctx3 Master Context is different", ctx2, ctx3.getSharedMaster()); // Mixed master!
+ }
+
+ Assert.assertTrue("Gears1 is shared", !g1.usesSharedGears());
+ Assert.assertTrue("Gears2 is not shared", g2.usesSharedGears());
+ Assert.assertTrue("Gears3 is not shared", g3.usesSharedGears());
+
+ try {
+ Thread.sleep(duration);
+ } catch(final Exception e) {
+ e.printStackTrace();
+ }
+ animator.stop();
+ Assert.assertEquals(false, animator.isAnimating());
+
+ System.err.println("XXX Destroy in clean order NOW");
+ f3.destroy();
+ f2.destroy();
+ f1.destroy();
+
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(f1, false));
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(f1, false));
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(f2, false));
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(f2, false));
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(f3, false));
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(f3, false));
+ }
+
+ static long duration = 1000; // ms
+
+ public static void main(final String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ try {
+ duration = Integer.parseInt(args[i]);
+ } catch (final Exception ex) { ex.printStackTrace(); }
+ }
+ }
+ /**
+ BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
+ System.err.println("Press enter to continue");
+ System.err.println(stdin.readLine()); */
+ org.junit.runner.JUnitCore.main(TestSharedContextVBOES2NEWT4.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2SWT3.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2SWT3.java
index 90cb503ce..09f4408f1 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2SWT3.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2SWT3.java
@@ -220,12 +220,9 @@ public class TestSharedContextVBOES2SWT3 extends UITestCase {
final List<GLContext> ctx1Shares = ctx1.getCreatedShares();
final List<GLContext> ctx2Shares = ctx2.getCreatedShares();
final List<GLContext> ctx3Shares = ctx3.getCreatedShares();
- System.err.println("XXX-C-3.1:");
- MiscUtils.dumpSharedGLContext(ctx1);
- System.err.println("XXX-C-3.2:");
- MiscUtils.dumpSharedGLContext(ctx2);
- System.err.println("XXX-C-3.3:");
- MiscUtils.dumpSharedGLContext(ctx3);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.1", ctx1);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.2", ctx2);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.3", ctx3);
Assert.assertTrue("Ctx1 is not shared", ctx1.isShared());
Assert.assertTrue("Ctx2 is not shared", ctx2.isShared());
@@ -314,12 +311,9 @@ public class TestSharedContextVBOES2SWT3 extends UITestCase {
final List<GLContext> ctx1Shares = ctx1.getCreatedShares();
final List<GLContext> ctx2Shares = ctx2.getCreatedShares();
final List<GLContext> ctx3Shares = ctx3.getCreatedShares();
- System.err.println("XXX-C-3.1:");
- MiscUtils.dumpSharedGLContext(ctx1);
- System.err.println("XXX-C-3.2:");
- MiscUtils.dumpSharedGLContext(ctx2);
- System.err.println("XXX-C-3.3:");
- MiscUtils.dumpSharedGLContext(ctx3);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.1", ctx1);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.2", ctx2);
+ MiscUtils.dumpSharedGLContext("XXX-C-3.2", ctx3);
Assert.assertTrue("Ctx1 is not shared", ctx1.isShared());
Assert.assertTrue("Ctx2 is not shared", ctx2.isShared());
diff --git a/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java b/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java
index e401534bd..7100e1e1a 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java
@@ -214,21 +214,23 @@ public class MiscUtils {
}
}
- public static void dumpSharedGLContext(final GLContext self) {
+ public static void dumpSharedGLContext(final String prefix, final GLContext self) {
int i = 0, j = 0;
- System.err.println("Myself: hash 0x"+Integer.toHexString(self.hashCode())+", \t(isShared "+self.isShared()+", created "+self.isCreated()+")");
+ final GLContext master = self.getSharedMaster();
+ final int masterHash = null != master ? master.hashCode() : 0;
+ System.err.println(prefix+": hash 0x"+Integer.toHexString(self.hashCode())+", \t(isShared "+self.isShared()+", created "+self.isCreated()+", master 0x"+Integer.toHexString(masterHash)+")");
{
final List<GLContext> set = self.getCreatedShares();
for (final Iterator<GLContext> iter = set.iterator(); iter.hasNext(); ) {
final GLContext c = iter.next();
- System.err.println("Ctx #"+(i++)+": hash 0x"+Integer.toHexString(c.hashCode())+", \t(created "+c.isCreated()+")");
+ System.err.println(" Created Ctx #"+(i++)+": hash 0x"+Integer.toHexString(c.hashCode())+", \t(created "+c.isCreated()+")");
}
}
{
final List<GLContext> set = self.getDestroyedShares();
for (final Iterator<GLContext> iter = set.iterator(); iter.hasNext(); ) {
final GLContext c = iter.next();
- System.err.println("Ctx #"+(j++)+": hash 0x"+Integer.toHexString(c.hashCode())+", \t(created "+c.isCreated()+")");
+ System.err.println(" Destroyed Ctx #"+(j++)+": hash 0x"+Integer.toHexString(c.hashCode())+", \t(created "+c.isCreated()+")");
}
}
System.err.println("\t Total created "+i+" + destroyed "+j+" = "+(i+j));