]> source.dussan.org Git - tigervnc.git/commitdiff
Extend JavaPixelBuffer to make further use of Graphics2D ops
authorBrian P. Hinz <bphinz@users.sf.net>
Thu, 25 May 2017 03:17:37 +0000 (23:17 -0400)
committerBrian P. Hinz <bphinz@users.sf.net>
Thu, 25 May 2017 03:35:07 +0000 (23:35 -0400)
java/com/tigervnc/vncviewer/JavaPixelBuffer.java

index 4febec15ed4af3ab9b695d52262085ed09f89798..016b8cf87860ea8e42feaf23aaed8ecb87bc714f 100644 (file)
@@ -24,6 +24,7 @@ import java.awt.image.*;
 import java.nio.*;
 
 import com.tigervnc.rfb.*;
+import com.tigervnc.rfb.Point;
 
 public class JavaPixelBuffer extends PlatformPixelBuffer 
 {
@@ -36,6 +37,23 @@ public class JavaPixelBuffer extends PlatformPixelBuffer
     image.setAccelerationPriority(1);
   }
 
+  public WritableRaster getBufferRW(Rect r)
+  {
+    synchronized(image) {
+      return ((BufferedImage)image)
+        .getSubimage(r.tl.x, r.tl.y, r.width(), r.height()).getRaster();
+    }
+  }
+
+  public Raster getBuffer(Rect r)
+  {
+    Rectangle rect =
+      new Rectangle(r.tl.x, r.tl.y, r.width(), r.height());
+    synchronized(image) {
+      return ((BufferedImage)image).getData(rect);
+    }
+  }
+
   public void fillRect(Rect r, byte[] pix)
   {
     ColorModel cm = format.getColorModel();
@@ -43,7 +61,7 @@ public class JavaPixelBuffer extends PlatformPixelBuffer
       ByteBuffer.wrap(pix).order(format.getByteOrder()).asIntBuffer().get(0);
     Color c = new Color(cm.getRGB(pixel));
     synchronized(image) {
-      Graphics2D g2 = ((BufferedImage)image).createGraphics();
+      Graphics2D g2 = (Graphics2D)image.getGraphics();
       g2.setColor(c);
       g2.fillRect(r.tl.x, r.tl.y, r.width(), r.height());
       g2.dispose();
@@ -52,6 +70,20 @@ public class JavaPixelBuffer extends PlatformPixelBuffer
     commitBufferRW(r);
   }
 
+  public void copyRect(Rect rect, Point move_by_delta)
+  {
+    synchronized(image) {
+      Graphics2D g2 = (Graphics2D)image.getGraphics();
+      g2.copyArea(rect.tl.x - move_by_delta.x,
+                  rect.tl.y - move_by_delta.y,
+                  rect.width(), rect.height(),
+                  move_by_delta.x, move_by_delta.y);
+      g2.dispose();
+    }
+
+    commitBufferRW(rect);
+  }
+
   private static PixelFormat getPreferredPF()
   {
     GraphicsEnvironment ge =