From f4dc73bad4f662bdc3c94cb1e224f9a1989beba5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=B8ren=20Sandmann=20Pedersen?= Date: Sun, 12 Sep 2010 04:35:08 -0400 Subject: [PATCH] Do opacity computation with shifts instead of comparing with 0 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 -- 2.7.4