Skip to content

Commit

Permalink
Using default nsview if not provided by raw-window-handle
Browse files Browse the repository at this point in the history
  • Loading branch information
Logan McGrath committed Jan 18, 2020
1 parent 3a41272 commit 7927f4c
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
build
ffi/dawn*.h
dist
.idea
84 changes: 84 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions wgpu-native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ parking_lot = "0.9"
raw-window-handle = "0.3"
libc = {version="0.2", features=[]}

[target.'cfg(target_os = "macos")'.dependencies.objc]
objc = "0.2.7"
30 changes: 21 additions & 9 deletions wgpu-native/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use core::{gfx_select, hub::Token, id};

use std::{marker::PhantomData, slice};

#[cfg(target_os = "macos")]
use objc::{msg_send, runtime::Object, sel, sel_impl};

pub type RequestAdapterCallback =
unsafe extern "C" fn(id: id::AdapterId, userdata: *mut std::ffi::c_void);
pub type BufferMapReadCallback =
Expand All @@ -29,15 +32,24 @@ pub fn wgpu_create_surface(raw_handle: raw_window_handle::RawWindowHandle) -> id
.create_surface_from_uiview(h.ui_view, cfg!(debug_assertions)),
},
#[cfg(target_os = "macos")]
Rwh::MacOS(h) => core::instance::Surface {
#[cfg(feature = "vulkan-portability")]
vulkan: instance
.vulkan
.as_ref()
.map(|inst| inst.create_surface_from_ns_view(h.ns_view)),
metal: instance
.metal
.create_surface_from_nsview(h.ns_view, cfg!(debug_assertions)),
Rwh::MacOS(h) => {
let ns_view =
if h.ns_view.is_null() {
let ns_window = h.ns_window as *mut Object;
unsafe { msg_send![ns_window, contentView] }
} else {
h.ns_view
};
core::instance::Surface {
#[cfg(feature = "vulkan-portability")]
vulkan: instance
.vulkan
.as_ref()
.map(|inst| inst.create_surface_from_ns_view(ns_view)),
metal: instance
.metal
.create_surface_from_nsview(ns_view, cfg!(debug_assertions)),
}
},
#[cfg(all(unix, not(target_os = "ios"), not(target_os = "macos")))]
Rwh::Xlib(h) => core::instance::Surface {
Expand Down

0 comments on commit 7927f4c

Please sign in to comment.