From 3e2f2afa28f768d22723b5fb9c3a9759f66564e5 Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Sat, 10 Jul 2021 01:56:42 +0200 Subject: [PATCH] egl: Let the native surface handle attributes The required surface attributes for egl surface creation might be very dependent on the used egl platform. Therefor let the native surface type handle the attributes instead of deriving them from a set of properties. --- src/backend/egl/context.rs | 4 ---- src/backend/egl/native.rs | 14 +++++++++----- src/backend/egl/surface.rs | 34 +++------------------------------- src/backend/winit.rs | 2 -- 4 files changed, 12 insertions(+), 42 deletions(-) diff --git a/src/backend/egl/context.rs b/src/backend/egl/context.rs index 654e770..92a28c2 100644 --- a/src/backend/egl/context.rs +++ b/src/backend/egl/context.rs @@ -300,9 +300,6 @@ pub struct PixelFormatRequirements { pub depth_bits: Option, /// Minimum number of bits for the depth buffer. `None` means "don't care". The default value is `None`. pub stencil_bits: Option, - /// If `true`, only double-buffered formats will be considered. If `false`, only single-buffer formats. - /// `None` means "don't care". The default is `None`. - pub double_buffer: Option, /// Contains the minimum number of samples per pixel in the color, depth and stencil buffers. /// `None` means "don't care". Default is `None`. A value of `Some(0)` indicates that multisampling must not be enabled. pub multisampling: Option, @@ -317,7 +314,6 @@ impl Default for PixelFormatRequirements { alpha_bits: Some(8), depth_bits: Some(24), stencil_bits: Some(8), - double_buffer: Some(true), multisampling: None, } } diff --git a/src/backend/egl/native.rs b/src/backend/egl/native.rs index 81d7e9f..f9aedde 100644 --- a/src/backend/egl/native.rs +++ b/src/backend/egl/native.rs @@ -182,7 +182,6 @@ pub unsafe trait EGLNativeSurface: Send + Sync { &self, display: &Arc, config_id: ffi::egl::types::EGLConfig, - surface_attributes: &[c_int], ) -> Result<*const c_void, super::EGLError>; /// Will be called to check if any internal resources will need @@ -224,6 +223,13 @@ pub unsafe trait EGLNativeSurface: Send + Sync { } } +#[cfg(feature = "backend_winit")] +static WINIT_SURFACE_ATTRIBUTES: [c_int; 3] = [ + ffi::egl::RENDER_BUFFER as c_int, + ffi::egl::BACK_BUFFER as c_int, + ffi::egl::NONE as c_int, +]; + #[cfg(feature = "backend_winit")] /// Typed Xlib window for the `X11` backend #[derive(Debug)] @@ -235,7 +241,6 @@ unsafe impl EGLNativeSurface for XlibWindow { &self, display: &Arc, config_id: ffi::egl::types::EGLConfig, - surface_attributes: &[c_int], ) -> Result<*const c_void, super::EGLError> { wrap_egl_call(|| unsafe { let mut id = self.0; @@ -243,7 +248,7 @@ unsafe impl EGLNativeSurface for XlibWindow { display.handle, config_id, (&mut id) as *mut std::os::raw::c_ulong as *mut _, - surface_attributes.as_ptr(), + WINIT_SURFACE_ATTRIBUTES.as_ptr(), ) }) } @@ -255,14 +260,13 @@ unsafe impl EGLNativeSurface for wegl::WlEglSurface { &self, display: &Arc, config_id: ffi::egl::types::EGLConfig, - surface_attributes: &[c_int], ) -> Result<*const c_void, super::EGLError> { wrap_egl_call(|| unsafe { ffi::egl::CreatePlatformWindowSurfaceEXT( display.handle, config_id, self.ptr() as *mut _, - surface_attributes.as_ptr(), + WINIT_SURFACE_ATTRIBUTES.as_ptr(), ) }) } diff --git a/src/backend/egl/surface.rs b/src/backend/egl/surface.rs index 9508dde..bbb4d24 100644 --- a/src/backend/egl/surface.rs +++ b/src/backend/egl/surface.rs @@ -6,8 +6,6 @@ use std::sync::{ Arc, }; -use nix::libc::c_int; - use crate::backend::egl::{ display::{EGLDisplay, EGLDisplayHandle, PixelFormat}, ffi, @@ -15,7 +13,7 @@ use crate::backend::egl::{ EGLError, SwapBuffersError, }; -use slog::{debug, o, trace}; +use slog::{debug, o}; /// EGL surface of a given EGL context for rendering pub struct EGLSurface { @@ -24,7 +22,6 @@ pub struct EGLSurface { pub(crate) surface: AtomicPtr, config_id: ffi::egl::types::EGLConfig, pixel_format: PixelFormat, - surface_attributes: Vec, logger: ::slog::Logger, } @@ -36,7 +33,6 @@ impl fmt::Debug for EGLSurface { .field("surface", &self.surface) .field("config_id", &self.config_id) .field("pixel_format", &self.pixel_format) - .field("surface_attributes", &self.surface_attributes) .field("logger", &self.logger) .finish() } @@ -58,7 +54,6 @@ impl EGLSurface { pub fn new( display: &EGLDisplay, pixel_format: PixelFormat, - double_buffered: Option, config: ffi::egl::types::EGLConfig, native: N, log: L, @@ -69,29 +64,7 @@ impl EGLSurface { { let log = crate::slog_or_fallback(log.into()).new(o!("smithay_module" => "renderer_egl")); - let surface_attributes = { - let mut out: Vec = Vec::with_capacity(3); - - match double_buffered { - Some(true) => { - trace!(log, "Setting RENDER_BUFFER to BACK_BUFFER"); - out.push(ffi::egl::RENDER_BUFFER as c_int); - out.push(ffi::egl::BACK_BUFFER as c_int); - } - Some(false) => { - trace!(log, "Setting RENDER_BUFFER to SINGLE_BUFFER"); - out.push(ffi::egl::RENDER_BUFFER as c_int); - out.push(ffi::egl::SINGLE_BUFFER as c_int); - } - None => {} - } - - out.push(ffi::egl::NONE as i32); - out - }; - - let surface = native.create(&display.display, config, &surface_attributes)?; - + let surface = native.create(&display.display, config)?; if surface == ffi::egl::NO_SURFACE { return Err(EGLError::BadSurface); } @@ -102,7 +75,6 @@ impl EGLSurface { surface: AtomicPtr::new(surface as *mut _), config_id: config, pixel_format, - surface_attributes, logger: log, }) } @@ -129,7 +101,7 @@ impl EGLSurface { .compare_exchange( surface, self.native - .create(&self.display, self.config_id, &self.surface_attributes) + .create(&self.display, self.config_id) .map_err(SwapBuffersError::EGLCreateSurface)? as *mut _, Ordering::SeqCst, Ordering::SeqCst, diff --git a/src/backend/winit.rs b/src/backend/winit.rs index e62200a..b88b7c3 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -172,7 +172,6 @@ where EGLSurface::new( &display, context.pixel_format().unwrap(), - reqs.double_buffer, context.config_id(), surface, log.clone(), @@ -183,7 +182,6 @@ where EGLSurface::new( &display, context.pixel_format().unwrap(), - reqs.double_buffer, context.config_id(), xlib_window, log.clone(),