[gtk+/wip/pango-shadow-cache: 5/9] cssshadowvalue: Add a hacky workaround for bugs in SNA



commit e663a1f0d8cf2173ffb1d1bbb51b0282dbfc428e
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Fri Aug 29 16:35:56 2014 -0700

    cssshadowvalue: Add a hacky workaround for bugs in SNA
    
    SNA doesn't like mask_surface, so apply the mask on a temporary image
    surface that we then paint to the server surface.

 gtk/gtkcssshadowvalue.c |   45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 44 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkcssshadowvalue.c b/gtk/gtkcssshadowvalue.c
index 3007f11..04080e6 100644
--- a/gtk/gtkcssshadowvalue.c
+++ b/gtk/gtkcssshadowvalue.c
@@ -490,6 +490,19 @@ has_empty_clip (cairo_t *cr)
   return x1 == x2 && y1 == y2;
 }
 
+static gboolean
+using_sna (cairo_t *cr)
+{
+  cairo_surface_t *surface = cairo_get_target (cr);
+
+  /* Assume that all Xlib surfaces are using SNA, since we can't
+   * detect whether the X server is actually using SNA. */
+  if (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_XLIB)
+    return TRUE;
+
+  return FALSE;
+}
+
 static void
 draw_shadow (const GtkCssValue   *shadow,
             cairo_t             *cr,
@@ -537,7 +550,37 @@ draw_shadow (const GtkCssValue   *shadow,
   if (blur)
     {
       _gtk_cairo_blur_surface (shadow_surface, radius);
-      cairo_mask_surface (cr, shadow_surface, 0, 0);
+
+#define SNA_IS_BUGGY 1
+      /* SNA doesn't like mask_surface very much, and will break it.
+       * To appease it, apply the mask on a temporary image surface,
+       * and paint that to our server surface. */
+      if (using_sna (cr) && SNA_IS_BUGGY)
+        {
+          cairo_surface_t *workaround_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+                                                                            cairo_image_surface_get_width 
(shadow_surface),
+                                                                            cairo_image_surface_get_height 
(shadow_surface));
+          cairo_t *workaround_cr = cairo_create (workaround_surface);
+          double offset_x, offset_y;
+
+          cairo_surface_get_device_offset (shadow_surface, &offset_x, &offset_y);
+          cairo_surface_set_device_offset (shadow_surface, 0, 0);
+
+          gdk_cairo_set_source_rgba (workaround_cr, _gtk_css_rgba_value_get_rgba (shadow->color));
+          cairo_mask_surface (workaround_cr, shadow_surface, 0, 0);
+          cairo_destroy (workaround_cr);
+
+          cairo_surface_set_device_offset (workaround_surface, offset_x, offset_y);
+          cairo_set_source_surface (cr, workaround_surface, 0, 0);
+          cairo_paint (cr);
+
+          cairo_surface_destroy (workaround_surface);
+        }
+      else
+        {
+          cairo_mask_surface (cr, shadow_surface, 0, 0);
+        }
+
       cairo_destroy (shadow_cr);
       cairo_surface_destroy (shadow_surface);
     }


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