Skip to content
简体中文

Cross-Platform GPU Architecture

egfx is structured into three strict layers so upper-layer Emacs Lisp code never touches C pointers, shader source, or platform window handles.

The L0 host (packages/egfx/native/core/) manages OS compositor child views synchronized to Emacs window and buffer geometry:

  • macOS (egfx_host_macos.m): Cocoa child view backed by CAMetalLayer, NSTrackingCursorUpdate cursor shaping, burst-coalesced presentation, and CAShapeLayer even-odd occlusion hole masking.
  • Windows (egfx_host_win32.c): Win32 child HWND on a shared Direct3D 11 device (with WARP fallback), DXGI Flip-Model swapchains through DirectComposition, GetDpiForWindow Per-Monitor DPI snapping, and SetWindowRgn clipping/holes.
  • Linux (egfx_host_linux.c): Vulkan 1.0+ WSI loaded via runtime dlopen("libvulkan.so.1") with zero -dev headers, 32-bit ARGB TrueColor X11 visual + XShape holes, Wayland desynchronized wl_subsurface, and GTK4/GTK3 window discovery.
  • Partial-scroll clipping & Z-order stacking: Surfaces clip cleanly at window boundaries without bleeding over header-line, mode-line, or adjacent splits.
  • Real-time child-frame occlusion: Floating child frames (which-key, corfu, posframe, floating transient menus) automatically punch live holes in overlapping GPU layers and native containers.
  • Zero-polling < 1 ms event delivery: Native pointer, scroll, pinch, and raw key events wake Emacs through make-pipe-process + env->open_channel with zero polling timers.
  • Graceful non-GPU fallbacks: Automatically degrades to Emacs 32 :type canvas, in-memory images, Kitty Graphics Protocol, 24-bit half-block text, ASCII, or mock for headless testing.

Built-in providers (egfx-2d and pixels) compile strictly against egfx_abi.h and share a platform-neutral GPU contract implemented natively on Metal (MSL), Direct3D 11 (HLSL SM 5.0), and Vulkan (offline SPIR-V):

  1. Instanced SDF 2D vector pass: Analytical anti-aliased boxes, rounded boxes, analytical drop shadows, circles, segments, polylines, cubic Beziers, triangles, ear-clipped polygons, arcs/pies, linear & radial gradients, and per-item/group scissor clips.
  2. GPU-textured rounded images: LRU texture cache backed by native decoding (ImageIO, dlopen GdkPixbuf, WIC) plus direct RGBA8 uploads.
  3. Instanced HiDPI UTF-8 / CJK text atlas: 2048 × 2048 shelf-packed glyph atlas with epoch recovery and platform-native rasterization (CoreText, dlopen Pango/Cairo, DirectWrite/Direct2D).
  4. Zero-malloc pixel blitter (pixels): Pointer-swapped staging buffers for 60 FPS video frames, emulators, and external renderers.

lisp/egfx-canvas.el exposes the declarative egfx-canvas API:

  • Automatic pointer policy upgrades (pass-through → hover → capture) based on declared interactivity.
  • Emacs keyboard focus retained by default (:key-mode 'emacs); opt into :key-mode 'raw only for physical game input.
  • Static canvases hold zero Emacs timers and 0% idle CPU; closing the canvas or killing its owner buffer tears down all active animations and OS views immediately.