[mutter/wip/cairo: 2427/2431] theme: Remove our own gradient stuff



commit 21be928b20cd09b0f20ec3d0715b6d5294737279
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    |   71 ----
 src/ui/gradient.c      |  902 ------------------------------------------------
 src/ui/testgradient.c  |  315 -----------------
 src/ui/theme-parser.c  |   20 +-
 src/ui/theme-private.h |   19 +-
 src/ui/theme.c         |  162 ++++------
 7 files changed, 80 insertions(+), 1416 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 6f7cf5f..401f1fb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -150,8 +150,6 @@ libmutter_la_SOURCES =                              \
        meta/errors.h                           \
        core/frame.c                            \
        core/frame.h                            \
-       ui/gradient.c                           \
-       meta/gradient.h                         \
        core/keybindings.c                      \
        core/keybindings-private.h              \
        core/main.c                             \
@@ -265,7 +263,6 @@ libmutterinclude_headers =                  \
        meta/compositor.h                       \
        meta/display.h                          \
        meta/errors.h                           \
-       meta/gradient.h                         \
        meta/group.h                            \
        meta/keybindings.h                      \
        meta/main.h                             \
@@ -346,13 +343,11 @@ Meta-$(api_version).gir: libmutter.la
 endif
 
 testboxes_SOURCES = core/testboxes.c
-testgradient_SOURCES = ui/testgradient.c
 testasyncgetprop_SOURCES = x11/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
 
 dbus_idle_built_sources = meta-dbus-idle-monitor.c meta-dbus-idle-monitor.h
diff --git a/src/ui/theme-parser.c b/src/ui/theme-parser.c
index 30811a8..014668c 100644
--- a/src/ui/theme-parser.c
+++ b/src/ui/theme-parser.c
@@ -2149,10 +2149,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;
@@ -2164,7 +2162,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))
@@ -2223,13 +2221,6 @@ parse_draw_op_element (GMarkupParseContext  *context,
             }
         }
 
-      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);
 
       op->data.image.pixbuf = pixbuf;
@@ -2240,7 +2231,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 */
@@ -2531,16 +2521,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;
@@ -2572,10 +2559,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);
 
       op->data.icon.x = meta_draw_spec_new (info->theme, x, NULL);
@@ -2583,7 +2566,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 b09bc1f..6e7afd0 100644
--- a/src/ui/theme-private.h
+++ b/src/ui/theme-private.h
@@ -23,7 +23,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>
@@ -275,6 +274,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,
@@ -539,7 +546,6 @@ struct _MetaDrawOp
 
     struct {
       MetaColorSpec *colorize_spec;
-      MetaAlphaGradientSpec *alpha_spec;
       GdkPixbuf *pixbuf;
       MetaDrawSpec *x;
       MetaDrawSpec *y;
@@ -582,7 +588,6 @@ struct _MetaDrawOp
     } gtk_vline;
 
     struct {
-      MetaAlphaGradientSpec *alpha_spec;
       MetaDrawSpec *x;
       MetaDrawSpec *y;
       MetaDrawSpec *width;
@@ -972,8 +977,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 6fa2e9e..9680469 100644
--- a/src/ui/theme.c
+++ b/src/ui/theme.c
@@ -38,7 +38,6 @@
 #include "theme-private.h"
 #include "frames.h" /* for META_TYPE_FRAMES */
 #include "util-private.h"
-#include <meta/gradient.h>
 #include <meta/prefs.h>
 #include <gtk/gtk.h>
 #include <string.h>
@@ -1010,42 +1009,87 @@ 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)
+        color.alpha *= alpha_spec->alphas[i];
+
+      cairo_pattern_add_color_stop_rgba (pattern,
+                                         i / (float)n_colors,
+                                         color.red,
+                                         color.green,
+                                         color.blue,
+                                         color.alpha);
 
       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 +3090,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 +3126,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 +3171,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 +3300,6 @@ replicate_cols (GdkPixbuf  *src,
 
 static GdkPixbuf*
 scale_and_alpha_pixbuf (GdkPixbuf             *src,
-                        MetaAlphaGradientSpec *alpha_spec,
                         MetaImageFillType      fill_type,
                         int                    width,
                         int                    height,
@@ -3381,9 +3382,6 @@ scale_and_alpha_pixbuf (GdkPixbuf             *src,
         }
     }
 
-  if (pixbuf)
-    pixbuf = apply_alpha (pixbuf, alpha_spec, pixbuf == src);
-
   return pixbuf;
 }
 
@@ -3437,28 +3435,6 @@ 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;
 
@@ -3488,7 +3464,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,
@@ -3498,7 +3473,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,
@@ -3511,13 +3485,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);
@@ -3527,6 +3499,7 @@ draw_op_as_pixbuf (const MetaDrawOp    *op,
     case META_DRAW_RECTANGLE:
     case META_DRAW_ARC:
     case META_DRAW_CLIP:
+    case META_DRAW_GRADIENT:
     case META_DRAW_GTK_ARROW:
     case META_DRAW_GTK_BOX:
     case META_DRAW_GTK_VLINE:
@@ -3800,23 +3773,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]