From e4d46b64223f3cb5572eca1306611fb25856b579 Mon Sep 17 00:00:00 2001 From: Brian Hinz Date: Sun, 26 Aug 2012 18:20:15 +0000 Subject: [PATCH] Significantly improve performance by eliminating the intermediary MemoryImageSource and instead directly modifying the pixels in the BufferedImage. Supposedly, doing this causes the BufferedImage to become unmanaged. At one time, unmanaged images weren't hardware-accelerated on some platforms, but that doesn't seem to be the case with Java 1.5 and later. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4960 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- .../com/tigervnc/vncviewer/BIPixelBuffer.java | 25 +++++-------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/java/com/tigervnc/vncviewer/BIPixelBuffer.java b/java/com/tigervnc/vncviewer/BIPixelBuffer.java index d5ec7b6b..88c93963 100644 --- a/java/com/tigervnc/vncviewer/BIPixelBuffer.java +++ b/java/com/tigervnc/vncviewer/BIPixelBuffer.java @@ -1,4 +1,5 @@ /* Copyright (C) 2012 Brian P. Hinz + * Copyright (C) 2012 D. R. Commander. All Rights Reserved. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,14 +34,10 @@ public class BIPixelBuffer extends PlatformPixelBuffer implements ImageObserver public void setPF(PixelFormat pf) { super.setPF(pf); - if (source != null) - source.newPixels(data, cm, 0, width_); } public void updateColourMap() { cm = new IndexColorModel(8, nColours, reds, greens, blues); - if (source != null) - source.newPixels(data, cm, 0, width_); } // resize() resizes the image, preserving the image data where possible. @@ -56,12 +53,11 @@ public class BIPixelBuffer extends PlatformPixelBuffer implements ImageObserver image = gc.createCompatibleImage(w, h, Transparency.TRANSLUCENT); image.setAccelerationPriority(1); image.createGraphics(); - data = new int[width() * height()]; - source = new MemoryImageSource(w, h, cm, data, 0, w); - source.setAnimated(true); - source.setFullBufferUpdates(false); - source.newPixels(data, cm, 0, width_); - sourceImage = tk.createImage(source); + WritableRaster wr = image.getRaster(); + SinglePixelPackedSampleModel sm = + (SinglePixelPackedSampleModel)image.getSampleModel(); + DataBufferInt db = (DataBufferInt)wr.getDataBuffer(); + data = db.getData(); } public void fillRect(int x, int y, int w, int h, int pix) { @@ -98,12 +94,6 @@ public class BIPixelBuffer extends PlatformPixelBuffer implements ImageObserver } else { for (int j = 0; j < h; j++) System.arraycopy(pix, (w*j), data, width_ * (y + j) + x, w); - source.newPixels(x, y, w, h, true); - Graphics2D graphics = (Graphics2D)image.getGraphics(); - graphics.setClip(x, y, w, h); - graphics.drawImage(sourceImage, 0, 0, null); - graphics.setClip(0, 0, width(), height()); - graphics.dispose(); } } @@ -136,9 +126,6 @@ public class BIPixelBuffer extends PlatformPixelBuffer implements ImageObserver } BufferedImage image; - MemoryImageSource source; - int[] data; - Image sourceImage; Rectangle clip; static LogWriter vlog = new LogWriter("BIPixelBuffer"); -- 2.39.5