diff options
author | Sven Gothel <[email protected]> | 2009-06-17 13:32:55 +0000 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2009-06-17 13:32:55 +0000 |
commit | 42a3da77136f0f39679f022b9c7e243464025539 (patch) | |
tree | e84523a9f76aa43cfb8722308fd9d332fbcf90f9 /src/demos/es1/RedSquare.java | |
parent | ac2cdb722753f4eb5294cac532d54b284ad21725 (diff) |
RedSquare: single thread / one-pump test
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/trunk@354 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4
Diffstat (limited to 'src/demos/es1/RedSquare.java')
-rwxr-xr-x | src/demos/es1/RedSquare.java | 101 |
1 files changed, 78 insertions, 23 deletions
diff --git a/src/demos/es1/RedSquare.java b/src/demos/es1/RedSquare.java index 5c8e7fa..b8592d8 100755 --- a/src/demos/es1/RedSquare.java +++ b/src/demos/es1/RedSquare.java @@ -82,6 +82,8 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo public void mouseWheelMoved(MouseEvent e) { } + public boolean shouldQuit() { return quit; } + public void run() { System.err.println(glp+" RedSquare.run() 0"); int width = 800; @@ -103,7 +105,8 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo window.addKeyListener(this); window.addGLEventListener(this); // window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_CURRENT); // default - // window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_NONE); // no current .. + window.setEventHandlerMode(GLWindow.EVENT_HANDLER_GL_NONE); // no current .. + window.setRunPumpMessages(pumpOnce?false:true); window.enablePerfLog(true); // Size OpenGL to Video Surface @@ -112,19 +115,43 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo window.setVisible(true); window.enablePerfLog(true); - do { - window.display(); - } while (!quit && window.getDuration() < 20000) ; + if(!oneThread) { + do { + display(); + } while (!quit && window.getDuration() < 20000) ; + + shutdown(); + } + } catch (Throwable t) { + t.printStackTrace(); + } + } + + public void display() { + try { + if(pumpOnce && !oneThread) { + GLWindow.runCurrentThreadPumpMessage(); + } + window.display(); + } catch (Throwable t) { + t.printStackTrace(); + } + } + public void shutdown() { + try { // Shut things down cooperatively window.destroy(); - window.getFactory().shutdown(); + if(oneThread) { + window.getFactory().shutdown(); + } System.out.println(glp+" RedSquare shut down cleanly."); } catch (Throwable t) { t.printStackTrace(); } } + // FIXME: we must add storage of the pointers in the GL state to // the GLImpl classes. The need for this can be seen by making // these variables method local instead of instance members. The @@ -217,42 +244,70 @@ public class RedSquare extends Thread implements WindowListener, KeyListener, Mo public static int USE_NEWT = 0; public static int USE_AWT = 1 << 0; + public static boolean oneThread = false; + public static boolean pumpOnce = true; + public static void main(String[] args) { int type = USE_NEWT ; List threads = new ArrayList(); for(int i=0; i<args.length; i++) { - if(args[i].equals("-awt")) { + if(args[i].equals("-pumponce")) { + pumpOnce=true; + } else if(args[i].equals("-1thread")) { + oneThread=true; + } else if(args[i].equals("-awt")) { type |= USE_AWT; - } - if(args[i].startsWith("-GL")) { + } else if(args[i].startsWith("-GL")) { threads.add(new RedSquare(args[i].substring(1), type)); } } if(threads.size()==0) { threads.add(new RedSquare(null, type)); } - Thread firstT = (Thread) threads.remove(0); - for(Iterator i = threads.iterator(); i.hasNext(); ) { - ((Thread)i.next()).start(); - } + if(!oneThread) { + Thread firstT = (Thread) threads.remove(0); - // always run the first on main .. - firstT.run(); + for(Iterator i = threads.iterator(); i.hasNext(); ) { + ((Thread)i.next()).start(); + } + + // always run the first on main .. + firstT.run(); - boolean done = false; + boolean done = false; - while(!done) { - int aliveCount = 0; + while(!done) { + int aliveCount = 0; + for(Iterator i = threads.iterator(); i.hasNext(); ) { + if ( ((Thread)i.next()).isAlive() ) { + try { + Thread.sleep(100); + } catch (InterruptedException ie) {} + aliveCount++; + } + } + done = 0==aliveCount ; + } + } else { + // init all .. for(Iterator i = threads.iterator(); i.hasNext(); ) { - if ( ((Thread)i.next()).isAlive() ) { - try { - Thread.sleep(100); - } catch (InterruptedException ie) {} - aliveCount++; + ((Thread)i.next()).run(); + } + while (threads.size()>0) { + if(pumpOnce) { + GLWindow.runCurrentThreadPumpMessage(); + } + for(Iterator i = threads.iterator(); i.hasNext(); ) { + RedSquare app = (RedSquare) i.next(); + if(app.shouldQuit()) { + app.shutdown(); + i.remove(); + } else { + app.display(); + } } } - done = 0==aliveCount ; } } } |