summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven de Marothy <sven@physto.se>2006-06-03 22:41:40 +0000
committerSven de Marothy <sven@physto.se>2006-06-03 22:41:40 +0000
commitf103d1dbbc989779e4398518fd3da436c919fc76 (patch)
tree81e61c1b0570e31eb2c2a5ca77c5fc909f6447b3
parent2b48e7eda66f88d6f6a57e11c8f438837e23b391 (diff)
downloadclasspath-f103d1dbbc989779e4398518fd3da436c919fc76.tar.gz
2006-06-02 Sven de Marothy <sven@physto.se>
* gnu/java/awt/peer/gtk/VolatileImageGraphics.java * include/gnu_java_awt_peer_gtk_GtkVolatileImage.h * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c New files. * gnu/java/awt/peer/gtk/ComponentGraphics.java (drawImage): Overloads for VolatileImage drawing. (drawVolatile): New method. * native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c * include/gnu_java_awt_peer_gtk_ComponentGraphics.h (drawVolatile): New method. * gnu/java/awt/peer/gtk/GtkVolatileImage.java Unstub implementation. * include/Makefile.am * native/jni/gtk-peer/Makefile.am Add new files. * native/jni/gtk-peer/gtkpeer.h New prototype.
-rw-r--r--ChangeLog20
-rw-r--r--gnu/java/awt/peer/gtk/ComponentGraphics.java32
-rw-r--r--gnu/java/awt/peer/gtk/GtkVolatileImage.java101
-rw-r--r--gnu/java/awt/peer/gtk/VolatileImageGraphics.java129
-rw-r--r--include/Makefile.am1
-rw-r--r--include/gnu_java_awt_peer_gtk_ComponentGraphics.h1
-rw-r--r--include/gnu_java_awt_peer_gtk_GtkVolatileImage.h22
-rw-r--r--native/jni/gtk-peer/Makefile.am1
-rw-r--r--native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c37
-rw-r--r--native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c188
-rw-r--r--native/jni/gtk-peer/gtkpeer.h2
11 files changed, 508 insertions, 26 deletions
diff --git a/ChangeLog b/ChangeLog
index ac9c70bc4..4ca1379bf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2006-06-02 Sven de Marothy <sven@physto.se>
+
+ * gnu/java/awt/peer/gtk/VolatileImageGraphics.java
+ * include/gnu_java_awt_peer_gtk_GtkVolatileImage.h
+ * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c
+ New files.
+ * gnu/java/awt/peer/gtk/ComponentGraphics.java
+ (drawImage): Overloads for VolatileImage drawing.
+ (drawVolatile): New method.
+ * native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c
+ * include/gnu_java_awt_peer_gtk_ComponentGraphics.h
+ (drawVolatile): New method.
+ * gnu/java/awt/peer/gtk/GtkVolatileImage.java
+ Unstub implementation.
+ * include/Makefile.am
+ * native/jni/gtk-peer/Makefile.am
+ Add new files.
+ * native/jni/gtk-peer/gtkpeer.h
+ New prototype.
+
2006-06-03 Roman Kennke <kennke@aicas.com>
PR 27418
diff --git a/gnu/java/awt/peer/gtk/ComponentGraphics.java b/gnu/java/awt/peer/gtk/ComponentGraphics.java
index 70644be1a..2ab96519d 100644
--- a/gnu/java/awt/peer/gtk/ComponentGraphics.java
+++ b/gnu/java/awt/peer/gtk/ComponentGraphics.java
@@ -110,6 +110,10 @@ public class ComponentGraphics extends CairoGraphics2D
private native void copyAreaNative(GtkComponentPeer component, int x, int y,
int width, int height, int dx, int dy);
+ private native void drawVolatile(GtkComponentPeer component,
+ Image vimg, int x, int y,
+ int width, int height);
+
/**
* Returns a Graphics2D object for a component, either an instance of this
* class (if xrender is supported), or a context which copies.
@@ -183,4 +187,32 @@ public class ComponentGraphics extends CairoGraphics2D
super.drawGlyphVector(gv, x, y);
end_gdk_drawing();
}
+
+ public boolean drawImage(Image img, int x, int y, ImageObserver observer)
+ {
+ if( img instanceof GtkVolatileImage )
+ {
+ ((GtkVolatileImage)img).validate( null );
+ drawVolatile( component, img, x, y-20 ,
+ ((GtkVolatileImage)img).width,
+ ((GtkVolatileImage)img).height );
+ return true;
+ }
+ return super.drawImage( img, x, y, observer );
+ }
+
+ public boolean drawImage(Image img, int x, int y, int width, int height,
+ ImageObserver observer)
+ {
+ if( img instanceof GtkVolatileImage )
+ {
+ ((GtkVolatileImage)img).validate( null );
+ drawVolatile( component, img, x, y-20,
+ width, height );
+ return true;
+ }
+ return super.drawImage( img, x, y, width, height, observer );
+ }
+
}
+
diff --git a/gnu/java/awt/peer/gtk/GtkVolatileImage.java b/gnu/java/awt/peer/gtk/GtkVolatileImage.java
index 496090a09..b2f86f543 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.getSharedGtkImage() );
+ 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;
+ }
}
diff --git a/gnu/java/awt/peer/gtk/VolatileImageGraphics.java b/gnu/java/awt/peer/gtk/VolatileImageGraphics.java
new file mode 100644
index 000000000..81de3d705
--- /dev/null
+++ b/gnu/java/awt/peer/gtk/VolatileImageGraphics.java
@@ -0,0 +1,129 @@
+/* VolatileImageGraphics.java
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath 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, or (at your option)
+any later version.
+
+GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.awt.peer.gtk;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.GraphicsConfiguration;
+import java.awt.Image;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.Shape;
+import java.awt.font.GlyphVector;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+import java.awt.image.DataBuffer;
+import java.awt.image.DataBufferInt;
+import java.awt.image.ColorModel;
+import java.awt.image.DirectColorModel;
+import java.awt.image.RenderedImage;
+import java.awt.image.ImageObserver;
+import java.util.WeakHashMap;
+
+public class VolatileImageGraphics extends CairoSurfaceGraphics
+{
+ private GtkVolatileImage owner;
+
+ public VolatileImageGraphics(GtkVolatileImage owner)
+ {
+ super( owner.offScreen );
+ this.owner = owner;
+ }
+
+ VolatileImageGraphics(VolatileImageGraphics copyFrom)
+ {
+ super( copyFrom.owner.offScreen );
+ owner = copyFrom.owner;
+ }
+
+ /**
+ * Abstract methods.
+ */
+ public Graphics create()
+ {
+ return new VolatileImageGraphics( this );
+ }
+
+ public void copyAreaImpl(int x, int y, int width, int height, int dx, int dy)
+ {
+ surface.copyAreaNative(x, y, width, height, dx, dy, surface.width);
+ owner.invalidate();
+ }
+
+ /**
+ * Overloaded methods that do actual drawing need to enter the gdk threads
+ * and also do certain things before and after.
+ */
+ public void draw(Shape s)
+ {
+ super.draw(s);
+ Rectangle r = s.getBounds();
+ owner.invalidate();
+ }
+
+ public void fill(Shape s)
+ {
+ super.fill(s);
+ Rectangle r = s.getBounds();
+ owner.invalidate();
+ }
+
+ public void drawRenderedImage(RenderedImage image, AffineTransform xform)
+ {
+ super.drawRenderedImage(image, xform);
+ owner.invalidate();
+ }
+
+ protected boolean drawImage(Image img, AffineTransform xform,
+ Color bgcolor, ImageObserver obs)
+ {
+ boolean rv = super.drawImage(img, xform, bgcolor, obs);
+ owner.invalidate();
+ return rv;
+ }
+
+ public void drawGlyphVector(GlyphVector gv, float x, float y)
+ {
+ super.drawGlyphVector(gv, x, y);
+ owner.invalidate();
+ }
+}
+
diff --git a/include/Makefile.am b/include/Makefile.am
index d14a443c0..b01611aa4 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -74,6 +74,7 @@ $(top_srcdir)/include/gnu_java_awt_peer_gtk_GtkTextAreaPeer.h \
$(top_srcdir)/include/gnu_java_awt_peer_gtk_GtkTextFieldPeer.h \
$(top_srcdir)/include/gnu_java_awt_peer_gtk_GtkToolkit.h \
$(top_srcdir)/include/gnu_java_awt_peer_gtk_GtkWindowPeer.h \
+$(top_srcdir)/include/gnu_java_awt_peer_gtk_GtkVolatileImage.h \
$(top_srcdir)/include/gnu_java_awt_peer_gtk_GThreadNativeMethodRunner.h
QTPEER_H_FILES = \
diff --git a/include/gnu_java_awt_peer_gtk_ComponentGraphics.h b/include/gnu_java_awt_peer_gtk_ComponentGraphics.h
index 0378d0c54..03917502b 100644
--- a/include/gnu_java_awt_peer_gtk_ComponentGraphics.h
+++ b/include/gnu_java_awt_peer_gtk_ComponentGraphics.h
@@ -15,6 +15,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_start_1gdk_1
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_end_1gdk_1drawing (JNIEnv *env, jobject);
JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_hasXRender (JNIEnv *env, jclass);
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_copyAreaNative (JNIEnv *env, jobject, jobject, jint, jint, jint, jint, jint, jint);
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_drawVolatile (JNIEnv *env, jobject, jobject, jobject, jint, jint, jint, jint);
#ifdef __cplusplus
}
diff --git a/include/gnu_java_awt_peer_gtk_GtkVolatileImage.h b/include/gnu_java_awt_peer_gtk_GtkVolatileImage.h
new file mode 100644
index 000000000..67c08cf7d
--- /dev/null
+++ b/include/gnu_java_awt_peer_gtk_GtkVolatileImage.h
@@ -0,0 +1,22 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+
+#ifndef __gnu_java_awt_peer_gtk_GtkVolatileImage__
+#define __gnu_java_awt_peer_gtk_GtkVolatileImage__
+
+#include <jni.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+JNIEXPORT jlong JNICALL Java_gnu_java_awt_peer_gtk_GtkVolatileImage_init (JNIEnv *env, jobject, jobject, jint, jint);
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkVolatileImage_destroy (JNIEnv *env, jobject);
+JNIEXPORT jintArray JNICALL Java_gnu_java_awt_peer_gtk_GtkVolatileImage_getPixels (JNIEnv *env, jobject);
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkVolatileImage_update (JNIEnv *env, jobject, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __gnu_java_awt_peer_gtk_GtkVolatileImage__ */
diff --git a/native/jni/gtk-peer/Makefile.am b/native/jni/gtk-peer/Makefile.am
index 0cd775b53..a4013cf37 100644
--- a/native/jni/gtk-peer/Makefile.am
+++ b/native/jni/gtk-peer/Makefile.am
@@ -39,6 +39,7 @@ libgtkpeer_la_SOURCES = gnu_java_awt_peer_gtk_CairoSurface.c \
gnu_java_awt_peer_gtk_GtkTextFieldPeer.c \
gnu_java_awt_peer_gtk_GtkToolkit.c \
gnu_java_awt_peer_gtk_GtkWindowPeer.c \
+ gnu_java_awt_peer_gtk_GtkVolatileImage.c \
cairographics2d.h \
gthread-jni.c \
gdkfont.h \
diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c
index c17c223a7..016313330 100644
--- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c
+++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c
@@ -94,8 +94,6 @@ void cp_gtk_grab_current_drawable(GtkWidget *widget, GdkDrawable **draw,
*draw = *win;
gdk_window_get_internal_paint_info (*win, draw, 0, 0);
- /* g_object_ref (*draw); */
- /* FIXME: Unref this. */
}
/**
@@ -211,3 +209,38 @@ Java_gnu_java_awt_peer_gtk_ComponentGraphics_copyAreaNative
gdk_threads_leave();
}
+JNIEXPORT void JNICALL
+Java_gnu_java_awt_peer_gtk_ComponentGraphics_drawVolatile
+(JNIEnv *env, jobject obj __attribute__ ((unused)), jobject peer,
+ jobject img, jint x, jint y, jint w, jint h)
+{
+ GdkPixmap *pixmap;
+ GtkWidget *widget = NULL;
+ void *ptr = NULL;
+ GdkGC *gc;
+
+ gdk_threads_enter();
+
+ ptr = NSA_GET_PTR (env, peer);
+ g_assert (ptr != NULL);
+
+ widget = GTK_WIDGET (ptr);
+ g_assert (widget != NULL);
+
+ while(widget->window != NULL)
+ widget = widget->window;
+ pixmap = cp_gtk_get_pixmap( env, img );
+
+
+ gc = gdk_gc_new( widget );
+ gdk_draw_drawable(widget,
+ gc,
+ pixmap,
+ 0, 0,
+ x, y,
+ w, h);
+
+ schedule_flush ();
+
+ gdk_threads_leave();
+}
diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c
new file mode 100644
index 000000000..c0606e14f
--- /dev/null
+++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c
@@ -0,0 +1,188 @@
+/* gnu_java_awt_peer_gtk_VolatileImage.c
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath 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, or (at your option)
+any later version.
+
+GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include "jcl.h"
+#include "gtkpeer.h"
+#include <gdk/gdkx.h>
+#include <gdk/gdktypes.h>
+#include <gdk/gdkprivate.h>
+#include <gdk/gdkx.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gdk-pixbuf/gdk-pixdata.h>
+
+#include "gnu_java_awt_peer_gtk_GtkVolatileImage.h"
+#include "cairographics2d.h"
+
+/* prototypes */
+static void *getNativeObject( JNIEnv *env, jobject obj );
+static void setNativeObject( JNIEnv *env, jobject obj, void *ptr );
+
+GdkPixmap *cp_gtk_get_pixmap( JNIEnv *env, jobject obj);
+
+/**
+ * Creates a cairo surface, ARGB32, native ordering, premultiplied alpha.
+ */
+JNIEXPORT jlong JNICALL
+Java_gnu_java_awt_peer_gtk_GtkVolatileImage_init (JNIEnv *env, jobject obj,
+ jobject peer,
+ jint width, jint height)
+{
+ GtkWidget *widget = NULL;
+ GdkPixmap* pixmap;
+ void *ptr = NULL;
+
+ gdk_threads_enter();
+
+ if( peer != NULL )
+ {
+ ptr = NSA_GET_PTR (env, peer);
+ g_assert (ptr != NULL);
+
+ widget = GTK_WIDGET (ptr);
+ g_assert (widget != NULL);
+ pixmap = gdk_pixmap_new( widget->window, width, height, -1 );
+ }
+ else
+ pixmap = gdk_pixmap_new( NULL, width, height, 16 );
+
+ gdk_threads_leave();
+
+ g_assert( pixmap != NULL );
+
+ return PTR_TO_JLONG( pixmap );
+}
+
+/**
+ * Destroy the surface
+ */
+JNIEXPORT void JNICALL
+Java_gnu_java_awt_peer_gtk_GtkVolatileImage_destroy (JNIEnv *env, jobject obj)
+{
+ GdkPixmap* pixmap = getNativeObject(env, obj);
+ if( pixmap != NULL )
+ {
+ gdk_threads_enter();
+ g_object_unref( pixmap );
+ gdk_threads_leave();
+ }
+}
+
+/**
+ * Gets all pixels in an array
+ */
+JNIEXPORT jintArray JNICALL
+Java_gnu_java_awt_peer_gtk_GtkVolatileImage_getPixels
+(JNIEnv *env, jobject obj)
+{
+ jint *pixeldata, *jpixdata;
+ GdkPixmap *pixmap;
+ jintArray jpixels;
+ int width, height, depth, size;
+ jclass cls;
+ jfieldID field;
+
+ cls = (*env)->GetObjectClass (env, obj);
+ field = (*env)->GetFieldID (env, cls, "width", "I");
+ g_assert (field != 0);
+ width = (*env)->GetIntField (env, obj, field);
+
+ field = (*env)->GetFieldID (env, cls, "height", "I");
+ g_assert (field != 0);
+ height = (*env)->GetIntField (env, obj, field);
+
+ pixmap = (jint *)getNativeObject(env, obj);
+ g_assert(pixmap != NULL);
+
+ gdk_threads_enter();
+
+ /* get depth in bytes */
+ depth = gdk_drawable_get_depth( pixmap ) >> 3;
+ size = width * height * 4;
+ jpixels = (*env)->NewIntArray ( env, size );
+ jpixdata = (*env)->GetIntArrayElements (env, jpixels, NULL);
+ /* memcpy (jpixdata, pixeldata, size * sizeof( jint )); */
+
+ (*env)->ReleaseIntArrayElements (env, jpixels, jpixdata, 0);
+
+ gdk_threads_leave();
+
+ return jpixels;
+}
+
+/**
+ * Update the pixels.
+ */
+JNIEXPORT void JNICALL
+Java_gnu_java_awt_peer_gtk_GtkVolatileImage_update
+(JNIEnv *env, jobject obj, jobject gtkimage)
+{
+ GdkPixmap *pixmap = getNativeObject(env, obj);
+ GdkPixbuf *pixbuf;
+
+ gdk_threads_enter();
+ g_assert( pixmap != NULL );
+
+ pixbuf = cp_gtk_image_get_pixbuf (env, gtkimage);
+ g_assert( pixbuf != NULL );
+
+ gdk_draw_pixbuf (pixmap, NULL, pixbuf,
+ 0, 0, 0, 0, /* src and dest x, y */
+ -1, -1, /* full width, height */
+ GDK_RGB_DITHER_NORMAL, 0, 0);
+ gdk_threads_leave();
+}
+
+GdkPixmap *cp_gtk_get_pixmap( JNIEnv *env, jobject obj)
+{
+ return (GdkPixmap *)getNativeObject(env, obj);
+}
+
+/**
+ * Gets the native object field.
+ */
+static void *
+getNativeObject( JNIEnv *env, jobject obj )
+{
+ jclass cls;
+ jlong value;
+ jfieldID nofid;
+ cls = (*env)->GetObjectClass( env, obj );
+ nofid = (*env)->GetFieldID( env, cls, "nativePointer", "J" );
+ value = (*env)->GetLongField( env, obj, nofid );
+ (*env)->DeleteLocalRef( env, cls );
+ return JLONG_TO_PTR(void, value);
+}
diff --git a/native/jni/gtk-peer/gtkpeer.h b/native/jni/gtk-peer/gtkpeer.h
index ebdd365ea..065d20608 100644
--- a/native/jni/gtk-peer/gtkpeer.h
+++ b/native/jni/gtk-peer/gtkpeer.h
@@ -209,6 +209,8 @@ void cp_gtk_textcomponent_connect_signals (GObject *ptr, jobject *gref);
/* Debugging */
void cp_gtk_print_current_thread (void);
+GdkPixmap *cp_gtk_get_pixmap( JNIEnv *env, jobject obj);
+
#define SYNCHRONIZE_GDK 0
#define DEBUG_LOCKING 0