Rename WaylandEGLDisplay to EGLBufferReader

This commit is contained in:
Chandler Newman 2020-04-15 21:19:20 +01:00
parent a4d2043b7e
commit f7c05fa064
8 changed files with 41 additions and 38 deletions

View File

@ -3,7 +3,7 @@ use std::{cell::RefCell, rc::Rc};
use slog::Logger; use slog::Logger;
#[cfg(feature = "egl")] #[cfg(feature = "egl")]
use smithay::backend::egl::display::WaylandEGLDisplay; use smithay::backend::egl::display::EGLBufferReader;
use smithay::{ use smithay::{
reexports::wayland_server::protocol::wl_buffer::WlBuffer, reexports::wayland_server::protocol::wl_buffer::WlBuffer,
wayland::shm::with_buffer_contents as shm_buffer_contents, wayland::shm::with_buffer_contents as shm_buffer_contents,
@ -13,15 +13,18 @@ use smithay::{
#[derive(Clone)] #[derive(Clone)]
pub struct BufferUtils { pub struct BufferUtils {
#[cfg(feature = "egl")] #[cfg(feature = "egl")]
egl_display: Rc<RefCell<Option<WaylandEGLDisplay>>>, egl_buffer_reader: Rc<RefCell<Option<EGLBufferReader>>>,
log: Logger, log: Logger,
} }
impl BufferUtils { impl BufferUtils {
/// Creates a new `BufferUtils`. /// Creates a new `BufferUtils`.
#[cfg(feature = "egl")] #[cfg(feature = "egl")]
pub fn new(egl_display: Rc<RefCell<Option<WaylandEGLDisplay>>>, log: Logger) -> Self { pub fn new(egl_buffer_reader: Rc<RefCell<Option<EGLBufferReader>>>, log: Logger) -> Self {
Self { egl_display, log } Self {
egl_buffer_reader,
log,
}
} }
/// Creates a new `BufferUtils`. /// Creates a new `BufferUtils`.
@ -34,7 +37,7 @@ impl BufferUtils {
#[cfg(feature = "egl")] #[cfg(feature = "egl")]
pub fn dimensions(&self, buffer: &WlBuffer) -> Option<(i32, i32)> { pub fn dimensions(&self, buffer: &WlBuffer) -> Option<(i32, i32)> {
// Try to retrieve the EGL dimensions of this buffer, and, if that fails, the shm dimensions. // Try to retrieve the EGL dimensions of this buffer, and, if that fails, the shm dimensions.
self.egl_display self.egl_buffer_reader
.borrow() .borrow()
.as_ref() .as_ref()
.and_then(|display| display.egl_buffer_dimensions(buffer)) .and_then(|display| display.egl_buffer_dimensions(buffer))

View File

@ -12,7 +12,7 @@ use glium::{
use slog::Logger; use slog::Logger;
#[cfg(feature = "egl")] #[cfg(feature = "egl")]
use smithay::backend::egl::display::WaylandEGLDisplay; use smithay::backend::egl::display::EGLBufferReader;
use smithay::{ use smithay::{
backend::{ backend::{
egl::{BufferAccessError, EGLImages, Format}, egl::{BufferAccessError, EGLImages, Format},
@ -44,7 +44,7 @@ pub struct GliumDrawer<F: GLGraphicsBackend + 'static> {
index_buffer: glium::IndexBuffer<u16>, index_buffer: glium::IndexBuffer<u16>,
programs: [glium::Program; shaders::FRAGMENT_COUNT], programs: [glium::Program; shaders::FRAGMENT_COUNT],
#[cfg(feature = "egl")] #[cfg(feature = "egl")]
egl_display: Rc<RefCell<Option<WaylandEGLDisplay>>>, egl_buffer_reader: Rc<RefCell<Option<EGLBufferReader>>>,
log: Logger, log: Logger,
} }
@ -58,7 +58,7 @@ impl<T: Into<GliumGraphicsBackend<T>> + GLGraphicsBackend + 'static> GliumDrawer
#[cfg(feature = "egl")] #[cfg(feature = "egl")]
pub fn init( pub fn init(
backend: T, backend: T,
egl_display: Rc<RefCell<Option<WaylandEGLDisplay>>>, egl_buffer_reader: Rc<RefCell<Option<EGLBufferReader>>>,
log: Logger, log: Logger,
) -> GliumDrawer<T> { ) -> GliumDrawer<T> {
let display = backend.into(); let display = backend.into();
@ -98,7 +98,7 @@ impl<T: Into<GliumGraphicsBackend<T>> + GLGraphicsBackend + 'static> GliumDrawer
vertex_buffer, vertex_buffer,
index_buffer, index_buffer,
programs, programs,
egl_display, egl_buffer_reader,
log, log,
} }
} }
@ -151,7 +151,7 @@ impl<F: GLGraphicsBackend + 'static> GliumDrawer<F> {
#[cfg(feature = "egl")] #[cfg(feature = "egl")]
pub fn texture_from_buffer(&self, buffer: wl_buffer::WlBuffer) -> Result<TextureMetadata, ()> { pub fn texture_from_buffer(&self, buffer: wl_buffer::WlBuffer) -> Result<TextureMetadata, ()> {
// try to retrieve the egl contents of this buffer // try to retrieve the egl contents of this buffer
let images = if let Some(display) = &self.egl_display.borrow().as_ref() { let images = if let Some(display) = &self.egl_buffer_reader.borrow().as_ref() {
display.egl_buffer_contents(buffer) display.egl_buffer_contents(buffer)
} else { } else {
Err(BufferAccessError::NotManaged(buffer)) Err(BufferAccessError::NotManaged(buffer))

View File

@ -15,7 +15,7 @@ use glium::Surface as GliumSurface;
use slog::Logger; use slog::Logger;
#[cfg(feature = "egl")] #[cfg(feature = "egl")]
use smithay::backend::egl::{display::WaylandEGLDisplay, EGLGraphicsBackend}; use smithay::backend::egl::{display::EGLBufferReader, EGLGraphicsBackend};
use smithay::{ use smithay::{
backend::{ backend::{
drm::{ drm::{
@ -85,10 +85,10 @@ pub fn run_udev(mut display: Display, mut event_loop: EventLoop<AnvilState>, log
::std::env::set_var("WAYLAND_DISPLAY", name); ::std::env::set_var("WAYLAND_DISPLAY", name);
#[cfg(feature = "egl")] #[cfg(feature = "egl")]
let active_egl_context = Rc::new(RefCell::new(None)); let egl_buffer_reader = Rc::new(RefCell::new(None));
#[cfg(feature = "egl")] #[cfg(feature = "egl")]
let buffer_utils = BufferUtils::new(active_egl_context.clone(), log.clone()); let buffer_utils = BufferUtils::new(egl_buffer_reader.clone(), log.clone());
#[cfg(not(feature = "egl"))] #[cfg(not(feature = "egl"))]
let buffer_utils = BufferUtils::new(log.clone()); let buffer_utils = BufferUtils::new(log.clone());
@ -127,7 +127,7 @@ pub fn run_udev(mut display: Display, mut event_loop: EventLoop<AnvilState>, log
UdevHandlerImpl { UdevHandlerImpl {
compositor_token, compositor_token,
#[cfg(feature = "egl")] #[cfg(feature = "egl")]
active_egl_context, egl_buffer_reader,
session: session.clone(), session: session.clone(),
backends: HashMap::new(), backends: HashMap::new(),
display: display.clone(), display: display.clone(),
@ -294,7 +294,7 @@ struct BackendData<S: SessionNotifier> {
struct UdevHandlerImpl<S: SessionNotifier, Data: 'static> { struct UdevHandlerImpl<S: SessionNotifier, Data: 'static> {
compositor_token: CompositorToken<Roles>, compositor_token: CompositorToken<Roles>,
#[cfg(feature = "egl")] #[cfg(feature = "egl")]
active_egl_context: Rc<RefCell<Option<WaylandEGLDisplay>>>, egl_buffer_reader: Rc<RefCell<Option<EGLBufferReader>>>,
session: AutoSession, session: AutoSession,
backends: HashMap<dev_t, BackendData<S>>, backends: HashMap<dev_t, BackendData<S>>,
display: Rc<RefCell<Display>>, display: Rc<RefCell<Display>>,
@ -313,7 +313,7 @@ impl<S: SessionNotifier, Data: 'static> UdevHandlerImpl<S, Data> {
#[cfg(feature = "egl")] #[cfg(feature = "egl")]
pub fn scan_connectors( pub fn scan_connectors(
device: &mut RenderDevice, device: &mut RenderDevice,
egl_display: Rc<RefCell<Option<WaylandEGLDisplay>>>, egl_buffer_reader: Rc<RefCell<Option<EGLBufferReader>>>,
logger: &::slog::Logger, logger: &::slog::Logger,
) -> HashMap<crtc::Handle, GliumDrawer<RenderSurface>> { ) -> HashMap<crtc::Handle, GliumDrawer<RenderSurface>> {
// Get a set of all modesetting resource handles (excluding planes): // Get a set of all modesetting resource handles (excluding planes):
@ -343,7 +343,7 @@ impl<S: SessionNotifier, Data: 'static> UdevHandlerImpl<S, Data> {
if let Entry::Vacant(entry) = backends.entry(crtc) { if let Entry::Vacant(entry) = backends.entry(crtc) {
let renderer = GliumDrawer::init( let renderer = GliumDrawer::init(
device.create_surface(crtc).unwrap(), device.create_surface(crtc).unwrap(),
egl_display.clone(), egl_buffer_reader.clone(),
logger.clone(), logger.clone(),
); );
@ -419,7 +419,7 @@ impl<S: SessionNotifier, Data: 'static> UdevHandler for UdevHandlerImpl<S, Data>
#[cfg(feature = "egl")] #[cfg(feature = "egl")]
{ {
if path.canonicalize().ok() == self.primary_gpu { if path.canonicalize().ok() == self.primary_gpu {
*self.active_egl_context.borrow_mut() = *self.egl_buffer_reader.borrow_mut() =
device.bind_wl_display(&*self.display.borrow()).ok(); device.bind_wl_display(&*self.display.borrow()).ok();
} }
} }
@ -427,7 +427,7 @@ impl<S: SessionNotifier, Data: 'static> UdevHandler for UdevHandlerImpl<S, Data>
#[cfg(feature = "egl")] #[cfg(feature = "egl")]
let backends = Rc::new(RefCell::new(UdevHandlerImpl::<S, Data>::scan_connectors( let backends = Rc::new(RefCell::new(UdevHandlerImpl::<S, Data>::scan_connectors(
&mut device, &mut device,
self.active_egl_context.clone(), self.egl_buffer_reader.clone(),
&self.logger, &self.logger,
))); )));
@ -491,7 +491,7 @@ impl<S: SessionNotifier, Data: 'static> UdevHandler for UdevHandlerImpl<S, Data>
#[cfg(feature = "egl")] #[cfg(feature = "egl")]
let new_backends = UdevHandlerImpl::<S, Data>::scan_connectors( let new_backends = UdevHandlerImpl::<S, Data>::scan_connectors(
&mut (*evented).0, &mut (*evented).0,
self.active_egl_context.clone(), self.egl_buffer_reader.clone(),
&self.logger, &self.logger,
); );
#[cfg(not(feature = "egl"))] #[cfg(not(feature = "egl"))]
@ -532,7 +532,7 @@ impl<S: SessionNotifier, Data: 'static> UdevHandler for UdevHandlerImpl<S, Data>
#[cfg(feature = "egl")] #[cfg(feature = "egl")]
{ {
if device.dev_path().and_then(|path| path.canonicalize().ok()) == self.primary_gpu { if device.dev_path().and_then(|path| path.canonicalize().ok()) == self.primary_gpu {
*self.active_egl_context.borrow_mut() = None; *self.egl_buffer_reader.borrow_mut() = None;
} }
} }

View File

@ -37,10 +37,10 @@ pub fn run_winit(
let (renderer, mut input) = winit::init(log.clone()).map_err(|_| ())?; let (renderer, mut input) = winit::init(log.clone()).map_err(|_| ())?;
#[cfg(feature = "egl")] #[cfg(feature = "egl")]
let egl_display = Rc::new(RefCell::new( let egl_buffer_reader = Rc::new(RefCell::new(
if let Ok(egl_display) = renderer.bind_wl_display(&display) { if let Ok(egl_buffer_reader) = renderer.bind_wl_display(&display) {
info!(log, "EGL hardware-acceleration enabled"); info!(log, "EGL hardware-acceleration enabled");
Some(egl_display) Some(egl_buffer_reader)
} else { } else {
None None
}, },
@ -48,12 +48,12 @@ pub fn run_winit(
let (w, h) = renderer.get_framebuffer_dimensions(); let (w, h) = renderer.get_framebuffer_dimensions();
#[cfg(feature = "egl")] #[cfg(feature = "egl")]
let drawer = GliumDrawer::init(renderer, egl_display.clone(), log.clone()); let drawer = GliumDrawer::init(renderer, egl_buffer_reader.clone(), log.clone());
#[cfg(not(feature = "egl"))] #[cfg(not(feature = "egl"))]
let drawer = GliumDrawer::init(renderer, log.clone()); let drawer = GliumDrawer::init(renderer, log.clone());
#[cfg(feature = "egl")] #[cfg(feature = "egl")]
let buffer_utils = BufferUtils::new(egl_display, log.clone()); let buffer_utils = BufferUtils::new(egl_buffer_reader, log.clone());
#[cfg(not(feature = "egl"))] #[cfg(not(feature = "egl"))]
let buffer_utils = BufferUtils::new(log.clone()); let buffer_utils = BufferUtils::new(log.clone());

View File

@ -19,7 +19,7 @@ use super::{Device, DeviceHandler, Surface};
use crate::backend::egl::native::{Backend, NativeDisplay, NativeSurface}; use crate::backend::egl::native::{Backend, NativeDisplay, NativeSurface};
use crate::backend::egl::Error as EGLError; use crate::backend::egl::Error as EGLError;
#[cfg(feature = "use_system_lib")] #[cfg(feature = "use_system_lib")]
use crate::backend::egl::{display::WaylandEGLDisplay, EGLGraphicsBackend}; use crate::backend::egl::{display::EGLBufferReader, EGLGraphicsBackend};
mod surface; mod surface;
pub use self::surface::*; pub use self::surface::*;
@ -199,7 +199,7 @@ where
D: Device + NativeDisplay<B, Arguments = crtc::Handle> + 'static, D: Device + NativeDisplay<B, Arguments = crtc::Handle> + 'static,
<D as Device>::Surface: NativeSurface, <D as Device>::Surface: NativeSurface,
{ {
fn bind_wl_display(&self, display: &Display) -> Result<WaylandEGLDisplay, EGLError> { fn bind_wl_display(&self, display: &Display) -> Result<EGLBufferReader, EGLError> {
self.dev.bind_wl_display(display) self.dev.bind_wl_display(display)
} }
} }

View File

@ -410,7 +410,7 @@ impl<B: native::Backend, N: native::NativeDisplay<B>> EGLGraphicsBackend for EGL
/// ///
/// This might return [`OtherEGLDisplayAlreadyBound`](ErrorKind::OtherEGLDisplayAlreadyBound) /// This might return [`OtherEGLDisplayAlreadyBound`](ErrorKind::OtherEGLDisplayAlreadyBound)
/// if called for the same [`Display`] multiple times, as only one egl display may be bound at any given time. /// if called for the same [`Display`] multiple times, as only one egl display may be bound at any given time.
fn bind_wl_display(&self, display: &Display) -> Result<WaylandEGLDisplay, Error> { fn bind_wl_display(&self, display: &Display) -> Result<EGLBufferReader, Error> {
if !self.extensions.iter().any(|s| s == "EGL_WL_bind_wayland_display") { if !self.extensions.iter().any(|s| s == "EGL_WL_bind_wayland_display") {
return Err(Error::EglExtensionNotSupported(&["EGL_WL_bind_wayland_display"])); return Err(Error::EglExtensionNotSupported(&["EGL_WL_bind_wayland_display"]));
} }
@ -418,7 +418,7 @@ impl<B: native::Backend, N: native::NativeDisplay<B>> EGLGraphicsBackend for EGL
if res == 0 { if res == 0 {
return Err(Error::OtherEGLDisplayAlreadyBound); return Err(Error::OtherEGLDisplayAlreadyBound);
} }
Ok(WaylandEGLDisplay::new( Ok(EGLBufferReader::new(
Arc::downgrade(&self.display), Arc::downgrade(&self.display),
display.c_ptr(), display.c_ptr(),
&self.extensions, &self.extensions,
@ -430,7 +430,7 @@ impl<B: native::Backend, N: native::NativeDisplay<B>> EGLGraphicsBackend for EGL
/// ///
/// Can be created by using [`EGLGraphicsBackend::bind_wl_display`]. /// Can be created by using [`EGLGraphicsBackend::bind_wl_display`].
#[cfg(feature = "use_system_lib")] #[cfg(feature = "use_system_lib")]
pub struct WaylandEGLDisplay { pub struct EGLBufferReader {
display: Weak<ffi::egl::types::EGLDisplay>, display: Weak<ffi::egl::types::EGLDisplay>,
wayland: *mut wl_display, wayland: *mut wl_display,
#[cfg(feature = "renderer_gl")] #[cfg(feature = "renderer_gl")]
@ -440,7 +440,7 @@ pub struct WaylandEGLDisplay {
} }
#[cfg(feature = "use_system_lib")] #[cfg(feature = "use_system_lib")]
impl WaylandEGLDisplay { impl EGLBufferReader {
fn new( fn new(
display: Weak<ffi::egl::types::EGLDisplay>, display: Weak<ffi::egl::types::EGLDisplay>,
wayland: *mut wl_display, wayland: *mut wl_display,
@ -609,7 +609,7 @@ impl WaylandEGLDisplay {
} }
#[cfg(feature = "use_system_lib")] #[cfg(feature = "use_system_lib")]
impl Drop for WaylandEGLDisplay { impl Drop for EGLBufferReader {
fn drop(&mut self) { fn drop(&mut self) {
if let Some(display) = self.display.upgrade() { if let Some(display) = self.display.upgrade() {
if !self.wayland.is_null() { if !self.wayland.is_null() {

View File

@ -41,7 +41,7 @@ pub mod native;
pub mod surface; pub mod surface;
pub use self::surface::EGLSurface; pub use self::surface::EGLSurface;
#[cfg(feature = "use_system_lib")] #[cfg(feature = "use_system_lib")]
use crate::backend::egl::display::WaylandEGLDisplay; use crate::backend::egl::display::EGLBufferReader;
use std::ffi::CString; use std::ffi::CString;
use std::sync::Weak; use std::sync::Weak;
@ -246,7 +246,7 @@ impl Drop for EGLImages {
} }
/// Trait any backend type may implement that allows binding a [`Display`](wayland_server::Display) /// Trait any backend type may implement that allows binding a [`Display`](wayland_server::Display)
/// to create an [`WaylandDisplay`](display::WaylandDisplay) for EGL-based [`WlBuffer`]s. /// to create an [`EGLBufferReader`](display::EGLBufferReader) for EGL-based [`WlBuffer`]s.
#[cfg(feature = "use_system_lib")] #[cfg(feature = "use_system_lib")]
pub trait EGLGraphicsBackend { pub trait EGLGraphicsBackend {
/// Binds this EGL context to the given Wayland display. /// Binds this EGL context to the given Wayland display.
@ -261,5 +261,5 @@ pub trait EGLGraphicsBackend {
/// ///
/// This might return [`OtherEGLDisplayAlreadyBound`](ErrorKind::OtherEGLDisplayAlreadyBound) /// This might return [`OtherEGLDisplayAlreadyBound`](ErrorKind::OtherEGLDisplayAlreadyBound)
/// if called for the same [`Display`] multiple times, as only one context may be bound at any given time. /// if called for the same [`Display`] multiple times, as only one context may be bound at any given time.
fn bind_wl_display(&self, display: &Display) -> Result<WaylandEGLDisplay, Error>; fn bind_wl_display(&self, display: &Display) -> Result<EGLBufferReader, Error>;
} }

View File

@ -33,7 +33,7 @@ use winit::{
}; };
#[cfg(feature = "use_system_lib")] #[cfg(feature = "use_system_lib")]
use crate::backend::egl::{display::WaylandEGLDisplay, EGLGraphicsBackend}; use crate::backend::egl::{display::EGLBufferReader, EGLGraphicsBackend};
/// Errors thrown by the `winit` backends /// Errors thrown by the `winit` backends
#[derive(thiserror::Error, Debug)] #[derive(thiserror::Error, Debug)]
@ -336,7 +336,7 @@ impl GLGraphicsBackend for WinitGraphicsBackend {
#[cfg(feature = "use_system_lib")] #[cfg(feature = "use_system_lib")]
impl EGLGraphicsBackend for WinitGraphicsBackend { impl EGLGraphicsBackend for WinitGraphicsBackend {
fn bind_wl_display(&self, wl_display: &Display) -> Result<WaylandEGLDisplay, EGLError> { fn bind_wl_display(&self, wl_display: &Display) -> Result<EGLBufferReader, EGLError> {
match *self.window { match *self.window {
Window::Wayland { ref display, .. } => display.bind_wl_display(wl_display), Window::Wayland { ref display, .. } => display.bind_wl_display(wl_display),
Window::X11 { ref display, .. } => display.bind_wl_display(wl_display), Window::X11 { ref display, .. } => display.bind_wl_display(wl_display),