@geastack/engine 0.1.15 → 0.1.17

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.
@@ -2,8 +2,13 @@
2
2
  #pragma once
3
3
 
4
4
  #include <memory>
5
+ #include <algorithm>
6
+ #include <cmath>
7
+ #include <type_traits>
5
8
 
6
9
  #include "canvas.h"
10
+ #include <image.h>
11
+ #include "display.h"
7
12
  #include "node.h"
8
13
 
9
14
  #include <cstdint>
@@ -11,8 +16,54 @@
11
16
  #include <string>
12
17
  #include <vector>
13
18
 
19
+ namespace gea::framework::display_present { struct Frame; }
20
+
14
21
  namespace gea::embedded::ui {
15
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
+
16
67
  struct CanvasPerfStats {
17
68
  std::int64_t canvasLookupUs = 0;
18
69
  std::int64_t markDirtyUs = 0;
@@ -53,6 +104,7 @@ enum class CanvasPresentCommandType : std::uint8_t {
53
104
  };
54
105
 
55
106
  struct CanvasPresentCommand {
107
+ gea::framework::graphics::ImageReference imageReference;
56
108
  CanvasPresentCommandType type = CanvasPresentCommandType::Clear;
57
109
  gea::framework::graphics::pixel::native_t clearColor = 0;
58
110
  gea::framework::graphics::pixel::native_t color = 0;
@@ -95,6 +147,14 @@ void canvasTotalsRead(int *begin, int *end, int *fillRect, int *drawImage, int *
95
147
  // object each time, so a context passed to a helper (a by-value copy in
96
148
  // generated code) must draw into, and style, the same batch as the original.
97
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;
98
158
  gea::framework::graphics::Canvas *batchCanvas_ = nullptr;
99
159
  std::vector<CanvasPresentCommand> presentCommands_;
100
160
  std::size_t presentCommandCount_ = 0;
@@ -142,6 +202,11 @@ public:
142
202
  static std::shared_ptr<CanvasContextState> stateFor(int nodeId);
143
203
  // Drops canvas `nodeId`'s state, so a node id reused later starts clean.
144
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();
145
210
 
146
211
  bool valid() const { return nodeId_ >= 0; }
147
212
  // The absence state `valid()` already answers, in the spelling a test uses.
@@ -223,14 +288,14 @@ public:
223
288
  // 0xRRGGBBAA app values (converted to native pixels during packing). This
224
289
  // replaces per-triangle fillTriangleRgb565 calls whose per-command record +
225
290
  // replay dispatch dominated at a few hundred triangles per frame.
226
- void fillTrianglesRgb565Sorted(const std::vector<std::int32_t> &x0s,
227
- const std::vector<std::int32_t> &y0s,
228
- const std::vector<std::int32_t> &x1s,
229
- const std::vector<std::int32_t> &y1s,
230
- const std::vector<std::int32_t> &x2s,
231
- const std::vector<std::int32_t> &y2s,
232
- const std::vector<std::uint32_t> &colors,
233
- 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,
234
299
  int count);
235
300
  void beginPath();
236
301
  void arc(double x, double y, double radius, double startAngle, double endAngle);
@@ -278,6 +343,9 @@ private:
278
343
  gea::framework::graphics::Canvas *canvas();
279
344
  gea::framework::graphics::Canvas *drawingCanvas();
280
345
  bool recordingPresentBatch() const;
346
+ void prepareBitmapOnlyDraw();
347
+ bool retainNumericBatch();
348
+ std::vector<gea::platform::display::DisplayPresentCommand> displayPresentCommands() const;
281
349
  void appendPresentClear(gea::framework::graphics::pixel::native_t color);
282
350
  void appendPresentFillRect(int x, int y, int w, int h, gea::framework::graphics::pixel::native_t color);
283
351
  void appendPresentStrokeRect(int x, int y, int w, int h, gea::framework::graphics::pixel::native_t color);
@@ -314,14 +382,14 @@ private:
314
382
  const std::vector<std::uint16_t> &ys,
315
383
  int radius,
316
384
  gea::framework::graphics::pixel::native_t color);
317
- void appendPresentTriangles(const std::vector<std::int32_t> &x0s,
318
- const std::vector<std::int32_t> &y0s,
319
- const std::vector<std::int32_t> &x1s,
320
- const std::vector<std::int32_t> &y1s,
321
- const std::vector<std::int32_t> &x2s,
322
- const std::vector<std::int32_t> &y2s,
323
- const std::vector<std::uint32_t> &colors,
324
- 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,
325
393
  int count);
326
394
  void appendPresentDrawImage(const gea::framework::graphics::pixel::native_t *pixels,
327
395
  const std::uint8_t *alphaPixels,
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
@@ -150,6 +150,7 @@ NodeHandle Document::createElement(const char *tag) const
150
150
  NodeHandle node;
151
151
  if (lowered == "button") node = createButton();
152
152
  else if (lowered == "canvas") node = createCanvas();
153
+ else if (lowered == "camera") node = createCamera();
153
154
  else if (lowered == "audio") node = createAudio();
154
155
  else if (lowered == "img" || lowered == "image" || lowered == "video") node = createImage();
155
156
  else if (lowered == "virtual-list") node = createVirtualList();
@@ -355,7 +356,7 @@ void Document::addEventListener(const char *type, gea::framework::events::EventL
355
356
  // `rotary` (and `keydown` bound on a non-input) is a genuine document-level
356
357
  // event — it has no element target, so it is stored off-tree as a singleton
357
358
  // and dispatched directly by the runtime, never bound to a node.
358
- if (std::strcmp(type, "rotary") == 0 || std::strcmp(type, "keydown") == 0) {
359
+ if (std::strcmp(type, "rotary") == 0 || std::strcmp(type, "keydown") == 0 || std::strcmp(type, "keyup") == 0) {
359
360
  setDocumentEventListener(type, std::move(listener));
360
361
  return;
361
362
  }
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;
@@ -41,15 +41,13 @@ constexpr int kInputCaretInsetY = 6;
41
41
  // centering formula here matches the height the framework's bitmap text path
42
42
  // would draw at by default.
43
43
  constexpr int kBitmapFontHeight = gea::framework::graphics::BitmapFont8x16::kHeight;
44
- // #475569 (slate-600). Computed via packRgb565Components because the
45
- // display layer byte-swaps the wire format — a raw 0x4A69 literal would
46
- // land as BGR garbage (the "purple placeholder" symptom).
47
- inline std::uint16_t kPlaceholderColor()
44
+ // #475569 (slate-600), packed in the target native color format.
45
+ inline gea::framework::graphics::pixel::native_t kPlaceholderColor()
48
46
  {
49
- return gea::framework::graphics::pixel::packRgb565Components(71 / 8, 85 / 4, 105 / 8);
47
+ return gea::framework::graphics::pixel::nativeColor(71, 85, 105);
50
48
  }
51
49
 
52
- const char *inputContentText(int id, std::uint16_t *outColor, std::uint16_t textColor)
50
+ const char *inputContentText(int id, gea::framework::graphics::pixel::native_t *outColor, gea::framework::graphics::pixel::native_t textColor)
53
51
  {
54
52
  auto &tree = Tree::instance();
55
53
  const char *value = tree.getAttribute(id, "value");
@@ -111,7 +109,7 @@ void InputRenderer::record(int id)
111
109
  if (n.type != NodeType::View) return;
112
110
  if (std::strcmp(tagFromId(n.tag_id), "input") != 0) return;
113
111
 
114
- std::uint16_t color = n.computedStyle().text_color;
112
+ gea::framework::graphics::pixel::native_t color = n.computedStyle().text_color;
115
113
  const char *content = inputContentText(id, &color, n.computedStyle().text_color);
116
114
 
117
115
  const int x = n.layout.x;
@@ -199,7 +197,7 @@ void InputRenderer::record(int id)
199
197
  const int caretY = contentY + kInputCaretInsetY;
200
198
  int caretH = contentH - kInputCaretInsetY * 2;
201
199
  if (caretH < 4) caretH = contentH > 4 ? contentH - 2 : contentH;
202
- const std::uint16_t caretColor = n.computedStyle().text_color ? n.computedStyle().text_color : 0xFFFF;
200
+ const gea::framework::graphics::pixel::native_t caretColor = n.computedStyle().text_color ? n.computedStyle().text_color : gea::framework::graphics::pixel::nativeColor(255, 255, 255);
203
201
 
204
202
  DisplayCommand *cmd = DisplayList::instance().append();
205
203
  if (cmd) {
package/ui/internal.h CHANGED
@@ -68,6 +68,8 @@ void rootScrollImageHoldTick();
68
68
  DrawText,
69
69
  BlitImage,
70
70
  BlitImageScaled,
71
+ BlitImageProjected,
72
+ ReplayCanvasBatch,
71
73
  BeginFilterBlur,
72
74
  ApplyFilterBlur,
73
75
  FillTransformedLinearGradient,
@@ -108,6 +110,7 @@ void rootScrollImageHoldTick();
108
110
  int16_t x, y, w, h;
109
111
  gea::framework::graphics::pixel::native_t color;
110
112
  } fill;
113
+ struct { int16_t nodeId, x, y, width, height; std::uint32_t identity; } canvasBatch;
111
114
  struct
112
115
  {
113
116
  int16_t cx, cy, r;
@@ -274,6 +277,15 @@ void rootScrollImageHoldTick();
274
277
  int16_t tl, tr, br, bl;
275
278
  } scaledBlit;
276
279
  struct
280
+ {
281
+ const gea::framework::graphics::pixel::native_t *pixels;
282
+ const uint8_t *alpha;
283
+ int16_t sourceWidth, sourceHeight, x, y, width, height;
284
+ int16_t xs[4], ys[4];
285
+ int16_t tl, tr, br, bl;
286
+ uint8_t backfaceHidden;
287
+ } projectedBlit;
288
+ struct
277
289
  {
278
290
  int16_t nodeId;
279
291
  int16_t radius;
@@ -301,6 +313,8 @@ void rootScrollImageHoldTick();
301
313
  DisplayCommand *append();
302
314
  int setRecordingTextClipOwner(int owner);
303
315
  void clear();
316
+ void retainImage(int id);
317
+ void pruneImageReferences();
304
318
  void resetStorage();
305
319
  // allowSkipStatic: caller guarantees this frame will use the direct
306
320
  // (backdrop-blit) replay path, so recordNode may skip re-recording fully-static
@@ -365,6 +379,7 @@ void rootScrollImageHoldTick();
365
379
  void replayDirectDirtyRegion(int x0, int y0, int x1, int y1, int origin = -1);
366
380
  void replayDirectDirtyRegions(const DisplayReplayRegion *regions, int count);
367
381
  bool canReplaySimpleDirtyRegions(int width, int height) const;
382
+ bool canReplaySimpleDirtyRegions(int width, int height, const DisplayReplayRegion *regions, int count) const;
368
383
  void replaySimpleClippedDirtyRegion(int x0, int y0, int x1, int y1, int origin = -1);
369
384
  // Static-backdrop cache: bake every non-dirty (static) node into the bg cache
370
385
  // buffer once it's stable, so the dirty-region replay can blit that backdrop and
@@ -569,6 +584,11 @@ void rootScrollImageHoldTick();
569
584
  // keepBoxWidth re-wraps within the current layout.width (a cross-
570
585
  // stretched block's box) and only updates the height.
571
586
  static bool remeasureContentBox(int id, bool keepBoxWidth = false);
587
+ // Flex layout resized this text item's main (inline) size: re-wrap the
588
+ // run within the new layout.width and update layout.height. Returns the
589
+ // widest wrapped line's border-box width — larger than layout.width only
590
+ // when an unbreakable run overflows the box. One measurement.
591
+ static int reflowToBoxWidth(int id);
572
592
  };
573
593
 
574
594
  // Materializes `<input>` JSX elements. They emit View nodes (tag_name=="input")