[vte/vte-next: 55/114] Draw onto the passed-in context



commit b7f759b0dbc6278da2e00adca8e1b571382c9ab4
Author: Christian Persch <chpe gnome org>
Date:   Tue May 3 15:47:21 2011 +0200

    Draw onto the passed-in context
    
    Don't create our own cairo context, but instead draw to the
    context passed to ::draw.

 src/vte.c     |   16 +++++++-------
 src/vtedraw.c |   61 +++++++++++++++++++-------------------------------------
 src/vtedraw.h |    6 +---
 3 files changed, 31 insertions(+), 52 deletions(-)
---
diff --git a/src/vte.c b/src/vte.c
index fd8dfd5..6a8098c 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -4311,6 +4311,7 @@ _vte_terminal_visible_beep(VteTerminal *terminal)
 	widget = &terminal->widget;
 
 	if (gtk_widget_get_realized (widget)) {
+                cairo_t *cr;
 
 		style = gtk_widget_get_style (widget);
 		gtk_widget_get_allocation (widget, &allocation);
@@ -4319,12 +4320,14 @@ _vte_terminal_visible_beep(VteTerminal *terminal)
                 color.blue = style->fg[gtk_widget_get_state (widget)].blue / 65535.;
                 color.alpha = 1.0;
 
-		_vte_draw_start(terminal->pvt->draw);
+                cr = gdk_cairo_create(gtk_widget_get_window(widget));
+                _vte_draw_set_cairo(terminal->pvt->draw, cr);
 		_vte_draw_fill_rectangle(terminal->pvt->draw,
 					 0, 0,
 					 allocation.width, allocation.height,
 					 &color);
-		_vte_draw_end(terminal->pvt->draw);
+                _vte_draw_set_cairo(terminal->pvt->draw, NULL);
+                cairo_destroy(cr);
 
 		/* Force the repaint, max delay of UPDATE_REPEAT_TIMEOUT */
 		_vte_invalidate_all (terminal);
@@ -8331,13 +8334,11 @@ vte_terminal_fill_rectangle(VteTerminal *terminal,
 			    gint width,
 			    gint height)
 {
-	_vte_draw_start(terminal->pvt->draw);
 	_vte_draw_fill_rectangle(terminal->pvt->draw,
 				 x + terminal->pvt->inner_border.left,
                                  y + terminal->pvt->inner_border.top,
 				 width, height,
 				 color);
-	_vte_draw_end(terminal->pvt->draw);
 }
 
 static void
@@ -8361,13 +8362,11 @@ vte_terminal_draw_rectangle(VteTerminal *terminal,
 			    gint width,
 			    gint height)
 {
-	_vte_draw_start(terminal->pvt->draw);
 	_vte_draw_draw_rectangle(terminal->pvt->draw,
 				 x + terminal->pvt->inner_border.left,
                                  y + terminal->pvt->inner_border.top,
 				 width, height,
 				 color);
-	_vte_draw_end(terminal->pvt->draw);
 }
 
 static void
@@ -10245,11 +10244,12 @@ vte_terminal_draw(GtkWidget *widget,
                             clip_rect.width, clip_rect.height);
         }
 
+        _vte_draw_set_cairo(terminal->pvt->draw, cr);
+
         allocated_width = gtk_widget_get_allocated_width(widget);
         allocated_height = gtk_widget_get_allocated_height(widget);
 
         /* Designate the start of the drawing operation and clear the area. */
-        _vte_draw_start(terminal->pvt->draw);
         {
                 if (terminal->pvt->scroll_background) {
                         _vte_draw_set_background_scroll(terminal->pvt->draw,
@@ -10306,7 +10306,7 @@ vte_terminal_draw(GtkWidget *widget,
         vte_terminal_paint_im_preedit_string(terminal);
 
         /* Done with various structures. */
-        _vte_draw_end(terminal->pvt->draw);
+        _vte_draw_set_cairo(terminal->pvt->draw, NULL);
 
         cairo_region_destroy (region);
 
diff --git a/src/vtedraw.c b/src/vtedraw.c
index 4d9bede..1e70249 100644
--- a/src/vtedraw.c
+++ b/src/vtedraw.c
@@ -722,8 +722,6 @@ font_info_get_unistr_info (struct font_info *info,
 struct _vte_draw {
 	GtkWidget *widget;
 
-	gint started;
-
 	struct font_info *font;
 	struct font_info *font_bold;
 	cairo_pattern_t *bg_pattern;
@@ -768,36 +766,18 @@ _vte_draw_free (struct _vte_draw *draw)
 }
 
 void
-_vte_draw_start (struct _vte_draw *draw)
+_vte_draw_set_cairo(struct _vte_draw *draw,
+                    cairo_t *cr)
 {
-	GdkWindow *window;
-
-	g_return_if_fail (gtk_widget_get_realized (draw->widget));
-
-	_vte_debug_print (VTE_DEBUG_DRAW, "draw_start\n");
-
-	if (draw->started == 0) {
-		window = gtk_widget_get_window(draw->widget);
-		g_object_ref (window);
-		draw->cr = gdk_cairo_create (window);
-	}
-
-	draw->started++;
-}
-
-void
-_vte_draw_end (struct _vte_draw *draw)
-{
-	g_return_if_fail (draw->started);
-
-	draw->started--;
-	if (draw->started == 0) {
-		cairo_destroy (draw->cr);
-		draw->cr = NULL;
-		g_object_unref (gtk_widget_get_window(draw->widget));
- 	}
-
-	_vte_debug_print (VTE_DEBUG_DRAW, "draw_end\n");
+  _vte_debug_print (VTE_DEBUG_DRAW, "%s cairo context\n", cr ? "Settings" : "Unsetting");
+
+  if (cr) {
+    g_assert (draw->cr == NULL);
+    draw->cr = cr;
+  } else {
+    g_assert (draw->cr != NULL);
+    draw->cr = NULL;
+  }
 }
 
 void
@@ -831,7 +811,8 @@ void
 _vte_draw_clip (struct _vte_draw *draw, cairo_region_t *region)
 {
 	_vte_debug_print (VTE_DEBUG_DRAW, "draw_clip\n");
-	gdk_cairo_region(draw->cr, region);
+        g_assert(draw->cr);
+        gdk_cairo_region(draw->cr, region);
 	cairo_clip (draw->cr);
 }
 
@@ -843,7 +824,8 @@ _vte_draw_clear (struct _vte_draw *draw, gint x, gint y, gint width, gint height
 	_vte_debug_print (VTE_DEBUG_DRAW, "draw_clear (%d, %d, %d, %d)\n",
 			  x,y,width, height);
 
-	cairo_rectangle (draw->cr, x, y, width, height);
+        g_assert(draw->cr);
+        cairo_rectangle (draw->cr, x, y, width, height);
 	cairo_set_operator (draw->cr, CAIRO_OPERATOR_SOURCE);
 	cairo_set_source (draw->cr, draw->bg_pattern);
 	cairo_fill (draw->cr);
@@ -924,6 +906,7 @@ _vte_draw_text_internal (struct _vte_draw *draw,
 
 	g_return_if_fail (font != NULL);
 
+        g_assert(draw->cr);
         gdk_cairo_set_source_rgba (draw->cr, color);
 	cairo_set_operator (draw->cr, CAIRO_OPERATOR_OVER);
 
@@ -982,7 +965,7 @@ _vte_draw_text (struct _vte_draw *draw,
 	       struct _vte_draw_text_request *requests, gsize n_requests,
 	       const GdkRGBA *color, gboolean bold)
 {
-	g_return_if_fail (draw->started);
+	g_assert(draw->cr);
 
 	if (_vte_debug_on (VTE_DEBUG_DRAW)) {
 		GString *string = g_string_new ("");
@@ -1057,14 +1040,13 @@ _vte_draw_draw_rectangle (struct _vte_draw *draw,
 			 gint x, gint y, gint width, gint height,
 			 const GdkRGBA *color)
 {
-	g_return_if_fail (draw->started);
-
 	_vte_debug_print (VTE_DEBUG_DRAW,
 			"draw_rectangle (%d, %d, %d, %d, color=(%.3f,%.3f,%.3f,%.3f))\n",
 			x,y,width,height,
 			color->red, color->green, color->blue, color->alpha);
 
-	cairo_set_operator (draw->cr, CAIRO_OPERATOR_OVER);
+        g_assert(draw->cr);
+        cairo_set_operator (draw->cr, CAIRO_OPERATOR_OVER);
 	cairo_rectangle (draw->cr, x+VTE_LINE_WIDTH/2., y+VTE_LINE_WIDTH/2., width-VTE_LINE_WIDTH, height-VTE_LINE_WIDTH);
 	gdk_cairo_set_source_rgba (draw->cr, color);
 	cairo_set_line_width (draw->cr, VTE_LINE_WIDTH);
@@ -1076,14 +1058,13 @@ _vte_draw_fill_rectangle (struct _vte_draw *draw,
 			 gint x, gint y, gint width, gint height,
 			 const GdkRGBA *color)
 {
-	g_return_if_fail (draw->started);
-
 	_vte_debug_print (VTE_DEBUG_DRAW,
 			"draw_fill_rectangle (%d, %d, %d, %d, color=(%.3f,%.3f,%.3f,%.3f))\n",
 			x,y,width,height,
 			color->red, color->green, color->blue, color->alpha);
 
-	cairo_set_operator (draw->cr, CAIRO_OPERATOR_OVER);
+        g_assert(draw->cr);
+        cairo_set_operator (draw->cr, CAIRO_OPERATOR_OVER);
 	cairo_rectangle (draw->cr, x, y, width, height);
         gdk_cairo_set_source_rgba (draw->cr, color);
 	cairo_fill (draw->cr);
diff --git a/src/vtedraw.h b/src/vtedraw.h
index 6c1863e..d0d2be9 100644
--- a/src/vtedraw.h
+++ b/src/vtedraw.h
@@ -61,10 +61,8 @@ struct _vte_draw_text_request {
 struct _vte_draw *_vte_draw_new(GtkWidget *widget);
 void _vte_draw_free(struct _vte_draw *draw);
 
-/* Begin and end a drawing operation.  If anything is buffered locally, it is
-   flushed to the window system when _end() is called. */
-void _vte_draw_start(struct _vte_draw *draw);
-void _vte_draw_end(struct _vte_draw *draw);
+void _vte_draw_set_cairo(struct _vte_draw *draw,
+                         cairo_t *cr);
 
 void _vte_draw_set_background_pattern (struct _vte_draw *draw,
                                        cairo_pattern_t *pattern);



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