Donner SVG 0.8.0-pre
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
donner::editor::GlTextureCache Class Reference

Owns the GL textures the advanced editor uses for overlay and composited presentation. More...

#include "donner/editor/GlTextureCache.h"

Classes

struct  ThumbnailTextureView
 Upload a Layers-panel preview thumbnail bitmap into a per-row GL/WGPU texture and return its ImGui texture handle. More...
struct  TileView
 One composite-tile entry as presentation sees it: the GL texture handle (resolved from the upload cache) plus its paint-order geometry. More...

Public Member Functions

 GlTextureCache (std::shared_ptr<::donner::geode::GeodeDevice > geodeDevice=nullptr)
 GlTextureCache (const GlTextureCache &)=delete
GlTextureCache & operator= (const GlTextureCache &)=delete
void initialize ()
void uploadComposited (const RenderResult::CompositedPreview &preview, std::optional< EditorRasterViewport > rasterViewport=std::nullopt)
 Upload the worker's tile snapshot into per-tile GL textures. Allocates/reuses one texture per tile id; bumps a per-tile upload-generation so identity uploads short-circuit; evicts textures whose tile is absent from the snapshot.
void uploadCompositedOverview (const RenderResult::CompositedPreview &preview, const EditorRasterViewport &rasterViewport)
 Upload a full-document overview preview without replacing active viewport-bounded tiles.
void advancePresentationFrame ()
 Advance one presentation frame, retiring WGPU texture snapshots whose handles have aged past the backend's frames-in-flight window.
void resetComposited ()
ThumbnailTextureView uploadThumbnail (std::uint64_t key, const svg::RendererBitmap &bitmap)
ThumbnailTextureView retainThumbnailTextureSnapshot (std::uint64_t key, std::shared_ptr< const svg::RendererTextureSnapshot > textureSnapshot)
void setDocumentCompositeBytes (std::uint64_t bytes)
 Report bytes retained by the non-WGPU explicit document compositor.
void retainThumbnailsOnly (const std::vector< std::uint64_t > &liveKeys)
 Evict every cached thumbnail texture whose key is not in liveKeys, freeing the backing GL/WGPU texture. Called after each Layers-panel render so thumbnails for removed rows do not leak across refreshes.
std::size_t thumbnailTextureCount () const
 Number of thumbnail textures currently retained (testing/diagnostics).
const std::vector< TileView > & tiles () const
 Paint-order tile view; metadata-only direct-surface entries have a zero texture handle. Empty when no composited preview has been uploaded yet (or the preview was cleared via resetComposited).
const std::vector< TileView > & overviewTiles () const
 Last retained unbounded full-document tile set, drawn underneath viewport-bounded tiles as a coherent zoom-out fallback.
bool activeTilesViewportBounded () const
 True when the active tile set was rendered from a viewport-bounded raster target.
int metadataOnlyMissCount () const
 Number of metadata-only tiles skipped during the most recent composited upload because their cached texture identity was absent or stale.
int duplicateLiveTextureCount () const
 Number of duplicate live texture handles found in the most recent composited upload across different tile ids.
const FrameCostBreakdown::CompositedUploadlastCompositedUploadCost () const
 Cost counters for the most recent composited upload.
PresentationResourceStats presentationResourceStats () const
 Resource counters for the textures currently retained by this cache.
PresentationCoverageDiagnostics coverageDiagnostics () const
 Coverage counters for active bounded tiles and retained overview infill.

Detailed Description

Owns the GL textures the advanced editor uses for overlay and composited presentation.

The cache is intentionally dumb: callers decide when textures should update; this class only owns the texture names, uploads pixel buffers, and tracks the currently-valid dimensions.

Composited preview rendering is per-tile: instead of three named bg/promoted/fg textures, the cache owns one GL texture per CompositedTile (keyed on the tile id), allocated lazily on first upload and freed when the tile leaves the snapshot. The GL presentation compositor samples tiles() in paint order into one pane-sized texture. WebGPU builds retain the direct-framebuffer presentation path.


Class Documentation

◆ donner::editor::GlTextureCache::ThumbnailTextureView

struct donner::editor::GlTextureCache::ThumbnailTextureView

Upload a Layers-panel preview thumbnail bitmap into a per-row GL/WGPU texture and return its ImGui texture handle.

Reuses the same Donner-bitmap -> texture path as the render pane (UploadBitmap / uploadBitmapToWgpu). One texture is owned per key (the Layers row stable id); it is reuploaded only when the bitmap's dimensions or a cheap content fingerprint change, so calling this every frame with an unchanged thumbnail does not re-upload. Donner renders the thumbnail pixels; this only blits them to a texture – see CLAUDE.md "No Rendering Vector Graphics With ImGui".

Parameters
keyStable id of the Layers row the thumbnail belongs to.
bitmapDonner-rendered RGBA thumbnail bitmap.
Returns
ImGui texture handle plus the UV range that contains the valid payload, or an empty view if the texture could not be created.
Class Members
ImTextureID texture = 0 ImGui texture handle.
Vector2d uvBottomRight = Vector2d(1.0, 1.0) Bottom-right valid payload UV.

◆ donner::editor::GlTextureCache::TileView

struct donner::editor::GlTextureCache::TileView

One composite-tile entry as presentation sees it: the GL texture handle (resolved from the upload cache) plus its paint-order geometry.

Class Members
Vector2d bitmapDimsDoc = Vector2d::Zero()
Vector2i bitmapDimsPx = Vector2i::Zero()
Vector2d canvasOffsetDoc = Vector2d::Zero()
Transform2d documentFromCachedDocument = Transform2d()
Vector2d dragTranslationDoc = Vector2d::Zero()
uint64_t generation = 0
string id
bool isDragTarget = false
Kind kind = RenderResult::CompositedTile::Kind::Segment
Entity layerEntity = entt::null
bool metadataOnly = false
Vector2i rasterCanvasSize = Vector2i::Zero()
ImTextureID texture = 0
shared_ptr< const RendererTextureSnapshot > textureSnapshot
Vector2d uvBottomRight = Vector2d(1.0, 1.0)

Member Function Documentation

◆ retainThumbnailsOnly()

void donner::editor::GlTextureCache::retainThumbnailsOnly ( const std::vector< std::uint64_t > & liveKeys)

Evict every cached thumbnail texture whose key is not in liveKeys, freeing the backing GL/WGPU texture. Called after each Layers-panel render so thumbnails for removed rows do not leak across refreshes.

Parameters
liveKeysStable ids of the rows currently shown by the panel.

The documentation for this class was generated from the following file: