Skip to content

Commit 122e393

Browse files
committed
feat: some fixes ig
1 parent 02b990a commit 122e393

File tree

7 files changed

+52
-19
lines changed

7 files changed

+52
-19
lines changed

Cargo.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ wayland = [
3232
"dep:gl",
3333
"dep:memfd",
3434
]
35+
dmabuf = []
3536
profile_tokio = ["dep:console-subscriber", "tokio/tracing"]
3637
profile_app = ["dep:tracing-tracy"]
3738
local_deps = ["stereokit-rust/force-local-deps"]
@@ -115,6 +116,8 @@ khronos-egl = { version = "6.0.0", features = [
115116
], optional = true }
116117
gl = { version = "0.14.0", optional = true }
117118
memfd = { version = "0.6.4", optional = true }
119+
libc = "0.2.172"
120+
nix = "0.30.1"
118121

119122
[dependencies.stereokit-rust]
120123
git = "https://github.com/mvvvv/StereoKit-rust.git"

src/core/graphics_info.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub struct GraphicsInfo {
3939
unsafe impl Send for GraphicsInfo {}
4040
unsafe impl Sync for GraphicsInfo {}
4141
impl GraphicsInfo {
42+
#[allow(unused)]
4243
pub fn register_debug_callback(&self) -> Result<(), Error> {
4344
let extensions_str = self.extensions()?;
4445
dbg!(&extensions_str);

src/wayland/core/buffer.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use std::sync::Arc;
22

3+
#[cfg(feature = "dmabuf")]
4+
use crate::wayland::dmabuf::buffer_backing::DmabufBacking;
35
use crate::{
46
core::registry::Registry,
5-
wayland::{
6-
GraphicsInfo, core::shm_buffer_backing::ShmBufferBacking,
7-
dmabuf::buffer_backing::DmabufBacking,
8-
},
7+
wayland::{GraphicsInfo, core::shm_buffer_backing::ShmBufferBacking},
98
};
109
use mint::Vector2;
1110
use stereokit_rust::tex::Tex;
@@ -20,6 +19,7 @@ pub static BUFFER_REGISTRY: Registry<Buffer> = Registry::new();
2019
#[derive(Debug)]
2120
pub enum BufferBacking {
2221
Shm(ShmBufferBacking),
22+
#[cfg(feature = "dmabuf")]
2323
Dmabuf(DmabufBacking),
2424
}
2525
impl BufferBacking {
@@ -42,9 +42,11 @@ impl Buffer {
4242
buffer
4343
}
4444

45+
#[allow(unused)]
4546
pub fn init_tex(self: Arc<Self>, graphics_info: &Arc<GraphicsInfo>) {
4647
match &self.backing {
4748
BufferBacking::Shm(_) => (),
49+
#[cfg(feature = "dmabuf")]
4850
BufferBacking::Dmabuf(backing) => backing.init_tex(graphics_info, self.clone()),
4951
}
5052
}
@@ -54,6 +56,7 @@ impl Buffer {
5456
tracing::info!("Updating texture for buffer {:?}", self.id);
5557
match &self.backing {
5658
BufferBacking::Shm(backing) => backing.update_tex(),
59+
#[cfg(feature = "dmabuf")]
5760
BufferBacking::Dmabuf(backing) => backing
5861
.get_tex()
5962
.map(|tex| tex.get_id().to_string())
@@ -68,6 +71,7 @@ impl Buffer {
6871
pub fn size(&self) -> Vector2<usize> {
6972
match &self.backing {
7073
BufferBacking::Shm(backing) => backing.size(),
74+
#[cfg(feature = "dmabuf")]
7175
BufferBacking::Dmabuf(backing) => backing.size(),
7276
}
7377
}

src/wayland/core/keyboard.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ use memfd::MemfdOptions;
33
use slotmap::{DefaultKey, KeyData};
44
use std::{
55
collections::HashSet,
6-
io::Write,
76
os::{
8-
fd::IntoRawFd,
7+
fd::{AsRawFd, IntoRawFd},
98
unix::io::{FromRawFd, OwnedFd},
109
},
1110
sync::{Arc, Weak},
@@ -82,12 +81,18 @@ impl Keyboard {
8281
}
8382

8483
async fn send_keymap(&self, client: &mut Client, keymap: &[u8]) -> Result<()> {
85-
let mut file = MemfdOptions::default()
84+
let file = MemfdOptions::default()
8685
.create("stardust-keymap")
8786
.map_err(|e| waynest::server::Error::Custom(e.to_string()))?
8887
.into_file();
89-
file.write_all(keymap)?;
90-
file.flush()?;
88+
file.set_len(keymap.len() as u64)?;
89+
// file.write_all(keymap)?;
90+
// file.flush()?;
91+
92+
// let map = libc::mmap(addr, len, prot, flags, fd, offset)
93+
94+
let mut map = unsafe { memmap2::MmapMut::map_mut(file.as_raw_fd()) }?;
95+
map.copy_from_slice(keymap);
9196

9297
let fd = unsafe { OwnedFd::from_raw_fd(file.into_raw_fd()) };
9398

src/wayland/core/registry.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ use crate::wayland::{
66
seat::{Seat, WlSeat},
77
shm::{Shm, WlShm},
88
},
9-
dmabuf::Dmabuf,
109
xdg::wm_base::{WmBase, XdgWmBase},
1110
};
1211
pub use waynest::server::protocol::core::wayland::wl_registry::*;
12+
#[cfg(feature = "dmabuf")]
13+
use waynest::server::protocol::stable::linux_dmabuf_v1::zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1;
1314
use waynest::{
14-
server::{
15-
Client, Dispatcher, Error, Result,
16-
protocol::stable::linux_dmabuf_v1::zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1,
17-
},
15+
server::{Client, Dispatcher, Error, Result},
1816
wire::{NewId, ObjectId},
1917
};
2018

@@ -25,6 +23,7 @@ impl RegistryGlobals {
2523
pub const WM_BASE: u32 = 2;
2624
pub const SEAT: u32 = 3;
2725
pub const OUTPUT: u32 = 4;
26+
#[cfg(feature = "dmabuf")]
2827
pub const DMABUF: u32 = 5;
2928
}
3029

@@ -78,11 +77,12 @@ impl Registry {
7877
)
7978
.await?;
8079

80+
#[cfg(feature = "dmabuf")]
8181
self.global(
8282
client,
8383
sender_id,
8484
RegistryGlobals::DMABUF,
85-
Dmabuf::INTERFACE.to_string(),
85+
crate::wayland::dmabuf::Dmabuf::INTERFACE.to_string(),
8686
Dmabuf::VERSION,
8787
)
8888
.await?;
@@ -131,6 +131,7 @@ impl WlRegistry for Registry {
131131
tracing::info!("Binding output");
132132
client.insert(new_id.object_id, Output);
133133
}
134+
#[cfg(feature = "dmabuf")]
134135
RegistryGlobals::DMABUF => {
135136
tracing::info!("Binding dmabuf");
136137
let dmabuf = client.insert(new_id.object_id, Dmabuf::new());

src/wayland/mod.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod core;
2+
#[cfg(feature = "dmabuf")]
23
pub mod dmabuf;
34
pub mod util;
45
pub mod xdg;
@@ -16,6 +17,7 @@ use core::{
1617
display::Display,
1718
surface::WL_SURFACE_REGISTRY,
1819
};
20+
#[cfg(feature = "dmabuf")]
1921
use dmabuf::buffer_params::BufferParams;
2022
use mint::Vector2;
2123
use std::{
@@ -28,15 +30,14 @@ use std::{
2830
use tokio::{net::UnixStream, sync::mpsc, task::AbortHandle};
2931
use tokio_stream::StreamExt;
3032
use tracing::{debug_span, instrument};
33+
#[cfg(feature = "dmabuf")]
34+
use waynest::server::protocol::stable::linux_dmabuf_v1::zwp_linux_buffer_params_v1::ZwpLinuxBufferParamsV1;
3135
use waynest::{
3236
server::{
3337
self,
3438
protocol::{
3539
core::wayland::{wl_buffer::WlBuffer, wl_callback::WlCallback, wl_display::WlDisplay},
36-
stable::{
37-
linux_dmabuf_v1::zwp_linux_buffer_params_v1::ZwpLinuxBufferParamsV1,
38-
xdg_shell::xdg_toplevel::XdgToplevel,
39-
},
40+
stable::xdg_shell::xdg_toplevel::XdgToplevel,
4041
},
4142
},
4243
wire::{DecodeError, ObjectId},
@@ -98,7 +99,9 @@ pub fn get_free_wayland_socket_path() -> Option<PathBuf> {
9899
pub enum Message {
99100
Frame(Arc<Callback>),
100101
ReleaseBuffer(Arc<Buffer>),
102+
#[cfg(feature = "dmabuf")]
101103
DmabufImportSuccess(Arc<BufferParams>, Arc<Buffer>),
104+
#[cfg(feature = "dmabuf")]
102105
DmabufImportFailure(Arc<BufferParams>),
103106
CloseToplevel(Arc<Toplevel>),
104107
ResizeToplevel {
@@ -203,9 +206,11 @@ impl WaylandClient {
203206
client.remove(callback.0);
204207
callback.done(client, callback.0, serial).await
205208
}
209+
#[cfg(feature = "dmabuf")]
206210
Message::DmabufImportSuccess(params, buffer) => {
207211
params.created(client, params.id, buffer.id).await
208212
}
213+
#[cfg(feature = "dmabuf")]
209214
Message::DmabufImportFailure(params) => {
210215
client.remove(params.id);
211216
params.failed(client, params.id).await

0 commit comments

Comments
 (0)