gallium/util: Add new u_box helpers

Signed-off-by: Axel Davy <davyaxel0@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9451>
This commit is contained in:
Axel Davy
2021-03-06 17:34:22 +01:00
committed by Marge Bot
parent a5819e1b49
commit 26a9e2bb15
+39
View File
@@ -119,6 +119,45 @@ u_box_volume_3d(const struct pipe_box *box)
return (int64_t)box->width * box->height * box->depth;
}
/* Aliasing of @dst permitted. Supports empty width */
static inline void
u_box_union_1d(struct pipe_box *dst,
const struct pipe_box *a, const struct pipe_box *b)
{
int x, width;
if (a->width == 0) {
x = b->x;
width = b->width;
} else if (b->width == 0) {
x = a->x;
width = a->width;
} else {
x = MIN2(a->x, b->x);
width = MAX2(a->x + a->width, b->x + b->width) - x;
}
dst->x = x;
dst->width = width;
}
/* Aliasing of @dst permitted. */
static inline void
u_box_intersect_1d(struct pipe_box *dst,
const struct pipe_box *a, const struct pipe_box *b)
{
int x;
x = MAX2(a->x, b->x);
dst->width = MIN2(a->x + a->width, b->x + b->width) - x;
dst->x = x;
if (dst->width <= 0) {
dst->x = 0;
dst->width = 0;
}
}
/* Aliasing of @dst permitted. */
static inline void
u_box_union_2d(struct pipe_box *dst,