[Pixman] [PATCH] Do opacity computation with shifts instead of comparing with 0
Søren Sandmann
sandmann at daimi.au.dk
Sun Sep 12 06:14:47 PDT 2010
From: Søren Sandmann Pedersen <ssp at redhat.com>
Also add a COMPILE_TIME_ASSERT() macro and use it to assert that the
shift is correct.
---
pixman/pixman-private.h | 3 +++
pixman/pixman.c | 14 +++++++++-----
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/pixman/pixman-private.h b/pixman/pixman-private.h
index 3557fb2..36b9d91 100644
--- a/pixman/pixman-private.h
+++ b/pixman/pixman-private.h
@@ -744,6 +744,9 @@ pixman_region16_copy_from_region32 (pixman_region16_t *dst,
#undef DEBUG
+#define COMPILE_TIME_ASSERT(x) \
+ do { typedef int compile_time_assertion [(x)?1:-1]; } while (0)
+
/* Turn on debugging depending on what type of release this is
*/
#if (((PIXMAN_VERSION_MICRO % 2) == 0) && ((PIXMAN_VERSION_MINOR % 2) == 1))
diff --git a/pixman/pixman.c b/pixman/pixman.c
index 47ffdd6..cdf4b75 100644
--- a/pixman/pixman.c
+++ b/pixman/pixman.c
@@ -139,14 +139,18 @@ optimize_operator (pixman_op_t op,
uint32_t dst_flags)
{
pixman_bool_t is_source_opaque, is_dest_opaque;
- int opaqueness;
- is_source_opaque = ((src_flags & mask_flags) & FAST_PATH_IS_OPAQUE) != 0;
- is_dest_opaque = (dst_flags & FAST_PATH_IS_OPAQUE) != 0;
+#define OPAQUE_SHIFT 13
+
+ COMPILE_TIME_ASSERT (FAST_PATH_IS_OPAQUE == (1 << OPAQUE_SHIFT));
+
+ is_dest_opaque = (dst_flags & FAST_PATH_IS_OPAQUE);
+ is_source_opaque = ((src_flags & mask_flags) & FAST_PATH_IS_OPAQUE);
- opaqueness = ((is_dest_opaque << 1) | is_source_opaque);
+ is_dest_opaque >>= OPAQUE_SHIFT - 1;
+ is_source_opaque >>= OPAQUE_SHIFT;
- return operator_table[op].opaque_info[opaqueness];
+ return operator_table[op].opaque_info[is_dest_opaque | is_source_opaque];
}
static void
--
1.7.1.1
More information about the Pixman
mailing list