--- head/src/load-graph.cpp	2008-04-18 13:10:12.000000000 +0100
+++ karl/src/load-graph.cpp	2008-04-18 15:01:17.000000000 +0100
@@ -62,8 +62,7 @@
 #define FRAME_WIDTH 4
 void draw_background(LoadGraph *g) {
 	double dash[2] = { 1.0, 2.0 };
-	cairo_t *cr;
-	cairo_t* tmp_cr;
+	cairo_t *tmp_cr;
 	guint i;
 	unsigned num_bars;
 	char *caption;
@@ -76,13 +75,13 @@
 	g->graph_delx = (g->draw_width - 2.0 - g->rmargin - g->indent) / (LoadGraph::NUM_POINTS - 3);
 	g->graph_buffer_offset = (int) (1.5 * g->graph_delx) + FRAME_WIDTH ;
 
-	cr = cairo_create (g->buffer);
-	g->background_buffer = cairo_surface_create_similar (cairo_get_target (cr),
-							     CAIRO_CONTENT_COLOR_ALPHA,
-							     g->draw_width + (2*FRAME_WIDTH),
-							     g->draw_height + (2*FRAME_WIDTH));  // ** We need the whole area as we are now setting the background colour here
+
+	g->background = gdk_pixmap_new (GDK_DRAWABLE (g->disp->window),
+					g->disp->allocation.width,
+					g->disp->allocation.height,
+					-1);
+	tmp_cr = gdk_cairo_create (g->background);
 	
-	tmp_cr = cairo_create (g->background_buffer);
 
 	// set the background colour
 	GtkStyle *style = gtk_widget_get_style (ProcData::get_instance()->notebook);
@@ -160,75 +159,12 @@
 
 	cairo_stroke (tmp_cr);
 	cairo_destroy (tmp_cr);
-	cairo_destroy (cr); 
 }
 
 /* Redraws the backing buffer for the load graph and updates the window */
 void
 load_graph_draw (LoadGraph *g)
 {
-	cairo_t *cr;
-	guint i, j;
-	gdouble tmp;
-
-	cr = cairo_create (g->buffer);
-
-	/* draw the graph */
-	if ((g->render_counter == 0)) {  
-		cairo_surface_destroy(g->graph_buffer);
-		cairo_t* tmp_cr;
-
-		g->graph_buffer = cairo_surface_create_similar (cairo_get_target (cr),
-							 	CAIRO_CONTENT_COLOR_ALPHA,
-								g->draw_width,
-								g->draw_height);
-		tmp_cr = cairo_create (g->graph_buffer);
-
-		cairo_set_line_width (tmp_cr, 1.5);
-		cairo_set_line_cap (tmp_cr, CAIRO_LINE_CAP_ROUND);
-		cairo_set_line_join (tmp_cr, CAIRO_LINE_JOIN_ROUND);
-
-		for (j = 0; j < g->n; ++j) {
-			cairo_move_to (tmp_cr,
-				       g->draw_width - 2.0,
-				       (1.0f - g->data[0][j]) * g->real_draw_height);
-			gdk_cairo_set_source_color (tmp_cr, &(g->colors [j]));
-
-			for (i = 1; i < LoadGraph::NUM_POINTS; ++i) {
-				if (g->data[i][j] == -1.0f)
-					continue;
-
-				cairo_curve_to (tmp_cr, 
-					       (g->draw_width - (i-1) * g->graph_delx) - (g->graph_delx/2),
-					       (1.0f - g->data[i-1][j]) * g->real_draw_height,
-					       (g->draw_width - i * g->graph_delx) + (g->graph_delx/2),
-					       (1.0f - g->data[i][j]) * g->real_draw_height,
-					       g->draw_width - i * g->graph_delx,
-					       (1.0f - g->data[i][j]) * g->real_draw_height);
-			}
-
-			cairo_stroke (tmp_cr);
-
-		}
-		cairo_destroy (tmp_cr);
-	} 
-
-	/* Composite and clip the surfaces together */
-	if (g->background_buffer == NULL) {
-		draw_background(g);
-	}
-	cairo_set_source_surface (cr, g->background_buffer, 0, 0);
-	cairo_paint (cr);
-
-	tmp = (float)(g->draw_width - g->rmargin - g->indent) / (float)LoadGraph::NUM_POINTS;
-	tmp = tmp / g->frames_per_unit;
-	tmp = tmp * g->render_counter;
-	cairo_set_source_surface (cr, g->graph_buffer, g->graph_buffer_offset - tmp, FRAME_WIDTH);
-	cairo_rectangle (cr, g->rmargin + g->indent + FRAME_WIDTH + 1, FRAME_WIDTH - 1,
-			 g->draw_width - g->rmargin - g->indent - 1 , g->real_draw_height + FRAME_WIDTH - 1);
-	cairo_fill (cr);
-	cairo_destroy (cr);
-
 	/* repaint */
 	gtk_widget_queue_draw (g->disp);
 }
@@ -241,8 +177,6 @@
 		      gpointer data_ptr)
 {
 	LoadGraph * const g = static_cast<LoadGraph*>(data_ptr);
-	cairo_t *cr;
-
 	g->draw_width = widget->allocation.width - 2 * FRAME_WIDTH;
 	g->draw_height = widget->allocation.height - 2 * FRAME_WIDTH;
 
@@ -257,21 +191,12 @@
 						g);
 	}
 
-	cr = gdk_cairo_create (widget->window);
-
-	if (g->buffer)
-		cairo_surface_destroy (g->buffer);
-
-	g->buffer = cairo_surface_create_similar (cairo_get_target (cr),
-						  CAIRO_CONTENT_COLOR,
-						  widget->allocation.width,
-						  widget->allocation.height);
-
-	cairo_destroy (cr);
-
-	if (g->background_buffer != NULL) {
-		cairo_surface_destroy(g->background_buffer);
-		g->background_buffer = NULL;
+	if (g->background) {
+		g_object_unref (g->background);
+		g->background = NULL;
+	}
+	if (g->gc == NULL) {
+		g->gc = gdk_gc_new (GDK_DRAWABLE (widget->window));
 	}
 
 	load_graph_draw (g);
@@ -285,13 +210,60 @@
 		   gpointer data_ptr)
 {
 	LoadGraph * const g = static_cast<LoadGraph*>(data_ptr);
-	cairo_t *cr;
 
-	cr = gdk_cairo_create(widget->window);
+	guint i, j;
+	gdouble tmp, x_offset, my_width;
+
+	if (g->background == NULL) {
+		draw_background(g);
+	}
+	gdk_draw_drawable (g->disp->window,
+			   g->gc,
+			   g->background,
+			   0, 0, 0, 0, 
+			   g->disp->allocation.width, 
+			   g->disp->allocation.height);
+
+	tmp = (float)(g->draw_width - g->rmargin - g->indent) / (float)LoadGraph::NUM_POINTS;
+	tmp = tmp / g->frames_per_unit;
+        tmp = tmp * (g->render_counter + 1);
+
+	/* draw the graph */
+	cairo_t* cr;
 
-	cairo_set_source_surface(cr, g->buffer, 0, 0);
-	cairo_paint(cr);
-	cairo_destroy(cr);
+	cr = gdk_cairo_create (g->disp->window);
+
+	cairo_set_line_width (cr, 1);
+	cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
+	cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
+	cairo_rectangle (cr, g->rmargin + g->indent + FRAME_WIDTH + 1, FRAME_WIDTH - 1,
+			 g->draw_width - g->rmargin - g->indent - 1 , g->real_draw_height + FRAME_WIDTH - 1);
+	cairo_clip(cr);
+
+        x_offset = g->rmargin - tmp;
+	my_width = g->draw_width - FRAME_WIDTH;
+	for (j = 0; j < g->n; ++j) {
+		cairo_move_to (cr,
+			       x_offset + my_width - 2.0,
+			       (1.0f - g->data[0][j]) * g->real_draw_height);
+		gdk_cairo_set_source_color (cr, &(g->colors [j]));
+
+		for (i = 1; i < LoadGraph::NUM_POINTS; ++i) {
+			if (g->data[i][j] == -1.0f)
+				continue;
+			cairo_curve_to (cr, 
+				       x_offset + (my_width - (i-1) * g->graph_delx) - (g->graph_delx/2),
+				       (1.0f - g->data[i-1][j]) * g->real_draw_height+3.5,
+				       x_offset + (my_width - i * g->graph_delx) + (g->graph_delx/2),
+				       (1.0f - g->data[i][j]) * g->real_draw_height+3.5,
+				       x_offset + my_width - i * g->graph_delx ,
+				       (1.0f - g->data[i][j]) * g->real_draw_height+3.5);
+		}
+		cairo_stroke (cr);
+
+	}
+
+	cairo_destroy (cr);
 
 	return TRUE;
 }
@@ -480,9 +452,9 @@
 	g->net.max = new_max;
 
 	// force the graph background to be redrawn now that scale has changed
-	if (g->background_buffer != NULL) {
-		cairo_surface_destroy(g->background_buffer);
-		g->background_buffer = NULL;
+	if (g->background) {
+		g_object_unref (g->background);
+		g->background = NULL;
 	}
 }
 
@@ -559,7 +531,7 @@
 {
 	LoadGraph * const g = static_cast<LoadGraph*>(user_data);
 
-	if (g->render_counter == 0) {
+	if (g->render_counter == g->frames_per_unit - 1) {
 		std::rotate(&g->data[0], &g->data[LoadGraph::NUM_POINTS - 1], &g->data[LoadGraph::NUM_POINTS]);
 
 		switch (g->type) {
@@ -597,10 +569,8 @@
   if (this->timer_index)
     g_source_remove(this->timer_index);
 
-  if (this->buffer) {
-    cairo_surface_destroy(this->buffer);
-    this->buffer = NULL;
-  }
+  if (this->background)
+    g_object_unref (this->background);
 }
 
 
@@ -633,9 +603,8 @@
     graph_buffer_offset(0),
     main_widget(NULL),
     disp(NULL),
-    buffer(NULL),
-    graph_buffer(NULL),
-    background_buffer(NULL),
+    gc(NULL),
+    background(NULL),
     timer_index(0),
     draw(FALSE),
     mem_color_picker(NULL),
@@ -700,9 +669,7 @@
 	}
 
 	g->timer_index = 0;
-	g->render_counter = g->frames_per_unit;
-	g->background_buffer = NULL;
-	g->graph_buffer = NULL;
+	g->render_counter = (g->frames_per_unit - 1);
 	g->draw = FALSE;
 
 	g->main_widget = gtk_vbox_new (FALSE, FALSE);
@@ -730,10 +697,6 @@
 	  g->data[i] = &g->data_block[0] + i * g->n;
 
 	gtk_widget_show_all (g->main_widget);
-
-	load_graph_start(g);
-	load_graph_stop(g);
-
 }
 
 void
@@ -775,9 +738,9 @@
 						load_graph_update,
 						g);
 	}
-	if (g->background_buffer != NULL) {
-		cairo_surface_destroy(g->background_buffer);
-		g->background_buffer = NULL;
+	if (g->background != NULL) {
+		g_object_unref(g->background);
+		g->background = NULL;
 	}
 }
 
--- head/src/load-graph.h	2008-04-18 13:10:12.000000000 +0100
+++ karl/src/load-graph.h	2008-04-18 13:44:24.000000000 +0100
@@ -65,9 +65,8 @@
 	GtkWidget *main_widget;
 	GtkWidget *disp;
 
-	cairo_surface_t *buffer;
-	cairo_surface_t *graph_buffer;
-	cairo_surface_t *background_buffer;
+	GdkGC *gc;
+	GdkDrawable *background;
 
 	guint timer_index;

