@geastack/engine 0.1.14 → 0.1.16

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.
@@ -1,7 +1,14 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  #pragma once
3
3
 
4
+ #include <memory>
5
+ #include <algorithm>
6
+ #include <cmath>
7
+ #include <type_traits>
8
+
4
9
  #include "canvas.h"
10
+ #include <image.h>
11
+ #include "display.h"
5
12
  #include "node.h"
6
13
 
7
14
  #include <cstdint>
@@ -9,8 +16,54 @@
9
16
  #include <string>
10
17
  #include <vector>
11
18
 
19
+ namespace gea::framework::display_present { struct Frame; }
20
+
12
21
  namespace gea::embedded::ui {
13
22
 
23
+ // Borrow numeric containers for the duration of one draw call. Typed arrays
24
+ // need no temporary vectors; only the retained triangle command owns a copy.
25
+ class CanvasNumericArrayView {
26
+ public:
27
+ template <typename Container>
28
+ CanvasNumericArrayView(const Container &values)
29
+ : source_(&values), size_(values.size()),
30
+ read_(+[](const void *source, std::size_t index, bool truncate) {
31
+ const auto &container = *static_cast<const Container *>(source);
32
+ using Element = std::remove_cvref_t<decltype(container[index])>;
33
+ static_assert(std::is_arithmetic_v<Element>,
34
+ "Canvas arrays must contain numeric values");
35
+ if constexpr (std::is_floating_point_v<Element>) {
36
+ const auto value = container[index];
37
+ if (!std::isfinite(value))
38
+ return std::int64_t{0};
39
+ if constexpr (std::is_same_v<Element, float>) {
40
+ // Keep ordinary Float32 coordinates on the hardware float path.
41
+ if (value >= -2147483648.0f && value < 2147483520.0f)
42
+ return static_cast<std::int64_t>(static_cast<std::int32_t>(
43
+ truncate ? std::trunc(value) : std::round(value)));
44
+ }
45
+ return static_cast<std::int64_t>(
46
+ std::clamp(truncate ? std::trunc(static_cast<double>(value))
47
+ : std::round(static_cast<double>(value)),
48
+ -2147483648.0, 4294967295.0));
49
+ } else {
50
+ return static_cast<std::int64_t>(container[index]);
51
+ }
52
+ }) {}
53
+
54
+ std::size_t size() const { return size_; }
55
+
56
+ std::int64_t operator[](std::size_t index) const { return read_(source_, index, false); }
57
+
58
+ // Integer order and packed RGBA values retain integer conversion semantics.
59
+ std::int64_t truncated(std::size_t index) const { return read_(source_, index, true); }
60
+
61
+ private:
62
+ const void *source_;
63
+ std::size_t size_;
64
+ std::int64_t (*read_)(const void *, std::size_t, bool);
65
+ };
66
+
14
67
  struct CanvasPerfStats {
15
68
  std::int64_t canvasLookupUs = 0;
16
69
  std::int64_t markDirtyUs = 0;
@@ -51,6 +104,7 @@ enum class CanvasPresentCommandType : std::uint8_t {
51
104
  };
52
105
 
53
106
  struct CanvasPresentCommand {
107
+ gea::framework::graphics::ImageReference imageReference;
54
108
  CanvasPresentCommandType type = CanvasPresentCommandType::Clear;
55
109
  gea::framework::graphics::pixel::native_t clearColor = 0;
56
110
  gea::framework::graphics::pixel::native_t color = 0;
@@ -87,6 +141,53 @@ void canvasPerfStatsReset();
87
141
  CanvasPerfStats canvasPerfStatsRead();
88
142
  void canvasTotalsRead(int *begin, int *end, int *fillRect, int *drawImage, int *nullPixels, int *presentOk);
89
143
 
144
+ // Everything a 2D context carries between calls: the open batch and its
145
+ // recorded commands, styles, the current path. One per canvas, shared by every
146
+ // CanvasRenderingContext2D for it -- `getContext('2d')` hands back the same
147
+ // object each time, so a context passed to a helper (a by-value copy in
148
+ // generated code) must draw into, and style, the same batch as the original.
149
+ struct CanvasContextState {
150
+ std::uint32_t identity_ = 0;
151
+ std::shared_ptr<gea::framework::display_present::Frame> retainedFrame_;
152
+ std::shared_ptr<gea::framework::display_present::Frame> pendingRetainedFrame_;
153
+ int retainedWidth_ = 0;
154
+ int retainedHeight_ = 0;
155
+ int retainedDamageX0_ = 0, retainedDamageY0_ = 0;
156
+ int retainedDamageX1_ = -1, retainedDamageY1_ = -1;
157
+ bool retainedBatchChanged_ = false;
158
+ gea::framework::graphics::Canvas *batchCanvas_ = nullptr;
159
+ std::vector<CanvasPresentCommand> presentCommands_;
160
+ std::size_t presentCommandCount_ = 0;
161
+ gea::framework::graphics::pixel::native_t fillStyle_ = gea::framework::graphics::pixel::nativeColor(255, 255, 255);
162
+ gea::framework::graphics::pixel::native_t strokeStyle_ = gea::framework::graphics::pixel::nativeColor(255, 255, 255);
163
+ std::string fillStyleSource_;
164
+ std::string strokeStyleSource_;
165
+ double arcX_ = 0.0;
166
+ double arcY_ = 0.0;
167
+ double arcRadius_ = 0.0;
168
+ std::vector<double> pathX_;
169
+ std::vector<double> pathY_;
170
+ // Start index in pathX_/pathY_ of each subpath (one per moveTo), so a path
171
+ // can hold MULTIPLE rings/contours — required for concave polygons with
172
+ // holes (even-odd fill) and multi-part strokes.
173
+ std::vector<int> pathStarts_;
174
+ double lineWidth_ = 1.0;
175
+ float fontScale_ = 1.0f;
176
+ int fontFamilyId_ = -1;
177
+ int fontSizePx_ = 16;
178
+ // Cache the last CSS font string so setFont can skip the parse + FontRegistry
179
+ // lookups when an app re-sets the same font every frame (e.g. an FPS readout).
180
+ std::string lastFontStr_;
181
+ std::uint8_t globalAlpha_ = 255;
182
+ int batchDepth_ = 0;
183
+ bool fillStyleCached_ = false;
184
+ bool strokeStyleCached_ = false;
185
+ bool hasArc_ = false;
186
+ bool pathClosed_ = false;
187
+ bool presentRecording_ = false;
188
+ bool batchDirty_ = false;
189
+ };
190
+
90
191
  class CanvasRenderingContext2D {
91
192
  public:
92
193
  // A non-explicit default ctor is required so this type can be a by-value
@@ -95,8 +196,17 @@ public:
95
196
  // which copy-`{}`-initializes each field — and copy-init cannot select an
96
197
  // `explicit` constructor. `explicit` is kept on the int form so a bare
97
198
  // `int` still can't implicitly convert to a context.
98
- CanvasRenderingContext2D() : nodeId_(-1) {}
99
- explicit CanvasRenderingContext2D(int nodeId) : nodeId_(nodeId) {}
199
+ CanvasRenderingContext2D() : nodeId_(-1), state_(stateFor(-1)) {}
200
+ explicit CanvasRenderingContext2D(int nodeId) : nodeId_(nodeId), state_(stateFor(nodeId)) {}
201
+ // The shared state of canvas `nodeId`; -1 is the direct-canvas display.
202
+ static std::shared_ptr<CanvasContextState> stateFor(int nodeId);
203
+ // Drops canvas `nodeId`'s state, so a node id reused later starts clean.
204
+ static void releaseState(int nodeId);
205
+ static void materializeRetainedCanvas(int nodeId);
206
+ static bool replayRetainedCanvas(int nodeId, std::uint32_t identity, int x, int y, int width, int height);
207
+ static bool hasRetainedCanvas(int nodeId);
208
+ static bool retainedCanvasDamage(int nodeId, int &x0, int &y0, int &x1, int &y1);
209
+ static void clearRetainedCanvasDamage();
100
210
 
101
211
  bool valid() const { return nodeId_ >= 0; }
102
212
  // The absence state `valid()` already answers, in the spelling a test uses.
@@ -178,14 +288,14 @@ public:
178
288
  // 0xRRGGBBAA app values (converted to native pixels during packing). This
179
289
  // replaces per-triangle fillTriangleRgb565 calls whose per-command record +
180
290
  // replay dispatch dominated at a few hundred triangles per frame.
181
- void fillTrianglesRgb565Sorted(const std::vector<std::int32_t> &x0s,
182
- const std::vector<std::int32_t> &y0s,
183
- const std::vector<std::int32_t> &x1s,
184
- const std::vector<std::int32_t> &y1s,
185
- const std::vector<std::int32_t> &x2s,
186
- const std::vector<std::int32_t> &y2s,
187
- const std::vector<std::uint32_t> &colors,
188
- const std::vector<std::int32_t> &order,
291
+ void fillTrianglesRgb565Sorted(const CanvasNumericArrayView &x0s,
292
+ const CanvasNumericArrayView &y0s,
293
+ const CanvasNumericArrayView &x1s,
294
+ const CanvasNumericArrayView &y1s,
295
+ const CanvasNumericArrayView &x2s,
296
+ const CanvasNumericArrayView &y2s,
297
+ const CanvasNumericArrayView &colors,
298
+ const CanvasNumericArrayView &order,
189
299
  int count);
190
300
  void beginPath();
191
301
  void arc(double x, double y, double radius, double startAngle, double endAngle);
@@ -197,6 +307,14 @@ public:
197
307
  void fillText(const std::string &text, int x, int y);
198
308
  void fillText(const std::string &text, double x, double y);
199
309
  void drawImage(int imageId, int dx, int dy);
310
+ // drawImage at full opacity whatever globalAlpha is: putImageData.
311
+ void putImage(int imageId, int dx, int dy);
312
+ // Draws `height` rows of `width` opaque pixels, row r read from
313
+ // `pixels + r * stride`, at (dx, dy). The rows must stay valid until the
314
+ // frame is presented: they are recorded, not copied. This is a sub-rectangle
315
+ // of a larger buffer -- putImageData's dirty rectangle -- without a copy.
316
+ // Like putImageData, it ignores globalAlpha.
317
+ void drawPixelRows(const gea::framework::graphics::pixel::native_t *pixels, int stride, int width, int height, int dx, int dy);
200
318
  void drawImage(int imageId, double dx, double dy);
201
319
  void drawImage(int imageId, int dx, int dy, int dw, int dh);
202
320
  void drawImage(int imageId, double dx, double dy, double dw, double dh);
@@ -225,6 +343,9 @@ private:
225
343
  gea::framework::graphics::Canvas *canvas();
226
344
  gea::framework::graphics::Canvas *drawingCanvas();
227
345
  bool recordingPresentBatch() const;
346
+ void prepareBitmapOnlyDraw();
347
+ bool retainNumericBatch();
348
+ std::vector<gea::platform::display::DisplayPresentCommand> displayPresentCommands() const;
228
349
  void appendPresentClear(gea::framework::graphics::pixel::native_t color);
229
350
  void appendPresentFillRect(int x, int y, int w, int h, gea::framework::graphics::pixel::native_t color);
230
351
  void appendPresentStrokeRect(int x, int y, int w, int h, gea::framework::graphics::pixel::native_t color);
@@ -261,14 +382,14 @@ private:
261
382
  const std::vector<std::uint16_t> &ys,
262
383
  int radius,
263
384
  gea::framework::graphics::pixel::native_t color);
264
- void appendPresentTriangles(const std::vector<std::int32_t> &x0s,
265
- const std::vector<std::int32_t> &y0s,
266
- const std::vector<std::int32_t> &x1s,
267
- const std::vector<std::int32_t> &y1s,
268
- const std::vector<std::int32_t> &x2s,
269
- const std::vector<std::int32_t> &y2s,
270
- const std::vector<std::uint32_t> &colors,
271
- const std::vector<std::int32_t> &order,
385
+ void appendPresentTriangles(const CanvasNumericArrayView &x0s,
386
+ const CanvasNumericArrayView &y0s,
387
+ const CanvasNumericArrayView &x1s,
388
+ const CanvasNumericArrayView &y1s,
389
+ const CanvasNumericArrayView &x2s,
390
+ const CanvasNumericArrayView &y2s,
391
+ const CanvasNumericArrayView &colors,
392
+ const CanvasNumericArrayView &order,
272
393
  int count);
273
394
  void appendPresentDrawImage(const gea::framework::graphics::pixel::native_t *pixels,
274
395
  const std::uint8_t *alphaPixels,
@@ -310,37 +431,7 @@ private:
310
431
  void markDrawDirty();
311
432
 
312
433
  int nodeId_;
313
- gea::framework::graphics::Canvas *batchCanvas_ = nullptr;
314
- std::vector<CanvasPresentCommand> presentCommands_;
315
- std::size_t presentCommandCount_ = 0;
316
- gea::framework::graphics::pixel::native_t fillStyle_ = gea::framework::graphics::pixel::nativeColor(255, 255, 255);
317
- gea::framework::graphics::pixel::native_t strokeStyle_ = gea::framework::graphics::pixel::nativeColor(255, 255, 255);
318
- std::string fillStyleSource_;
319
- std::string strokeStyleSource_;
320
- double arcX_ = 0.0;
321
- double arcY_ = 0.0;
322
- double arcRadius_ = 0.0;
323
- std::vector<double> pathX_;
324
- std::vector<double> pathY_;
325
- // Start index in pathX_/pathY_ of each subpath (one per moveTo), so a path
326
- // can hold MULTIPLE rings/contours — required for concave polygons with
327
- // holes (even-odd fill) and multi-part strokes.
328
- std::vector<int> pathStarts_;
329
- double lineWidth_ = 1.0;
330
- float fontScale_ = 1.0f;
331
- int fontFamilyId_ = -1;
332
- int fontSizePx_ = 16;
333
- // Cache the last CSS font string so setFont can skip the parse + FontRegistry
334
- // lookups when an app re-sets the same font every frame (e.g. an FPS readout).
335
- std::string lastFontStr_;
336
- std::uint8_t globalAlpha_ = 255;
337
- int batchDepth_ = 0;
338
- bool fillStyleCached_ = false;
339
- bool strokeStyleCached_ = false;
340
- bool hasArc_ = false;
341
- bool pathClosed_ = false;
342
- bool presentRecording_ = false;
343
- bool batchDirty_ = false;
434
+ std::shared_ptr<CanvasContextState> state_;
344
435
  };
345
436
 
346
437
  class CanvasElement : public NodeHandle {
package/ui/core.cpp CHANGED
@@ -39,6 +39,7 @@ void Tree::markNodeDisplayCommandsDirty(int node)
39
39
  if (node < 0 || node >= kMaxNodes) return;
40
40
  GEA_REFRESH_PERF(refreshPerfStatsMutable().treeMarkNodeCommandDirtyCalls++);
41
41
  auto &state = treeState();
42
+ if (node < state.nodeCount) state.nodes[node].render.canvas_pixels_only_dirty = 0;
42
43
  state.nodeCommandDirty[node] = 1;
43
44
  const int root = state.mountedRoot;
44
45
  if (root >= 0 && root < state.nodeCount && node < state.nodeCount && isDocumentCanvasRoot(state.nodes[root]) &&
@@ -0,0 +1,80 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+
4
+ // Debug builds only. JSX listeners are delegated to the body, so DevTools
5
+ // cannot learn which node a handler belongs to from the event system. The
6
+ // runtime names the node through GEA_JSX_NODE_LISTENER_HOOK; this records the
7
+ // event type and the registering call stack so the host can link each handler
8
+ // to the TSX line that attached it.
9
+ #if defined(ESP_PLATFORM) && defined(GEA_NATIVE_DEBUGGER) && GEA_NATIVE_DEBUGGER
10
+ #include "tree_state.h"
11
+ #include <cstdint>
12
+ #include <string>
13
+ #include <unordered_map>
14
+ #include <unordered_set>
15
+ #include <vector>
16
+ #if defined(__XTENSA__)
17
+ #include "esp_cpu_utils.h"
18
+ #include "esp_debug_helpers.h"
19
+ #endif
20
+
21
+ namespace gea::embedded::ui {
22
+ struct DebuggerListener {
23
+ // Registration passes through runtime helpers whose depth varies with
24
+ // inlining; the host picks the first frame that maps to app source.
25
+ static constexpr int kSites = 6;
26
+ std::string type;
27
+ std::uint32_t sites[kSites] = {};
28
+ int count = 0;
29
+ };
30
+ // Keyed by lifetime identity, never by slot: a recycled slot must not inherit
31
+ // the previous node's handlers. Owned by the app/render lock.
32
+ inline std::unordered_map<std::uint32_t, std::vector<DebuggerListener>> &debuggerListeners() {
33
+ static std::unordered_map<std::uint32_t, std::vector<DebuggerListener>> listeners;
34
+ return listeners;
35
+ }
36
+ // Drop registrations of nodes that no longer exist so list churn cannot grow
37
+ // the registry without bound while no debugger is connected.
38
+ inline void debuggerPruneListeners() {
39
+ auto &state = treeState();
40
+ std::unordered_set<std::uint32_t> live;
41
+ for (int i = 0; i < kMaxNodes; ++i)
42
+ if (state.nodeActive[i])
43
+ live.insert(state.nodes[i].debugger_identity);
44
+ auto &listeners = debuggerListeners();
45
+ for (auto it = listeners.begin(); it != listeners.end();)
46
+ it = live.count(it->first) ? std::next(it) : listeners.erase(it);
47
+ }
48
+ // Not inlined: the backtrace starts at this function's caller.
49
+ [[gnu::noinline]] inline void debuggerNoteListener(int slot, const char *type) {
50
+ auto &state = treeState();
51
+ if (slot < 0 || slot >= kMaxNodes || !state.nodeActive[slot] || !type)
52
+ return;
53
+ DebuggerListener listener;
54
+ listener.type = type;
55
+ #if defined(__XTENSA__)
56
+ esp_backtrace_frame_t frame = {};
57
+ esp_backtrace_get_start(&frame.pc, &frame.sp, &frame.next_pc);
58
+ while (listener.count < DebuggerListener::kSites) {
59
+ // The call instruction itself, not the return address after it.
60
+ listener.sites[listener.count++] = esp_cpu_process_stack_pc(frame.pc);
61
+ if (!frame.next_pc || !esp_backtrace_get_next_frame(&frame))
62
+ break;
63
+ }
64
+ #else
65
+ listener.sites[listener.count++] =
66
+ std::uint32_t(reinterpret_cast<std::uintptr_t>(__builtin_return_address(0)));
67
+ #endif
68
+ static unsigned notes = 0;
69
+ if (++notes % 128 == 0)
70
+ debuggerPruneListeners();
71
+ auto &list = debuggerListeners()[state.nodes[slot].debugger_identity];
72
+ if (list.size() < 16)
73
+ list.push_back(std::move(listener));
74
+ }
75
+ } // namespace gea::embedded::ui
76
+
77
+ #ifndef GEA_JSX_NODE_LISTENER_HOOK
78
+ #define GEA_JSX_NODE_LISTENER_HOOK(node, type) ::gea::embedded::ui::debuggerNoteListener((node), (type))
79
+ #endif
80
+ #endif
@@ -0,0 +1,79 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+
4
+ #if defined(GEA_NATIVE_DEBUGGER) && GEA_NATIVE_DEBUGGER
5
+ #include "internal.h"
6
+ #include "tree_internal.h"
7
+ #include "tree_state.h"
8
+ #include <algorithm>
9
+ #include <cstdint>
10
+
11
+ namespace gea::embedded::ui {
12
+ // Owned by the app/render lock. A lease clears the overlay even if the host dies.
13
+ struct DebuggerOverlay {
14
+ int slot = -1;
15
+ std::uint32_t identity = 0;
16
+ std::int64_t deadline = 0;
17
+ bool repaint = false;
18
+ gea::framework::graphics::pixel::native_t color = 0;
19
+
20
+ void prepare() const {
21
+ auto &state = treeState();
22
+ if ((slot >= 0 || repaint) && state.mountedRoot >= 0) {
23
+ // Overlay commands are separate from node paint ranges. Re-record while
24
+ // visible so incremental, fused and banded replay all see current bounds.
25
+ state.displayListDirty = true;
26
+ state.displayListRebuildStructural = true;
27
+ state.nodes[state.mountedRoot].render.dirty = true;
28
+ }
29
+ }
30
+ void set(int node, gea::framework::graphics::pixel::native_t outline) {
31
+ slot = node;
32
+ identity = node >= 0 ? treeState().nodes[node].debugger_identity : 0;
33
+ color = outline;
34
+ deadline = std::int64_t(treeState().lastFrameMs) + 2500;
35
+ repaint = true;
36
+ prepare();
37
+ }
38
+ void record(int root, int width, int height) {
39
+ auto &state = treeState();
40
+ repaint = false;
41
+ if (slot < 0) return;
42
+ if (slot >= state.nodeCount || !state.nodeActive[slot] ||
43
+ state.nodes[slot].debugger_identity != identity ||
44
+ std::int64_t(state.lastFrameMs) >= deadline ||
45
+ !Tree::instance().containsNode(root, slot)) {
46
+ slot = -1;
47
+ identity = 0;
48
+ return;
49
+ }
50
+ for (int parent = slot; parent >= 0; parent = state.nodes[parent].parent)
51
+ if (state.nodes[parent].computedStyle().display == kDisplayNone) return;
52
+ int16_t xs[4], ys[4];
53
+ ViewRenderer::transformedCorners(state.nodes[slot], false, xs, ys);
54
+ int x0 = *std::min_element(xs, xs + 4), y0 = *std::min_element(ys, ys + 4);
55
+ int x1 = *std::max_element(xs, xs + 4), y1 = *std::max_element(ys, ys + 4);
56
+ if (x1 <= x0 || y1 <= y0) return;
57
+ auto fill = [&](int x, int y, int w, int h) {
58
+ const int right = std::min(width, x + w), bottom = std::min(height, y + h);
59
+ x = std::max(0, x); y = std::max(0, y);
60
+ w = right - x; h = bottom - y;
61
+ if (w <= 0 || h <= 0) return;
62
+ if (auto *command = DisplayList::instance().append()) {
63
+ command->type = DisplayCommandType::FillRect;
64
+ command->bx = command->fill.x = x;
65
+ command->by = command->fill.y = y;
66
+ command->bw = command->fill.w = w;
67
+ command->bh = command->fill.h = h;
68
+ command->fill.color = color;
69
+ }
70
+ };
71
+ fill(x0, y0, x1 - x0, 2);
72
+ fill(x0, y1 - 2, x1 - x0, 2);
73
+ fill(x0, y0, 2, y1 - y0);
74
+ fill(x1 - 2, y0, 2, y1 - y0);
75
+ }
76
+ };
77
+ inline DebuggerOverlay debuggerOverlay;
78
+ } // namespace gea::embedded::ui
79
+ #endif
@@ -0,0 +1,105 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+
4
+ #if defined(GEA_NATIVE_DEBUGGER) && GEA_NATIVE_DEBUGGER
5
+ #include "debugger_overlay.h"
6
+ #include "events.h"
7
+ #include "event.h"
8
+ #include "services/frame_scheduler.h"
9
+
10
+ namespace gea::embedded::ui {
11
+ // Shared by every retained-tree target. Calls run under the app/render lock;
12
+ // transports own a token and renew its lease while their inspector is connected.
13
+ struct DebuggerPicker {
14
+ unsigned token = 0, revision = 0;
15
+ bool active = false;
16
+ std::int64_t deadline = 0;
17
+ std::uint32_t held = 0;
18
+ int hovered = -1, selected = -1;
19
+ unsigned hoverIdentity = 0, selectedIdentity = 0;
20
+
21
+ static int now() { return gea::framework::services::FrameScheduler::nowMs(); }
22
+ static int identity(int slot, unsigned lifetime) {
23
+ auto &state = treeState();
24
+ return slot >= 0 && slot < state.nodeCount && state.nodeActive[slot] &&
25
+ state.nodes[slot].debugger_identity == lifetime &&
26
+ Tree::instance().containsNode(state.mountedRoot, slot)
27
+ ? int(lifetime * 2 + 2) : 0;
28
+ }
29
+ int hoverId() const { return identity(hovered, hoverIdentity); }
30
+ int selectedId() const { return identity(selected, selectedIdentity); }
31
+ void expire() {
32
+ if (active && std::int64_t(now()) >= deadline) cancel(token);
33
+ }
34
+ void outline(int slot) {
35
+ debuggerOverlay.set(slot, gea::framework::graphics::pixel::nativeColor(0, 200, 255));
36
+ debuggerOverlay.deadline = std::int64_t(now()) + 2500;
37
+ }
38
+ void begin(unsigned owner) {
39
+ expire();
40
+ if (token == owner) return; // A delayed renewal must never rearm a picked node.
41
+ token = owner;
42
+ active = true;
43
+ selected = hovered = -1;
44
+ selectedIdentity = hoverIdentity = 0;
45
+ deadline = std::int64_t(now()) + 2500;
46
+ Tree::instance().resetInput();
47
+ gea::framework::events::TouchRuntime::resetGestureState();
48
+ outline(-1);
49
+ }
50
+ void renew(unsigned owner) {
51
+ expire();
52
+ if (token == owner && active) {
53
+ deadline = std::int64_t(now()) + 2500;
54
+ if (hoverId()) outline(hovered);
55
+ }
56
+ }
57
+ void cancel(unsigned owner) {
58
+ if (token != owner) return;
59
+ active = false;
60
+ selected = hovered = -1;
61
+ selectedIdentity = hoverIdentity = 0;
62
+ outline(-1);
63
+ // Keep captured fingers until release, including cancellation mid-gesture.
64
+ }
65
+ bool point(unsigned owner, int x, int y, bool select) {
66
+ expire();
67
+ if (!active || owner != token) return false;
68
+ hovered = Tree::instance().hitTestNode(x, y);
69
+ hoverIdentity = hovered >= 0 ? treeState().nodes[hovered].debugger_identity : 0;
70
+ outline(hovered);
71
+ if (select && hoverId()) {
72
+ selected = hovered;
73
+ selectedIdentity = hoverIdentity;
74
+ ++revision;
75
+ active = false;
76
+ }
77
+ return true;
78
+ }
79
+ bool capturesInput() { expire(); return active || held; }
80
+ bool consume(gea::framework::events::TouchPhase phase, int x, int y, int pointer) {
81
+ using gea::framework::events::TouchPhase;
82
+ // capturesInput() has already expired the lease before coordinates are
83
+ // consumed. Do not switch routing after resolving the primary move cache.
84
+ // Hardware controllers use IDs 0..9. Keep a bounded mask, even for a
85
+ // malformed target event; never let inspection leak an application gesture.
86
+ const unsigned bit = 1u << unsigned(pointer >= 0 && pointer < 32 ? pointer : 31);
87
+ if (phase == TouchPhase::Down) {
88
+ held &= ~bit; // Recover a missing release on the next fresh press.
89
+ if (!active && !held) return false;
90
+ held |= bit;
91
+ if (active) point(token, x, y, true);
92
+ return true;
93
+ }
94
+ if (!active && !held) return false;
95
+ if (phase == TouchPhase::Up) held &= ~bit;
96
+ else {
97
+ held |= bit;
98
+ if (active) point(token, x, y, false);
99
+ }
100
+ return true;
101
+ }
102
+ };
103
+ inline DebuggerPicker debuggerPicker;
104
+ } // namespace gea::embedded::ui
105
+ #endif
package/ui/document.cpp CHANGED
@@ -355,7 +355,7 @@ void Document::addEventListener(const char *type, gea::framework::events::EventL
355
355
  // `rotary` (and `keydown` bound on a non-input) is a genuine document-level
356
356
  // event — it has no element target, so it is stored off-tree as a singleton
357
357
  // and dispatched directly by the runtime, never bound to a node.
358
- if (std::strcmp(type, "rotary") == 0 || std::strcmp(type, "keydown") == 0) {
358
+ if (std::strcmp(type, "rotary") == 0 || std::strcmp(type, "keydown") == 0 || std::strcmp(type, "keyup") == 0) {
359
359
  setDocumentEventListener(type, std::move(listener));
360
360
  return;
361
361
  }
package/ui/image_node.cpp CHANGED
@@ -3,6 +3,7 @@
3
3
  #include "image.h"
4
4
 
5
5
  #include <image.h>
6
+ #include <algorithm>
6
7
 
7
8
  namespace gea::embedded::ui {
8
9
 
@@ -135,11 +136,41 @@ void ImageRenderer::record(const Node &node)
135
136
  if (iw <= 0 || ih <= 0) return;
136
137
 
137
138
  ImageFitRect fit = ImageFitResolver::resolve(*n, iw, ih);
138
- applyAxisAlignedTransform(*n, fit);
139
+ if (!applyAxisAlignedTransform(*n, fit)) {
140
+ DisplayCommand *cmd = DisplayList::instance().append();
141
+ if (!cmd) return;
142
+ DisplayList::instance().retainImage(n->image_id);
143
+ cmd->type = DisplayCommandType::BlitImageProjected;
144
+ auto &image = cmd->projectedBlit;
145
+ image.pixels = pixels;
146
+ image.alpha = alpha;
147
+ image.sourceWidth = iw;
148
+ image.sourceHeight = ih;
149
+ image.x = fit.x;
150
+ image.y = fit.y;
151
+ image.width = fit.width;
152
+ image.height = fit.height;
153
+ image.tl = n->computedStyle().border_radius[GEA_CSS_RADIUS_INDEX(0)];
154
+ image.tr = n->computedStyle().border_radius[GEA_CSS_RADIUS_INDEX(1)];
155
+ image.br = n->computedStyle().border_radius[GEA_CSS_RADIUS_INDEX(2)];
156
+ image.bl = n->computedStyle().border_radius[GEA_CSS_RADIUS_INDEX(3)];
157
+ image.backfaceHidden = n->computedStyle().backface_hidden;
158
+ ViewRenderer::transformedRectCorners(*n, false, fit.x, fit.y, fit.width, fit.height, image.xs, image.ys);
159
+ int x0 = image.xs[0], x1 = x0, y0 = image.ys[0], y1 = y0;
160
+ for (int corner = 1; corner < 4; ++corner) {
161
+ x0 = std::min(x0, int(image.xs[corner]));
162
+ x1 = std::max(x1, int(image.xs[corner]));
163
+ y0 = std::min(y0, int(image.ys[corner]));
164
+ y1 = std::max(y1, int(image.ys[corner]));
165
+ }
166
+ cmd->bx = x0; cmd->by = y0; cmd->bw = x1 - x0; cmd->bh = y1 - y0;
167
+ return;
168
+ }
139
169
 
140
170
  if (iw == fit.width && ih == fit.height && !hasImageRadius(*n)) {
141
171
  DisplayCommand *cmd = DisplayList::instance().append();
142
172
  if (!cmd) return;
173
+ DisplayList::instance().retainImage(n->image_id);
143
174
  cmd->type = DisplayCommandType::BlitImage;
144
175
  cmd->bx = fit.x; cmd->by = fit.y; cmd->bw = fit.width; cmd->bh = fit.height;
145
176
  cmd->blit.pixels = pixels;
@@ -154,6 +185,7 @@ void ImageRenderer::record(const Node &node)
154
185
 
155
186
  DisplayCommand *cmd = DisplayList::instance().append();
156
187
  if (!cmd) return;
188
+ DisplayList::instance().retainImage(n->image_id);
157
189
  cmd->type = DisplayCommandType::BlitImageScaled;
158
190
  cmd->bx = fit.x; cmd->by = fit.y; cmd->bw = fit.width; cmd->bh = fit.height;
159
191
  cmd->scaledBlit.pixels = pixels;
package/ui/input.cpp CHANGED
@@ -13,6 +13,27 @@
13
13
  #include <cstdlib>
14
14
  #include <cstring>
15
15
 
16
+ // Applications with short canvases can tune native momentum without replacing
17
+ // the engine gesture/scroll path. Defaults retain the existing long-list feel.
18
+ #ifndef GEA_SCROLL_MOMENTUM_LAUNCH_BOOST
19
+ #define GEA_SCROLL_MOMENTUM_LAUNCH_BOOST 1.45f
20
+ #endif
21
+ #ifndef GEA_SCROLL_MOMENTUM_CARRY_BOOST
22
+ #define GEA_SCROLL_MOMENTUM_CARRY_BOOST 2.0f
23
+ #endif
24
+ #ifndef GEA_SCROLL_MOMENTUM_MAX_VELOCITY
25
+ #define GEA_SCROLL_MOMENTUM_MAX_VELOCITY 24.0f
26
+ #endif
27
+ #ifndef GEA_SCROLL_MOMENTUM_MIN_VELOCITY
28
+ #define GEA_SCROLL_MOMENTUM_MIN_VELOCITY 0.06f
29
+ #endif
30
+ #ifndef GEA_SCROLL_MOMENTUM_DECAY_MS
31
+ #define GEA_SCROLL_MOMENTUM_DECAY_MS 680.0f
32
+ #endif
33
+ #ifndef GEA_SCROLL_MOMENTUM_STOP_VELOCITY
34
+ #define GEA_SCROLL_MOMENTUM_STOP_VELOCITY 0.012f
35
+ #endif
36
+
16
37
  namespace gea::embedded::ui {
17
38
 
18
39
  namespace {
@@ -802,12 +823,12 @@ private:
802
823
  int y;
803
824
  };
804
825
  static constexpr int kVelocitySampleCount = 5;
805
- static constexpr float kLaunchVelocityBoost = 1.45f;
806
- static constexpr float kCarryOverBoost = 2.0f;
807
- static constexpr float kMaxMomentumVelocity = 24.0f; // px/ms = 24000 px/s
808
- static constexpr float kMinFlingVelocity = 0.06f; // px/ms = 60 px/s
809
- static constexpr float kMomentumDecayMs = 680.0f;
810
- static constexpr float kStopVelocity = 0.012f; // px/ms = 12 px/s
826
+ static constexpr float kLaunchVelocityBoost = GEA_SCROLL_MOMENTUM_LAUNCH_BOOST;
827
+ static constexpr float kCarryOverBoost = GEA_SCROLL_MOMENTUM_CARRY_BOOST;
828
+ static constexpr float kMaxMomentumVelocity = GEA_SCROLL_MOMENTUM_MAX_VELOCITY; // px/ms
829
+ static constexpr float kMinFlingVelocity = GEA_SCROLL_MOMENTUM_MIN_VELOCITY; // px/ms
830
+ static constexpr float kMomentumDecayMs = GEA_SCROLL_MOMENTUM_DECAY_MS;
831
+ static constexpr float kStopVelocity = GEA_SCROLL_MOMENTUM_STOP_VELOCITY; // px/ms
811
832
 
812
833
  int activeTouchNode_ = -1;
813
834
  std::uint16_t savedBackgroundColor_ = 0;