From df883aa937d2f3ecf52048b60caff48b1c9edac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Sandmann=20Pedersen?= Date: Tue, 17 Feb 2009 06:06:40 -0500 Subject: [PATCH] [region] Add a cairo_region_overlap_t type --- src/cairo-analysis-surface.c | 4 ++-- src/cairo-region-private.h | 8 +++++++- src/cairo-region.c | 33 ++++++++++++++++++++++++--------- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/cairo-analysis-surface.c b/src/cairo-analysis-surface.c index 9c97c1117..eaa7947ef 100644 --- a/src/cairo-analysis-surface.c +++ b/src/cairo-analysis-surface.c @@ -215,7 +215,7 @@ _add_operation (cairo_analysis_surface_t *surface, * region there is no benefit in emitting a native operation as * the fallback image will be painted on top. */ - if (_cairo_region_contains_rectangle (surface->fallback_region, rect) == PIXMAN_REGION_IN) + if (_cairo_region_contains_rectangle (surface->fallback_region, rect) == CAIRO_REGION_OVERLAP_IN) return CAIRO_INT_STATUS_IMAGE_FALLBACK; if (backend_status == CAIRO_INT_STATUS_FLATTEN_TRANSPARENCY) { @@ -226,7 +226,7 @@ _add_operation (cairo_analysis_surface_t *surface, * natively supported and the backend will blend the * transparency into the white background. */ - if (_cairo_region_contains_rectangle (surface->supported_region, rect) == PIXMAN_REGION_OUT) + if (_cairo_region_contains_rectangle (surface->supported_region, rect) == CAIRO_REGION_OVERLAP_OUT) backend_status = CAIRO_STATUS_SUCCESS; } diff --git a/src/cairo-region-private.h b/src/cairo-region-private.h index 5a93ebd22..450b0864e 100644 --- a/src/cairo-region-private.h +++ b/src/cairo-region-private.h @@ -52,6 +52,12 @@ struct _cairo_region { pixman_region32_t rgn; }; +typedef enum _cairo_region_overlap { + CAIRO_REGION_OVERLAP_IN, /* completely inside region */ + CAIRO_REGION_OVERLAP_OUT, /* completely outside region */ + CAIRO_REGION_OVERLAP_PART, /* partly inside region */ +} cairo_region_overlap_t; + cairo_private cairo_region_t * _cairo_region_create (void); @@ -105,7 +111,7 @@ cairo_private void _cairo_region_translate (cairo_region_t *region, int x, int y); -cairo_private pixman_region_overlap_t +cairo_private cairo_region_overlap_t _cairo_region_contains_rectangle (cairo_region_t *region, const cairo_rectangle_int_t *rect); diff --git a/src/cairo-region.c b/src/cairo-region.c index 5f53bc923..b951e6341 100644 --- a/src/cairo-region.c +++ b/src/cairo-region.c @@ -279,19 +279,34 @@ _cairo_region_translate (cairo_region_t *region, pixman_region32_translate (®ion->rgn, x, y); } -pixman_region_overlap_t +cairo_region_overlap_t _cairo_region_contains_rectangle (cairo_region_t *region, const cairo_rectangle_int_t *rect) { pixman_box32_t pbox; + pixman_region_overlap_t poverlap; - if (region->status) - return PIXMAN_REGION_OUT; - - pbox.x1 = rect->x; - pbox.y1 = rect->y; - pbox.x2 = rect->x + rect->width; - pbox.y2 = rect->y + rect->height; + if (!region->status) + { + pbox.x1 = rect->x; + pbox.y1 = rect->y; + pbox.x2 = rect->x + rect->width; + pbox.y2 = rect->y + rect->height; + + poverlap = pixman_region32_contains_rectangle (®ion->rgn, &pbox); + + switch (poverlap) + { + case PIXMAN_REGION_OUT: + return CAIRO_REGION_OVERLAP_OUT; + + case PIXMAN_REGION_IN: + return CAIRO_REGION_OVERLAP_IN; + + case PIXMAN_REGION_PART: + return CAIRO_REGION_OVERLAP_PART; + } + } - return pixman_region32_contains_rectangle (®ion->rgn, &pbox); + return CAIRO_REGION_OVERLAP_OUT; }