29package com.jogamp.opengl.test.junit.jogl.acore;
31import java.io.IOException;
32import java.util.concurrent.atomic.AtomicInteger;
34import com.jogamp.common.os.Platform;
35import com.jogamp.common.util.InterruptSource;
36import com.jogamp.junit.util.JunitTracer;
37import com.jogamp.nativewindow.NativeSurface;
38import com.jogamp.opengl.GLAutoDrawable;
39import com.jogamp.opengl.GLCapabilities;
40import com.jogamp.opengl.GLEventListener;
41import com.jogamp.opengl.GLProfile;
44import org.junit.BeforeClass;
45import org.junit.FixMethodOrder;
46import org.junit.runners.MethodSorters;
48import com.jogamp.newt.opengl.GLWindow;
49import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
50import com.jogamp.opengl.test.junit.util.UITestCase;
52@FixMethodOrder(MethodSorters.NAME_ASCENDING)
54 static final int demoSizePos = 80;
57 final Object postSync;
62 this.postSync = postSync;
71 private final int frameCount;
76 this.frameCount = frameCount;
81 System.err.println(
"Animatr "+
id+
", count "+frameCount+
": PRE: "+Thread.currentThread().getName());
83 for(
int c=0; c<frameCount; c++) {
84 System.err.println(
"Animatr "+
id+
": Action "+c+
" / "+frameCount+
": "+Thread.currentThread().getName());
89 System.err.println(
"Animatr "+
id+
": DONE/SYNC: "+Thread.currentThread().getName());
90 synchronized (postSync) {
92 System.err.println(
"Animatr "+
id+
": END: "+Thread.currentThread().getName());
104 private final int actionCount;
109 this.actionCount = actionCount;
114 System.err.println(
"Resizer "+
id+
", count "+actionCount+
": PRE: "+Thread.currentThread().getName());
116 for(
int c=0; c<actionCount; c++) {
122 System.err.println(
"Resizer "+
id+
": Action "+i+
" / "+actionCount+
": "+Thread.currentThread().getName());
140 System.err.println(
"Resizer "+
id+
": DONE/SYNC: "+Thread.currentThread().getName());
141 synchronized (postSync) {
143 System.err.println(
"Resizer "+
id+
": END: "+Thread.currentThread().getName());
144 postSync.notifyAll();
150 for(
int i=tasks.length-1; i>=0; i--) {
151 if(!tasks[i].done()) {
158 protected static boolean isDead(
final Thread[] threads) {
159 for(
int i=threads.length-1; i>=0; i--) {
160 if(threads[i].isAlive()) {
168 AtomicInteger reshapeCount =
new AtomicInteger(0);
169 AtomicInteger displayCount =
new AtomicInteger(0);
177 System.err.println(
"*** reshapes: "+reshapeCount+
", displays "+displayCount);
182 displayCount.incrementAndGet();
187 reshapeCount.incrementAndGet();
196 protected void runJOGLTasks(
final int animThreadCount,
final int frameCount,
final int reszThreadCount,
final int resizeCount)
throws InterruptedException {
203 glWindow.
setSize(demoSizePos, demoSizePos);
206 final String currentThreadName = Thread.currentThread().getName();
207 final Object sync =
new Object();
210 final InterruptSource.Thread[] animThreads =
new InterruptSource.Thread[reszThreadCount];
211 final InterruptSource.Thread[] resizeThreads =
new InterruptSource.Thread[reszThreadCount];
213 System.err.println(
"animThreadCount "+animThreadCount+
", frameCount "+frameCount);
214 System.err.println(
"reszThreadCount "+reszThreadCount+
", resizeCount "+resizeCount);
215 System.err.println(
"tasks "+(animTasks.length+resizeTasks.length)+
", threads "+(animThreads.length+resizeThreads.length));
217 for(
int i=0; i<animThreadCount; i++) {
218 System.err.println(
"create anim task/thread "+i);
219 animTasks[i] =
new RudeAnimator(glWindow, frameCount, sync, i);
220 animThreads[i] =
new InterruptSource.Thread(
null, animTasks[i], currentThreadName+
"-anim"+i);
222 for(
int i=0; i<reszThreadCount; i++) {
223 System.err.println(
"create resz task/thread "+i);
224 resizeTasks[i] =
new RudeResizer(glWindow, resizeCount, sync, i);
225 resizeThreads[i] =
new InterruptSource.Thread(
null, resizeTasks[i], currentThreadName+
"-resz"+i);
228 myEventCounter.
reset();
231 for(
int i=0; i<reszThreadCount+animThreadCount; i++) {
233 System.err.println(
"start resize thread "+j);
234 resizeThreads[j++].start();
236 System.err.println(
"start anim thread "+k);
237 animThreads[k++].start();
240 synchronized (sync) {
241 while(!done(resizeTasks) || !done(animTasks)) {
244 }
catch (
final InterruptedException e) {
245 throw new RuntimeException(e);
250 while(i<30 && !isDead(animThreads) && !isDead(resizeThreads)) {
260 runJOGLTasks(1, 200, 1, 100);
265 runJOGLTasks(3, 100, 3, 50);
271 if( Platform.OSType.MACOS == Platform.getOSType() ) {
272 JunitTracer.setTestSupported(
false);
276 static boolean manual_test =
false;
278 public static void main(
final String args[])
throws IOException {
280 for(
int i=0; i<args.length; i++) {
281 if(args[i].equals(
"-time")) {
285 }
catch (
final Exception ex) { ex.printStackTrace(); }
289 org.junit.runner.JUnitCore.
main(tstname);
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final int lockSurface()
Lock the surface of this native window.
final int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
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 int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
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 void unlockSurface()
Unlock the surface of this native window.
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
final void runOnEDTIfAvail(final boolean wait, final Runnable task)
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.
Specifies the the OpenGL profile.
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height)
Called by the drawable during the first repaint after the component has been resized.
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
void display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
void dispose(final GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
MyRunnable(final Object postSync, final int id)
RudeAnimator(final GLAutoDrawable glad, final int frameCount, final Object postSync, final int id)
Emulates a resize behavior with immediate display() call while the surface is still locked.
RudeResizer(final GLWindow win, final int actionCount, final Object postSync, final int id)
static boolean isDead(final Thread[] threads)
void runJOGLTasks(final int animThreadCount, final int frameCount, final int reszThreadCount, final int resizeCount)
static void main(final String args[])
void test01_1A1RThreads_100Resizes()
void test01_3A3RThreads_50Resizes()
static boolean done(final MyRunnable[] tasks)
static void beforeClass()
Provides low-level information required for hardware-accelerated rendering using a surface in a platf...
static final int LOCK_SURFACE_NOT_READY
Returned by lockSurface() if the surface is not ready to be locked, {@value}.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.