29package com.jogamp.opengl.test.junit.jogl.acore;
31import com.jogamp.common.util.InterruptSource;
32import com.jogamp.common.util.InterruptedRuntimeException;
33import com.jogamp.nativewindow.Capabilities;
34import com.jogamp.nativewindow.util.InsetsImmutable;
35import com.jogamp.opengl.GLCapabilities;
36import com.jogamp.opengl.GLProfile;
38import org.junit.Assert;
39import org.junit.BeforeClass;
41import com.jogamp.newt.Display;
42import com.jogamp.newt.NewtFactory;
43import com.jogamp.newt.Screen;
44import com.jogamp.newt.Window;
45import com.jogamp.newt.opengl.GLWindow;
46import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
47import com.jogamp.opengl.test.junit.util.UITestCase;
48import com.jogamp.opengl.test.junit.util.ValidateLockListener;
49import com.jogamp.opengl.util.Animator;
64 static final int demoWinSize = 128;
66 static long duration = 300;
69 static int num_x, num_y;
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;
91 public static class JOGLTask implements Runnable {
93 private final Object postSync;
94 private final boolean reuse;
95 private boolean done =
false;
97 public JOGLTask(
final Object postSync,
final int id,
final boolean reuse) {
98 this.postSync = postSync;
103 final int x = (
id % num_x ) * ( demoWinSize + insets.
getTotalHeight() );
104 final int y = ( (
id / num_x) % num_y ) * ( demoWinSize + insets.
getTotalHeight() );
109 System.err.println(
"JOGLTask "+
id+
": START: "+x+
"/"+y+
", reuse "+reuse+
" - "+Thread.currentThread().getName());
113 Assert.assertNotNull(glWindow);
122 glWindow.
setSize(demoWinSize, demoWinSize);
126 System.err.println(
"JOGLTask "+
id+
": INITIALIZED: "+
", "+display+
" - "+Thread.currentThread().
getName());
129 Assert.assertEquals(
true, animator.isAnimating());
130 Assert.assertEquals(
true, glWindow.
isVisible());
132 Assert.assertEquals(
true, glWindow.
isRealized());
133 System.err.println(
"JOGLTask "+
id+
": RUNNING: "+Thread.currentThread().getName());
138 }
catch (
final InterruptedException e) {
146 System.err.println(
"JOGLTask "+
id+
": DONE/SYNC: "+Thread.currentThread().getName());
147 synchronized (postSync) {
149 System.err.println(
"JOGLTask "+
id+
": END: "+Thread.currentThread().getName());
150 postSync.notifyAll();
158 for(
int i=tasks.length-1; i>=0; i--) {
159 if(!tasks[i].
done()) {
166 final StringBuilder sb =
new StringBuilder();
168 for(
int i=0; i<tasks.length; i++) {
172 sb.append(i).append(
": ").append(tasks[i].
done());
175 return sb.toString();
178 protected static boolean isDead(
final Thread[] threads) {
179 for(
int i=threads.length-1; i>=0; i--) {
180 if(threads[i].isAlive()) {
187 final StringBuilder sb =
new StringBuilder();
189 for(
int i=0; i<threads.length; i++) {
193 sb.append(i).append(
": ").append(threads[i].isAlive());
196 return sb.toString();
199 protected void runJOGLTasks(
final int num,
final boolean reuse)
throws InterruptedException {
201 System.err.println(
"InitConcurrentBaseNEWT "+num+
" threads, reuse display: "+reuse);
202 final String currentThreadName = Thread.currentThread().getName();
203 final Object syncDone =
new Object();
205 final InterruptSource.Thread[] threads =
new InterruptSource.Thread[num];
207 for(i=0; i<num; i++) {
208 tasks[i] =
new JOGLTask(syncDone, i, reuse);
209 threads[i] =
new InterruptSource.Thread(
null, tasks[i], currentThreadName+
"-jt"+i);
211 final long t0 = System.currentTimeMillis();
213 for(i=0; i<num; i++) {
217 synchronized (syncDone) {
218 while(!
done(tasks)) {
221 }
catch (
final InterruptedException e) {
222 throw new InterruptedRuntimeException(e);
224 System.err.println(i+
": "+
doneDump(tasks));
228 final long t1 = System.currentTimeMillis();
229 System.err.println(
"total: "+(t1-t0)/1000.0+
"s");
231 Assert.assertTrue(
"Tasks are incomplete. Complete: "+
doneDump(tasks),
done(tasks));
233 while(i<30 && !
isDead(threads)) {
237 Assert.assertTrue(
"Threads are still alive after 3s. Alive: "+
isAliveDump(threads),
isDead(threads));
Specifies a set of capabilities that a window's rendering context must support, such as color depth p...
abstract String getName()
static Display createDisplay(final String name)
Create a Display entity.
static Window createWindow(final CapabilitiesImmutable caps)
Create a top level Window entity on the default Display and default Screen.
static Screen createScreen(final Display display, final int index)
Create a Screen entity.
A screen may span multiple MonitorDevices representing their combined virtual size.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final boolean isNativeValid()
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 boolean isVisible()
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
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.
Specifies the the OpenGL profile.
static void shutdown()
Manual shutdown method, may be called after your last JOGL use within the running JVM.
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
static AbstractGraphicsDevice getDefaultDevice()
JOGLTask(final Object postSync, final int id, final boolean reuse)
Concurrent and lock-free initialization and rendering using exclusive NEWT Display EDT instances,...
static boolean isDead(final Thread[] threads)
static String doneDump(final JOGLTask[] tasks)
static String isAliveDump(final Thread[] threads)
static boolean done(final JOGLTask[] tasks)
void runJOGLTasks(final int num, final boolean reuse)
final long getTotalFPSDuration()
final void setUpdateFPSFrames(final int frames, final PrintStream out)
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.
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.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
boolean isRealized()
Returns true if this drawable is realized, otherwise false.