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:
parent
d97a9f9970
commit
3e2f2afa28
|
@ -300,9 +300,6 @@ pub struct PixelFormatRequirements {
|
||||||
pub depth_bits: Option<u8>,
|
pub depth_bits: Option<u8>,
|
||||||
/// Minimum number of bits for the depth buffer. `None` means "don't care". The default value is `None`.
|
/// Minimum number of bits for the depth buffer. `None` means "don't care". The default value is `None`.
|
||||||
pub stencil_bits: Option<u8>,
|
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.
|
/// 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.
|
/// `None` means "don't care". Default is `None`. A value of `Some(0)` indicates that multisampling must not be enabled.
|
||||||
pub multisampling: Option<u16>,
|
pub multisampling: Option<u16>,
|
||||||
|
@ -317,7 +314,6 @@ impl Default for PixelFormatRequirements {
|
||||||
alpha_bits: Some(8),
|
alpha_bits: Some(8),
|
||||||
depth_bits: Some(24),
|
depth_bits: Some(24),
|
||||||
stencil_bits: Some(8),
|
stencil_bits: Some(8),
|
||||||
double_buffer: Some(true),
|
|
||||||
multisampling: None,
|
multisampling: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,7 +182,6 @@ pub unsafe trait EGLNativeSurface: Send + Sync {
|
||||||
&self,
|
&self,
|
||||||
display: &Arc<EGLDisplayHandle>,
|
display: &Arc<EGLDisplayHandle>,
|
||||||
config_id: ffi::egl::types::EGLConfig,
|
config_id: ffi::egl::types::EGLConfig,
|
||||||
surface_attributes: &[c_int],
|
|
||||||
) -> Result<*const c_void, super::EGLError>;
|
) -> Result<*const c_void, super::EGLError>;
|
||||||
|
|
||||||
/// Will be called to check if any internal resources will need
|
/// 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")]
|
#[cfg(feature = "backend_winit")]
|
||||||
/// Typed Xlib window for the `X11` backend
|
/// Typed Xlib window for the `X11` backend
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -235,7 +241,6 @@ unsafe impl EGLNativeSurface for XlibWindow {
|
||||||
&self,
|
&self,
|
||||||
display: &Arc<EGLDisplayHandle>,
|
display: &Arc<EGLDisplayHandle>,
|
||||||
config_id: ffi::egl::types::EGLConfig,
|
config_id: ffi::egl::types::EGLConfig,
|
||||||
surface_attributes: &[c_int],
|
|
||||||
) -> Result<*const c_void, super::EGLError> {
|
) -> Result<*const c_void, super::EGLError> {
|
||||||
wrap_egl_call(|| unsafe {
|
wrap_egl_call(|| unsafe {
|
||||||
let mut id = self.0;
|
let mut id = self.0;
|
||||||
|
@ -243,7 +248,7 @@ unsafe impl EGLNativeSurface for XlibWindow {
|
||||||
display.handle,
|
display.handle,
|
||||||
config_id,
|
config_id,
|
||||||
(&mut id) as *mut std::os::raw::c_ulong as *mut _,
|
(&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,
|
&self,
|
||||||
display: &Arc<EGLDisplayHandle>,
|
display: &Arc<EGLDisplayHandle>,
|
||||||
config_id: ffi::egl::types::EGLConfig,
|
config_id: ffi::egl::types::EGLConfig,
|
||||||
surface_attributes: &[c_int],
|
|
||||||
) -> Result<*const c_void, super::EGLError> {
|
) -> Result<*const c_void, super::EGLError> {
|
||||||
wrap_egl_call(|| unsafe {
|
wrap_egl_call(|| unsafe {
|
||||||
ffi::egl::CreatePlatformWindowSurfaceEXT(
|
ffi::egl::CreatePlatformWindowSurfaceEXT(
|
||||||
display.handle,
|
display.handle,
|
||||||
config_id,
|
config_id,
|
||||||
self.ptr() as *mut _,
|
self.ptr() as *mut _,
|
||||||
surface_attributes.as_ptr(),
|
WINIT_SURFACE_ATTRIBUTES.as_ptr(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,6 @@ use std::sync::{
|
||||||
Arc,
|
Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use nix::libc::c_int;
|
|
||||||
|
|
||||||
use crate::backend::egl::{
|
use crate::backend::egl::{
|
||||||
display::{EGLDisplay, EGLDisplayHandle, PixelFormat},
|
display::{EGLDisplay, EGLDisplayHandle, PixelFormat},
|
||||||
ffi,
|
ffi,
|
||||||
|
@ -15,7 +13,7 @@ use crate::backend::egl::{
|
||||||
EGLError, SwapBuffersError,
|
EGLError, SwapBuffersError,
|
||||||
};
|
};
|
||||||
|
|
||||||
use slog::{debug, o, trace};
|
use slog::{debug, o};
|
||||||
|
|
||||||
/// EGL surface of a given EGL context for rendering
|
/// EGL surface of a given EGL context for rendering
|
||||||
pub struct EGLSurface {
|
pub struct EGLSurface {
|
||||||
|
@ -24,7 +22,6 @@ pub struct EGLSurface {
|
||||||
pub(crate) surface: AtomicPtr<nix::libc::c_void>,
|
pub(crate) surface: AtomicPtr<nix::libc::c_void>,
|
||||||
config_id: ffi::egl::types::EGLConfig,
|
config_id: ffi::egl::types::EGLConfig,
|
||||||
pixel_format: PixelFormat,
|
pixel_format: PixelFormat,
|
||||||
surface_attributes: Vec<c_int>,
|
|
||||||
logger: ::slog::Logger,
|
logger: ::slog::Logger,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +33,6 @@ impl fmt::Debug for EGLSurface {
|
||||||
.field("surface", &self.surface)
|
.field("surface", &self.surface)
|
||||||
.field("config_id", &self.config_id)
|
.field("config_id", &self.config_id)
|
||||||
.field("pixel_format", &self.pixel_format)
|
.field("pixel_format", &self.pixel_format)
|
||||||
.field("surface_attributes", &self.surface_attributes)
|
|
||||||
.field("logger", &self.logger)
|
.field("logger", &self.logger)
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
|
@ -58,7 +54,6 @@ impl EGLSurface {
|
||||||
pub fn new<N, L>(
|
pub fn new<N, L>(
|
||||||
display: &EGLDisplay,
|
display: &EGLDisplay,
|
||||||
pixel_format: PixelFormat,
|
pixel_format: PixelFormat,
|
||||||
double_buffered: Option<bool>,
|
|
||||||
config: ffi::egl::types::EGLConfig,
|
config: ffi::egl::types::EGLConfig,
|
||||||
native: N,
|
native: N,
|
||||||
log: L,
|
log: L,
|
||||||
|
@ -69,29 +64,7 @@ impl EGLSurface {
|
||||||
{
|
{
|
||||||
let log = crate::slog_or_fallback(log.into()).new(o!("smithay_module" => "renderer_egl"));
|
let log = crate::slog_or_fallback(log.into()).new(o!("smithay_module" => "renderer_egl"));
|
||||||
|
|
||||||
let surface_attributes = {
|
let surface = native.create(&display.display, config)?;
|
||||||
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)?;
|
|
||||||
|
|
||||||
if surface == ffi::egl::NO_SURFACE {
|
if surface == ffi::egl::NO_SURFACE {
|
||||||
return Err(EGLError::BadSurface);
|
return Err(EGLError::BadSurface);
|
||||||
}
|
}
|
||||||
|
@ -102,7 +75,6 @@ impl EGLSurface {
|
||||||
surface: AtomicPtr::new(surface as *mut _),
|
surface: AtomicPtr::new(surface as *mut _),
|
||||||
config_id: config,
|
config_id: config,
|
||||||
pixel_format,
|
pixel_format,
|
||||||
surface_attributes,
|
|
||||||
logger: log,
|
logger: log,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -129,7 +101,7 @@ impl EGLSurface {
|
||||||
.compare_exchange(
|
.compare_exchange(
|
||||||
surface,
|
surface,
|
||||||
self.native
|
self.native
|
||||||
.create(&self.display, self.config_id, &self.surface_attributes)
|
.create(&self.display, self.config_id)
|
||||||
.map_err(SwapBuffersError::EGLCreateSurface)? as *mut _,
|
.map_err(SwapBuffersError::EGLCreateSurface)? as *mut _,
|
||||||
Ordering::SeqCst,
|
Ordering::SeqCst,
|
||||||
Ordering::SeqCst,
|
Ordering::SeqCst,
|
||||||
|
|
|
@ -172,7 +172,6 @@ where
|
||||||
EGLSurface::new(
|
EGLSurface::new(
|
||||||
&display,
|
&display,
|
||||||
context.pixel_format().unwrap(),
|
context.pixel_format().unwrap(),
|
||||||
reqs.double_buffer,
|
|
||||||
context.config_id(),
|
context.config_id(),
|
||||||
surface,
|
surface,
|
||||||
log.clone(),
|
log.clone(),
|
||||||
|
@ -183,7 +182,6 @@ where
|
||||||
EGLSurface::new(
|
EGLSurface::new(
|
||||||
&display,
|
&display,
|
||||||
context.pixel_format().unwrap(),
|
context.pixel_format().unwrap(),
|
||||||
reqs.double_buffer,
|
|
||||||
context.config_id(),
|
context.config_id(),
|
||||||
xlib_window,
|
xlib_window,
|
||||||
log.clone(),
|
log.clone(),
|
||||||
|
|
Loading…
Reference in New Issue