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.
This commit is contained in:
Victor Brekenfeld 2021-07-10 01:56:42 +02:00
parent d97a9f9970
commit 3e2f2afa28
4 changed files with 12 additions and 42 deletions

View File

@ -300,9 +300,6 @@ pub struct PixelFormatRequirements {
pub depth_bits: Option<u8>,
/// Minimum number of bits for the depth buffer. `None` means "don't care". The default value is `None`.
pub stencil_bits: Option<u8>,
/// 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<bool>,
/// 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<u16>,
@ -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,
}
}

View File

@ -182,7 +182,6 @@ pub unsafe trait EGLNativeSurface: Send + Sync {
&self,
display: &Arc<EGLDisplayHandle>,
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<EGLDisplayHandle>,
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<EGLDisplayHandle>,
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(),
)
})
}

View File

@ -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<nix::libc::c_void>,
config_id: ffi::egl::types::EGLConfig,
pixel_format: PixelFormat,
surface_attributes: Vec<c_int>,
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<N, L>(
display: &EGLDisplay,
pixel_format: PixelFormat,
double_buffered: Option<bool>,
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<c_int> = 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,

View File

@ -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(),