summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <sandmann@redhat.com>2009-11-07 22:37:48 -0500
committerSøren Sandmann Pedersen <ssp@redhat.com>2010-03-14 12:59:37 -0400
commitb273dd11a5164ef1c5f61ee74b0aee26df62d49c (patch)
tree4505c6d5aa4900bae406eeee0866ee2b4dac1efa
parentda2ecbed6cc82fafc8c7c702d56b4cd3d1b9f5a7 (diff)
Simplify pixman_compute_composite_region32()
- It is not necessary to initialize the region before the call. - Move all the pixman_region32_fini() calls to one place. - Factor out the source clipping code.
-rw-r--r--pixman/pixman.c100
1 files changed, 47 insertions, 53 deletions
diff --git a/pixman/pixman.c b/pixman/pixman.c
index 10e25d81..27eefbb0 100644
--- a/pixman/pixman.c
+++ b/pixman/pixman.c
@@ -241,10 +241,10 @@ clip_general_image (pixman_region32_t * region,
}
static inline pixman_bool_t
-clip_source_image (pixman_region32_t * region,
- pixman_image_t * image,
- int dx,
- int dy)
+do_clip_source_image (pixman_region32_t * region,
+ pixman_image_t * image,
+ int dx,
+ int dy)
{
/* Source clips are ignored, unless they are explicitly turned on
* and the clip in question was set by an X client. (Because if
@@ -259,6 +259,32 @@ clip_source_image (pixman_region32_t * region,
dx, dy);
}
+static pixman_bool_t
+clip_source_image (pixman_region32_t *region,
+ pixman_image_t *image,
+ int dx,
+ int dy)
+{
+ if (!image->common.clip_sources)
+ return TRUE;
+
+ if (image->common.have_clip_region)
+ {
+ if (!do_clip_source_image (region, image, dx, dy))
+ return FALSE;
+ }
+ if (image->common.alpha_map && image->common.alpha_map->common.have_clip_region)
+ {
+ if (!do_clip_source_image (region, (pixman_image_t *)image->common.alpha_map,
+ dx + image->common.alpha_origin_x,
+ dy + image->common.alpha_origin_y))
+ {
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
/*
* returns FALSE if the final region is empty. Indistinguishable from
* an allocation failure, but rendering ignores those anyways.
@@ -293,17 +319,22 @@ pixman_compute_composite_region32 (pixman_region32_t * region,
if (region->extents.x1 >= region->extents.x2 ||
region->extents.y1 >= region->extents.y2)
{
- pixman_region32_init (region);
- return FALSE;
+ goto out_fini;
}
+ /* clip against src */
+ if (!clip_source_image (region, src_image, src_x - dest_x, src_y - dest_y))
+ goto out_fini;
+
+ /* clip against mask */
+ if (mask_image && !clip_source_image (region, mask_image, mask_x - dest_x, mask_y - dest_y))
+ goto out_fini;
+
+ /* clip against dest */
if (dst_image->common.have_clip_region)
{
if (!clip_general_image (region, &dst_image->common.clip_region, 0, 0))
- {
- pixman_region32_fini (region);
- return FALSE;
- }
+ goto out_fini;
}
if (dst_image->common.alpha_map && dst_image->common.alpha_map->common.have_clip_region)
@@ -312,51 +343,15 @@ pixman_compute_composite_region32 (pixman_region32_t * region,
-dst_image->common.alpha_origin_x,
-dst_image->common.alpha_origin_y))
{
- pixman_region32_fini (region);
- return FALSE;
- }
- }
-
- /* clip against src */
- if (src_image->common.have_clip_region)
- {
- if (!clip_source_image (region, src_image, dest_x - src_x, dest_y - src_y))
- {
- pixman_region32_fini (region);
- return FALSE;
- }
- }
- if (src_image->common.alpha_map && src_image->common.alpha_map->common.have_clip_region)
- {
- if (!clip_source_image (region, (pixman_image_t *)src_image->common.alpha_map,
- dest_x - (src_x - src_image->common.alpha_origin_x),
- dest_y - (src_y - src_image->common.alpha_origin_y)))
- {
- pixman_region32_fini (region);
- return FALSE;
- }
- }
- /* clip against mask */
- if (mask_image && mask_image->common.have_clip_region)
- {
- if (!clip_source_image (region, mask_image, dest_x - mask_x, dest_y - mask_y))
- {
- pixman_region32_fini (region);
- return FALSE;
- }
- if (mask_image->common.alpha_map && mask_image->common.alpha_map->common.have_clip_region)
- {
- if (!clip_source_image (region, (pixman_image_t *)mask_image->common.alpha_map,
- dest_x - (mask_x - mask_image->common.alpha_origin_x),
- dest_y - (mask_y - mask_image->common.alpha_origin_y)))
- {
- pixman_region32_fini (region);
- return FALSE;
- }
+ goto out_fini;
}
}
return TRUE;
+
+out_fini:
+ pixman_region32_fini (region);
+ return FALSE;
}
static void
@@ -570,8 +565,7 @@ do_composite (pixman_implementation_t *imp,
apply_workaround (dest, &dest_x, &dest_y, &dest_bits, &dest_dx, &dest_dy);
}
- pixman_region32_init (&region);
-
+ /* Compute composite region */
if (!pixman_compute_composite_region32 (
&region, src, mask, dest,
src_x, src_y, mask_x, mask_y, dest_x, dest_y, width, height))