Skip to content
Merged
2 changes: 1 addition & 1 deletion wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ features = ["wgsl-in"]

[dev-dependencies]
env_logger = "0.9"
winit = "~0.27.1" # for "halmark" example
winit = "0.27.1" # for "halmark" example

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
glutin = "0.28.0" # for "gles" example
29 changes: 11 additions & 18 deletions wgpu-hal/src/gles/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,13 +779,13 @@ impl crate::Instance<super::Api> for Instance {
#[cfg_attr(any(target_os = "android", feature = "emscripten"), allow(unused_mut))]
let mut inner = self.inner.lock();

match raw_window_handle {
Rwh::Xlib(_) => {}
Rwh::Xcb(_) => {}
Rwh::Win32(_) => {}
Rwh::AppKit(_) => {}
match (raw_window_handle, has_handle.raw_display_handle()) {
(Rwh::Xlib(_), _) => {}
(Rwh::Xcb(_), _) => {}
(Rwh::Win32(_), _) => {}
(Rwh::AppKit(_), _) => {}
#[cfg(target_os = "android")]
Rwh::AndroidNdk(handle) => {
(Rwh::AndroidNdk(handle), _) => {
let format = inner
.egl
.instance
Expand All @@ -800,24 +800,17 @@ impl crate::Instance<super::Api> for Instance {
}
}
#[cfg(not(feature = "emscripten"))]
Rwh::Wayland(_) => {
(Rwh::Wayland(_), raw_window_handle::RawDisplayHandle::Wayland(display_handle)) => {
/* Wayland displays are not sharable between surfaces so if the
* surface we receive from this handle is from a different
* display, we must re-initialize the context.
*
* See gfx-rs/gfx#3545
*/
let wayland_raw = if let raw_window_handle::RawDisplayHandle::Wayland(display) =
has_handle.raw_display_handle()
{
display.display
} else {
return Err(crate::InstanceError);
};
log::warn!("Re-initializing Gles context due to Wayland window");
if inner
.wl_display
.map(|ptr| ptr != wayland_raw)
.map(|ptr| ptr != display_handle.display)
.unwrap_or(true)
{
use std::ops::DerefMut;
Expand All @@ -830,7 +823,7 @@ impl crate::Instance<super::Api> for Instance {
.unwrap()
.get_platform_display(
EGL_PLATFORM_WAYLAND_KHR,
wayland_raw,
display_handle.display,
&display_attributes,
)
.unwrap();
Expand All @@ -840,13 +833,13 @@ impl crate::Instance<super::Api> for Instance {
.map_err(|_| crate::InstanceError)?;

let old_inner = std::mem::replace(inner.deref_mut(), new_inner);
inner.wl_display = Some(wayland_raw);
inner.wl_display = Some(display_handle.display);

drop(old_inner);
}
}
#[cfg(feature = "emscripten")]
Rwh::Web(_) => {}
(Rwh::Web(_), _) => {}
other => {
log::error!("Unsupported window: {:?}", other);
return Err(crate::InstanceError);
Expand Down
44 changes: 15 additions & 29 deletions wgpu-hal/src/vulkan/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,60 +597,46 @@ impl crate::Instance<super::Api> for super::Instance {
use raw_window_handle::RawDisplayHandle;
use raw_window_handle::RawWindowHandle;

match has_handle.raw_window_handle() {
RawWindowHandle::Wayland(handle)
if self
.shared
.extensions
.contains(&khr::WaylandSurface::name()) =>
{
if let RawDisplayHandle::Wayland(v) = has_handle.raw_display_handle() {
Ok(self.create_surface_from_wayland(v.display, handle.surface))
} else {
Err(crate::InstanceError)
}
match (
has_handle.raw_window_handle(),
has_handle.raw_display_handle(),
) {
(RawWindowHandle::Wayland(handle), RawDisplayHandle::Wayland(display)) => {
Ok(self.create_surface_from_wayland(display.display, handle.surface))
}
RawWindowHandle::Xlib(handle)
(RawWindowHandle::Xlib(handle), RawDisplayHandle::Xlib(display))
if self.shared.extensions.contains(&khr::XlibSurface::name()) =>
{
if let RawDisplayHandle::Xlib(v) = has_handle.raw_display_handle() {
Ok(self.create_surface_from_xlib(v.display as *mut _, handle.window))
} else {
Err(crate::InstanceError)
}
Ok(self.create_surface_from_xlib(display.display as *mut _, handle.window))
}
RawWindowHandle::Xcb(handle)
(RawWindowHandle::Xcb(handle), RawDisplayHandle::Xcb(display))
if self.shared.extensions.contains(&khr::XcbSurface::name()) =>
{
if let RawDisplayHandle::Xcb(v) = has_handle.raw_display_handle() {
Ok(self.create_surface_from_xcb(v.connection, handle.window))
} else {
Err(crate::InstanceError)
}
Ok(self.create_surface_from_xcb(display.connection, handle.window))
}
RawWindowHandle::AndroidNdk(handle) => {
(RawWindowHandle::AndroidNdk(handle), _) => {
Ok(self.create_surface_android(handle.a_native_window))
}
#[cfg(windows)]
RawWindowHandle::Win32(handle) => {
(RawWindowHandle::Win32(handle), _) => {
use winapi::um::libloaderapi::GetModuleHandleW;

let hinstance = GetModuleHandleW(std::ptr::null());
Ok(self.create_surface_from_hwnd(hinstance as *mut _, handle.hwnd))
}
#[cfg(target_os = "macos")]
RawWindowHandle::AppKit(handle)
(RawWindowHandle::AppKit(handle), _)
if self.shared.extensions.contains(&ext::MetalSurface::name()) =>
{
Ok(self.create_surface_from_view(handle.ns_view))
}
#[cfg(target_os = "ios")]
RawWindowHandle::UiKit(handle)
(RawWindowHandle::UiKit(handle), _)
if self.shared.extensions.contains(&ext::MetalSurface::name()) =>
{
Ok(self.create_surface_from_view(handle.ui_view))
}
_ => Err(crate::InstanceError),
(_, _) => Err(crate::InstanceError),
}
}

Expand Down
2 changes: 1 addition & 1 deletion wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ noise = { version = "0.7", default-features = false }
obj = "0.10"
png = "0.17"
nanorand = { version = "0.7", default-features = false, features = ["wyrand"] }
winit = "~0.27.1" # for "halmark" example
winit = "0.27.1" # for "halmark" example

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
async-executor = "1.0"
Expand Down