2006-02-02  Federico Mena Quintero  <federico@ximian.com>

	* gdk/gdkwindow.c (gdk_window_set_bg_pattern): Work around
	https://bugs.freedesktop.org/show_bug.cgi?id=4320, which used to
	be our own http://bugzilla.gnome.org/show_bug.cgi?id=314616.  If
	one uses a pixmap for a pattern in Cairo, and sets the pattern to
	CAIRO_EXTEND_REPEAT; and if the destination surface is also a
	pixmap, Cairo does a slow copy instead of using XCopyArea()
	multiple times.  So, we test whether we actually need a repeating
	pattern, and only turn on CAIRO_EXTEND_REPEAT in that case.

Novell bug: https://bugzilla.novell.com/show_bug.cgi?id=117163

--- gtk+/gdk/gdkwindow.c~	2006-01-17 15:32:30.000000000 -0600
+++ gtk+/gdk/gdkwindow.c	2006-02-02 13:21:51.000000000 -0600
@@ -1746,6 +1746,9 @@ gdk_window_set_bg_pattern (GdkWindow    
     {
       cairo_surface_t *surface = _gdk_drawable_ref_cairo_surface (private->bg_pixmap);
       cairo_pattern_t *pattern = cairo_pattern_create_for_surface (surface);
+      gint pixmap_width, pixmap_height;
+      gint window_width, window_height;
+
       cairo_surface_destroy (surface);
 
       if (x_offset != 0 || y_offset != 0)
@@ -1755,7 +1758,16 @@ gdk_window_set_bg_pattern (GdkWindow    
 	  cairo_pattern_set_matrix (pattern, &matrix);
 	}
 
-      cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
+      /* Workaround for a bug in Cairo and/or XRENDER: https://bugs.freedesktop.org/show_bug.cgi?id=4320
+       *
+       * Repeat fills with a pixmap pattern and a pixmap destination surface are
+       * slow.  So, we do a lame test for "do we actually need to repeat".
+       */
+      gdk_drawable_get_size (GDK_DRAWABLE (private->bg_pixmap), &pixmap_width, &pixmap_height);
+      gdk_drawable_get_size (GDK_DRAWABLE (window), &window_width, &window_height);
+      if (pixmap_width < window_width || pixmap_height < window_height)
+	cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
+
       cairo_set_source (cr, pattern);
       cairo_pattern_destroy (pattern);
     }
