[Nautilus-list] Background flashes and performance patches



These are the background flash fixes and performance hacks we have in our 
RPMS. I haven't analyzed them.

/ Alex

--- gnome-libs-1.2.13/libgnomeui/gnome-canvas.c.bghack	Mon Jan  8 12:51:06 2001
+++ gnome-libs-1.2.13/libgnomeui/gnome-canvas.c	Mon Jul 23 16:45:01 2001
@@ -3172,6 +3172,18 @@
 #define IMAGE_WIDTH_AA 256
 #define IMAGE_HEIGHT_AA 64
 
+static GQuark bg_hack_quark = 0;
+void
+gnome_canvas_set_nautilus_bg_hack (GnomeCanvas *canvas,
+				   gboolean     use_bg_hack)
+{
+	if (!bg_hack_quark)
+		bg_hack_quark = g_quark_from_static_string ("nautilus-bg-hack");
+
+	use_bg_hack = use_bg_hack != FALSE;
+	gtk_object_set_data_by_id (GTK_OBJECT (canvas), bg_hack_quark, GUINT_TO_POINTER (use_bg_hack));
+}
+
 /* Repaints the areas in the canvas that need it */
 static void
 paint (GnomeCanvas *canvas)
@@ -3183,6 +3195,12 @@
 	GdkPixmap *pixmap;
 	ArtIRect *rects;
 	gint n_rects, i;
+	gboolean bg_hack = FALSE;
+
+	if (!bg_hack_quark)
+		bg_hack_quark = g_quark_from_static_string ("nautilus-bg-hack");
+	if (gtk_object_get_data_by_id (GTK_OBJECT (canvas), bg_hack_quark))
+		bg_hack = TRUE;
 
 	if (canvas->need_update) {
 		double affine[6];
@@ -3241,7 +3259,9 @@
 			if (canvas->aa) {
 				GnomeCanvasBuf buf;
 				GdkColor *color;
-
+				gint dest_x;
+				gint dest_y;
+				
 				buf.buf = g_new (guchar, IMAGE_WIDTH_AA * IMAGE_HEIGHT_AA * 3);
 				buf.buf_rowstride = IMAGE_WIDTH_AA * 3;
 				buf.rect.x0 = draw_x1;
@@ -3260,23 +3280,26 @@
 						canvas->root->object.klass)->render) (
 							canvas->root, &buf);
 
+				dest_x = draw_x1 - DISPLAY_X1 (canvas) + canvas->zoom_xofs;
+				dest_y = draw_y1 - DISPLAY_Y1 (canvas) + canvas->zoom_yofs;
+
 				if (buf.is_bg) {
-					gdk_rgb_gc_set_foreground (canvas->pixmap_gc, buf.bg_color);
-					gdk_draw_rectangle (canvas->layout.bin_window,
-							    canvas->pixmap_gc,
-							    TRUE,
-							    (draw_x1 - DISPLAY_X1 (canvas)
-							     + canvas->zoom_xofs),
-							    (draw_y1 - DISPLAY_Y1 (canvas)
-							     + canvas->zoom_yofs),
-							    width, height);
+					if (bg_hack)
+						gdk_window_clear_area (canvas->layout.bin_window,
+								       dest_x, dest_y,
+								       width, height);
+					else {
+						gdk_rgb_gc_set_foreground (canvas->pixmap_gc, buf.bg_color);
+						gdk_draw_rectangle (canvas->layout.bin_window,
+								    canvas->pixmap_gc,
+								    TRUE,
+								    dest_x, dest_y,
+								    width, height);
+					}
 				} else {
 					gdk_draw_rgb_image_dithalign (canvas->layout.bin_window,
 							    canvas->pixmap_gc,
-							    (draw_x1 - DISPLAY_X1 (canvas)
-							     + canvas->zoom_xofs),
-							    (draw_y1 - DISPLAY_Y1 (canvas)
-							     + canvas->zoom_yofs),
+						            dest_x, dest_y,
 							    width, height,
 							    canvas->dither,
 							    buf.buf,
--- nautilus-1.0.4/src/nautilus-desktop-window.c.noflash	Tue Jul 10 14:13:32 2001
+++ nautilus-1.0.4/src/nautilus-desktop-window.c	Tue Jul 10 15:12:35 2001
@@ -173,6 +173,12 @@
 realize (GtkWidget *widget)
 {
 	NautilusDesktopWindow *window;
+	GdkAtom type;
+	gulong nitems, bytes_after;
+	gint format;
+	guchar *data;
+	gboolean have_set_background = FALSE;
+	Window w;
 
 	window = NAUTILUS_DESKTOP_WINDOW (widget);
 
@@ -225,6 +231,54 @@
 				0, 0,
 				gdk_screen_width (),
 				gdk_screen_height ());
+
+	/* Set the background to show the root window to avoid a flash that
+	 * would otherwise occur.
+	 */
+	gtk_widget_set_app_paintable (widget, TRUE);
+	w = GDK_WINDOW_XWINDOW (widget->window);
+	XGetWindowProperty (GDK_DISPLAY(), GDK_ROOT_WINDOW(),
+			    gdk_atom_intern("_XROOTPMAP_ID", FALSE),
+			    0L, 1L, False, XA_PIXMAP,
+			    &type, &format, &nitems, &bytes_after,
+			    &data);
+  
+	if (type == XA_PIXMAP) {
+		if (format == 32 && nitems == 1 && bytes_after == 0) {
+			gdk_error_trap_push ();
+			XSetWindowBackgroundPixmap (GDK_DISPLAY (), w,
+						    *(Pixmap *)data);
+			gdk_flush ();
+			if (!gdk_error_trap_pop ())
+				have_set_background = TRUE;
+		}
+  
+		XFree (data);
+	}
+
+	if (!have_set_background) {
+		XGetWindowProperty (GDK_DISPLAY(), GDK_ROOT_WINDOW(),
+				    gdk_atom_intern("_XROOTCOLOR_PIXEL", FALSE),
+				    0L, 1L, False, AnyPropertyType,
+				    &type, &format, &nitems, &bytes_after,
+				    &data);
+  
+		if (type != None) {
+			if (format == 32 && nitems == 1 && bytes_after == 0) {
+				XSetWindowBackground (GDK_DISPLAY (), w,
+						      *(gulong *)data);
+				have_set_background = TRUE;
+			}
+  
+			XFree (data);
+		}
+	}
+
+	if (!have_set_background) {
+		XSetWindowBackgroundPixmap (GDK_DISPLAY (), w,
+					    None);
+	}
+	
 
 	/* Get rid of the things that window managers add to resize
 	 * and otherwise manipulate the window.
diff -u -r nautilus-1.0.4/libnautilus-private/nautilus-directory-background.c nautilus-1.0.4-bghack/libnautilus-private/nautilus-directory-background.c
--- nautilus-1.0.4/libnautilus-private/nautilus-directory-background.c	Thu May 10 21:30:30 2001
+++ nautilus-1.0.4-bghack/libnautilus-private/nautilus-directory-background.c	Mon Jul 23 23:28:10 2001
@@ -41,6 +41,7 @@
 #include <libgnome/gnome-config.h>
 #include <libgnome/gnome-util.h>
 #include <libgnomevfs/gnome-vfs-utils.h>
+#include <gmodule.h>
 
 static void background_changed_callback     (EelBackground *background, 
                                              NautilusFile       *file);
@@ -647,11 +648,41 @@
 	XFlush(GDK_DISPLAY());
 }
 	
+/* Check to see if our gnome canvas supports the "nautilus_bg_hack", if so
+ * turn it on.
+ */
+static void
+turn_on_bg_hack (GnomeCanvas *canvas)
+{
+	static gboolean init = FALSE;
+	static gboolean have_bg_hack = FALSE;
+	static void (*set_nautilus_bg_hack) (GnomeCanvas *canvas,
+                                             gboolean     use_bg_hack) = NULL;
+        
+	if (!init) {
+		GModule *module = g_module_open (NULL, 0);
+		if (module) {
+			if (g_module_symbol (module,
+					     "gnome_canvas_set_nautilus_bg_hack",
+					     (gpointer *)&set_nautilus_bg_hack)) {
+				have_bg_hack = TRUE;
+			}
+		}
+		init = TRUE;
+	}
+        
+	if (have_bg_hack) {
+                set_nautilus_bg_hack (canvas, TRUE);
+        }
+}
+
 static void
 image_loading_done_callback (EelBackground *background, gboolean successful_load, void *disconnect_signal)
 {
 	int	      width;
 	int	      height;
+	int	      screen_width;
+	int	      screen_height;
 	GdkGC        *gc;
 	GdkPixmap    *pixmap;
 	GdkWindow    *background_window;
@@ -662,18 +693,24 @@
 					       disconnect_signal);
 	}
 
-	width  = gdk_screen_width ();
-	height = gdk_screen_height ();
+	screen_width  = gdk_screen_width ();
+	screen_height = gdk_screen_height ();
+
+        eel_background_get_sample_size (background,
+                                        screen_width, screen_height,
+                                        &width, &height);
 
-	pixmap = make_root_pixmap (width, height);
+        pixmap = make_root_pixmap (width, height);
 	gc = gdk_gc_new (pixmap);
-	eel_background_draw_to_drawable (background, pixmap, gc, 0, 0, width, height, width, height);
+	eel_background_draw_to_drawable (background, pixmap, gc, 0, 0, width, height, screen_width, screen_height);
 	gdk_gc_unref (gc);
 
 	set_root_pixmap (pixmap);
 
 	background_window = eel_background_get_desktop_background_window (background);
 	if (background_window != NULL) {
+                GnomeCanvas *canvas = gtk_object_get_data (GTK_OBJECT (background), "icon_container");
+                turn_on_bg_hack (canvas);
 		gdk_window_set_back_pixmap (background_window, pixmap, FALSE);
 	}
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]