Module: Mesa Branch: master Commit: 26a9e2bb15aaac0957a0be493d9634c82a1fa6c5 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=26a9e2bb15aaac0957a0be493d9634c82a1fa6c5
Author: Axel Davy <[email protected]> Date: Sat Mar 6 17:34:22 2021 +0100 gallium/util: Add new u_box helpers Signed-off-by: Axel Davy <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9451> --- src/gallium/auxiliary/util/u_box.h | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/gallium/auxiliary/util/u_box.h b/src/gallium/auxiliary/util/u_box.h index b3f478e7bfc..764bf5037a5 100644 --- a/src/gallium/auxiliary/util/u_box.h +++ b/src/gallium/auxiliary/util/u_box.h @@ -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, _______________________________________________ mesa-commit mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/mesa-commit
