From 730dbc896a18b4202cae7b604f42e5f6f93560d0 Mon Sep 17 00:00:00 2001 From: Christian Meissl Date: Tue, 25 May 2021 12:28:35 +0200 Subject: [PATCH] handle egl query with EGL_WAYLAND_Y_INVERTED_WL... ...returning EGL_FALSE --- src/backend/egl/display.rs | 40 +++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/src/backend/egl/display.rs b/src/backend/egl/display.rs index 249ddfd..4821f5f 100644 --- a/src/backend/egl/display.rs +++ b/src/backend/egl/display.rs @@ -734,16 +734,32 @@ impl EGLBufferReader { }) .map_err(BufferAccessError::NotManaged)?; - let mut inverted: i32 = 0; - wrap_egl_call(|| unsafe { - ffi::egl::QueryWaylandBufferWL( - **self.display, - buffer.as_ref().c_ptr() as _, - ffi::egl::WAYLAND_Y_INVERTED_WL, - &mut inverted, - ) - }) - .map_err(BufferAccessError::NotManaged)?; + let y_inverted = { + let mut inverted: i32 = 0; + + // Query the egl buffer with EGL_WAYLAND_Y_INVERTED_WL to retrieve the + // buffer orientation. + // The call can either fail, succeed with EGL_TRUE or succeed with EGL_FALSE. + // The specification for eglQuery defines that unsupported attributes shall return + // EGL_FALSE. In case of EGL_WAYLAND_Y_INVERTED_WL the specification defines that + // if EGL_FALSE is returned the value of inverted should be assumed as EGL_TRUE. + // + // see: https://www.khronos.org/registry/EGL/extensions/WL/EGL_WL_bind_wayland_display.txt + match wrap_egl_call(|| unsafe { + ffi::egl::QueryWaylandBufferWL( + **self.display, + buffer.as_ref().c_ptr() as _, + ffi::egl::WAYLAND_Y_INVERTED_WL, + &mut inverted, + ) + }) + .map_err(BufferAccessError::NotManaged)? + { + ffi::egl::TRUE => inverted != 0, + ffi::egl::FALSE => true, + _ => unreachable!(), + } + }; let mut images = Vec::with_capacity(format.num_planes()); for i in 0..format.num_planes() { @@ -767,7 +783,9 @@ impl EGLBufferReader { display: self.display.clone(), width: width as u32, height: height as u32, - y_inverted: inverted != 0, + // y_inverted is negated here because the gles2 renderer + // already inverts the buffer during rendering. + y_inverted: !y_inverted, format, images, })