Skip fetching pixels when possible
authorSøren Sandmann Pedersen <ssp@redhat.com>
Sat, 11 Dec 2010 13:10:04 +0000 (08:10 -0500)
committerSøren Sandmann Pedersen <ssp@redhat.com>
Tue, 18 Jan 2011 17:42:26 +0000 (12:42 -0500)
Add two new iterator flags, ITER_IGNORE_ALPHA and ITER_IGNORE_RGB that
are set when the alpha and rgb values are not needed. If both are set,
then we can skip fetching entirely and just use
_pixman_iter_get_scanline_noop.

pixman/pixman-bits-image.c
pixman/pixman-general.c
pixman/pixman-implementation.c
pixman/pixman-private.h

index 8d4e4f5..8cabfdc 100644 (file)
@@ -1466,7 +1466,16 @@ _pixman_bits_image_dest_iter_init (pixman_image_t *image,
        }
        else
        {
-           iter->get_scanline = dest_get_scanline_narrow;
+           if ((flags & (ITER_IGNORE_RGB | ITER_IGNORE_ALPHA)) ==
+               (ITER_IGNORE_RGB | ITER_IGNORE_ALPHA))
+           {
+               iter->get_scanline = _pixman_iter_get_scanline_noop;
+           }
+           else
+           {
+               iter->get_scanline = dest_get_scanline_narrow;
+           }
+
            iter->write_back = dest_write_back_narrow;
        }
     }
index e7a7283..16ea3a4 100644 (file)
@@ -107,6 +107,34 @@ general_dest_iter_init (pixman_implementation_t *imp,
     }
 }
 
+typedef struct op_info_t op_info_t;
+struct op_info_t
+{
+    uint8_t src, dst;
+};
+
+#define ITER_IGNORE_BOTH                                               \
+    (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB | ITER_LOCALIZED_ALPHA)
+
+static const op_info_t op_flags[PIXMAN_N_OPERATORS] =
+{
+    /* Src                   Dst                   */
+    { ITER_IGNORE_BOTH,      ITER_IGNORE_BOTH      }, /* CLEAR */
+    { ITER_LOCALIZED_ALPHA,  ITER_IGNORE_BOTH      }, /* SRC */
+    { ITER_IGNORE_BOTH,      ITER_LOCALIZED_ALPHA  }, /* DST */
+    { 0,                     ITER_LOCALIZED_ALPHA  }, /* OVER */
+    { ITER_LOCALIZED_ALPHA,  0                     }, /* OVER_REVERSE */
+    { ITER_LOCALIZED_ALPHA,  ITER_IGNORE_RGB       }, /* IN */
+    { ITER_IGNORE_RGB,       ITER_LOCALIZED_ALPHA  }, /* IN_REVERSE */
+    { ITER_LOCALIZED_ALPHA,  ITER_IGNORE_RGB       }, /* OUT */
+    { ITER_IGNORE_RGB,       ITER_LOCALIZED_ALPHA  }, /* OUT_REVERSE */
+    { 0,                     0                     }, /* ATOP */
+    { 0,                     0                     }, /* ATOP_REVERSE */
+    { 0,                     0                     }, /* XOR */
+    { ITER_LOCALIZED_ALPHA,  ITER_LOCALIZED_ALPHA  }, /* ADD */
+    { 0,                     0                     }, /* SATURATE */
+};
+
 #define SCANLINE_BUFFER_LENGTH 8192
 
 static void
@@ -130,7 +158,7 @@ general_composite_rect  (pixman_implementation_t *imp,
     pixman_iter_t src_iter, mask_iter, dest_iter;
     pixman_combine_32_func_t compose;
     pixman_bool_t component_alpha;
-    iter_flags_t narrow, dest_flags;
+    iter_flags_t narrow, src_flags;
     int Bpp;
     int i;
 
@@ -159,39 +187,39 @@ general_composite_rect  (pixman_implementation_t *imp,
     mask_buffer = src_buffer + width * Bpp;
     dest_buffer = mask_buffer + width * Bpp;
 
+    /* src iter */
+    src_flags = narrow | op_flags[op].src;
+
     _pixman_implementation_src_iter_init (imp->toplevel, &src_iter, src,
                                          src_x, src_y, width, height,
-                                         src_buffer, narrow);
-
-    _pixman_implementation_src_iter_init (imp->toplevel, &mask_iter, mask,
-                                         mask_x, mask_y, width, height,
-                                         mask_buffer, narrow);
-
-    if (op == PIXMAN_OP_CLEAR          ||
-       op == PIXMAN_OP_SRC             ||
-       op == PIXMAN_OP_DST             ||
-       op == PIXMAN_OP_OVER            ||
-       op == PIXMAN_OP_IN_REVERSE      ||
-       op == PIXMAN_OP_OUT_REVERSE     ||
-       op == PIXMAN_OP_ADD)
-    {
-       dest_flags = narrow | ITER_LOCALIZED_ALPHA;
-    }
-    else
+                                         src_buffer, src_flags);
+
+    /* mask iter */
+    if ((src_flags & (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB)) ==
+       (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB))
     {
-       dest_flags = narrow;
+       /* If it doesn't matter what the source is, then it doesn't matter
+        * what the mask is
+        */
+       mask = NULL;
     }
 
-    _pixman_implementation_dest_iter_init (imp->toplevel, &dest_iter, dest,
-                                          dest_x, dest_y, width, height,
-                                          dest_buffer, dest_flags);
-
     component_alpha =
         mask                            &&
         mask->common.type == BITS       &&
         mask->common.component_alpha    &&
         PIXMAN_FORMAT_RGB (mask->bits.format);
 
+    _pixman_implementation_src_iter_init (
+       imp->toplevel, &mask_iter, mask, mask_x, mask_y, width, height,
+       mask_buffer, narrow | (component_alpha? 0 : ITER_IGNORE_RGB));
+
+    /* dest iter */
+    _pixman_implementation_dest_iter_init (imp->toplevel, &dest_iter, dest,
+                                          dest_x, dest_y, width, height,
+                                          dest_buffer,
+                                          narrow | op_flags[op].dst);
+
     if (narrow)
     {
        if (component_alpha)
index e633432..adaf9c6 100644 (file)
@@ -278,6 +278,11 @@ _pixman_implementation_src_iter_init (pixman_implementation_t      *imp,
     {
        iter->get_scanline = get_scanline_null;
     }
+    else if ((flags & (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB)) ==
+            (ITER_IGNORE_ALPHA | ITER_IGNORE_RGB))
+    {
+       iter->get_scanline = _pixman_iter_get_scanline_noop;
+    }
     else
     {
        (*imp->src_iter_init) (
index 0aeae2e..1662d2c 100644 (file)
@@ -202,7 +202,9 @@ typedef enum
      * we can treat it as if it were ARGB, which means in some cases we can
      * avoid copying it to a temporary buffer.
      */
-    ITER_LOCALIZED_ALPHA =     (1 << 1)
+    ITER_LOCALIZED_ALPHA =     (1 << 1),
+    ITER_IGNORE_ALPHA =                (1 << 2),
+    ITER_IGNORE_RGB =          (1 << 3)
 } iter_flags_t;
 
 struct pixman_iter_t