From f34cf4b06831d9a5ae51e4e9338a6bb553fb882b Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 22 Feb 2019 22:50:46 +0100 Subject: [PATCH] Upgrade anvil to wayland-server 0.23 --- anvil/src/glium_drawer.rs | 19 ++++++++----------- anvil/src/shell.rs | 12 ++++++------ anvil/src/udev.rs | 12 ++++++------ anvil/src/window_map.rs | 13 +++++-------- anvil/src/winit.rs | 6 +++--- src/backend/egl/mod.rs | 23 ++++++++++------------- 6 files changed, 38 insertions(+), 47 deletions(-) diff --git a/anvil/src/glium_drawer.rs b/anvil/src/glium_drawer.rs index dc05b67..f41f11b 100644 --- a/anvil/src/glium_drawer.rs +++ b/anvil/src/glium_drawer.rs @@ -18,10 +18,7 @@ use smithay::{ egl::{BufferAccessError, EGLImages, Format}, graphics::{gl::GLGraphicsBackend, glium::GliumGraphicsBackend}, }, - reexports::wayland_server::{ - protocol::{wl_buffer, wl_surface}, - Resource, - }, + reexports::wayland_server::protocol::{wl_buffer, wl_surface}, wayland::{ compositor::{roles::Role, SubsurfaceRole, TraversalAction}, data_device::DnDIconRole, @@ -148,7 +145,7 @@ impl> + GLGraphicsBackend + 'static> GliumDrawer impl GliumDrawer { #[cfg(feature = "egl")] - pub fn texture_from_buffer(&self, buffer: Resource) -> Result { + pub fn texture_from_buffer(&self, buffer: wl_buffer::WlBuffer) -> Result { // try to retrieve the egl contents of this buffer let images = if let Some(display) = &self.egl_display.borrow().as_ref() { display.egl_buffer_contents(buffer) @@ -199,11 +196,11 @@ impl GliumDrawer { } #[cfg(not(feature = "egl"))] - pub fn texture_from_buffer(&self, buffer: Resource) -> Result { + pub fn texture_from_buffer(&self, buffer: wl_buffer::WlBuffer) -> Result { self.texture_from_shm_buffer(buffer) } - fn texture_from_shm_buffer(&self, buffer: Resource) -> Result { + fn texture_from_shm_buffer(&self, buffer: wl_buffer::WlBuffer) -> Result { match shm_buffer_contents(&buffer, |slice, data| { crate::shm_load::load_shm_buffer(data, slice) .map(|(image, kind)| (Texture2d::new(&self.display, image).unwrap(), kind, data)) @@ -292,7 +289,7 @@ impl GliumDrawer { fn draw_surface_tree( &self, frame: &mut Frame, - root: &Resource, + root: &wl_surface::WlSurface, location: (i32, i32), compositor_token: MyCompositorToken, screen_dimensions: (u32, u32), @@ -307,7 +304,7 @@ impl GliumDrawer { } // notify the client that we have finished reading the // buffer - buffer.send(wl_buffer::Event::Release); + buffer.release(); } } if let Some(ref metadata) = attributes.user_data.texture { @@ -371,7 +368,7 @@ impl GliumDrawer { pub fn draw_cursor( &self, frame: &mut Frame, - surface: &Resource, + surface: &wl_surface::WlSurface, (x, y): (i32, i32), token: MyCompositorToken, ) { @@ -392,7 +389,7 @@ impl GliumDrawer { pub fn draw_dnd_icon( &self, frame: &mut Frame, - surface: &Resource, + surface: &wl_surface::WlSurface, (x, y): (i32, i32), token: MyCompositorToken, ) { diff --git a/anvil/src/shell.rs b/anvil/src/shell.rs index 9e6fe7c..a5c7284 100644 --- a/anvil/src/shell.rs +++ b/anvil/src/shell.rs @@ -8,8 +8,8 @@ use rand; use smithay::{ reexports::wayland_server::{ - protocol::{wl_buffer, wl_callback, wl_shell_surface, wl_surface}, - Display, Resource, + protocol::{wl_buffer, wl_shell_surface, wl_surface}, + Display, }, wayland::{ compositor::{compositor_init, CompositorToken, SurfaceAttributes, SurfaceEvent}, @@ -56,8 +56,8 @@ pub fn init_shell( move |request, surface, ctoken| match request { SurfaceEvent::Commit => surface_commit(&surface, ctoken), SurfaceEvent::Frame { callback } => callback - .implement(|e, _| match e {}, None::, ()) - .send(wl_callback::Event::Done { callback_data: 0 }), + .implement_closure(|_, _| unreachable!(), None::, ()) + .done(0), }, log.clone(), ); @@ -131,11 +131,11 @@ pub fn init_shell( #[derive(Default)] pub struct SurfaceData { - pub buffer: Option>, + pub buffer: Option, pub texture: Option, } -fn surface_commit(surface: &Resource, token: CompositorToken) { +fn surface_commit(surface: &wl_surface::WlSurface, token: CompositorToken) { // we retrieve the contents of the associated buffer and copy it token.with_surface_data(surface, |attributes| { match attributes.buffer.take() { diff --git a/anvil/src/udev.rs b/anvil/src/udev.rs index 4447dc5..7e970b4 100644 --- a/anvil/src/udev.rs +++ b/anvil/src/udev.rs @@ -49,7 +49,7 @@ use smithay::{ EventLoop, LoopHandle, Source, }, protocol::{wl_output, wl_surface}, - Display, Resource, + Display, }, }, wayland::{ @@ -175,7 +175,7 @@ pub fn run_udev(mut display: Display, mut event_loop: EventLoop<()>, log: Logger }); let keyboard = w_seat .add_keyboard(XkbConfig::default(), 1000, 500, |seat, focus| { - set_data_device_focus(seat, focus.and_then(|s| s.client())) + set_data_device_focus(seat, focus.and_then(|s| s.as_ref().client())) }) .expect("Failed to initialize the keyboard"); @@ -290,7 +290,7 @@ struct UdevHandlerImpl { pointer_location: Rc>, pointer_image: ImageBuffer, Vec>, cursor_status: Arc>, - dnd_icon: Arc>>>, + dnd_icon: Arc>>, loop_handle: LoopHandle, notifier: S, logger: ::slog::Logger, @@ -527,7 +527,7 @@ pub struct DrmHandlerImpl { window_map: Rc>, pointer_location: Rc>, cursor_status: Arc>, - dnd_icon: Arc>>>, + dnd_icon: Arc>>, logger: ::slog::Logger, } @@ -553,7 +553,7 @@ impl DeviceHandler for DrmHandlerImpl { { let guard = self.dnd_icon.lock().unwrap(); if let Some(ref surface) = *guard { - if surface.is_alive() { + if surface.as_ref().is_alive() { drawer.draw_dnd_icon( &mut frame, surface, @@ -569,7 +569,7 @@ impl DeviceHandler for DrmHandlerImpl { // reset the cursor if the surface is no longer alive let mut reset = false; if let CursorImageStatus::Image(ref surface) = *guard { - reset = !surface.is_alive(); + reset = !surface.as_ref().is_alive(); } if reset { *guard = CursorImageStatus::Default; diff --git a/anvil/src/window_map.rs b/anvil/src/window_map.rs index 5c54f68..2548a08 100644 --- a/anvil/src/window_map.rs +++ b/anvil/src/window_map.rs @@ -1,5 +1,5 @@ use smithay::{ - reexports::wayland_server::{protocol::wl_surface, Resource}, + reexports::wayland_server::protocol::wl_surface, utils::Rectangle, wayland::{ compositor::{roles::Role, CompositorToken, SubsurfaceRole, SurfaceAttributes, TraversalAction}, @@ -28,7 +28,7 @@ where Kind::Wl(ref t) => t.alive(), } } - pub fn get_surface(&self) -> Option<&Resource> { + pub fn get_surface(&self) -> Option<&wl_surface::WlSurface> { match *self { Kind::Xdg(ref t) => t.get_surface(), Kind::Wl(ref t) => t.get_surface(), @@ -55,7 +55,7 @@ where point: (f64, f64), ctoken: CompositorToken, get_size: F, - ) -> Option<(Resource, (f64, f64))> + ) -> Option<(wl_surface::WlSurface, (f64, f64))> where F: Fn(&SurfaceAttributes) -> Option<(i32, i32)>, { @@ -177,10 +177,7 @@ where self.windows.insert(0, window); } - pub fn get_surface_under( - &self, - point: (f64, f64), - ) -> Option<(Resource, (f64, f64))> { + pub fn get_surface_under(&self, point: (f64, f64)) -> Option<(wl_surface::WlSurface, (f64, f64))> { for w in &self.windows { if let Some(surface) = w.matching(point, self.ctoken, &self.get_size) { return Some(surface); @@ -192,7 +189,7 @@ where pub fn get_surface_and_bring_to_top( &mut self, point: (f64, f64), - ) -> Option<(Resource, (f64, f64))> { + ) -> Option<(wl_surface::WlSurface, (f64, f64))> { let mut found = None; for (i, w) in self.windows.iter().enumerate() { if let Some(surface) = w.matching(point, self.ctoken, &self.get_size) { diff --git a/anvil/src/winit.rs b/anvil/src/winit.rs index 93adfbf..c23972d 100644 --- a/anvil/src/winit.rs +++ b/anvil/src/winit.rs @@ -88,7 +88,7 @@ pub fn run_winit(display: &mut Display, event_loop: &mut EventLoop<()>, log: Log let keyboard = seat .add_keyboard(XkbConfig::default(), 1000, 500, |seat, focus| { - set_data_device_focus(seat, focus.and_then(|s| s.client())) + set_data_device_focus(seat, focus.and_then(|s| s.as_ref().client())) }) .expect("Failed to initialize the keyboard"); @@ -151,7 +151,7 @@ pub fn run_winit(display: &mut Display, event_loop: &mut EventLoop<()>, log: Log { let guard = dnd_icon.lock().unwrap(); if let Some(ref surface) = *guard { - if surface.is_alive() { + if surface.as_ref().is_alive() { drawer.draw_dnd_icon(&mut frame, surface, (x as i32, y as i32), compositor_token); } } @@ -162,7 +162,7 @@ pub fn run_winit(display: &mut Display, event_loop: &mut EventLoop<()>, log: Log // reset the cursor if the surface is no longer alive let mut reset = false; if let CursorImageStatus::Image(ref surface) = *guard { - reset = !surface.is_alive(); + reset = !surface.as_ref().is_alive(); } if reset { *guard = CursorImageStatus::Default; diff --git a/src/backend/egl/mod.rs b/src/backend/egl/mod.rs index 3536c88..316df5d 100644 --- a/src/backend/egl/mod.rs +++ b/src/backend/egl/mod.rs @@ -27,10 +27,7 @@ use std::{ rc::{Rc, Weak}, }; #[cfg(feature = "wayland_frontend")] -use wayland_server::{ - protocol::wl_buffer::{self, WlBuffer}, - Display, Resource, -}; +use wayland_server::{protocol::wl_buffer::WlBuffer, Display}; #[cfg(feature = "native_lib")] use wayland_sys::server::wl_display; @@ -78,7 +75,7 @@ pub enum BufferAccessError { /// The corresponding Context is not alive anymore ContextLost, /// This buffer is not managed by the EGL buffer - NotManaged(Resource), + NotManaged(WlBuffer), /// Failed to create `EGLImages` from the buffer EGLImageCreationFailed, /// The required EGL extension is not supported by the underlying EGL implementation @@ -239,7 +236,7 @@ pub struct EGLImages { /// Format of these images pub format: Format, images: Vec, - buffer: Resource, + buffer: WlBuffer, #[cfg(feature = "renderer_gl")] gl: gl_ffi::Gles2, #[cfg(feature = "renderer_gl")] @@ -303,7 +300,7 @@ impl Drop for EGLImages { } } } - self.buffer.send(wl_buffer::Event::Release); + self.buffer.release(); } } @@ -373,14 +370,14 @@ impl EGLDisplay { /// to render it another way. pub fn egl_buffer_contents( &self, - buffer: Resource, + buffer: WlBuffer, ) -> ::std::result::Result { if let Some(display) = self.egl.upgrade() { let mut format: i32 = 0; if unsafe { ffi::egl::QueryWaylandBufferWL( *display, - buffer.c_ptr() as *mut _, + buffer.as_ref().c_ptr() as *mut _, ffi::egl::EGL_TEXTURE_FORMAT, &mut format as *mut _, ) == 0 @@ -401,7 +398,7 @@ impl EGLDisplay { if unsafe { ffi::egl::QueryWaylandBufferWL( *display, - buffer.c_ptr() as *mut _, + buffer.as_ref().c_ptr() as *mut _, ffi::egl::WIDTH as i32, &mut width as *mut _, ) == 0 @@ -413,7 +410,7 @@ impl EGLDisplay { if unsafe { ffi::egl::QueryWaylandBufferWL( *display, - buffer.c_ptr() as *mut _, + buffer.as_ref().c_ptr() as *mut _, ffi::egl::HEIGHT as i32, &mut height as *mut _, ) == 0 @@ -425,7 +422,7 @@ impl EGLDisplay { if unsafe { ffi::egl::QueryWaylandBufferWL( *display, - buffer.c_ptr() as *mut _, + buffer.as_ref().c_ptr() as *mut _, ffi::egl::WAYLAND_Y_INVERTED_WL, &mut inverted as *mut _, ) != 0 @@ -446,7 +443,7 @@ impl EGLDisplay { *display, ffi::egl::NO_CONTEXT, ffi::egl::WAYLAND_BUFFER_WL, - buffer.c_ptr() as *mut _, + buffer.as_ref().c_ptr() as *mut _, out.as_ptr(), ) };