gecko-dev/gfx/cairo/cairo-debug-helpers.patch

246 lines
7.6 KiB
Diff

Index: src/cairo-debug.c
===================================================================
--- src/cairo-debug.c.orig
+++ src/cairo-debug.c
@@ -35,6 +35,8 @@
#include "cairoint.h"
+#include "cairo-clip-private.h"
+
/**
* cairo_debug_reset_static_data:
*
@@ -70,3 +72,192 @@ cairo_debug_reset_static_data (void)
#endif
}
+/*
+ * clip dumper
+ */
+void
+cairo_debug_dump_clip (struct _cairo_clip *clip,
+ FILE *fp)
+{
+ fprintf (fp, "clip %p: %s ", (clip->mode == CAIRO_CLIP_MODE_PATH ? "PATH" :
+ clip->mode == CAIRO_CLIP_MODE_REGION ? "REGION" :
+ clip->mode == CAIRO_CLIP_MODE_MASK ? "MASK" :
+ "INVALID?!"));
+ if (clip->mode == CAIRO_CLIP_MODE_PATH) {
+ fprintf (fp, "\n=== clip path ===\n");
+ } else if (clip->mode == CAIRO_CLIP_MODE_REGION) {
+ if (!clip->region) {
+ fprintf (fp, "region = NULL");
+ } else if (pixman_region_num_rects (clip->region) == 1) {
+ pixman_box16_t *rects = pixman_region_rects (clip->region);
+ fprintf (fp, "region [%d %d %d %d]",
+ rects[0].x1, rects[0].y1,
+ rects[0].x2, rects[0].y2);
+ } else {
+ pixman_box16_t *rects = pixman_region_rects (clip->region);
+ int i, nr = pixman_region_num_rects(clip->region);
+ fprintf (fp, "region (%d rects)\n", nr);
+ for (i = 0; i < nr; i++) {
+ fprintf (fp, "rect %d: [%d %d %d %d]", i,
+ rects[nr].x1, rects[nr].y1,
+ rects[nr].x2, rects[nr].y2);
+ }
+ }
+ } else if (clip->mode == CAIRO_CLIP_MODE_MASK) {
+ fprintf (fp, "mask, surface: %p rect: [%d %d %d %d]", clip->surface,
+ clip->surface_rect.x, clip->surface_rect.y, clip->surface_rect.width, clip->surface_rect.height);
+ }
+
+ fprintf (fp, "\n");
+}
+
+/*
+ * path dumper
+ */
+
+typedef struct _cairo_debug_path_dump_closure {
+ unsigned int op_count;
+ FILE *fp;
+} cairo_debug_path_dump_closure_t;
+
+static cairo_status_t
+_cairo_debug_path_move_to (void *closure,
+ cairo_point_t *point)
+{
+ cairo_debug_path_dump_closure_t *fdc =
+ (cairo_debug_path_dump_closure_t*) closure;
+ fprintf (fdc->fp, "%d: moveto (%f, %f)\n",
+ fdc->op_count++,
+ _cairo_fixed_to_double(point->x),
+ _cairo_fixed_to_double(point->y));
+ return CAIRO_STATUS_SUCCESS;
+}
+
+static cairo_status_t
+_cairo_debug_path_line_to (void *closure,
+ cairo_point_t *point)
+{
+ cairo_debug_path_dump_closure_t *fdc =
+ (cairo_debug_path_dump_closure_t*) closure;
+ fprintf (fdc->fp, "%d: lineto (%f, %f)\n",
+ fdc->op_count++,
+ _cairo_fixed_to_double(point->x),
+ _cairo_fixed_to_double(point->y));
+ return CAIRO_STATUS_SUCCESS;
+}
+
+static cairo_status_t
+_cairo_debug_path_curve_to (void *closure,
+ cairo_point_t *p0,
+ cairo_point_t *p1,
+ cairo_point_t *p2)
+{
+ cairo_debug_path_dump_closure_t *fdc =
+ (cairo_debug_path_dump_closure_t*) closure;
+ fprintf (fdc->fp, "%d: curveto (%f, %f) (%f, %f) (%f, %f)\n",
+ fdc->op_count++,
+ _cairo_fixed_to_double(p0->x),
+ _cairo_fixed_to_double(p0->y),
+ _cairo_fixed_to_double(p1->x),
+ _cairo_fixed_to_double(p1->y),
+ _cairo_fixed_to_double(p2->x),
+ _cairo_fixed_to_double(p2->y));
+ return CAIRO_STATUS_SUCCESS;
+}
+
+static cairo_status_t
+_cairo_debug_path_close_path (void *closure)
+{
+ cairo_debug_path_dump_closure_t *fdc =
+ (cairo_debug_path_dump_closure_t*) closure;
+ fprintf (fdc->fp, "%d: close\n",
+ fdc->op_count++);
+ return CAIRO_STATUS_SUCCESS;
+}
+
+/**
+ * cairo_debug_dump_path
+ * @path: a #cairo_path_fixed_t
+ * @fp: the file pointer where to dump the given path
+ *
+ * Dumps @path in human-readable form to @fp.
+ */
+void
+cairo_debug_dump_path (cairo_path_fixed_t *path,
+ FILE *fp)
+{
+ cairo_debug_path_dump_closure_t fdc;
+ fdc.fp = fp;
+ fdc.op_count = 0;
+
+ fprintf (fp, "=== path %p ===\n", path);
+ _cairo_path_fixed_interpret (path,
+ CAIRO_DIRECTION_FORWARD,
+ _cairo_debug_path_move_to,
+ _cairo_debug_path_line_to,
+ _cairo_debug_path_curve_to,
+ _cairo_debug_path_close_path,
+ &fdc);
+ fprintf (fp, "======================\n");
+}
+
+/*
+ * traps dumping
+ */
+
+/**
+ * cairo_debug_dump_traps
+ * @traps: a #cairo_traps_t
+ * @fp: the file pointer where to dump the traps
+ *
+ * Dumps @traps in human-readable form to @fp.
+ */
+void
+cairo_debug_dump_traps (cairo_traps_t *traps,
+ FILE *fp)
+{
+ fprintf (fp, "=== traps %p ===\n", traps);
+ fprintf (fp, "extents: (%f, %f) (%f, %f)\n",
+ _cairo_fixed_to_double (traps->extents.p1.x),
+ _cairo_fixed_to_double (traps->extents.p1.y),
+ _cairo_fixed_to_double (traps->extents.p2.x),
+ _cairo_fixed_to_double (traps->extents.p2.y));
+
+ cairo_debug_dump_trapezoid_array (traps->traps,
+ traps->num_traps,
+ fp);
+
+ fprintf (fp, "=======================\n");
+}
+
+/**
+ * cairo_debug_dump_trapezoid_array
+ * @traps: a #cairo_trapezoid_t pointer
+ * @num_traps: the number of trapezoids in @traps
+ * @fp: the file pointer where to dump the traps
+ *
+ * Dumps num_traps in the @traps array in human-readable form to @fp.
+ */
+void
+cairo_debug_dump_trapezoid_array (cairo_trapezoid_t *traps,
+ int num_traps,
+ FILE *fp)
+{
+ int i;
+
+ for (i = 0; i < num_traps; i++) {
+ fprintf (fp, "% 3d: t: %f b: %f l: (%f,%f)->(%f,%f) r: (%f,%f)->(%f,%f)\n",
+ i,
+ _cairo_fixed_to_double (traps[i].top),
+ _cairo_fixed_to_double (traps[i].bottom),
+ _cairo_fixed_to_double (traps[i].left.p1.x),
+ _cairo_fixed_to_double (traps[i].left.p1.y),
+ _cairo_fixed_to_double (traps[i].left.p2.x),
+ _cairo_fixed_to_double (traps[i].left.p2.y),
+ _cairo_fixed_to_double (traps[i].right.p1.x),
+ _cairo_fixed_to_double (traps[i].right.p1.y),
+ _cairo_fixed_to_double (traps[i].right.p2.x),
+ _cairo_fixed_to_double (traps[i].right.p2.y));
+ }
+}
+
Index: src/cairo-debug.h
===================================================================
--- src/cairo-debug.h.orig
+++ src/cairo-debug.h
@@ -37,12 +37,34 @@
#define CAIRO_DEBUG_H
#include <cairo-features.h>
+#include <stdio.h>
CAIRO_BEGIN_DECLS
+struct _cairo_path_fixed;
+struct _cairo_traps;
+struct _cairo_trapezoid;
+struct _cairo_clip;
+
void
cairo_debug_reset_static_data (void);
+void
+cairo_debug_dump_clip (struct _cairo_clip *clip,
+ FILE *fp);
+void
+cairo_debug_dump_path (struct _cairo_path_fixed *path,
+ FILE *fp);
+
+void
+cairo_debug_dump_traps (struct _cairo_traps *traps,
+ FILE *fp);
+
+void
+cairo_debug_dump_trapezoid_array (struct _cairo_trapezoid *traps,
+ int num_traps,
+ FILE *fp);
+
CAIRO_END_DECLS
#endif /* CAIRO_H */