Renders SVG documents with Geode directly into a window surface the host owns, keeping every frame on the GPU from rendering through presentation. More...
#include "donner/svg/renderer/GeodeSurfaceRenderer.h"
Public Types | |
| enum class | FrameStatus { Presented , Skipped , ResizeNeeded , Failed } |
| Outcome of one draw call. More... | |
Public Member Functions | |
| ~GeodeSurfaceRenderer () | |
| Releases the surface, then the device. Native builds wait, bounded, for submitted frames to finish; WebAssembly builds do not wait. | |
| GeodeSurfaceRenderer (const GeodeSurfaceRenderer &)=delete | |
| GeodeSurfaceRenderer & | operator= (const GeodeSurfaceRenderer &)=delete |
| GeodeSurfaceRenderer (GeodeSurfaceRenderer &&)=delete | |
| GeodeSurfaceRenderer & | operator= (GeodeSurfaceRenderer &&)=delete |
| bool | resize (Vector2i sizePx, std::string *error=nullptr) |
| Changes the drawable size, for example after the host view resizes or moves to a display with a different scale. | |
| Vector2i | size () const |
| Current drawable size in pixels. | |
| FrameStatus | draw (SVGDocument &document) |
Draws document into the next surface frame and presents it. | |
| bool | isDeviceLost () const |
| True once the GPU device has been lost; every later draw returns Failed. | |
| void | trimTexturePool (RendererGeodeTexturePoolTrim level) |
| Frees pooled textures no frame is using, as RendererGeode::trimTexturePool does. | |
Static Public Member Functions | |
| static std::unique_ptr< GeodeSurfaceRenderer > | CreateForMetalLayer (void *metalLayer, Vector2i sizePx, std::string *error=nullptr) |
| Creates a renderer that presents to a Core Animation Metal layer. | |
| static std::unique_ptr< GeodeSurfaceRenderer > | CreateForCanvas (std::string_view canvasSelector, Vector2i sizePx, std::string *error=nullptr) |
| Creates a renderer that presents to a browser <canvas> element through WebGPU. | |
Renders SVG documents with Geode directly into a window surface the host owns, keeping every frame on the GPU from rendering through presentation.
Available with Geode enabled (donner.configure(renderer = "geode")) on macOS, presenting to a CAMetalLayer (CreateForMetalLayer), and in WebAssembly builds with the browser backend (--@donner//donner/svg/renderer/geode:browser_backend=true), presenting to a <canvas> (CreateForCanvas).
This is the application-embedding entry point: it opens a GPU root, the Geode device and a runtime surface, and acquires, draws and presents one frame per draw.
Metal layer contract:
Typical use from a macOS view that is already in a window:
Canvas contract:
Linux (Vulkan) window presentation has no public entry point yet.
|
strong |
Outcome of one draw call.
| Enumerator | |
|---|---|
| Presented | The frame was drawn and handed to the surface for presentation. |
| Skipped | No surface frame was available in time. Nothing was drawn; draw again next frame. |
| ResizeNeeded | The surface's pixel extent differs from the configured size. Nothing was drawn; call resize with the current size (for a Metal layer, bounds.size * contentsScale), then draw again. |
| Failed | The device was lost, or the surface refused a frame. Recreate the renderer to continue. |
|
static |
Creates a renderer that presents to a browser <canvas> element through WebGPU.
| canvasSelector | CSS selector naming the canvas, such as "#canvas". In a worker, which has no document, the selector instead names an OffscreenCanvas registered through Emscripten's offscreen-canvas support; a leading # is stripped, so "#id" works there. |
| sizePx | Drawing-buffer size in pixels. Both dimensions must be positive. |
| error | When non-null, receives a description of why creation failed. |
|
static |
Creates a renderer that presents to a Core Animation Metal layer.
| metalLayer | The host's CAMetalLayer*, bridged to void*. It must outlive the renderer. |
| sizePx | Drawable size in pixels (bounds.size * contentsScale). Both dimensions must be positive. |
| error | When non-null, receives a description of why creation failed. |
|
nodiscard |
Draws document into the next surface frame and presents it.
The document is drawn at its canvas size; set it to size() to fill the surface.
| document | Document to draw. |
|
nodiscard |
Changes the drawable size, for example after the host view resizes or moves to a display with a different scale.
Resizing to the current size does nothing.
| sizePx | New size in pixels (for a Metal layer, bounds.size * contentsScale). Both dimensions must be positive. |
| error | When non-null, receives a description of why the resize failed. |
| void donner::svg::GeodeSurfaceRenderer::trimTexturePool | ( | RendererGeodeTexturePoolTrim | level | ) |
Frees pooled textures no frame is using, as RendererGeode::trimTexturePool does.
Call it with RendererGeodeTexturePoolTrim::All when the host hides the surface, for example on a browser visibilitychange to hidden, and with ToFloor when drawing pauses.
| level | How much to free. |