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.
1. L0 Native Host Microkernel
Section titled “1. L0 Native Host Microkernel”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 byCAMetalLayer,NSTrackingCursorUpdatecursor shaping, burst-coalesced presentation, andCAShapeLayereven-odd occlusion hole masking. - Windows (
egfx_host_win32.c): Win32 childHWNDon a shared Direct3D 11 device (with WARP fallback), DXGI Flip-Model swapchains through DirectComposition,GetDpiForWindowPer-Monitor DPI snapping, andSetWindowRgnclipping/holes. - Linux (
egfx_host_linux.c): Vulkan 1.0+ WSI loaded via runtimedlopen("libvulkan.so.1")with zero-devheaders, 32-bit ARGB TrueColor X11 visual +XShapeholes, Wayland desynchronizedwl_subsurface, and GTK4/GTK3 window discovery.
Core L0 Capabilities
Section titled “Core L0 Capabilities”- 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, floatingtransientmenus) automatically punch live holes in overlapping GPU layers and native containers. - Zero-polling
< 1 msevent delivery: Native pointer, scroll, pinch, and raw key events wake Emacs throughmake-pipe-process+env->open_channelwith 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, ormockfor headless testing.
2. L1 Built-In GPU Rendering Engine
Section titled “2. L1 Built-In GPU Rendering Engine”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):
- 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.
- GPU-textured rounded images: LRU texture cache backed by native decoding (
ImageIO,dlopenGdkPixbuf,WIC) plus direct RGBA8 uploads. - Instanced HiDPI UTF-8 / CJK text atlas:
2048 × 2048shelf-packed glyph atlas with epoch recovery and platform-native rasterization (CoreText,dlopenPango/Cairo,DirectWrite/Direct2D). - Zero-malloc pixel blitter (
pixels): Pointer-swapped staging buffers for 60 FPS video frames, emulators, and external renderers.
3. High-Level Pure-Elisp Canvas Layer
Section titled “3. High-Level Pure-Elisp Canvas Layer”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 'rawonly 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.