When a backend isn’t stereoscopy-aware, the compositor itself will
calculate the correct offset.

Backends which are aware of stereoscopy should do this computation
themselves, in the correct place.

Signed-off-by: Emmanuel Gil Peyrot <linkma...@linkmauve.fr>
---
 libweston/compositor.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 53 insertions(+), 3 deletions(-)

diff --git a/libweston/compositor.c b/libweston/compositor.c
index dc2b563a..a2f624f6 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -788,6 +788,53 @@ viewport_surface_to_buffer(struct weston_surface *surface,
        *by = sy * src_height / surface->height + src_y;
 }
 
+static void
+stereo_surface_to_buffer(struct weston_surface *surface,
+                        float sx, float sy, float *bx, float *by)
+{
+       struct weston_buffer_viewport *vp = &surface->buffer_viewport;
+       uint32_t default_side = vp->surface.default_side;
+
+       if (surface->compositor->capabilities & WESTON_CAP_STEREOSCOPY) {
+               /* The backend supports stereoscopy natively, we don’t have to
+                * do anything here. */
+               *bx = sx;
+               *by = sy;
+       } else {
+               switch (vp->buffer.stereoscopy_layout) {
+               case ZWP_STEREOSCOPY_V1_LAYOUT_NONE:
+                       *bx = sx;
+                       *by = sy;
+                       break;
+               case ZWP_STEREOSCOPY_V1_LAYOUT_FRAME_PACKING:
+                       /* TODO: Frame-packing support for clients doesn’t work
+                        * currently, since the buffer size needs to be bigger
+                        * than the surface size, and we have no provision for
+                        * that currently. */
+                       *bx = sx;
+                       *by = sy;
+                       if (default_side == 
ZWP_STEREOSCOPY_DESCRIPTION_V1_SIDE_RIGHT)
+                               *by += surface->height * 25.0 / 24.0;
+                       break;
+               case ZWP_STEREOSCOPY_V1_LAYOUT_TOP_AND_BOTTOM:
+                       *bx = sx;
+                       *by = sy / 2.0;
+                       if (default_side == 
ZWP_STEREOSCOPY_DESCRIPTION_V1_SIDE_RIGHT)
+                               *by += surface->height / 2.0;
+                       break;
+               case ZWP_STEREOSCOPY_V1_LAYOUT_SIDE_BY_SIDE:
+                       *bx = sx / 2.0;
+                       *by = sy;
+                       if (default_side == 
ZWP_STEREOSCOPY_DESCRIPTION_V1_SIDE_RIGHT)
+                               *bx += surface->width / 2.0;
+                       break;
+               default:
+                       // TODO: add support for the other layouts.
+                       assert(0);
+               }
+       }
+}
+
 WL_EXPORT void
 weston_surface_to_buffer_float(struct weston_surface *surface,
                               float sx, float sy, float *bx, float *by)
@@ -795,7 +842,8 @@ weston_surface_to_buffer_float(struct weston_surface 
*surface,
        struct weston_buffer_viewport *vp = &surface->buffer_viewport;
 
        /* first transform coordinates if the viewport is set */
-       viewport_surface_to_buffer(surface, sx, sy, bx, by);
+       stereo_surface_to_buffer(surface, sx, sy, bx, by);
+       viewport_surface_to_buffer(surface, *bx, *by, bx, by);
 
        weston_transformed_coord(surface->width_from_buffer,
                                 surface->height_from_buffer,
@@ -829,11 +877,13 @@ weston_surface_to_buffer_rect(struct weston_surface 
*surface,
        float xf, yf;
 
        /* first transform box coordinates if the viewport is set */
-       viewport_surface_to_buffer(surface, rect.x1, rect.y1, &xf, &yf);
+       stereo_surface_to_buffer(surface, rect.x1, rect.y1, &xf, &yf);
+       viewport_surface_to_buffer(surface, xf, yf, &xf, &yf);
        rect.x1 = floorf(xf);
        rect.y1 = floorf(yf);
 
-       viewport_surface_to_buffer(surface, rect.x2, rect.y2, &xf, &yf);
+       stereo_surface_to_buffer(surface, rect.x2, rect.y2, &xf, &yf);
+       viewport_surface_to_buffer(surface, xf, yf, &xf, &yf);
        rect.x2 = ceilf(xf);
        rect.y2 = ceilf(yf);
 
-- 
2.15.0

_______________________________________________
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to