Skip to content

GL surfaces - #1

Merged
colemancda merged 21 commits into
masterfrom
feature/gl-surface
Nov 16, 2026
Merged

colemancda merged 21 commits into
masterfrom
feature/gl-surface

Conversation

@colemancda

Copy link
Copy Markdown
Member

Implements AppRuntime's graphics contracts (Surface, SurfaceDelegate; Graphics.md) on Linux, and draws GLSurface nodes in the player.

Depends on PureSwift/Cacao#46 (Image(pixels:)). CI here fails to build until it's merged into Cacao's develop.

ExampleGL on Linux

How

  • LinuxGraphics, a new host module. It opens libEGL.so.1 and libGLESv2.so.2 at run time, so the host links no GL; without them, graphics is unavailable.
  • One GLES 2.0 context for the app, on Mesa's surfaceless platform where there is one and otherwise the default display. Each surface on screen has a pbuffer of its pixel size, which is the default framebuffer the guest draws in.
  • Frames. A main-loop timer at about 60 Hz calls frame for each attached surface, then reads the pixels back (flipped, premultiplied) into Cacao's Image(pixels:). Before each frame it sends the moves since the last one, one per pointer. Whatever EGL context was current before a frame is current again after it; SDL's renderer may use one on the same thread.
  • Lost context. If the context is lost, every surface gets contextLost, a new context is made, and every surface gets contextRestored. rt_gl_context_generation changes for the wasm2c shim.
  • The view (Sources/LinuxUI/HostGLSurface.swift):
    • It attaches the surface on appear, sending resize with the size in pixels, and detaches it on disappear, which cancels pointers in contact and drops focus.
    • A drag is the mouse (pointer 0) with the primary button, and hovering moves it.
    • A click focuses the surface. Keys arrive as USB HID usage IDs, mapped from Cacao's key characters by their positions on a US layout.
    • sync-darwinui.sh keeps Host*.swift files and hooks NodeView's unknown-type case to HostNodeViews.
  • The packager. It knows the graphics contracts and graphics, and it links -lGLESv2 into hosts for apps that declare graphics. linux-app-host links it as-needed when built with an app library.
  • Image, CI and scripts. The dev image and CI gain Mesa's EGL and GLES (llvmpipe). docker.sh mounts CACAO_PATH and passes CACAO_SCREENSHOT_DELAY through.

Not yet

  • Pointer capture: setPointerCaptured returns false.
  • Scrolling, touches as touches, and mouse buttons other than the primary.
  • Pausing frames while the window is in the background.
  • PortMaster: devices bring their own GL, but ports don't build on Cacao yet.

Each frame is read back and uploaded again. A GL backend for Cacao's compositor could show the pbuffer as a texture instead.

Tested

  • Linux (Docker, Mesa llvmpipe): all suites pass, against the Cacao branch from Cacao#46 (CACAO_PATH).
    • LinuxGraphicsTests, 10 tests:
      • surface identifiers;
      • no input without a view;
      • moves coalesced per frame, a pointer's move before its up;
      • focus loss cancels contacts and releases keys;
      • detaching cancels contacts and stops frames;
      • resize comes first;
      • pixel flipping and premultiplying;
      • a real frame read back, including a resize;
      • the previous EGL context restored;
      • a lost context replaced.
    • The other suites: LinuxUI 43, Packager 21, Host 12, Bluetooth 12.
  • End to end: AppRuntime's ExampleGL as a linux-arm64 slice, linked into linux-app-host, run headless with CACAO_SCREENSHOT_DELAY=1. That's the screenshot above.
  • macOS: LinuxGraphics, LinuxUI and LinuxPackager build. A full macOS build already stops at CLinuxHost's features.h on master, so that failure isn't from this branch.

@colemancda
colemancda merged commit fb898a1 into master Nov 16, 2026
1 of 2 checks passed
@colemancda
colemancda deleted the feature/gl-surface branch November 16, 2026 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant