From cc1c9d93254df120fc1041e121cb3b5edd00ffc9 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sun, 3 Sep 2023 14:22:04 +0400 Subject: Add initial dmabuf feedback implementation --- src/backend/tty.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src/backend/tty.rs') diff --git a/src/backend/tty.rs b/src/backend/tty.rs index eec796f1..2db762fc 100644 --- a/src/backend/tty.rs +++ b/src/backend/tty.rs @@ -12,7 +12,7 @@ use smithay::backend::drm::{DrmDevice, DrmDeviceFd, DrmEvent, DrmEventTime}; use smithay::backend::egl::{EGLContext, EGLDisplay}; use smithay::backend::libinput::{LibinputInputBackend, LibinputSessionInterface}; use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture}; -use smithay::backend::renderer::{Bind, DebugFlags, ImportEgl}; +use smithay::backend::renderer::{Bind, DebugFlags, ImportDma, ImportEgl}; use smithay::backend::session::libseat::LibSeatSession; use smithay::backend::session::{Event as SessionEvent, Session}; use smithay::backend::udev::{self, UdevBackend, UdevEvent}; @@ -27,10 +27,11 @@ use smithay::reexports::nix::fcntl::OFlag; use smithay::reexports::nix::libc::dev_t; use smithay::reexports::wayland_protocols::wp::presentation_time::server::wp_presentation_feedback; use smithay::utils::DeviceFd; +use smithay::wayland::dmabuf::{DmabufFeedbackBuilder, DmabufGlobal, DmabufState}; use smithay_drm_extras::drm_scanner::{DrmScanEvent, DrmScanner}; use smithay_drm_extras::edid::EdidInfo; -use crate::niri::OutputRenderElements; +use crate::niri::{OutputRenderElements, State}; use crate::{LoopData, Niri}; const BACKGROUND_COLOR: [f32; 4] = [0.1, 0.1, 0.1, 1.]; @@ -59,6 +60,8 @@ struct OutputDevice { formats: HashSet, drm_scanner: DrmScanner, surfaces: HashMap, + dmabuf_state: DmabufState, + dmabuf_global: DmabufGlobal, } #[derive(Debug, Clone, Copy)] @@ -331,6 +334,13 @@ impl Tty { let formats = Bind::::supported_formats(&gles).unwrap_or_default(); + let mut dmabuf_state = DmabufState::new(); + let default_feedback = DmabufFeedbackBuilder::new(device_id, gles.dmabuf_formats()) + .build() + .unwrap(); + let dmabuf_global = dmabuf_state + .create_global_with_default_feedback::(&niri.display_handle, &default_feedback); + self.output_device = Some(OutputDevice { id: device_id, token, @@ -340,6 +350,8 @@ impl Tty { formats, drm_scanner: DrmScanner::new(), surfaces: HashMap::new(), + dmabuf_state, + dmabuf_global, }); self.device_changed(device_id, niri); @@ -394,7 +406,11 @@ impl Tty { } let mut device = self.output_device.take().unwrap(); + device + .dmabuf_state + .destroy_global::(&niri.display_handle, device.dmabuf_global); device.gles.unbind_wl_display(); + niri.event_loop.remove(device.token); } @@ -582,6 +598,10 @@ impl Tty { } } } + + pub fn dmabuf_state(&mut self) -> &mut DmabufState { + &mut self.output_device.as_mut().unwrap().dmabuf_state + } } fn refresh_interval(mode: DrmMode) -> Duration { -- cgit