[gtk+/wip/paint-stack-cleanup: 3/3] gdkwindow: Don't clear to the background automatically



commit 36f68b98be9b07a068a5373b7742599f68b5259d
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sat Jun 21 10:56:16 2014 -0400

    gdkwindow: Don't clear to the background automatically
    
    Introduce a new API, gdk_window_paint_background, which paints the
    background, which we call inside GtkWidget as part of expose event
    handling.
    
    This allows users that were using gdk_cairo_create without a
    gdk_window_begin_paint_region to start using it now, as they did not
    want the clear-to-background behavior.

 gdk/gdkwindow.c |   35 +++++++++++++++++++++--------------
 gdk/gdkwindow.h |    3 +++
 gtk/gtkwidget.c |    2 ++
 3 files changed, 26 insertions(+), 14 deletions(-)
---
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index 807434d..d93c183 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -160,9 +160,6 @@ static void gdk_window_get_property (GObject      *object,
                                      GValue       *value,
                                      GParamSpec   *pspec);
 
-static void gdk_window_clear_backing_region (GdkWindow *window,
-                                            cairo_region_t *region);
-
 static void recompute_visible_regions   (GdkWindow *private,
                                         gboolean recalculate_children);
 static void gdk_window_invalidate_in_parent (GdkWindow *private);
@@ -2773,8 +2770,7 @@ gdk_window_begin_paint_region (GdkWindow       *window,
       window->current_paint.surface_needs_composite = FALSE;
     }
 
-  if (!cairo_region_is_empty (window->current_paint.region))
-    gdk_window_clear_backing_region (window);
+  window->current_paint.cleared_to_background = FALSE;
 }
 
 /**
@@ -2943,19 +2939,33 @@ gdk_window_get_visible_region (GdkWindow *window)
   return cairo_region_copy (window->clip_region);
 }
 
-static void
-gdk_window_clear_backing_region (GdkWindow *window)
+/**
+ * gdk_window_paint_background:
+ * @window: a #GdkWindow
+ * @cr: a #cairo_t to paint with
+ *
+ * Paints the background surface of #GdkWindow to #cr.
+ *
+ * This does not do any clipping to the clip region of the window,
+ * it simply paints the surface, so make sure to establish a clip
+ * beforehand.
+ *
+ * This function is intended to be called while in a paint started
+ * with gdk_window_begin_paint_region() or gdk_window_begin_paint_rect().
+ */
+void
+gdk_window_paint_background (GdkWindow *window,
+                             cairo_t   *cr)
 {
   GdkWindow *bg_window;
   cairo_pattern_t *pattern = NULL;
   int x_offset = 0, y_offset = 0;
-  cairo_t *cr;
+
+  g_return_if_fail (GDK_IS_WINDOW (window));
 
   if (GDK_WINDOW_DESTROYED (window))
     return;
 
-  cr = cairo_create (window->current_paint.surface);
-
   for (bg_window = window; bg_window; bg_window = bg_window->parent)
     {
       pattern = gdk_window_get_background_pattern (bg_window);
@@ -2975,10 +2985,7 @@ gdk_window_clear_backing_region (GdkWindow *window)
   else
     cairo_set_source_rgb (cr, 0, 0, 0);
 
-  gdk_cairo_region (cr, window->current_paint.region);
-  cairo_fill (cr);
-
-  cairo_destroy (cr);
+  cairo_paint (cr);
 
   /* Since we've cleared to an opaque pattern, we can skip alpha
    * blending later on in the composite stage. */
diff --git a/gdk/gdkwindow.h b/gdk/gdkwindow.h
index 23a317a..19b4fcb 100644
--- a/gdk/gdkwindow.h
+++ b/gdk/gdkwindow.h
@@ -1103,6 +1103,9 @@ void       gdk_window_set_shadow_width         (GdkWindow      *window,
 GDK_AVAILABLE_IN_3_14
 gboolean  gdk_window_show_window_menu          (GdkWindow      *window,
                                                 GdkEvent       *event);
+GDK_AVAILABLE_IN_3_14
+void      gdk_window_paint_background          (GdkWindow      *window,
+                                                cairo_t        *cr);
 
 G_END_DECLS
 
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 7e56ecb..6389073 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -7519,6 +7519,8 @@ gtk_widget_send_expose (GtkWidget *widget,
   gdk_cairo_region (cr, event->expose.region);
   cairo_clip (cr);
 
+  gdk_window_paint_background (event->expose.window, cr);
+
   gtk_cairo_set_event (cr, &event->expose);
 
   if (event->expose.window == widget->priv->window)


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