compositor-drm: Support overlays with transformed buffers
Make overlays work when the client uses a buffer with the same
transformation as the output.
In order to calculate the destination rectangle, the same logic in
weston_surface_to_buffer_float() is needed, but with the output
dimensions instead. For that reason, this patch generalizes this
function into weston_transformed_{coord,rect} and moves it to util.c.
The surface functions are then implemented using those.
diff --git a/src/compositor.c b/src/compositor.c
index f56e515..d62a740 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -294,71 +294,19 @@
weston_surface_to_buffer_float(struct weston_surface *surface,
float sx, float sy, float *bx, float *by)
{
- switch (surface->buffer_transform) {
- case WL_OUTPUT_TRANSFORM_NORMAL:
- default:
- *bx = sx;
- *by = sy;
- break;
- case WL_OUTPUT_TRANSFORM_FLIPPED:
- *bx = surface->geometry.width - sx;
- *by = sy;
- break;
- case WL_OUTPUT_TRANSFORM_90:
- *bx = surface->geometry.height - sy;
- *by = sx;
- break;
- case WL_OUTPUT_TRANSFORM_FLIPPED_90:
- *bx = surface->geometry.height - sy;
- *by = surface->geometry.width - sx;
- break;
- case WL_OUTPUT_TRANSFORM_180:
- *bx = surface->geometry.width - sx;
- *by = surface->geometry.height - sy;
- break;
- case WL_OUTPUT_TRANSFORM_FLIPPED_180:
- *bx = sx;
- *by = surface->geometry.height - sy;
- break;
- case WL_OUTPUT_TRANSFORM_270:
- *bx = sy;
- *by = surface->geometry.width - sx;
- break;
- case WL_OUTPUT_TRANSFORM_FLIPPED_270:
- *bx = sy;
- *by = sx;
- break;
- }
+ weston_transformed_coord(surface->geometry.width,
+ surface->geometry.height,
+ surface->buffer_transform,
+ sx, sy, bx, by);
}
WL_EXPORT pixman_box32_t
weston_surface_to_buffer_rect(struct weston_surface *surface,
pixman_box32_t rect)
{
- float x1, x2, y1, y2;
-
- pixman_box32_t ret;
-
- weston_surface_to_buffer_float(surface, rect.x1, rect.y1, &x1, &y1);
- weston_surface_to_buffer_float(surface, rect.x2, rect.y2, &x2, &y2);
-
- if (x1 <= x2) {
- ret.x1 = x1;
- ret.x2 = x2;
- } else {
- ret.x1 = x2;
- ret.x2 = x1;
- }
-
- if (y1 <= y2) {
- ret.y1 = y1;
- ret.y2 = y2;
- } else {
- ret.y1 = y2;
- ret.y2 = y1;
- }
-
- return ret;
+ return weston_transformed_rect(surface->geometry.width,
+ surface->geometry.height,
+ surface->buffer_transform, rect);
}
WL_EXPORT void