xbintsc 0.7.8 → 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 (116) 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/context.d.ts +4 -3
  4. package/dist/src/codegen/generator/context.js +6 -5
  5. package/dist/src/codegen/generator/context.js.map +1 -1
  6. package/dist/src/codegen/generator/expressions/assignment.js +3 -3
  7. package/dist/src/driver/config.d.ts +1 -1
  8. package/dist/src/driver/options.d.ts +1 -1
  9. package/dist/src/driver/version.d.ts +1 -1
  10. package/dist/src/driver/version.js +1 -1
  11. package/dist/src/extensions/gui/features.d.ts +14 -6
  12. package/dist/src/extensions/gui/features.js +34 -6
  13. package/dist/src/extensions/gui/features.js.map +1 -1
  14. package/dist/src/extensions/gui/index.js +3 -3
  15. package/dist/tests/codegen/llvm.test.js +1 -1
  16. package/dist/tests/e2e/gui-audio.test.js +24 -0
  17. package/dist/tests/e2e/gui-audio.test.js.map +1 -1
  18. package/dist/tests/e2e/gui-draw-perf.test.js +9 -0
  19. package/dist/tests/e2e/gui-draw-perf.test.js.map +1 -1
  20. package/dist/tests/e2e/gui-font-face.test.d.ts +3 -1
  21. package/dist/tests/e2e/gui-font-face.test.js +99 -7
  22. package/dist/tests/e2e/gui-font-face.test.js.map +1 -1
  23. package/dist/tests/e2e/gui-frame-pacing.test.d.ts +15 -0
  24. package/dist/tests/e2e/gui-frame-pacing.test.js +68 -0
  25. package/dist/tests/e2e/gui-frame-pacing.test.js.map +1 -0
  26. package/dist/tests/e2e/gui-initial-url.test.d.ts +10 -0
  27. package/dist/tests/e2e/gui-initial-url.test.js +49 -0
  28. package/dist/tests/e2e/gui-initial-url.test.js.map +1 -0
  29. package/dist/tests/e2e/gui-webgl-depth-range.test.d.ts +18 -0
  30. package/dist/tests/e2e/gui-webgl-depth-range.test.js +140 -0
  31. package/dist/tests/e2e/gui-webgl-depth-range.test.js.map +1 -0
  32. package/dist/tests/extensions/gui-features.test.js +27 -2
  33. package/dist/tests/extensions/gui-features.test.js.map +1 -1
  34. package/doc/ai/extensions.md +10 -4
  35. package/doc/ai/zh-CN/extensions.md +8 -3
  36. package/doc/gui/api.md +35 -2
  37. package/doc/gui/build.md +34 -15
  38. package/doc/gui/known-issues.md +1 -1
  39. package/doc/gui/rendering.md +45 -8
  40. package/doc/gui/runtime.md +13 -0
  41. package/doc/gui/webgl.md +11 -2
  42. package/doc/gui.md +9 -4
  43. package/doc/implemented/codegen.md +3 -2
  44. package/doc/zh-CN/gui/api.md +25 -2
  45. package/doc/zh-CN/gui/build.md +20 -7
  46. package/doc/zh-CN/gui/known-issues.md +1 -1
  47. package/doc/zh-CN/gui/rendering.md +33 -8
  48. package/doc/zh-CN/gui/runtime.md +9 -0
  49. package/doc/zh-CN/gui/webgl.md +3 -2
  50. package/doc/zh-CN/gui.md +10 -5
  51. package/doc/zh-CN/implemented/codegen.md +3 -2
  52. package/package.json +7 -7
  53. package/runtime/ext_gui/audio_graph_commands.cpp +127 -0
  54. package/runtime/ext_gui/audio_mixer.cpp +84 -163
  55. package/runtime/ext_gui/audio_mixer.h +59 -3
  56. package/runtime/ext_gui/audio_mixer_extra.cpp +8 -0
  57. package/runtime/ext_gui/audio_param_apply.cpp +160 -0
  58. package/runtime/ext_gui/browser.cpp +6 -19
  59. package/runtime/ext_gui/browser_location.cpp +78 -0
  60. package/runtime/ext_gui/css_sheet.cpp +4 -2
  61. package/runtime/ext_gui/document_animation.cpp +7 -0
  62. package/runtime/ext_gui/dom_api_computed_style.cpp +3 -2
  63. package/runtime/ext_gui/dom_api_webgl.cpp +31 -0
  64. package/runtime/ext_gui/dom_api_webgl_internal.h +4 -0
  65. package/runtime/ext_gui/dom_api_webgl_shader.cpp +19 -4
  66. package/runtime/ext_gui/dom_api_webgl_state.cpp +6 -3
  67. package/runtime/ext_gui/gui.cpp +100 -1
  68. package/runtime/ext_gui/gui_events.cpp +8 -2
  69. package/runtime/ext_gui/perf.cpp +18 -6
  70. package/runtime/ext_gui/perf.h +37 -0
  71. package/runtime/ext_gui/style.cpp +27 -10
  72. package/runtime/ext_gui/style.h +10 -1
  73. package/runtime/ext_gui/text.cpp +4 -0
  74. package/runtime/ext_gui/text_font_bytes.cpp +117 -0
  75. package/runtime/ext_gui/text_font_bytes.h +65 -0
  76. package/runtime/ext_gui/text_font_db.cpp +5 -0
  77. package/runtime/ext_gui/text_font_sfnt.cpp +71 -24
  78. package/runtime/ext_gui/text_font_sfnt.h +5 -2
  79. package/runtime/ext_gui/text_hb.cpp +34 -5
  80. package/runtime/ext_gui/text_stb.cpp +7 -30
  81. package/runtime/ext_gui/text_webfont.cpp +217 -0
  82. package/runtime/ext_gui/warnings.cpp +26 -0
  83. package/runtime/ext_gui/warnings.h +8 -0
  84. package/runtime/ext_gui/webfont_bridge.c +23 -0
  85. package/runtime/ext_gui/webgl.h +34 -39
  86. package/runtime/ext_gui/webgl_blit_color.cpp +5 -0
  87. package/runtime/ext_gui/webgl_buffer_objects.cpp +19 -5
  88. package/runtime/ext_gui/webgl_draw.cpp +72 -12
  89. package/runtime/ext_gui/webgl_draw_setup.cpp +8 -2
  90. package/runtime/ext_gui/webgl_draw_state.h +13 -2
  91. package/runtime/ext_gui/webgl_objects.h +4 -0
  92. package/runtime/ext_gui/webgl_program.h +64 -0
  93. package/runtime/ext_gui/webgl_state.cpp +7 -0
  94. package/runtime/ext_gui/webgl_uniform.cpp +78 -0
  95. package/runtime/ext_gui/window.cpp +6 -0
  96. package/runtime/rt_object.h +6 -0
  97. package/runtime/rt_profile.h +6 -0
  98. package/runtime/xt_containers/access.inc +2 -47
  99. package/runtime/xt_containers/ic_get.inc +70 -0
  100. package/runtime/xt_containers/method_cache.inc +24 -10
  101. package/runtime/xt_containers/objects.inc +12 -1
  102. package/runtime/xt_containers/shapes.inc +78 -0
  103. package/runtime/xt_containers.c +1 -0
  104. package/runtime/xt_profile.c +3 -0
  105. package/scripts/build-gui.ts +43 -49
  106. package/scripts/gui-engine-build.ts +58 -0
  107. package/scripts/gui-vendor-source.ts +53 -0
  108. package/scripts/gui-webfont-build.ts +138 -0
  109. package/src/cli/help.ts +1 -1
  110. package/src/codegen/generator/context.ts +6 -6
  111. package/src/codegen/generator/expressions/assignment.ts +3 -3
  112. package/src/driver/config.ts +1 -1
  113. package/src/driver/options.ts +1 -1
  114. package/src/driver/version.ts +1 -1
  115. package/src/extensions/gui/features.ts +34 -6
  116. package/src/extensions/gui/index.ts +3 -3
@@ -21,7 +21,9 @@
21
21
  #ifndef XT_GUI_AUDIO_MIXER_H
22
22
  #define XT_GUI_AUDIO_MIXER_H
23
23
 
24
+ #include <atomic>
24
25
  #include <cstdint>
26
+ #include <functional>
25
27
  #include <memory>
26
28
  #include <mutex>
27
29
  #include <unordered_map>
@@ -283,7 +285,7 @@ class AudioMixer {
283
285
  void param_cancel(uint64_t node, int index, double time, bool hold);
284
286
 
285
287
  /* -- clock and device -------------------------------------------------- */
286
- double current_time();
288
+ double current_time() const;
287
289
  /** Best effort: a headless host has no device and playback stays silent. */
288
290
  bool start_device();
289
291
  void suspend_device();
@@ -304,14 +306,56 @@ class AudioMixer {
304
306
  const float *pull_locked(AudioNode *node);
305
307
  void render_quantum_locked();
306
308
  void render_locked(float *out, int frames);
309
+ /** Queue a graph/parameter mutation for the audio thread; the command runs
310
+ * with `mutex_` held at the next quantum boundary. Parameter scheduling goes
311
+ * through here so a page's per-frame Web Audio calls never wait for a
312
+ * convolver block to finish (the mixer holds `mutex_` for its whole DSP
313
+ * pass). */
314
+ void post_command(std::function<void()> command);
315
+ /** Apply queued mutations now (for a getter that must observe them). */
316
+ void drain_commands_locked();
317
+ /** Apply a parameter mutation straight to a node the audio thread has not
318
+ * inserted yet, under the pending table's lock, and return true. Return false
319
+ * when the node is already in the graph so the caller queues the mutation in
320
+ * the FIFO instead.
321
+ *
322
+ * A pending node's parameters are not rendered yet, so touching them here is
323
+ * safe: the queued insertion erases the entry from `pending_nodes_` under this
324
+ * same lock, so a direct write either completes before the audio thread can
325
+ * render the node or is not attempted at all. Without this, a
326
+ * `gain.value = 0.5` right after `createGain()` was only *queued* while
327
+ * `param_value` answered from the pending node's untouched default — a getter
328
+ * read `1` back until something drained the FIFO. On a host with no audio
329
+ * device (a headless CI runner, or a program that builds its graph before the
330
+ * first `start()`) nothing drains it, so the write was never observable. */
331
+ template <typename Mutate>
332
+ bool mutate_pending_param(uint64_t node, int index, Mutate mutate) {
333
+ std::lock_guard<std::mutex> lock(pending_mutex_);
334
+ auto found = pending_nodes_.find(node);
335
+ if (found == pending_nodes_.end()) return false;
336
+ AudioNode &target = *found->second;
337
+ if (index >= 0 && index < target.param_count) mutate(target.params[index]);
338
+ return true;
339
+ }
307
340
 
308
341
  std::mutex mutex_;
342
+ std::mutex command_mutex_;
343
+ std::vector<std::function<void()>> commands_;
309
344
  std::unordered_map<uint64_t, std::shared_ptr<AudioNode>> nodes_;
310
- uint64_t next_node_id_ = 1;
345
+ /** Nodes created by the page but not yet inserted by the audio thread. The
346
+ * constructor runs on the main thread and `param_value` reads a pending
347
+ * node's defaults there, so creating a node never waits for the render lock;
348
+ * insertion is queued like every other graph mutation. */
349
+ std::unordered_map<uint64_t, std::shared_ptr<AudioNode>> pending_nodes_;
350
+ std::mutex pending_mutex_;
351
+ std::atomic<uint64_t> next_node_id_{1};
311
352
  uint64_t destination_id_ = 0;
312
353
  uint64_t listener_id_ = 0;
313
354
  uint64_t serial_ = 0;
314
- uint64_t frames_rendered_ = 0;
355
+ /** Read by the page (`AudioContext.currentTime`, `AudioParam` scheduling)
356
+ * while the audio thread advances it; atomic so a read never waits for a
357
+ * quantum render. Updated under `mutex_`, which still orders graph state. */
358
+ std::atomic<uint64_t> frames_rendered_{0};
315
359
  std::vector<float> pending_;
316
360
  size_t pending_offset_ = 0;
317
361
 
@@ -319,6 +363,18 @@ class AudioMixer {
319
363
  bool running_ = true;
320
364
  SDL_AudioStream *stream_ = nullptr;
321
365
  bool device_tried_ = false;
366
+
367
+ /* Audio-path diagnostics. `XT_GUI_AUDIO_SILENT=1` renders silence while
368
+ * keeping the clock and the locking, which separates the mixer's DSP cost
369
+ * from the page's main-thread Web Audio calls. `XT_AUDIO_PROFILE=1`
370
+ * accumulates the render/lock times and dumps them at shutdown. */
371
+ bool silent_ = false;
372
+ bool profile_ = false;
373
+ uint64_t start_ns_ = 0;
374
+ std::atomic<uint64_t> lock_wait_ns_{0};
375
+ std::atomic<uint64_t> render_ns_{0};
376
+ std::atomic<uint64_t> render_quanta_{0};
377
+ std::atomic<uint64_t> max_render_ns_{0};
322
378
  };
323
379
 
324
380
  } // namespace xtgui
@@ -11,6 +11,7 @@ namespace xtgui {
11
11
 
12
12
  void AudioMixer::set_shaper_curve(uint64_t node, const std::vector<float> &curve, int oversample) {
13
13
  std::lock_guard<std::mutex> lock(mutex_);
14
+ drain_commands_locked();
14
15
  AudioNode *target = node_locked(node);
15
16
  if (target == nullptr) return;
16
17
  /* A one-entry curve is a DC curve on the platform; keep the same length
@@ -21,6 +22,7 @@ void AudioMixer::set_shaper_curve(uint64_t node, const std::vector<float> &curve
21
22
 
22
23
  void AudioMixer::set_shaper_oversample(uint64_t node, int oversample) {
23
24
  std::lock_guard<std::mutex> lock(mutex_);
25
+ drain_commands_locked();
24
26
  AudioNode *target = node_locked(node);
25
27
  if (target != nullptr) target->shaper_oversample = oversample > 1 ? oversample : 1;
26
28
  }
@@ -28,6 +30,7 @@ void AudioMixer::set_shaper_oversample(uint64_t node, int oversample) {
28
30
  void AudioMixer::set_convolver_impulse(uint64_t node, std::shared_ptr<AudioClip> clip,
29
31
  bool normalize) {
30
32
  std::lock_guard<std::mutex> lock(mutex_);
33
+ drain_commands_locked();
31
34
  AudioNode *target = node_locked(node);
32
35
  if (target == nullptr) return;
33
36
  prepare_convolver(target, clip, normalize);
@@ -35,6 +38,7 @@ void AudioMixer::set_convolver_impulse(uint64_t node, std::shared_ptr<AudioClip>
35
38
 
36
39
  void AudioMixer::set_analyser_fft(uint64_t node, int fft_size) {
37
40
  std::lock_guard<std::mutex> lock(mutex_);
41
+ drain_commands_locked();
38
42
  AudioNode *target = node_locked(node);
39
43
  if (target == nullptr) return;
40
44
  if (fft_size < 32) fft_size = 32;
@@ -46,6 +50,7 @@ void AudioMixer::set_analyser_fft(uint64_t node, int fft_size) {
46
50
 
47
51
  void AudioMixer::set_analyser_smoothing(uint64_t node, float smoothing) {
48
52
  std::lock_guard<std::mutex> lock(mutex_);
53
+ drain_commands_locked();
49
54
  AudioNode *target = node_locked(node);
50
55
  if (target == nullptr) return;
51
56
  if (smoothing < 0.0f) smoothing = 0.0f;
@@ -55,6 +60,7 @@ void AudioMixer::set_analyser_smoothing(uint64_t node, float smoothing) {
55
60
 
56
61
  bool AudioMixer::analyser_time_domain(uint64_t node, int count, std::vector<float> *out) {
57
62
  std::lock_guard<std::mutex> lock(mutex_);
63
+ drain_commands_locked();
58
64
  AudioNode *target = node_locked(node);
59
65
  if (target == nullptr || out == nullptr) return false;
60
66
  const size_t size = target->analyser_ring.size();
@@ -70,6 +76,7 @@ bool AudioMixer::analyser_time_domain(uint64_t node, int count, std::vector<floa
70
76
 
71
77
  bool AudioMixer::analyser_spectrum(uint64_t node, std::vector<float> *out) {
72
78
  std::lock_guard<std::mutex> lock(mutex_);
79
+ drain_commands_locked();
73
80
  AudioNode *target = node_locked(node);
74
81
  if (target == nullptr || out == nullptr) return false;
75
82
  const size_t size = target->analyser_ring.size();
@@ -111,6 +118,7 @@ void AudioMixer::set_panner(uint64_t node, int distance_model, double ref_distan
111
118
  double max_distance, double rolloff, double cone_inner,
112
119
  double cone_outer, double cone_gain, int panning_model) {
113
120
  std::lock_guard<std::mutex> lock(mutex_);
121
+ drain_commands_locked();
114
122
  AudioNode *target = node_locked(node);
115
123
  if (target == nullptr) return;
116
124
  target->distance_model = distance_model;
@@ -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
+ }
@@ -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
  }
@@ -327,6 +327,37 @@ std::vector<double> webgl_numbers(xt_value value) {
327
327
  return out;
328
328
  }
329
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
+
330
361
  std::vector<uint8_t> webgl_bytes(xt_value value) {
331
362
  std::vector<uint8_t> out;
332
363
  if (!XT_IS_OBJECT(value)) return out;
@@ -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. */
@@ -326,8 +326,18 @@ void uniform_vectors(xt_value self, int32_t argc, xt_value *argv, int components
326
326
  uint32_t program = 0;
327
327
  int location = 0;
328
328
  if (!location_of(xt_arg(argc, argv, 0), &program, &location)) return;
329
- const std::vector<double> numbers =
330
- 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);
331
341
  if (numbers.empty()) return;
332
342
  const int count = (int)(numbers.size() / components);
333
343
  if (integer) {
@@ -414,8 +424,13 @@ void uniform_matrix(xt_value self, int32_t argc, xt_value *argv, int dimensions)
414
424
  uint32_t program = 0;
415
425
  int location = 0;
416
426
  if (!location_of(xt_arg(argc, argv, 0), &program, &location)) return;
417
- const std::vector<double> values =
418
- 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);
419
434
  if (values.empty()) return;
420
435
  context->uniform_matrix(program, location, dimensions, values.data());
421
436
  }
@@ -114,8 +114,11 @@ METHOD(webgl_depth_mask) {
114
114
 
115
115
  METHOD(webgl_depth_range) {
116
116
  (void)env;
117
- (void)argc;
118
- (void)argv;
117
+ xtgui::WebGLContext *context = context_of(self);
118
+ if (context != nullptr) {
119
+ context->depth_range((float)webgl_number(argc, argv, 0, 0.0),
120
+ (float)webgl_number(argc, argv, 1, 1.0));
121
+ }
119
122
  return XT_UNDEFINED;
120
123
  }
121
124
 
@@ -319,7 +322,7 @@ METHOD(webgl_get_parameter) {
319
322
  return number_array(values, 4);
320
323
  }
321
324
  case GL_DEPTH_RANGE: {
322
- const double values[2] = {0, 1};
325
+ const double values[2] = {context->depth_range_near(), context->depth_range_far()};
323
326
  return number_array(values, 2);
324
327
  }
325
328
  case GL_BLEND_COLOR: {