|
|
Donner 0.8.0-pre
Embeddable browser-grade SVG2 engine
|
Represents a single compositor layer with its cached bitmap and dirty state. More...
#include "donner/svg/compositor/CompositorLayer.h"
Public Member Functions | |
| CompositorLayer (uint32_t id, Entity entity, Entity firstEntity, Entity lastEntity) | |
| Construct a layer for the given entity. | |
Accessors | |
| uint32_t | id () const |
| Returns the unique layer identifier. | |
| Entity | entity () const |
| Returns the root entity of this layer. | |
| Entity | firstEntity () const |
| Returns the first entity in the layer's render range. | |
| Entity | lastEntity () const |
| Returns the last entity in the layer's render range. | |
| const RendererBitmap & | bitmap () const |
| Returns the cached bitmap for this layer. Empty if not yet rasterized. | |
| const std::shared_ptr< const RendererTextureSnapshot > & | textureSnapshot () const |
| Returns the cached GPU texture for this layer, if the renderer produced one. | |
| const Transform2d & | canvasFromBitmap () const |
| Returns the canvasFromBitmap transform applied during blitting. Maps bitmap-local pixel coordinates (origin at the bitmap's top left, i.e. the rasterize-time coordinate frame) into canvas pixels. Identity when the DOM entity has not moved since rasterization; a pure translation during the bitmap-reuse fast path; other transforms force re-rasterization before compose. | |
| const Vector2d & | canvasOffset () const |
| Canvas-space top-left position of the bitmap's pixel (0,0). Zero for canvas-sized layers (the rasterize spans the whole canvas and the bitmap's origin is the canvas origin). Non-zero for intrinsic- sized layers, where the rasterize covers only the entity's world-bounds + filter padding and the bitmap is placed back into the canvas at canvasOffset. | |
| void | setCanvasOffset (const Vector2d &offset) |
| Set the canvas-space top-left where this layer's bitmap blits back. Called by CompositorController::rasterizeLayer immediately after setBitmap when the layer was rasterized into a tight-bound offscreen. | |
| const std::optional< Transform2d > & | bitmapEntityFromWorldTransform () const |
| Returns the entity's absolute transform at the moment the cached bitmap was rasterized, if any. The compositor uses this to decide whether a subsequent DOM transform mutation can reuse the bitmap by updating canvasFromBitmap_ (pure-translation delta) vs forcing re-rasterization (any other delta). | |
| bool | isDirty () const |
| Returns true if the layer needs re-rasterization. | |
| bool | hasValidBitmap () const |
| Returns true if the layer has a valid cached bitmap. | |
| bool | hasRenderablePayload () const |
| Returns true if the layer has any renderable cached payload. | |
| FallbackReason | fallbackReasons () const |
| Returns the fallback reasons for this layer, or FallbackReason::None. | |
| bool | requiresConservativeFallback () const |
| Returns true if this layer requires conservative fallback (re-rasterize every frame). | |
Mutators | |
| void | markDirty () |
| Mark the layer as needing re-rasterization. | |
| void | clearDirty () |
| Clear the dirty flag after re-rasterization. | |
| void | setBitmap (RendererBitmap bitmap, const Transform2d &worldFromEntityTransform) |
| Set the cached bitmap for this layer, along with the entity's absolute transform at the moment of rasterization. Stored so a subsequent fast-path DOM translation mutation can detect that the bitmap's pixel content is still valid (only its world-space position drifted) and reuse it via a compose-offset delta. | |
| void | setTextureSnapshot (std::shared_ptr< const RendererTextureSnapshot > texture, const Transform2d &worldFromEntityTransform) |
| Set the cached GPU texture for this layer. | |
| uint64_t | generation () const |
| Monotonic version counter — bumped on every setBitmap. The editor uses it to decide whether to re-upload this layer's bitmap to its cached GL texture. | |
| void | setGeneration (uint64_t generation) |
| Override the generation with a controller-supplied value. Per-object ++generation_ resets to 1 whenever a fresh CompositorLayer is built (e.g. after resetAllLayers on document replace). Because entity ids are reused across a document swap, that fresh "1" can collide with the generation the editor already cached for the previous document's layer at the same entity id, suppressing the re-upload and leaving stale pixels on screen. CompositorController calls this with a process-monotonic counter (shared with static segments) so each rasterization is globally unique. See CompositorController::rasterizeLayer. | |
| uint32_t | rasterizeCount () const |
| Cumulative number of times this layer's bitmap has been re-rasterized since construction. Increments with generation_, but is exposed as a separate counter so the editor's layer-inspector panel can show a "rasterize count" column without ambiguity over what generation means (the editor uses generation for GL texture upload gating). | |
| double | lastRasterizeMs () const |
| Wall-clock milliseconds the most recent rasterizeLayer call took, as measured by the compositor. Zero if the layer has never been rasterized. See CompositorController::snapshotLayerInspectorRows. | |
| void | setLastRasterizeMs (double ms) |
| Record the wall-clock duration of the most recent rasterization. Called by CompositorController::rasterizeLayer immediately after setBitmap. | |
| const ImmediateLayerPlan & | immediatePlan () const |
| Returns immediate-mode eligibility and timing diagnostics for this layer. | |
| void | setImmediatePlan (ImmediateLayerPlan plan) |
| Set immediate-mode eligibility and timing diagnostics for this layer. | |
| bool | isImmediate () const |
| Returns true when editor-facing presentation treats this layer as a transient immediate tile. | |
| void | setCanvasFromBitmap (const Transform2d &transform) |
| Set the canvasFromBitmap transform used during blitting. | |
| void | setFallbackReasons (FallbackReason reasons) |
| Set the fallback reasons for this layer. | |
| void | setEntityRange (Entity firstEntity, Entity lastEntity) |
| Update the entity range rendered into this layer. | |
| void | remapEntities (Entity newEntity, Entity newFirstEntity, Entity newLastEntity) |
| Remap the layer's entity ids (entity_, firstEntity_, lastEntity_) from old to new — used by CompositorController::remapAfterStructural
Replace when a structurally-identical document swap gives every element a new entity id but leaves the rasterized pixels valid. The cached bitmap_, canvasFromBitmap_, bitmapEntityFromWorld
Transform_, and fallbackReasons_ survive unchanged — they're keyed on position-in-paint-order, not entity id. | |
| void | setLayerId (uint32_t id) |
| Reassign the layer's numeric id. Used by CompositorController::reconcileLayers() when the resolver reassigns an id for a still-promoted entity (e.g. after a higher-weight neighbor demotes and this entity shifts up). The cached bitmap, dirty flag, and composition transform are preserved across an id change. | |
Represents a single compositor layer with its cached bitmap and dirty state.
Each layer corresponds to a promoted entity subtree. The layer caches its rasterized output and tracks whether re-rasterization is needed (dirty) or only the composition transform has changed.
| donner::svg::compositor::CompositorLayer::CompositorLayer | ( | uint32_t | id, |
| Entity | entity, | ||
| Entity | firstEntity, | ||
| Entity | lastEntity ) |
Construct a layer for the given entity.
| id | Unique layer identifier. |
| entity | The root entity of this layer. |
| firstEntity | First entity in the layer's render range (inclusive). |
| lastEntity | Last entity in the layer's render range (inclusive). |
|
inlinenodiscard |
Returns the canvasFromBitmap transform applied during blitting. Maps bitmap-local pixel coordinates (origin at the bitmap's top left, i.e. the rasterize-time coordinate frame) into canvas pixels. Identity when the DOM entity has not moved since rasterization; a pure translation during the bitmap-reuse fast path; other transforms force re-rasterization before compose.
When the bitmap is intrinsic-sized (smaller than the canvas, rasterized into a tight bound — see canvasOffset()), the full compose transform is Translate(canvasOffset) * canvasFromBitmap. canvasFromBitmap_ itself still encodes only the post-rasterize drift, so the fast-path math is unchanged.
|
inlinenodiscard |
Canvas-space top-left position of the bitmap's pixel (0,0). Zero for canvas-sized layers (the rasterize spans the whole canvas and the bitmap's origin is the canvas origin). Non-zero for intrinsic- sized layers, where the rasterize covers only the entity's world-bounds + filter padding and the bitmap is placed back into the canvas at canvasOffset.
See design doc 0033 §M2 "Intrinsic-size layer rasterization".
|
inline |
Set the cached bitmap for this layer, along with the entity's absolute transform at the moment of rasterization. Stored so a subsequent fast-path DOM translation mutation can detect that the bitmap's pixel content is still valid (only its world-space position drifted) and reuse it via a compose-offset delta.
Bumps generation_ so the editor can tell a fresh rasterization from a preserved-across-remap cache via CompositorTile:: generation and skip redundant GL texture uploads.