This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gui][PATCH] fixes to clipping and drawable flushing


hi,

this small but terribly frustrating patch, along with some changes I just put into cairo, fix most of the clipping problems on java2d / cairo. it means cairo is in control of flushing drawables to the screen now, as well as managing the clip region. the cairo change was to accelerate rectangular clip regions, so that this doesn't incur too much of a performance penalty, as well as implement "set clip" functionality.

you *will* need to update your copy of cairo if you wish to use this patch with the associated cairo java2d backend; it uses a new cairo API call.

-graydon


2004-03-19 Graydon Hoare <graydon@redhat.com>


	* javax/swing/JComponent.java: Turn off double buffer by default.
	* javax/swing/plaf/basic/BasicViewportUI.java: Clear rects before painting.
	* jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c
	(Java_gnu_java_awt_peer_gtk_GdkGraphics2D_gdkDrawDrawable):
	Use cairo to copy areas.
	(Java_gnu_java_awt_peer_gtk_GdkGraphics2D_cairoClip):
	Initialize and set clip region.

--- javax/swing/JComponent.java	12 Mar 2004 16:03:17 -0000	1.7.2.2
+++ javax/swing/JComponent.java	19 Mar 2004 23:53:40 -0000
@@ -100,7 +100,7 @@
   Border border;
   JToolTip tooltip;
   String tool_tip_text;
-  boolean use_double_buffer, opaque;
+  boolean use_double_buffer = false, opaque;
   Image doubleBuffer;
   int doubleBufferWidth = -1;
   int doubleBufferHeight = -1;
--- javax/swing/plaf/basic/BasicViewportUI.java	12 Mar 2004 16:03:17 -0000	1.3.8.1
+++ javax/swing/plaf/basic/BasicViewportUI.java	19 Mar 2004 23:53:40 -0000
@@ -127,6 +127,7 @@
 
     Point pos = v.getViewPosition();
     Rectangle viewBounds = view.getBounds();
+    Rectangle portBounds = v.getBounds();
 
     if (backingStoreImage == null 
         || backingStoreWidth != viewBounds.width
@@ -138,6 +139,32 @@
       }
 
     Graphics g2 = backingStoreImage.getGraphics();
+
+
+    if (c.getBackground() != null)
+      {
+        // fill the backing store background
+        java.awt.Color save = g2.getColor();
+        g2.setColor(c.getBackground());
+        g2.fillRect (0, 0, backingStoreWidth, backingStoreHeight);
+        g2.setColor(save);
+
+        // fill the viewport background
+        save = g.getColor();
+        g.setColor(c.getBackground());
+        g.fillRect (0, 0, portBounds.width, portBounds.height);
+        g.setColor(save);
+
+      }
+    else
+      {
+        // clear the backing store background
+        g2.clearRect(0, 0, backingStoreWidth, backingStoreHeight);
+
+        // clear the viewport background
+        g.clearRect(0, 0, portBounds.width, portBounds.height);
+      }
+
     view.paint(g2);
     g2 = null;
     g.drawImage(backingStoreImage, 
--- jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c	26 Feb 2004 22:09:29 -0000	1.5.8.2
+++ jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c	19 Mar 2004 23:53:40 -0000
@@ -371,9 +371,12 @@
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics2D_gdkDrawDrawable
   (JNIEnv *env, jobject self, jobject other, jint x, jint y)
 {
+  GdkRectangle clipRect;
   struct graphics2d *src = NULL, *dst = NULL;
   gint s_height, s_width, d_height, d_width, height, width;
+  cairo_matrix_t *matrix;
   GdkGC *gc;
+  cairo_operator_t tmp_op;
 
   src = (struct graphics2d *)NSA_GET_G2D_PTR (env, other);
   dst = (struct graphics2d *)NSA_GET_G2D_PTR (env, self);
@@ -386,19 +389,33 @@
   gdk_drawable_get_size (src->drawable, &s_width, &s_height);
   gdk_drawable_get_size (dst->drawable, &d_width, &d_height);
   width = min (s_width, d_width);
-  height = min (s_width, d_height);
+  height = min (s_height, d_height);
+  gdk_threads_leave ();  
 
-  gc = gdk_gc_new (dst->drawable);
-  g_assert (gc != NULL);
+  begin_drawing_operation(dst); 
 
-  gdk_draw_drawable(dst->drawable, gc, src->drawable, 
- 		    0, 0, x, y, width, height); 
-  gdk_flush ();
+  matrix = cairo_matrix_create ();
+  cairo_surface_get_matrix (src->surface, matrix);
+  cairo_matrix_translate (matrix, (double)-x, (double)-y);
+  cairo_surface_set_matrix (src->surface, matrix);
+
+  tmp_op = cairo_current_operator (dst->cr); 
+  cairo_set_operator(dst->cr, CAIRO_OPERATOR_SRC); 
+  cairo_show_surface (dst->cr, src->surface, width, height);
+  cairo_set_operator(dst->cr, tmp_op);
+
+  cairo_matrix_translate (matrix, (double)x, (double)y);
+  cairo_surface_set_matrix (src->surface, matrix);
+  cairo_matrix_destroy (matrix);
 
-  g_object_unref (gc);
+  end_drawing_operation(dst);
 
-  if (src->debug) printf ("copied %d x %d pixels from offscreen drawable\n", width, height);
+  gdk_threads_enter ();  
+  gdk_flush ();
   gdk_threads_leave ();  
+
+  if (src->debug) printf ("copied %d x %d pixels from offscreen drawable\n", width, height);
+
 }
 
 static jintArray
@@ -1215,6 +1232,7 @@
   gr = (struct graphics2d *) NSA_GET_G2D_PTR (env, obj);
   g_assert (gr != NULL);
   if (gr->debug) printf ("cairo_clip\n");
+  cairo_init_clip (gr->cr); 
   cairo_clip (gr->cr);
 }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]