GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: gx_canvas_polygon_draw.c Lines: 34 34 100.0 %
Date: 2026-03-06 19:21:09 Branches: 20 20 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
10
 **************************************************************************/
11
12
13
/**************************************************************************/
14
/**************************************************************************/
15
/**                                                                       */
16
/** GUIX Component                                                        */
17
/**                                                                       */
18
/**   Canvas Management (Canvas)                                          */
19
/**                                                                       */
20
/**************************************************************************/
21
22
#define GX_SOURCE_CODE
23
24
25
/* Include necessary system files.  */
26
27
#include "gx_api.h"
28
#include "gx_system.h"
29
#include "gx_utility.h"
30
#include "gx_display.h"
31
#include "gx_canvas.h"
32
33
34
/**************************************************************************/
35
/*                                                                        */
36
/*  FUNCTION                                               RELEASE        */
37
/*                                                                        */
38
/*    _gx_canvas_polygon_draw                             PORTABLE C      */
39
/*                                                           6.1          */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    Kenneth Maxwell, Microsoft Corporation                              */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This draws a polygon into the current context.                      */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    point_array                           Array of points of the polygon*/
51
/*                                            terminated by NULL entry.   */
52
/*    number_of_points                      Number of points of polygon   */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    status                                Completion status             */
57
/*                                                                        */
58
/*  CALLS                                                                 */
59
/*                                                                        */
60
/*    _gx_utility_rectangle_define          Define a rectangle            */
61
/*    _gx_utility_rectangle_overlap_detect  Detect rectangle overlap      */
62
/*    [gx_display_driver_polygon_draw]      The display driver basic      */
63
/*                                            polygon drawing routine     */
64
/*    [gx_display_driver_polygon_fill]      The display driver basic      */
65
/*                                            polygon drawing routine     */
66
/*                                                                        */
67
/*  CALLED BY                                                             */
68
/*                                                                        */
69
/*    Application Code                                                    */
70
/*                                                                        */
71
/**************************************************************************/
72
1446
UINT  _gx_canvas_polygon_draw(GX_POINT *point_array, INT number_of_points)
73
{
74
GX_DRAW_CONTEXT *context;
75
GX_DISPLAY      *display;
76
GX_RECTANGLE     bound;
77
GX_VIEW         *view;
78
GX_RECTANGLE     clip_rect;
79
INT              i;
80
1446
GX_VALUE         left = point_array[0].gx_point_x;
81
1446
GX_VALUE         right = point_array[0].gx_point_x;
82
1446
GX_VALUE         top = point_array[0].gx_point_y;
83
1446
GX_VALUE         bottom = point_array[0].gx_point_y;
84
GX_VALUE         width;
85
86
    /* Calculate the minumum bounding rectangle. */
87
9214
    for (i = 1; i < number_of_points; i++)
88
    {
89
7768
        if (point_array[i].gx_point_x < left)
90
        {
91
294
            left = point_array[i].gx_point_x;
92
        }
93
7768
        if (point_array[i].gx_point_x > right)
94
        {
95
3177
            right = point_array[i].gx_point_x;
96
        }
97
7768
        if (point_array[i].gx_point_y < top)
98
        {
99
591
            top = point_array[i].gx_point_y;
100
        }
101
7768
        if (point_array[i].gx_point_y > bottom)
102
        {
103
1909
            bottom = point_array[i].gx_point_y;
104
        }
105
    }
106
107
    /* pick up the current drawing context */
108
1446
    context = _gx_system_current_draw_context;
109
110
1446
    width = (GX_VALUE)((context -> gx_draw_context_brush.gx_brush_width + 1) >> 1);
111
112
1446
    _gx_utility_rectangle_define(&bound, (GX_VALUE)(left - width), (GX_VALUE)(top - width), (GX_VALUE)(right + width), (GX_VALUE)(bottom + width));
113
114
    /* clip the polygon bounding box to the dirty rectangle */
115
1446
    if (!_gx_utility_rectangle_overlap_detect(&bound, &context -> gx_draw_context_dirty, &bound))
116
    {
117
        /* nothing to draw, return */
118
22
        return GX_SUCCESS;
119
    }
120
121
    /* pick up current display driver */
122
1424
    display = context -> gx_draw_context_display;
123
124
    /* test to determine if the bounding rectangle overlaps the region we are allowed to draw
125
       into. For each view that overlaps the bounding rectangle, do some drawing.
126
     */
127
1424
    view = context -> gx_draw_context_view_head;
128
129
2863
    while (view)
130
    {
131
1439
        if (!_gx_utility_rectangle_overlap_detect(&view -> gx_view_rectangle, &bound, &clip_rect))
132
        {
133
16
            view = view -> gx_view_next;
134
16
            continue;
135
        }
136
137
        /* we have a view into which we can draw the polygon, do it */
138
1423
        GX_RECTANGLE *original_clip = context->gx_draw_context_clip;
139
1423
        context -> gx_draw_context_clip = &clip_rect;
140
141
1423
        if (context -> gx_draw_context_brush.gx_brush_style & (GX_BRUSH_SOLID_FILL | GX_BRUSH_PIXELMAP_FILL))
142
        {
143
1363
            display -> gx_display_driver_polygon_fill(context, point_array, number_of_points);
144
        }
145
146
1423
        if (display -> gx_display_driver_polygon_draw)
147
        {
148
            /* Draw polygon. */
149
1418
            display -> gx_display_driver_polygon_draw(context, point_array, number_of_points);
150
        }
151
152
1423
        view = view -> gx_view_next;
153
1423
        context -> gx_draw_context_clip = original_clip;
154
155
    }
156
157
    /* Return successful completion.  */
158
1424
    return(GX_SUCCESS);
159
}
160