[mutter/wip/cairo: 2/11] theme: Remove our own gradient stuff



commit 9e3f5d937549aff5609e52fd2f7d8e39ca0255f2
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Fri Oct 28 13:08:48 2011 -0400

    theme: Remove our own gradient stuff
    
    Part one of porting to cairo. This requires removing support for a seldomly
    used feature in the theme format - alpha gradients on tint, icon and image.
    Grepping through gnome-themes-standard and searching for code, I couldn't
    find any usage of this feature, so I consider it safe to remove.
    
    Thanks to Benjamin Otte for helping me clean this up.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=662962

 src/Makefile.am        |    7 +-
 src/meta/gradient.h    |   65 ----
 src/ui/gradient.c      |  865 ------------------------------------------------
 src/ui/testgradient.c  |  317 ------------------
 src/ui/theme-parser.c  |   19 +-
 src/ui/theme-private.h |   19 +-
 src/ui/theme.c         |  163 ++++------
 7 files changed, 83 insertions(+), 1372 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 5d5dcb9..11bb130 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -88,8 +88,6 @@ libmutter_la_SOURCES =				\
 	core/eventqueue.h			\
 	core/frame.c				\
 	core/frame.h				\
-	ui/gradient.c				\
-	meta/gradient.h				\
 	core/group-private.h			\
 	core/group-props.c			\
 	core/group-props.h			\
@@ -163,7 +161,6 @@ libmutterinclude_base_headers =		\
 	meta/compositor.h			\
 	meta/display.h				\
 	meta/errors.h				\
-	meta/gradient.h				\
 	meta/group.h				\
 	meta/keybindings.h			\
 	meta/main.h				\
@@ -236,13 +233,11 @@ endif
 mutter_theme_viewer_LDADD= $(MUTTER_LIBS) libmutter.la
 
 testboxes_SOURCES = core/testboxes.c
-testgradient_SOURCES = ui/testgradient.c
 testasyncgetprop_SOURCES = core/testasyncgetprop.c
 
-noinst_PROGRAMS=testboxes testgradient testasyncgetprop
+noinst_PROGRAMS=testboxes testasyncgetprop
 
 testboxes_LDADD = $(MUTTER_LIBS) libmutter.la
-testgradient_LDADD = $(MUTTER_LIBS) libmutter.la
 testasyncgetprop_LDADD = $(MUTTER_LIBS) libmutter.la
 
 @INTLTOOL_DESKTOP_RULE@
diff --git a/src/ui/theme-parser.c b/src/ui/theme-parser.c
index 9063541..709a609 100644
--- a/src/ui/theme-parser.c
+++ b/src/ui/theme-parser.c
@@ -2147,10 +2147,8 @@ parse_draw_op_element (GMarkupParseContext  *context,
       const char *y;
       const char *width;
       const char *height;
-      const char *alpha;
       const char *colorize;
       const char *fill_type;
-      MetaAlphaGradientSpec *alpha_spec;
       GdkPixbuf *pixbuf;
       MetaColorSpec *colorize_spec = NULL;
       MetaImageFillType fill_type_val;
@@ -2162,7 +2160,7 @@ parse_draw_op_element (GMarkupParseContext  *context,
                               error,
                               "!x", &x, "!y", &y,
                               "!width", &width, "!height", &height,
-                              "alpha", &alpha, "!filename", &filename,
+                              "!filename", &filename,
                               "colorize", &colorize,
                               "fill_type", &fill_type,
                               NULL))
@@ -2220,13 +2218,6 @@ parse_draw_op_element (GMarkupParseContext  *context,
               return;
             }
         }
-
-      alpha_spec = NULL;
-      if (alpha && !parse_alpha (alpha, &alpha_spec, context, error))
-        {
-          g_object_unref (G_OBJECT (pixbuf));
-          return;
-        }
       
       op = meta_draw_op_new (META_DRAW_IMAGE);
 
@@ -2238,7 +2229,6 @@ parse_draw_op_element (GMarkupParseContext  *context,
       op->data.image.width = meta_draw_spec_new (info->theme, width, NULL);
       op->data.image.height = meta_draw_spec_new (info->theme, height, NULL);
 
-      op->data.image.alpha_spec = alpha_spec;
       op->data.image.fill_type = fill_type_val;
       
       /* Check for vertical & horizontal stripes */
@@ -2529,16 +2519,13 @@ parse_draw_op_element (GMarkupParseContext  *context,
       const char *y;
       const char *width;
       const char *height;
-      const char *alpha;
       const char *fill_type;
-      MetaAlphaGradientSpec *alpha_spec;
       MetaImageFillType fill_type_val;
       
       if (!locate_attributes (context, element_name, attribute_names, attribute_values,
                               error,
                               "!x", &x, "!y", &y,
                               "!width", &width, "!height", &height,
-                              "alpha", &alpha,
                               "fill_type", &fill_type,
                               NULL))
         return;
@@ -2570,9 +2557,6 @@ parse_draw_op_element (GMarkupParseContext  *context,
             }
         }
       
-      alpha_spec = NULL;
-      if (alpha && !parse_alpha (alpha, &alpha_spec, context, error))
-        return;
       
       op = meta_draw_op_new (META_DRAW_ICON);
       
@@ -2581,7 +2565,6 @@ parse_draw_op_element (GMarkupParseContext  *context,
       op->data.icon.width = meta_draw_spec_new (info->theme, width, NULL);
       op->data.icon.height = meta_draw_spec_new (info->theme, height, NULL);
 
-      op->data.icon.alpha_spec = alpha_spec;
       op->data.icon.fill_type = fill_type_val;
       
       g_assert (info->op_list);
diff --git a/src/ui/theme-private.h b/src/ui/theme-private.h
index 0f28b31..f9f4da6 100644
--- a/src/ui/theme-private.h
+++ b/src/ui/theme-private.h
@@ -25,7 +25,6 @@
 #define META_THEME_PRIVATE_H
 
 #include <meta/boxes.h>
-#include <meta/gradient.h>
 #include <meta/theme.h>
 #include <meta/common.h>
 #include <gtk/gtk.h>
@@ -276,6 +275,14 @@ typedef enum
 
 typedef enum
 {
+  META_GRADIENT_VERTICAL,
+  META_GRADIENT_HORIZONTAL,
+  META_GRADIENT_DIAGONAL,
+  META_GRADIENT_LAST
+} MetaGradientType;
+
+typedef enum
+{
   META_COLOR_SPEC_BASIC,
   META_COLOR_SPEC_GTK,
   META_COLOR_SPEC_GTK_CUSTOM,
@@ -540,7 +547,6 @@ struct _MetaDrawOp
 
     struct {
       MetaColorSpec *colorize_spec;
-      MetaAlphaGradientSpec *alpha_spec;
       GdkPixbuf *pixbuf;
       MetaDrawSpec *x;
       MetaDrawSpec *y;
@@ -583,7 +589,6 @@ struct _MetaDrawOp
     } gtk_vline;
 
     struct {
-      MetaAlphaGradientSpec *alpha_spec;
       MetaDrawSpec *x;
       MetaDrawSpec *y;
       MetaDrawSpec *width;
@@ -991,8 +996,12 @@ gboolean       meta_draw_op_list_contains (MetaDrawOpList    *op_list,
 
 MetaGradientSpec* meta_gradient_spec_new    (MetaGradientType        type);
 void              meta_gradient_spec_free   (MetaGradientSpec       *desc);
-GdkPixbuf*        meta_gradient_spec_render (const MetaGradientSpec *desc,
-                                             GtkStyleContext        *gtk_style,
+void              meta_gradient_spec_render (const MetaGradientSpec *spec,
+                                             const MetaAlphaGradientSpec *alpha_spec,
+                                             cairo_t                *cr,
+                                             GtkStyleContext        *style,
+                                             int                     x,
+                                             int                     y,
                                              int                     width,
                                              int                     height);
 gboolean          meta_gradient_spec_validate (MetaGradientSpec     *spec,
diff --git a/src/ui/theme.c b/src/ui/theme.c
index d923fbe..e925031 100644
--- a/src/ui/theme.c
+++ b/src/ui/theme.c
@@ -38,7 +38,6 @@
 #include <config.h>
 #include "theme-private.h"
 #include <meta/util.h>
-#include <meta/gradient.h>
 #include <meta/prefs.h>
 #include <gtk/gtk.h>
 #include <string.h>
@@ -998,42 +997,91 @@ meta_gradient_spec_free (MetaGradientSpec *spec)
   g_free (spec);
 }
 
-GdkPixbuf*
-meta_gradient_spec_render (const MetaGradientSpec *spec,
-                           GtkStyleContext        *style,
-                           int                     width,
-                           int                     height)
+static cairo_pattern_t *
+meta_gradient_spec_pattern (const MetaGradientSpec *spec,
+                            const MetaAlphaGradientSpec *alpha_spec,
+                            GtkStyleContext        *style)
 {
+  cairo_pattern_t *pattern;
   int n_colors;
-  GdkRGBA *colors;
   GSList *tmp;
   int i;
-  GdkPixbuf *pixbuf;
+
+  if (spec->type == META_GRADIENT_HORIZONTAL)
+    pattern = cairo_pattern_create_linear (0, 0, 1, 0);
+  if (spec->type == META_GRADIENT_VERTICAL)
+    pattern = cairo_pattern_create_linear (0, 0, 0, 1);
+  else if (spec->type == META_GRADIENT_DIAGONAL)
+    pattern = cairo_pattern_create_linear (0, 0, 1, 1);
+  else
+    g_assert_not_reached ();
 
   n_colors = g_slist_length (spec->color_specs);
 
   if (n_colors == 0)
     return NULL;
 
-  colors = g_new (GdkRGBA, n_colors);
+  if (alpha_spec != NULL)
+    g_assert (n_colors == alpha_spec->n_alphas);
 
   i = 0;
   tmp = spec->color_specs;
   while (tmp != NULL)
     {
-      meta_color_spec_render (tmp->data, style, &colors[i]);
+      GdkRGBA color;
+
+      meta_color_spec_render (tmp->data, style, &color);
+
+      if (alpha_spec != NULL)
+        cairo_pattern_add_color_stop_rgba (pattern,
+                                           i / (float)n_colors,
+                                           color.red,
+                                           color.green,
+                                           color.blue,
+                                           alpha_spec->alphas[i]);
+      else
+        cairo_pattern_add_color_stop_rgb (pattern,
+                                          i / (float)n_colors,
+                                          color.red,
+                                          color.green,
+                                          color.blue);
 
       tmp = tmp->next;
       ++i;
     }
 
-  pixbuf = meta_gradient_create_multi (width, height,
-                                       colors, n_colors,
-                                       spec->type);
+  return pattern;
+}
 
-  g_free (colors);
 
-  return pixbuf;
+void
+meta_gradient_spec_render (const MetaGradientSpec *spec,
+                           const MetaAlphaGradientSpec *alpha_spec,
+                           cairo_t                *cr,
+                           GtkStyleContext        *style,
+                           int                     x,
+                           int                     y,
+                           int                     width,
+                           int                     height)
+{
+  cairo_pattern_t *pattern;
+
+  cairo_save (cr);
+
+  pattern = meta_gradient_spec_pattern (spec, alpha_spec, style);
+  if (pattern == NULL)
+    return;
+
+  cairo_rectangle (cr, x, y, width, height);
+
+  cairo_translate (cr, x, y);
+  cairo_scale (cr, width, height);
+
+  cairo_set_source (cr, pattern);
+  cairo_fill (cr);
+  cairo_pattern_destroy (pattern);
+
+  cairo_restore (cr);
 }
 
 gboolean
@@ -3046,9 +3094,6 @@ meta_draw_op_free (MetaDrawOp *op)
       break;
 
     case META_DRAW_IMAGE:
-      if (op->data.image.alpha_spec)
-        meta_alpha_gradient_spec_free (op->data.image.alpha_spec);
-
       if (op->data.image.pixbuf)
         g_object_unref (G_OBJECT (op->data.image.pixbuf));
 
@@ -3085,9 +3130,6 @@ meta_draw_op_free (MetaDrawOp *op)
       break;
 
     case META_DRAW_ICON:
-      if (op->data.icon.alpha_spec)
-        meta_alpha_gradient_spec_free (op->data.icon.alpha_spec);
-
       meta_draw_spec_free (op->data.icon.x);
       meta_draw_spec_free (op->data.icon.y);
       meta_draw_spec_free (op->data.icon.width);
@@ -3133,42 +3175,6 @@ meta_draw_op_free (MetaDrawOp *op)
 }
 
 static GdkPixbuf*
-apply_alpha (GdkPixbuf             *pixbuf,
-             MetaAlphaGradientSpec *spec,
-             gboolean               force_copy)
-{
-  GdkPixbuf *new_pixbuf;
-  gboolean needs_alpha;
-  
-  g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
-  
-  needs_alpha = spec && (spec->n_alphas > 1 ||
-                         spec->alphas[0] != 0xff);
-
-  if (!needs_alpha)
-    return pixbuf;
-  
-  if (!gdk_pixbuf_get_has_alpha (pixbuf))
-    {
-      new_pixbuf = gdk_pixbuf_add_alpha (pixbuf, FALSE, 0, 0, 0);
-      g_object_unref (G_OBJECT (pixbuf));
-      pixbuf = new_pixbuf;
-    }
-  else if (force_copy)
-    {
-      new_pixbuf = gdk_pixbuf_copy (pixbuf);
-      g_object_unref (G_OBJECT (pixbuf));
-      pixbuf = new_pixbuf;
-    }
-  
-  g_assert (gdk_pixbuf_get_has_alpha (pixbuf));
-
-  meta_gradient_add_alpha (pixbuf, spec->alphas, spec->n_alphas, spec->type);
-  
-  return pixbuf;
-}
-
-static GdkPixbuf*
 pixbuf_tile (GdkPixbuf *tile,
              int        width,
              int        height)
@@ -3298,7 +3304,6 @@ replicate_cols (GdkPixbuf  *src,
 
 static GdkPixbuf*
 scale_and_alpha_pixbuf (GdkPixbuf             *src,
-                        MetaAlphaGradientSpec *alpha_spec,
                         MetaImageFillType      fill_type,
                         int                    width,
                         int                    height,
@@ -3380,9 +3385,6 @@ scale_and_alpha_pixbuf (GdkPixbuf             *src,
             }
         }
     }
-
-  if (pixbuf)
-    pixbuf = apply_alpha (pixbuf, alpha_spec, pixbuf == src);
   
   return pixbuf;
 }
@@ -3449,32 +3451,12 @@ draw_op_as_pixbuf (const MetaDrawOp    *op,
             
             gdk_pixbuf_fill (pixbuf, rgba);
           }
-        else
-          {
-            rgba = GDK_COLOR_RGBA (color);
-            
-            gdk_pixbuf_fill (pixbuf, rgba);
-
-            meta_gradient_add_alpha (pixbuf,
-                                     op->data.tint.alpha_spec->alphas,
-                                     op->data.tint.alpha_spec->n_alphas,
-                                     op->data.tint.alpha_spec->type);
-          }
       }
       break;
 
     case META_DRAW_GRADIENT:
-      {
-        pixbuf = meta_gradient_spec_render (op->data.gradient.gradient_spec,
-                                            context, width, height);
-
-        pixbuf = apply_alpha (pixbuf,
-                              op->data.gradient.alpha_spec,
-                              FALSE);
-      }
       break;
 
-      
     case META_DRAW_IMAGE:
       {
 	if (op->data.image.colorize_spec)
@@ -3501,7 +3483,6 @@ draw_op_as_pixbuf (const MetaDrawOp    *op,
             if (op->data.image.colorize_cache_pixbuf)
               {
                 pixbuf = scale_and_alpha_pixbuf (op->data.image.colorize_cache_pixbuf,
-                                                 op->data.image.alpha_spec,
                                                  op->data.image.fill_type,
                                                  width, height,
                                                  op->data.image.vertical_stripes,
@@ -3511,7 +3492,6 @@ draw_op_as_pixbuf (const MetaDrawOp    *op,
 	else
 	  {
 	    pixbuf = scale_and_alpha_pixbuf (op->data.image.pixbuf,
-                                             op->data.image.alpha_spec,
                                              op->data.image.fill_type,
                                              width, height,
                                              op->data.image.vertical_stripes,
@@ -3530,13 +3510,11 @@ draw_op_as_pixbuf (const MetaDrawOp    *op,
           width <= gdk_pixbuf_get_width (info->mini_icon) &&
           height <= gdk_pixbuf_get_height (info->mini_icon))
         pixbuf = scale_and_alpha_pixbuf (info->mini_icon,
-                                         op->data.icon.alpha_spec,
                                          op->data.icon.fill_type,
                                          width, height,
                                          FALSE, FALSE);
       else if (info->icon)
         pixbuf = scale_and_alpha_pixbuf (info->icon,
-                                         op->data.icon.alpha_spec,
                                          op->data.icon.fill_type,
                                          width, height,
                                          FALSE, FALSE);
@@ -3816,23 +3794,16 @@ meta_draw_op_draw_with_env (const MetaDrawOp    *op,
     case META_DRAW_GRADIENT:
       {
         int rx, ry, rwidth, rheight;
-        GdkPixbuf *pixbuf;
 
         rx = parse_x_position_unchecked (op->data.gradient.x, env);
         ry = parse_y_position_unchecked (op->data.gradient.y, env);
         rwidth = parse_size_unchecked (op->data.gradient.width, env);
         rheight = parse_size_unchecked (op->data.gradient.height, env);
 
-        pixbuf = draw_op_as_pixbuf (op, style_gtk, info,
-                                    rwidth, rheight);
-
-        if (pixbuf)
-          {
-            gdk_cairo_set_source_pixbuf (cr, pixbuf, rx, ry);
-            cairo_paint (cr);
-
-            g_object_unref (G_OBJECT (pixbuf));
-          }
+        meta_gradient_spec_render (op->data.gradient.gradient_spec,
+                                   op->data.gradient.alpha_spec,
+                                   cr, style_gtk,
+                                   rx, ry, rwidth, rheight);
       }
       break;
 



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