X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fauxiliary%2Futil%2Fu_rect.h;h=221d9188730eaa98af9ac7d4b53f6212578c4b7b;hb=37db383abbec071e2b3d26d0a531ec8296705b63;hp=59e842e16d147e9df5f99958e78c2faf9252eb77;hpb=c789bd376f09c3b61617aeef6f5adbba2c541178;p=mesa.git diff --git a/src/gallium/auxiliary/util/u_rect.h b/src/gallium/auxiliary/util/u_rect.h index 59e842e16d1..221d9188730 100644 --- a/src/gallium/auxiliary/util/u_rect.h +++ b/src/gallium/auxiliary/util/u_rect.h @@ -1,6 +1,6 @@ /************************************************************************** * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright 2008 VMware, Inc. * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -18,7 +18,7 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -26,47 +26,89 @@ **************************************************************************/ -/** - * Pipe copy/fill rect helpers. - */ - - #ifndef U_RECT_H #define U_RECT_H +#include "pipe/p_compiler.h" +#include "util/u_math.h" -#include "pipe/p_format.h" +#ifdef __cplusplus +extern "C" { +#endif -struct pipe_context; -struct pipe_surface; +struct u_rect { + int x0, x1; + int y0, y1; +}; +/* Do two rectangles intersect? + * Note: empty rectangles are valid as inputs (and never intersect). + */ +static inline boolean +u_rect_test_intersection(const struct u_rect *a, + const struct u_rect *b) +{ + return (!(a->x1 < b->x0 || + b->x1 < a->x0 || + a->y1 < b->y0 || + b->y1 < a->y0 || + a->x1 < a->x0 || + a->y1 < a->y0 || + b->x1 < b->x0 || + b->y1 < b->y0)); +} -extern void -pipe_copy_rect(ubyte * dst, const struct pipe_format_block *block, - unsigned dst_stride, unsigned dst_x, unsigned dst_y, - unsigned width, unsigned height, const ubyte * src, - int src_stride, unsigned src_x, int src_y); +/* Find the intersection of two rectangles known to intersect. + */ +static inline void +u_rect_find_intersection(const struct u_rect *a, + struct u_rect *b) +{ + /* Caller should verify intersection exists before calling. + */ + if (b->x0 < a->x0) b->x0 = a->x0; + if (b->x1 > a->x1) b->x1 = a->x1; + if (b->y0 < a->y0) b->y0 = a->y0; + if (b->y1 > a->y1) b->y1 = a->y1; +} -extern void -pipe_fill_rect(ubyte * dst, const struct pipe_format_block *block, - unsigned dst_stride, unsigned dst_x, unsigned dst_y, - unsigned width, unsigned height, uint32_t value); +static inline int +u_rect_area(const struct u_rect *r) +{ + return (r->x1 - r->x0) * (r->y1 - r->y0); +} -extern void -util_surface_copy(struct pipe_context *pipe, - boolean do_flip, - struct pipe_surface *dst, - unsigned dst_x, unsigned dst_y, - struct pipe_surface *src, - unsigned src_x, unsigned src_y, - unsigned w, unsigned h); +static inline void +u_rect_possible_intersection(const struct u_rect *a, + struct u_rect *b) +{ + if (u_rect_test_intersection(a,b)) { + u_rect_find_intersection(a,b); + } + else { + /* + * Note the u_rect_xx tests deal with inclusive coordinates + * hence all-zero would not be an empty box. + */ + b->x0 = b->y0 = 0; + b->x1 = b->y1 = -1; + } +} -extern void -util_surface_fill(struct pipe_context *pipe, - struct pipe_surface *dst, - unsigned dstx, unsigned dsty, - unsigned width, unsigned height, unsigned value); +/* Set @d to a rectangle that covers both @a and @b. + */ +static inline void +u_rect_union(struct u_rect *d, const struct u_rect *a, const struct u_rect *b) +{ + d->x0 = MIN2(a->x0, b->x0); + d->y0 = MIN2(a->y0, b->y0); + d->x1 = MAX2(a->x1, b->x1); + d->y1 = MAX2(a->y1, b->y1); +} +#ifdef __cplusplus +} +#endif #endif /* U_RECT_H */