Donner 0.8.0-pre
Embeddable browser-grade SVG2 engine
Loading...
Searching...
No Matches
donner::editor::AsyncRenderer Class Reference

Public Member Functions

 AsyncRenderer (const AsyncRenderer &)=delete
AsyncRenderer & operator= (const AsyncRenderer &)=delete
 AsyncRenderer (AsyncRenderer &&)=delete
AsyncRenderer & operator= (AsyncRenderer &&)=delete
bool isBusy () const
 Returns true while a render is in flight or a finished result is waiting to be polled. The UI thread must not touch the Renderer or mutate the SVGDocument while this returns true.
bool hasRenderInFlightForTesting () const
 Returns true only while the worker may still be computing or cancelling a render. Unlike isBusy(), a staged result waiting in DoneState is not in flight.
bool waitUntilNoRenderInFlightForTesting (std::chrono::steady_clock::time_point deadline)
 Wait until no worker render is actively in flight.
void setReplayRenderDelayForTesting (std::chrono::milliseconds delay)
 Inject a fixed delay into each worker render attempt for replay tests.
void setReplayResultHoldFramesForTesting (int frameCount)
 Hold each staged result for a fixed number of poll attempts in replay tests.
std::uint64_t replayResultHoldPollCountForTesting () const
 Number of poll attempts that intentionally withheld a staged result for replay tests.
void requestRender (const RenderRequest &request)
 Post a render request to the worker. Non-blocking. If the worker is busy, this cancels the in-flight render at the next compositor safe point and replaces the pending request slot with the latest request.
void cancelInFlight ()
 Cancel an in-flight render without posting a replacement. Use when the current render is dispensable and the UI needs the worker to become idle before dispatching registry-touching input. Safe to call from any thread.
std::uint64_t cancelledRenderCount () const
 Design doc 0033 §M4 — count of renders that were cancelled mid-flight by a subsequent requestRender. Exposed for tests to assert preemption is engaging (vs. the worker silently queueing requests). Incremented under the internal mutex; safe to read from any thread.
std::optional< RenderResultpollResult ()
 If a render has completed since the last call, returns the resulting bitmap and transitions the worker back to idle. Returns std::nullopt if no render is pending-ready (either still busy or idle with nothing to hand off).
void setWakeCallback (std::function< void()> callback)
 Install a callback that the worker thread invokes when a render result or cancellation completes. Used by the editor's on-demand render loop to wake the UI thread (e.g. via glfwPostEmptyEvent) so fresh results or newly-idle deferred input get picked up without continuous polling.
void setTightBoundedSegmentsEnabled (bool enabled)
 Toggle whether the compositor uses tight-bounded segment rasterization (design doc 0027). The change applies at the start of the next worker iteration — renderFrame calls CompositorController::setTightBoundedSegmentsEnabled before compositing, which marks all cached segments dirty so the flip takes full effect that frame.
bool tightBoundedSegmentsEnabled () const
 Mirror of the current toggle state. UI reads this to render the correct check state in the View menu without racing the worker.
std::uint64_t compositorResetCountForTesting () const
 Number of times the worker has called CompositorController::resetAllLayers() since construction. Tests use this to assert that frame-version mutations do not masquerade as document replacements.
std::uint64_t compositorReconstructCountForTesting () const
 Number of times the worker has reconstructed compositor_ from scratch. First construction counts as one. Tests use this to verify that structural remaps preserve cached layer state across drag-writeback reparses.
svg::compositor::CompositorController::FastPathCounters compositorFastPathCountersForTesting () const
 Snapshot of the compositor's fast-path counters. Read-only — the worker writes them under the mutex when transitioning to Done. Returns zeros before the compositor is constructed (first render not yet requested). UI-thread safe.
svg::compositor::CompositorController::RenderFrameStats compositorRenderFrameStats () const
 Snapshot of the worker compositor's immediate-vs-cached raster costs from the latest completed render.
std::vector< svg::compositor::CompositorController::LayerInspectorRowcompositorLayerInspectorRows () const
 Snapshot of the compositor's per-layer diagnostic rows (design doc 0033 M1). Captured under the worker mutex at every Done transition; the UI thread copies the cached vector out under the lock. Empty before the first render lands or when the compositor isn't instantiated.
std::vector< svg::compositor::CompositorController::SegmentInspectorRowcompositorSegmentInspectorRows () const
 Snapshot of the compositor's per-segment diagnostic rows. Same capture point and locking as the per-layer rows.
std::vector< svg::compositor::CompositorController::CompositeTileSnapshotcompositorCompositeTiles () const
 Unified in-paint-order snapshot of every tile the compositor blits to produce the final composite (design doc 0033 §M1++). The editor's layer-inspector panel renders this list with thumbnails for every tile so the operator can see the comprehensive composite at a glance.
svg::compositor::CompositorController::StateSnapshot compositorState () const
 Compositor-wide diagnostic state: active-hints count, layer count, split-path active flag, drag-target entity, canvas size. The editor's layer-inspector panel renders this as a state header so the operator can spot mismatches between the editor's idea of the drag target and the compositor's.
Entity workerCompositorEntity () const
 The worker's current view of which entity is promoted. Read on the UI thread; the worker updates it under the same mutex as the other snapshot fields when transitioning to Done. entt::null when the worker hasn't promoted anything (e.g. promotion was refused). Compare against the editor's selection to spot races between the editor's selectedEntity and what the compositor actually holds.
Vector2i lastDocumentCanvasSize () const
 Output raster size from the worker's last-completed render. This is the presentation epoch: at high zoom it can be smaller than the SVG document's semantic canvas size because the worker rendered only the visible viewport plus margin.

Member Function Documentation

◆ compositorReconstructCountForTesting()

std::uint64_t donner::editor::AsyncRenderer::compositorReconstructCountForTesting ( ) const
inlinenodiscard

Number of times the worker has reconstructed compositor_ from scratch. First construction counts as one. Tests use this to verify that structural remaps preserve cached layer state across drag-writeback reparses.

Safe to read from the UI thread; incremented under the internal mutex on the worker.

◆ compositorResetCountForTesting()

std::uint64_t donner::editor::AsyncRenderer::compositorResetCountForTesting ( ) const
inlinenodiscard

Number of times the worker has called CompositorController::resetAllLayers() since construction. Tests use this to assert that frame-version mutations do not masquerade as document replacements.

Counts only resets driven by a request.documentGeneration mismatch; not the implicit reset performed on first compositor construction.

Safe to read from the UI thread; incremented under the internal mutex on the worker.

◆ setReplayRenderDelayForTesting()

void donner::editor::AsyncRenderer::setReplayRenderDelayForTesting ( std::chrono::milliseconds delay)

Inject a fixed delay into each worker render attempt for replay tests.

Parameters
delayDelay duration. Negative durations are clamped to zero.

◆ setReplayResultHoldFramesForTesting()

void donner::editor::AsyncRenderer::setReplayResultHoldFramesForTesting ( int frameCount)

Hold each staged result for a fixed number of poll attempts in replay tests.

Parameters
frameCountNumber of poll attempts to withhold a newly staged result.

◆ setTightBoundedSegmentsEnabled()

void donner::editor::AsyncRenderer::setTightBoundedSegmentsEnabled ( bool enabled)
inline

Toggle whether the compositor uses tight-bounded segment rasterization (design doc 0027). The change applies at the start of the next worker iteration — renderFrame calls CompositorController::setTightBoundedSegmentsEnabled before compositing, which marks all cached segments dirty so the flip takes full effect that frame.

Safe to call from the UI thread while a render is in flight; the flag is stored in an std::atomic<bool>, and the worker reads it at a well-defined point in each iteration.

◆ setWakeCallback()

void donner::editor::AsyncRenderer::setWakeCallback ( std::function< void()> callback)

Install a callback that the worker thread invokes when a render result or cancellation completes. Used by the editor's on-demand render loop to wake the UI thread (e.g. via glfwPostEmptyEvent) so fresh results or newly-idle deferred input get picked up without continuous polling.

The callback runs on the worker thread. It must be thread-safe and must NOT re-enter the renderer — a simple wake-up post into the window's event queue is the intended use.

◆ waitUntilNoRenderInFlightForTesting()

bool donner::editor::AsyncRenderer::waitUntilNoRenderInFlightForTesting ( std::chrono::steady_clock::time_point deadline)
nodiscard

Wait until no worker render is actively in flight.

Parameters
deadlineSteady-clock deadline for the bounded wait.

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