gecko-dev/gfx/cairo/cairo-clip-extract-rectangl...

313 строки
11 KiB
Diff

Index: gfx/cairo/cairo/src/cairo.h
===================================================================
RCS file: /home/rocallahan/mozilla-cvs-mirror/mozilla/gfx/cairo/cairo/src/cairo.h,v
retrieving revision 1.9
diff -u -t -p -1 -2 -r1.9 cairo.h
--- gfx/cairo/cairo/src/cairo.h 10 Feb 2006 02:20:34 -0000 1.9
+++ gfx/cairo/cairo/src/cairo.h 21 Feb 2006 23:17:08 -0000
@@ -1129,24 +1129,42 @@ cairo_public cairo_path_t *
cairo_copy_path (cairo_t *cr);
cairo_public cairo_path_t *
cairo_copy_path_flat (cairo_t *cr);
cairo_public void
cairo_append_path (cairo_t *cr,
cairo_path_t *path);
cairo_public void
cairo_path_destroy (cairo_path_t *path);
+/**
+ * cairo_clip_rect_t:
+ *
+ * A data structure for holding clip rectangles.
+ */
+typedef struct _cairo_clip_rect {
+ double x, y, width, height;
+} cairo_clip_rect_t;
+
+cairo_public cairo_bool_t
+cairo_has_clip (cairo_t *cr);
+
+cairo_public cairo_bool_t
+cairo_extract_clip_rectangles (cairo_t *cr,
+ int max_rectangles,
+ cairo_clip_rect_t *rectangles_out,
+ int *num_rectangles_out);
+
/* Error status queries */
cairo_public cairo_status_t
cairo_status (cairo_t *cr);
cairo_public const char *
cairo_status_to_string (cairo_status_t status);
/* Surface manipulation */
cairo_public cairo_surface_t *
cairo_surface_create_similar (cairo_surface_t *other,
Index: gfx/cairo/cairo/src/cairoint.h
===================================================================
RCS file: /home/rocallahan/mozilla-cvs-mirror/mozilla/gfx/cairo/cairo/src/cairoint.h,v
retrieving revision 1.19
diff -u -t -p -1 -2 -r1.19 cairoint.h
--- gfx/cairo/cairo/src/cairoint.h 10 Feb 2006 02:51:12 -0000 1.19
+++ gfx/cairo/cairo/src/cairoint.h 21 Feb 2006 23:18:00 -0000
@@ -1229,24 +1229,33 @@ cairo_private cairo_status_t
_cairo_gstate_in_fill (cairo_gstate_t *gstate,
cairo_path_fixed_t *path,
double x,
double y,
cairo_bool_t *inside_ret);
cairo_private cairo_status_t
_cairo_gstate_clip (cairo_gstate_t *gstate, cairo_path_fixed_t *path);
cairo_private cairo_status_t
_cairo_gstate_reset_clip (cairo_gstate_t *gstate);
+cairo_private cairo_bool_t
+_cairo_gstate_has_clip (cairo_gstate_t *gstate);
+
+cairo_private cairo_bool_t
+_cairo_gstate_extract_clip_rectangles (cairo_gstate_t *gstate,
+ int max_rectangles,
+ cairo_clip_rect_t *rectangles_out,
+ int *num_rectangles_out);
+
cairo_private cairo_status_t
_cairo_gstate_show_surface (cairo_gstate_t *gstate,
cairo_surface_t *surface,
double x,
double y,
double width,
double height);
cairo_private cairo_status_t
_cairo_gstate_select_font_face (cairo_gstate_t *gstate,
const char *family,
cairo_font_slant_t slant,
Index: gfx/cairo/cairo/src/cairo-clip-private.h
===================================================================
RCS file: /home/rocallahan/mozilla-cvs-mirror/mozilla/gfx/cairo/cairo/src/cairo-clip-private.h,v
retrieving revision 1.2
diff -u -t -p -1 -2 -r1.2 cairo-clip-private.h
--- gfx/cairo/cairo/src/cairo-clip-private.h 10 Jan 2006 22:56:38 -0000 1.2
+++ gfx/cairo/cairo/src/cairo-clip-private.h 7 Feb 2006 22:44:42 -0000
@@ -105,13 +105,22 @@ _cairo_clip_intersect_to_rectangle (cair
cairo_private cairo_status_t
_cairo_clip_intersect_to_region (cairo_clip_t *clip,
pixman_region16_t *region);
cairo_private cairo_status_t
_cairo_clip_combine_to_surface (cairo_clip_t *clip,
cairo_operator_t op,
cairo_surface_t *dst,
int dst_x,
int dst_y,
const cairo_rectangle_t *extents);
+cairo_private cairo_bool_t
+_cairo_clip_has_clip (cairo_clip_t *clip);
+
+cairo_private cairo_bool_t
+_cairo_clip_extract_rectangles (cairo_clip_t *clip,
+ int max_rectangles,
+ cairo_clip_rect_t *rectangles_out,
+ int *num_rectangles_out);
+
#endif /* CAIRO_CLIP_PRIVATE_H */
Index: gfx/cairo/cairo/src/cairo-clip.c
===================================================================
RCS file: /home/rocallahan/mozilla-cvs-mirror/mozilla/gfx/cairo/cairo/src/cairo-clip.c,v
retrieving revision 1.3
diff -u -t -p -1 -2 -r1.3 cairo-clip.c
--- gfx/cairo/cairo/src/cairo-clip.c 10 Jan 2006 22:56:38 -0000 1.3
+++ gfx/cairo/cairo/src/cairo-clip.c 21 Feb 2006 23:19:34 -0000
@@ -450,12 +450,62 @@ _cairo_clip_clip (cairo_clip_t *cl
status = _cairo_clip_intersect_region (clip, &traps, target);
if (status != CAIRO_INT_STATUS_UNSUPPORTED)
goto bail;
status = _cairo_clip_intersect_mask (clip, &traps, antialias, target);
bail:
_cairo_traps_fini (&traps);
return status;
}
+
+cairo_bool_t
+_cairo_clip_has_clip (cairo_clip_t *clip)
+{
+ return clip->region != NULL || clip->surface != NULL || clip->path != NULL;
+}
+
+static cairo_bool_t
+_cairo_region_to_clip_rectangles (pixman_region16_t *region,
+ int max_rectangles,
+ cairo_clip_rect_t *rectangles_out,
+ int *num_rectangles_out)
+{
+ int n_boxes, i;
+ pixman_box16_t *boxes;
+
+ /* no region -> we can't represent it as rectangles */
+ if (region == NULL)
+ return FALSE;
+
+ n_boxes = pixman_region_num_rects (region);
+ *num_rectangles_out = n_boxes;
+ if (n_boxes > max_rectangles)
+ return FALSE;
+
+ boxes = pixman_region_rects (region);
+
+ for (i = 0; i < n_boxes; i++) {
+ rectangles_out[i].x = boxes[i].x1;
+ rectangles_out[i].y = boxes[i].y1;
+ rectangles_out[i].width = boxes[i].x2 - boxes[i].x1;
+ rectangles_out[i].height = boxes[i].y2 - boxes[i].y1;
+ }
+
+ return TRUE;
+}
+
+cairo_bool_t
+_cairo_clip_extract_rectangles (cairo_clip_t *clip,
+ int max_rectangles,
+ cairo_clip_rect_t *rectangles_out,
+ int *num_rectangles_out)
+{
+ /* can't handle paths or surfaces for now */
+ if (clip->path != NULL || clip->surface != NULL)
+ return FALSE;
+
+ return _cairo_region_to_clip_rectangles (clip->region,
+ max_rectangles, rectangles_out, num_rectangles_out);
+}
Index: gfx/cairo/cairo/src/cairo-gstate.c
===================================================================
RCS file: /home/rocallahan/mozilla-cvs-mirror/mozilla/gfx/cairo/cairo/src/cairo-gstate.c,v
retrieving revision 1.4
diff -u -t -p -1 -2 -r1.4 cairo-gstate.c
--- gfx/cairo/cairo/src/cairo-gstate.c 10 Jan 2006 22:56:38 -0000 1.4
+++ gfx/cairo/cairo/src/cairo-gstate.c 21 Feb 2006 23:18:13 -0000
@@ -1174,24 +1174,42 @@ _cairo_gstate_reset_clip (cairo_gstate_t
{
return _cairo_clip_reset (&gstate->clip);
}
cairo_status_t
_cairo_gstate_clip (cairo_gstate_t *gstate, cairo_path_fixed_t *path)
{
return _cairo_clip_clip (&gstate->clip,
path, gstate->fill_rule, gstate->tolerance,
gstate->antialias, gstate->target);
}
+cairo_bool_t
+_cairo_gstate_has_clip (cairo_gstate_t *gstate)
+{
+ return _cairo_clip_has_clip (&gstate->clip);
+}
+
+cairo_bool_t
+_cairo_gstate_extract_clip_rectangles (cairo_gstate_t *gstate,
+ int max_rectangles,
+ cairo_clip_rect_t *rectangles_out,
+ int *num_rectangles_out)
+{
+ return _cairo_clip_extract_rectangles (&gstate->clip,
+ max_rectangles,
+ rectangles_out,
+ num_rectangles_out);
+}
+
static void
_cairo_gstate_unset_scaled_font (cairo_gstate_t *gstate)
{
if (gstate->scaled_font) {
cairo_scaled_font_destroy (gstate->scaled_font);
gstate->scaled_font = NULL;
}
}
cairo_status_t
_cairo_gstate_select_font_face (cairo_gstate_t *gstate,
const char *family,
Index: gfx/cairo/cairo/src/cairo.c
===================================================================
RCS file: /home/rocallahan/mozilla-cvs-mirror/mozilla/gfx/cairo/cairo/src/cairo.c,v
retrieving revision 1.11
diff -u -t -p -1 -2 -r1.11 cairo.c
--- gfx/cairo/cairo/src/cairo.c 10 Feb 2006 02:56:14 -0000 1.11
+++ gfx/cairo/cairo/src/cairo.c 21 Feb 2006 23:17:34 -0000
@@ -2575,24 +2575,63 @@ cairo_get_group_target (cairo_t *cr)
* with it.
**/
cairo_path_t *
cairo_copy_path (cairo_t *cr)
{
if (cr->status)
return (cairo_path_t*) &_cairo_path_nil;
return _cairo_path_data_create (&cr->path, cr->gstate);
}
/**
+ * cairo_has_clip
+ * @cr: a cairo context
+ *
+ * Returns TRUE if the cairo context has any clipping active, otherwise
+ * FALSE.
+ */
+cairo_bool_t
+cairo_has_clip (cairo_t *cr)
+{
+ if (cr->status)
+ return FALSE;
+ return _cairo_gstate_has_clip (cr->gstate);
+}
+
+/**
+ * cairo_extract_clip_rectangles
+ * @cr: a cairo context
+ * @max_rectangles: the maximum number of rectangles to be returned
+ * @rectangles_out: the output buffer for the rectangles
+ * @num_rectangles_out: the number of rectangles returned
+ *
+ * If the current clip can be expressed as the union of at most
+ * 'max_rectangles' device-coordinate rectangles, then we fill in the array
+ * with the rectangles, and return True. Otherwise we return False. When there
+ * is no clipping active, we return False.
+ */
+cairo_bool_t
+cairo_extract_clip_rectangles (cairo_t *cr,
+ int max_rectangles,
+ cairo_clip_rect_t *rectangles_out,
+ int *num_rectangles_out)
+{
+ if (cr->status)
+ return FALSE;
+ return _cairo_gstate_extract_clip_rectangles (cr->gstate, max_rectangles,
+ rectangles_out, num_rectangles_out);
+}
+
+/**
* cairo_copy_path_flat:
* @cr: a cairo context
*
* Gets a flattened copy of the current path and returns it to the
* user as a #cairo_path_t. See #cairo_path_data_t for hints on
* how to iterate over the returned data structure.
*
* This function is like cairo_copy_path() except that any curves
* in the path will be approximated with piecewise-linear
* approximations, (accurate to within the current tolerance
* value). That is, the result is guaranteed to not have any elements
* of type %CAIRO_PATH_CURVE_TO which will instead be replaced by a