[gtk/wip/matthiasc/lottie-stroke: 21/24] path: Add debugging output




commit 8c0d96a1547146d7655bf2e14861383eb65c245d
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Nov 29 12:59:57 2020 -0500

    path: Add debugging output
    
    When in a debugger, you printf. When in a stroker, ... you lineto.
    
    With this compiled in, you can now set the STROKE_DEBUG
    environment variable to show various parts of the stroking
    machinery scaffolding in the output.

 gsk/gskpath.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 105 insertions(+)
---
diff --git a/gsk/gskpath.c b/gsk/gskpath.c
index 0169c81589..aa61da0a03 100644
--- a/gsk/gskpath.c
+++ b/gsk/gskpath.c
@@ -26,6 +26,8 @@
 
 #include "gskstrokeprivate.h"
 
+#include "gdk/gdk-private.h"
+
 /**
  * SECTION:gskpath
  * @Title: Path
@@ -3625,6 +3627,105 @@ contour_to_ops (GskContour *contour,
   return g_list_reverse (data.ops);
 }
 
+#define STROKE_DEBUG 1
+
+#ifdef STROKE_DEBUG
+enum {
+  STROKE_DEBUG_LEFT_CURVES         = 1 << 0,
+  STROKE_DEBUG_RIGHT_CURVES        = 1 << 1,
+  STROKE_DEBUG_LEFT_POINTS         = 1 << 2,
+  STROKE_DEBUG_RIGHT_POINTS        = 1 << 3,
+  STROKE_DEBUG_OFFSET_LINES        = 1 << 4,
+  STROKE_DEBUG_LEFT_INTERSECTIONS  = 1 << 5,
+  STROKE_DEBUG_RIGHT_INTERSECTIONS = 1 << 6,
+  STROKE_DEBUG_CURVE_POINTS        = 1 << 7,
+  STROKE_DEBUG_CURVE_LINES         = 1 << 8
+};
+
+static void
+emit_debug (GskPathBuilder *builder,
+            GList          *ops)
+{
+  GList *l;
+  PathOpData *op;
+  int i;
+  const GdkDebugKey debug_keys[] = {
+    { "left-curves", STROKE_DEBUG_LEFT_CURVES, "Show left offset curve" },
+    { "right-curves", STROKE_DEBUG_RIGHT_CURVES, "Show right offset curve" },
+    { "offset-curves", STROKE_DEBUG_LEFT_CURVES|STROKE_DEBUG_RIGHT_CURVES, "Show offset curves" },
+    { "left-points", STROKE_DEBUG_LEFT_POINTS, "Show left offset points" },
+    { "right-points", STROKE_DEBUG_RIGHT_POINTS, "Show right offset points" },
+    { "offset-points", STROKE_DEBUG_LEFT_POINTS|STROKE_DEBUG_RIGHT_POINTS, "Show offset points" },
+    { "offset-lines", STROKE_DEBUG_OFFSET_LINES, "Show offset lines" },
+    { "left-intersections", STROKE_DEBUG_LEFT_INTERSECTIONS, "Show left intersection" },
+    { "right-intersections", STROKE_DEBUG_RIGHT_INTERSECTIONS, "Show right intersections" },
+    { "intersections", STROKE_DEBUG_LEFT_INTERSECTIONS|STROKE_DEBUG_RIGHT_INTERSECTIONS, "Show intersection" 
},
+    { "curve-points", STROKE_DEBUG_CURVE_POINTS, "Show curve points" },
+    { "curve-lines", STROKE_DEBUG_CURVE_LINES, "Show curve lines" },
+  };
+  static guint debug;
+  static int initialized = 0;
+
+  if (!initialized)
+    {
+      debug = gdk_parse_debug_var ("STROKE_DEBUG", debug_keys, G_N_ELEMENTS (debug_keys));
+      initialized = 1;
+    }
+
+  for (l = ops; l; l = l->next)
+    {
+      op = l->data;
+
+      if (debug & STROKE_DEBUG_LEFT_CURVES)
+        {
+          gsk_path_builder_move_to (builder, op->l[0].x, op->l[0].y);
+          gsk_path_builder_curve_to (builder,
+                                     op->l[1].x, op->l[1].y,
+                                     op->l[2].x, op->l[2].y,
+                                     op->l[3].x, op->l[3].y);
+        }
+      if (debug & STROKE_DEBUG_RIGHT_CURVES)
+        {
+          gsk_path_builder_move_to (builder, op->r[0].x, op->r[0].y);
+          gsk_path_builder_curve_to (builder,
+                                     op->r[1].x, op->r[1].y,
+                                     op->r[2].x, op->r[2].y,
+                                     op->r[3].x, op->r[3].y);
+        }
+
+      for (i = 0; i < op->n_pts; i++)
+        {
+          if (debug & STROKE_DEBUG_LEFT_POINTS)
+            gsk_path_builder_add_circle (builder, &GRAPHENE_POINT_INIT (op->l[i].x, op->l[i].y), 2);
+          if (debug & STROKE_DEBUG_RIGHT_POINTS)
+            gsk_path_builder_add_circle (builder, &GRAPHENE_POINT_INIT (op->r[i].x, op->r[i].y), 2);
+          if (debug & STROKE_DEBUG_CURVE_POINTS)
+            gsk_path_builder_add_circle (builder, &GRAPHENE_POINT_INIT (op->pts[i].x, op->pts[i].y), 2);
+          if (debug & STROKE_DEBUG_OFFSET_LINES)
+            {
+              gsk_path_builder_move_to (builder, op->r[i].x, op->r[i].y);
+              gsk_path_builder_line_to (builder, op->pts[i].x, op->pts[i].y);
+              gsk_path_builder_line_to (builder, op->l[i].x, op->l[i].y);
+            }
+       }
+      for (i = 0; i < 1; i++)
+        {
+          if (debug & STROKE_DEBUG_LEFT_INTERSECTIONS)
+            gsk_path_builder_add_circle (builder, &GRAPHENE_POINT_INIT (op->le[i].x, op->le[i].y), 2);
+          if (debug & STROKE_DEBUG_RIGHT_INTERSECTIONS)
+            gsk_path_builder_add_circle (builder, &GRAPHENE_POINT_INIT (op->re[i].x, op->re[i].y), 2);
+        }
+
+      if (debug & STROKE_DEBUG_CURVE_LINES)
+        {
+          gsk_path_builder_move_to (builder, op->pts[0].x, op->pts[0].y);
+          for (i = 1; i < op->n_pts; i++)
+            gsk_path_builder_line_to (builder, op->pts[i].x, op->pts[i].y);
+        }
+    }
+}
+#endif
+
 static void
 gsk_contour_to_stroke (GskContour     *contour,
                        GskStroke      *stroke,
@@ -3948,6 +4049,10 @@ gsk_contour_to_stroke (GskContour     *contour,
 
   gsk_path_builder_close (builder);
 
+#ifdef STROKE_DEBUG
+  emit_debug (builder, ops);
+#endif
+
   g_list_free_full (ops, g_free);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]