euv-core 0.53.0

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
use super::*;

/// Lazily compiled WebGL2 offscreen hardware scene pipelines for Ocean + Origami Boat and Instanced 3D PBR Open-World rendering.
#[derive(Clone)]
pub(crate) struct WebGl2ScenePipeline {
    /// Compiled fullscreen GPU ocean shader program.
    pub(crate) ocean_program: WebGlProgram,
    /// `u_time_agit_hor_aspect` uniform location.
    pub(crate) ocean_time_loc: Option<WebGlUniformLocation>,
    /// `u_roll_boat_uv` uniform location.
    pub(crate) ocean_roll_loc: Option<WebGlUniformLocation>,
    /// `u_sun_dir_wake` uniform location.
    pub(crate) ocean_sun_loc: Option<WebGlUniformLocation>,
    /// Compiled origami paper boat shader program.
    pub(crate) boat_program: WebGlProgram,
    /// VAO for 32-byte `GpuOceanBoatVertex` attributes.
    pub(crate) boat_vao: WebGlVertexArrayObject,
    /// Dynamic VBO holding projected origami boat vertices.
    pub(crate) boat_vbo: WebGlBuffer,
    /// Allocated byte capacity of `boat_vbo`.
    pub(crate) boat_vbo_cap: usize,
    /// Compiled fullscreen 3D atmospheric sky gradient shader program.
    pub(crate) sky3d_program: WebGlProgram,
    /// `u_view_proj` location on `sky3d_program`.
    pub(crate) sky3d_vp_loc: Option<WebGlUniformLocation>,
    /// `u_camera_pos` location on `sky3d_program`.
    pub(crate) sky3d_cam_loc: Option<WebGlUniformLocation>,
    /// `u_sun_dir_fog` location on `sky3d_program`.
    pub(crate) sky3d_sun_dir_loc: Option<WebGlUniformLocation>,
    /// `u_sun_color_ambient` location on `sky3d_program`.
    pub(crate) sky3d_sun_loc: Option<WebGlUniformLocation>,
    /// `u_sky_horizon_tod` location on `sky3d_program`.
    pub(crate) sky3d_hor_loc: Option<WebGlUniformLocation>,
    /// `u_sky_zenith_aspect` location on `sky3d_program`.
    pub(crate) sky3d_zen_loc: Option<WebGlUniformLocation>,
    /// Compiled instanced 3D PBR open-world shader program.
    pub(crate) mesh3d_program: WebGlProgram,
    /// `u_view_proj` location on `mesh3d_program`.
    pub(crate) mesh3d_vp_loc: Option<WebGlUniformLocation>,
    /// `u_camera_pos` location on `mesh3d_program`.
    pub(crate) mesh3d_cam_loc: Option<WebGlUniformLocation>,
    /// `u_sun_dir_fog` location on `mesh3d_program`.
    pub(crate) mesh3d_sun_fog_loc: Option<WebGlUniformLocation>,
    /// `u_sun_color_ambient` location on `mesh3d_program`.
    pub(crate) mesh3d_sun_col_loc: Option<WebGlUniformLocation>,
    /// `u_sky_horizon_tod` location on `mesh3d_program`.
    pub(crate) mesh3d_hor_loc: Option<WebGlUniformLocation>,
    /// `u_sky_zenith_aspect` location on `mesh3d_program`.
    pub(crate) mesh3d_zen_loc: Option<WebGlUniformLocation>,
    /// VAO binding static 48-byte `GpuWorld3dVertex` + instanced 96-byte `GpuWorld3dInstance`.
    pub(crate) mesh3d_vao: WebGlVertexArrayObject,
    /// Static GPU vertex buffer uploaded once per `GpuWorld3dMeshBuffer::revision`.
    pub(crate) mesh3d_vert_vbo: WebGlBuffer,
    /// Uploaded mesh revision matching `mesh3d_vert_vbo`.
    pub(crate) mesh3d_vert_rev: u64,
    /// Allocated byte capacity of `mesh3d_vert_vbo`.
    pub(crate) mesh3d_vert_cap: usize,
    /// Per-frame instanced transform and material VBO.
    pub(crate) mesh3d_inst_vbo: WebGlBuffer,
    /// Allocated byte capacity of `mesh3d_inst_vbo`.
    pub(crate) mesh3d_inst_cap: usize,
    /// Cached byte offset bound on instanced attribute slots `3..9` of `mesh3d_vao`.
    pub(crate) mesh3d_inst_base_off: i32,
    /// Offscreen scene FBO rendering color + depth before UI compositing.
    pub(crate) scene_fbo: WebGlFramebuffer,
    /// Offscreen RGBA8 color texture attached to `scene_fbo` and bound on UI `TEXTURE3`.
    pub(crate) scene_color_tex: WebGlTexture,
    /// Offscreen `DEPTH_COMPONENT24` renderbuffer attached to `scene_fbo` for 3D occlusion.
    pub(crate) scene_depth_rbo: WebGlRenderbuffer,
    /// Physical `(width, height)` currently allocated for `scene_color_tex` and `scene_depth_rbo`.
    pub(crate) scene_dims: (u32, u32),
    /// Interactive PBF wake RGBA8 texture bound on ocean `TEXTURE0`.
    pub(crate) wake_tex: WebGlTexture,
    /// Allocated `(width, height)` of `wake_tex`.
    pub(crate) wake_dims: (u32, u32),
}

/// One sibling tiled WebGL2 `<canvas>` slice rendering a disjoint physical sub-rect of an oversized viewport (`> GL_MAX_TEXTURE_SIZE`).
#[derive(Clone)]
pub(crate) struct WebGl2TileCanvas {
    /// Mounted sibling `<canvas data-euv-canvas-role="tile">` element.
    pub(crate) canvas: HtmlCanvasElement,
    /// Independent WebGL2 context locked to this tile canvas.
    pub(crate) gl2: WebGl2RenderingContext,
    /// Compiled instanced uber-shader pipeline for this tile canvas.
    pub(crate) instanced: WebGl2InstancedPipeline,
    /// Last applied tile CSS geometry `(phys_x, phys_y, tile_w, tile_h, req_w, req_h)` avoiding per-frame DOM `style` attribute writes.
    pub(crate) last_style_geom: (u32, u32, u32, u32, u32, u32),
}

/// Compiled WebGL2 64-byte instanced uber-shader pipeline drawing all `PrimKind` variants via `draw_arrays_instanced` with persistent glyph and image atlases.
#[derive(Clone)]
pub(crate) struct WebGl2InstancedPipeline {
    /// Compiled `GLSL_ES3_UI_VERTEX_SHADER` + `GLSL_ES3_UI_FRAGMENT_SHADER` program.
    pub(crate) program: WebGlProgram,
    /// Persistent VAO binding `a_corner` (`location 0`) and 64-byte instanced `GpuPrimitiveInstance` attributes (`locations 1..=5`).
    pub(crate) vao: WebGlVertexArrayObject,
    /// Dynamic `GL_STREAM_DRAW` instance buffer receiving 64-byte `GpuPrimitiveInstance` slices directly from WASM linear memory.
    pub(crate) instance_vbo: WebGlBuffer,
    /// Currently allocated GPU byte capacity of `instance_vbo`.
    pub(crate) instance_vbo_cap_bytes: usize,
    /// Cached `u_viewport` uniform location.
    pub(crate) viewport_loc: Option<WebGlUniformLocation>,
    /// Cached `u_scroll_offset` uniform location.
    pub(crate) scroll_loc: Option<WebGlUniformLocation>,
    /// Cached `u_tile_origin` uniform location for multi-canvas tiled WebGL2 presentation.
    pub(crate) tile_origin_loc: Option<WebGlUniformLocation>,
    /// Cached `gl.bindTexture` function handle (avoids per-frame `Reflect::get`).
    pub(crate) bind_texture_fn: Option<Function>,
    /// Resident R8 glyph coverage atlas texture bound on `TEXTURE0`.
    pub(crate) glyph_r8_tex: Option<JsValue>,
    /// Allocated R8 glyph atlas width in pixels.
    pub(crate) glyph_r8_w: u32,
    /// Allocated R8 glyph atlas height in pixels.
    pub(crate) glyph_r8_h: u32,
    /// Resident RGBA8 color glyph atlas texture bound on `TEXTURE1`.
    pub(crate) glyph_rgba8_tex: Option<JsValue>,
    /// Resident RGBA8 image atlas texture bound on `TEXTURE2`.
    pub(crate) image_atlas_tex: Option<JsValue>,
    /// Allocated RGBA8 image atlas width in pixels.
    pub(crate) image_atlas_w: u32,
    /// Allocated RGBA8 image atlas height in pixels.
    pub(crate) image_atlas_h: u32,
    /// Resident external/3D/fluid render target texture bound on `TEXTURE3`.
    pub(crate) external_tex: Option<JsValue>,
    /// Cached `GL_MAX_TEXTURE_SIZE` queried once at initialization (avoids per-frame GPU sync stall).
    pub(crate) max_tex_dim: u32,
    /// Compiled Dual-Kawase `BackdropBlur` program (`GLSL_ES3_BACKDROP_BLUR_VERTEX_SHADER` + `GLSL_ES3_BACKDROP_BLUR_FRAGMENT_SHADER`).
    pub(crate) blur_program: Option<WebGlProgram>,
    /// `u_texel_size` uniform location on `blur_program`.
    pub(crate) blur_texel_loc: Option<WebGlUniformLocation>,
    /// `u_blur_offset` uniform location on `blur_program`.
    pub(crate) blur_offset_loc: Option<WebGlUniformLocation>,
    /// `u_blur_pass_mode` uniform location on `blur_program`.
    pub(crate) blur_mode_loc: Option<WebGlUniformLocation>,
    /// Offscreen scene FBO capturing pre-blur UI layers.
    pub(crate) blur_scene_fbo: Option<WebGlFramebuffer>,
    /// Offscreen scene RGBA8 color texture bound to `blur_scene_fbo`.
    pub(crate) blur_scene_tex: Option<WebGlTexture>,
    /// Offscreen half-resolution Dual-Kawase downsample FBO.
    pub(crate) blur_half_fbo: Option<WebGlFramebuffer>,
    /// Offscreen half-resolution RGBA8 texture bound to `blur_half_fbo`.
    pub(crate) blur_half_tex: Option<WebGlTexture>,
    /// Offscreen full-resolution Dual-Kawase upsample FBO.
    pub(crate) blur_full_fbo: Option<WebGlFramebuffer>,
    /// Offscreen full-resolution RGBA8 blurred texture bound on `TEXTURE3` during blur batch draw.
    pub(crate) blur_full_tex: Option<WebGlTexture>,
    /// Physical `(width, height)` currently allocated for the Dual-Kawase blur FBOs.
    pub(crate) blur_dims: (u32, u32),
    /// Lazily compiled hardware GPU Ocean and 3D PBR offscreen scene pipeline.
    pub(crate) scene_gl: Option<WebGl2ScenePipeline>,
    /// Latest window-level R8 glyph atlas revision synchronized into this context's `TEXTURE0`.
    pub(crate) synced_glyph_r8_rev: u64,
    /// Latest window-level RGBA8 image atlas revision synchronized into this context's `TEXTURE2`.
    pub(crate) synced_image_rgba8_rev: u64,
}

/// Borrowed uniform location bundle passed to `web_draw_gl2_direct_batches`.
pub(crate) struct WebGl2DirectUniforms<'a> {
    /// `u_view` physical viewport uniform location.
    pub(crate) view_loc: Option<&'a WebGlUniformLocation>,
    /// `u_rect` primitive bounds uniform location.
    pub(crate) rect_loc: Option<&'a WebGlUniformLocation>,
    /// `u_color` primitive RGBA color uniform location.
    pub(crate) color_loc: Option<&'a WebGlUniformLocation>,
}

/// Compiled WebGL2 direct GPU primitive pipeline handles returned by `web_init_gl2_direct_pipeline`.
pub(crate) struct WebGl2DirectPipeline {
    /// Compiled direct primitive `WebGlProgram`.
    pub(crate) program: WebGlProgram,
    /// `u_view` physical viewport uniform location.
    pub(crate) view_loc: Option<WebGlUniformLocation>,
    /// `u_rect` primitive bounds uniform location.
    pub(crate) rect_loc: Option<WebGlUniformLocation>,
    /// `u_color` primitive RGBA color uniform location.
    pub(crate) color_loc: Option<WebGlUniformLocation>,
}

/// Compiled WebGL2 fullscreen blit pipeline handles returned by `web_init_gl2_blit_pipeline`.
pub(crate) struct WebGl2BlitPipeline {
    /// Compiled fullscreen blit `WebGlProgram`.
    pub(crate) program: WebGlProgram,
    /// Resident WebGL2 texture object.
    pub(crate) texture: Option<JsValue>,
    /// Optional `u_view` drawing-buffer size uniform location.
    pub(crate) view_loc: Option<WebGlUniformLocation>,
    /// Cached `gl.bindTexture` function handle (eliminates per-frame `Reflect::get`).
    pub(crate) bind_texture_fn: Option<Function>,
    /// Cached `GL_MAX_TEXTURE_SIZE` queried once at pipeline creation.
    pub(crate) max_tex_dim: u32,
}

/// Initialized DOM canvas surface bundle returned by `web_create_canvas` or `web_create_independent_canvas`.
pub(crate) struct WebCanvasSurface {
    /// Mounted `<canvas>` element.
    pub(crate) canvas: HtmlCanvasElement,
    /// Selected graphics context tier (`WebGpu`, `WebGl2`, or fallback `Canvas2d`).
    pub(crate) context_kind: WebCanvasContextKind,
    /// Active presentation mode (`GpuDirect`, `GpuUpload`, or `Software`).
    pub(crate) presentation_mode: WebPresentationMode,
    /// Optional WebGPU `GPUCanvasContext`.
    pub(crate) webgpu_ctx: Option<Object>,
    /// Whether browser `navigator.gpu` WebGPU capability was detected.
    pub(crate) webgpu_available: bool,
    /// Optional hardware-composited `WebGl2RenderingContext`.
    pub(crate) gl2: Option<WebGl2RenderingContext>,
    /// Optional compiled WebGL2 64-byte instanced uber-shader pipeline (`draw_arrays_instanced`, zero CPU raster).
    pub(crate) gl2_instanced: Option<WebGl2InstancedPipeline>,
    /// Optional compiled WebGL2 direct GPU primitive program (`cpu_mirror_active = false`).
    pub(crate) gl2_direct_program: Option<WebGlProgram>,
    /// Optional `u_view` uniform location for direct GPU primitive rendering.
    pub(crate) gl2_direct_view_loc: Option<WebGlUniformLocation>,
    /// Optional `u_rect` uniform location for direct GPU primitive rendering.
    pub(crate) gl2_direct_rect_loc: Option<WebGlUniformLocation>,
    /// Optional `u_color` uniform location for direct GPU primitive rendering.
    pub(crate) gl2_direct_color_loc: Option<WebGlUniformLocation>,
    /// Optional compiled WebGL2 fullscreen blit program (`GpuUpload`).
    pub(crate) gl2_program: Option<WebGlProgram>,
    /// Optional resident WebGL2 texture object.
    pub(crate) gl2_texture: Option<JsValue>,
    /// Optional `u_view` drawing-buffer size uniform location of the blit program.
    pub(crate) gl2_view_loc: Option<WebGlUniformLocation>,
    /// Cached `gl.bindTexture` function handle for the blit pipeline.
    pub(crate) gl2_bind_texture_fn: Option<Function>,
    /// Cached `GL_MAX_TEXTURE_SIZE` for the active WebGL2 context.
    pub(crate) gl2_max_tex_dim: u32,
    /// Optional last-resort `CanvasRenderingContext2d`.
    pub(crate) ctx2d: Option<CanvasRenderingContext2d>,
}

/// Truthful browser presentation telemetry separating `GpuDirect`, `GpuUpload`, and `Software` and always tagging rAF as `SubmissionProxy`.
#[derive(Clone, Copy, Data, Debug, Default, Eq, PartialEq)]
pub struct WebPresentTelemetry {
    /// Active Web presentation mode (`GpuDirect`, `GpuUpload`, or `Software`).
    #[get(type(copy))]
    pub(crate) mode: WebPresentationMode,
    /// Explicit CPU-mirror telemetry flag (`false` for `GpuDirect`; `true` for `GpuUpload` and `Software`).
    #[get(type(copy))]
    pub(crate) cpu_mirror_active: bool,
    /// Exact framebuffer bytes uploaded via WebGL2 `texSubImage2D`/`texImage2D` or Canvas2D `putImageData` (`0` for `GpuDirect`).
    #[get(type(copy))]
    pub(crate) upload_bytes: u64,
    /// Number of GPU primitives drawn directly on WebGL2 in the latest `GpuDirect` frame (`0` on upload/2D).
    #[get(type(copy))]
    pub(crate) primitive_count: u32,
    /// Truthful timing source (`SubmissionProxy` for browser rAF without compositor proof).
    #[get(type(copy))]
    pub(crate) present_timing_source: WebPresentTimingSource,
    /// Monotonic generation ID of the currently visible foreground `<canvas>`.
    #[get(type(copy))]
    pub(crate) active_canvas_generation: u64,
    /// Total atomic independent-canvas handoff swaps completed.
    #[get(type(copy))]
    pub(crate) handoff_swaps_completed: u64,
    /// Total aborted candidate handoffs where the previous active `<canvas>` remained untouched.
    #[get(type(copy))]
    pub(crate) handoff_aborts: u64,
    /// Count of browser rAF ticks recorded strictly as submission proxies.
    #[get(type(copy))]
    pub(crate) raf_callback_count: u64,
}

/// Hidden independent sibling `<canvas>` pre-warming a candidate context before atomic frame-boundary visibility swap.
#[derive(Clone, CustomDebug, Data)]
pub(crate) struct WebStandbyCanvasTarget {
    /// Monotonic generation identifier assigned to this independent `<canvas>`.
    #[get(type(copy))]
    pub(crate) generation: u64,
    /// Target presentation mode (`GpuDirect`, `GpuUpload`, or `Software`).
    #[get(type(copy))]
    pub(crate) target_mode: WebPresentationMode,
    /// Locked browser context family (`WebGpu`, `WebGl2`, or `Canvas2d`).
    #[get(type(copy))]
    pub(crate) context_kind: WebCanvasContextKind,
    /// Backing DOM `<canvas>` element mounted hidden behind the active canvas.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) canvas: HtmlCanvasElement,
    /// Optional WebGPU context on this standby canvas.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) webgpu_ctx: Option<Object>,
    /// Optional WebGL2 context on this standby canvas.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) gl2: Option<WebGl2RenderingContext>,
    /// Optional compiled WebGL2 64-byte instanced uber-shader pipeline on this standby canvas.
    #[debug(skip)]
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) gl2_instanced: Option<WebGl2InstancedPipeline>,
    /// Optional direct primitive WebGL2 program on this standby canvas.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) gl2_direct_program: Option<WebGlProgram>,
    /// Optional `u_view` location for standby direct primitive program.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) gl2_direct_view_loc: Option<WebGlUniformLocation>,
    /// Optional `u_rect` location for standby direct primitive program.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) gl2_direct_rect_loc: Option<WebGlUniformLocation>,
    /// Optional `u_color` location for standby direct primitive program.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) gl2_direct_color_loc: Option<WebGlUniformLocation>,
    /// Optional blit WebGL2 program on this standby canvas.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) gl2_program: Option<WebGlProgram>,
    /// Optional resident WebGL2 texture on this standby canvas.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) gl2_texture: Option<JsValue>,
    /// Optional `u_view` uniform location on standby blit program.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) gl2_view_loc: Option<WebGlUniformLocation>,
    /// Cached `gl.bindTexture` function handle on standby blit pipeline.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) gl2_bind_texture_fn: Option<Function>,
    /// Cached `GL_MAX_TEXTURE_SIZE` for standby WebGL2 context.
    #[get(type(copy))]
    pub(crate) gl2_max_tex_dim: u32,
    /// Allocated standby texture width in pixels.
    #[get(type(copy))]
    pub(crate) gl2_tex_width: u32,
    /// Allocated standby texture height in pixels.
    #[get(type(copy))]
    pub(crate) gl2_tex_height: u32,
    /// Optional 2D context on this standby canvas.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) ctx2d: Option<CanvasRenderingContext2d>,
    /// True once a candidate first frame rendered cleanly onto this hidden canvas.
    #[get(type(copy))]
    pub(crate) ready: bool,
    /// Physical width of the pre-warmed candidate frame.
    #[get(type(copy))]
    pub(crate) ready_width: u32,
    /// Physical height of the pre-warmed candidate frame.
    #[get(type(copy))]
    pub(crate) ready_height: u32,
    /// Scene revision matching the pre-warmed candidate frame.
    #[get(type(copy))]
    pub(crate) ready_scene_version: u64,
}

/// Browser canvas window record storing live DOM `HtmlCanvasElement`, GPU/WebGL2/2D context, independent standby canvas, and telemetry.
#[derive(Clone, CustomDebug, Data)]
pub struct WebWindowRecord {
    /// Declarative window configuration.
    pub(crate) config: WindowConfig,
    /// Live window state and DPR metrics.
    #[get(type(copy))]
    pub(crate) state: WindowState,
    /// Assigned canvas registration identifier.
    #[get(type(copy))]
    pub(crate) canvas_id: u32,
    /// Active graphics context tier (`WebGpu`, `WebGl2`, or last-resort `Canvas2d`).
    #[get(type(copy))]
    pub(crate) context_kind: WebCanvasContextKind,
    /// Active presentation mode (`GpuDirect`, `GpuUpload`, or `Software`).
    #[get(type(copy))]
    pub(crate) presentation_mode: WebPresentationMode,
    /// Explicit CPU-mirror flag (`false` for `GpuDirect`; `true` for `GpuUpload` and `Software`).
    #[get(type(copy))]
    pub(crate) cpu_mirror_active: bool,
    /// Monotonic generation ID of the active foreground `<canvas>`.
    #[get(type(copy))]
    pub(crate) active_canvas_generation: u64,
    /// Backing DOM canvas element.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) canvas: Option<HtmlCanvasElement>,
    /// Active WebGPU `GPUCanvasContext` when WebGPU is primary.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) webgpu_ctx: Option<Object>,
    /// Whether browser `navigator.gpu` WebGPU capability was detected on this window.
    #[get(type(copy))]
    pub(crate) webgpu_available: bool,
    /// Active hardware-composited `WebGl2RenderingContext` when WebGL2 is bound.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) gl2: Option<WebGl2RenderingContext>,
    /// Compiled WebGL2 64-byte instanced uber-shader pipeline (`draw_arrays_instanced`, zero CPU pixel raster).
    #[debug(skip)]
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) gl2_instanced: Option<WebGl2InstancedPipeline>,
    /// Compiled WebGL2 direct GPU primitive program (`GpuDirect`, zero CPU pixel mirror).
    #[debug(skip)]
    #[get(skip)]
    pub(crate) gl2_direct_program: Option<WebGlProgram>,
    /// `u_view` uniform location for direct WebGL2 primitive rendering.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) gl2_direct_view_loc: Option<WebGlUniformLocation>,
    /// `u_rect` uniform location for direct WebGL2 primitive rendering.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) gl2_direct_rect_loc: Option<WebGlUniformLocation>,
    /// `u_color` uniform location for direct WebGL2 primitive rendering.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) gl2_direct_color_loc: Option<WebGlUniformLocation>,
    /// Compiled fullscreen blit `WebGlProgram` for WebGL2 dirty-rect texture presentation.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) gl2_program: Option<WebGlProgram>,
    /// Resident WebGL2 texture object backing dirty-rect `texSubImage2D` uploads.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) gl2_texture: Option<JsValue>,
    /// `u_view` drawing-buffer size uniform location enabling 1:1 `texelFetch` presentation.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) gl2_view_loc: Option<WebGlUniformLocation>,
    /// Cached `gl.bindTexture` function handle eliminating per-frame `Reflect::get` overhead.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) gl2_bind_texture_fn: Option<Function>,
    /// Cached `GL_MAX_TEXTURE_SIZE` queried once at WebGL2 initialization.
    #[get(type(copy))]
    pub(crate) gl2_max_tex_dim: u32,
    /// Allocated WebGL2 texture width in pixels.
    #[get(type(copy))]
    pub(crate) gl2_tex_width: u32,
    /// Allocated WebGL2 texture height in pixels.
    #[get(type(copy))]
    pub(crate) gl2_tex_height: u32,
    /// Last-resort 2D software blit context (only acquired when WebGPU & WebGL2 are unavailable).
    #[debug(skip)]
    #[get(skip)]
    pub(crate) ctx2d: Option<CanvasRenderingContext2d>,
    /// Optional hidden independent sibling `<canvas>` pre-warming a candidate backend before atomic frame-boundary handoff.
    #[debug(skip)]
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) standby_canvas: Option<WebStandbyCanvasTarget>,
    /// Latest browser presentation telemetry snapshot.
    #[get(type(copy))]
    pub(crate) last_telemetry: WebPresentTelemetry,
    /// Attached browser `ResizeObserver` watching canvas layout changes without polling reflows.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) resize_observer: Option<Object>,
    /// Active sibling tiled WebGL2 canvases for lossless physical surfaces exceeding `GL_MAX_TEXTURE_SIZE`.
    #[debug(skip)]
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) tiled_canvases: Vec<WebGl2TileCanvas>,
    /// Last applied DOM `data-euv-tiled` grid `(columns, rows)` (`(0, 0)` unset, `(1, 1)` single-canvas untiled).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) active_tile_grid: (u32, u32),
    /// Latest full R8 glyph atlas snapshot cached for seeding newly created tiled or returning main WebGL2 contexts.
    #[debug(skip)]
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) cached_glyph_r8_atlas: Option<DirectGpuAtlasUpload>,
    /// Monotonic revision counter incremented whenever `cached_glyph_r8_atlas` updates.
    #[get(type(copy))]
    pub(crate) cached_glyph_r8_rev: u64,
    /// Latest full RGBA8 image atlas snapshot cached for seeding newly created tiled or returning main WebGL2 contexts.
    #[debug(skip)]
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) cached_image_rgba8_atlas: Option<DirectGpuAtlasUpload>,
    /// Monotonic revision counter incremented whenever `cached_image_rgba8_atlas` updates.
    #[get(type(copy))]
    pub(crate) cached_image_rgba8_rev: u64,
}

/// Direct Browser WebAssembly (`web-sys` WebGPU / WebGL2 / Canvas2D / DOM Events) platform backend.
#[derive(Clone, Data, Debug)]
pub struct WebPlatform {
    /// Monotonic window handle allocator.
    #[get(pub(crate), type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) next_id: u64,
    /// Active web canvas windows.
    pub(crate) windows: HashMap<WindowId, WebWindowRecord>,
    /// Queued browser pointer, keyboard, wheel, and resize events.
    pub(crate) pending_events: Vec<WindowEvent>,
    /// Clipboard cache.
    #[get(skip)]
    pub(crate) clipboard_cache: Option<String>,
    /// Last observed `document.hidden` visibility state.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) last_hidden: bool,
    /// Last observed `navigator.onLine` connectivity state.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) last_online: bool,
    /// Last observed browser dark/light appearance mode.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) last_theme: ThemeMode,
    /// Last observed browser BCP-47 locale tag.
    #[get(pub(crate))]
    #[set(pub(crate))]
    pub(crate) last_locale: String,
    /// Last measured CSS `env(safe-area-inset-*)` insets in logical CSS pixels.
    #[get(pub(crate), type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) last_safe_area: SafeAreaInsets,
    /// Measured browser display refresh rate in Hertz (`60.0` default, updated from `requestAnimationFrame` cadence).
    #[get(pub(crate), type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) refresh_rate_hz: f32,
    /// Whether the browser `requestAnimationFrame` loop is paused while hidden/backgrounded.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) pump_paused: bool,
    /// Demand-driven `rAF` dirty flag (`true` when input, signal, or animation requires a frame; `false` sleeps at 0 Hz).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) needs_frame: bool,
    /// Whether a browser `requestAnimationFrame` callback is currently scheduled.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) raf_scheduled: bool,
    /// Active `requestAnimationFrame` handle (`0` when no frame callback is armed).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) raf_handle: i32,
}

/// Thread-local sensor fusion state bridging browser `devicemotion` and `deviceorientation` events into `DeviceMotionSample`.
#[derive(Clone, Copy, Data, Debug)]
pub(crate) struct WebDeviceMotionState {
    /// Whether `devicemotion` and `deviceorientation` DOM listeners have already been attached.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) listeners_attached: bool,
    /// Whether at least one `devicemotion` callback has delivered live inertial readings.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) has_motion_event: bool,
    /// Latest device-frame gravity vector derived from `deviceorientation` (`+X_right, +Y_up, +Z_out`, `m/s²`).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) orient_gravity_dev: Option<[f32; 3]>,
    /// Latest azimuth/yaw angle in radians from `deviceorientation.alpha`.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) last_yaw_rad: f32,
    /// Low-pass filtered device-frame gravity fallback used when `event.acceleration` is null.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) filtered_gravity_dev: Option<[f32; 3]>,
    /// Auto-detected sign multiplier converting raw `accelerationIncludingGravity` to downward gravity (`-1.0` W3C / `+1.0` Safari).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) gravity_sign: f32,
    /// Whether `pending_sample` holds an unread sensor update for `WebPlatform::poll_events`.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) has_pending_sample: bool,
    /// Most recently fused screen-aligned `DeviceMotionSample` pending delivery into `WebPlatform::poll_events`.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) pending_sample: DeviceMotionSample,
}