[cairo-commit] src/cairo.h src/cairoint.h src/cairo-region.c

Benjamin Otte company at kemper.freedesktop.org
Tue Jul 6 08:44:23 PDT 2010


 src/cairo-region.c |   80 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/cairo.h        |    6 +++
 src/cairoint.h     |    2 +
 3 files changed, 88 insertions(+)

New commits:
commit 4c91bb9a221bc8e3d65a96365bbd1157b3f4e612
Author: Benjamin Otte <otte at redhat.com>
Date:   Tue Jul 6 17:27:18 2010 +0200

    region: Add cairo_region_xor() and cairo_region_xor_rectangle()
    
    gdk_region_xor() was a quite often used function in GDK and now that
    GDKe uses cairo regions, it seems like a worthwhile addition to Cairo.

diff --git a/src/cairo-region.c b/src/cairo-region.c
index 565a7de..85d7c09 100644
--- a/src/cairo-region.c
+++ b/src/cairo-region.c
@@ -652,6 +652,86 @@ cairo_region_union_rectangle (cairo_region_t *dst,
 slim_hidden_def (cairo_region_union_rectangle);
 
 /**
+ * cairo_region_xor:
+ * @dst: a #cairo_region_t
+ * @other: another #cairo_region_t
+ *
+ * Computes the exclusive difference of @dst with @other and places the
+ * result in @dst. That is, @dst will be set to contain all areas that
+ * are either in @dst or in @other, but not in both.
+ *
+ * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY
+ *
+ * Since: 1.10
+ **/
+cairo_status_t
+cairo_region_xor (cairo_region_t *dst, const cairo_region_t *other)
+{
+    cairo_status_t status = CAIRO_STATUS_SUCCESS;
+    pixman_region32_t tmp;
+
+    if (dst->status)
+	return dst->status;
+
+    if (other->status)
+	return _cairo_region_set_error (dst, other->status);
+
+    pixman_region32_init (&tmp);
+
+    /* XXX: get an xor function into pixman */
+    if (! pixman_region32_subtract (&tmp, CONST_CAST &other->rgn, &dst->rgn) ||
+        ! pixman_region32_subtract (&dst->rgn, &dst->rgn, CONST_CAST &other->rgn) || 
+        ! pixman_region32_union (&dst->rgn, &dst->rgn, &tmp))
+	status = _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY);
+
+    pixman_region32_fini (&tmp);
+
+    return status;
+}
+slim_hidden_def (cairo_region_xor);
+
+/**
+ * cairo_region_xor_rectangle:
+ * @dst: a #cairo_region_t
+ * @rectangle: a #cairo_rectangle_int_t
+ *
+ * Computes the exclusive difference of @dst with @rectangle and places the
+ * result in @dst. That is, @dst will be set to contain all areas that are 
+ * either in @dst or in @rectangle, but not in both.
+ *
+ * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY
+ *
+ * Since: 1.10
+ **/
+cairo_status_t
+cairo_region_xor_rectangle (cairo_region_t *dst,
+			    const cairo_rectangle_int_t *rectangle)
+{
+    cairo_status_t status = CAIRO_STATUS_SUCCESS;
+    pixman_region32_t region, tmp;
+
+    if (dst->status)
+	return dst->status;
+
+    pixman_region32_init_rect (&region,
+			       rectangle->x, rectangle->y,
+			       rectangle->width, rectangle->height);
+    pixman_region32_init (&tmp);
+
+    /* XXX: get an xor function into pixman */
+    if (! pixman_region32_subtract (&tmp, &region, &dst->rgn) ||
+        ! pixman_region32_subtract (&dst->rgn, &dst->rgn, &region) || 
+        ! pixman_region32_union (&dst->rgn, &dst->rgn, &tmp))
+	status = _cairo_region_set_error (dst, CAIRO_STATUS_NO_MEMORY);
+
+    pixman_region32_fini (&tmp);
+    pixman_region32_fini (&region);
+
+    return status;
+}
+slim_hidden_def (cairo_region_xor_rectangle);
+
+/**
  * cairo_region_is_empty:
  * @region: a #cairo_region_t
  *
diff --git a/src/cairo.h b/src/cairo.h
index a2d37f9..94fc11f 100644
--- a/src/cairo.h
+++ b/src/cairo.h
@@ -2685,6 +2685,12 @@ cairo_public cairo_status_t
 cairo_region_union_rectangle (cairo_region_t *dst,
 			      const cairo_rectangle_int_t *rectangle);
 
+cairo_public cairo_status_t
+cairo_region_xor (cairo_region_t *dst, const cairo_region_t *other);
+
+cairo_public cairo_status_t
+cairo_region_xor_rectangle (cairo_region_t *dst,
+			    const cairo_rectangle_int_t *rectangle);
 
 /* Functions to be used while debugging (not intended for use in production code) */
 cairo_public void
diff --git a/src/cairoint.h b/src/cairoint.h
index 1a938ed..fe2f7fc 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -2498,6 +2498,8 @@ slim_hidden_proto (cairo_region_intersect);
 slim_hidden_proto (cairo_region_intersect_rectangle);
 slim_hidden_proto (cairo_region_union);
 slim_hidden_proto (cairo_region_union_rectangle);
+slim_hidden_proto (cairo_region_xor);
+slim_hidden_proto (cairo_region_xor_rectangle);
 
 #if CAIRO_HAS_PNG_FUNCTIONS
 


More information about the cairo-commit mailing list