BufferedImage performance is poor on Microsoft Windows platforms, so fallback to the 1.2 implementation if the BI cannot be HW accelerated.  Also streamline some of the code by removing synchronized statements and making the method calls themselves synchronized.  Modification to the selector implementation to make it behave more like a unix selector

git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4880 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/java/com/tigervnc/rfb/CMsgWriter.java b/java/com/tigervnc/rfb/CMsgWriter.java
index c4f4355..af7d137 100644
--- a/java/com/tigervnc/rfb/CMsgWriter.java
+++ b/java/com/tigervnc/rfb/CMsgWriter.java
@@ -24,7 +24,7 @@
 
   abstract public void writeClientInit(boolean shared);
 
-  public void writeSetPixelFormat(PixelFormat pf) 
+  synchronized public void writeSetPixelFormat(PixelFormat pf) 
   {
     startMsg(MsgTypes.msgTypeSetPixelFormat);                                 
     os.pad(3);
@@ -32,7 +32,7 @@
     endMsg();
   }
 
-  public void writeSetEncodings(int nEncodings, int[] encodings) 
+  synchronized public void writeSetEncodings(int nEncodings, int[] encodings) 
   {
     startMsg(MsgTypes.msgTypeSetEncodings);
     os.skip(1);
@@ -45,7 +45,7 @@
   // Ask for encodings based on which decoders are supported.  Assumes higher
   // encoding numbers are more desirable.
 
-  public void writeSetEncodings(int preferredEncoding, boolean useCopyRect) 
+  synchronized public void writeSetEncodings(int preferredEncoding, boolean useCopyRect) 
   {
     int nEncodings = 0;
     int[] encodings = new int[Encodings.encodingMax+3];
@@ -113,7 +113,7 @@
     writeSetEncodings(nEncodings, encodings);
   }
 
-  public void writeFramebufferUpdateRequest(Rect r, boolean incremental) 
+  synchronized public void writeFramebufferUpdateRequest(Rect r, boolean incremental) 
   {
     startMsg(MsgTypes.msgTypeFramebufferUpdateRequest);
     os.writeU8(incremental?1:0);
@@ -124,7 +124,7 @@
     endMsg();
   }
 
-  public void writeKeyEvent(int key, boolean down) 
+  synchronized public void writeKeyEvent(int key, boolean down) 
   {
     startMsg(MsgTypes.msgTypeKeyEvent);
     os.writeU8(down?1:0);
@@ -133,7 +133,7 @@
     endMsg();
   }
 
-  public void writePointerEvent(Point pos, int buttonMask) 
+  synchronized public void writePointerEvent(Point pos, int buttonMask) 
   {
     Point p = new Point(pos.x,pos.y);
     if (p.x < 0) p.x = 0;
@@ -148,7 +148,7 @@
     endMsg();
   }
 
-  public void writeClientCutText(String str, int len) 
+  synchronized public void writeClientCutText(String str, int len) 
   {
     startMsg(MsgTypes.msgTypeClientCutText);
     os.pad(3);
@@ -165,7 +165,7 @@
   abstract public void startMsg(int type);
   abstract public void endMsg();
 
-  public void setOutStream(OutStream os_) { os = os_; }
+  synchronized public void setOutStream(OutStream os_) { os = os_; }
 
   ConnParams getConnParams() { return cp; }
   OutStream getOutStream() { return os; }
diff --git a/java/com/tigervnc/rfb/CMsgWriterV3.java b/java/com/tigervnc/rfb/CMsgWriterV3.java
index 430c374..8f01f3c 100644
--- a/java/com/tigervnc/rfb/CMsgWriterV3.java
+++ b/java/com/tigervnc/rfb/CMsgWriterV3.java
@@ -26,20 +26,20 @@
 
   public CMsgWriterV3(ConnParams cp_, OutStream os_) { super(cp_, os_); }
 
-  public void writeClientInit(boolean shared) {
+  synchronized public void writeClientInit(boolean shared) {
     os.writeU8(shared?1:0);
     endMsg();
   }
 
-  public void startMsg(int type) {
+  synchronized public void startMsg(int type) {
     os.writeU8(type);
   }
 
-  public void endMsg() {
+  synchronized public void endMsg() {
     os.flush();
   }
 
-  public void writeSetDesktopSize(int width, int height,
+  synchronized public void writeSetDesktopSize(int width, int height,
                                   ScreenSet layout)
 	{
 	  if (!cp.supportsSetDesktopSize)
@@ -67,7 +67,7 @@
 	  endMsg();
 	}
 
-  public void writeFence(int flags, int len, byte[] data)
+  synchronized public void writeFence(int flags, int len, byte[] data)
   {
     if (!cp.supportsFence)
       throw new Exception("Server does not support fences");
@@ -87,7 +87,7 @@
     endMsg();
   }
   
-  public void writeEnableContinuousUpdates(boolean enable,
+  synchronized public void writeEnableContinuousUpdates(boolean enable,
                                            int x, int y, int w, int h)
   {
     if (!cp.supportsContinuousUpdates)
diff --git a/java/com/tigervnc/rfb/TightDecoder.java b/java/com/tigervnc/rfb/TightDecoder.java
index 7424457..9902097 100644
--- a/java/com/tigervnc/rfb/TightDecoder.java
+++ b/java/com/tigervnc/rfb/TightDecoder.java
@@ -249,16 +249,7 @@
 
     // Create an Image object from the JPEG data.
     Image jpeg = tk.createImage(netbuf);
-    tk.prepareImage(jpeg, -1, -1, null); 
-    synchronized(this) { 
-      while ((tk.checkImage(jpeg, -1, -1, null) & ImageObserver.ALLBITS) == 0) {
-        try {
-          this.wait(1);
-        } catch (InterruptedException e) {
-          throw new Exception("Error decoding JPEG data");
-        }
-      }
-    }
+    jpeg.setAccelerationPriority(1);
     handler.imageRect(r, jpeg);
     jpeg.flush();
   }