[Xfce4-commits] [panel-plugins/xfce4-cpugraph-plugin] 12/16: No need to create cairo contexts

noreply at xfce.org noreply at xfce.org
Wed May 29 04:10:13 CEST 2019


This is an automated email from the git hooks/post-receive script.

a   n   d   r   e       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository panel-plugins/xfce4-cpugraph-plugin.

commit 75e404966a964f5752783287cb3f9725326735c6
Author: Andre Miranda <andreldm at xfce.org>
Date:   Tue Apr 23 00:27:02 2019 -0300

    No need to create cairo contexts
---
 panel-plugin/cpu.c  |  8 ++---
 panel-plugin/mode.c | 91 +++++++++++++++++++++++------------------------------
 panel-plugin/mode.h |  8 ++---
 3 files changed, 47 insertions(+), 60 deletions(-)

diff --git a/panel-plugin/cpu.c b/panel-plugin/cpu.c
index 266fb15..12506cf 100644
--- a/panel-plugin/cpu.c
+++ b/panel-plugin/cpu.c
@@ -363,16 +363,16 @@ static void draw_area_cb( GtkWidget * widget, cairo_t * cr, gpointer data )
 	switch( base->mode )
 	{
 		case 0:
-			draw_graph_normal( base, da, w, h );
+			draw_graph_normal( base, cr, w, h );
 			break;
 		case 1:
-			draw_graph_LED( base, da, w, h );
+			draw_graph_LED( base, cr, w, h );
 			break;
 		case 2:
-			draw_graph_no_history( base, da, w, h );
+			draw_graph_no_history( base, cr, w, h );
 			break;
 		case 3:
-			draw_graph_grid(base, da, w, h);
+			draw_graph_grid(base, cr, w, h);
 			break;
 	}
 }
diff --git a/panel-plugin/mode.c b/panel-plugin/mode.c
index 640c082..c1d66ad 100644
--- a/panel-plugin/mode.c
+++ b/panel-plugin/mode.c
@@ -40,16 +40,15 @@ static void mix_colors( gdouble ratio, GdkRGBA *color1, GdkRGBA *color2, cairo_t
 	gdk_cairo_set_source_rgba( target, &color );
 }
 
-void draw_graph_normal( CPUGraph *base, GtkWidget *da, gint w, gint h )
+void draw_graph_normal( CPUGraph *base, cairo_t *cr, gint w, gint h )
 {
 	gint x, y;
 	gint usage;
 	gdouble t;
 	gint tmp;
-	cairo_t *fg1 = gdk_cairo_create( gtk_widget_get_window( da ) );
 
 	if( base->color_mode == 0 )
-		gdk_cairo_set_source_rgba( fg1, &base->colors[1] );
+		gdk_cairo_set_source_rgba( cr, &base->colors[1] );
 
 	for( x = 0; x < w; x++ )
 	{
@@ -60,10 +59,10 @@ void draw_graph_normal( CPUGraph *base, GtkWidget *da, gint w, gint h )
 		if( base->color_mode == 0 )
 		{
 			/* draw line */
-			cairo_set_line_cap( fg1, CAIRO_LINE_CAP_SQUARE );
-			cairo_move_to( fg1, x, h - usage );
-			cairo_line_to( fg1, x, h - 1 );
-			cairo_stroke( fg1 );
+			cairo_set_line_cap( cr, CAIRO_LINE_CAP_SQUARE );
+			cairo_move_to( cr, x, h - usage );
+			cairo_line_to( cr, x, h - 1 );
+			cairo_stroke( cr );
 		}
 		else
 		{
@@ -73,18 +72,17 @@ void draw_graph_normal( CPUGraph *base, GtkWidget *da, gint w, gint h )
 				t = (base->color_mode == 1) ?
 					(tmp / (gdouble) (h)) :
 					(tmp / (gdouble) (usage));
-				mix_colors( t, &base->colors[1], &base->colors[2], fg1 );
+				mix_colors( t, &base->colors[1], &base->colors[2], cr );
 				/* draw point */
-				cairo_set_line_cap( fg1, CAIRO_LINE_CAP_SQUARE );
-				cairo_move_to( fg1, x, y );
-				cairo_stroke( fg1 );
+				cairo_set_line_cap( cr, CAIRO_LINE_CAP_SQUARE );
+				cairo_move_to( cr, x, y );
+				cairo_stroke( cr );
 			}
 		}
 	}
-	cairo_destroy( fg1 );
 }
 
-void draw_graph_LED( CPUGraph *base, GtkWidget *da, gint w, gint h )
+void draw_graph_LED( CPUGraph *base, cairo_t *cr, gint w, gint h )
 {
 	gint nrx = (w + 1) / 3;
 	gint nry = (h + 1) / 2;
@@ -92,11 +90,6 @@ void draw_graph_LED( CPUGraph *base, GtkWidget *da, gint w, gint h )
 	gint idx;
 	gint limit;
 
-	cairo_t *fg1 = gdk_cairo_create( gtk_widget_get_window( da ) );
-	cairo_t *fg2 = gdk_cairo_create( gtk_widget_get_window( da ) );
-	gdk_cairo_set_source_rgba( fg1, &base->colors[1] );
-	gdk_cairo_set_source_rgba( fg2, &base->colors[2] );
-
 	for( x = 0; x * 3 < w; x++ )
 	{
 		idx = nrx-x;
@@ -108,31 +101,28 @@ void draw_graph_LED( CPUGraph *base, GtkWidget *da, gint w, gint h )
 				gdouble t = (base->color_mode == 1) ?
 				           (y / (gdouble)nry) :
 				           (y / (gdouble)limit);
-				mix_colors( t, &base->colors[3], &base->colors[2], fg2 );
+				mix_colors( t, &base->colors[3], &base->colors[2], cr );
 			}
 			/* draw rectangle */
-			cairo_t *fg = y >= limit ? fg1 : fg2;
-			cairo_rectangle( fg, x * 3, y * 2, 2, 1 );
-			cairo_fill( fg );
+			gdk_cairo_set_source_rgba( cr, y >= limit ? &base->colors[1] : &base->colors[2] );
+			cairo_rectangle( cr, x * 3, y * 2, 2, 1 );
+			cairo_fill( cr );
 		}
 	}
-	cairo_destroy( fg1 );
-	cairo_destroy( fg2 );
 }
 
-void draw_graph_no_history( CPUGraph *base, GtkWidget *da, gint w, gint h )
+void draw_graph_no_history( CPUGraph *base, cairo_t *cr, gint w, gint h )
 {
 	gint y;
 	gint usage = h * base->history[0] / CPU_SCALE;
 	gint tmp = 0;
 	gdouble t;
-	cairo_t *fg1 = gdk_cairo_create( gtk_widget_get_window( da ) );
 
 	if( base->color_mode == 0 )
 	{
-		gdk_cairo_set_source_rgba( fg1, &base->colors[1] );
-		cairo_rectangle( fg1, 0, h - usage, w, usage );
-		cairo_fill( fg1 );
+		gdk_cairo_set_source_rgba( cr, &base->colors[1] );
+		cairo_rectangle( cr, 0, h - usage, w, usage );
+		cairo_fill( cr );
 	}
 	else
 	{
@@ -141,16 +131,15 @@ void draw_graph_no_history( CPUGraph *base, GtkWidget *da, gint w, gint h )
 			t = (base->color_mode == 1) ?
 				(tmp / (gdouble) (h)) :
 				(tmp / (gdouble) (usage));
-			mix_colors( t, &base->colors[1], &base->colors[2], fg1 );
+			mix_colors( t, &base->colors[1], &base->colors[2], cr );
 			tmp++;
 			/* draw line */
-			cairo_set_line_cap( fg1, CAIRO_LINE_CAP_SQUARE );
-			cairo_move_to( fg1, 0, y );
-			cairo_line_to( fg1, w -1, y );
-			cairo_stroke( fg1 );
+			cairo_set_line_cap( cr, CAIRO_LINE_CAP_SQUARE );
+			cairo_move_to( cr, 0, y );
+			cairo_line_to( cr, w -1, y );
+			cairo_stroke( cr );
 		}
 	}
-	cairo_destroy( fg1 );
 }
 
 typedef struct
@@ -159,45 +148,43 @@ typedef struct
 	gint y;
 } point;
 
-void draw_graph_grid( CPUGraph *base, GtkWidget *da, gint w, gint h )
+void draw_graph_grid( CPUGraph *base, cairo_t *cr, gint w, gint h )
 {
 	gint x, y;
 	gint usage;
 	point last, current;
 	last.x = 0;
 	last.y = h;
-	cairo_t *fg1 = gdk_cairo_create( gtk_widget_get_window( da ) );
 
-	gdk_cairo_set_source_rgba( fg1, &base->colors[1] );
+	gdk_cairo_set_source_rgba( cr, &base->colors[1] );
 	for( x = 0; x * 6 < w; x++ )
 	{
 		/* draw line */
-		cairo_set_line_cap( fg1, CAIRO_LINE_CAP_SQUARE );
-		cairo_move_to( fg1, x * 6, 0 );
-		cairo_line_to( fg1, x * 6,  h - 1 );
-		cairo_stroke( fg1 );
+		cairo_set_line_cap( cr, CAIRO_LINE_CAP_SQUARE );
+		cairo_move_to( cr, x * 6, 0 );
+		cairo_line_to( cr, x * 6,  h - 1 );
+		cairo_stroke( cr );
 	}
 	for( y = 0; y * 4 < h; y++ )
 	{
 		/* draw line */
-		cairo_set_line_cap( fg1, CAIRO_LINE_CAP_SQUARE );
-		cairo_move_to( fg1, 0, y * 4 );
-		cairo_line_to( fg1, w - 1,  y * 4 );
-		cairo_stroke( fg1 );
+		cairo_set_line_cap( cr, CAIRO_LINE_CAP_SQUARE );
+		cairo_move_to( cr, 0, y * 4 );
+		cairo_line_to( cr, w - 1,  y * 4 );
+		cairo_stroke( cr );
 	}
 
-	gdk_cairo_set_source_rgba( fg1, &base->colors[2] );
+	gdk_cairo_set_source_rgba( cr, &base->colors[2] );
 	for( x = 0; x < w; x++ )
 	{
 		usage = h * base->history[w - 1- x] / CPU_SCALE;
 		current.x = x;
 		current.y = h - usage;
 		/* draw line */
-		cairo_set_line_cap( fg1, CAIRO_LINE_CAP_SQUARE );
-		cairo_move_to( fg1, current.x, current.y );
-		cairo_line_to( fg1, last.x,  last.y );
-		cairo_stroke( fg1 );
+		cairo_set_line_cap( cr, CAIRO_LINE_CAP_SQUARE );
+		cairo_move_to( cr, current.x, current.y );
+		cairo_line_to( cr, last.x,  last.y );
+		cairo_stroke( cr );
 		last = current;
 	}
-	cairo_destroy( fg1 );
 }
diff --git a/panel-plugin/mode.h b/panel-plugin/mode.h
index d931070..7354cd1 100644
--- a/panel-plugin/mode.h
+++ b/panel-plugin/mode.h
@@ -26,9 +26,9 @@
 
 #include "cpu.h"
 
-void draw_graph_normal( CPUGraph *base, GtkWidget *da, gint w, gint h );
-void draw_graph_LED( CPUGraph *base, GtkWidget *da, gint w, gint h );
-void draw_graph_no_history( CPUGraph *base, GtkWidget *da, gint w, gint h );
-void draw_graph_grid( CPUGraph *base, GtkWidget *da, gint w, gint h );
+void draw_graph_normal( CPUGraph *base, cairo_t *cr, gint w, gint h );
+void draw_graph_LED( CPUGraph *base, cairo_t *cr, gint w, gint h );
+void draw_graph_no_history( CPUGraph *base, cairo_t *cr, gint w, gint h );
+void draw_graph_grid( CPUGraph *base, cairo_t *cr, gint w, gint h );
 
 #endif /* !_XFCE_MODE_H_ */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list