]> source.dussan.org Git - tigervnc.git/commitdiff
Multithreaded decoder improvements (java viewer)
authorBrian P. Hinz <bphinz@users.sf.net>
Sat, 6 May 2017 14:55:41 +0000 (10:55 -0400)
committerBrian P. Hinz <bphinz@users.sf.net>
Sat, 6 May 2017 14:59:31 +0000 (10:59 -0400)
java/com/tigervnc/rfb/DecodeManager.java
java/com/tigervnc/rfb/JpegDecompressor.java
java/com/tigervnc/vncviewer/JavaPixelBuffer.java

index 7e2aedf63394142dc257a6412920e11e6a8564a5..c1557460d00f00cf30fce777127b8bbe73411f7a 100644 (file)
@@ -43,7 +43,6 @@ public class DecodeManager {
     producerCond = queueMutex.newCondition();
     consumerCond = queueMutex.newCondition();
 
-    //cpuCount = 1;
     cpuCount = Runtime.getRuntime().availableProcessors();
     if (cpuCount == 0) {
       vlog.error("Unable to determine the number of CPU cores on this system");
@@ -151,12 +150,12 @@ public class DecodeManager {
                               bufferStream.length(), conn.cp,
                               entry.affectedRegion);
 
+    queueMutex.lock();
+
     // The workers add buffers to the end so it's safe to assume
     // the front is still the same buffer
     freeBuffers.removeFirst();
 
-    queueMutex.lock();
-
     workQueue.addLast(entry);
 
     // We only put a single entry on the queue so waking a single
@@ -249,6 +248,7 @@ public class DecodeManager {
     public void run()
     {
       manager.queueMutex.lock();
+
       while (!stopRequested) {
         QueueEntry entry;
 
@@ -257,7 +257,7 @@ public class DecodeManager {
         if (entry == null) {
           // Wait and try again
           try {
-          manager.consumerCond.await();
+            manager.consumerCond.await();
           } catch (InterruptedException e) { }
           continue;
         }
@@ -281,7 +281,7 @@ public class DecodeManager {
         manager.queueMutex.lock();
 
         // Remove the entry from the queue and give back the memory buffer
-        manager.freeBuffers.add(entry.bufferStream);
+        manager.freeBuffers.addLast(entry.bufferStream);
         manager.workQueue.remove(entry);
         entry = null;
 
@@ -307,7 +307,7 @@ public class DecodeManager {
       if (!manager.workQueue.peek().active)
         return manager.workQueue.peek();
 
-      for (iter = manager.workQueue.iterator(); iter.hasNext();) {
+      next:for (iter = manager.workQueue.iterator(); iter.hasNext();) {
         QueueEntry entry;
 
         Iterator<QueueEntry> iter2;
@@ -317,7 +317,7 @@ public class DecodeManager {
         // Another thread working on this?
         if (entry.active) {
           lockedRegion.assign_union(entry.affectedRegion);
-          continue;
+          continue next;
         }
 
         // If this is an ordered decoder then make sure this is the first
@@ -326,7 +326,7 @@ public class DecodeManager {
           for (iter2 = manager.workQueue.iterator(); iter2.hasNext() && iter2 != iter;) {
             if (entry.encoding == (iter2.next()).encoding) {
               lockedRegion.assign_union(entry.affectedRegion);
-              continue;
+              continue next;
             }
           }
         }
@@ -346,14 +346,14 @@ public class DecodeManager {
                                               entry2.bufferStream.length(),
                                               entry.cp))
               lockedRegion.assign_union(entry.affectedRegion);
-              continue;
+              continue next;
           }
         }
 
         // Check overlap with earlier rectangles
         if (!lockedRegion.intersect(entry.affectedRegion).is_empty()) {
           lockedRegion.assign_union(entry.affectedRegion);
-          continue;
+          continue next;
         }
 
         return entry;
index 31542942895d61c6e77ea995ebc26e4d2dd5c911..23c6f65ca879d24040e65df523cf14455b20abf8 100644 (file)
@@ -39,11 +39,11 @@ public class JpegDecompressor {
       ImageIO.setUseCache(false);
       BufferedImage jpeg =
         ImageIO.read(new MemoryCacheImageInputStream(new ByteArrayInputStream(src)));
+      jpeg.setAccelerationPriority(1);
       BufferedImage image = (BufferedImage)pb.getImage();
       Graphics2D g2 = image.createGraphics();
       g2.drawImage(jpeg, r.tl.x, r.tl.y, r.width(), r.height(), null);
       g2.dispose();
-      image.flush();
       jpeg.flush();
     } catch (IOException e) {
       throw new Exception(e.getMessage());
index 89c42fe3abfce180e0fbebdf16cb878a552c72b6..16242d050bac033069e0b30e73c1f41f4ab37f3b 100644 (file)
@@ -33,6 +33,7 @@ public class JavaPixelBuffer extends PlatformPixelBuffer
           getPreferredPF().getColorModel().createCompatibleWritableRaster(w,h));
     image = new BufferedImage(getPreferredPF().getColorModel(),
                               getBufferRW(new Rect(0, 0, w, h)), true, null);
+    image.setAccelerationPriority(1);
   }
 
   public synchronized void fillRect(Rect r, byte[] pix)