Skip to content

Commit

Permalink
Update wgpu example to wgpu 0.19
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 authored and wash2 committed Mar 20, 2024
1 parent 82ece74 commit 3bed072
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 35 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ drm-fourcc = "2.2.0"
font-kit = "0.11.0"
image = "0.24"
env_logger = "0.10"
wgpu = "0.18.0"
wgpu = "0.19.0"
raqote = "0.8.2"
raw-window-handle = "0.5.2"
raw-window-handle = "0.6.0"
pollster = "0.3.0"

[[example]]
Expand Down
51 changes: 18 additions & 33 deletions examples/wgpu.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use raw_window_handle::{
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle,
WaylandDisplayHandle, WaylandWindowHandle,
RawDisplayHandle, RawWindowHandle, WaylandDisplayHandle, WaylandWindowHandle,
};
use smithay_client_toolkit::{
compositor::{CompositorHandler, CompositorState},
Expand All @@ -18,6 +17,7 @@ use smithay_client_toolkit::{
WaylandSurface,
},
};
use std::ptr::NonNull;
use wayland_client::{
globals::registry_queue_init,
protocol::{wl_output, wl_seat, wl_surface},
Expand Down Expand Up @@ -52,38 +52,22 @@ fn main() {
});

// Create the raw window handle for the surface.
let handle = {
let mut handle = WaylandDisplayHandle::empty();
handle.display = conn.backend().display_ptr() as *mut _;
let display_handle = RawDisplayHandle::Wayland(handle);

let mut handle = WaylandWindowHandle::empty();
handle.surface = window.wl_surface().id().as_ptr() as *mut _;
let window_handle = RawWindowHandle::Wayland(handle);

/// https://github.com/rust-windowing/raw-window-handle/issues/49
struct YesRawWindowHandleImplementingHasRawWindowHandleIsUnsound(
RawDisplayHandle,
RawWindowHandle,
);

unsafe impl HasRawDisplayHandle for YesRawWindowHandleImplementingHasRawWindowHandleIsUnsound {
fn raw_display_handle(&self) -> RawDisplayHandle {
self.0
}
}

unsafe impl HasRawWindowHandle for YesRawWindowHandleImplementingHasRawWindowHandleIsUnsound {
fn raw_window_handle(&self) -> RawWindowHandle {
self.1
}
}

YesRawWindowHandleImplementingHasRawWindowHandleIsUnsound(display_handle, window_handle)
let raw_display_handle = RawDisplayHandle::Wayland(WaylandDisplayHandle::new(
NonNull::new(conn.backend().display_ptr() as *mut _).unwrap(),
));
let raw_window_handle = RawWindowHandle::Wayland(WaylandWindowHandle::new(
NonNull::new(window.wl_surface().id().as_ptr() as *mut _).unwrap(),
));

let surface = unsafe {
instance
.create_surface_unsafe(wgpu::SurfaceTargetUnsafe::RawHandle {
raw_display_handle,
raw_window_handle,
})
.unwrap()
};

let surface = unsafe { instance.create_surface(&handle).unwrap() };

// Pick a supported adapter
let adapter = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions {
compatible_surface: Some(&surface),
Expand Down Expand Up @@ -137,7 +121,7 @@ struct Wgpu {
adapter: wgpu::Adapter,
device: wgpu::Device,
queue: wgpu::Queue,
surface: wgpu::Surface,
surface: wgpu::Surface<'static>,
}

impl CompositorHandler for Wgpu {
Expand Down Expand Up @@ -231,6 +215,7 @@ impl WindowHandler for Wgpu {
alpha_mode: wgpu::CompositeAlphaMode::Auto,
width: self.width,
height: self.height,
desired_maximum_frame_latency: 2,
// Wayland is inherently a mailbox system.
present_mode: wgpu::PresentMode::Mailbox,
};
Expand Down

0 comments on commit 3bed072

Please sign in to comment.