gl-renderer: Remove support for non-quad polygons from clipper

The added complexity is unnecessary, it is limited to polygons of
length less than or equal to 8, there is currently no use for that
feature nor any plans to use it and tests are non-existent.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
This commit is contained in:
Loïc Molinari 2024-04-15 15:34:47 +02:00 committed by Marius Vlad
parent 5e43ef81ae
commit bef1f5fd7d
3 changed files with 11 additions and 33 deletions

View File

@ -295,8 +295,7 @@ clip_polygon_bottom(struct clip_context *ctx, const struct polygon8 *src,
* https://www.codeguru.com/cplusplus/polygon-clipping/ * https://www.codeguru.com/cplusplus/polygon-clipping/
*/ */
WESTON_EXPORT_FOR_TESTS int WESTON_EXPORT_FOR_TESTS int
clipper_clip(const struct clipper_vertex *polygon, clipper_clip(const struct clipper_vertex polygon[4],
size_t polygon_len,
const struct clipper_vertex box[2], const struct clipper_vertex box[2],
struct clipper_vertex *restrict vertices) struct clipper_vertex *restrict vertices)
{ {
@ -304,12 +303,9 @@ clipper_clip(const struct clipper_vertex *polygon,
struct polygon8 p, tmp; struct polygon8 p, tmp;
int i, n; int i, n;
if (polygon_len > 8)
return -1;
memcpy(ctx.box, box, 2 * sizeof *box); memcpy(ctx.box, box, 2 * sizeof *box);
memcpy(p.pos, polygon, polygon_len * sizeof *polygon); memcpy(p.pos, polygon, 4 * sizeof *polygon);
p.n = polygon_len; p.n = 4;
tmp.n = clip_polygon_left(&ctx, &p, tmp.pos); tmp.n = clip_polygon_left(&ctx, &p, tmp.pos);
p.n = clip_polygon_right(&ctx, &tmp, p.pos); p.n = clip_polygon_right(&ctx, &tmp, p.pos);
tmp.n = clip_polygon_top(&ctx, &p, tmp.pos); tmp.n = clip_polygon_top(&ctx, &p, tmp.pos);
@ -390,7 +386,7 @@ clipper_quad_clip(struct clipper_quad *quad,
/* Then use our general purpose clipping algorithm: /* Then use our general purpose clipping algorithm:
*/ */
n = clipper_clip(quad->polygon, 4, box, vertices); n = clipper_clip(quad->polygon, box, vertices);
if (n < 3) if (n < 3)
return 0; return 0;

View File

@ -42,15 +42,14 @@ struct clipper_quad {
/* /*
* General purpose clipping function. Compute the boundary vertices of the * General purpose clipping function. Compute the boundary vertices of the
* intersection of a 'polygon' and a clipping 'box'. 'polygon' points to an * intersection of a 'polygon' and a clipping 'box'. 'polygon' points to an
* array of 'polygon_len' vertices, less than or equal to 8, defining a convex * array of 4 vertices defining a convex polygon of any winding order. 'box'
* polygon of any winding order. 'box' points to an array of 2 vertices where * points to an array of 2 vertices where the values of the 1st vertex are less
* the values of the 1st vertex are less than or equal to the values of the 2nd * than or equal to the values of the 2nd vertex. Up to 8 resulting vertices,
* vertex. Up to 16 resulting vertices, using 'polygon' winding order, are * using 'polygon' winding order, are written to 'vertices'. The return value is
* written to 'vertices'. The return value is the number of vertices created. * the number of vertices created.
*/ */
int int
clipper_clip(const struct clipper_vertex *polygon, clipper_clip(const struct clipper_vertex polygon[4],
size_t polygon_len,
const struct clipper_vertex box[2], const struct clipper_vertex box[2],
struct clipper_vertex *restrict vertices); struct clipper_vertex *restrict vertices);

View File

@ -44,7 +44,6 @@ struct vertex_clip_test_data {
}; };
struct clipper_vertex polygon[8]; struct clipper_vertex polygon[8];
struct clipper_vertex clipped[8]; struct clipper_vertex clipped[8];
int polygon_n;
int clipped_n; int clipped_n;
bool aligned; bool aligned;
}; };
@ -86,7 +85,6 @@ static const struct vertex_clip_test_data clip_expected_data[] = {
.box = BOX (50.0f, 50.0f, 100.0f, 100.0f), .box = BOX (50.0f, 50.0f, 100.0f, 100.0f),
.polygon = QUAD(51.0f, 51.0f, 99.0f, 99.0f), .polygon = QUAD(51.0f, 51.0f, 99.0f, 99.0f),
.clipped = QUAD(51.0f, 51.0f, 99.0f, 99.0f), .clipped = QUAD(51.0f, 51.0f, 99.0f, 99.0f),
.polygon_n = 4,
.clipped_n = 4, .clipped_n = 4,
}, },
@ -95,7 +93,6 @@ static const struct vertex_clip_test_data clip_expected_data[] = {
.box = BOX (50.0f, 50.0f, 100.0f, 100.0f), .box = BOX (50.0f, 50.0f, 100.0f, 100.0f),
.polygon = QUAD(51.0f, 51.0f, 99.0f, 101.0f), .polygon = QUAD(51.0f, 51.0f, 99.0f, 101.0f),
.clipped = QUAD(51.0f, 51.0f, 99.0f, 100.0f), .clipped = QUAD(51.0f, 51.0f, 99.0f, 100.0f),
.polygon_n = 4,
.clipped_n = 4, .clipped_n = 4,
}, },
@ -104,7 +101,6 @@ static const struct vertex_clip_test_data clip_expected_data[] = {
.box = BOX (50.0f, 50.0f, 100.0f, 100.0f), .box = BOX (50.0f, 50.0f, 100.0f, 100.0f),
.polygon = QUAD(51.0f, 49.0f, 99.0f, 99.0f), .polygon = QUAD(51.0f, 49.0f, 99.0f, 99.0f),
.clipped = QUAD(51.0f, 50.0f, 99.0f, 99.0f), .clipped = QUAD(51.0f, 50.0f, 99.0f, 99.0f),
.polygon_n = 4,
.clipped_n = 4, .clipped_n = 4,
}, },
@ -113,7 +109,6 @@ static const struct vertex_clip_test_data clip_expected_data[] = {
.box = BOX (50.0f, 50.0f, 100.0f, 100.0f), .box = BOX (50.0f, 50.0f, 100.0f, 100.0f),
.polygon = QUAD(49.0f, 51.0f, 99.0f, 99.0f), .polygon = QUAD(49.0f, 51.0f, 99.0f, 99.0f),
.clipped = QUAD(50.0f, 51.0f, 99.0f, 99.0f), .clipped = QUAD(50.0f, 51.0f, 99.0f, 99.0f),
.polygon_n = 4,
.clipped_n = 4, .clipped_n = 4,
}, },
@ -122,7 +117,6 @@ static const struct vertex_clip_test_data clip_expected_data[] = {
.box = BOX (50.0f, 50.0f, 100.0f, 100.0f), .box = BOX (50.0f, 50.0f, 100.0f, 100.0f),
.polygon = QUAD(51.0f, 51.0f, 101.0f, 99.0f), .polygon = QUAD(51.0f, 51.0f, 101.0f, 99.0f),
.clipped = QUAD(51.0f, 51.0f, 100.0f, 99.0f), .clipped = QUAD(51.0f, 51.0f, 100.0f, 99.0f),
.polygon_n = 4,
.clipped_n = 4, .clipped_n = 4,
}, },
@ -132,7 +126,6 @@ static const struct vertex_clip_test_data clip_expected_data[] = {
.polygon = {{ 25.0f, 75.0f}, {75.0f, 25.0f}, .polygon = {{ 25.0f, 75.0f}, {75.0f, 25.0f},
{125.0f, 75.0f}, {75.0f, 125.0f}}, {125.0f, 75.0f}, {75.0f, 125.0f}},
.clipped = QUAD(50.0f, 50.0f, 100.0f, 100.0f), .clipped = QUAD(50.0f, 50.0f, 100.0f, 100.0f),
.polygon_n = 4,
.clipped_n = 4, .clipped_n = 4,
}, },
@ -145,7 +138,6 @@ static const struct vertex_clip_test_data clip_expected_data[] = {
{100.0f, 62.5f}, {100.0f, 87.5f}, {100.0f, 62.5f}, {100.0f, 87.5f},
{ 87.5f, 100.0f}, { 62.5f, 100.0f}, { 87.5f, 100.0f}, { 62.5f, 100.0f},
{ 50.0f, 87.5f}, { 50.0f, 62.5f}}, { 50.0f, 87.5f}, { 50.0f, 62.5f}},
.polygon_n = 4,
.clipped_n = 8, .clipped_n = 8,
}, },
@ -158,7 +150,6 @@ static const struct vertex_clip_test_data clip_expected_data[] = {
{ 50.0f, 87.5f}, { 62.5f, 100.0f}, { 50.0f, 87.5f}, { 62.5f, 100.0f},
{ 87.5f, 100.0f}, {100.0f, 87.5f}, { 87.5f, 100.0f}, {100.0f, 87.5f},
{100.0f, 62.5f}, { 87.5f, 50.0f}}, {100.0f, 62.5f}, { 87.5f, 50.0f}},
.polygon_n = 4,
.clipped_n = 8, .clipped_n = 8,
}, },
}; };
@ -169,19 +160,11 @@ TEST_P(clip_expected, clip_expected_data)
struct clipper_vertex clipped[8]; struct clipper_vertex clipped[8];
int clipped_n; int clipped_n;
clipped_n = clipper_clip(tdata->polygon, tdata->polygon_n, tdata->box, clipped_n = clipper_clip(tdata->polygon, tdata->box, clipped);
clipped);
assert_vertices(clipped, clipped_n, tdata->clipped, tdata->clipped_n); assert_vertices(clipped, clipped_n, tdata->clipped, tdata->clipped_n);
} }
TEST(clip_size_too_high)
{
struct clipper_vertex polygon[8] = {}, box[2] = {};
assert(clipper_clip(polygon, 9, box, NULL) == -1);
}
/* clipper_quad_clip() tests: */ /* clipper_quad_clip() tests: */
static const struct vertex_clip_test_data quad_clip_expected_data[] = { static const struct vertex_clip_test_data quad_clip_expected_data[] = {