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
7 changes: 5 additions & 2 deletions ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ pub extern "C" fn processing_init() {
#[unsafe(no_mangle)]
pub extern "C" fn processing_create_surface(
window_handle: u64,
display_handle: u64,
width: u32,
height: u32,
scale_factor: f32,
) -> u64 {
error::clear_error();
error::check(|| renderer::create_surface(window_handle, width, height, scale_factor))
.unwrap_or(0)
error::check(|| {
renderer::create_surface(window_handle, display_handle, width, height, scale_factor)
})
.unwrap_or(0)
}

/// Destroy the surface associated with the given window ID.
Expand Down
31 changes: 27 additions & 4 deletions renderer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod error;
pub mod render;

use std::{cell::RefCell, num::NonZero, sync::OnceLock};
use std::{cell::RefCell, ffi::c_void, num::NonZero, ptr::NonNull, sync::OnceLock};

use bevy::{
app::{App, AppExit},
Expand Down Expand Up @@ -95,6 +95,7 @@ impl HasDisplayHandle for GlfwWindow {
/// actually create the surface.
pub fn create_surface(
window_handle: u64,
display_handle: u64,
width: u32,
height: u32,
scale_factor: f32,
Expand Down Expand Up @@ -132,7 +133,7 @@ pub fn create_surface(
}
};

let window = AppKitWindowHandle::new(std::ptr::NonNull::new(ns_view_ptr).unwrap());
let window = AppKitWindowHandle::new(NonNull::new(ns_view_ptr).unwrap());
let display = AppKitDisplayHandle::new();
(
RawWindowHandle::AppKit(window),
Expand Down Expand Up @@ -178,8 +179,30 @@ pub fn create_surface(
};

#[cfg(target_os = "linux")]
let (raw_window_handle, raw_display_handle) =
{ todo!("implement linux raw window handle conversion") };
let (raw_window_handle, raw_display_handle) = {
use raw_window_handle::{WaylandDisplayHandle, WaylandWindowHandle};

if window_handle == 0 {
return Err(error::ProcessingError::HandleError(
HandleError::Unavailable,
));
}
let window_handle_ptr = NonNull::new(window_handle as *mut c_void).unwrap();
let window = WaylandWindowHandle::new(window_handle_ptr);

if display_handle == 0 {
return Err(error::ProcessingError::HandleError(
HandleError::Unavailable,
));
}
let display_handle_ptr = NonNull::new(display_handle as *mut c_void).unwrap();
let display = WaylandDisplayHandle::new(display_handle_ptr);

(
RawWindowHandle::Wayland(window),
RawDisplayHandle::Wayland(display),
)
};

let glfw_window = GlfwWindow {
window_handle: raw_window_handle,
Expand Down