29package com.jogamp.opengl.test.junit.jogl.acore;
33import com.jogamp.newt.opengl.GLWindow;
35import com.jogamp.nativewindow.util.InsetsImmutable;
36import com.jogamp.opengl.GLCapabilities;
37import com.jogamp.opengl.GLContext;
38import com.jogamp.opengl.GLProfile;
40import com.jogamp.opengl.util.Animator;
42import jogamp.opengl.GLContextShareSet;
44import com.jogamp.opengl.test.junit.util.GLTestUtil;
45import com.jogamp.opengl.test.junit.util.MiscUtils;
46import com.jogamp.opengl.test.junit.util.NewtTestUtil;
47import com.jogamp.opengl.test.junit.util.UITestCase;
48import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
50import org.junit.Assert;
51import org.junit.BeforeClass;
53import org.junit.FixMethodOrder;
54import org.junit.runners.MethodSorters;
63@FixMethodOrder(MethodSorters.NAME_ASCENDING)
67 static final int width=128, height=128;
73 Assert.assertNotNull(glp);
75 Assert.assertNotNull(caps);
77 setTestSupported(
false);
83 Assert.assertNotNull(glWindow);
85 glWindow.
setTitle(
"Shared Gears NEWT Test: "+x+
"/"+y+
" shared true");
86 glWindow.
setSize(width, height);
94 asyncEachAnimator(
true, 3);
99 asyncEachAnimator(
false, 3);
102 public void asyncEachAnimator(
final boolean destroyCleanOrder,
final int loops)
throws InterruptedException {
110 final GLWindow f1 = createGLWindow(0, 0, g1);
118 Assert.assertTrue(
"Gears1 not initialized", g1.
waitForInit(
true));
119 System.err.println(
"XXX-0-C-M - GLContextShareSet.Map");
120 GLContextShareSet.printMap(System.err);
125 final int slaveCount = 10;
126 final int slavesPerRow=4;
127 for(
int j=0; j<loops; j++) {
132 for(
int i=0; i<slaveCount; i++) {
137 final int y = 1 + i/slavesPerRow;
138 final int x = i%slavesPerRow;
139 final GLWindow f2 = createGLWindow(width*x,
142 f2.setSharedAutoDrawable(f1);
150 Assert.assertTrue(
"Gears2 not initialized", g2.
waitForInit(
true));
159 Assert.assertTrue(
"Gears1 is shared", !g1.usesSharedGears());
160 Assert.assertTrue(
"Ctx1 is not shared", ctx1.
isShared());
161 Assert.assertEquals(
"Ctx1 has unexpected number of created shares", slaveCount, ctx1Shares.size());
162 Assert.assertEquals(
"Ctx1 Master Context is different", ctx1, ctx1.
getSharedMaster());
164 for(
int i=0; i<slaveCount; i++) {
166 Assert.assertTrue(
"Gears2 is not shared", sg[i].usesSharedGears());
167 Assert.assertTrue(
"CtxS["+i+
"] is not shared", sc[i].isShared());
168 Assert.assertEquals(
"CtxS["+i+
"] has unexpected number of created shares", slaveCount, ctxSShares.size());
169 Assert.assertEquals(
"CtxS["+i+
"] Master Context is different", ctx1, sc[i].getSharedMaster());
171 System.err.println(
"XXX-"+j+
"-C - GLContextShareSet.Map");
172 GLContextShareSet.printMap(System.err);
175 Thread.sleep(duration);
176 }
catch(
final Exception e) {
180 if( destroyCleanOrder ) {
181 System.err.println(
"XXX Destroy in clean order");
182 for(
int i=slaveCount-1; 0<=i; i--) {
189 System.err.println(
"XXX Destroy in creation order (but Master) - Driver Impl. May trigger driver Bug i.e. not postponing GL ctx destruction after releasing all refs.");
190 for(
int i=0; i<slaveCount; i++) {
197 System.err.println(
"XXX-"+j+
"-X-SX1 - GLContextShareSet.Map");
198 GLContextShareSet.printMap(System.err);
199 Assert.assertEquals(
"GLContextShareSet ctx1.createdCount is not 1", 1, GLContextShareSet.getCreatedShareCount(ctx1));
200 Assert.assertEquals(
"GLContextShareSet ctx1.destroyedCount is not slaveCount", slaveCount, GLContextShareSet.getDestroyedShareCount(ctx1));
201 for(
int i=0; i<slaveCount; i++) {
210 try { Thread.sleep(100); }
catch (
final InterruptedException ie) {}
212 try { Thread.sleep(100); }
catch (
final InterruptedException ie) {}
214 System.err.println(
"XXX-"+j+
"-X-SX2 - GLContextShareSet.Map");
215 GLContextShareSet.printMap(System.err);
216 Assert.assertEquals(
"GLContextShareSet ctx1.createdCount is not 1", 1, GLContextShareSet.getCreatedShareCount(ctx1));
217 Assert.assertEquals(
"GLContextShareSet ctx1.destroyedCount is not 0", 0, GLContextShareSet.getDestroyedShareCount(ctx1));
222 System.err.println(
"XXX-X-X-M1 - GLContextShareSet.Map");
223 GLContextShareSet.printMap(System.err);
224 Assert.assertEquals(
"GLContextShareSet ctx1.createdCount is not 1", 1, GLContextShareSet.getCreatedShareCount(ctx1));
225 Assert.assertEquals(
"GLContextShareSet ctx1.destroyedCount is not 0", 0, GLContextShareSet.getDestroyedShareCount(ctx1));
226 Assert.assertEquals(
"GLContextShareSet is not 1", 1, GLContextShareSet.getSize());
229 System.err.println(
"XXX-X-X-M2 - GLContextShareSet.Map");
230 GLContextShareSet.printMap(System.err);
233 Assert.assertEquals(
"GLContextShareSet ctx1.createdCount is not 0", 0, GLContextShareSet.getCreatedShareCount(ctx1));
234 Assert.assertEquals(
"GLContextShareSet ctx1.destroyedCount is not 0", 0, GLContextShareSet.getDestroyedShareCount(ctx1));
237 Assert.assertFalse(
"Ctx1 is still shared", ctx1.
isShared());
238 Assert.assertEquals(
"Ctx1 still has created shares", 0, ctx1Shares.size());
239 Assert.assertEquals(
"Ctx1 Master Context is not null",
null, ctx1.
getSharedMaster());
241 Assert.assertEquals(
"GLContextShareSet is not 0", 0, GLContextShareSet.getSize());
244 static long duration = 1000;
245 static boolean mainRun =
false;
247 public static void main(
final String args[]) {
249 for(
int i=0; i<args.length; i++) {
250 if(args[i].equals(
"-time")) {
253 duration = Integer.parseInt(args[i]);
254 }
catch (
final Exception ex) { ex.printStackTrace(); }
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final void setPosition(final int x, final int y)
Sets the location of the window's client area excluding insets (window decorations) in window units.
final void setTitle(final String title)
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final InsetsImmutable getInsets()
Returns the insets defined as the width and height of the window decoration on the left,...
final void setUndecorated(final boolean value)
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Specifies a set of OpenGL capabilities.
Abstraction for an OpenGL rendering context.
final boolean isShared()
Returns true if this GLContext is shared, otherwise false.
final GLContext getSharedMaster()
Returns the shared master GLContext of this GLContext if shared, otherwise return null.
final List< GLContext > getCreatedShares()
Returns a new list of created GLContext shared with this GLContext.
Specifies the the OpenGL profile.
static boolean isAvailable(final AbstractGraphicsDevice device, final String profile)
Returns the availability of a profile on a device.
static final String GL2ES2
The intersection of the desktop GL3, GL2 and embedded ES2 profile.
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
Analyze Bug 1312: Test potential memory leak in GLContextShareSet due to its usage of hard references...
void test01CleanDtorOrder()
GLWindow createGLWindow(final int x, final int y, final GearsES2 gears)
void asyncEachAnimator(final boolean destroyCleanOrder, final int loops)
static void main(final String args[])
void test02DirtyDtorOrder()
void setValidateBuffers(final boolean v)
void setSharedGears(final GearsES2 shared)
boolean waitForInit(final boolean initialized)
void setSyncObjects(final Object sync)
GearsES2 setVerbose(final boolean v)
void setUseMappedBuffers(final boolean v)
static boolean waitForContextCreated(final GLAutoDrawable autoDrawable, final boolean created, final Runnable waitAction)
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
static boolean waitForVisible(final Window win, final boolean visible, final Runnable waitAction)
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.
Immutable insets representing rectangular window decoration insets on all four edges in window units.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
GLContext getContext()
Returns the context associated with this drawable.