Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions crates/processing_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,30 @@ pub extern "C" fn processing_surface_create_x11(
.unwrap_or(0)
}

/// Create a WebGPU surface on Linux. The display server is auto-detected from
/// the environment.
///
/// SAFETY:
/// - Init has been called.
/// - The handle types match the active display server.
/// - This is called from the same thread as init.
#[cfg(target_os = "linux")]
#[unsafe(no_mangle)]
pub extern "C" fn processing_surface_create(
window_handle: u64,
display_handle: u64,
width: u32,
height: u32,
scale_factor: f32,
) -> u64 {
error::clear_error();
error::check(|| {
surface_create_linux(window_handle, display_handle, width, height, scale_factor)
})
.map(|e| e.to_bits())
.unwrap_or(0)
}

/// Create a graphics context for a surface.
///
/// SAFETY:
Expand Down
48 changes: 48 additions & 0 deletions crates/processing_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,54 @@ pub fn surface_create_x11(
})
}

/// Create a WebGPU surface on Linux, auto-detecting Wayland vs. X11 from the
/// environment.
#[cfg(target_os = "linux")]
pub fn surface_create_linux(
window_handle: u64,
display_handle: u64,
width: u32,
height: u32,
scale_factor: f32,
) -> error::Result<Entity> {
// prefer wayland, since x11 may also be available under xwayland
let nonempty = |name| std::env::var_os(name).is_some_and(|v| !v.is_empty());
let is_wayland = nonempty("WAYLAND_DISPLAY") || nonempty("WAYLAND_SOCKET");

#[cfg(all(feature = "wayland", feature = "x11"))]
{
if is_wayland {
surface_create_wayland(window_handle, display_handle, width, height, scale_factor)
} else {
surface_create_x11(window_handle, display_handle, width, height, scale_factor)
}
}
#[cfg(all(feature = "wayland", not(feature = "x11")))]
{
let _ = is_wayland;
surface_create_wayland(window_handle, display_handle, width, height, scale_factor)
}
#[cfg(all(not(feature = "wayland"), feature = "x11"))]
{
let _ = is_wayland;
surface_create_x11(window_handle, display_handle, width, height, scale_factor)
}
#[cfg(not(any(feature = "wayland", feature = "x11")))]
{
let _ = (
window_handle,
display_handle,
width,
height,
scale_factor,
is_wayland,
);
Err(processing_core::error::ProcessingError::InvalidArgument(
"libprocessing was built without `wayland` or `x11` features".into(),
))
}
}

/// Create a WebGPU surface from a web canvas element pointer.
#[cfg(target_arch = "wasm32")]
pub fn surface_create_web(
Expand Down
Loading