xbintsc 0.7.7 → 0.7.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/dist/src/cli/help.d.ts +1 -1
  2. package/dist/src/cli/help.js +1 -1
  3. package/dist/src/codegen/generator/calls/invocation.js +6 -4
  4. package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
  5. package/dist/src/codegen/generator/context.d.ts +4 -3
  6. package/dist/src/codegen/generator/context.js +6 -5
  7. package/dist/src/codegen/generator/context.js.map +1 -1
  8. package/dist/src/codegen/generator/expressions/assignment.js +3 -3
  9. package/dist/src/driver/config.d.ts +1 -1
  10. package/dist/src/driver/options.d.ts +1 -1
  11. package/dist/src/driver/version.d.ts +1 -1
  12. package/dist/src/driver/version.js +1 -1
  13. package/dist/src/extensions/gui/features.d.ts +14 -6
  14. package/dist/src/extensions/gui/features.js +34 -6
  15. package/dist/src/extensions/gui/features.js.map +1 -1
  16. package/dist/src/extensions/gui/index.js +3 -3
  17. package/dist/tests/codegen/llvm.test.js +1 -1
  18. package/dist/tests/e2e/gui-audio.test.js +24 -0
  19. package/dist/tests/e2e/gui-audio.test.js.map +1 -1
  20. package/dist/tests/e2e/gui-draw-perf.test.js +9 -0
  21. package/dist/tests/e2e/gui-draw-perf.test.js.map +1 -1
  22. package/dist/tests/e2e/gui-font-face.test.d.ts +3 -1
  23. package/dist/tests/e2e/gui-font-face.test.js +99 -7
  24. package/dist/tests/e2e/gui-font-face.test.js.map +1 -1
  25. package/dist/tests/e2e/gui-frame-pacing.test.d.ts +15 -0
  26. package/dist/tests/e2e/gui-frame-pacing.test.js +68 -0
  27. package/dist/tests/e2e/gui-frame-pacing.test.js.map +1 -0
  28. package/dist/tests/e2e/gui-initial-url.test.d.ts +10 -0
  29. package/dist/tests/e2e/gui-initial-url.test.js +49 -0
  30. package/dist/tests/e2e/gui-initial-url.test.js.map +1 -0
  31. package/dist/tests/e2e/gui-layout.test.js +85 -0
  32. package/dist/tests/e2e/gui-layout.test.js.map +1 -1
  33. package/dist/tests/e2e/gui-webgl-depth-init.test.d.ts +13 -0
  34. package/dist/tests/e2e/gui-webgl-depth-init.test.js +144 -0
  35. package/dist/tests/e2e/gui-webgl-depth-init.test.js.map +1 -0
  36. package/dist/tests/e2e/gui-webgl-depth-range.test.d.ts +18 -0
  37. package/dist/tests/e2e/gui-webgl-depth-range.test.js +140 -0
  38. package/dist/tests/e2e/gui-webgl-depth-range.test.js.map +1 -0
  39. package/dist/tests/e2e/gui-webgl.test.js +49 -0
  40. package/dist/tests/e2e/gui-webgl.test.js.map +1 -1
  41. package/dist/tests/e2e/gui-webgpu-attachment.test.d.ts +19 -0
  42. package/dist/tests/e2e/gui-webgpu-attachment.test.js +258 -0
  43. package/dist/tests/e2e/gui-webgpu-attachment.test.js.map +1 -0
  44. package/dist/tests/e2e/method-call-cache.test.js +27 -0
  45. package/dist/tests/e2e/method-call-cache.test.js.map +1 -1
  46. package/dist/tests/extensions/gui-features.test.js +27 -2
  47. package/dist/tests/extensions/gui-features.test.js.map +1 -1
  48. package/doc/ai/extensions.md +10 -4
  49. package/doc/ai/zh-CN/extensions.md +8 -3
  50. package/doc/gui/animation.md +1 -1
  51. package/doc/gui/api.md +35 -2
  52. package/doc/gui/build.md +34 -15
  53. package/doc/gui/dom.md +3 -2
  54. package/doc/gui/known-issues.md +1 -1
  55. package/doc/gui/layout.md +9 -3
  56. package/doc/gui/rendering.md +45 -8
  57. package/doc/gui/runtime.md +13 -0
  58. package/doc/gui/webgl.md +29 -3
  59. package/doc/gui/webgpu.md +20 -0
  60. package/doc/gui.md +9 -4
  61. package/doc/implemented/codegen.md +4 -3
  62. package/doc/zh-CN/gui/animation.md +1 -1
  63. package/doc/zh-CN/gui/api.md +25 -2
  64. package/doc/zh-CN/gui/build.md +20 -7
  65. package/doc/zh-CN/gui/dom.md +3 -2
  66. package/doc/zh-CN/gui/known-issues.md +1 -1
  67. package/doc/zh-CN/gui/layout.md +7 -4
  68. package/doc/zh-CN/gui/rendering.md +33 -8
  69. package/doc/zh-CN/gui/runtime.md +9 -0
  70. package/doc/zh-CN/gui/webgl.md +7 -4
  71. package/doc/zh-CN/gui/webgpu.md +18 -0
  72. package/doc/zh-CN/gui.md +10 -5
  73. package/doc/zh-CN/implemented/codegen.md +4 -3
  74. package/package.json +7 -7
  75. package/runtime/ext_gui/audio_graph_commands.cpp +127 -0
  76. package/runtime/ext_gui/audio_mixer.cpp +84 -163
  77. package/runtime/ext_gui/audio_mixer.h +59 -3
  78. package/runtime/ext_gui/audio_mixer_extra.cpp +8 -0
  79. package/runtime/ext_gui/audio_param_apply.cpp +160 -0
  80. package/runtime/ext_gui/browser.cpp +6 -19
  81. package/runtime/ext_gui/browser_location.cpp +78 -0
  82. package/runtime/ext_gui/css.cpp +1 -0
  83. package/runtime/ext_gui/css.h +4 -0
  84. package/runtime/ext_gui/css_sheet.cpp +4 -2
  85. package/runtime/ext_gui/document_animation.cpp +7 -0
  86. package/runtime/ext_gui/dom_api_computed_style.cpp +3 -2
  87. package/runtime/ext_gui/dom_api_webgl.cpp +39 -2
  88. package/runtime/ext_gui/dom_api_webgl_extensions.cpp +134 -0
  89. package/runtime/ext_gui/dom_api_webgl_internal.h +4 -0
  90. package/runtime/ext_gui/dom_api_webgl_shader.cpp +28 -4
  91. package/runtime/ext_gui/dom_api_webgl_state.cpp +6 -103
  92. package/runtime/ext_gui/gui.cpp +100 -1
  93. package/runtime/ext_gui/gui_events.cpp +8 -2
  94. package/runtime/ext_gui/layout_flex.cpp +5 -2
  95. package/runtime/ext_gui/layout_flow.cpp +24 -1
  96. package/runtime/ext_gui/layout_flow_internal.h +11 -2
  97. package/runtime/ext_gui/media_query.cpp +3 -0
  98. package/runtime/ext_gui/perf.cpp +18 -6
  99. package/runtime/ext_gui/perf.h +37 -0
  100. package/runtime/ext_gui/style.cpp +28 -10
  101. package/runtime/ext_gui/style.h +10 -1
  102. package/runtime/ext_gui/style_length.cpp +4 -0
  103. package/runtime/ext_gui/style_print.cpp +7 -1
  104. package/runtime/ext_gui/style_values.cpp +6 -5
  105. package/runtime/ext_gui/text.cpp +4 -0
  106. package/runtime/ext_gui/text_font_bytes.cpp +117 -0
  107. package/runtime/ext_gui/text_font_bytes.h +65 -0
  108. package/runtime/ext_gui/text_font_db.cpp +5 -0
  109. package/runtime/ext_gui/text_font_sfnt.cpp +71 -24
  110. package/runtime/ext_gui/text_font_sfnt.h +5 -2
  111. package/runtime/ext_gui/text_hb.cpp +34 -5
  112. package/runtime/ext_gui/text_stb.cpp +7 -30
  113. package/runtime/ext_gui/text_webfont.cpp +217 -0
  114. package/runtime/ext_gui/warnings.cpp +26 -0
  115. package/runtime/ext_gui/warnings.h +8 -0
  116. package/runtime/ext_gui/webfont_bridge.c +23 -0
  117. package/runtime/ext_gui/webgl.h +36 -39
  118. package/runtime/ext_gui/webgl_blit_color.cpp +5 -0
  119. package/runtime/ext_gui/webgl_buffer_objects.cpp +19 -5
  120. package/runtime/ext_gui/webgl_context.cpp +2 -0
  121. package/runtime/ext_gui/webgl_draw.cpp +72 -12
  122. package/runtime/ext_gui/webgl_draw_setup.cpp +8 -2
  123. package/runtime/ext_gui/webgl_draw_state.h +13 -2
  124. package/runtime/ext_gui/webgl_framebuffer.cpp +8 -0
  125. package/runtime/ext_gui/webgl_objects.h +19 -0
  126. package/runtime/ext_gui/webgl_program.h +64 -0
  127. package/runtime/ext_gui/webgl_state.cpp +7 -0
  128. package/runtime/ext_gui/webgl_targets.cpp +31 -7
  129. package/runtime/ext_gui/webgl_uniform.cpp +78 -0
  130. package/runtime/ext_gui/webgpu.h +10 -0
  131. package/runtime/ext_gui/webgpu_buffer.cpp +3 -1
  132. package/runtime/ext_gui/webgpu_canvas.cpp +1 -0
  133. package/runtime/ext_gui/webgpu_command.cpp +51 -11
  134. package/runtime/ext_gui/webgpu_convert.cpp +7 -2
  135. package/runtime/ext_gui/webgpu_pass.cpp +12 -0
  136. package/runtime/ext_gui/webgpu_queue.cpp +3 -0
  137. package/runtime/ext_gui/webgpu_resources.cpp +1 -0
  138. package/runtime/ext_gui/window.cpp +6 -0
  139. package/runtime/rt_object.h +6 -0
  140. package/runtime/rt_profile.h +6 -0
  141. package/runtime/xt_containers/access.inc +2 -47
  142. package/runtime/xt_containers/ic_get.inc +70 -0
  143. package/runtime/xt_containers/method_cache.inc +42 -11
  144. package/runtime/xt_containers/objects.inc +12 -1
  145. package/runtime/xt_containers/shapes.inc +78 -0
  146. package/runtime/xt_containers.c +1 -0
  147. package/runtime/xt_profile.c +3 -0
  148. package/scripts/build-gui.ts +43 -49
  149. package/scripts/gui-engine-build.ts +58 -0
  150. package/scripts/gui-vendor-source.ts +53 -0
  151. package/scripts/gui-webfont-build.ts +138 -0
  152. package/src/cli/help.ts +1 -1
  153. package/src/codegen/generator/calls/invocation.ts +6 -4
  154. package/src/codegen/generator/context.ts +6 -6
  155. package/src/codegen/generator/expressions/assignment.ts +3 -3
  156. package/src/driver/config.ts +1 -1
  157. package/src/driver/options.ts +1 -1
  158. package/src/driver/version.ts +1 -1
  159. package/src/extensions/gui/features.ts +34 -6
  160. package/src/extensions/gui/index.ts +3 -3
@@ -0,0 +1,160 @@
1
+ /*
2
+ * xbintsc GUI engine — queued AudioParam scheduling.
3
+ *
4
+ * The mixer renders a 128-frame quantum while holding its graph mutex, and a
5
+ * reverb convolver makes that quantum take up to a few milliseconds. A page
6
+ * schedules its sounds from `requestAnimationFrame` (`gain.value = …`,
7
+ * `setTargetAtTime`, the ramps, …); taking the same mutex made every one of
8
+ * those calls wait for the current quantum, which showed up as main-thread
9
+ * frame time — on the Saltline scene it was the single largest audio cost.
10
+ *
11
+ * The setters below therefore *queue* a command instead: the audio thread
12
+ * applies queued commands at the next quantum boundary, in FIFO order, with the
13
+ * mutex already held. `param_value` flushes first because a getter must observe
14
+ * a just-written value; ordering between queued commands is preserved.
15
+ *
16
+ * A node the audio thread has not inserted yet is the exception: the FIFO runs
17
+ * on the audio thread, so a write to a node that is still in `pending_nodes_`
18
+ * would not be observable before the next quantum — and not at all when no
19
+ * audio thread exists (a headless host, or a graph built before the first
20
+ * `start()`). Such writes are applied directly to the pending node instead
21
+ * (`mutate_pending_param`); `param_value` already reads that table, so the
22
+ * getter observes them. Ordering is unaffected: the insertion command erases
23
+ * the pending entry under the same lock, so every direct write happens before
24
+ * the node can be rendered, and every later write for it goes through the FIFO.
25
+ */
26
+
27
+ #include "audio_mixer.h"
28
+
29
+ #include <utility>
30
+
31
+ namespace xtgui {
32
+
33
+ void AudioMixer::post_command(std::function<void()> command) {
34
+ std::lock_guard<std::mutex> lock(command_mutex_);
35
+ commands_.push_back(std::move(command));
36
+ }
37
+
38
+ void AudioMixer::drain_commands_locked() {
39
+ std::vector<std::function<void()>> pending;
40
+ {
41
+ std::lock_guard<std::mutex> lock(command_mutex_);
42
+ pending.swap(commands_);
43
+ }
44
+ for (std::function<void()> &command : pending) command();
45
+ }
46
+
47
+ namespace {
48
+
49
+ double audio_now(const AudioMixer &mixer) {
50
+ return mixer.current_time();
51
+ }
52
+
53
+ } // namespace
54
+
55
+ double AudioMixer::param_value(uint64_t node, int index) {
56
+ /* A node created on this thread is not in `nodes_` until the audio thread
57
+ * inserts it; read its values from the pending table instead of flushing the
58
+ * queue (which would wait for the render lock). Parameter writes for a
59
+ * pending node were applied directly there, so this is not a stale default. */
60
+ {
61
+ std::lock_guard<std::mutex> pending_lock(pending_mutex_);
62
+ auto found = pending_nodes_.find(node);
63
+ if (found != pending_nodes_.end()) {
64
+ const AudioNode &target = *found->second;
65
+ if (index < 0 || index >= target.param_count) return 0.0;
66
+ return target.params[index].value_at(audio_now(*this));
67
+ }
68
+ }
69
+ std::lock_guard<std::mutex> lock(mutex_);
70
+ drain_commands_locked();
71
+ AudioNode *target = node_locked(node);
72
+ if (target == nullptr || index < 0 || index >= target->param_count) return 0.0;
73
+ return target->params[index].value_at(audio_now(*this));
74
+ }
75
+
76
+ void AudioMixer::param_set(uint64_t node, int index, double value) {
77
+ const double now = audio_now(*this);
78
+ if (mutate_pending_param(node, index,
79
+ [&](AudioParamState &param) { param.set_value(value, now); })) {
80
+ return;
81
+ }
82
+ post_command([this, node, index, value]() {
83
+ AudioNode *target = node_locked(node);
84
+ if (target == nullptr || index < 0 || index >= target->param_count) return;
85
+ target->params[index].set_value(value, audio_now(*this));
86
+ });
87
+ }
88
+
89
+ void AudioMixer::param_set_at(uint64_t node, int index, double value, double time) {
90
+ if (mutate_pending_param(node, index,
91
+ [&](AudioParamState &param) { param.set_value_at_time(value, time); })) {
92
+ return;
93
+ }
94
+ post_command([this, node, index, value, time]() {
95
+ AudioNode *target = node_locked(node);
96
+ if (target == nullptr || index < 0 || index >= target->param_count) return;
97
+ target->params[index].set_value_at_time(value, time);
98
+ });
99
+ }
100
+
101
+ void AudioMixer::param_linear_ramp(uint64_t node, int index, double value, double time) {
102
+ if (mutate_pending_param(node, index,
103
+ [&](AudioParamState &param) { param.linear_ramp(value, time); })) {
104
+ return;
105
+ }
106
+ post_command([this, node, index, value, time]() {
107
+ AudioNode *target = node_locked(node);
108
+ if (target == nullptr || index < 0 || index >= target->param_count) return;
109
+ target->params[index].linear_ramp(value, time);
110
+ });
111
+ }
112
+
113
+ void AudioMixer::param_exponential_ramp(uint64_t node, int index, double value, double time) {
114
+ if (mutate_pending_param(node, index,
115
+ [&](AudioParamState &param) { param.exponential_ramp(value, time); })) {
116
+ return;
117
+ }
118
+ post_command([this, node, index, value, time]() {
119
+ AudioNode *target = node_locked(node);
120
+ if (target == nullptr || index < 0 || index >= target->param_count) return;
121
+ target->params[index].exponential_ramp(value, time);
122
+ });
123
+ }
124
+
125
+ void AudioMixer::param_set_target(uint64_t node, int index, double value, double time,
126
+ double time_constant) {
127
+ if (mutate_pending_param(node, index, [&](AudioParamState &param) {
128
+ param.set_target(value, time, time_constant);
129
+ })) {
130
+ return;
131
+ }
132
+ post_command([this, node, index, value, time, time_constant]() {
133
+ AudioNode *target = node_locked(node);
134
+ if (target == nullptr || index < 0 || index >= target->param_count) return;
135
+ target->params[index].set_target(value, time, time_constant);
136
+ });
137
+ }
138
+
139
+ void AudioMixer::param_cancel(uint64_t node, int index, double time, bool hold) {
140
+ if (mutate_pending_param(node, index, [&](AudioParamState &param) {
141
+ if (hold) {
142
+ param.cancel_and_hold(time);
143
+ } else {
144
+ param.cancel_scheduled(time);
145
+ }
146
+ })) {
147
+ return;
148
+ }
149
+ post_command([this, node, index, time, hold]() {
150
+ AudioNode *target = node_locked(node);
151
+ if (target == nullptr || index < 0 || index >= target->param_count) return;
152
+ if (hold) {
153
+ target->params[index].cancel_and_hold(time);
154
+ } else {
155
+ target->params[index].cancel_scheduled(time);
156
+ }
157
+ });
158
+ }
159
+
160
+ } // namespace xtgui
@@ -25,6 +25,11 @@
25
25
  #include <string>
26
26
  #include <unordered_map>
27
27
 
28
+ /* Defined in browser_location.cpp, which keeps this unit inside the file-length
29
+ * budget. Declared outside the anonymous namespace so it keeps external
30
+ * linkage. */
31
+ xt_value xt_gui_location_build(void);
32
+
28
33
  namespace {
29
34
 
30
35
  xt_value g_navigator = XT_UNDEFINED;
@@ -235,24 +240,6 @@ xt_value navigator_build(void) {
235
240
  return nav;
236
241
  }
237
242
 
238
- xt_value location_build(void) {
239
- xt_value location = xt_object_new();
240
- set_prop(location, "href", string_of("xbintsc://localhost/"));
241
- set_prop(location, "protocol", string_of("xbintsc:"));
242
- set_prop(location, "host", string_of("localhost"));
243
- set_prop(location, "hostname", string_of("localhost"));
244
- set_prop(location, "port", string_of(""));
245
- set_prop(location, "pathname", string_of("/"));
246
- set_prop(location, "search", string_of(""));
247
- set_prop(location, "hash", string_of(""));
248
- set_prop(location, "origin", string_of("xbintsc://localhost"));
249
- set_method(location, "reload", (void *)noop);
250
- set_method(location, "assign", (void *)noop);
251
- set_method(location, "replace", (void *)noop);
252
- set_prop(location, "toString", fn_of((void *)noop));
253
- return location;
254
- }
255
-
256
243
  /* -- localStorage --------------------------------------------------------- */
257
244
 
258
245
  xt_value storage_get_item(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
@@ -446,7 +433,7 @@ void ensure_singletons(void) {
446
433
  xt_gc_add_root(&g_local_storage);
447
434
  }
448
435
  if (!XT_IS_OBJECT(g_location)) {
449
- g_location = location_build();
436
+ g_location = xt_gui_location_build();
450
437
  xt_gc_add_root(&g_location);
451
438
  }
452
439
  }
@@ -0,0 +1,78 @@
1
+ /*
2
+ * xbintsc GUI engine — the `location` object.
3
+ *
4
+ * Split out of `browser.cpp` to keep that unit within the repository's
5
+ * file-length budget. The interesting part is `XT_GUI_URL`: a page addresses
6
+ * itself through `location.search`/`location.hash` (`?bench=1`, `?q=low`,
7
+ * `#shot`), and a compiled program has no browser address bar to supply them.
8
+ */
9
+
10
+ #include "gui_engine.h"
11
+
12
+ #include <string>
13
+
14
+ namespace {
15
+
16
+ xt_value string_of(const char *text) { return xt_string_from_cstr(text != NULL ? text : ""); }
17
+
18
+ xt_value fn_of(void *fn) { return xt_closure_new(fn, 0, NULL); }
19
+
20
+ void set_prop(xt_value target, const char *name, xt_value value) {
21
+ xt_object_set(target, xt_string_from_cstr(name), value);
22
+ }
23
+
24
+ void set_method(xt_value target, const char *name, void *fn) { set_prop(target, name, fn_of(fn)); }
25
+
26
+ xt_value noop(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
27
+ (void)self;
28
+ (void)env;
29
+ (void)argc;
30
+ (void)argv;
31
+ return XT_UNDEFINED;
32
+ }
33
+
34
+ } // namespace
35
+
36
+ xt_value xt_gui_location_build(void) {
37
+ xt_value location = xt_object_new();
38
+ std::string pathname = "/";
39
+ std::string search;
40
+ std::string hash;
41
+ /* `XT_GUI_URL` may be a bare `?query`/`#hash` or a `path?query#hash`; the
42
+ * origin stays `xbintsc://localhost`. Unset keeps the historical empty URL. */
43
+ const char *configured = SDL_getenv("XT_GUI_URL");
44
+ if (configured != NULL && configured[0] != '\0') {
45
+ std::string rest(configured);
46
+ const size_t scheme = rest.find("://");
47
+ if (scheme != std::string::npos) {
48
+ const size_t slash = rest.find('/', scheme + 3);
49
+ rest = slash == std::string::npos ? std::string() : rest.substr(slash);
50
+ }
51
+ const size_t hash_at = rest.find('#');
52
+ if (hash_at != std::string::npos) {
53
+ hash = rest.substr(hash_at);
54
+ rest.erase(hash_at);
55
+ }
56
+ const size_t query_at = rest.find('?');
57
+ if (query_at != std::string::npos) {
58
+ search = rest.substr(query_at);
59
+ rest.erase(query_at);
60
+ }
61
+ if (!rest.empty()) pathname = rest[0] == '/' ? rest : "/" + rest;
62
+ }
63
+ const std::string href = "xbintsc://localhost" + pathname + search + hash;
64
+ set_prop(location, "href", string_of(href.c_str()));
65
+ set_prop(location, "protocol", string_of("xbintsc:"));
66
+ set_prop(location, "host", string_of("localhost"));
67
+ set_prop(location, "hostname", string_of("localhost"));
68
+ set_prop(location, "port", string_of(""));
69
+ set_prop(location, "pathname", string_of(pathname.c_str()));
70
+ set_prop(location, "search", string_of(search.c_str()));
71
+ set_prop(location, "hash", string_of(hash.c_str()));
72
+ set_prop(location, "origin", string_of("xbintsc://localhost"));
73
+ set_method(location, "reload", (void *)noop);
74
+ set_method(location, "assign", (void *)noop);
75
+ set_method(location, "replace", (void *)noop);
76
+ set_prop(location, "toString", fn_of((void *)noop));
77
+ return location;
78
+ }
@@ -128,6 +128,7 @@ static Length makeScalarLength(double number, const std::string &rawUnit) {
128
128
  else if (unit == "rem") length.unit = Unit::Rem;
129
129
  else if (unit == "vw") length.unit = Unit::Vw;
130
130
  else if (unit == "vh") length.unit = Unit::Vh;
131
+ else if (unit == "ch") length.unit = Unit::Ch;
131
132
  else if (unit == "pt") { length.value = (float)number * (96.0f / 72.0f); length.unit = Unit::Px; }
132
133
  else if (unit == "pc") { length.value = (float)number * 16.0f; length.unit = Unit::Px; }
133
134
  else if (unit == "in") { length.value = (float)number * 96.0f; length.unit = Unit::Px; }
@@ -26,6 +26,10 @@ enum class Unit {
26
26
  Rem,
27
27
  Vw,
28
28
  Vh,
29
+ /** `ch`: the advance width of "0" in the element's font. Resolved as half an
30
+ * `em`, the usual measure for a digit in the proportional faces the engine
31
+ * loads; see `doc/gui/known-issues.md` for that approximation. */
32
+ Ch,
29
33
  Number,
30
34
  Clamp,
31
35
  Min,
@@ -208,8 +208,10 @@ bool functionArgument(const std::string &text, size_t open_paren, std::string *o
208
208
  }
209
209
 
210
210
  /** Parse the `src` descriptor: keep every `url(...)` source in order and drop
211
- * `local(...)`. The `format(...)` hint is retained for diagnostics/future
212
- * format selection; the runtime simply tries the sources in order. */
211
+ * `local(...)`. The `format(...)` hint is kept but is advisory only: the runtime
212
+ * tries each source and detects the container from the file's signature, so a
213
+ * mislabelled entry still loads and an unknown format falls through to the
214
+ * next source. */
213
215
  void parseFontFaceSources(const std::string &value, FontFaceRule *rule) {
214
216
  rule->sources.clear();
215
217
  for (const std::string &part : xt_css_split_commas(value)) {
@@ -423,6 +423,13 @@ bool XtDocument::advance(double delta_ms) {
423
423
  if (previous < end && clock_ms_ >= end) just_finished = true;
424
424
  }
425
425
  if (!running && !just_finished) return false;
426
+ /* A pending restyle is about to call `updateDisplay()` again with the clock
427
+ * we just advanced. Rebuilding the displayed styles here too meant a full
428
+ * per-node style copy and a full layout twice on every dirty frame of an
429
+ * animating page — the Saltline HUD mutates a transform every frame while a
430
+ * transition is running, so that was the normal path. The restyle's
431
+ * `updateDisplay()` produces exactly the same result. */
432
+ if (dirty_) return false;
426
433
  updateDisplay();
427
434
  return true;
428
435
  }
@@ -65,8 +65,9 @@ std::string computed_value(const xtgui::XtStyle *style, const std::string &rawNa
65
65
  std::string property = xtgui::xt_css_lower(xtgui::xt_css_trim(mapped));
66
66
  if (property.empty()) return std::string();
67
67
  if (property.size() > 2 && property[0] == '-' && property[1] == '-') {
68
- auto found = style->variables.find(property);
69
- return found == style->variables.end() ? std::string() : found->second;
68
+ if (!style->variables) return std::string();
69
+ auto found = style->variables->find(property);
70
+ return found == style->variables->end() ? std::string() : found->second;
70
71
  }
71
72
  return xtgui::xt_style_property_to_string(*style, property);
72
73
  }
@@ -306,8 +306,14 @@ std::string webgl_string(int32_t argc, xt_value *argv, int32_t index) {
306
306
 
307
307
  std::vector<double> webgl_numbers(xt_value value) {
308
308
  std::vector<double> out;
309
- if (!XT_IS_OBJECT(value)) return out;
310
- const int kind = xt_typed_array_kind_of(value);
309
+ /* A WebGL numeric argument may be a typed array *or* a plain JavaScript
310
+ * array: the spec's IDL accepts `sequence<GLfloat>`, and three.js relies on
311
+ * it (`uniform1fv` is handed the plain `weights` array of the PMREM blur
312
+ * shader without a `Float32Array` conversion). Arrays carry `XT_TAG_ARRAY`,
313
+ * not `XT_TAG_OBJECT`, so both tags have to be accepted here. */
314
+ const bool is_array = XT_IS_ARRAY(value);
315
+ if (!XT_IS_OBJECT(value) && !is_array) return out;
316
+ const int kind = is_array ? -1 : xt_typed_array_kind_of(value);
311
317
  const double length = xt_to_number(xt_get(value, xt_string_from_cstr("length")));
312
318
  if (!(length > 0.0) || length > 100000000.0) return out;
313
319
  out.reserve((size_t)length);
@@ -321,6 +327,37 @@ std::vector<double> webgl_numbers(xt_value value) {
321
327
  return out;
322
328
  }
323
329
 
330
+ /**
331
+ * Copy a 32-bit typed array's elements as `float` in one memcpy.
332
+ *
333
+ * A `Float32Array` passed to `uniformMatrix4fv` is the hot WebGL call of every
334
+ * three.js frame; the generic `webgl_numbers` path allocated a `double` vector
335
+ * and made one runtime call per element. The element width is inferred from
336
+ * `byteLength == length * 4`, which is exactly the set of views a float uniform
337
+ * accepts (Float32Array, and the invalid-but-tolerated Int32/Uint32). Plain
338
+ * arrays and other views return false and keep the old path.
339
+ */
340
+ bool webgl_float_elements(xt_value value, std::vector<float> *out) {
341
+ out->clear();
342
+ if (!XT_IS_OBJECT(value) || xt_typed_array_kind_of(value) < 0) return false;
343
+ const double length = xt_to_number(xt_get(value, xt_string_from_cstr("length")));
344
+ const double bytes = xt_to_number(xt_get(value, xt_string_from_cstr("byteLength")));
345
+ if (!(length >= 0.0) || bytes != length * 4.0) return false;
346
+ xt_value buffer = xt_typed_array_buffer_of(value);
347
+ if (!xt_is_array_buffer(buffer)) return false;
348
+ const uint32_t offset = xt_typed_array_byte_offset_of(value);
349
+ out->resize((size_t)length);
350
+ if (length > 0.0) {
351
+ const uint32_t byte_length = (uint32_t)(length * 4.0);
352
+ auto *bytes = reinterpret_cast<uint8_t *>(out->data());
353
+ if (xt_array_buffer_copy_bytes_out(buffer, offset, bytes, byte_length) != byte_length) {
354
+ out->clear();
355
+ return false;
356
+ }
357
+ }
358
+ return true;
359
+ }
360
+
324
361
  std::vector<uint8_t> webgl_bytes(xt_value value) {
325
362
  std::vector<uint8_t> out;
326
363
  if (!XT_IS_OBJECT(value)) return out;
@@ -0,0 +1,134 @@
1
+ /*
2
+ * xbintsc GUI engine — WebGL extension entry points.
3
+ *
4
+ * `getSupportedExtensions` / `getExtension` decide what a capability probe sees;
5
+ * the compressed-texture families are built by `dom_api_webgl_compressed.cpp`.
6
+ * `WEBGL_lose_context` lives here too because its two methods are the only
7
+ * extension that carries behaviour. `KHR_parallel_shader_compile` publishes
8
+ * only `COMPLETION_STATUS_KHR`: translation is synchronous, so the completion
9
+ * query is always true (`dom_api_webgl_shader.cpp`).
10
+ */
11
+
12
+ #include "dom_api_internal.h"
13
+
14
+ #include <string>
15
+
16
+ #include "webgl.h"
17
+
18
+ #define METHOD(name) xt_value name(xt_value self, xt_value env, int32_t argc, xt_value *argv)
19
+
20
+ namespace domapi {
21
+ namespace {
22
+
23
+ /** Fire a `webglcontextlost`/`webglcontextrestored` event on the canvas that
24
+ * owns the context. `self` is the context or extension handle. */
25
+ void dispatch_context_event(xt_value self, const char *type) {
26
+ XtGuiWindow *win = nullptr;
27
+ xtgui::Node *node = resolve_node(xt_object_get_cstr(self, "__xt_gl_node"), &win);
28
+ if (win != nullptr && node != nullptr) xt_gui_dispatch_to_node(win, node, type);
29
+ }
30
+
31
+ } // namespace
32
+
33
+ METHOD(webgl_lose_context);
34
+ METHOD(webgl_restore_context);
35
+
36
+ METHOD(webgl_get_supported_extensions) {
37
+ (void)env;
38
+ (void)argc;
39
+ (void)argv;
40
+ xt_value list = xt_array_new(0, nullptr);
41
+ xt_array_push(list, xt_string_from_cstr("OES_element_index_uint"));
42
+ xt_array_push(list, xt_string_from_cstr("OES_standard_derivatives"));
43
+ xt_array_push(list, xt_string_from_cstr("OES_texture_float"));
44
+ xt_array_push(list, xt_string_from_cstr("OES_texture_half_float"));
45
+ xt_array_push(list, xt_string_from_cstr("WEBGL_depth_texture"));
46
+ xt_array_push(list, xt_string_from_cstr("EXT_color_buffer_float"));
47
+ xt_array_push(list, xt_string_from_cstr("EXT_color_buffer_half_float"));
48
+ xt_array_push(list, xt_string_from_cstr("WEBGL_lose_context"));
49
+ /* Compilation is synchronous, so the completion query is always true; the
50
+ * extension is still advertised because three.js (and other loaders) warn
51
+ * when a probe finds it missing. */
52
+ xt_array_push(list, xt_string_from_cstr("KHR_parallel_shader_compile"));
53
+ xt_array_push(list, xt_string_from_cstr("EXT_texture_filter_anisotropic"));
54
+ xtgui::WebGLContext *context = webgl_from_context(self);
55
+ if (context != nullptr && context->supports_texture_format(0x83F1)) {
56
+ xt_array_push(list, xt_string_from_cstr("WEBGL_compressed_texture_s3tc"));
57
+ }
58
+ if (context != nullptr && context->supports_texture_format(0x8C4D)) {
59
+ xt_array_push(list, xt_string_from_cstr("WEBGL_compressed_texture_s3tc_srgb"));
60
+ }
61
+ if (context != nullptr && context->supports_texture_format(0x93B0)) {
62
+ xt_array_push(list, xt_string_from_cstr("WEBGL_compressed_texture_astc"));
63
+ }
64
+ return list;
65
+ }
66
+
67
+ METHOD(webgl_get_extension) {
68
+ (void)env;
69
+ const std::string name = webgl_string(argc, argv, 0);
70
+ if (name.rfind("WEBGL_compressed_texture_", 0) == 0) {
71
+ xt_value extension = webgl_compressed_extension(name, webgl_from_context(self));
72
+ if (!XT_IS_UNDEFINED(extension)) return extension;
73
+ }
74
+ if (name == "OES_element_index_uint" || name == "OES_standard_derivatives" ||
75
+ name == "OES_texture_float" || name == "OES_texture_half_float" ||
76
+ name == "WEBGL_depth_texture" || name == "EXT_color_buffer_float" ||
77
+ name == "EXT_color_buffer_half_float") {
78
+ return xt_object_new();
79
+ }
80
+ if (name == "EXT_texture_filter_anisotropic") {
81
+ xt_value e = xt_object_new();
82
+ xt_object_set(e, xt_string_from_cstr("MAX_TEXTURE_MAX_ANISOTROPY_EXT"), xt_number(0x84FF));
83
+ xt_object_set(e, xt_string_from_cstr("TEXTURE_MAX_ANISOTROPY_EXT"), xt_number(0x84FE));
84
+ return e;
85
+ }
86
+ if (name == "KHR_parallel_shader_compile") {
87
+ xt_value e = xt_object_new();
88
+ xt_object_set(e, xt_string_from_cstr("COMPLETION_STATUS_KHR"),
89
+ xt_number(xtgui::kWebGLCompletionStatusKHR));
90
+ return e;
91
+ }
92
+ if (name == "WEBGL_lose_context") {
93
+ xt_value object = xt_object_new();
94
+ /* The closures receive this object as `this`, so carry the context id and
95
+ * the canvas handle over from the context that produced the extension. */
96
+ xt_object_set(object, xt_string_from_cstr("__xt_gl_context"),
97
+ xt_object_get_cstr(self, "__xt_gl_context"));
98
+ xt_object_set(object, xt_string_from_cstr("__xt_gl_node"),
99
+ xt_object_get_cstr(self, "__xt_gl_node"));
100
+ xt_object_set(object, xt_string_from_cstr("loseContext"),
101
+ xt_closure_new((void *)webgl_lose_context, 0, nullptr));
102
+ xt_object_set(object, xt_string_from_cstr("restoreContext"),
103
+ xt_closure_new((void *)webgl_restore_context, 0, nullptr));
104
+ return object;
105
+ }
106
+ return XT_NULL;
107
+ }
108
+
109
+ /* `WEBGL_lose_context.loseContext()` / `restoreContext()`: the simulator drops
110
+ * every object and reports `CONTEXT_LOST_WEBGL` until the restore, so a page
111
+ * exercises the same loss/restore path it would take on a real GPU reset. */
112
+ METHOD(webgl_lose_context) {
113
+ (void)env;
114
+ (void)argc;
115
+ (void)argv;
116
+ xtgui::WebGLContext *context = webgl_from_context(self);
117
+ if (context == nullptr || context->lost()) return XT_UNDEFINED;
118
+ context->lose_context();
119
+ dispatch_context_event(self, "webglcontextlost");
120
+ return XT_UNDEFINED;
121
+ }
122
+
123
+ METHOD(webgl_restore_context) {
124
+ (void)env;
125
+ (void)argc;
126
+ (void)argv;
127
+ xtgui::WebGLContext *context = webgl_from_context(self);
128
+ if (context == nullptr || !context->lost()) return XT_UNDEFINED;
129
+ context->restore_context();
130
+ if (!context->lost()) dispatch_context_event(self, "webglcontextrestored");
131
+ return XT_UNDEFINED;
132
+ }
133
+
134
+ } // namespace domapi
@@ -39,6 +39,10 @@ int webgl_int(int32_t argc, xt_value *argv, int32_t index, int fallback);
39
39
  std::string webgl_string(int32_t argc, xt_value *argv, int32_t index);
40
40
  /** Read an array/typed array of numbers. */
41
41
  std::vector<double> webgl_numbers(xt_value value);
42
+ /** Fast path: copy a 32-bit typed array's elements as floats. Returns false for
43
+ * a plain array or a non-32-bit view (the caller falls back to
44
+ * `webgl_numbers`). */
45
+ bool webgl_float_elements(xt_value value, std::vector<float> *out);
42
46
  /** Read the raw bytes of a typed array / ArrayBuffer (or a byte array). */
43
47
  std::vector<uint8_t> webgl_bytes(xt_value value);
44
48
  /** Store `count` bytes into a typed array / array handle. */
@@ -98,6 +98,10 @@ METHOD(webgl_get_shader_parameter) {
98
98
  if (record == nullptr) return XT_NULL;
99
99
  if (pname == GL_COMPILE_STATUS) return xt_bool(context->shader_compiled(shader));
100
100
  if (pname == GL_DELETE_STATUS) return XT_FALSE;
101
+ if (pname == xtgui::kWebGLCompletionStatusKHR) {
102
+ /* `KHR_parallel_shader_compile`: no compilation is ever pending. */
103
+ return XT_TRUE;
104
+ }
101
105
  if (pname == GL_SHADER_TYPE) return xt_number(record->type);
102
106
  return XT_NULL;
103
107
  }
@@ -182,6 +186,11 @@ METHOD(webgl_get_program_parameter) {
182
186
  if (pname == GL_LINK_STATUS) return xt_bool(context->program_linked(program));
183
187
  if (pname == GL_VALIDATE_STATUS) return xt_bool(context->program_linked(program));
184
188
  if (pname == GL_DELETE_STATUS) return XT_FALSE;
189
+ if (pname == xtgui::kWebGLCompletionStatusKHR) {
190
+ /* `KHR_parallel_shader_compile`: linking is synchronous, so a `compileAsync`
191
+ * poller that waits on this pname finishes on its first tick. */
192
+ return xt_bool(context->program(program) != nullptr);
193
+ }
185
194
  if (pname == GL_ATTACHED_SHADERS) {
186
195
  return xt_number((double)context->attached_shaders(program).size());
187
196
  }
@@ -317,8 +326,18 @@ void uniform_vectors(xt_value self, int32_t argc, xt_value *argv, int components
317
326
  uint32_t program = 0;
318
327
  int location = 0;
319
328
  if (!location_of(xt_arg(argc, argv, 0), &program, &location)) return;
320
- const std::vector<double> numbers =
321
- webgl_numbers(argc > 1 ? xt_arg(argc, argv, 1) : XT_UNDEFINED);
329
+ const xt_value source = argc > 1 ? xt_arg(argc, argv, 1) : XT_UNDEFINED;
330
+ /* A `Float32Array` is the normal argument; reading its bytes once is much
331
+ * cheaper than a `double` vector built with one runtime call per element. */
332
+ if (!integer) {
333
+ std::vector<float> floats;
334
+ if (webgl_float_elements(source, &floats) && !floats.empty()) {
335
+ const int count = (int)(floats.size() / (size_t)components);
336
+ context->uniform_floats_raw(program, location, components, floats.data(), count);
337
+ return;
338
+ }
339
+ }
340
+ const std::vector<double> numbers = webgl_numbers(source);
322
341
  if (numbers.empty()) return;
323
342
  const int count = (int)(numbers.size() / components);
324
343
  if (integer) {
@@ -405,8 +424,13 @@ void uniform_matrix(xt_value self, int32_t argc, xt_value *argv, int dimensions)
405
424
  uint32_t program = 0;
406
425
  int location = 0;
407
426
  if (!location_of(xt_arg(argc, argv, 0), &program, &location)) return;
408
- const std::vector<double> values =
409
- webgl_numbers(argc > 2 ? xt_arg(argc, argv, 2) : XT_UNDEFINED);
427
+ const xt_value source = argc > 2 ? xt_arg(argc, argv, 2) : XT_UNDEFINED;
428
+ std::vector<float> floats;
429
+ if (webgl_float_elements(source, &floats) && !floats.empty()) {
430
+ context->uniform_matrix_raw(program, location, dimensions, floats.data());
431
+ return;
432
+ }
433
+ const std::vector<double> values = webgl_numbers(source);
410
434
  if (values.empty()) return;
411
435
  context->uniform_matrix(program, location, dimensions, values.data());
412
436
  }