feat: dmatex!! (sorta, borken)

This commit is contained in:
Nova
2025-07-10 10:13:38 -07:00
parent 929ea054f3
commit 63cf0db448
12 changed files with 146 additions and 277 deletions

View File

@@ -1,17 +1,15 @@
use std::sync::{Arc, atomic::AtomicBool};
#[cfg(feature = "dmabuf")]
use crate::wayland::dmabuf::buffer_backing::DmabufBacking;
use crate::{
core::registry::Registry,
wayland::{
GraphicsInfo, MessageSink, core::shm_buffer_backing::ShmBufferBacking, util::ClientExt,
},
wayland::{MessageSink, core::shm_buffer_backing::ShmBufferBacking, util::ClientExt},
};
use bevy::{
asset::{Assets, Handle},
image::Image,
};
use bevy_dmabuf::import::ImportedDmatexs;
use mint::Vector2;
pub use waynest::server::protocol::core::wayland::wl_buffer::*;
use waynest::{
@@ -19,12 +17,11 @@ use waynest::{
wire::ObjectId,
};
pub static BUFFER_REGISTRY: Registry<Buffer> = Registry::new();
pub static WL_BUFFER_REGISTRY: Registry<Buffer> = Registry::new();
#[derive(Debug)]
pub enum BufferBacking {
Shm(ShmBufferBacking),
#[cfg(feature = "dmabuf")]
Dmabuf(DmabufBacking),
}
impl BufferBacking {
@@ -53,29 +50,21 @@ impl Buffer {
rendered: AtomicBool::new(false),
},
);
BUFFER_REGISTRY.add_raw(&buffer);
WL_BUFFER_REGISTRY.add_raw(&buffer);
buffer
}
#[allow(unused)]
pub fn init_tex(self: Arc<Self>, graphics_info: &mut GraphicsInfo) {
match &self.backing {
BufferBacking::Shm(_) => (),
#[cfg(feature = "dmabuf")]
BufferBacking::Dmabuf(backing) => backing.init_tex(graphics_info, self.clone()),
}
}
/// Returns the tex if it was updated
pub fn update_tex(&self, images: &mut Assets<Image>) -> Option<Handle<Image>> {
pub fn update_tex(
&self,
dmatexes: &ImportedDmatexs,
images: &mut Assets<Image>,
buffer: Arc<Buffer>,
) -> Option<Handle<Image>> {
tracing::debug!("Updating texture for buffer {:?}", self.id);
match &self.backing {
BufferBacking::Shm(backing) => backing.update_tex(images),
#[cfg(feature = "dmabuf")]
BufferBacking::Dmabuf(backing) => backing
.get_tex()
.map(|tex| tex.get_id().to_string())
.and_then(|tex_id| Tex::find(tex_id).ok()),
BufferBacking::Dmabuf(backing) => backing.update_tex(dmatexes, images, buffer),
}
}
@@ -86,7 +75,6 @@ impl Buffer {
pub fn is_transparent(&self) -> bool {
match &self.backing {
BufferBacking::Shm(backing) => backing.is_transparent(),
#[cfg(feature = "dmabuf")]
BufferBacking::Dmabuf(backing) => backing.is_transparent(),
}
}
@@ -94,7 +82,6 @@ impl Buffer {
pub fn size(&self) -> Vector2<usize> {
match &self.backing {
BufferBacking::Shm(backing) => backing.size(),
#[cfg(feature = "dmabuf")]
BufferBacking::Dmabuf(backing) => backing.size(),
}
}

View File

@@ -6,10 +6,11 @@ use crate::wayland::{
seat::{Seat, WlSeat},
shm::{Shm, WlShm},
},
dmabuf::Dmabuf,
xdg::wm_base::{WmBase, XdgWmBase},
};
pub use waynest::server::protocol::core::wayland::wl_registry::*;
#[cfg(feature = "dmabuf")]
use waynest::server::protocol::stable::linux_dmabuf_v1::zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1;
use waynest::{
server::{Client, Dispatcher, Error, Result},
@@ -23,7 +24,6 @@ impl RegistryGlobals {
pub const WM_BASE: u32 = 2;
pub const SEAT: u32 = 3;
pub const OUTPUT: u32 = 4;
#[cfg(feature = "dmabuf")]
pub const DMABUF: u32 = 5;
}
@@ -77,7 +77,6 @@ impl Registry {
)
.await?;
#[cfg(feature = "dmabuf")]
self.global(
client,
sender_id,
@@ -131,7 +130,6 @@ impl WlRegistry for Registry {
tracing::info!("Binding output");
client.insert(new_id.object_id, Output);
}
#[cfg(feature = "dmabuf")]
RegistryGlobals::DMABUF => {
tracing::info!("Binding dmabuf");
let dmabuf = client.insert(new_id.object_id, Dmabuf::new());

View File

@@ -14,6 +14,7 @@ use bevy::{
image::Image,
render::alpha::AlphaMode,
};
use bevy_dmabuf::import::ImportedDmatexs;
use mint::Vector2;
use parking_lot::Mutex;
use std::sync::{Arc, OnceLock, atomic::Ordering};
@@ -111,6 +112,7 @@ impl Surface {
pub fn update_graphics(
&self,
dmatexes: &ImportedDmatexs,
materials: &mut Assets<BevyMaterial>,
images: &mut Assets<Image>,
) {
@@ -139,7 +141,7 @@ impl Surface {
})
});
if let Some(new_tex) = buffer.update_tex(images) {
if let Some(new_tex) = buffer.update_tex(dmatexes, images, buffer.clone()) {
buffer.rendered.store(true, Ordering::Relaxed);
let material = materials.get_mut(material).unwrap();
material.base_color_texture.replace(new_tex);