diff options
author | Jason Ekstrand <jason@jlekstrand.net> | 2013-10-27 22:25:01 -0500 |
---|---|---|
committer | Kristian Høgsberg <krh@bitplanet.net> | 2013-11-07 16:34:59 -0800 |
commit | 33ff636812b8f5db20be5c4c77bc3f9f25ea274b (patch) | |
tree | 2d6c810c751b8244f88a7337694a20bd8954b4a4 /src/pixman-renderer.c | |
parent | b6a3cc7f178123d7b094c3036de32548cdeeaeb7 (diff) | |
download | weston-33ff636812b8f5db20be5c4c77bc3f9f25ea274b.tar.gz |
Move region transformation code to weston_transformed_region
Both the Pixman renderer and the X11 backend contained effectively the same
region transformation code. This commit adds a weston_transformed_region
function and changes pixman-renderer and compositor-x11 to use it.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Diffstat (limited to 'src/pixman-renderer.c')
-rw-r--r-- | src/pixman-renderer.c | 106 |
1 files changed, 3 insertions, 103 deletions
diff --git a/src/pixman-renderer.c b/src/pixman-renderer.c index 79c1d5b1..a80be5f5 100644 --- a/src/pixman-renderer.c +++ b/src/pixman-renderer.c @@ -127,112 +127,12 @@ pixman_renderer_read_pixels(struct weston_output *output, } static void -box_scale(pixman_box32_t *dst, int scale) -{ - dst->x1 *= scale; - dst->x2 *= scale; - dst->y1 *= scale; - dst->y2 *= scale; -} - -static void -scale_region (pixman_region32_t *region, int scale) -{ - pixman_box32_t *rects, *scaled_rects; - int nrects, i; - - if (scale != 1) { - rects = pixman_region32_rectangles(region, &nrects); - scaled_rects = calloc(nrects, sizeof(pixman_box32_t)); - - for (i = 0; i < nrects; i++) { - scaled_rects[i] = rects[i]; - box_scale(&scaled_rects[i], scale); - } - pixman_region32_clear(region); - - pixman_region32_init_rects (region, scaled_rects, nrects); - free (scaled_rects); - } -} - -static void -transform_region (pixman_region32_t *region, int width, int height, enum wl_output_transform transform) -{ - pixman_box32_t *rects, *transformed_rects; - int nrects, i; - - if (transform == WL_OUTPUT_TRANSFORM_NORMAL) - return; - - rects = pixman_region32_rectangles(region, &nrects); - transformed_rects = calloc(nrects, sizeof(pixman_box32_t)); - - for (i = 0; i < nrects; i++) { - switch (transform) { - default: - case WL_OUTPUT_TRANSFORM_NORMAL: - transformed_rects[i].x1 = rects[i].x1; - transformed_rects[i].y1 = rects[i].y1; - transformed_rects[i].x2 = rects[i].x2; - transformed_rects[i].y2 = rects[i].y2; - break; - case WL_OUTPUT_TRANSFORM_90: - transformed_rects[i].x1 = height - rects[i].y2; - transformed_rects[i].y1 = rects[i].x1; - transformed_rects[i].x2 = height - rects[i].y1; - transformed_rects[i].y2 = rects[i].x2; - break; - case WL_OUTPUT_TRANSFORM_180: - transformed_rects[i].x1 = width - rects[i].x2; - transformed_rects[i].y1 = height - rects[i].y2; - transformed_rects[i].x2 = width - rects[i].x1; - transformed_rects[i].y2 = height - rects[i].y1; - break; - case WL_OUTPUT_TRANSFORM_270: - transformed_rects[i].x1 = rects[i].y1; - transformed_rects[i].y1 = width - rects[i].x2; - transformed_rects[i].x2 = rects[i].y2; - transformed_rects[i].y2 = width - rects[i].x1; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED: - transformed_rects[i].x1 = width - rects[i].x2; - transformed_rects[i].y1 = rects[i].y1; - transformed_rects[i].x2 = width - rects[i].x1; - transformed_rects[i].y2 = rects[i].y2; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_90: - transformed_rects[i].x1 = height - rects[i].y2; - transformed_rects[i].y1 = width - rects[i].x2; - transformed_rects[i].x2 = height - rects[i].y1; - transformed_rects[i].y2 = width - rects[i].x1; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_180: - transformed_rects[i].x1 = rects[i].x1; - transformed_rects[i].y1 = height - rects[i].y2; - transformed_rects[i].x2 = rects[i].x2; - transformed_rects[i].y2 = height - rects[i].y1; - break; - case WL_OUTPUT_TRANSFORM_FLIPPED_270: - transformed_rects[i].x1 = rects[i].y1; - transformed_rects[i].y1 = rects[i].x1; - transformed_rects[i].x2 = rects[i].y2; - transformed_rects[i].y2 = rects[i].x2; - break; - } - } - pixman_region32_clear(region); - - pixman_region32_init_rects (region, transformed_rects, nrects); - free (transformed_rects); -} - -static void region_global_to_output(struct weston_output *output, pixman_region32_t *region) { pixman_region32_translate(region, -output->x, -output->y); - transform_region (region, output->width, output->height, output->transform); - scale_region (region, output->current_scale); + weston_transformed_region(output->width, output->height, + output->transform, output->current_scale, + region, region); } #define D2F(v) pixman_double_to_fixed((double)v) |