Move import_dmabuf to backends

This commit is contained in:
Ivan Molodetskikh
2024-01-03 11:16:47 +04:00
parent 628891db2c
commit 57a7347620
4 changed files with 35 additions and 11 deletions
+8
View File
@@ -2,6 +2,7 @@ use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use smithay::backend::allocator::dmabuf::Dmabuf;
use smithay::backend::renderer::gles::GlesRenderer;
use smithay::output::Output;
@@ -93,6 +94,13 @@ impl Backend {
}
}
pub fn import_dmabuf(&mut self, dmabuf: &Dmabuf) -> Result<(), ()> {
match self {
Backend::Tty(tty) => tty.import_dmabuf(dmabuf),
Backend::Winit(winit) => winit.import_dmabuf(dmabuf),
}
}
#[cfg_attr(not(feature = "dbus"), allow(unused))]
pub fn connectors(&self) -> Arc<Mutex<HashMap<String, Output>>> {
match self {
+12
View File
@@ -8,6 +8,7 @@ use std::time::Duration;
use anyhow::{anyhow, Context};
use libc::dev_t;
use smithay::backend::allocator::dmabuf::Dmabuf;
use smithay::backend::allocator::gbm::{GbmAllocator, GbmBufferFlags, GbmDevice};
use smithay::backend::allocator::Fourcc;
use smithay::backend::drm::compositor::{DrmCompositor, PrimaryPlaneElement};
@@ -974,6 +975,17 @@ impl Tty {
}
}
pub fn import_dmabuf(&mut self, dmabuf: &Dmabuf) -> Result<(), ()> {
let device = self.output_device.as_mut().ok_or(())?;
match device.gles.import_dmabuf(dmabuf, None) {
Ok(_texture) => Ok(()),
Err(err) => {
debug!("error importing dmabuf: {err:?}");
Err(())
}
}
}
pub fn connectors(&self) -> Arc<Mutex<HashMap<String, Output>>> {
self.connectors.clone()
}
+12 -1
View File
@@ -5,9 +5,10 @@ use std::rc::Rc;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use smithay::backend::allocator::dmabuf::Dmabuf;
use smithay::backend::renderer::damage::OutputDamageTracker;
use smithay::backend::renderer::gles::GlesRenderer;
use smithay::backend::renderer::{DebugFlags, ImportEgl, Renderer};
use smithay::backend::renderer::{DebugFlags, ImportDma, ImportEgl, Renderer};
use smithay::backend::winit::{self, WinitEvent, WinitGraphicsBackend};
use smithay::output::{Mode, Output, PhysicalProperties, Scale, Subpixel};
use smithay::reexports::calloop::LoopHandle;
@@ -199,6 +200,16 @@ impl Winit {
renderer.set_debug_flags(renderer.debug_flags() ^ DebugFlags::TINT);
}
pub fn import_dmabuf(&mut self, dmabuf: &Dmabuf) -> Result<(), ()> {
match self.backend.renderer().import_dmabuf(dmabuf, None) {
Ok(_texture) => Ok(()),
Err(err) => {
debug!("error importing dmabuf: {err:?}");
Err(())
}
}
}
pub fn connectors(&self) -> Arc<Mutex<HashMap<String, Output>>> {
self.connectors.clone()
}
+3 -10
View File
@@ -9,7 +9,6 @@ use std::sync::Arc;
use std::thread;
use smithay::backend::allocator::dmabuf::Dmabuf;
use smithay::backend::renderer::ImportDma;
use smithay::desktop::{PopupKind, PopupManager};
use smithay::input::pointer::{CursorIcon, CursorImageStatus, PointerHandle};
use smithay::input::{Seat, SeatHandler, SeatState};
@@ -202,17 +201,11 @@ impl DmabufHandler for State {
dmabuf: Dmabuf,
notifier: ImportNotifier,
) {
let Some(renderer) = self.backend.renderer() else {
notifier.failed();
return;
};
match renderer.import_dmabuf(&dmabuf, None) {
Ok(_texture) => {
match self.backend.import_dmabuf(&dmabuf) {
Ok(_) => {
let _ = notifier.successful::<State>();
}
Err(err) => {
debug!("error importing dmabuf: {err:?}");
Err(_) => {
notifier.failed();
}
}