From 8cf921a7420ad66de2e39ec429d2e6fcefe7625f Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 3 Mar 2025 10:17:46 -0600 Subject: [PATCH] util/box: Add a intersect_2d helper Fixes: 3d38c9597ff3 ("zink: hook up KHR_partial_update") Reviewed-by: Kenneth Graunke Part-of: --- src/util/box.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/util/box.h b/src/util/box.h index 53b00079b7f..2fb0be6fd23 100644 --- a/src/util/box.h +++ b/src/util/box.h @@ -190,6 +190,31 @@ u_box_union_2d(struct pipe_box *dst, dst->y = y; } +/* Aliasing of @dst permitted. */ +static inline void +u_box_intersect_2d(struct pipe_box *dst, + const struct pipe_box *a, const struct pipe_box *b) +{ + int x, y; + + x = MAX2(a->x, b->x); + y = MAX2(a->y, b->y); + + 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; + } + + dst->height = MIN2(a->y + a->height, b->y + b->height) - y; + dst->y = y; + if (dst->height <= 0) { + dst->y = 0; + dst->height = 0; + } +} + /* Aliasing of @dst permitted. */ static inline void u_box_union_3d(struct pipe_box *dst,