Guides

Display and input

Give the guest a 2D or 3D virtio GPU, drawn on a canvas with WebGPU or WebGL2, and a keyboard, tablet or mouse that the user or your code controls.

A display

Add a virtio GPU and the guest gets a graphical console and /dev/dri/card0:

warm-system-aarch64 ... -device virtio-gpu-pci -device virtio-keyboard-pci -device virtio-tablet-pci
DeviceWhat the guest gets
virtio-gpu-pciA 2D display: a framebuffer console, a software-drawn desktop, and a hardware cursor. It's 1280×800 by default; set xres and yres as in QEMU. Warm64's own refresh_rate sets the display mode's refresh rate in millihertz (refresh_rate=60000 for 60 Hz); the default is 75 Hz, as in QEMU's EDID.
virtio-gpu-gl-pciThe same, plus 3D, with -display …,gl=on (see below).
ramfbA plain framebuffer that firmware sets up, for firmware and kernels without a virtio GPU driver.

As with QEMU on macOS, there's no virtio-vga, so -vga virtio fails with Virtio VGA not available.

Where the picture goes

Your code gets the picture through the host's display:

  • A canvas. Pass an OffscreenCanvas and Warm64's GPU worker draws on it directly.
  • Frames. Pass a frame(width, height, pixels) callback to receive each changed frame, up to refreshHz times a second.
  • Screenshots. screendump saves the screen as PNG or PPM, with or without a display attached.
const canvas = document.querySelector("canvas").transferControlToOffscreen();
const vm = await WARM.launch("... -accel wapi -display default,gl=on -device virtio-gpu-gl-pci -device virtio-keyboard-pci", {
  ...browserWARMHost(),
  display: { canvas },
});

In Node there's no window, so use frame or screendump.

await vm.qmp("screendump", { filename: "screen.png", format: "png" });

When the page resizes, tell the guest, just as QEMU does when you resize its window:

vm.setUIInfo({ width: 1440, height: 900 });

3D graphics

virtio-gpu-gl-pci adds 3D. As in QEMU, it needs OpenGL turned on for the display (it's off by default), and -accel wapi draws it with the host's GPU (see What renders it):

warm-system-aarch64 ... -accel wapi -display default,gl=on -device virtio-gpu-gl-pci

Without gl=on (or gl=core, gl=es), the command line is refused with QEMU's error, The display backend does not have OpenGL support enabled. QEMU's macOS build has no virtio-gpu-gl-pci, but Warm64 has it on every host.

The guest uses it through wision, Warm64's own guest driver. It provides EGL, OpenGL ES 3.0, OpenGL 2.1 through GLX, GBM, and video decoding through VA-API (VP9, H.264 and AV1, 8- and 10-bit). Until wision is installed, the guest draws with its own software OpenGL (Mesa's llvmpipe), because Mesa's virgl driver gets no answer from the device.

Installing wision

You don't need to prepare the guest image: wision installs itself on any arm64 Linux, glibc or musl. You can offer the installer in one of two ways, and neither is there unless you ask for it.

  • As a disk. -drive file=wision:installer,if=virtio attaches the installer as a read-only disk, after the other drives. In the guest, as root, run it from that disk (/dev/vdb if there's one other disk):
  sh < /dev/vdb

It needs nothing but the shell and dd.

  • On the network. -netdev user,id=n0,wision=on answers to the name wision on the guest's network and serves the installer there:
  curl wision | sh
  # or
  wget -qO- wision | sh

The installer puts the driver in /usr/local/lib/wision, first on the dynamic loader's path, and leaves a wision command behind: wision status, wision update, and wision remove, which restores the system as it was. Your next login runs the session on wision.

What renders it

Machine and hostRenders with
-accel tcg, QEMU's defaultSoftware, on every host
-accel wapi, a browser with WebGPUWebGPU
-accel wapi, a browser with WebGL2WebGL2
-accel wapi, neither, or a display that offers only softwareSoftware
NodeSoftware

With -accel wapi, Warm64 tries WebGPU first, then WebGL2, then software, among the APIs -wapi allows. -wapi webgl2 leaves WebGPU out, and with -wapi webgpu a browser without WebGPU draws in software rather than with WebGL2. gl=core and gl=es turn OpenGL on just as gl=on does; they don't choose anything else. The host's display has a say too: with gl: "software", it draws in software whatever the command line asks, as QEMU does on a computer whose OpenGL is software-only.

Smooth animations

An emulated core can't always finish every frame of an animation in the time the guest plans for it, so on the host's clock a desktop's animations skip frames. With -icount shift=auto, the guest's clock stretches while it's busy. Animations then show every frame, a little slower, and the guest catches up with the host's time when it's idle. As in QEMU, -icount is off by default, and x-elastic=off keeps QEMU's own -icount clock. See Warm64's additions.

Keyboard and pointer

As in QEMU, virtio-keyboard-* adds a keyboard, virtio-tablet-* an absolute tablet, and virtio-mouse-* a relative mouse, each only the one thing it names. Linux calls them QEMU Virtio Keyboard, QEMU Virtio Tablet and QEMU Virtio Mouse.

As in QEMU, the pointing device listed last on the command line decides the mode:

  • A tablet: the guest's pointer follows the user's pointer, and the display doesn't draw the guest's cursor, since the page's own pointer is the cursor. To show the guest's cursor image on it instead, as QEMU's GTK display does, give the display a cursor hook.
  • A mouse: the machine is in relative mode, as QEMU is with -device virtio-mouse-pci. The display draws the guest's cursor wherever the guest puts it, and the page captures the pointer and sends its movement, as QEMU's window does after a click. See Embedding in a web page.

query-mice (HMP info mice) lists the pointing devices and marks the current one, which receives the button presses. HMP mouse_set INDEX switches to another.

To use USB instead, add a controller and the devices:

warm-system-aarch64 ... -device qemu-xhci -device usb-kbd -device usb-tablet

Sending input from code

// type Enter
await vm.qmp("send-key", { keys: [{ type: "qcode", data: "ret" }] });
// click in the middle of the screen
await vm.qmp("input-send-event", { events: [
  { type: "abs", data: { axis: "x", value: 16384 } },
  { type: "abs", data: { axis: "y", value: 16384 } },
  { type: "btn", data: { down: true, button: "left" } },
  { type: "btn", data: { down: false, button: "left" } },
] });

Pointer positions run from 0 to 32767 across the screen. rel events move the mouse when there is one, and an x and a y in the same command count as one motion. See send-key and input-send-event in QEMU's QMP reference.

USB

QEMU's xHCI controller, -device qemu-xhci, takes QEMU's USB devices: a keyboard (usb-kbd), a tablet (usb-tablet), a mouse (usb-mouse), disks (usb-storage and usb-uas, see Disks and images) and the rest. As in QEMU, the virt machine has no USB controller of its own. -usb doesn't add one, and info usb says USB support not enabled until you add a controller.

See also