summaryrefslogtreecommitdiff
path: root/gnu/java/awt/peer/gtk/GtkVolatileImage.java
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/java/awt/peer/gtk/GtkVolatileImage.java')
-rw-r--r--gnu/java/awt/peer/gtk/GtkVolatileImage.java101
1 files changed, 77 insertions, 24 deletions
diff --git a/gnu/java/awt/peer/gtk/GtkVolatileImage.java b/gnu/java/awt/peer/gtk/GtkVolatileImage.java
index 496090a09..cebb715ab 100644
--- a/gnu/java/awt/peer/gtk/GtkVolatileImage.java
+++ b/gnu/java/awt/peer/gtk/GtkVolatileImage.java
@@ -1,4 +1,4 @@
-/* GtkVolatileImage.java -- a hardware-accelerated image buffer
+/* GtkVolatileImage.java -- wraps an X pixmap
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,6 +38,7 @@ exception statement from your version. */
package gnu.java.awt.peer.gtk;
import java.awt.ImageCapabilities;
+import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.image.BufferedImage;
@@ -46,54 +47,96 @@ import java.awt.image.VolatileImage;
public class GtkVolatileImage extends VolatileImage
{
- private int width;
- private int height;
+ int width, height;
private ImageCapabilities caps;
- public GtkVolatileImage(int width, int height)
- {
- this(width, height, null);
- }
+ /**
+ * Don't touch, accessed from native code.
+ */
+ private long nativePointer;
- public GtkVolatileImage(int width, int height, ImageCapabilities caps)
+ /**
+ * Offscreen image we draw to.
+ */
+ CairoSurface offScreen;
+
+ private boolean needsUpdate = false;
+
+ native long init(GtkComponentPeer component, int width, int height);
+
+ native void destroy();
+
+ native int[] getPixels();
+
+ native void update(GtkImage image);
+
+ public GtkVolatileImage(GtkComponentPeer component,
+ int width, int height, ImageCapabilities caps)
{
this.width = width;
this.height = height;
this.caps = caps;
+ nativePointer = init( component, width, height );
+ offScreen = new CairoSurface( width, height );
}
- // FIXME: should return a buffered image snapshot of the accelerated
- // visual
- public BufferedImage getSnapshot()
+ public GtkVolatileImage(int width, int height, ImageCapabilities caps)
{
- return null;
+ this(null, width, height, caps);
}
- public int getWidth()
+ public GtkVolatileImage(int width, int height)
{
- return width;
+ this(null, width, height, null);
}
- public int getHeight()
+ public void finalize()
{
- return height;
+ dispose();
+ }
+
+ public void dispose()
+ {
+ destroy();
+ }
+
+ void invalidate()
+ {
+ needsUpdate = true;
+ }
+
+ public BufferedImage getSnapshot()
+ {
+ CairoSurface cs = new CairoSurface( width, height );
+ cs.setPixels( getPixels() );
+ return CairoSurface.getBufferedImage( cs );
+ }
+
+ public Graphics getGraphics()
+ {
+ return createGraphics();
}
- // FIXME: should return a graphics wrapper around this image's
- // visual
public Graphics2D createGraphics()
{
- return null;
+ invalidate();
+ return offScreen.getGraphics();
}
public int validate(GraphicsConfiguration gc)
{
+ if( needsUpdate )
+ {
+ update( offScreen.getGtkImage() );
+ needsUpdate = false;
+ return VolatileImage.IMAGE_RESTORED;
+ }
return VolatileImage.IMAGE_OK;
}
public boolean contentsLost()
{
- return false;
+ return needsUpdate;
}
public ImageCapabilities getCapabilities()
@@ -101,18 +144,28 @@ public class GtkVolatileImage extends VolatileImage
return caps;
}
- public synchronized Object getProperty (String name, ImageObserver observer)
+ public int getWidth()
+ {
+ return width;
+ }
+
+ public int getHeight()
{
- return null;
+ return height;
}
- public synchronized int getWidth (ImageObserver observer)
+ public int getWidth(java.awt.image.ImageObserver observer)
{
return width;
}
- public synchronized int getHeight (ImageObserver observer)
+ public int getHeight(java.awt.image.ImageObserver observer)
{
return height;
}
+
+ public Object getProperty(String name, ImageObserver observer)
+ {
+ return null;
+ }
}