2006-06-05 Sven de Marothy <[EMAIL PROTECTED]> * include/gnu_java_awt_peer_gtk_ComponentGraphics.h * native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c * gnu/java/awt/peer/gtk/ComponentGraphics.java (initFromVolatile): New method. * gnu/java/awt/peer/gtk/GtkVolatileImage.java * gnu/java/awt/peer/gtk/VolatileImageGraphics.java Reimplement. * include/gnu_java_awt_peer_gtk_GtkVolatileImage.h * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c (copyArea, drawVolatileImage): New methods.
Index: gnu/java/awt/peer/gtk/ComponentGraphics.java =================================================================== RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java,v retrieving revision 1.9 diff -U3 -r1.9 ComponentGraphics.java --- gnu/java/awt/peer/gtk/ComponentGraphics.java 5 Jun 2006 03:39:14 -0000 1.9 +++ gnu/java/awt/peer/gtk/ComponentGraphics.java 6 Jun 2006 02:13:44 -0000 @@ -46,6 +46,7 @@ import java.awt.Image; import java.awt.Rectangle; import java.awt.Shape; +import java.awt.Point; import java.awt.font.FontRenderContext; import java.awt.font.GlyphVector; import java.awt.geom.AffineTransform; @@ -64,8 +65,12 @@ public class ComponentGraphics extends CairoGraphics2D { private GtkComponentPeer component; - private long cairo_t; + protected long cairo_t; + ComponentGraphics() + { + } + private ComponentGraphics(GtkComponentPeer component) { this.component = component; @@ -94,6 +99,11 @@ private native long initState(GtkComponentPeer component); /** + * Creates a cairo_t for a volatile image + */ + protected native long initFromVolatile( long pixmapPtr, int width, int height); + + /** * Grab lock */ private native void start_gdk_drawing(); @@ -194,8 +204,7 @@ { if( img instanceof GtkVolatileImage ) { - ((GtkVolatileImage)img).validate( null ); - drawVolatile( component, img, x, y-20 , + drawVolatile( component, img, x, y - 20, ((GtkVolatileImage)img).width, ((GtkVolatileImage)img).height ); return true; @@ -208,8 +217,7 @@ { if( img instanceof GtkVolatileImage ) { - ((GtkVolatileImage)img).validate( null ); - drawVolatile( component, img, x, y-20, + drawVolatile( component, img, x, y - 20, width, height ); return true; } Index: gnu/java/awt/peer/gtk/GtkVolatileImage.java =================================================================== RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/GtkVolatileImage.java,v retrieving revision 1.5 diff -U3 -r1.5 GtkVolatileImage.java --- gnu/java/awt/peer/gtk/GtkVolatileImage.java 4 Jun 2006 19:44:39 -0000 1.5 +++ gnu/java/awt/peer/gtk/GtkVolatileImage.java 6 Jun 2006 02:13:44 -0000 @@ -53,23 +53,18 @@ /** * Don't touch, accessed from native code. */ - private long nativePointer; - - /** - * Offscreen image we draw to. - */ - CairoSurface offScreen; - - private boolean needsUpdate = false; + long nativePointer; native long init(GtkComponentPeer component, int width, int height); native void destroy(); native int[] getPixels(); - - native void update(GtkImage image); + native void copyArea( int x, int y, int w, int h, int dx, int dy ); + + native void drawVolatile( long ptr, int x, int y, int w, int h ); + public GtkVolatileImage(GtkComponentPeer component, int width, int height, ImageCapabilities caps) { @@ -77,7 +72,6 @@ this.height = height; this.caps = caps; nativePointer = init( component, width, height ); - offScreen = new CairoSurface( width, height ); } public GtkVolatileImage(int width, int height, ImageCapabilities caps) @@ -100,11 +94,6 @@ destroy(); } - void invalidate() - { - needsUpdate = true; - } - public BufferedImage getSnapshot() { CairoSurface cs = new CairoSurface( width, height ); @@ -119,24 +108,17 @@ public Graphics2D createGraphics() { - invalidate(); - return offScreen.getGraphics(); + return new VolatileImageGraphics( this ); } public int validate(GraphicsConfiguration gc) { - if( needsUpdate ) - { - update( offScreen.getGtkImage() ); - needsUpdate = false; - return VolatileImage.IMAGE_RESTORED; - } return VolatileImage.IMAGE_OK; } public boolean contentsLost() { - return needsUpdate; + return false; } public ImageCapabilities getCapabilities() Index: gnu/java/awt/peer/gtk/VolatileImageGraphics.java =================================================================== RCS file: /sources/classpath/classpath/gnu/java/awt/peer/gtk/VolatileImageGraphics.java,v retrieving revision 1.1 diff -U3 -r1.1 VolatileImageGraphics.java --- gnu/java/awt/peer/gtk/VolatileImageGraphics.java 3 Jun 2006 22:41:41 -0000 1.1 +++ gnu/java/awt/peer/gtk/VolatileImageGraphics.java 6 Jun 2006 02:13:44 -0000 @@ -58,72 +58,65 @@ import java.awt.image.ImageObserver; import java.util.WeakHashMap; -public class VolatileImageGraphics extends CairoSurfaceGraphics +public class VolatileImageGraphics extends ComponentGraphics { private GtkVolatileImage owner; - public VolatileImageGraphics(GtkVolatileImage owner) + public VolatileImageGraphics(GtkVolatileImage img) { - super( owner.offScreen ); - this.owner = owner; - } - - VolatileImageGraphics(VolatileImageGraphics copyFrom) - { - super( copyFrom.owner.offScreen ); - owner = copyFrom.owner; + this.owner = img; + cairo_t = initFromVolatile( owner.nativePointer, img.width, img.height ); + setup( cairo_t ); + setClip( new Rectangle( 0, 0, img.width, img.height) ); } - /** - * Abstract methods. - */ - public Graphics create() + private VolatileImageGraphics(VolatileImageGraphics copy) { - return new VolatileImageGraphics( this ); + this.owner = copy.owner; + initFromVolatile( owner.nativePointer, owner.width, owner.height ); + setClip( new Rectangle( 0, 0, owner.width, owner.height) ); + copy( copy, cairo_t ); } - + 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(); + owner.copyArea(x, y, width, height, dx, dy); } - /** - * 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) + public GraphicsConfiguration getDeviceConfiguration() { - super.draw(s); - Rectangle r = s.getBounds(); - owner.invalidate(); + return null; } - public void fill(Shape s) + public Graphics create() { - super.fill(s); - Rectangle r = s.getBounds(); - owner.invalidate(); + return new VolatileImageGraphics( this ); } - public void drawRenderedImage(RenderedImage image, AffineTransform xform) - { - super.drawRenderedImage(image, xform); - owner.invalidate(); - } - protected boolean drawImage(Image img, AffineTransform xform, - Color bgcolor, ImageObserver obs) + public boolean drawImage(Image img, int x, int y, ImageObserver observer) { - boolean rv = super.drawImage(img, xform, bgcolor, obs); - owner.invalidate(); - return rv; + if( img instanceof GtkVolatileImage ) + { + owner.drawVolatile( ((GtkVolatileImage)img).nativePointer, + x, y, + ((GtkVolatileImage)img).width, + ((GtkVolatileImage)img).height ); + return true; + } + return super.drawImage( img, x, y, observer ); } - - public void drawGlyphVector(GlyphVector gv, float x, float y) + + public boolean drawImage(Image img, int x, int y, int width, int height, + ImageObserver observer) { - super.drawGlyphVector(gv, x, y); - owner.invalidate(); + if( img instanceof GtkVolatileImage ) + { + owner.drawVolatile( ((GtkVolatileImage)img).nativePointer, + x, y, width, height ); + return true; + } + return super.drawImage( img, x, y, width, height, observer ); } } Index: include/gnu_java_awt_peer_gtk_ComponentGraphics.h =================================================================== RCS file: /sources/classpath/classpath/include/gnu_java_awt_peer_gtk_ComponentGraphics.h,v retrieving revision 1.3 diff -U3 -r1.3 gnu_java_awt_peer_gtk_ComponentGraphics.h --- include/gnu_java_awt_peer_gtk_ComponentGraphics.h 3 Jun 2006 22:41:41 -0000 1.3 +++ include/gnu_java_awt_peer_gtk_ComponentGraphics.h 6 Jun 2006 02:13:48 -0000 @@ -11,6 +11,7 @@ #endif JNIEXPORT jlong JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_initState (JNIEnv *env, jobject, jobject); +JNIEXPORT jlong JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_initFromVolatile(JNIEnv *env, jobject, jlong, jint, jint); JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_start_1gdk_1drawing (JNIEnv *env, jobject); 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); Index: include/gnu_java_awt_peer_gtk_GtkVolatileImage.h =================================================================== RCS file: /sources/classpath/classpath/include/gnu_java_awt_peer_gtk_GtkVolatileImage.h,v retrieving revision 1.1 diff -U3 -r1.1 gnu_java_awt_peer_gtk_GtkVolatileImage.h --- include/gnu_java_awt_peer_gtk_GtkVolatileImage.h 3 Jun 2006 22:41:41 -0000 1.1 +++ include/gnu_java_awt_peer_gtk_GtkVolatileImage.h 6 Jun 2006 02:13:48 -0000 @@ -13,7 +13,8 @@ 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); +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkVolatileImage_copyArea (JNIEnv *env, jobject, jint, jint, jint, jint, jint, jint); +JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkVolatileImage_drawVolatile (JNIEnv *env, jobject, jlong, jint, jint, jint, jint); #ifdef __cplusplus } Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c =================================================================== RCS file: /sources/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c,v retrieving revision 1.12 diff -U3 -r1.12 gnu_java_awt_peer_gtk_ComponentGraphics.c --- native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c 4 Jun 2006 19:44:39 -0000 1.12 +++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c 6 Jun 2006 02:13:53 -0000 @@ -163,6 +163,43 @@ return PTR_TO_JLONG(cr); } +JNIEXPORT jlong JNICALL +Java_gnu_java_awt_peer_gtk_ComponentGraphics_initFromVolatile + (JNIEnv *env __attribute__ ((unused)), jobject obj __attribute__ ((unused)), + jlong ptr, jint width, jint height) +{ + Drawable draw; + Display * dpy; + Visual * vis; + GdkDrawable *drawable; + cairo_surface_t *surface; + cairo_t *cr; + + gdk_threads_enter(); + + drawable = JLONG_TO_PTR(GdkDrawable, ptr); + g_assert (drawable != NULL); + + draw = gdk_x11_drawable_get_xid(drawable); + g_assert (draw != (XID) 0); + + dpy = gdk_x11_drawable_get_xdisplay(drawable); + g_assert (dpy != NULL); + + vis = gdk_x11_visual_get_xvisual(gdk_drawable_get_visual(drawable)); + g_assert (vis != NULL); + + surface = cairo_xlib_surface_create (dpy, draw, vis, width, height); + g_assert (surface != NULL); + + cr = cairo_create (surface); + g_assert(cr != NULL); + + gdk_threads_leave(); + + return PTR_TO_JLONG(cr); +} + JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_ComponentGraphics_start_1gdk_1drawing (JNIEnv *env __attribute__ ((unused)), jobject obj __attribute__ ((unused))) @@ -220,7 +257,6 @@ GdkGC *gc; gdk_threads_enter(); - ptr = NSA_GET_PTR (env, peer); g_assert (ptr != NULL); @@ -229,14 +265,16 @@ pixmap = cp_gtk_get_pixmap( env, img ); - gc = gdk_gc_new(GDK_DRAWABLE(widget->window)); - gdk_draw_drawable(GDK_DRAWABLE(widget->window), + gc = gdk_gc_new(widget->window); + gdk_draw_drawable(widget->window, gc, pixmap, 0, 0, x, y, w, h); + g_object_unref( gc ); + schedule_flush (); gdk_threads_leave(); Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c =================================================================== RCS file: /sources/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c,v retrieving revision 1.2 diff -U3 -r1.2 gnu_java_awt_peer_gtk_GtkVolatileImage.c --- native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c 4 Jun 2006 17:52:05 -0000 1.2 +++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c 6 Jun 2006 02:13:53 -0000 @@ -146,28 +146,54 @@ } /** - * Update the pixels. + * Copy area */ JNIEXPORT void JNICALL -Java_gnu_java_awt_peer_gtk_GtkVolatileImage_update -(JNIEnv *env, jobject obj, jobject gtkimage) +Java_gnu_java_awt_peer_gtk_GtkVolatileImage_copyArea +(JNIEnv *env, jobject obj, jint x, jint y, jint w, jint h, jint dx, jint dy) { - GdkPixmap *pixmap = getNativeObject(env, obj); GdkPixbuf *pixbuf; + GdkPixmap* pixmap = getNativeObject(env, obj); - gdk_threads_enter(); - g_assert( pixmap != NULL ); - - pixbuf = cp_gtk_image_get_pixbuf (env, gtkimage); - g_assert( pixbuf != NULL ); + g_assert (pixmap != NULL); + gdk_threads_enter(); + + pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, TRUE, 8, w, h ); + gdk_pixbuf_get_from_drawable( pixbuf, pixmap, NULL, x, y, 0, 0, w, h ); gdk_draw_pixbuf (pixmap, NULL, pixbuf, - 0, 0, 0, 0, /* src and dest x, y */ - -1, -1, /* full width, height */ + 0, 0, x + dx, y + dy, + w, h, GDK_RGB_DITHER_NORMAL, 0, 0); gdk_threads_leave(); } +JNIEXPORT void JNICALL +Java_gnu_java_awt_peer_gtk_GtkVolatileImage_drawVolatile +(JNIEnv *env, jobject obj, jlong ptr, jint x, jint y, jint w, jint h) +{ + GdkPixmap *dst, *src; + GdkGC *gc; + + src = JLONG_TO_PTR(GdkPixmap, ptr); + dst = getNativeObject(env, obj); + g_assert (src != NULL); + g_assert (dst != NULL); + + gdk_threads_enter(); + + gc = gdk_gc_new( dst ); + gdk_draw_drawable(dst, + gc, + src, + 0, 0, + x, y, + w, h); + g_object_unref( gc ); + + gdk_threads_leave(); +} + GdkPixmap *cp_gtk_get_pixmap( JNIEnv *env, jobject obj) { return (GdkPixmap *)getNativeObject(env, obj);