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;
#[cfg(feature = "egl")]
use smithay::backend::egl::display::WaylandEGLDisplay;
use smithay::backend::egl::display::EGLBufferReader;
use smithay::{
reexports::wayland_server::protocol::wl_buffer::WlBuffer,
wayland::shm::with_buffer_contents as shm_buffer_contents,
@ -13,15 +13,18 @@ use smithay::{
#[derive(Clone)]
pub struct BufferUtils {
#[cfg(feature = "egl")]
egl_display: Rc<RefCell<Option<WaylandEGLDisplay>>>,
egl_buffer_reader: Rc<RefCell<Option<EGLBufferReader>>>,
log: Logger,
}
impl BufferUtils {
/// Creates a new `BufferUtils`.
#[cfg(feature = "egl")]
pub fn new(egl_display: Rc<RefCell<Option<WaylandEGLDisplay>>>, log: Logger) -> Self {
Self { egl_display, log }
pub fn new(egl_buffer_reader: Rc<RefCell<Option<EGLBufferReader>>>, log: Logger) -> Self {
Self {
egl_buffer_reader,
log,
}
}
/// Creates a new `BufferUtils`.
@ -34,7 +37,7 @@ impl BufferUtils {
#[cfg(feature = "egl")]
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.
self.egl_display
self.egl_buffer_reader
.borrow()
.as_ref()
.and_then(|display| display.egl_buffer_dimensions(buffer))

View File

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

View File

@ -15,7 +15,7 @@ use glium::Surface as GliumSurface;
use slog::Logger;
#[cfg(feature = "egl")]
use smithay::backend::egl::{display::WaylandEGLDisplay, EGLGraphicsBackend};
use smithay::backend::egl::{display::EGLBufferReader, EGLGraphicsBackend};
use smithay::{
backend::{
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);
#[cfg(feature = "egl")]
let active_egl_context = Rc::new(RefCell::new(None));
let egl_buffer_reader = Rc::new(RefCell::new(None));
#[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"))]
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 {
compositor_token,
#[cfg(feature = "egl")]
active_egl_context,
egl_buffer_reader,
session: session.clone(),
backends: HashMap::new(),
display: display.clone(),
@ -294,7 +294,7 @@ struct BackendData<S: SessionNotifier> {
struct UdevHandlerImpl<S: SessionNotifier, Data: 'static> {
compositor_token: CompositorToken<Roles>,
#[cfg(feature = "egl")]
active_egl_context: Rc<RefCell<Option<WaylandEGLDisplay>>>,
egl_buffer_reader: Rc<RefCell<Option<EGLBufferReader>>>,
session: AutoSession,
backends: HashMap<dev_t, BackendData<S>>,
display: Rc<RefCell<Display>>,
@ -313,7 +313,7 @@ impl<S: SessionNotifier, Data: 'static> UdevHandlerImpl<S, Data> {
#[cfg(feature = "egl")]
pub fn scan_connectors(
device: &mut RenderDevice,
egl_display: Rc<RefCell<Option<WaylandEGLDisplay>>>,
egl_buffer_reader: Rc<RefCell<Option<EGLBufferReader>>>,
logger: &::slog::Logger,
) -> HashMap<crtc::Handle, GliumDrawer<RenderSurface>> {
// 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) {
let renderer = GliumDrawer::init(
device.create_surface(crtc).unwrap(),
egl_display.clone(),
egl_buffer_reader.clone(),
logger.clone(),
);
@ -419,7 +419,7 @@ impl<S: SessionNotifier, Data: 'static> UdevHandler for UdevHandlerImpl<S, Data>
#[cfg(feature = "egl")]
{
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();
}
}
@ -427,7 +427,7 @@ impl<S: SessionNotifier, Data: 'static> UdevHandler for UdevHandlerImpl<S, Data>
#[cfg(feature = "egl")]
let backends = Rc::new(RefCell::new(UdevHandlerImpl::<S, Data>::scan_connectors(
&mut device,
self.active_egl_context.clone(),
self.egl_buffer_reader.clone(),
&self.logger,
)));
@ -491,7 +491,7 @@ impl<S: SessionNotifier, Data: 'static> UdevHandler for UdevHandlerImpl<S, Data>
#[cfg(feature = "egl")]
let new_backends = UdevHandlerImpl::<S, Data>::scan_connectors(
&mut (*evented).0,
self.active_egl_context.clone(),
self.egl_buffer_reader.clone(),
&self.logger,
);
#[cfg(not(feature = "egl"))]
@ -532,7 +532,7 @@ impl<S: SessionNotifier, Data: 'static> UdevHandler for UdevHandlerImpl<S, Data>
#[cfg(feature = "egl")]
{
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(|_| ())?;
#[cfg(feature = "egl")]
let egl_display = Rc::new(RefCell::new(
if let Ok(egl_display) = renderer.bind_wl_display(&display) {
let egl_buffer_reader = Rc::new(RefCell::new(
if let Ok(egl_buffer_reader) = renderer.bind_wl_display(&display) {
info!(log, "EGL hardware-acceleration enabled");
Some(egl_display)
Some(egl_buffer_reader)
} else {
None
},
@ -48,12 +48,12 @@ pub fn run_winit(
let (w, h) = renderer.get_framebuffer_dimensions();
#[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"))]
let drawer = GliumDrawer::init(renderer, log.clone());
#[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"))]
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::Error as EGLError;
#[cfg(feature = "use_system_lib")]
use crate::backend::egl::{display::WaylandEGLDisplay, EGLGraphicsBackend};
use crate::backend::egl::{display::EGLBufferReader, EGLGraphicsBackend};
mod surface;
pub use self::surface::*;
@ -199,7 +199,7 @@ where
D: Device + NativeDisplay<B, Arguments = crtc::Handle> + 'static,
<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)
}
}

View File

@ -410,7 +410,7 @@ impl<B: native::Backend, N: native::NativeDisplay<B>> EGLGraphicsBackend for EGL
///
/// 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.
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") {
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 {
return Err(Error::OtherEGLDisplayAlreadyBound);
}
Ok(WaylandEGLDisplay::new(
Ok(EGLBufferReader::new(
Arc::downgrade(&self.display),
display.c_ptr(),
&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`].
#[cfg(feature = "use_system_lib")]
pub struct WaylandEGLDisplay {
pub struct EGLBufferReader {
display: Weak<ffi::egl::types::EGLDisplay>,
wayland: *mut wl_display,
#[cfg(feature = "renderer_gl")]
@ -440,7 +440,7 @@ pub struct WaylandEGLDisplay {
}
#[cfg(feature = "use_system_lib")]
impl WaylandEGLDisplay {
impl EGLBufferReader {
fn new(
display: Weak<ffi::egl::types::EGLDisplay>,
wayland: *mut wl_display,
@ -609,7 +609,7 @@ impl WaylandEGLDisplay {
}
#[cfg(feature = "use_system_lib")]
impl Drop for WaylandEGLDisplay {
impl Drop for EGLBufferReader {
fn drop(&mut self) {
if let Some(display) = self.display.upgrade() {
if !self.wayland.is_null() {

View File

@ -41,7 +41,7 @@ pub mod native;
pub mod surface;
pub use self::surface::EGLSurface;
#[cfg(feature = "use_system_lib")]
use crate::backend::egl::display::WaylandEGLDisplay;
use crate::backend::egl::display::EGLBufferReader;
use std::ffi::CString;
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)
/// 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")]
pub trait EGLGraphicsBackend {
/// Binds this EGL context to the given Wayland display.
@ -261,5 +261,5 @@ pub trait EGLGraphicsBackend {
///
/// 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.
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")]
use crate::backend::egl::{display::WaylandEGLDisplay, EGLGraphicsBackend};
use crate::backend::egl::{display::EGLBufferReader, EGLGraphicsBackend};
/// Errors thrown by the `winit` backends
#[derive(thiserror::Error, Debug)]
@ -336,7 +336,7 @@ impl GLGraphicsBackend for WinitGraphicsBackend {
#[cfg(feature = "use_system_lib")]
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 {
Window::Wayland { ref display, .. } => display.bind_wl_display(wl_display),
Window::X11 { ref display, .. } => display.bind_wl_display(wl_display),