From: Brian Hinz Date: Wed, 12 Oct 2011 03:38:19 +0000 (+0000) Subject: Some tweaks to improve performance. X-Git-Tag: v1.1.90~89 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=83ca5ec408c3110a231dd6502c9d6a2e5e6a2098;p=tigervnc.git Some tweaks to improve performance. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4721 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- diff --git a/java/com/tigervnc/vncviewer/CConn.java b/java/com/tigervnc/vncviewer/CConn.java index d9e16829..089d241a 100644 --- a/java/com/tigervnc/vncviewer/CConn.java +++ b/java/com/tigervnc/vncviewer/CConn.java @@ -104,6 +104,7 @@ class ViewportFrame extends JFrame public void addChild(DesktopWindow child) { sp = new JScrollPane(child); + sp.setDoubleBuffered(true); child.setBackground(Color.BLACK); child.setOpaque(true); sp.setBorder(BorderFactory.createEmptyBorder(0,0,0,0)); @@ -699,8 +700,10 @@ public class CConn extends CConnection JOptionPane.PLAIN_MESSAGE); } - synchronized public void refresh() { - writer().writeFramebufferUpdateRequest(new Rect(0,0,cp.width,cp.height), false); + public void refresh() { + synchronized (this) { + writer().writeFramebufferUpdateRequest(new Rect(0,0,cp.width,cp.height), false); + } pendingUpdate = true; } @@ -1158,7 +1161,7 @@ public class CConn extends CConnection } - synchronized public void writePointerEvent(MouseEvent ev) { + public void writePointerEvent(MouseEvent ev) { if (state() != RFBSTATE_NORMAL) return; switch (ev.getID()) { @@ -1172,7 +1175,9 @@ public class CConn extends CConnection break; } - writeModifiers(ev.getModifiers() & ~KeyEvent.ALT_MASK & ~KeyEvent.META_MASK); + synchronized (this) { + writeModifiers(ev.getModifiers() & ~KeyEvent.ALT_MASK & ~KeyEvent.META_MASK); + } if (cp.width != desktop.scaledWidth || cp.height != desktop.scaledHeight) { @@ -1181,8 +1186,9 @@ public class CConn extends CConnection int sy = (desktop.scaleHeightRatio == 1.00) ? ev.getY() : (int)Math.floor(ev.getY()/desktop.scaleHeightRatio); ev.translatePoint(sx - ev.getX(), sy - ev.getY()); - writer().writePointerEvent(new Point(ev.getX(),ev.getY()), buttonMask); - } else { + } + + synchronized (this) { writer().writePointerEvent(new Point(ev.getX(),ev.getY()), buttonMask); } @@ -1212,7 +1218,7 @@ public class CConn extends CConnection } - void writeModifiers(int m) { + synchronized void writeModifiers(int m) { if ((m & Event.SHIFT_MASK) != (pressedModifiers & Event.SHIFT_MASK)) writeKeyEvent(Keysyms.Shift_L, (m & Event.SHIFT_MASK) != 0); if ((m & Event.CTRL_MASK) != (pressedModifiers & Event.CTRL_MASK)) diff --git a/java/com/tigervnc/vncviewer/DesktopWindow.java b/java/com/tigervnc/vncviewer/DesktopWindow.java index 21e2e8ea..8bf718b1 100644 --- a/java/com/tigervnc/vncviewer/DesktopWindow.java +++ b/java/com/tigervnc/vncviewer/DesktopWindow.java @@ -55,6 +55,7 @@ class DesktopWindow extends JPanel implements cc = cc_; setSize(width, height); im = new PixelBufferImage(width, height, cc, this); + im.image.setAccelerationPriority(1); cursor = new Cursor(); cursorBacking = new ManagedPixelBuffer(); @@ -69,7 +70,6 @@ class DesktopWindow extends JPanel implements }); setFocusTraversalKeysEnabled(false); setFocusable(true); - setDoubleBuffered(true); } public int width() { @@ -113,6 +113,7 @@ class DesktopWindow extends JPanel implements synchronized(this) { if (!cc.viewer.useLocalCursor.getValue()) return; + } hideLocalCursor(); @@ -162,7 +163,6 @@ class DesktopWindow extends JPanel implements tk.createImage(bitmap).getScaledInstance(cw,ch,hint); softCursor = tk.createCustomCursor(cursorImage, new java.awt.Point(hotspot.x,hotspot.y), "Cursor"); - } if (softCursor != null) { setCursor(softCursor); @@ -206,12 +206,14 @@ class DesktopWindow extends JPanel implements } // resize() is called when the desktop has changed size - synchronized public void resize() { + public void resize() { int w = cc.cp.width; int h = cc.cp.height; hideLocalCursor(); setSize(w, h); - im.resize(w, h); + synchronized (this) { + im.resize(w, h); + } } final void drawInvalidRect() { @@ -253,29 +255,35 @@ class DesktopWindow extends JPanel implements drawInvalidRect(); } - synchronized final public void fillRect(int x, int y, int w, int h, int pix) + final public void fillRect(int x, int y, int w, int h, int pix) { if (overlapsCursor(x, y, w, h)) hideLocalCursor(); - im.fillRect(x, y, w, h, pix); + synchronized (this) { + im.fillRect(x, y, w, h, pix); + } invalidate(x, y, w, h); if (softCursor == null) showLocalCursor(); } - synchronized final public void imageRect(int x, int y, int w, int h, + final public void imageRect(int x, int y, int w, int h, int[] pix) { if (overlapsCursor(x, y, w, h)) hideLocalCursor(); - im.imageRect(x, y, w, h, pix); + synchronized (this) { + im.imageRect(x, y, w, h, pix); + } invalidate(x, y, w, h); if (softCursor == null) showLocalCursor(); } - synchronized final public void copyRect(int x, int y, int w, int h, + final public void copyRect(int x, int y, int w, int h, int srcX, int srcY) { if (overlapsCursor(x, y, w, h) || overlapsCursor(srcX, srcY, w, h)) hideLocalCursor(); - im.copyRect(x, y, w, h, srcX, srcY); + synchronized (this) { + im.copyRect(x, y, w, h, srcX, srcY); + } if (!cc.viewer.fastCopyRect.getValue()) { invalidate(x, y, w, h); } @@ -293,7 +301,7 @@ class DesktopWindow extends JPanel implements //////////////////////////////////////////////////////////////////// // The following methods are all called from the GUI thread - synchronized void resetLocalCursor() { + void resetLocalCursor() { hideLocalCursor(); cursorAvailable = false; } @@ -350,7 +358,7 @@ class DesktopWindow extends JPanel implements scaleHeightRatio = (float)scaledHeight / (float)cc.cp.height; } - synchronized public void paintComponent(Graphics g) { + public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); @@ -362,7 +370,7 @@ class DesktopWindow extends JPanel implements g2.drawImage(im.image, 0, 0, scaledWidth, scaledHeight, null); } } - + String oldContents = ""; synchronized public void checkClipboard() { @@ -395,11 +403,11 @@ class DesktopWindow extends JPanel implements if (!cc.viewer.viewOnly.getValue()) cc.writePointerEvent(e); // - If local cursor rendering is enabled then use it - synchronized(this) { - if (cursorAvailable) { - // - Render the cursor! - if (e.getX() != cursorPosX || e.getY() != cursorPosY) { - hideLocalCursor(); + if (cursorAvailable) { + // - Render the cursor! + if (e.getX() != cursorPosX || e.getY() != cursorPosY) { + hideLocalCursor(); + synchronized(this) { if (e.getX() >= 0 && e.getX() < im.width() && e.getY() >= 0 && e.getY() < im.height()) { cursorPosX = e.getX(); diff --git a/java/com/tigervnc/vncviewer/PixelBufferImage.java b/java/com/tigervnc/vncviewer/PixelBufferImage.java index ccac4823..bb7e0e48 100644 --- a/java/com/tigervnc/vncviewer/PixelBufferImage.java +++ b/java/com/tigervnc/vncviewer/PixelBufferImage.java @@ -103,6 +103,7 @@ public class PixelBufferImage extends PixelBuffer implements ImageProducer public void put(int x, int y, int w, int h, Graphics g) { if (ic != null) { ic.setPixels(x, y, w, h, cm, data, width() * y + x, width()); + g.setClip(x, y, w, h); ic.imageComplete(ImageConsumer.SINGLEFRAMEDONE); } }