mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Merge #431
431: Expose FFI for creating wayland surface on wgpu-native r=kvark a=segfault87 * Added `wgpu_create_surface_from_wayland()` for creating Wayland surface from C side. * Updated FFI header and `examples/triangle` example accordingly. Co-authored-by: Park Joon-Kyu <segfault87@gmail.com>
This commit is contained in:
@@ -15,7 +15,11 @@ elseif(APPLE)
|
||||
set(OS_LIBRARIES "-framework Cocoa" "-framework CoreVideo" "-framework IOKit" "-framework QuartzCore")
|
||||
target_compile_options(${TARGET_NAME} PRIVATE -x objective-c)
|
||||
else(MSVC)
|
||||
add_definitions(-DWGPU_TARGET=WGPU_TARGET_LINUX)
|
||||
if(USE_WAYLAND)
|
||||
add_definitions(-DWGPU_TARGET=WGPU_TARGET_LINUX_WAYLAND)
|
||||
else(USE_WAYLAND)
|
||||
add_definitions(-DWGPU_TARGET=WGPU_TARGET_LINUX_X11)
|
||||
endif(USE_WAYLAND)
|
||||
target_compile_options(${TARGET_NAME} PRIVATE -Wall -Wextra -pedantic)
|
||||
endif(MSVC)
|
||||
|
||||
|
||||
@@ -12,8 +12,9 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#define WGPU_TARGET_MACOS 1
|
||||
#define WGPU_TARGET_LINUX 2
|
||||
#define WGPU_TARGET_LINUX_X11 2
|
||||
#define WGPU_TARGET_WINDOWS 3
|
||||
#define WGPU_TARGET_LINUX_WAYLAND 4
|
||||
|
||||
#if WGPU_TARGET == WGPU_TARGET_MACOS
|
||||
#include <Foundation/Foundation.h>
|
||||
@@ -23,8 +24,9 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
#if WGPU_TARGET == WGPU_TARGET_MACOS
|
||||
#define GLFW_EXPOSE_NATIVE_COCOA
|
||||
#elif WGPU_TARGET == WGPU_TARGET_LINUX
|
||||
#elif WGPU_TARGET == WGPU_TARGET_LINUX_X11
|
||||
#define GLFW_EXPOSE_NATIVE_X11
|
||||
#elif WGPU_TARGET == WGPU_TARGET_LINUX_WAYLAND
|
||||
#define GLFW_EXPOSE_NATIVE_WAYLAND
|
||||
#elif WGPU_TARGET == WGPU_TARGET_WINDOWS
|
||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||
@@ -174,12 +176,18 @@ int main() {
|
||||
[ns_window.contentView setLayer:metal_layer];
|
||||
surface = wgpu_create_surface_from_metal_layer(metal_layer);
|
||||
}
|
||||
#elif WGPU_TARGET == WGPU_TARGET_LINUX
|
||||
#elif WGPU_TARGET == WGPU_TARGET_LINUX_X11
|
||||
{
|
||||
Display *x11_display = glfwGetX11Display();
|
||||
Window x11_window = glfwGetX11Window(window);
|
||||
surface = wgpu_create_surface_from_xlib((const void **)x11_display, x11_window);
|
||||
}
|
||||
#elif WGPU_TARGET == WGPU_TARGET_LINUX_WAYLAND
|
||||
{
|
||||
struct wl_display *wayland_display = glfwGetWaylandDisplay();
|
||||
struct wl_surface *wayland_surface = glfwGetWaylandWindow(window);
|
||||
surface = wgpu_create_surface_from_wayland(wayland_surface, wayland_display);
|
||||
}
|
||||
#elif WGPU_TARGET == WGPU_TARGET_WINDOWS
|
||||
{
|
||||
HWND hwnd = glfwGetWin32Window(window);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
/* Generated with cbindgen:0.11.1 */
|
||||
/* Generated with cbindgen:0.12.1 */
|
||||
|
||||
/* DO NOT MODIFY THIS MANUALLY! This file was generated using cbindgen.
|
||||
* To generate this file:
|
||||
@@ -741,9 +741,11 @@ void wgpu_compute_pass_set_pipeline(WGPUComputePassId pass_id, WGPUComputePipeli
|
||||
|
||||
WGPUSurfaceId wgpu_create_surface_from_metal_layer(void *layer);
|
||||
|
||||
WGPUSurfaceId wgpu_create_surface_from_wayland(void *surface, void *display);
|
||||
|
||||
WGPUSurfaceId wgpu_create_surface_from_windows_hwnd(void *_hinstance, void *hwnd);
|
||||
|
||||
WGPUSurfaceId wgpu_create_surface_from_xlib(const void **display, uint64_t window);
|
||||
WGPUSurfaceId wgpu_create_surface_from_xlib(const void **display, unsigned long window);
|
||||
|
||||
WGPUBindGroupId wgpu_device_create_bind_group(WGPUDeviceId device_id,
|
||||
const WGPUBindGroupDescriptor *desc);
|
||||
|
||||
@@ -90,6 +90,19 @@ pub extern "C" fn wgpu_create_surface_from_xlib(
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(all(unix, not(target_os = "ios"), not(target_os = "macos")))]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_create_surface_from_wayland(
|
||||
surface: *mut std::ffi::c_void,
|
||||
display: *mut std::ffi::c_void,
|
||||
) -> id::SurfaceId {
|
||||
use raw_window_handle::unix::WaylandHandle;
|
||||
wgpu_create_surface(raw_window_handle::RawWindowHandle::Wayland(WaylandHandle {
|
||||
surface, display,
|
||||
..WaylandHandle::empty()
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "ios", target_os = "macos"))]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_create_surface_from_metal_layer(
|
||||
|
||||
Reference in New Issue
Block a user