browser DOM support

This commit is contained in:
Jorijn van der Graaf 2026-05-18 02:07:48 +02:00
commit 5352ef69a2
37 changed files with 2637 additions and 59 deletions

View file

@ -38,7 +38,9 @@ module;
#include <wayland-client.h>
#include <wayland-client-protocol.h>
#endif
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
#include "vulkan/vulkan.h"
#endif
#ifdef CRAFTER_GRAPHICS_WINDOW_WIN32
#include <windows.h>
#endif
@ -50,6 +52,7 @@ import :Keys;
import Crafter.Event;
export namespace Crafter {
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
struct Semaphores {
// Swap chain image presentation
VkSemaphore presentComplete;
@ -58,6 +61,7 @@ export namespace Crafter {
};
struct RenderPass;
struct DescriptorHeapVulkan;
#endif
struct Window {
FrameTime currentFrameTime;
@ -105,6 +109,16 @@ export namespace Crafter {
Window(Window&) = delete;
Window(Window&&) = delete;
Window& operator=(const Window&) = delete;
#ifdef CRAFTER_GRAPHICS_WINDOW_DOM
// DOM mode keeps a process-global pointer to the live Window so
// the JS bridge can deliver document/window events back. If the
// Window is destroyed (e.g. it was stack-allocated in main and
// main returned), the global must be cleared so subsequent
// browser callbacks become no-ops instead of dereferencing
// freed memory. Native builds have nothing to clean up at the
// Window level (Vulkan resources teardown is the user's job).
~Window();
#endif
void StartSync();
void StartUpdate();
@ -193,6 +207,7 @@ export namespace Crafter {
inline static wp_fractional_scale_v1* wp_scale = nullptr;
#endif
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
VkCommandBuffer StartInit();
void FinishInit();
VkCommandBuffer GetCmd();
@ -226,5 +241,13 @@ export namespace Crafter {
std::vector<RenderPass*> passes;
DescriptorHeapVulkan* descriptorHeap = nullptr;
std::optional<std::array<float, 4>> clearColor;
#else
// DOM mode: the page IS the window. `numFrames` stays as a public
// constant so cross-platform code can refer to Window::numFrames
// without #ifdef'ing the reference; nothing else lives here yet.
// V2 (WebGPU compute) will hang its GPUContext / swapchain texture
// members off this branch.
static constexpr std::uint8_t numFrames = 1;
#endif
};
}