29package com.jogamp.opengl.test.junit.jogl.acore.ect;
31import com.jogamp.newt.NewtFactory;
32import com.jogamp.newt.Window;
33import com.jogamp.opengl.test.junit.util.GLTestUtil;
34import com.jogamp.opengl.test.junit.util.UITestCase;
36import com.jogamp.opengl.util.AnimatorBase;
38import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
39import com.jogamp.common.os.Platform;
40import com.jogamp.nativewindow.Capabilities;
41import com.jogamp.nativewindow.util.InsetsImmutable;
43import com.jogamp.opengl.GLAutoDrawable;
44import com.jogamp.opengl.GLCapabilities;
45import com.jogamp.opengl.GLCapabilitiesImmutable;
46import com.jogamp.opengl.GLProfile;
48import org.junit.Assert;
49import org.junit.BeforeClass;
50import org.junit.AfterClass;
52import org.junit.FixMethodOrder;
53import org.junit.runners.MethodSorters;
58@FixMethodOrder(MethodSorters.NAME_ASCENDING)
60 static boolean testExclusiveWithAWT =
false;
61 static final int durationParts = 9;
62 static long duration = 320 * durationParts;
64 static boolean showFPS =
false;
65 static int showFPSRate = 100;
67 static final int demoWinSize = 128;
70 static int num_x, num_y;
72 static int swapInterval = 0;
77 dummyWindow.
setSize(demoWinSize, demoWinSize);
79 Assert.assertEquals(
true, dummyWindow.
isVisible());
84 final int[] demoScreenSize = dummyWindow.
convertToPixelUnits(
new int[] { demoWinSize, demoWinSize });
86 num_x = scrnWidth / ( demoScreenSize[0] + insetsScreenSize[0] ) - 2;
87 num_y = scrnHeight / ( demoScreenSize[1] + insetsScreenSize[1] ) - 2;
102 protected void runTestGL(
final GLCapabilitiesImmutable caps,
final int drawableCount,
final boolean exclusive,
final boolean preAdd,
final boolean preVisible,
final boolean shortenTest)
throws InterruptedException {
103 final boolean useAWTRenderThread = isAWTTestCase();
104 if( useAWTRenderThread && exclusive ) {
105 if( testExclusiveWithAWT ) {
106 System.err.println(
"Warning: Testing AWT + Exclusive -> Not advised!");
108 System.err.println(
"Info: Skip test: AWT + Exclusive!");
112 if( useAWTRenderThread && exclusive && !testExclusiveWithAWT) {
113 System.err.println(
"Skip test: AWT + Exclusive -> Not advised!");
116 final Thread awtRenderThread = getAWTRenderThread();
119 for(
int i=0; i<drawableCount; i++) {
120 animators[i] = createAnimator();
121 if( !useAWTRenderThread ) {
127 drawables[i] = createGLAutoDrawable(
"Win #"+i, x, y, demoWinSize, demoWinSize, caps);
128 Assert.assertNotNull(drawables[i]);
134 animators[i].
add(drawables[i]);
136 if( useAWTRenderThread ) {
137 Assert.assertEquals(
null, animators[i].setExclusiveContext(awtRenderThread));
139 Assert.assertEquals(
false, animators[i].setExclusiveContext(
true));
143 Assert.assertFalse(animators[i].isAnimating());
144 Assert.assertFalse(animators[i].isStarted());
148 setGLAutoDrawableVisible(drawables);
151 for(
int i=0; i<drawableCount; i++) {
152 Assert.assertEquals(
true, drawables[i].isRealized());
158 for(
int i=0; i<drawableCount; i++) {
159 Assert.assertTrue(animators[i].start());
161 Assert.assertTrue(animators[i].isStarted());
163 Assert.assertTrue(animators[i].isAnimating());
165 Assert.assertFalse(animators[i].isAnimating());
167 if( useAWTRenderThread ) {
168 Assert.assertEquals(
null, animators[i].setExclusiveContext(awtRenderThread));
170 Assert.assertEquals(
false, animators[i].setExclusiveContext(
true));
173 animators[i].
add(drawables[i]);
174 Assert.assertTrue(animators[i].isAnimating());
178 Assert.assertEquals(exclusive, animators[i].isExclusiveContextEnabled());
182 if( useAWTRenderThread ) {
183 Assert.assertEquals(awtRenderThread, ect);
185 Assert.assertEquals(animators[i].getThread(), ect);
188 Assert.assertEquals(
null, ect);
190 Assert.assertEquals(ect, drawables[i].getExclusiveContextThread());
195 setGLAutoDrawableVisible(drawables);
198 for(
int i=0; i<drawableCount; i++) {
199 Assert.assertEquals(
true, drawables[i].isRealized());
205 Thread.sleep(duration/durationParts);
210 final Thread ects[] =
new Thread[drawableCount];
211 for(
int i=0; i<drawableCount; i++) {
213 if( useAWTRenderThread ) {
214 Assert.assertEquals(awtRenderThread, ects[i]);
216 Assert.assertEquals(animators[i].getThread(), ects[i]);
221 Assert.assertEquals(ects[i], t);
225 Thread.sleep(duration/durationParts);
227 for(
int i=0; i<drawableCount; i++) {
232 while(!ok && c<5*50) {
238 System.err.println(
"Clearing drawable ECT was done 'later' @ "+(c*20)+
"ms, ok "+ok);
240 Assert.assertEquals(
true, ok);
243 Assert.assertEquals(
null, t);
246 Thread.sleep(duration/durationParts);
249 for(
int i=0; i<drawableCount; i++) {
251 if( useAWTRenderThread ) {
252 Assert.assertEquals(awtRenderThread, ects[i]);
254 Assert.assertEquals(animators[i].getThread(), ects[i]);
257 Assert.assertEquals(
true, animators[i].setExclusiveContext(
false));
258 Assert.assertFalse(animators[i].isExclusiveContextEnabled());
259 Assert.assertEquals(
null, drawables[i].getExclusiveContextThread());
262 Thread.sleep(duration/durationParts);
264 for(
int i=0; i<drawableCount; i++) {
265 Assert.assertEquals(
null, animators[i].setExclusiveContext(ects[i]));
266 Assert.assertTrue(animators[i].isExclusiveContextEnabled());
267 Assert.assertEquals(ects[i], animators[i].getExclusiveContextThread());
268 Assert.assertEquals(ects[i], drawables[i].getExclusiveContextThread());
271 Thread.sleep(duration/durationParts);
274 for(
int i=0; i<drawableCount; i++) {
275 Assert.assertEquals(exclusive, animators[i].isExclusiveContextEnabled());
276 Assert.assertTrue(animators[i].isStarted());
277 Assert.assertTrue(animators[i].isAnimating());
278 Assert.assertFalse(animators[i].isPaused());
281 Assert.assertTrue(animators[i].pause());
282 Assert.assertTrue(animators[i].isStarted());
283 Assert.assertFalse(animators[i].isAnimating());
284 Assert.assertTrue(animators[i].isPaused());
285 Assert.assertEquals(exclusive, animators[i].isExclusiveContextEnabled());
288 if( useAWTRenderThread ) {
289 Assert.assertEquals(awtRenderThread, ect);
291 Assert.assertEquals(animators[i].getThread(), ect);
294 Assert.assertEquals(
null, animators[i].getExclusiveContextThread());
297 Assert.assertEquals(
null, drawables[i].getExclusiveContextThread());
299 Thread.sleep(duration/durationParts);
302 for(
int i=0; i<drawableCount; i++) {
303 Assert.assertTrue(animators[i].resume());
304 Assert.assertTrue(animators[i].isStarted());
305 Assert.assertTrue(animators[i].isAnimating());
306 Assert.assertFalse(animators[i].isPaused());
307 Assert.assertEquals(exclusive, animators[i].isExclusiveContextEnabled());
310 if( useAWTRenderThread ) {
311 Assert.assertEquals(awtRenderThread, ect);
313 Assert.assertEquals(animators[i].getThread(), ect);
315 Assert.assertEquals(ect, drawables[i].getExclusiveContextThread());
317 Assert.assertEquals(
null, animators[i].getExclusiveContextThread());
318 Assert.assertEquals(
null, drawables[i].getExclusiveContextThread());
321 Thread.sleep(duration/durationParts);
324 for(
int i=0; i<drawableCount; i++) {
325 Assert.assertTrue(animators[i].stop());
326 Assert.assertFalse(animators[i].isAnimating());
327 Assert.assertFalse(animators[i].isStarted());
328 Assert.assertFalse(animators[i].isPaused());
329 Assert.assertEquals(exclusive, animators[i].isExclusiveContextEnabled());
330 Assert.assertEquals(
null, animators[i].getExclusiveContextThread());
331 Assert.assertEquals(
null, drawables[i].getExclusiveContextThread());
333 Thread.sleep(duration/durationParts);
336 for(
int i=0; i<drawableCount; i++) {
337 Assert.assertTrue(animators[i].start());
338 Assert.assertTrue(animators[i].isStarted());
339 Assert.assertTrue(animators[i].isAnimating());
340 Assert.assertEquals(exclusive, animators[i].isExclusiveContextEnabled());
345 if( useAWTRenderThread ) {
346 Assert.assertEquals(awtRenderThread, ect);
348 Assert.assertEquals(animators[i].getThread(), ect);
351 Assert.assertEquals(
null, ect);
353 Assert.assertEquals(ect, drawables[i].getExclusiveContextThread());
356 Thread.sleep(duration/durationParts);
359 for(
int i=0; i<drawableCount; i++) {
361 animators[i].
remove(drawable);
363 Assert.assertTrue(animators[i].isStarted());
364 Assert.assertFalse(animators[i].isAnimating());
369 for(
int i=0; i<drawableCount; i++) {
370 Assert.assertTrue(animators[i].stop());
371 Assert.assertFalse(animators[i].isAnimating());
372 Assert.assertFalse(animators[i].isStarted());
373 Assert.assertFalse(animators[i].isPaused());
374 Assert.assertEquals(exclusive, animators[i].isExclusiveContextEnabled());
375 Assert.assertEquals(
null, animators[i].getExclusiveContextThread());
379 for(
int i=0; i<drawableCount; i++) {
380 destroyGLAutoDrawableVisible(drawables[i]);
389 runTestGL(caps, 1 ,
false ,
true ,
false ,
false );
396 runTestGL(caps, 1 ,
false ,
false ,
false ,
true );
403 runTestGL(caps, 1 ,
true ,
true ,
false ,
false );
410 runTestGL(caps, 1 ,
true ,
false ,
false ,
true );
417 runTestGL(caps, 4 ,
false ,
true ,
false ,
false );
424 runTestGL(caps, 4 ,
false ,
false ,
false ,
true );
429 if( Platform.OSType.MACOS == Platform.getOSType() ) {
431 System.err.println(
"Disabled, see Bug 1415");
436 runTestGL(caps, 4 ,
true ,
true ,
false ,
false );
441 if( Platform.OSType.MACOS == Platform.getOSType() ) {
443 System.err.println(
"Disabled, see Bug 1415");
448 runTestGL(caps, 4 ,
true ,
false ,
false ,
true );
455 runTestGL(caps, 1 ,
false ,
true ,
true ,
false );
462 runTestGL(caps, 1 ,
false ,
false ,
true ,
true );
469 runTestGL(caps, 1 ,
true ,
true ,
true ,
false );
476 runTestGL(caps, 1 ,
true ,
false ,
true ,
true );
483 runTestGL(caps, 4 ,
false ,
true ,
true ,
false );
490 runTestGL(caps, 4 ,
false ,
false ,
true ,
true );
497 runTestGL(caps, 4 ,
true ,
true ,
true ,
false );
504 runTestGL(caps, 4 ,
true ,
false ,
true ,
true );
Specifies a set of capabilities that a window's rendering context must support, such as color depth p...
static Window createWindow(final CapabilitiesImmutable caps)
Create a top level Window entity on the default Display and default Screen.
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
ExclusiveContextThread base implementation to test correctness of the ExclusiveContext feature and An...
void test07ExclPre_4WinPostVis()
void test17ExclPre_4WinPreVis()
void test06NormalPost_4WinPostVis()
void test13ExclPre_1WinPreVis()
void test02NormalPost_1WinPostVis()
void test12NormalPost_1WinPreVis()
static void initClass00()
void test14ExclPost_1WinPreVis()
abstract boolean isAWTTestCase()
void test04ExclPost_1WinPostVis()
abstract void setGLAutoDrawableVisible(GLAutoDrawable[] glads)
void test01NormalPre_1WinPostVis()
abstract GLAutoDrawable createGLAutoDrawable(String title, int x, int y, int width, int height, GLCapabilitiesImmutable caps)
void test08ExclPost_4WinPostVis()
void test11NormalPre_1WinPreVis()
static void releaseClass00()
abstract void destroyGLAutoDrawableVisible(GLAutoDrawable glad)
void runTestGL(final GLCapabilitiesImmutable caps, final int drawableCount, final boolean exclusive, final boolean preAdd, final boolean preVisible, final boolean shortenTest)
void test16NormalPost_4WinPreVis()
void test05NormalPre_4WinPostVis()
abstract AnimatorBase createAnimator()
void test15NormalPre_4WinPreVis()
void test18ExclPost_4WinPreVis()
void test03ExclPre_1WinPostVis()
abstract Thread getAWTRenderThread()
GearsES2 setVerbose(final boolean v)
static boolean waitForRealized(final GLAutoDrawable glad, final boolean realized, final Runnable waitAction)
Base implementation of GLAnimatorControl
static final int MODE_EXPECT_AWT_RENDERING_THREAD
If present in modeBits field and AWT is available, implementation is aware of the AWT EDT,...
final synchronized void setModeBits(final boolean enable, final int bitValues)
Enables or disables the given bitValues in this Animators modeBits.
final synchronized Thread getExclusiveContextThread()
Returns the exclusive context thread if isExclusiveContextEnabled() and isStarted(),...
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final synchronized void remove(final GLAutoDrawable drawable)
Removes a drawable from the animator's list of rendering drawables.
final void setUpdateFPSFrames(final int frames, final PrintStream out)
int[] convertToPixelUnits(final int[] windowUnitsAndResult)
Converts the given window units into pixel units in place.
InsetsImmutable getInsets()
Returns the insets defined as the width and height of the window decoration on the left,...
Immutable insets representing rectangular window decoration insets on all four edges in window units.
Specifying NEWT's Window functionality:
void setSize(int width, int height)
Sets the size of the window's client area in window units, excluding decorations.
void setVisible(boolean visible)
Calls setVisible(true, visible), i.e.
void destroy()
Destroys this window incl.releasing all related resources.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
Thread setExclusiveContextThread(Thread t)
Dedicates this instance's GLContext to the given thread.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Thread getExclusiveContextThread()
Specifies an immutable set of OpenGL capabilities.