feat(wayland): implement infrastructure for async dmatex importing

Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
Schmarni
2025-07-12 06:17:12 +02:00
parent 49224ad6b5
commit c59198b4a2
3 changed files with 46 additions and 23 deletions

View File

@@ -6,15 +6,15 @@ use bevy::{
};
use bevy_dmabuf::{
dmatex::{Dmatex, DmatexPlane, Resolution},
import::ImportedDmatexs,
import::{ImportedDmatexs, ImportedTexture},
};
use drm_fourcc::DrmFourcc;
use mint::Vector2;
use parking_lot::Mutex;
use std::sync::{Arc, OnceLock};
use waynest::server::protocol::stable::linux_dmabuf_v1::zwp_linux_buffer_params_v1::Flags;
/// Parameters for a shared memory buffer
#[derive(Debug)]
pub struct DmabufBacking {
message_sink: Option<MessageSink>,
params: Arc<BufferParams>,
@@ -22,6 +22,20 @@ pub struct DmabufBacking {
format: DrmFourcc,
_flags: Flags,
tex: OnceLock<Handle<Image>>,
pending_imported_dmatex: Mutex<Option<ImportedTexture>>,
}
impl std::fmt::Debug for DmabufBacking {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DmabufBacking")
.field("message_sink", &self.message_sink)
.field("params", &self.params)
.field("size", &self.size)
.field("format", &self.format)
.field("_flags", &self._flags)
.field("tex", &self.tex)
.finish()
}
}
impl DmabufBacking {
@@ -40,6 +54,7 @@ impl DmabufBacking {
format,
_flags: flags,
tex: OnceLock::new(),
pending_imported_dmatex: Mutex::new(None),
}
}
@@ -96,12 +111,16 @@ impl DmabufBacking {
images: &mut Assets<Image>,
buffer: Arc<Buffer>,
) -> Option<Handle<Image>> {
if self.tex.get().is_none()
&& let Some(dmatex) = self.import_dmabuf(dmatexes, images, buffer)
{
let _ = self.tex.set(dmatex);
}
self.tex.get().cloned()
self.pending_imported_dmatex
.lock()
.take()
.map(|tex| dmatexes.insert_imported_dmatex(images, tex))
// if self.tex.get().is_none()
// && let Some(dmatex) = self.import_dmabuf(dmatexes, images, buffer)
// {
// let _ = self.tex.set(dmatex);
// }
// self.tex.get().cloned()
}
pub fn is_transparent(&self) -> bool {

View File

@@ -13,7 +13,10 @@ use crate::{
},
};
use bevy::app::{App, Plugin, Update};
use bevy::ecs::schedule::IntoScheduleConfigs;
use bevy::ecs::system::{Res, ResMut};
use bevy::render::renderer::RenderDevice;
use bevy::render::{Render, RenderApp};
use bevy::{asset::Assets, ecs::resource::Resource, image::Image};
use bevy_dmabuf::import::ImportedDmatexs;
use cluFlock::ToFlock;
@@ -286,14 +289,24 @@ impl Drop for Wayland {
}
}
static RENDER_DEVICE: OnceLock<RenderDevice> = OnceLock::new();
pub struct WaylandPlugin;
impl Plugin for WaylandPlugin {
fn build(&self, app: &mut App) {
app.add_systems(PreFrameWait, early_frame);
app.add_systems(Update, update_graphics);
app.sub_app_mut(RenderApp).add_systems(
Render,
init_render_device.run_if(|| RENDER_DEVICE.get().is_none()),
);
}
}
fn init_render_device(dev: Res<RenderDevice>) {
_ = RENDER_DEVICE.set(dev.clone());
}
fn early_frame() {
info!("test");
for buffer in WL_BUFFER_REGISTRY.get_valid_contents() {