aboutsummaryrefslogtreecommitdiffstats
path: root/java/com/tigervnc/vncviewer/BIPixelBuffer.java
diff options
context:
space:
mode:
authorBrian Hinz <bphinz@users.sourceforge.net>2012-04-05 02:08:49 +0000
committerBrian Hinz <bphinz@users.sourceforge.net>2012-04-05 02:08:49 +0000
commit28aa3a810f56b89d90ae32e5e75101db133ff530 (patch)
treef718ef00c7f0c2bbded56225f50eb62e19a1e1c4 /java/com/tigervnc/vncviewer/BIPixelBuffer.java
parent0878eca6aa47106a24fee53ab3791c677fdfefbe (diff)
downloadtigervnc-28aa3a810f56b89d90ae32e5e75101db133ff530.tar.gz
tigervnc-28aa3a810f56b89d90ae32e5e75101db133ff530.zip
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
Diffstat (limited to 'java/com/tigervnc/vncviewer/BIPixelBuffer.java')
-rw-r--r--java/com/tigervnc/vncviewer/BIPixelBuffer.java105
1 files changed, 105 insertions, 0 deletions
diff --git a/java/com/tigervnc/vncviewer/BIPixelBuffer.java b/java/com/tigervnc/vncviewer/BIPixelBuffer.java
new file mode 100644
index 00000000..cc19c1da
--- /dev/null
+++ b/java/com/tigervnc/vncviewer/BIPixelBuffer.java
@@ -0,0 +1,105 @@
+/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
+ * Copyright (C) 2011-2012 TigerVNC Team.
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ * USA.
+ */
+
+package com.tigervnc.vncviewer;
+
+import java.awt.*;
+import java.awt.image.*;
+
+import com.tigervnc.rfb.*;
+import com.tigervnc.rfb.Exception;
+
+public class BIPixelBuffer extends PlatformPixelBuffer
+{
+ public BIPixelBuffer(int w, int h, CConn cc_, DesktopWindow desktop_) {
+ super(w, h, cc_, desktop_);
+ }
+
+ // resize() resizes the image, preserving the image data where possible.
+ public void resize(int w, int h) {
+ if (w == width() && h == height()) return;
+
+ width_ = w;
+ height_ = h;
+ GraphicsEnvironment ge =
+ GraphicsEnvironment.getLocalGraphicsEnvironment();
+ GraphicsDevice gd = ge.getDefaultScreenDevice();
+ GraphicsConfiguration gc = gd.getDefaultConfiguration();
+ image = gc.createCompatibleImage(w, h, Transparency.OPAQUE);
+ image.setAccelerationPriority(1);
+ image.createGraphics();
+ }
+
+ public void fillRect(int x, int y, int w, int h, int pix) {
+ Graphics2D graphics = (Graphics2D)image.getGraphics();
+ switch (format.depth) {
+ case 24:
+ graphics.setColor(new Color(pix));
+ graphics.fillRect(x, y, w, h);
+ break;
+ default:
+ Color color = new Color((0xff << 24) | (cm.getRed(pix) << 16) |
+ (cm.getGreen(pix) << 8) | (cm.getBlue(pix)));
+ graphics.setColor(color);
+ graphics.fillRect(x, y, w, h);
+ break;
+ }
+ graphics.dispose();
+ }
+
+ public void imageRect(int x, int y, int w, int h, Object pix) {
+ Graphics2D graphics = (Graphics2D)image.getGraphics();
+ Image img;
+ if (pix instanceof Image) {
+ img = (Image)pix;
+ } else {
+ img = tk.createImage(new MemoryImageSource(w, h, cm, (int[])pix, 0, w));
+ img.setAccelerationPriority(1);
+ }
+ boolean ret = tk.prepareImage(img, -1, -1, null);
+ if (!ret) {
+ while ((tk.checkImage(img, -1, -1, null) & ImageObserver.ALLBITS) == 0) {
+ synchronized (this) {
+ try {
+ this.wait(0, 10000);
+ } catch (InterruptedException e) {
+ throw new Exception("Error decoding JPEG data");
+ }
+ }
+ }
+ }
+ graphics.drawImage(img, x, y, w, h, null);
+ graphics.dispose();
+ img.flush();
+ }
+
+ public void copyRect(int x, int y, int w, int h, int srcX, int srcY) {
+ Graphics2D graphics = (Graphics2D)image.getGraphics();
+ graphics.copyArea(srcX, srcY, w, h, x - srcX, y - srcY);
+ graphics.dispose();
+ }
+
+ public Image getImage() {
+ return (Image)image;
+ }
+
+ BufferedImage image;
+
+ static LogWriter vlog = new LogWriter("BIPixelBuffer");
+}