[vte] drawing: Remove start/end



commit cd40ae1387546d52bae9c344d798cbee830ecc9a
Author: Christian Persch <chpe gnome org>
Date:   Thu Mar 27 16:35:23 2014 +0100

    drawing: Remove start/end
    
    _vte_draw_start/end doesn't fit with the current drawing model anymore.
    Instead just set the cairo context at the start of ::draw, and unset it
    at the end.

 src/vte.c     |    4 ++--
 src/vtedraw.c |   52 ++++++++++++++++++----------------------------------
 src/vtedraw.h |    6 ++----
 3 files changed, 22 insertions(+), 40 deletions(-)
---
diff --git a/src/vte.c b/src/vte.c
index de803d2..a97540b 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -10308,7 +10308,7 @@ vte_terminal_draw(GtkWidget *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);
+       _vte_draw_set_cairo(terminal->pvt->draw, cr);
 
        _vte_draw_clip(terminal->pvt->draw, region);
        _vte_draw_clear (terminal->pvt->draw, 0, 0,
@@ -10355,7 +10355,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 02f3d52..73a0660 100644
--- a/src/vtedraw.c
+++ b/src/vtedraw.c
@@ -734,8 +734,6 @@ guint _vte_draw_get_style(gboolean bold, gboolean italic) {
 struct _vte_draw {
        GtkWidget *widget;
 
-       gint started;
-
        struct font_info *fonts[4];
        cairo_pattern_t *bg_pattern;
 
@@ -790,36 +788,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
@@ -839,6 +819,7 @@ void
 _vte_draw_clip (struct _vte_draw *draw, cairo_region_t *region)
 {
        _vte_debug_print (VTE_DEBUG_DRAW, "draw_clip\n");
+        g_assert(draw->cr);
        gdk_cairo_region(draw->cr, region);
        cairo_clip (draw->cr);
 }
@@ -851,6 +832,7 @@ _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);
 
+        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);
@@ -959,6 +941,7 @@ _vte_draw_set_source_color_alpha (struct _vte_draw *draw,
                                   const PangoColor *color,
                                   guchar            alpha)
 {
+        g_assert(draw->cr);
        cairo_set_source_rgba (draw->cr,
                              color->red / 65535.,
                              color->green / 65535.,
@@ -979,6 +962,7 @@ _vte_draw_text_internal (struct _vte_draw *draw,
 
        g_return_if_fail (font != NULL);
 
+        g_assert(draw->cr);
        _vte_draw_set_source_color_alpha (draw, color, alpha);
        cairo_set_operator (draw->cr, CAIRO_OPERATOR_OVER);
 
@@ -1037,7 +1021,7 @@ _vte_draw_text (struct _vte_draw *draw,
               struct _vte_draw_text_request *requests, gsize n_requests,
               const PangoColor *color, guchar alpha, guint style)
 {
-       g_return_if_fail (draw->started);
+        g_assert(draw->cr);
 
        if (_vte_debug_on (VTE_DEBUG_DRAW)) {
                GString *string = g_string_new ("");
@@ -1115,7 +1099,7 @@ _vte_draw_draw_rectangle (struct _vte_draw *draw,
                         gint x, gint y, gint width, gint height,
                         const PangoColor *color, guchar alpha)
 {
-       g_return_if_fail (draw->started);
+        g_assert(draw->cr);
 
        _vte_debug_print (VTE_DEBUG_DRAW,
                        "draw_rectangle (%d, %d, %d, %d, color=(%d,%d,%d,%d))\n",
@@ -1135,7 +1119,7 @@ _vte_draw_fill_rectangle (struct _vte_draw *draw,
                         gint x, gint y, gint width, gint height,
                         const PangoColor *color, guchar alpha)
 {
-       g_return_if_fail (draw->started);
+        g_assert(draw->cr);
 
        _vte_debug_print (VTE_DEBUG_DRAW,
                        "draw_fill_rectangle (%d, %d, %d, %d, color=(%d,%d,%d,%d))\n",
diff --git a/src/vtedraw.h b/src/vtedraw.h
index 2d03e33..e3d5562 100644
--- a/src/vtedraw.h
+++ b/src/vtedraw.h
@@ -71,10 +71,8 @@ void _vte_draw_free(struct _vte_draw *draw);
 
 cairo_t *_vte_draw_get_context (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_solid(struct _vte_draw *draw,
                                     const GdkRGBA *color);


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