From c5f475ebb58c32ad742fd64edb234e15e4e60474 Mon Sep 17 00:00:00 2001 From: Drakulix Date: Sun, 7 Jan 2018 13:02:26 +0100 Subject: [PATCH] Make unbind_egl_display into Drop implementation for EGLDisplay --- Cargo.toml | 9 +++--- examples/helpers/glium.rs | 3 -- src/backend/drm/backend.rs | 4 --- src/backend/drm/mod.rs | 4 --- src/backend/graphics/egl/native.rs | 4 +-- src/backend/graphics/egl/wayland.rs | 47 +++++++++-------------------- src/backend/graphics/glium.rs | 3 -- src/backend/winit.rs | 7 ----- src/lib.rs | 1 + 9 files changed, 23 insertions(+), 59 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5a8d11e..7886742 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/examples/helpers/glium.rs b/examples/helpers/glium.rs index 814a81e..addaf1c 100644 --- a/examples/helpers/glium.rs +++ b/examples/helpers/glium.rs @@ -192,7 +192,4 @@ impl EGLWaylandExtension fn bind_wl_display(&self, display: &Display) -> EGLResult { self.display.bind_wl_display(display) } - fn unbind_wl_display(&self, display: &Display) -> EGLResult<()> { - self.display.unbind_wl_display(display) - } } diff --git a/src/backend/drm/backend.rs b/src/backend/drm/backend.rs index 2eb9044..428efd2 100644 --- a/src/backend/drm/backend.rs +++ b/src/backend/drm/backend.rs @@ -467,8 +467,4 @@ impl EGLWaylandExtensions for DrmBackend { fn bind_wl_display(&self, display: &Display) -> EGLResult { self.backend.context.bind_wl_display(display) } - - fn unbind_wl_display(&self, display: &Display) -> EGLResult<()> { - self.backend.context.unbind_wl_display(display) - } } diff --git a/src/backend/drm/mod.rs b/src/backend/drm/mod.rs index a109d19..e30bbe8 100644 --- a/src/backend/drm/mod.rs +++ b/src/backend/drm/mod.rs @@ -441,10 +441,6 @@ impl EGLWaylandExtensions for DrmDevice { fn bind_wl_display(&self, display: &Display) -> EGLResult { self.context.bind_wl_display(display) } - - fn unbind_wl_display(&self, display: &Display) -> EGLResult<()> { - self.context.unbind_wl_display(display) - } } impl Drop for DrmDevice { diff --git a/src/backend/graphics/egl/native.rs b/src/backend/graphics/egl/native.rs index 43dfe06..801e48b 100644 --- a/src/backend/graphics/egl/native.rs +++ b/src/backend/graphics/egl/native.rs @@ -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")] diff --git a/src/backend/graphics/egl/wayland.rs b/src/backend/graphics/egl/wayland.rs index b29671c..5c6ad10 100644 --- a/src/backend/graphics/egl/wayland.rs +++ b/src/backend/graphics/egl/wayland.rs @@ -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; - - /// 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); +pub struct EGLDisplay(Weak, *mut wl_display); impl EGLDisplay { - pub fn new>(context: &EGLContext) -> EGLDisplay { - EGLDisplay(Rc::downgrade(&context.display)) + fn new>(context: &EGLContext, display: *mut wl_display) -> EGLDisplay { + EGLDisplay(Rc::downgrade(&context.display), display) } pub fn egl_buffer_contents(&self, buffer: WlBuffer) -> ::std::result::Result { @@ -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 EGLWaylandExtensions for Rc { fn bind_wl_display(&self, display: &Display) -> Result { (**self).bind_wl_display(display) } - fn unbind_wl_display(&self, display: &Display) -> Result<()> { - (**self).unbind_wl_display(display) - } } impl> EGLWaylandExtensions for EGLContext { @@ -306,17 +300,6 @@ impl> 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() })) } } diff --git a/src/backend/graphics/glium.rs b/src/backend/graphics/glium.rs index 50856de..bdeb526 100644 --- a/src/backend/graphics/glium.rs +++ b/src/backend/graphics/glium.rs @@ -81,9 +81,6 @@ impl EGLWaylandExtension fn bind_wl_display(&self, display: &Display) -> EGLResult { (*self.backend).0.bind_wl_display(display) } - fn unbind_wl_display(&self, display: &Display) -> EGLResult<()> { - (*self.backend).0.unbind_wl_display(display) - } } diff --git a/src/backend/winit.rs b/src/backend/winit.rs index 8c0d6e9..bf00189 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -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` diff --git a/src/lib.rs b/src/lib.rs index d22fbff..928e1a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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")]