gl-renderer: Prefix clipper API
Prefix and slightly rename the clipper structs and funcs: - struct clip_vertex -> struct clipper_vertex - struct gl_quad -> struct clipper_quad - clip_transformed() -> clipper_clip() - init_quad() -> clipper_quad_init() - clip_quad() -> clipper_quad_clip() - clip_quad_box32() -> clipper_quad_clip_box32() - float_difference() -> clipper_float_difference() Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
This commit is contained in:
parent
2d0d0175d2
commit
42205628bf
|
@ -112,7 +112,7 @@ weston_coord_global_to_surface(struct weston_view *view, struct weston_coord_glo
|
|||
|
||||
static void
|
||||
global_to_surface(pixman_box32_t *rect, struct weston_view *ev,
|
||||
struct clip_vertex polygon[4], bool *axis_aligned)
|
||||
struct clipper_vertex polygon[4], bool *axis_aligned)
|
||||
{
|
||||
struct weston_coord_global rect_g[4] = {
|
||||
{ .c = weston_coord(rect->x1, rect->y1) },
|
||||
|
@ -181,7 +181,7 @@ struct cliptest {
|
|||
};
|
||||
|
||||
static void
|
||||
draw_polygon_closed(cairo_t *cr, struct clip_vertex *pos, int n)
|
||||
draw_polygon_closed(cairo_t *cr, struct clipper_vertex *pos, int n)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -192,7 +192,7 @@ draw_polygon_closed(cairo_t *cr, struct clip_vertex *pos, int n)
|
|||
}
|
||||
|
||||
static void
|
||||
draw_polygon_labels(cairo_t *cr, struct clip_vertex *pos, int n)
|
||||
draw_polygon_labels(cairo_t *cr, struct clipper_vertex *pos, int n)
|
||||
{
|
||||
char str[16];
|
||||
int i;
|
||||
|
@ -205,7 +205,7 @@ draw_polygon_labels(cairo_t *cr, struct clip_vertex *pos, int n)
|
|||
}
|
||||
|
||||
static void
|
||||
draw_coordinates(cairo_t *cr, double ox, double oy, struct clip_vertex *pos, int n)
|
||||
draw_coordinates(cairo_t *cr, double ox, double oy, struct clipper_vertex *pos, int n)
|
||||
{
|
||||
char str[64];
|
||||
int i;
|
||||
|
@ -222,7 +222,7 @@ draw_coordinates(cairo_t *cr, double ox, double oy, struct clip_vertex *pos, int
|
|||
static void
|
||||
draw_box(cairo_t *cr, pixman_box32_t *box, struct weston_view *view)
|
||||
{
|
||||
struct clip_vertex pos[4];
|
||||
struct clipper_vertex pos[4];
|
||||
|
||||
if (view) {
|
||||
weston_view_from_global_float(view, box->x1, box->y1, &pos[0].x, &pos[0].y);
|
||||
|
@ -241,7 +241,7 @@ draw_box(cairo_t *cr, pixman_box32_t *box, struct weston_view *view)
|
|||
|
||||
static void
|
||||
draw_geometry(cairo_t *cr, struct weston_view *view,
|
||||
struct clip_vertex *v, int n)
|
||||
struct clipper_vertex *v, int n)
|
||||
{
|
||||
struct geometry *g = view->geometry;
|
||||
float cx, cy;
|
||||
|
@ -277,15 +277,15 @@ redraw_handler(struct widget *widget, void *data)
|
|||
struct rectangle allocation;
|
||||
cairo_t *cr;
|
||||
cairo_surface_t *surface;
|
||||
struct gl_quad quad;
|
||||
struct clip_vertex transformed_v[4], v[8];
|
||||
struct clipper_quad quad;
|
||||
struct clipper_vertex transformed_v[4], v[8];
|
||||
bool axis_aligned;
|
||||
int n;
|
||||
|
||||
global_to_surface(&g->quad, &cliptest->view, transformed_v,
|
||||
&axis_aligned);
|
||||
init_quad(&quad, transformed_v, axis_aligned);
|
||||
n = clip_quad_box32(&quad, &g->surf, v);
|
||||
clipper_quad_init(&quad, transformed_v, axis_aligned);
|
||||
n = clipper_quad_clip_box32(&quad, &g->surf, v);
|
||||
|
||||
widget_get_allocation(cliptest->widget, &allocation);
|
||||
|
||||
|
@ -552,8 +552,8 @@ benchmark(void)
|
|||
struct weston_surface surface;
|
||||
struct weston_view view;
|
||||
struct geometry geom;
|
||||
struct gl_quad quad;
|
||||
struct clip_vertex transformed_v[4], v[8];
|
||||
struct clipper_quad quad;
|
||||
struct clipper_vertex transformed_v[4], v[8];
|
||||
bool axis_aligned;
|
||||
int i;
|
||||
double t;
|
||||
|
@ -581,8 +581,8 @@ benchmark(void)
|
|||
geometry_set_phi(&geom, (float)i / 360.0f);
|
||||
global_to_surface(&geom.quad, &view, transformed_v,
|
||||
&axis_aligned);
|
||||
init_quad(&quad, transformed_v, axis_aligned);
|
||||
clip_quad_box32(&quad, &geom.surf, v);
|
||||
clipper_quad_init(&quad, transformed_v, axis_aligned);
|
||||
clipper_quad_clip_box32(&quad, &geom.surf, v);
|
||||
}
|
||||
t = read_timer();
|
||||
|
||||
|
|
|
@ -473,7 +473,7 @@ timeline_submit_render_sync(struct gl_renderer *gr,
|
|||
|
||||
static void
|
||||
global_to_surface(pixman_box32_t *rect, struct weston_view *ev,
|
||||
struct clip_vertex polygon[4], bool *axis_aligned)
|
||||
struct clipper_vertex polygon[4], bool *axis_aligned)
|
||||
{
|
||||
struct weston_coord_global rect_g[4] = {
|
||||
{ .c = weston_coord(rect->x1, rect->y1) },
|
||||
|
@ -550,14 +550,14 @@ texture_region(struct weston_paint_node *pnode,
|
|||
struct weston_compositor *ec = pnode->surface->compositor;
|
||||
struct weston_view *ev = pnode->view;
|
||||
struct gl_renderer *gr = get_renderer(ec);
|
||||
struct clip_vertex *v;
|
||||
struct clipper_vertex *v;
|
||||
unsigned int *vtxcnt, nvtx = 0;
|
||||
pixman_box32_t *rects, *surf_rects;
|
||||
pixman_box32_t *raw_rects;
|
||||
int i, j, nrects, nsurf, raw_nrects;
|
||||
bool used_band_compression, axis_aligned;
|
||||
struct clip_vertex polygon[4];
|
||||
struct gl_quad quad;
|
||||
struct clipper_vertex polygon[4];
|
||||
struct clipper_quad quad;
|
||||
|
||||
raw_rects = pixman_region32_rectangles(region, &raw_nrects);
|
||||
surf_rects = pixman_region32_rectangles(surf_region, &nsurf);
|
||||
|
@ -578,7 +578,7 @@ texture_region(struct weston_paint_node *pnode,
|
|||
|
||||
for (i = 0; i < nrects; i++) {
|
||||
global_to_surface(&rects[i], ev, polygon, &axis_aligned);
|
||||
init_quad(&quad, polygon, axis_aligned);
|
||||
clipper_quad_init(&quad, polygon, axis_aligned);
|
||||
for (j = 0; j < nsurf; j++) {
|
||||
int n;
|
||||
|
||||
|
@ -595,7 +595,7 @@ texture_region(struct weston_paint_node *pnode,
|
|||
* To do this, we first calculate the (up to eight) points at the
|
||||
* intersection of the edges of the quad and the surface rect.
|
||||
*/
|
||||
n = clip_quad_box32(&quad, &surf_rects[j], v);
|
||||
n = clipper_quad_clip_box32(&quad, &surf_rects[j], v);
|
||||
if (n >= 3) {
|
||||
v += n;
|
||||
vtxcnt[nvtx++] = n;
|
||||
|
|
|
@ -31,13 +31,13 @@
|
|||
#include "vertex-clipping.h"
|
||||
|
||||
struct clip_context {
|
||||
struct clip_vertex prev;
|
||||
struct clip_vertex box[2];
|
||||
struct clip_vertex *vertices;
|
||||
struct clipper_vertex prev;
|
||||
struct clipper_vertex box[2];
|
||||
struct clipper_vertex *vertices;
|
||||
};
|
||||
|
||||
WESTON_EXPORT_FOR_TESTS float
|
||||
float_difference(float a, float b)
|
||||
clipper_float_difference(float a, float b)
|
||||
{
|
||||
/* https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ */
|
||||
static const float max_diff = 4.0f * FLT_MIN;
|
||||
|
@ -64,7 +64,7 @@ clip_intersect_y(float p1x, float p1y, float p2x, float p2y,
|
|||
float x_arg)
|
||||
{
|
||||
float a;
|
||||
float diff = float_difference(p1x, p2x);
|
||||
float diff = clipper_float_difference(p1x, p2x);
|
||||
|
||||
/* Practically vertical line segment, yet the end points have already
|
||||
* been determined to be on different sides of the line. Therefore
|
||||
|
@ -86,7 +86,7 @@ clip_intersect_x(float p1x, float p1y, float p2x, float p2y,
|
|||
float y_arg)
|
||||
{
|
||||
float a;
|
||||
float diff = float_difference(p1y, p2y);
|
||||
float diff = clipper_float_difference(p1y, p2y);
|
||||
|
||||
/* Practically horizontal line segment, yet the end points have already
|
||||
* been determined to be on different sides of the line. Therefore
|
||||
|
@ -202,13 +202,13 @@ clip_polygon_topbottom(struct clip_context *ctx,
|
|||
}
|
||||
|
||||
struct polygon8 {
|
||||
struct clip_vertex pos[8];
|
||||
struct clipper_vertex pos[8];
|
||||
int n;
|
||||
};
|
||||
|
||||
static void
|
||||
clip_context_prepare(struct clip_context *ctx, const struct polygon8 *src,
|
||||
struct clip_vertex *dst)
|
||||
struct clipper_vertex *dst)
|
||||
{
|
||||
ctx->prev.x = src->pos[src->n - 1].x;
|
||||
ctx->prev.y = src->pos[src->n - 1].y;
|
||||
|
@ -217,7 +217,7 @@ clip_context_prepare(struct clip_context *ctx, const struct polygon8 *src,
|
|||
|
||||
static int
|
||||
clip_polygon_left(struct clip_context *ctx, const struct polygon8 *src,
|
||||
struct clip_vertex *dst)
|
||||
struct clipper_vertex *dst)
|
||||
{
|
||||
enum path_transition trans;
|
||||
int i;
|
||||
|
@ -236,7 +236,7 @@ clip_polygon_left(struct clip_context *ctx, const struct polygon8 *src,
|
|||
|
||||
static int
|
||||
clip_polygon_right(struct clip_context *ctx, const struct polygon8 *src,
|
||||
struct clip_vertex *dst)
|
||||
struct clipper_vertex *dst)
|
||||
{
|
||||
enum path_transition trans;
|
||||
int i;
|
||||
|
@ -255,7 +255,7 @@ clip_polygon_right(struct clip_context *ctx, const struct polygon8 *src,
|
|||
|
||||
static int
|
||||
clip_polygon_top(struct clip_context *ctx, const struct polygon8 *src,
|
||||
struct clip_vertex *dst)
|
||||
struct clipper_vertex *dst)
|
||||
{
|
||||
enum path_transition trans;
|
||||
int i;
|
||||
|
@ -274,7 +274,7 @@ clip_polygon_top(struct clip_context *ctx, const struct polygon8 *src,
|
|||
|
||||
static int
|
||||
clip_polygon_bottom(struct clip_context *ctx, const struct polygon8 *src,
|
||||
struct clip_vertex *dst)
|
||||
struct clipper_vertex *dst)
|
||||
{
|
||||
enum path_transition trans;
|
||||
int i;
|
||||
|
@ -292,10 +292,10 @@ clip_polygon_bottom(struct clip_context *ctx, const struct polygon8 *src,
|
|||
}
|
||||
|
||||
WESTON_EXPORT_FOR_TESTS int
|
||||
clip_transformed(const struct clip_vertex *polygon,
|
||||
size_t polygon_len,
|
||||
const struct clip_vertex box[2],
|
||||
struct clip_vertex *restrict vertices)
|
||||
clipper_clip(const struct clipper_vertex *polygon,
|
||||
size_t polygon_len,
|
||||
const struct clipper_vertex box[2],
|
||||
struct clipper_vertex *restrict vertices)
|
||||
{
|
||||
struct clip_context ctx;
|
||||
struct polygon8 p, tmp;
|
||||
|
@ -316,23 +316,23 @@ clip_transformed(const struct clip_vertex *polygon,
|
|||
vertices[0] = p.pos[0];
|
||||
n = 1;
|
||||
for (i = 1; i < p.n; i++) {
|
||||
if (float_difference(vertices[n - 1].x, p.pos[i].x) == 0.0f &&
|
||||
float_difference(vertices[n - 1].y, p.pos[i].y) == 0.0f)
|
||||
if (clipper_float_difference(vertices[n - 1].x, p.pos[i].x) == 0.0f &&
|
||||
clipper_float_difference(vertices[n - 1].y, p.pos[i].y) == 0.0f)
|
||||
continue;
|
||||
vertices[n] = p.pos[i];
|
||||
n++;
|
||||
}
|
||||
if (float_difference(vertices[n - 1].x, p.pos[0].x) == 0.0f &&
|
||||
float_difference(vertices[n - 1].y, p.pos[0].y) == 0.0f)
|
||||
if (clipper_float_difference(vertices[n - 1].x, p.pos[0].x) == 0.0f &&
|
||||
clipper_float_difference(vertices[n - 1].y, p.pos[0].y) == 0.0f)
|
||||
n--;
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
void
|
||||
init_quad(struct gl_quad *quad,
|
||||
const struct clip_vertex polygon[4],
|
||||
bool axis_aligned)
|
||||
clipper_quad_init(struct clipper_quad *quad,
|
||||
const struct clipper_vertex polygon[4],
|
||||
bool axis_aligned)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -354,9 +354,9 @@ init_quad(struct gl_quad *quad,
|
|||
}
|
||||
|
||||
int
|
||||
clip_quad(struct gl_quad *quad,
|
||||
const struct clip_vertex box[2],
|
||||
struct clip_vertex *restrict vertices)
|
||||
clipper_quad_clip(struct clipper_quad *quad,
|
||||
const struct clipper_vertex box[2],
|
||||
struct clipper_vertex *restrict vertices)
|
||||
{
|
||||
int i, n;
|
||||
|
||||
|
@ -391,7 +391,7 @@ clip_quad(struct gl_quad *quad,
|
|||
* https://www.codeguru.com/cplusplus/polygon-clipping/
|
||||
* but without looking at any of that code.
|
||||
*/
|
||||
n = clip_transformed(quad->polygon, 4, box, vertices);
|
||||
n = clipper_clip(quad->polygon, 4, box, vertices);
|
||||
|
||||
if (n < 3)
|
||||
return 0;
|
||||
|
@ -400,14 +400,14 @@ clip_quad(struct gl_quad *quad,
|
|||
}
|
||||
|
||||
int
|
||||
clip_quad_box32(struct gl_quad *quad,
|
||||
const struct pixman_box32 *box,
|
||||
struct clip_vertex *restrict vertices)
|
||||
clipper_quad_clip_box32(struct clipper_quad *quad,
|
||||
const struct pixman_box32 *box,
|
||||
struct clipper_vertex *restrict vertices)
|
||||
{
|
||||
struct clip_vertex box_vertices[2] = {
|
||||
struct clipper_vertex box_vertices[2] = {
|
||||
{ box->x1, box->y1 },
|
||||
{ box->x2, box->y2 }
|
||||
};
|
||||
|
||||
return clip_quad(quad, box_vertices, vertices);
|
||||
return clipper_quad_clip(quad, box_vertices, vertices);
|
||||
}
|
||||
|
|
|
@ -29,58 +29,59 @@
|
|||
#include <stdbool.h>
|
||||
#include <pixman.h>
|
||||
|
||||
struct clip_vertex {
|
||||
struct clipper_vertex {
|
||||
float x, y;
|
||||
};
|
||||
|
||||
struct gl_quad {
|
||||
struct clip_vertex polygon[4];
|
||||
struct clip_vertex bbox[2]; /* Valid if !axis_aligned. */
|
||||
struct clipper_quad {
|
||||
struct clipper_vertex polygon[4];
|
||||
struct clipper_vertex bbox[2]; /* Valid if !axis_aligned. */
|
||||
bool axis_aligned;
|
||||
};
|
||||
|
||||
float
|
||||
float_difference(float a, float b);
|
||||
|
||||
int
|
||||
clip_transformed(const struct clip_vertex *polygon,
|
||||
size_t polygon_len,
|
||||
const struct clip_vertex box[2],
|
||||
struct clip_vertex *restrict vertices);
|
||||
clipper_clip(const struct clipper_vertex *polygon,
|
||||
size_t polygon_len,
|
||||
const struct clipper_vertex box[2],
|
||||
struct clipper_vertex *restrict vertices);
|
||||
|
||||
/*
|
||||
* Initialize a 'quad' clipping context. 'polygon' points to an array of 4
|
||||
* vertices defining a convex quadrilateral of any winding order. Call
|
||||
* 'clip_quad()' to clip an initialized 'quad' to a clipping box. Clipping is
|
||||
* faster if 'polygon' is an axis-aligned rectangle with edges parallel to the
|
||||
* axes of the coordinate space. 'axis_aligned' indicates whether 'polygon'
|
||||
* respects the conditions above.
|
||||
* 'clipper_quad_clip()' to clip an initialized 'quad' to a clipping box.
|
||||
* Clipping is faster if 'polygon' is an axis-aligned rectangle with edges
|
||||
* parallel to the axes of the coordinate space. 'axis_aligned' indicates
|
||||
* whether 'polygon' respects the conditions above.
|
||||
*/
|
||||
void
|
||||
init_quad(struct gl_quad *quad,
|
||||
const struct clip_vertex polygon[4],
|
||||
bool axis_aligned);
|
||||
clipper_quad_init(struct clipper_quad *quad,
|
||||
const struct clipper_vertex polygon[4],
|
||||
bool axis_aligned);
|
||||
|
||||
/*
|
||||
* Compute the boundary vertices of the intersection of a convex quadrilateral
|
||||
* stored into a 'quad' clipping context and a clipping 'box'. 'box' points to
|
||||
* an array of 2 vertices where the values of the 1st vertex are less than or
|
||||
* equal to the values of the 2nd vertex. Either 0 or [3, 8] resulting vertices,
|
||||
* with the same winding order than the 'polygon' passed to 'init_quad()', are
|
||||
* written to 'vertices'. The return value is the number of vertices created.
|
||||
* with the same winding order than the 'polygon' passed to
|
||||
* 'clipper_quad_init()', are written to 'vertices'. The return value is the
|
||||
* number of vertices created.
|
||||
*/
|
||||
int
|
||||
clip_quad(struct gl_quad *quad,
|
||||
const struct clip_vertex box[2],
|
||||
struct clip_vertex *restrict vertices);
|
||||
clipper_quad_clip(struct clipper_quad *quad,
|
||||
const struct clipper_vertex box[2],
|
||||
struct clipper_vertex *restrict vertices);
|
||||
|
||||
/*
|
||||
* Utility function calling 'clip_quad' but taking a pixman_box32 pointer as
|
||||
* clipping box.
|
||||
* Utility function calling 'clipper_quad_clip()' but taking a pixman_box32
|
||||
* pointer as clipping box.
|
||||
*/
|
||||
int
|
||||
clip_quad_box32(struct gl_quad *quad,
|
||||
const struct pixman_box32* box,
|
||||
struct clip_vertex *restrict vertices);
|
||||
clipper_quad_clip_box32(struct clipper_quad *quad,
|
||||
const struct pixman_box32 *box,
|
||||
struct clipper_vertex *restrict vertices);
|
||||
|
||||
float
|
||||
clipper_float_difference(float a, float b);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -44,9 +44,9 @@
|
|||
#define OUTSIDE_Y2 (BOUNDING_BOX_TOP_Y + 1.0f)
|
||||
|
||||
struct vertex_clip_test_data {
|
||||
struct clip_vertex box[2];
|
||||
struct clip_vertex polygon[8];
|
||||
struct clip_vertex clipped[8];
|
||||
struct clipper_vertex box[2];
|
||||
struct clipper_vertex polygon[8];
|
||||
struct clipper_vertex clipped[8];
|
||||
int polygon_n;
|
||||
int clipped_n;
|
||||
};
|
||||
|
@ -214,11 +214,11 @@ const struct vertex_clip_test_data test_data[] = {
|
|||
TEST_P(clip_polygon_n_vertices_emitted, test_data)
|
||||
{
|
||||
struct vertex_clip_test_data *tdata = data;
|
||||
struct clip_vertex clipped[8];
|
||||
struct clipper_vertex clipped[8];
|
||||
int clipped_n;
|
||||
|
||||
clipped_n = clip_transformed(tdata->polygon, tdata->polygon_n,
|
||||
tdata->box, clipped);
|
||||
clipped_n = clipper_clip(tdata->polygon, tdata->polygon_n, tdata->box,
|
||||
clipped);
|
||||
|
||||
assert(clipped_n == tdata->clipped_n);
|
||||
}
|
||||
|
@ -226,11 +226,11 @@ TEST_P(clip_polygon_n_vertices_emitted, test_data)
|
|||
TEST_P(clip_polygon_expected_vertices, test_data)
|
||||
{
|
||||
struct vertex_clip_test_data *tdata = data;
|
||||
struct clip_vertex clipped[8];
|
||||
struct clipper_vertex clipped[8];
|
||||
int clipped_n, i;
|
||||
|
||||
clipped_n = clip_transformed(tdata->polygon, tdata->polygon_n,
|
||||
tdata->box, clipped);
|
||||
clipped_n = clipper_clip(tdata->polygon, tdata->polygon_n, tdata->box,
|
||||
clipped);
|
||||
|
||||
for (i = 0; i < clipped_n; i++) {
|
||||
assert(clipped[i].x == tdata->clipped[i].x);
|
||||
|
@ -238,20 +238,20 @@ TEST_P(clip_polygon_expected_vertices, test_data)
|
|||
}
|
||||
}
|
||||
|
||||
TEST(clip_transformed_size_too_high)
|
||||
TEST(clip_size_too_high)
|
||||
{
|
||||
struct clip_vertex polygon[8] = {}, box[2] = {};
|
||||
struct clipper_vertex polygon[8] = {}, box[2] = {};
|
||||
|
||||
assert(clip_transformed(polygon, 9, box, NULL) == -1);
|
||||
assert(clipper_clip(polygon, 9, box, NULL) == -1);
|
||||
}
|
||||
|
||||
TEST(float_difference_different)
|
||||
{
|
||||
assert(float_difference(1.0f, 0.0f) == 1.0f);
|
||||
assert(clipper_float_difference(1.0f, 0.0f) == 1.0f);
|
||||
}
|
||||
|
||||
TEST(float_difference_same)
|
||||
{
|
||||
assert(float_difference(1.0f, 1.0f) == 0.0f);
|
||||
assert(clipper_float_difference(1.0f, 1.0f) == 0.0f);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue