< prev index next >

src/java.desktop/share/classes/sun/java2d/opengl/OGLRenderQueue.java

Print this page




  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.java2d.opengl;
  27 
  28 import sun.awt.util.ThreadGroupUtils;
  29 import sun.java2d.pipe.RenderBuffer;
  30 import sun.java2d.pipe.RenderQueue;
  31 import sun.misc.ManagedLocalsThread;
  32 
  33 import static sun.java2d.pipe.BufferedOpCodes.*;
  34 import java.security.AccessController;
  35 import java.security.PrivilegedAction;
  36 
  37 /**
  38  * OGL-specific implementation of RenderQueue.  This class provides a
  39  * single (daemon) thread that is responsible for periodically flushing
  40  * the queue, thus ensuring that only one thread communicates with the native
  41  * OpenGL libraries for the entire process.
  42  */
  43 public class OGLRenderQueue extends RenderQueue {
  44 
  45     private static OGLRenderQueue theInstance;
  46     private final QueueFlusher flusher;
  47 
  48     private OGLRenderQueue() {
  49         /*
  50          * The thread must be a member of a thread group
  51          * which will not get GCed before VM exit.


 144         // assert lock.isHeldByCurrentThread();
 145         int limit = buf.position();
 146         if (limit > 0) {
 147             // process the queue
 148             flushBuffer(buf.getAddress(), limit);
 149         }
 150         // reset the buffer position
 151         buf.clear();
 152         // clear the set of references, since we no longer need them
 153         refSet.clear();
 154     }
 155 
 156     private class QueueFlusher implements Runnable {
 157         private boolean needsFlush;
 158         private Runnable task;
 159         private Error error;
 160         private final Thread thread;
 161 
 162         public QueueFlusher() {
 163             String name = "Java2D Queue Flusher";
 164             thread = new ManagedLocalsThread(ThreadGroupUtils.getRootThreadGroup(), this, name);

 165             thread.setDaemon(true);
 166             thread.setPriority(Thread.MAX_PRIORITY);
 167             thread.start();
 168         }
 169 
 170         public synchronized void flushNow() {
 171             // wake up the flusher
 172             needsFlush = true;
 173             notify();
 174 
 175             // wait for flush to complete
 176             while (needsFlush) {
 177                 try {
 178                     wait();
 179                 } catch (InterruptedException e) {
 180                 }
 181             }
 182 
 183             // re-throw any error that may have occurred during the flush
 184             if (error != null) {




  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.java2d.opengl;
  27 
  28 import sun.awt.util.ThreadGroupUtils;
  29 import sun.java2d.pipe.RenderBuffer;
  30 import sun.java2d.pipe.RenderQueue;

  31 
  32 import static sun.java2d.pipe.BufferedOpCodes.*;
  33 import java.security.AccessController;
  34 import java.security.PrivilegedAction;
  35 
  36 /**
  37  * OGL-specific implementation of RenderQueue.  This class provides a
  38  * single (daemon) thread that is responsible for periodically flushing
  39  * the queue, thus ensuring that only one thread communicates with the native
  40  * OpenGL libraries for the entire process.
  41  */
  42 public class OGLRenderQueue extends RenderQueue {
  43 
  44     private static OGLRenderQueue theInstance;
  45     private final QueueFlusher flusher;
  46 
  47     private OGLRenderQueue() {
  48         /*
  49          * The thread must be a member of a thread group
  50          * which will not get GCed before VM exit.


 143         // assert lock.isHeldByCurrentThread();
 144         int limit = buf.position();
 145         if (limit > 0) {
 146             // process the queue
 147             flushBuffer(buf.getAddress(), limit);
 148         }
 149         // reset the buffer position
 150         buf.clear();
 151         // clear the set of references, since we no longer need them
 152         refSet.clear();
 153     }
 154 
 155     private class QueueFlusher implements Runnable {
 156         private boolean needsFlush;
 157         private Runnable task;
 158         private Error error;
 159         private final Thread thread;
 160 
 161         public QueueFlusher() {
 162             String name = "Java2D Queue Flusher";
 163             thread = new Thread(ThreadGroupUtils.getRootThreadGroup(),
 164                                 this, name, 0, false);
 165             thread.setDaemon(true);
 166             thread.setPriority(Thread.MAX_PRIORITY);
 167             thread.start();
 168         }
 169 
 170         public synchronized void flushNow() {
 171             // wake up the flusher
 172             needsFlush = true;
 173             notify();
 174 
 175             // wait for flush to complete
 176             while (needsFlush) {
 177                 try {
 178                     wait();
 179                 } catch (InterruptedException e) {
 180                 }
 181             }
 182 
 183             // re-throw any error that may have occurred during the flush
 184             if (error != null) {


< prev index next >