Closed
Description
Goals:
- De-facto windowing solution.
- BYOW: Bring your own window.
- Deno should not link to native windowing systems like X11.
- Deno should not have to be forked for windowing support.
/* any windowing library */
import { WindowBuilder } from "https://deno.land/x/sdl2/mod.ts";
const win = new WindowBuilder("Hello WGPU", 512, 512).build();
/* [string, Deno.PointerValue, Deno.PointerValue] */
const [system, windowHandle, displayHandle] = win.rawHandle();
const surface = new Deno.UnsafeWindowSurface(system, windowHandle, displayHandle);
/* GPUCanvasContext */
const context = surface.getContext();
context.configure({ /* ... */ });
for (const events of win.events()) {
const texture = context.getCurrentTexture();
// ...
surface.present();
}
Proposed: Add Deno.UnsafeWindowSurface
API:
- Creates a
raw_window_handle::RawWindowHandle
implementation fromwindowHandle
anddisplayHandle
- Internally calls
instance->create_surface(&win)
- Surface is returned wrapped in as a GPUCanvasContext (@crowlKats has already implemented presentation APIs)
class UnsafeWindowSurface {
constructor(
system: "cocoa" | "x11" | "win32",
winHandle: Deno.PointerValue,
displayHandle: Deno.PointerValue | null
);
getContext(type: "webgpu"): GPUCanvasContext;
present(): void;
}
Pros:
- Single binary. No extensions or Deno forks.
- Does not link CLI to windowing systems.
- Plug and play FFI windowing libraries with Deno WebGPU.
deno compile
-able.
Cons:
- Very low level
displayHandle
andwinHandle
can be invalid handles. Creating them requires--allow-ffi --unstable
I have a working implementation and a few demos I will share shortly.
cc-ing for visibility: @DjDeveloperr @load1n9 @eliassjogreen (also @aapoalas since this touches FFI too)