Donner SVG 0.8.0-pre
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 <cstdint>
#include <functional>
#include <memory>
#include <ostream>
#include <string>
#include <string_view>
#include <vector>
#include "donner/base/Vector2.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
struct  donner::editor::gui::internal::WgpuDiagnosticReadbackDecision
struct  donner::editor::gui::UiScaleConfig
 HiDPI settings derived from the native window/display scale. More...
struct  donner::editor::gui::EditorWindowOptions
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...

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)

Enumerations

enum class  WgpuSurfaceFailureKind {
  Timeout ,
  OutdatedOrLost ,
  Setup ,
  Fatal
}

Functions

constexpr bool donner::editor::gui::internal::ShouldShareWgpuFramebufferGeodeDevice (bool emscriptenBuild) noexcept
 The Wasm render worker owns a separate WebGPU device, so the UI's primary and direct-framebuffer renderers remain single-threaded and may share one GeodeDevice wrapper. Desktop's AsyncRenderer shares the primary wrapper across threads; its UI-only framebuffer renderers need a separate wrapper to isolate mutable counters and deferred-destroy queues.
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.
UiScaleConfig donner::editor::gui::ComputeUiScaleConfig (int logicalWindowWidth, int framebufferWidth, double contentScaleX)
 Derive the editor's UI scaling from logical window size, framebuffer size, and the platform's 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).

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.

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).