Merge pull request #1343 from catilac/1305-wayland

Wayland Support
This commit is contained in:
charlotte 🌸
2025-11-25 15:17:50 -08:00
committed by GitHub
3 changed files with 29 additions and 11 deletions

View File

@@ -11,8 +11,8 @@ public class PGraphicsWebGPU extends PGraphics {
return surface = new PSurfaceGLFW(this);
}
protected void initWebGPUSurface(long windowHandle, int width, int height, float scaleFactor) {
surfaceId = PWebGPU.createSurface(windowHandle, width, height, scaleFactor);
protected void initWebGPUSurface(long windowHandle, long displayHandle, int width, int height, float scaleFactor) {
surfaceId = PWebGPU.createSurface(windowHandle, displayHandle, width, height, scaleFactor);
if (surfaceId == 0) {
System.err.println("Failed to create WebGPU surface");
}

View File

@@ -1,11 +1,6 @@
package processing.webgpu;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.glfw.GLFWFramebufferSizeCallback;
import org.lwjgl.glfw.GLFWNativeCocoa;
import org.lwjgl.glfw.GLFWNativeWin32;
import org.lwjgl.glfw.GLFWWindowPosCallback;
import org.lwjgl.glfw.*;
import org.lwjgl.system.MemoryUtil;
import org.lwjgl.system.Platform;
@@ -30,6 +25,7 @@ public class PSurfaceGLFW implements PSurface {
protected PGraphics graphics;
protected long window;
protected long display;
protected boolean running = false;
protected boolean paused;
@@ -78,6 +74,8 @@ public class PSurfaceGLFW implements PSurface {
throw new RuntimeException("Failed to create GLFW window");
}
display = GLFW.glfwGetPrimaryMonitor();
windowCount.incrementAndGet();
// event callbacks
@@ -87,11 +85,12 @@ public class PSurfaceGLFW implements PSurface {
PWebGPU.init();
long windowHandle = getWindowHandle();
long displayHandle = getDisplayHandle();
int width = sketch.sketchWidth();
int height = sketch.sketchHeight();
float scaleFactor = sketch.sketchPixelDensity();
webgpu.initWebGPUSurface(windowHandle, width, height, scaleFactor);
webgpu.initWebGPUSurface(windowHandle, displayHandle, width, height, scaleFactor);
}
}
@@ -123,6 +122,24 @@ public class PSurfaceGLFW implements PSurface {
return GLFWNativeCocoa.glfwGetCocoaWindow(window);
} else if (Platform.get() == Platform.WINDOWS) {
return GLFWNativeWin32.glfwGetWin32Window(window);
} else if (Platform.get() == Platform.LINUX) {
// TODO: need to check if x11 or wayland
return GLFWNativeWayland.glfwGetWaylandWindow(window);
} else {
throw new UnsupportedOperationException("Window handle retrieval not implemented for this platform");
}
}
public long getDisplayHandle() {
if (Platform.get() == Platform.MACOSX) {
// TODO: Currently unsupported
return 0;
} else if (Platform.get() == Platform.WINDOWS) {
// TODO: Currently unsupported
return 0;
} else if (Platform.get() == Platform.LINUX) {
// TODO: need to check if x11 or wayland
return GLFWNativeWayland.glfwGetWaylandDisplay();
} else {
throw new UnsupportedOperationException("Window handle retrieval not implemented for this platform");
}

View File

@@ -38,13 +38,14 @@ public class PWebGPU {
* Creates a WebGPU surface from a native window handle.
*
* @param windowHandle The native window handle
* @param displayHandle The native display handle
* @param width Window width in physical pixels
* @param height Window height in phsyical pixels
* @param scaleFactor os provided scale factor
* @return Window ID to use for subsequent operations
*/
public static long createSurface(long windowHandle, int width, int height, float scaleFactor) {
long surfaceId = processing_create_surface(windowHandle, width, height, scaleFactor);
public static long createSurface(long windowHandle, long displayHandle, int width, int height, float scaleFactor) {
long surfaceId = processing_create_surface(windowHandle, displayHandle, width, height, scaleFactor);
checkError();
return surfaceId;
}