Donner SVG 0.8.0
0.8.0 ยท ebf353960.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
EditorWindow.h File Reference

EditorWindow - RAII wrapper around GLFW + OpenGL + Dear ImGui. Keeps the main binary thin by encapsulating everything that would otherwise be boilerplate: GLFW init, window creation, context current, glad loader, ImGui context, imgui_impl_glfw + imgui_impl_opengl3 setup, plus texture upload from a RendererBitmap. More...

#include <array>
#include <atomic>
#include <chrono>
#include <concepts>
#include <cstdint>
#include <deque>
#include <functional>
#include <memory>
#include <optional>
#include <ostream>
#include <string>
#include <string_view>
#include <vector>
#include "donner/base/Vector2.h"
#include "donner/gpu/DeviceLost.h"
#include "donner/svg/renderer/RendererInterface.h"
Include dependency graph for EditorWindow.h:
This graph shows which files directly or indirectly include this file:

Classes

struct  donner::editor::gui::internal::WgpuSurfaceRetryDecision
 Frame scheduling and reconfiguration actions after surface acquisition fails. More...
struct  donner::editor::gui::internal::WgpuDiagnosticReadbackDecision
 Retry and completion actions for one diagnostic readback result. More...
struct  donner::editor::gui::UiScaleConfig
 HiDPI settings derived from the native window/display scale. More...
class  donner::editor::gui::internal::PresentationSubmissionQueue
 Bounds pending UI submissions while retaining only the most recent input request. More...
struct  donner::editor::gui::internal::PresentationSubmissionQueue::Fence
 One submitted UI frame: the GPU serial that retires it and the input it presented. More...
struct  donner::editor::gui::internal::PresentationSubmissionQueue::CompletionObservation
 Serial and clock read after a bounded GPU completion confirmation. More...
struct  donner::editor::gui::internal::PresentationDeviceLossRecord
 Immutable first observation of settled presentation-device loss diagnostics. More...
struct  donner::editor::gui::internal::PresentationDeviceLossRecord::Observation
 Expensive owner-thread details acquired only for the first settled loss. More...
struct  donner::editor::gui::EditorWindowOptions
 Window creation settings and host UI configuration. More...
struct  donner::editor::gui::EditorWindowFrameTiming
 Host-frame timing captured by EditorWindow. More...
struct  donner::editor::gui::EditorWindowFonts
 Fonts loaded into this window's ImGui context for the editor shell. More...
struct  donner::editor::gui::EditorWindowInputOverride
 ImGui input state to inject for deterministic editor replay. More...
class  donner::editor::gui::EditorWindow
 Initializes GLFW + GL + ImGui when constructed, tears everything down in the destructor. One instance per process - ImGui's global state means we can't easily have two at once. More...
struct  donner::editor::gui::EditorWindow::PresentedDocumentFrameIdentity
 Stable document identity committed only after a complete framebuffer presentation. More...

Namespaces

namespace  donner
 Top-level Donner namespace, which is split into different sub-namespaces such as donner::svg and donner::css.

Typedefs

using GLFWscrollfun = void (*)(GLFWwindow*, double, double)
 GLFW-compatible callback for horizontal and vertical scroll offsets.

Enumerations

enum class  donner::editor::gui::internal::WgpuSurfaceFailureKind {
  Timeout ,
  OutdatedOrLost ,
  Setup ,
  Fatal
}
 Classification used to choose surface recovery behavior.

Functions

constexpr std::array< float, 4 > donner::editor::gui::internal::WasmSurfaceClearColor (std::array< float, 4 > transparentClearColor, bool premultipliedAlphaSupported) noexcept
 Pick the browser UI surface's clear color.
constexpr WgpuSurfaceRetryDecision donner::editor::gui::internal::WgpuSurfaceRetryDecisionFor (WgpuSurfaceFailureKind failure, unsigned consecutiveFailures) noexcept
 Bound retries so a permanently lost/device-fatal surface cannot turn the event-driven Wasm loop back into a hot spin.
constexpr WgpuDiagnosticReadbackDecision donner::editor::gui::internal::WgpuDiagnosticReadbackDecisionFor (bool captureSucceeded, unsigned consecutiveFailuresBeforeAttempt) noexcept
 Diagnostic readback is deliberately best-effort. A transient capture failure, including setup before mapAsync, gets two retries, while a successful capture or third consecutive failure completes the request so the event-driven browser loop cannot become a permanent readback spin.
constexpr bool donner::editor::gui::internal::ShouldRecheckPendingWgpuReadbackRequestsAfterCompletion (bool callbackAlive, WgpuDiagnosticReadbackDecision decision) noexcept
 Once the map callback releases the in-flight gate, every live completion must recheck the JavaScript request counters. A transient failure needs another attempt, while a successful or terminal attempt may have a newer request waiting behind it. The JavaScript wake helper filters completed requests, so this recheck does not create idle frames.
std::string donner::editor::gui::internal::BoundedPresentationDeviceLossReason (std::string_view reason)
 Copies a browser loss reason into the bounded payload retained for failure evidence.
UiScaleConfig donner::editor::gui::ComputeUiScaleConfig (int logicalWindowWidth, int framebufferWidth, double contentScaleX)
 Derive UI scaling from window size, framebuffer size, and the platform content scale hint. Prefers the framebuffer/logical ratio when available.

Variables

constexpr std::array< float, 4 > donner::editor::gui::internal::kWasmOpaqueSurfaceClearColor
 Opaque fallback clear color for the browser UI surface, matching the page background painted behind the canvas (donner/editor/wasm/editor.css: background: #101317).
constexpr std::size_t donner::editor::gui::internal::kMaximumPresentationDeviceLossReasonBytes = 1024
 Bound on the retained browser loss reason; a copy keeps at most one byte fewer than this.

Detailed Description

EditorWindow - RAII wrapper around GLFW + OpenGL + Dear ImGui. Keeps the main binary thin by encapsulating everything that would otherwise be boilerplate: GLFW init, window creation, context current, glad loader, ImGui context, imgui_impl_glfw + imgui_impl_opengl3 setup, plus texture upload from a RendererBitmap.

The class is intentionally narrow - it exposes only what the main binary needs:

  • construct/destruct (RAII handles cleanup)
  • shouldClose() / pollEvents() / waitEvents() / waitEventsTimeout() - event loop hooks
  • beginFrame() / endFrame() - ImGui frame bracketing + swap
  • uploadBitmap() - moves a CPU-side RGBA buffer into a GL texture (reuses the same texture ID across frames to avoid churn)
  • textureId() - exposes the current texture for ImGui::Image

Any code that wants to draw ImGui widgets happens between beginFrame() and endFrame() on the caller's side - this class doesn't own the widget tree, just the hosting surface.


Class Documentation

◆ donner::editor::gui::internal::PresentationSubmissionQueue::Fence

struct donner::editor::gui::internal::PresentationSubmissionQueue::Fence

One submitted UI frame: the GPU serial that retires it and the input it presented.

Class Members
uint64_t captureId = 0 Raster capture paired with the frame.
uint64_t frameId = 0 Presentation frame identity.
bool inputRepresented = false Whether the frame represents the input sealed with it; cleared when the full frame was not presented.
bool mouseDown = false Whether the primary button was down when sealed.
double pointerX = 0.0 Pointer x position when the frame was sealed.
double pointerY = 0.0 Pointer y position when the frame was sealed.
uint64_t serial = 0 Last GPU submission serial of the frame.
time_point submittedAt When the frame's work was submitted.
double viewportZoom = 0.0 Viewport zoom the frame was drawn with.

◆ donner::editor::gui::internal::PresentationSubmissionQueue::CompletionObservation

struct donner::editor::gui::internal::PresentationSubmissionQueue::CompletionObservation

Serial and clock read after a bounded GPU completion confirmation.

Class Members
time_point observedAt When the completion was observed.
uint64_t serial Highest completed submission serial observed.

◆ donner::editor::gui::internal::PresentationDeviceLossRecord::Observation

struct donner::editor::gui::internal::PresentationDeviceLossRecord::Observation

Expensive owner-thread details acquired only for the first settled loss.

Class Members
RcString browserReason
uint64_t completedSerial = 0
time_point observedAt
uint64_t oldestSerial = 0
uint64_t submittedSerial = 0

Function Documentation

◆ WasmSurfaceClearColor()

std::array< float, 4 > donner::editor::gui::internal::WasmSurfaceClearColor ( std::array< float, 4 > transparentClearColor,
bool premultipliedAlphaSupported )
nodiscardconstexprnoexcept

Pick the browser UI surface's clear color.

The Wasm UI surface clears uncovered render-pane pixels to alpha 0 so the worker's document canvas composites underneath it. That only produces transparency when the configured surface honors the alpha channel; a surface composited as opaque turns the same clear into solid black and blanks the whole editor area until real content covers it. Keep the transparent clear only when the surface actually reports premultiplied alpha; otherwise clear to the page background so the result matches what the page already paints behind the canvas.

Variable Documentation

◆ kWasmOpaqueSurfaceClearColor

std::array<float, 4> donner::editor::gui::internal::kWasmOpaqueSurfaceClearColor
inlineconstexpr
Initial value:
= {
16.0f / 255.0f, 19.0f / 255.0f, 23.0f / 255.0f, 1.0f}

Opaque fallback clear color for the browser UI surface, matching the page background painted behind the canvas (donner/editor/wasm/editor.css: background: #101317).