[gtk/wip/matthiasc/lottie-stroke: 4/9] Special-case rects for strokes




commit 580feec7b85aec5e8fc621adbe316efce697eb0b
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Dec 5 14:20:17 2020 -0500

    Special-case rects for strokes
    
    In many cases, the outline of a rectangle is just
    two rectangles.

 gsk/gskcontour.c | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)
---
diff --git a/gsk/gskcontour.c b/gsk/gskcontour.c
index dd665d9c51..0b6116802e 100644
--- a/gsk/gskcontour.c
+++ b/gsk/gskcontour.c
@@ -24,6 +24,7 @@
 #include "gskpathbuilder.h"
 #include "gskpathprivate.h"
 #include "gsksplineprivate.h"
+#include "gskstrokeprivate.h"
 
 typedef struct _GskContourClass GskContourClass;
 
@@ -471,12 +472,43 @@ gsk_rect_contour_get_winding (const GskContour       *contour,
   return 0;
 }
 
+static gboolean
+stroke_is_simple (GskStroke *stroke)
+{
+  if (stroke->line_join != GSK_LINE_JOIN_MITER &&
+      stroke->line_join != GSK_LINE_JOIN_MITER_CLIP)
+    return FALSE;
+
+  if (stroke->miter_limit < 1.5)
+    return FALSE;
+
+  if (stroke->n_dash != 0)
+    return FALSE;
+
+  return TRUE;
+}
+
 static void
 gsk_rect_contour_add_stroke (const GskContour *contour,
                              GskPathBuilder   *builder,
                              GskStroke        *stroke)
 {
-  gsk_contour_default_add_stroke (contour, builder, stroke);
+  const GskRectContour *self = (const GskRectContour *) contour;
+
+  if (stroke_is_simple (stroke))
+    {
+      graphene_rect_t rect;
+
+      graphene_rect_init (&rect, self->x, self->y, self->width, self->height);
+
+      graphene_rect_inset (&rect, stroke->line_width / 2, stroke->line_width / 2);
+      gsk_path_builder_add_rect (builder, &rect);
+
+      graphene_rect_inset (&rect, - stroke->line_width, - stroke->line_width);
+      rect.origin.x += rect.size.width;
+      rect.size.width = - rect.size.width;
+      gsk_path_builder_add_rect (builder, &rect);
+    }
 }
 
 static const GskContourClass GSK_RECT_CONTOUR_CLASS =


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