File 0005-d2d1-Refactor-outline-generation-as-preparation-for-.patch of Package wine

From 28b9eb070ae352ae04a08adfcbaf9ed5530d09b3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Br=C3=BCns?= <stefan.bruens@rwth-aachen.de>
Date: Wed, 5 Jan 2022 02:12:28 +0100
Subject: [PATCH 05/10] d2d1: Refactor outline generation as preparation for
 new TYPE_END vertex
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This is a preparative patch for the next change, behavior is essentially
unchanged, though it may be slightly faster.

Rearrange code for outline segment and join generation so it
will work for END_OPEN/END_CLOSED path, with coincident and disparate
last/first vertex.

Each vertex is now fetched once, and pivoted on the next iteration.
Also move invariants in front of the loop,

Path segments are drawn starting with the first segment, up
to vertex_count - 2 (index of start vertex). Only in case of
a END_CLOSED figure with non-coincident last/first vertex,
also the last line segment is drawn.

Joins are added between all drawn segments, and only for
END_CLOSED also the join at the first vertex is added.

Signed-off-by: Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de>
---
 dlls/d2d1/geometry.c | 97 ++++++++++++++++++++++++--------------------
 1 file changed, 52 insertions(+), 45 deletions(-)

diff --git a/dlls/d2d1/geometry.c b/dlls/d2d1/geometry.c
index a7074899fda..41987771ed4 100644
--- a/dlls/d2d1/geometry.c
+++ b/dlls/d2d1/geometry.c
@@ -2597,43 +2597,69 @@ static BOOL d2d_geometry_outline_add_arc_quadrant(struct d2d_geometry *geometry,
 static BOOL d2d_geometry_add_figure_outline(struct d2d_geometry *geometry,
         struct d2d_figure *figure, D2D1_FIGURE_END figure_end)
 {
-    const D2D1_POINT_2F *prev, *p0, *next;
-    enum d2d_vertex_type prev_type, type;
-    size_t bezier_idx, i;
+    const D2D1_POINT_2F *prev, *p0, *p1, *next, *next_prev;
+    enum d2d_vertex_type type;
+    size_t bezier_idx, i, vertex_count;
+
+    vertex_count = figure->vertex_count;
+    /* An OPEN path needs at least 2 vertices, a CLOSED one
+     * needs at least 1 vertex */
+    if (vertex_count < 2
+            && !(figure_end == D2D1_FIGURE_END_CLOSED && vertex_count >= 1))
+        return TRUE;
+
+    if (figure_end == D2D1_FIGURE_END_OPEN)
+        vertex_count--;
+
+    prev = p0 = &figure->vertices[0];
+    if (figure_end == D2D1_FIGURE_END_CLOSED)
+    {
+        /* In case of a CLOSED path, a join between first and last vertex is required */
+        if (d2d_vertex_type_is_bezier(figure->vertex_types[vertex_count - 1]))
+            prev = &figure->bezier_controls[figure->bezier_control_count - 1];
+        else
+            prev = &figure->vertices[vertex_count - 1];
+    }
 
-    for (i = 0, bezier_idx = 0; i < figure->vertex_count; ++i)
+    for (i = 0, bezier_idx = 0; i < vertex_count; ++i)
     {
         type = figure->vertex_types[i];
         if (type == D2D_VERTEX_TYPE_NONE)
+        {
+            prev = next_prev = &figure->vertices[i];
             continue;
+        }
 
-        p0 = &figure->vertices[i];
-
-        if (!i)
+        /* next: tangent along next segment, at p0
+         * p1: next vertex */
+        if (d2d_vertex_type_is_bezier(type))
         {
-            prev_type = figure->vertex_types[figure->vertex_count - 1];
-            if (d2d_vertex_type_is_bezier(prev_type))
-                prev = &figure->bezier_controls[figure->bezier_control_count - 1];
-            else
-                prev = &figure->vertices[figure->vertex_count - 1];
+            next_prev = next = &figure->bezier_controls[bezier_idx++];
+            /* type BEZIER implies i + 1 < figure->vertex_count */
+            p1 = &figure->vertices[i + 1];
+
+            if (!d2d_geometry_outline_add_bezier_segment(geometry, p0, next, p1))
+            {
+                ERR("Failed to add bezier segment.\n");
+                return FALSE;
+            }
         }
         else
         {
-            prev_type = figure->vertex_types[i - 1];
-            if (d2d_vertex_type_is_bezier(prev_type))
-                prev = &figure->bezier_controls[bezier_idx - 1];
+            if (i + 1 == figure->vertex_count)
+                next = p1 = &figure->vertices[0];
             else
-                prev = &figure->vertices[i - 1];
-        }
+                next = p1 = &figure->vertices[i + 1];
+            next_prev = p0;
 
-        if (d2d_vertex_type_is_bezier(type))
-            next = &figure->bezier_controls[bezier_idx++];
-        else if (i == figure->vertex_count - 1)
-            next = &figure->vertices[0];
-        else
-            next = &figure->vertices[i + 1];
+            if (!d2d_geometry_outline_add_line_segment(geometry, p0, p1))
+            {
+                ERR("Failed to add line segment.\n");
+                return FALSE;
+            }
+        }
 
-        if (figure_end == D2D1_FIGURE_END_CLOSED || (i && i < figure->vertex_count - 1))
+        if (i || figure_end == D2D1_FIGURE_END_CLOSED)
         {
             D2D1_POINT_2F q_next, q_prev;
 
@@ -2650,27 +2676,8 @@ static BOOL d2d_geometry_add_figure_outline(struct d2d_geometry *geometry,
             }
         }
 
-        if (type == D2D_VERTEX_TYPE_LINE && (figure_end == D2D1_FIGURE_END_CLOSED || i < figure->vertex_count - 1)
-                && !d2d_geometry_outline_add_line_segment(geometry, p0, next))
-        {
-            ERR("Failed to add line segment.\n");
-            return FALSE;
-        }
-        else if (d2d_vertex_type_is_bezier(type))
-        {
-            const D2D1_POINT_2F *p2;
-
-            if (i == figure->vertex_count - 1)
-                p2 = &figure->vertices[0];
-            else
-                p2 = &figure->vertices[i + 1];
-
-            if (!d2d_geometry_outline_add_bezier_segment(geometry, p0, next, p2))
-            {
-                ERR("Failed to add bezier segment.\n");
-                return FALSE;
-            }
-        }
+        p0 = p1;
+        prev = next_prev;
     }
 
     return TRUE;
-- 
2.34.1

openSUSE Build Service is sponsored by