[gtk/wip/otte/icontheme: 6/9] Revert "Break out cairo color matrix recoloring to gdk_cairo_image_surface_recolor()"



commit 51000c4833483f309bffd6a19f76f47ebf23ef3f
Author: Benjamin Otte <otte redhat com>
Date:   Sun Feb 2 00:56:39 2020 +0100

    Revert "Break out cairo color matrix recoloring to gdk_cairo_image_surface_recolor()"
    
    We're not in the business of adding Cairo APIs. That's Cairo's job.
    
    Also, we don't need this API anywhere like the original commit claimed,
    so there's no need to make it available in any way.
    
    This reverts commit afa6cc23692f83f0d38de24c9cf58a7a494c01d2.

 gdk/gdkcairo.c          | 71 -------------------------------------------------
 gdk/gdkcairo.h          |  6 -----
 gsk/gskrendernodeimpl.c | 53 +++++++++++++++++++++++++++++++++---
 3 files changed, 50 insertions(+), 80 deletions(-)
---
diff --git a/gdk/gdkcairo.c b/gdk/gdkcairo.c
index 68d46aa4ae..c5917cfeb9 100644
--- a/gdk/gdkcairo.c
+++ b/gdk/gdkcairo.c
@@ -456,74 +456,3 @@ gdk_cairo_region_from_clip (cairo_t *cr)
 
   return region;
 }
-
-/**
- * gdk_cairo_image_surface_recolor:
- * @image_surface: a cairo image surface
- * @color_matrix: the color matrix to use
- * @color_offset: the color offset to use
- *
- * Modifies the colors of an surfaceimage by applying an affine transformation
- * in RGB space.
- *
- * This is the same operation as in gtk_snapshot_push_color_matrix() but
- * always done on the cpu.
- */
-void
-gdk_cairo_image_surface_recolor (cairo_surface_t         *image_surface,
-                                 const graphene_matrix_t *color_matrix,
-                                 const graphene_vec4_t   *color_offset)
-{
-  graphene_vec4_t pixel;
-  guint32* pixel_data;
-  guchar *data;
-  gsize x, y, width, height, stride;
-  float alpha;
-
-  data = cairo_image_surface_get_data (image_surface);
-  width = cairo_image_surface_get_width (image_surface);
-  height = cairo_image_surface_get_height (image_surface);
-  stride = cairo_image_surface_get_stride (image_surface);
-
-  for (y = 0; y < height; y++)
-    {
-      pixel_data = (guint32 *) data;
-      for (x = 0; x < width; x++)
-        {
-          alpha = ((pixel_data[x] >> 24) & 0xFF) / 255.0;
-
-          if (alpha == 0)
-            {
-              graphene_vec4_init (&pixel, 0.0, 0.0, 0.0, 0.0);
-            }
-          else
-            {
-              graphene_vec4_init (&pixel,
-                                  ((pixel_data[x] >> 16) & 0xFF) / (255.0 * alpha),
-                                  ((pixel_data[x] >>  8) & 0xFF) / (255.0 * alpha),
-                                  ( pixel_data[x]        & 0xFF) / (255.0 * alpha),
-                                  alpha);
-              graphene_matrix_transform_vec4 (color_matrix, &pixel, &pixel);
-            }
-
-          graphene_vec4_add (&pixel, color_offset, &pixel);
-
-          alpha = graphene_vec4_get_w (&pixel);
-          if (alpha > 0.0)
-            {
-              alpha = MIN (alpha, 1.0);
-              pixel_data[x] = (((guint32) roundf (alpha * 255)) << 24) |
-                              (((guint32) roundf (CLAMP (graphene_vec4_get_x (&pixel), 0, 1) * alpha * 255)) 
<< 16) |
-                              (((guint32) roundf (CLAMP (graphene_vec4_get_y (&pixel), 0, 1) * alpha * 255)) 
<<  8) |
-                               ((guint32) roundf (CLAMP (graphene_vec4_get_z (&pixel), 0, 1) * alpha * 255));
-            }
-          else
-            {
-              pixel_data[x] = 0;
-            }
-        }
-      data += stride;
-    }
-
-  cairo_surface_mark_dirty (image_surface);
-}
diff --git a/gdk/gdkcairo.h b/gdk/gdkcairo.h
index 934b5d17ed..c4e2d3836c 100644
--- a/gdk/gdkcairo.h
+++ b/gdk/gdkcairo.h
@@ -26,7 +26,6 @@
 #include <gdk/gdkrgba.h>
 #include <gdk/gdkpixbuf.h>
 #include <pango/pangocairo.h>
-#include <graphene.h>
 
 G_BEGIN_DECLS
 
@@ -73,11 +72,6 @@ void      gdk_cairo_surface_upload_to_gl (cairo_surface_t *surface,
                                           int              height,
                                           GdkGLContext    *context);
 
-GDK_AVAILABLE_IN_ALL
-void      gdk_cairo_image_surface_recolor (cairo_surface_t         *image_surface,
-                                           const graphene_matrix_t *color_matrix,
-                                           const graphene_vec4_t   *color_offset);
-
 G_END_DECLS
 
 #endif /* __GDK_CAIRO_H__ */
diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c
index f82343054b..2434c5d40e 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -2339,6 +2339,11 @@ gsk_color_matrix_node_draw (GskRenderNode *node,
   GskColorMatrixNode *self = (GskColorMatrixNode *) node;
   cairo_pattern_t *pattern;
   cairo_surface_t *surface, *image_surface;
+  graphene_vec4_t pixel;
+  guint32* pixel_data;
+  guchar *data;
+  gsize x, y, width, height, stride;
+  float alpha;
 
   cairo_save (cr);
 
@@ -2355,10 +2360,52 @@ gsk_color_matrix_node_draw (GskRenderNode *node,
   cairo_pattern_get_surface (pattern, &surface);
   image_surface = cairo_surface_map_to_image (surface, NULL);
 
-  gdk_cairo_image_surface_recolor (image_surface,
-                                   &self->color_matrix,
-                                   &self->color_offset);
+  data = cairo_image_surface_get_data (image_surface);
+  width = cairo_image_surface_get_width (image_surface);
+  height = cairo_image_surface_get_height (image_surface);
+  stride = cairo_image_surface_get_stride (image_surface);
 
+  for (y = 0; y < height; y++)
+    {
+      pixel_data = (guint32 *) data;
+      for (x = 0; x < width; x++)
+        {
+          alpha = ((pixel_data[x] >> 24) & 0xFF) / 255.0;
+
+          if (alpha == 0)
+            {
+              graphene_vec4_init (&pixel, 0.0, 0.0, 0.0, 0.0);
+            }
+          else
+            {
+              graphene_vec4_init (&pixel,
+                                  ((pixel_data[x] >> 16) & 0xFF) / (255.0 * alpha),
+                                  ((pixel_data[x] >>  8) & 0xFF) / (255.0 * alpha),
+                                  ( pixel_data[x]        & 0xFF) / (255.0 * alpha),
+                                  alpha);
+              graphene_matrix_transform_vec4 (&self->color_matrix, &pixel, &pixel);
+            }
+
+          graphene_vec4_add (&pixel, &self->color_offset, &pixel);
+
+          alpha = graphene_vec4_get_w (&pixel);
+          if (alpha > 0.0)
+            {
+              alpha = MIN (alpha, 1.0);
+              pixel_data[x] = (((guint32) roundf (alpha * 255)) << 24) |
+                              (((guint32) roundf (CLAMP (graphene_vec4_get_x (&pixel), 0, 1) * alpha * 255)) 
<< 16) |
+                              (((guint32) roundf (CLAMP (graphene_vec4_get_y (&pixel), 0, 1) * alpha * 255)) 
<<  8) |
+                               ((guint32) roundf (CLAMP (graphene_vec4_get_z (&pixel), 0, 1) * alpha * 255));
+            }
+          else
+            {
+              pixel_data[x] = 0;
+            }
+        }
+      data += stride;
+    }
+
+  cairo_surface_mark_dirty (image_surface);
   cairo_surface_unmap_image (surface, image_surface);
 
   cairo_set_source (cr, pattern);


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