[gtk+/gtk-2-16] gdk: Ensure flush of surface when cairo_t is destroyed



commit fc197a38cc2bd3119d02a4267a5b4210ed0669aa
Author: Hans Breuer <hans breuer org>
Date:   Sun Nov 7 21:12:28 2010 +0100

    gdk: Ensure flush of surface when cairo_t is destroyed
    
    Add an ugly workaround because GTK does not ensure surfaces get flushed
    before directly accessing the drawable backed by the surface. This is
    not visible on X11 (where flushing is a no-op), but can be seen on
    Windows.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=628291

 gdk/gdkcairo.c |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)
---
diff --git a/gdk/gdkcairo.c b/gdk/gdkcairo.c
index 6e83f53..50762a9 100644
--- a/gdk/gdkcairo.c
+++ b/gdk/gdkcairo.c
@@ -23,6 +23,13 @@
 #include "gdkregion-generic.h"
 #include "gdkalias.h"
 
+static void
+gdk_ensure_surface_flush (gpointer surface)
+{
+  cairo_surface_flush (surface);
+  cairo_surface_destroy (surface);
+}
+
 /**
  * gdk_cairo_create:
  * @drawable: a #GdkDrawable
@@ -43,6 +50,7 @@
 cairo_t *
 gdk_cairo_create (GdkDrawable *drawable)
 {
+  static const cairo_user_data_key_t key;
   cairo_surface_t *surface;
   cairo_t *cr;
     
@@ -50,7 +58,13 @@ gdk_cairo_create (GdkDrawable *drawable)
 
   surface = _gdk_drawable_ref_cairo_surface (drawable);
   cr = cairo_create (surface);
-  cairo_surface_destroy (surface);
+
+  /* Ugly workaround for GTK not ensuring to flush surfaces before
+   * directly accessing the drawable backed by the surface. Not visible
+   * on X11 (where flushing is a no-op). For details, see
+   * https://bugzilla.gnome.org/show_bug.cgi?id=628291
+   */
+  cairo_set_user_data (cr, &key, surface, gdk_ensure_surface_flush);
 
   return cr;
 }



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