diff --git a/wit/animation-frame.wit b/wit/animation-frame.wit deleted file mode 100644 index f01bb07..0000000 --- a/wit/animation-frame.wit +++ /dev/null @@ -1,23 +0,0 @@ -// TODO: Move this into mini-canvas. - -package wasi:webgpu; - -/// This is similar to requestAnimationFrame in JavaScript, or wl_surface::frame in Wayland. -/// Should update as fast as the users display can, but not faster. -interface animation-frame { - use wasi:io/poll@0.2.0.{pollable}; - - listener: func() -> frame-listener; - - resource frame-listener { - subscribe: func() -> pollable; - - get: func() -> option; - } - - record frame-event { - /// This field doesn't mean anything. - // Can't have empty record. Would like to have a way around this. - nothing: bool, - } -} diff --git a/wit/key-events.wit b/wit/key-events.wit deleted file mode 100644 index dddf869..0000000 --- a/wit/key-events.wit +++ /dev/null @@ -1,33 +0,0 @@ -package wasi:webgpu; - -// TODO: Move this into mini-canvas. - -interface key-events { - use wasi:io/poll@0.2.0.{pollable}; - - up-listener: func() -> key-up-listener; - - resource key-up-listener { - subscribe: func() -> pollable; - - get: func() -> option; - } - - down-listener: func() -> key-down-listener; - - resource key-down-listener { - subscribe: func() -> pollable; - - get: func() -> option; - } - - record key-event { - // should `code` and `key` be enums? - code: string, - key: string, - alt-key: bool, - ctrl-key: bool, - meta-key: bool, - shift-key: bool, - } -} diff --git a/wit/mini-canvas.wit b/wit/mini-canvas.wit deleted file mode 100644 index 892d3f3..0000000 --- a/wit/mini-canvas.wit +++ /dev/null @@ -1,35 +0,0 @@ -package wasi:webgpu; - -interface mini-canvas { - use graphics-context.{graphics-context}; - use wasi:io/poll@0.2.0.{pollable}; - - record create-desc { - height: u32, - width: u32, - offscreen: bool, - } - - resource mini-canvas { - constructor(desc: create-desc); - - connect-graphics-context: func(context: borrow); - - resize-listener: func() -> resize-listener; - - height: func() -> u32; - width: func() -> u32; - } - - resource resize-listener { - subscribe: func() -> pollable; - - get: func() -> option; - } - - record resize-event { - height: u32, - width: u32, - } - -} diff --git a/wit/pointer-events.wit b/wit/pointer-events.wit deleted file mode 100644 index 3d6bc7f..0000000 --- a/wit/pointer-events.wit +++ /dev/null @@ -1,36 +0,0 @@ -package wasi:webgpu; - -// TODO: Move this into mini-canvas. - -interface pointer-events { - use wasi:io/poll@0.2.0.{pollable}; - - up-listener: func() -> pointer-up-listener; - - resource pointer-up-listener { - subscribe: func() -> pollable; - - get: func() -> option; - } - - down-listener: func() -> pointer-down-listener; - - resource pointer-down-listener { - subscribe: func() -> pollable; - - get: func() -> option; - } - - move-listener: func() -> pointer-move-listener; - - resource pointer-move-listener { - subscribe: func() -> pollable; - - get: func() -> option; - } - - record pointer-event { - x: float64, - y: float64, - } -} diff --git a/wit/raw-display.wit b/wit/raw-display.wit new file mode 100644 index 0000000..791a55e --- /dev/null +++ b/wit/raw-display.wit @@ -0,0 +1,37 @@ +package wasi:webgpu; + + +/// The raw-display interface is designed for when an application has raw access to the full display framebuffer, such as on an embedded device. +interface raw-display { + + enum framebuffer-format { + rgb888, + } + + /// Gets information on the connected displays. + displays: func() -> list; + + + record display-info { + /// Internal id for the display, used to connect a grapics-context. + id: u32, + /// An implementation defined identifier of the display. Should be unique. + /// This is so that an application can differentiate e.g. between front and back screens on a device. + name: string, + width: u32, + height: u32, + /// The framebuffer format used. + format: framebuffer-format, + /// Whether the drawing is done in the main framebuffer or in a back buffer. + /// When drawing in a back buffer, blitting is neccessary. + back-buffer: bool, + } + + /// Connects a graphics context to a fisplay. + connect-graphics-context: func(context: borrow, display-id: u32); + + /// Swaps the front and back buffer of a display, if there is one. + /// TODO: should this invalidate the grapics-context connection? Since the connected buffer changes. + blit: func(display-id: u32); + +} \ No newline at end of file diff --git a/wit/window.wit b/wit/window.wit new file mode 100644 index 0000000..ce86473 --- /dev/null +++ b/wit/window.wit @@ -0,0 +1,230 @@ +package wasi:webgpu; + +interface window { + use graphics-context.{graphics-context}; + use wasi:io/poll@0.2.0.{pollable}; + + + /// https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_code_values + enum key-code { + // TODO is this needed? I don't think the MVP needs key codes. + unidentified, + } + + /// https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values#document_keys + /// Excerpt of the most useful keys. + enum special-key { + alt, + alt-graph, + caps-lock, + ctrl, + meta, + num-lock, + scroll-lock, + shift, + + arrow-down, + arrow-left, + arrow-right, + arrow-up, + end, + home, + page-down, + page-up, + + backspace, + clear, + delete, + insert, + paste, + + context-menu, + escape, + pause, + + brightness-down, + brightness-up, + print, + + f1, + f2, + f3, + f4, + f5, + f6, + f7, + f8, + f9, + f10, + f11, + f12, + f13, + f14, + f15, + f16, + f17, + f18, + f19, + f20, + + app-switch, + + channel-down, + channel-up, + fast-forward, + media-pause, + media-play, + media-play-pause, + media-record, + media-rewind, + media-stop, + media-track-next, + media-track-previous, + + audio-volume-down, + audio-volume-up, + audio-volume-mute, + } + + flags modifiers { + ctrl, + alt, + alt-graph, + shift, + caps-lock, + meta, + } + + /// Describes the key location on the keyboard, for keys that appear more than once on a keyboard. + enum key-location { + standard, + left, + right, + numpad, + } + + variant key { + /// The key has an associated Unicode scalar value. + character(u32), + /// The key is a key without a Unicode scalar value. + special(special-key), + /// A dead key was pressed. The next key event will contain the combined character. + dead, + /// The key could not be identified. + unidentified, + } + + + record key-data { + modifiers: modifiers, + key: key, + code: key-code, + location: key-location, + repeat: bool, + } + + flags mouse-buttons { + left, + middle, + right, + } + + record mouse { + position: position, + buttons: mouse-buttons, + } + + record wheel { + mouse: mouse, + x: f32, + y: f32, + } + + + /// Window system capabilities that are supported. + /// Methods that use unsupported capabilities will trap in WASM. + flags capabilities { + /// The windows have a title that can be set. + title, + /// The windows have position on a display which can be moved by the program. Not given e.g. on the web, where position is handled by CSS. + position, + // The windows have icons which can be set by the program. + icon, + /// Windows can request to go into fullscreen mode. This capability not being present can mean fullscreen windows + /// are not supported, or the window is forced fullscreen. + fullscreen, + /// Whether windows are resizable, be it by the user or the program itself. + size, + } + + + record position { + x: u16, + y: u16, + } + + record size { + width: u16, + height: u16, + } + + record create-desc { + title: string, + position: position, + size: size, + visible: bool, + } + + /// Checks whether window functionality is available at all in the runtime. + available: func() -> bool; + + resource window { + constructor(desc: create-desc); + + connect-graphics-context: func(context: borrow); + + set-title: func(title: string); + get-title: func() -> string; + + // TODO add a display interface for querying the displays, so programs can see the resolution and find out where on which screen the window is. + set-position: func(position: position); + get-position: func() -> position; + + set-size: func(size: size); + get-size: func() -> size; + + /// Sets the visibility of the window. + set-visible: func(visible: bool); + + subscribe-resize: func() -> pollable; + get-resize: func() -> option; + + subscribe-reposition: func() -> pollable; + get-reposition: func() -> option; + + + subscribe-key-down: func() -> pollable; + get-key-down: func() -> option; + + subscribe-key-up: func() -> pollable; + get-key-up: func() -> option; + + + subscribe-mouse-down: func() -> pollable; + get-mouse-down: func() -> option; + + subscribe-mouse-up: func() -> pollable; + get-mouse-up: func() -> option; + + subscribe-mouse-move: func() -> pollable; + get-mouse-move: func() -> option; + + subscribe-wheel: func() -> pollable; + get-wheel: func() -> option; + + + // If the pollable is ready, that means a close event has occurred. Since there is no data, ther e is no need + // for a get function, and the ready status should be cleared on query. + subscribe-close: func() -> pollable; + } +}