compositor: Move weston_matrix_transform_region to compositor.c and export it
We're going to use this to replace much of the other transform code so it's no longer just relevant to pixman-renderer.c Signed-off-by: Derek Foreman <derekf@osg.samsung.com> [Pekka: add the warning about matrix restrictions] Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This commit is contained in:
committed by
Pekka Paalanen
parent
52c476ac8d
commit
bc9a61cc23
@@ -726,6 +726,63 @@ weston_transformed_rect(int width, int height,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Transform a region by a matrix, restricted to axis-aligned transformations
|
||||||
|
*
|
||||||
|
* Warning: This function does not work for projective, affine, or matrices
|
||||||
|
* that encode arbitrary rotations. Only 90-degree step rotations are
|
||||||
|
* supported.
|
||||||
|
*/
|
||||||
|
WL_EXPORT void
|
||||||
|
weston_matrix_transform_region(pixman_region32_t *dest,
|
||||||
|
struct weston_matrix *matrix,
|
||||||
|
pixman_region32_t *src)
|
||||||
|
{
|
||||||
|
pixman_box32_t *src_rects, *dest_rects;
|
||||||
|
int nrects, i;
|
||||||
|
|
||||||
|
src_rects = pixman_region32_rectangles(src, &nrects);
|
||||||
|
dest_rects = malloc(nrects * sizeof(*dest_rects));
|
||||||
|
if (!dest_rects)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (i = 0; i < nrects; i++) {
|
||||||
|
struct weston_vector vec1 = {{
|
||||||
|
src_rects[i].x1, src_rects[i].y1, 0, 1
|
||||||
|
}};
|
||||||
|
weston_matrix_transform(matrix, &vec1);
|
||||||
|
vec1.f[0] /= vec1.f[3];
|
||||||
|
vec1.f[1] /= vec1.f[3];
|
||||||
|
|
||||||
|
struct weston_vector vec2 = {{
|
||||||
|
src_rects[i].x2, src_rects[i].y2, 0, 1
|
||||||
|
}};
|
||||||
|
weston_matrix_transform(matrix, &vec2);
|
||||||
|
vec2.f[0] /= vec2.f[3];
|
||||||
|
vec2.f[1] /= vec2.f[3];
|
||||||
|
|
||||||
|
if (vec1.f[0] < vec2.f[0]) {
|
||||||
|
dest_rects[i].x1 = floor(vec1.f[0]);
|
||||||
|
dest_rects[i].x2 = ceil(vec2.f[0]);
|
||||||
|
} else {
|
||||||
|
dest_rects[i].x1 = floor(vec2.f[0]);
|
||||||
|
dest_rects[i].x2 = ceil(vec1.f[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (vec1.f[1] < vec2.f[1]) {
|
||||||
|
dest_rects[i].y1 = floor(vec1.f[1]);
|
||||||
|
dest_rects[i].y2 = ceil(vec2.f[1]);
|
||||||
|
} else {
|
||||||
|
dest_rects[i].y1 = floor(vec2.f[1]);
|
||||||
|
dest_rects[i].y2 = ceil(vec1.f[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pixman_region32_clear(dest);
|
||||||
|
pixman_region32_init_rects(dest, dest_rects, nrects);
|
||||||
|
free(dest_rects);
|
||||||
|
}
|
||||||
|
|
||||||
WL_EXPORT void
|
WL_EXPORT void
|
||||||
weston_transformed_region(int width, int height,
|
weston_transformed_region(int width, int height,
|
||||||
enum wl_output_transform transform,
|
enum wl_output_transform transform,
|
||||||
|
|||||||
@@ -1646,6 +1646,10 @@ weston_transformed_rect(int width, int height,
|
|||||||
int32_t scale,
|
int32_t scale,
|
||||||
pixman_box32_t rect);
|
pixman_box32_t rect);
|
||||||
void
|
void
|
||||||
|
weston_matrix_transform_region(pixman_region32_t *dest,
|
||||||
|
struct weston_matrix *matrix,
|
||||||
|
pixman_region32_t *src);
|
||||||
|
void
|
||||||
weston_transformed_region(int width, int height,
|
weston_transformed_region(int width, int height,
|
||||||
enum wl_output_transform transform,
|
enum wl_output_transform transform,
|
||||||
int32_t scale,
|
int32_t scale,
|
||||||
|
|||||||
@@ -133,64 +133,6 @@ pixman_renderer_read_pixels(struct weston_output *output,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Warning: This function does not work for projective, affine, or matrices
|
|
||||||
* that encode arbitrary rotations. Only 90-degree step rotations are
|
|
||||||
* supported.
|
|
||||||
*
|
|
||||||
* Luckily it is only used for output matrices, so it is fine here.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
weston_matrix_transform_region(pixman_region32_t *dest,
|
|
||||||
struct weston_matrix *matrix,
|
|
||||||
pixman_region32_t *src)
|
|
||||||
{
|
|
||||||
pixman_box32_t *src_rects, *dest_rects;
|
|
||||||
int nrects, i;
|
|
||||||
|
|
||||||
src_rects = pixman_region32_rectangles(src, &nrects);
|
|
||||||
dest_rects = malloc(nrects * sizeof(*dest_rects));
|
|
||||||
if (!dest_rects)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (i = 0; i < nrects; i++) {
|
|
||||||
struct weston_vector vec1 = {{
|
|
||||||
src_rects[i].x1, src_rects[i].y1, 0, 1
|
|
||||||
}};
|
|
||||||
weston_matrix_transform(matrix, &vec1);
|
|
||||||
vec1.f[0] /= vec1.f[3];
|
|
||||||
vec1.f[1] /= vec1.f[3];
|
|
||||||
|
|
||||||
struct weston_vector vec2 = {{
|
|
||||||
src_rects[i].x2, src_rects[i].y2, 0, 1
|
|
||||||
}};
|
|
||||||
weston_matrix_transform(matrix, &vec2);
|
|
||||||
vec2.f[0] /= vec2.f[3];
|
|
||||||
vec2.f[1] /= vec2.f[3];
|
|
||||||
|
|
||||||
if (vec1.f[0] < vec2.f[0]) {
|
|
||||||
dest_rects[i].x1 = floor(vec1.f[0]);
|
|
||||||
dest_rects[i].x2 = ceil(vec2.f[0]);
|
|
||||||
} else {
|
|
||||||
dest_rects[i].x1 = floor(vec2.f[0]);
|
|
||||||
dest_rects[i].x2 = ceil(vec1.f[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (vec1.f[1] < vec2.f[1]) {
|
|
||||||
dest_rects[i].y1 = floor(vec1.f[1]);
|
|
||||||
dest_rects[i].y2 = ceil(vec2.f[1]);
|
|
||||||
} else {
|
|
||||||
dest_rects[i].y1 = floor(vec2.f[1]);
|
|
||||||
dest_rects[i].y2 = ceil(vec1.f[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pixman_region32_clear(dest);
|
|
||||||
pixman_region32_init_rects(dest, dest_rects, nrects);
|
|
||||||
free(dest_rects);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
region_global_to_output(struct weston_output *output, pixman_region32_t *region)
|
region_global_to_output(struct weston_output *output, pixman_region32_t *region)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user