util/region: constify

This commit is contained in:
Simon Ser 2022-10-24 12:50:45 +02:00 committed by Simon Zeni
parent feb5691240
commit 9fd28d1e81
2 changed files with 17 additions and 17 deletions

View file

@ -26,33 +26,33 @@
* The resulting coordinates are rounded up or down so that the new region is * The resulting coordinates are rounded up or down so that the new region is
* at least as big as the original one. * at least as big as the original one.
*/ */
void wlr_region_scale(pixman_region32_t *dst, pixman_region32_t *src, void wlr_region_scale(pixman_region32_t *dst, const pixman_region32_t *src,
float scale); float scale);
void wlr_region_scale_xy(pixman_region32_t *dst, pixman_region32_t *src, void wlr_region_scale_xy(pixman_region32_t *dst, const pixman_region32_t *src,
float scale_x, float scale_y); float scale_x, float scale_y);
/** /**
* Applies a transform to a region inside a box of size `width` x `height`. * Applies a transform to a region inside a box of size `width` x `height`.
*/ */
void wlr_region_transform(pixman_region32_t *dst, pixman_region32_t *src, void wlr_region_transform(pixman_region32_t *dst, const pixman_region32_t *src,
enum wl_output_transform transform, int width, int height); enum wl_output_transform transform, int width, int height);
/** /**
* Expands the region of `distance`. If `distance` is negative, it shrinks the * Expands the region of `distance`. If `distance` is negative, it shrinks the
* region. * region.
*/ */
void wlr_region_expand(pixman_region32_t *dst, pixman_region32_t *src, void wlr_region_expand(pixman_region32_t *dst, const pixman_region32_t *src,
int distance); int distance);
/* /*
* Builds the smallest possible region that contains the region rotated about * Builds the smallest possible region that contains the region rotated about
* the point (ox, oy). * the point (ox, oy).
*/ */
void wlr_region_rotated_bounds(pixman_region32_t *dst, pixman_region32_t *src, void wlr_region_rotated_bounds(pixman_region32_t *dst, const pixman_region32_t *src,
float rotation, int ox, int oy); float rotation, int ox, int oy);
bool wlr_region_confine(pixman_region32_t *region, double x1, double y1, double x2, bool wlr_region_confine(const pixman_region32_t *region, double x1, double y1, double x2,
double y2, double *x2_out, double *y2_out); double y2, double *x2_out, double *y2_out);
#endif #endif

View file

@ -4,12 +4,12 @@
#include <stdlib.h> #include <stdlib.h>
#include <wlr/util/region.h> #include <wlr/util/region.h>
void wlr_region_scale(pixman_region32_t *dst, pixman_region32_t *src, void wlr_region_scale(pixman_region32_t *dst, const pixman_region32_t *src,
float scale) { float scale) {
wlr_region_scale_xy(dst, src, scale, scale); wlr_region_scale_xy(dst, src, scale, scale);
} }
void wlr_region_scale_xy(pixman_region32_t *dst, pixman_region32_t *src, void wlr_region_scale_xy(pixman_region32_t *dst, const pixman_region32_t *src,
float scale_x, float scale_y) { float scale_x, float scale_y) {
if (scale_x == 1.0 && scale_y == 1.0) { if (scale_x == 1.0 && scale_y == 1.0) {
pixman_region32_copy(dst, src); pixman_region32_copy(dst, src);
@ -17,7 +17,7 @@ void wlr_region_scale_xy(pixman_region32_t *dst, pixman_region32_t *src,
} }
int nrects; int nrects;
pixman_box32_t *src_rects = pixman_region32_rectangles(src, &nrects); const pixman_box32_t *src_rects = pixman_region32_rectangles(src, &nrects);
pixman_box32_t *dst_rects = malloc(nrects * sizeof(pixman_box32_t)); pixman_box32_t *dst_rects = malloc(nrects * sizeof(pixman_box32_t));
if (dst_rects == NULL) { if (dst_rects == NULL) {
@ -36,7 +36,7 @@ void wlr_region_scale_xy(pixman_region32_t *dst, pixman_region32_t *src,
free(dst_rects); free(dst_rects);
} }
void wlr_region_transform(pixman_region32_t *dst, pixman_region32_t *src, void wlr_region_transform(pixman_region32_t *dst, const pixman_region32_t *src,
enum wl_output_transform transform, int width, int height) { enum wl_output_transform transform, int width, int height) {
if (transform == WL_OUTPUT_TRANSFORM_NORMAL) { if (transform == WL_OUTPUT_TRANSFORM_NORMAL) {
pixman_region32_copy(dst, src); pixman_region32_copy(dst, src);
@ -44,7 +44,7 @@ void wlr_region_transform(pixman_region32_t *dst, pixman_region32_t *src,
} }
int nrects; int nrects;
pixman_box32_t *src_rects = pixman_region32_rectangles(src, &nrects); const pixman_box32_t *src_rects = pixman_region32_rectangles(src, &nrects);
pixman_box32_t *dst_rects = malloc(nrects * sizeof(pixman_box32_t)); pixman_box32_t *dst_rects = malloc(nrects * sizeof(pixman_box32_t));
if (dst_rects == NULL) { if (dst_rects == NULL) {
@ -109,7 +109,7 @@ void wlr_region_transform(pixman_region32_t *dst, pixman_region32_t *src,
free(dst_rects); free(dst_rects);
} }
void wlr_region_expand(pixman_region32_t *dst, pixman_region32_t *src, void wlr_region_expand(pixman_region32_t *dst, const pixman_region32_t *src,
int distance) { int distance) {
if (distance == 0) { if (distance == 0) {
pixman_region32_copy(dst, src); pixman_region32_copy(dst, src);
@ -117,7 +117,7 @@ void wlr_region_expand(pixman_region32_t *dst, pixman_region32_t *src,
} }
int nrects; int nrects;
pixman_box32_t *src_rects = pixman_region32_rectangles(src, &nrects); const pixman_box32_t *src_rects = pixman_region32_rectangles(src, &nrects);
pixman_box32_t *dst_rects = malloc(nrects * sizeof(pixman_box32_t)); pixman_box32_t *dst_rects = malloc(nrects * sizeof(pixman_box32_t));
if (dst_rects == NULL) { if (dst_rects == NULL) {
@ -136,7 +136,7 @@ void wlr_region_expand(pixman_region32_t *dst, pixman_region32_t *src,
free(dst_rects); free(dst_rects);
} }
void wlr_region_rotated_bounds(pixman_region32_t *dst, pixman_region32_t *src, void wlr_region_rotated_bounds(pixman_region32_t *dst, const pixman_region32_t *src,
float rotation, int ox, int oy) { float rotation, int ox, int oy) {
if (rotation == 0) { if (rotation == 0) {
pixman_region32_copy(dst, src); pixman_region32_copy(dst, src);
@ -144,7 +144,7 @@ void wlr_region_rotated_bounds(pixman_region32_t *dst, pixman_region32_t *src,
} }
int nrects; int nrects;
pixman_box32_t *src_rects = pixman_region32_rectangles(src, &nrects); const pixman_box32_t *src_rects = pixman_region32_rectangles(src, &nrects);
pixman_box32_t *dst_rects = malloc(nrects * sizeof(pixman_box32_t)); pixman_box32_t *dst_rects = malloc(nrects * sizeof(pixman_box32_t));
if (dst_rects == NULL) { if (dst_rects == NULL) {
@ -185,7 +185,7 @@ void wlr_region_rotated_bounds(pixman_region32_t *dst, pixman_region32_t *src,
free(dst_rects); free(dst_rects);
} }
static void region_confine(pixman_region32_t *region, double x1, double y1, double x2, static void region_confine(const pixman_region32_t *region, double x1, double y1, double x2,
double y2, double *x2_out, double *y2_out, pixman_box32_t box) { double y2, double *x2_out, double *y2_out, pixman_box32_t box) {
double x_clamped = fmax(fmin(x2, box.x2 - 1), box.x1); double x_clamped = fmax(fmin(x2, box.x2 - 1), box.x1);
double y_clamped = fmax(fmin(y2, box.y2 - 1), box.y1); double y_clamped = fmax(fmin(y2, box.y2 - 1), box.y1);
@ -242,7 +242,7 @@ static void region_confine(pixman_region32_t *region, double x1, double y1, doub
} }
} }
bool wlr_region_confine(pixman_region32_t *region, double x1, double y1, double x2, bool wlr_region_confine(const pixman_region32_t *region, double x1, double y1, double x2,
double y2, double *x2_out, double *y2_out) { double y2, double *x2_out, double *y2_out) {
pixman_box32_t box; pixman_box32_t box;
if (pixman_region32_contains_point(region, floor(x1), floor(y1), &box)) { if (pixman_region32_contains_point(region, floor(x1), floor(y1), &box)) {