Make unbind_egl_display into Drop implementation for EGLDisplay
This commit is contained in:
parent
6b650eb988
commit
c5f475ebb5
|
@ -7,21 +7,22 @@ description = "Smithay is a library for writing wayland compositors."
|
|||
repository = "https://github.com/Smithay/smithay"
|
||||
|
||||
[dependencies]
|
||||
wayland-server = "0.12.4"
|
||||
wayland-server = "0.12.5"
|
||||
wayland-sys = "0.12.5"
|
||||
nix = "0.9.0"
|
||||
xkbcommon = "0.2.1"
|
||||
tempfile = "2.1.5"
|
||||
slog = { version = "2.1.1" }
|
||||
slog-stdlog = "3.0.2"
|
||||
libloading = "0.4.0"
|
||||
wayland-client = { version = "0.12.4", optional = true }
|
||||
winit = { version = "0.9.0", optional = true }
|
||||
wayland-client = { version = "0.12.5", optional = true }
|
||||
winit = { version = "0.10.0", optional = true }
|
||||
drm = { version = "^0.3.1", optional = true }
|
||||
gbm = { version = "^0.4.0", git = "https://github.com/Smithay/gbm.rs.git", branch = "feature/ref_counted_api", optional = true, default-features = false, features = ["drm-support"] }
|
||||
glium = { version = "0.19.0", optional = true, default-features = false }
|
||||
input = { version = "0.4.0", optional = true }
|
||||
udev = { version = "0.2.0", optional = true }
|
||||
wayland-protocols = { version = "0.12.4", features = ["unstable_protocols", "server"] }
|
||||
wayland-protocols = { version = "0.12.5", features = ["unstable_protocols", "server"] }
|
||||
image = "0.17.0"
|
||||
error-chain = "0.11.0"
|
||||
lazy_static = "1.0.0"
|
||||
|
|
|
@ -192,7 +192,4 @@ impl<G: EGLWaylandExtensions + EGLGraphicsBackend + 'static> EGLWaylandExtension
|
|||
fn bind_wl_display(&self, display: &Display) -> EGLResult<EGLDisplay> {
|
||||
self.display.bind_wl_display(display)
|
||||
}
|
||||
fn unbind_wl_display(&self, display: &Display) -> EGLResult<()> {
|
||||
self.display.unbind_wl_display(display)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -467,8 +467,4 @@ impl<A: Device + 'static> EGLWaylandExtensions for DrmBackend<A> {
|
|||
fn bind_wl_display(&self, display: &Display) -> EGLResult<EGLDisplay> {
|
||||
self.backend.context.bind_wl_display(display)
|
||||
}
|
||||
|
||||
fn unbind_wl_display(&self, display: &Display) -> EGLResult<()> {
|
||||
self.backend.context.unbind_wl_display(display)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -441,10 +441,6 @@ impl<A: ControlDevice + 'static> EGLWaylandExtensions for DrmDevice<A> {
|
|||
fn bind_wl_display(&self, display: &Display) -> EGLResult<EGLDisplay> {
|
||||
self.context.bind_wl_display(display)
|
||||
}
|
||||
|
||||
fn unbind_wl_display(&self, display: &Display) -> EGLResult<()> {
|
||||
self.context.unbind_wl_display(display)
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: ControlDevice + 'static> Drop for DrmDevice<A> {
|
||||
|
|
|
@ -67,7 +67,7 @@ impl Backend for Wayland {
|
|||
}
|
||||
|
||||
#[cfg(feature = "backend_winit")]
|
||||
pub struct XlibWindow(*const c_void);
|
||||
pub struct XlibWindow(u64);
|
||||
#[cfg(feature = "backend_winit")]
|
||||
pub enum X11 {}
|
||||
#[cfg(feature = "backend_winit")]
|
||||
|
@ -241,7 +241,7 @@ pub unsafe trait NativeSurface {
|
|||
|
||||
#[cfg(feature = "backend_winit")]
|
||||
unsafe impl NativeSurface for XlibWindow {
|
||||
fn ptr(&self) -> ffi::NativeWindowType { self.0 }
|
||||
fn ptr(&self) -> ffi::NativeWindowType { self.0 as *const _ }
|
||||
}
|
||||
|
||||
#[cfg(feature = "backend_winit")]
|
||||
|
|
|
@ -6,6 +6,7 @@ use std::rc::{Rc, Weak};
|
|||
use std::fmt;
|
||||
use wayland_server::{Display, Resource, StateToken, StateProxy};
|
||||
use wayland_server::protocol::wl_buffer::WlBuffer;
|
||||
use wayland_sys::server::wl_display;
|
||||
|
||||
/// Error that can occur when accessing an EGL buffer
|
||||
pub enum BufferAccessError {
|
||||
|
@ -191,27 +192,13 @@ pub trait EGLWaylandExtensions {
|
|||
/// This might return `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<EGLDisplay>;
|
||||
|
||||
/// Unbinds this EGL context from the given Wayland display.
|
||||
///
|
||||
/// This will stop clients from using previously available extensions
|
||||
/// to utilize hardware-accelerated surface via EGL.
|
||||
///
|
||||
/// ## Errors
|
||||
///
|
||||
/// This might return `WlExtensionNotSupported` if binding is not supported
|
||||
/// by the EGL implementation.
|
||||
///
|
||||
/// This might return `OtherEGLDisplayAlreadyBound` if called for the same
|
||||
/// `Display` multiple times, as only one context may be bound at any given time.
|
||||
fn unbind_wl_display(&self, display: &Display) -> Result<()>;
|
||||
}
|
||||
|
||||
pub struct EGLDisplay(Weak<ffi::egl::types::EGLDisplay>);
|
||||
pub struct EGLDisplay(Weak<ffi::egl::types::EGLDisplay>, *mut wl_display);
|
||||
|
||||
impl EGLDisplay {
|
||||
pub fn new<B: native::Backend, N: native::NativeDisplay<B>>(context: &EGLContext<B, N>) -> EGLDisplay {
|
||||
EGLDisplay(Rc::downgrade(&context.display))
|
||||
fn new<B: native::Backend, N: native::NativeDisplay<B>>(context: &EGLContext<B, N>, display: *mut wl_display) -> EGLDisplay {
|
||||
EGLDisplay(Rc::downgrade(&context.display), display)
|
||||
}
|
||||
|
||||
pub fn egl_buffer_contents(&self, buffer: WlBuffer) -> ::std::result::Result<EGLImages, BufferAccessError> {
|
||||
|
@ -284,14 +271,21 @@ impl EGLDisplay {
|
|||
}
|
||||
}
|
||||
|
||||
impl Drop for EGLDisplay {
|
||||
fn drop(&mut self) {
|
||||
if let Some(display) = self.0.upgrade() {
|
||||
if !self.1.is_null() {
|
||||
unsafe { ffi::egl::UnbindWaylandDisplayWL(*display, self.1 as *mut _); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EGLWaylandExtensions> EGLWaylandExtensions for Rc<E>
|
||||
{
|
||||
fn bind_wl_display(&self, display: &Display) -> Result<EGLDisplay> {
|
||||
(**self).bind_wl_display(display)
|
||||
}
|
||||
fn unbind_wl_display(&self, display: &Display) -> Result<()> {
|
||||
(**self).unbind_wl_display(display)
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: native::Backend, N: native::NativeDisplay<B>> EGLWaylandExtensions for EGLContext<B, N> {
|
||||
|
@ -306,17 +300,6 @@ impl<B: native::Backend, N: native::NativeDisplay<B>> EGLWaylandExtensions for E
|
|||
if res == 0 {
|
||||
bail!(ErrorKind::OtherEGLDisplayAlreadyBound);
|
||||
}
|
||||
Ok(EGLDisplay::new(self))
|
||||
}
|
||||
|
||||
fn unbind_wl_display(&self, display: &Display) -> Result<()> {
|
||||
if !self.wl_drm_support {
|
||||
bail!(ErrorKind::EglExtensionNotSupported(&["EGL_WL_bind_wayland_display"]));
|
||||
}
|
||||
let res = unsafe { ffi::egl::UnbindWaylandDisplayWL(*self.display, display.ptr() as *mut _) };
|
||||
if res == 0 {
|
||||
bail!(ErrorKind::NoEGLDisplayBound);
|
||||
}
|
||||
Ok(())
|
||||
Ok(EGLDisplay::new(self, unsafe { display.ptr() }))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,9 +81,6 @@ impl<T: EGLGraphicsBackend + EGLWaylandExtensions + 'static> EGLWaylandExtension
|
|||
fn bind_wl_display(&self, display: &Display) -> EGLResult<EGLDisplay> {
|
||||
(*self.backend).0.bind_wl_display(display)
|
||||
}
|
||||
fn unbind_wl_display(&self, display: &Display) -> EGLResult<()> {
|
||||
(*self.backend).0.unbind_wl_display(display)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -266,13 +266,6 @@ impl EGLWaylandExtensions for WinitGraphicsBackend {
|
|||
Window::X11 { ref context, .. } => context.bind_wl_display(display),
|
||||
}
|
||||
}
|
||||
|
||||
fn unbind_wl_display(&self, display: &Display) -> EGLResult<()> {
|
||||
match *self.window {
|
||||
Window::Wayland { ref context, .. } => context.unbind_wl_display(display),
|
||||
Window::X11 { ref context, .. } => context.unbind_wl_display(display),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Errors that may happen when driving the event loop of `WinitInputBackend`
|
||||
|
|
|
@ -13,6 +13,7 @@ extern crate nix;
|
|||
extern crate tempfile;
|
||||
extern crate wayland_protocols;
|
||||
extern crate wayland_server;
|
||||
extern crate wayland_sys;
|
||||
extern crate xkbcommon;
|
||||
|
||||
#[cfg(feature = "backend_drm")]
|
||||
|
|
Loading…
Reference in New Issue