From c88b14f72564321892914f53f7c3ef657fc39fa8 Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Tue, 18 May 2021 21:17:33 +0200 Subject: [PATCH] fix compiling with limited feature sets --- src/backend/drm/mod.rs | 6 +++++- src/backend/drm/render.rs | 3 ++- src/backend/egl/display.rs | 4 +++- src/backend/renderer/gles2/mod.rs | 31 +++++++++++++++++++++++++++++-- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/backend/drm/mod.rs b/src/backend/drm/mod.rs index 148c77f..6273360 100644 --- a/src/backend/drm/mod.rs +++ b/src/backend/drm/mod.rs @@ -62,12 +62,16 @@ pub(crate) mod device; pub(self) mod error; +#[cfg(feature = "backend_gbm")] mod render; +#[cfg(feature = "backend_session")] pub(self) mod session; pub(self) mod surface; pub use device::{device_bind, DevPath, DeviceHandler, DrmDevice, DrmSource, Planes}; pub use error::Error as DrmError; +#[cfg(feature = "backend_gbm")] pub use render::{DrmRenderSurface, Error as DrmRenderError}; -pub use session::DrmDeviceObserver; +#[cfg(feature = "backend_session")] +pub use session::{DrmDeviceObserver, DrmSurfaceObserver}; pub use surface::DrmSurface; diff --git a/src/backend/drm/render.rs b/src/backend/drm/render.rs index b13c777..3b1e84b 100644 --- a/src/backend/drm/render.rs +++ b/src/backend/drm/render.rs @@ -19,6 +19,7 @@ use crate::backend::{ dmabuf::{AsDmabuf, Dmabuf}, Allocator, Buffer, Format, Fourcc, Modifier, Slot, Swapchain, }, + #[cfg(all(feature = "backend_egl", feature = "wayland_frontend"))] egl::display::EGLBufferReader, }; @@ -351,7 +352,7 @@ where self.renderer.shm_formats() } - #[cfg(feature = "wayland_frontend")] + #[cfg(all(feature = "backend_egl", feature = "wayland_frontend"))] fn import_buffer( &mut self, buffer: &wl_buffer::WlBuffer, diff --git a/src/backend/egl/display.rs b/src/backend/egl/display.rs index 4e7e79c..10647d2 100644 --- a/src/backend/egl/display.rs +++ b/src/backend/egl/display.rs @@ -20,8 +20,10 @@ use crate::backend::egl::{ ffi, ffi::egl::types::EGLImage, native::EGLNativeDisplay, - wrap_egl_call, BufferAccessError, EGLBuffer, EGLError, Error, Format, + wrap_egl_call, EGLError, Error, Format, }; +#[cfg(feature = "wayland_frontend")] +use crate::backend::egl::{BufferAccessError, EGLBuffer}; /// Wrapper around [`ffi::EGLDisplay`](ffi::egl::types::EGLDisplay) to ensure display is only destroyed /// once all resources bound to it have been dropped. diff --git a/src/backend/renderer/gles2/mod.rs b/src/backend/renderer/gles2/mod.rs index ddbf4a4..8fb0e49 100644 --- a/src/backend/renderer/gles2/mod.rs +++ b/src/backend/renderer/gles2/mod.rs @@ -25,13 +25,16 @@ use crate::backend::allocator::{ Format, }; use crate::backend::egl::{ - display::EGLBufferReader, ffi::egl::{self as ffi_egl, types::EGLImage}, EGLContext, EGLSurface, + ffi::egl::{self as ffi_egl, types::EGLImage}, EGLContext, EGLSurface, Format as EGLFormat, MakeCurrentError, }; use crate::backend::SwapBuffersError; #[cfg(feature = "wayland_frontend")] -use crate::wayland::compositor::Damage; +use crate::{ + backend::egl::display::EGLBufferReader, + wayland::compositor::Damage, +}; #[cfg(feature = "wayland_frontend")] use wayland_server::protocol::{wl_buffer, wl_shm}; #[cfg(feature = "wayland_frontend")] @@ -112,21 +115,25 @@ struct Gles2Buffer { _dmabuf: Dmabuf, } +#[cfg(feature = "wayland_frontend")] struct BufferEntry { id: u32, buffer: wl_buffer::WlBuffer, } +#[cfg(feature = "wayland_frontend")] impl std::hash::Hash for BufferEntry { fn hash(&self, hasher: &mut H) { self.id.hash(hasher); } } +#[cfg(feature = "wayland_frontend")] impl PartialEq for BufferEntry { fn eq(&self, other: &Self) -> bool { self.buffer == other.buffer } } +#[cfg(feature = "wayland_frontend")] impl Eq for BufferEntry {} /// A renderer utilizing OpenGL ES 2 @@ -138,6 +145,7 @@ pub struct Gles2Renderer { current_projection: Option>, extensions: Vec, programs: [Gles2Program; shaders::FRAGMENT_COUNT], + #[cfg(feature = "wayland_frontend")] textures: HashMap, gl: ffi::Gles2, egl: EGLContext, @@ -211,6 +219,7 @@ pub enum Gles2Error { } impl From for SwapBuffersError { + #[cfg(feature = "wayland_frontend")] fn from(err: Gles2Error) -> SwapBuffersError { match err { x @ Gles2Error::ShaderCompileError(_) @@ -227,6 +236,19 @@ impl From for SwapBuffersError { | x @ Gles2Error::EGLBufferAccessError(_) => SwapBuffersError::TemporaryFailure(Box::new(x)), } } + #[cfg(not(feature = "wayland_frontend"))] + fn from(err: Gles2Error) -> SwapBuffersError { + match err { + x @ Gles2Error::ShaderCompileError(_) + | x @ Gles2Error::ProgramLinkError + | x @ Gles2Error::GLFunctionLoaderError + | x @ Gles2Error::GLExtensionNotSupported(_) + | x @ Gles2Error::UnconstraintRenderingOperation => SwapBuffersError::ContextLost(Box::new(x)), + Gles2Error::ContextActivationError(err) => err.into(), + x @ Gles2Error::FramebufferBindingError + | x @ Gles2Error::BindBufferEGLError(_) => SwapBuffersError::TemporaryFailure(Box::new(x)), + } + } } extern "system" fn gl_debug_log( @@ -422,6 +444,7 @@ impl Gles2Renderer { target_buffer: None, target_surface: None, buffers: Vec::new(), + #[cfg(feature = "wayland_frontend")] textures: HashMap::new(), current_projection: None, destruction_callback: rx, @@ -447,6 +470,7 @@ impl Gles2Renderer { fn cleanup(&mut self) -> Result<(), Gles2Error> { self.make_current()?; + #[cfg(feature = "wayland_frontend")] self.textures.retain(|entry, tex| entry.buffer.as_ref().is_alive()); for resource in self.destruction_callback.try_iter() { match resource { @@ -523,6 +547,7 @@ impl Gles2Renderer { .TexParameteri(ffi::TEXTURE_2D, ffi::TEXTURE_WRAP_T, ffi::CLAMP_TO_EDGE as i32); self.gl.PixelStorei(ffi::UNPACK_ROW_LENGTH, stride / pixelsize); if let Some(region) = damage { + trace!(self.logger, "Uploading partial shm texture for {:?}", buffer); self.gl.PixelStorei(ffi::UNPACK_SKIP_PIXELS, region.x); self.gl.PixelStorei(ffi::UNPACK_SKIP_ROWS, region.y); self.gl.TexSubImage2D( @@ -539,6 +564,7 @@ impl Gles2Renderer { self.gl.PixelStorei(ffi::UNPACK_SKIP_PIXELS, 0); self.gl.PixelStorei(ffi::UNPACK_SKIP_ROWS, 0); } else { + trace!(self.logger, "Uploading shm texture for {:?}", buffer); self.gl.TexImage2D( ffi::TEXTURE_2D, 0, @@ -608,6 +634,7 @@ impl Gles2Renderer { }) } + #[cfg(feature = "wayland_frontend")] fn existing_texture( &self, buffer: &wl_buffer::WlBuffer,