Revert a change from yesterday that broke the viewer (setAccelerationPriority).  Fix some more issues with window sizing and scaling. Trying to eliminate unnecessary synchronization.

git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4725 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/java/com/tigervnc/vncviewer/CConn.java b/java/com/tigervnc/vncviewer/CConn.java
index 089d241..a485f33 100644
--- a/java/com/tigervnc/vncviewer/CConn.java
+++ b/java/com/tigervnc/vncviewer/CConn.java
@@ -85,8 +85,12 @@
             sp.setSize(new Dimension(cc.desktop.scaledWidth,
                                      cc.desktop.scaledHeight));
             sp.validate();
-            if (getExtendedState() != JFrame.MAXIMIZED_BOTH)
-              pack();
+            if (getExtendedState() != JFrame.MAXIMIZED_BOTH &&
+                scaleString.equals("FixedRatio")) {
+              int w = cc.desktop.scaledWidth + getInsets().left + getInsets().right;
+              int h = cc.desktop.scaledHeight + getInsets().top + getInsets().bottom;
+              setSize(w, h);
+            }
             if (cc.desktop.cursor != null) {
               Cursor cursor = cc.desktop.cursor;
               cc.setCursor(cursor.width(),cursor.height(),cursor.hotspot, 
@@ -512,7 +516,7 @@
         pack = false;
       }
 
-      if (!pack)
+      if (pack)
         viewport.setPreferredSize(new Dimension(w,h));
 
       if (viewport.getExtendedState() == JFrame.MAXIMIZED_BOTH) {
diff --git a/java/com/tigervnc/vncviewer/DesktopWindow.java b/java/com/tigervnc/vncviewer/DesktopWindow.java
index 8bf718b..978368d 100644
--- a/java/com/tigervnc/vncviewer/DesktopWindow.java
+++ b/java/com/tigervnc/vncviewer/DesktopWindow.java
@@ -55,7 +55,6 @@
     cc = cc_;
     setSize(width, height);
     im = new PixelBufferImage(width, height, cc, this);
-    im.image.setAccelerationPriority(1);
 
     cursor = new Cursor();
     cursorBacking = new ManagedPixelBuffer();
@@ -85,7 +84,7 @@
   // DesktopWindow has actually been made visible so that getGraphics() ought
   // to work.
 
-  public void initGraphics() { 
+  synchronized public void initGraphics() { 
     cc.viewport.g = cc.viewport.getGraphics(); 
     graphics = getComponentGraphics(cc.viewport.g);
     prepareImage(im.image, scaledWidth, scaledHeight, this);
@@ -111,8 +110,9 @@
     // might be being altered by the GUI thread.  However it's only a single
     // boolean and it doesn't matter if we get the wrong value anyway.
 
-    synchronized(this) {
-    if (!cc.viewer.useLocalCursor.getValue()) return;
+    synchronized(cc.viewer.useLocalCursor) {
+      if (!cc.viewer.useLocalCursor.getValue())
+        return;
     }
 
     hideLocalCursor();
@@ -211,7 +211,7 @@
     int h = cc.cp.height;
     hideLocalCursor();
     setSize(w, h);
-    synchronized (this) { 
+    synchronized (im) { 
       im.resize(w, h);
     }
   }
@@ -224,7 +224,7 @@
     int h = invalidBottom - y;
     invalidRect = false;
 
-    synchronized (this) {
+    synchronized (im) {
       im.put(x, y, w, h, graphics);
     }
   }
@@ -258,7 +258,7 @@
   final public void fillRect(int x, int y, int w, int h, int pix)
   {
     if (overlapsCursor(x, y, w, h)) hideLocalCursor();
-    synchronized (this) { 
+    synchronized (im) { 
       im.fillRect(x, y, w, h, pix);
     }
     invalidate(x, y, w, h);
@@ -269,7 +269,7 @@
   final public void imageRect(int x, int y, int w, int h,
                                            int[] pix) {
     if (overlapsCursor(x, y, w, h)) hideLocalCursor();
-    synchronized (this) {
+    synchronized (im) {
       im.imageRect(x, y, w, h, pix);
     }
     invalidate(x, y, w, h);
@@ -281,7 +281,7 @@
                                           int srcX, int srcY) {
     if (overlapsCursor(x, y, w, h) || overlapsCursor(srcX, srcY, w, h))
       hideLocalCursor();
-    synchronized (this) {
+    synchronized (im) {
       im.copyRect(x, y, w, h, srcX, srcY);
     }
     if (!cc.viewer.fastCopyRect.getValue()) {
@@ -407,7 +407,7 @@
       // - Render the cursor!
       if (e.getX() != cursorPosX || e.getY() != cursorPosY) {
         hideLocalCursor();
-        synchronized(this) {
+        synchronized(im) {
           if (e.getX() >= 0 && e.getX() < im.width() &&
               e.getY() >= 0 && e.getY() < im.height()) {
             cursorPosX = e.getX();
@@ -473,7 +473,7 @@
   // Note that mutex MUST be held when hideLocalCursor() and showLocalCursor()
   // are called.
 
-  private void hideLocalCursor() {
+  synchronized private void hideLocalCursor() {
     // - Blit the cursor backing store over the cursor
     if (cursorVisible) {
       cursorVisible = false;
@@ -484,7 +484,7 @@
     }
   }
 
-  private void showLocalCursor() {
+  synchronized private void showLocalCursor() {
     if (cursorAvailable && !cursorVisible) {
       if (!im.getPF().equal(cursor.getPF()) ||
           cursor.width() == 0 || cursor.height() == 0) {
@@ -522,15 +522,13 @@
 
   // run() is executed by the setColourMapEntriesTimerThread - it sleeps for
   // 100ms before actually updating the colourmap.
-  public void run() {
+  synchronized public void run() {
     try {
       Thread.sleep(100);
     } catch (InterruptedException e) {}
-    synchronized (this) {
-      im.updateColourMap();
-      im.put(0, 0, im.width(), im.height(), graphics);
-      setColourMapEntriesTimerThread = null;
-    }
+    im.updateColourMap();
+    im.put(0, 0, im.width(), im.height(), graphics);
+    setColourMapEntriesTimerThread = null;
   }
 
   // access to cc by different threads is specified in CConn
diff --git a/java/com/tigervnc/vncviewer/PixelBufferImage.java b/java/com/tigervnc/vncviewer/PixelBufferImage.java
index bb7e0e4..ef0eed8 100644
--- a/java/com/tigervnc/vncviewer/PixelBufferImage.java
+++ b/java/com/tigervnc/vncviewer/PixelBufferImage.java
@@ -63,7 +63,7 @@
     width_ = w;
     height_ = h;
     image = desktop.createImage(this);
-    //image.setAccelerationPriority(1);
+    image.setAccelerationPriority(1);
 
     data = new int[width() * height()];