@geastack/engine 0.1.22 → 0.1.24

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/engine",
3
- "version": "0.1.22",
3
+ "version": "0.1.24",
4
4
  "description": "GeaStack rendering engine, intrinsic JSX primitives, and native engine backends.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -128,7 +128,12 @@ constexpr int kRuntimeAsciiCount = kRuntimeAsciiLast - kRuntimeAsciiFirst + 1;
128
128
  constexpr int kRuntimeExtraCodepoints[] = {0x00b0,0x00b5,0x00d7,0x2013,0x2014,0x2018,0x2019,0x201c,0x201d,0x2022,0x2026,0x2190,0x2191,0x2192,0x2193,0x2212};
129
129
  constexpr int kRuntimeExtraGlyphs = sizeof(kRuntimeExtraCodepoints)/sizeof(int);
130
130
  #else
131
- constexpr int kRuntimeExtraGlyphs = 1;
131
+ // The degree sign, and the bullet a password input draws for each hidden
132
+ // character (lv_textarea's LV_TEXTAREA_PWD_BULLET_UNICODE): without it every
133
+ // masked character fell back to nothing. Kept short: each entry costs a Glyph
134
+ // in every one of the 64 cache slots, on boards with no PSRAM too.
135
+ constexpr int kRuntimeExtraCodepoints[] = {0x00b0, 0x2022};
136
+ constexpr int kRuntimeExtraGlyphs = sizeof(kRuntimeExtraCodepoints) / sizeof(int);
132
137
  #endif
133
138
  constexpr int kRuntimeGlyphCapacity = kRuntimeAsciiCount + kRuntimeExtraGlyphs;
134
139
  constexpr int kRuntimeFontCacheSlots = 64;
@@ -173,11 +178,7 @@ struct RuntimeRasterizedFontSlot {
173
178
  int runtimeCodepointAt(int index)
174
179
  {
175
180
  if (index >= 0 && index < kRuntimeAsciiCount) return kRuntimeAsciiFirst + index;
176
- #if GEA_EMBEDDED_TTF_FREETYPE
177
- if (index>=kRuntimeAsciiCount && index<kRuntimeGlyphCapacity) return kRuntimeExtraCodepoints[index-kRuntimeAsciiCount];
178
- #else
179
- if (index == kRuntimeAsciiCount) return 0x00b0;
180
- #endif
181
+ if (index >= kRuntimeAsciiCount && index < kRuntimeGlyphCapacity) return kRuntimeExtraCodepoints[index - kRuntimeAsciiCount];
181
182
  return -1;
182
183
  }
183
184
 
@@ -104,7 +104,14 @@ gea::framework::graphics::Canvas *CanvasStore::bindOwned(CanvasSurfaceState &sur
104
104
  // Cache-line aligned (size rounded up to the alignment) so DMA engines — the
105
105
  // ESP32-P4 PPA in particular — can scale/rotate straight into this buffer with
106
106
  // no bounce copy. A few padding bytes per canvas is a negligible cost.
107
+ // Apple hosts align to the page instead, so the GPU can read the buffer in
108
+ // place (a Metal buffer wraps whole, page-aligned pages) and presenting a
109
+ // canvas copies nothing.
110
+ #ifdef __APPLE__
111
+ constexpr std::size_t kCanvasAlign = 16384;
112
+ #else
107
113
  constexpr std::size_t kCanvasAlign = 128;
114
+ #endif
108
115
  const auto pixelBytes = static_cast<std::size_t>(width) * static_cast<std::size_t>(height) * sizeof(gea::framework::graphics::pixel::native_t);
109
116
  const auto byteCount = (pixelBytes + (kCanvasAlign - 1)) & ~(kCanvasAlign - 1);
110
117
  surface.pixels = static_cast<gea::framework::graphics::pixel::native_t *>(
package/ui/input.cpp CHANGED
@@ -1344,18 +1344,28 @@ void Tree::setActiveInputCaret(int pos)
1344
1344
  #endif
1345
1345
  }
1346
1346
 
1347
+ namespace {
1348
+ // lv_textarea's pwd_show_time: the last typed characters stay in clear this long.
1349
+ constexpr int kPasswordShowMs = 1500;
1350
+ // pwdRevealUntilMs while the reveal waits for its first frame tick.
1351
+ constexpr int kPasswordRevealPending = -1;
1352
+ }
1353
+
1347
1354
  void Tree::noteActiveInputTyped(int from, int to)
1348
1355
  {
1349
1356
  #if GEA_UI_INPUT_NODES
1350
1357
  auto &state = treeState();
1351
- constexpr int kPasswordShowMs = 1500;
1352
1358
  if (state.pwdRevealUntilMs != 0 && from == state.pwdRevealTo) {
1353
1359
  state.pwdRevealTo = to; // the same burst: keep showing it
1354
1360
  } else {
1355
1361
  state.pwdRevealFrom = from;
1356
1362
  state.pwdRevealTo = to;
1357
1363
  }
1358
- state.pwdRevealUntilMs = (state.lastFrameMs ? state.lastFrameMs : 1) + kPasswordShowMs;
1364
+ // The timer starts at the next frame tick, not at lastFrameMs: a key tap
1365
+ // lands between frames, and once the screen goes idle lastFrameMs can be
1366
+ // seconds old -- lastFrameMs + 1500 was already past, so the very next
1367
+ // tick turned the character into a bullet before it was ever drawn.
1368
+ state.pwdRevealUntilMs = kPasswordRevealPending;
1359
1369
  #else
1360
1370
  (void)from;
1361
1371
  (void)to;
@@ -1385,7 +1395,9 @@ void Tree::tickInputCaret(int timestampMs)
1385
1395
  return;
1386
1396
  }
1387
1397
  // The password characters typed last turn to bullets once their time is up.
1388
- if (state.pwdRevealUntilMs != 0 && timestampMs >= state.pwdRevealUntilMs) {
1398
+ if (state.pwdRevealUntilMs == kPasswordRevealPending) {
1399
+ state.pwdRevealUntilMs = (timestampMs > 0 ? timestampMs : 1) + kPasswordShowMs;
1400
+ } else if (state.pwdRevealUntilMs != 0 && timestampMs >= state.pwdRevealUntilMs) {
1389
1401
  state.pwdRevealUntilMs = 0;
1390
1402
  state.pwdRevealFrom = state.pwdRevealTo = 0;
1391
1403
  markActiveInputRepaint(state);
@@ -107,6 +107,14 @@ const char *inputContentText(int id, gea::framework::graphics::pixel::native_t *
107
107
  return nullptr;
108
108
  }
109
109
 
110
+ // How far each input's one line is scrolled left so its caret stays in view
111
+ // (lv_textarea one-line mode scrolls the label the same way).
112
+ std::unordered_map<int, int> &inputScrollX()
113
+ {
114
+ static std::unordered_map<int, int> scroll;
115
+ return scroll;
116
+ }
117
+
110
118
  const char *inputMeasureText(int id)
111
119
  {
112
120
  const char *content = inputContentText(id, nullptr, 0);
@@ -168,6 +176,51 @@ void InputRenderer::record(int id)
168
176
  if (contentW < 0) contentW = 0;
169
177
  if (contentH < 0) contentH = 0;
170
178
 
179
+ const auto &style = n.computedStyle();
180
+ const bool focused = tree.activeInputId() == id;
181
+ const char *valueAttr = tree.getAttribute(id, "value");
182
+ const bool hasValue = valueAttr && valueAttr[0];
183
+ // The width of what is shown before the caret (bullets on a password).
184
+ int caretPrefixW = -1;
185
+ if (focused && hasValue) {
186
+ const int caret = tree.activeInputCaret();
187
+ const std::string prefix = isPasswordInput(id) ? passwordDisplay(id, valueAttr, caret) : std::string(valueAttr, caret);
188
+ caretPrefixW = TextRenderer::measureWidth(prefix.c_str(), style.font_id, style.font_size, style.text_transform);
189
+ }
190
+
191
+ // An input is one line: its text never wraps. When it is wider than the
192
+ // box, the focused input scrolls it so the caret stays inside; an
193
+ // unfocused one shows its start. Either way it is clipped to the box.
194
+ int textW = content ? TextRenderer::measureWidth(content, style.font_id, style.font_size, style.text_transform) : 0;
195
+ int &scroll = inputScrollX()[id];
196
+ const int room = contentW - kInputCaretWidth;
197
+ if (!focused || !hasValue || textW <= room) {
198
+ scroll = 0;
199
+ } else {
200
+ if (caretPrefixW - scroll > room) scroll = caretPrefixW - room;
201
+ if (caretPrefixW < scroll) scroll = caretPrefixW;
202
+ const int maxScroll = textW - room;
203
+ if (scroll > maxScroll) scroll = maxScroll;
204
+ if (scroll < 0) scroll = 0;
205
+ }
206
+ const bool scrolled = focused && hasValue && textW > room;
207
+
208
+ // The clip: the content box widened by the caret's 1 px left offset, the
209
+ // node's full height (the caret overhangs the text by its outset).
210
+ const int clipX = contentX - 1;
211
+ const int clipW = contentW + 1;
212
+ const bool clip = clipW > 0 && h > 0;
213
+ if (clip) {
214
+ if (DisplayCommand *begin = DisplayList::instance().append()) {
215
+ begin->type = DisplayCommandType::PushClip;
216
+ begin->bx = begin->clip.x = static_cast<int16_t>(clipX);
217
+ begin->by = begin->clip.y = static_cast<int16_t>(y);
218
+ begin->bw = begin->clip.w = static_cast<int16_t>(clipW);
219
+ begin->bh = begin->clip.h = static_cast<int16_t>(h);
220
+ begin->clip.nodeId = -1;
221
+ }
222
+ }
223
+
171
224
  if (content) {
172
225
  // Matches TextRenderer::record's scale formula. The denominator is
173
226
  // the bitmap font's height (BitmapFont8x16::kHeight = 16). This
@@ -175,39 +228,39 @@ void InputRenderer::record(int id)
175
228
  // system rasterizes at font_size directly — but it still needs to
176
229
  // be non-zero to keep the bitmap path's math consistent for callers
177
230
  // without `font-family` set.
178
- const float textScale = n.computedStyle().font_size > 0
179
- ? static_cast<float>(n.computedStyle().font_size) / 16.0f
231
+ const float textScale = style.font_size > 0
232
+ ? static_cast<float>(style.font_size) / 16.0f
180
233
  : 1.0f;
181
234
 
182
235
  DisplayCommand *cmd = DisplayList::instance().append();
183
236
  if (cmd) {
184
237
  cmd->type = DisplayCommandType::DrawText;
185
238
  cmd->bx = x; cmd->by = y; cmd->bw = w; cmd->bh = h;
186
- cmd->text.text = content;
187
239
  // `getAttribute` returns a pointer to the in-tree attribute slot, so
188
240
  // the string is stable until the attribute is overwritten. The
189
241
  // DisplayList commands are replayed within the same frame, so this
190
242
  // stays valid for the duration of the present.
191
- cmd->text.x = contentX;
192
- // Vertically center the single-line text within the content area —
193
- // inputs are conventionally one line and the framework's text
194
- // renderer would otherwise top-align.
243
+ cmd->text.text = content;
244
+ // A scrolled line starts left of the box and is as wide as its text.
245
+ cmd->text.x = scrolled ? contentX - scroll : contentX;
246
+ // Vertically center the single-line text within the content area.
195
247
  // 16 = BitmapFont8x16::kHeight (default when no font_size set).
196
- const int fontSize = n.computedStyle().font_size > 0 ? n.computedStyle().font_size : 16;
248
+ const int fontSize = style.font_size > 0 ? style.font_size : 16;
197
249
  const int yCenter = contentY + (contentH - fontSize) / 2;
198
250
  cmd->text.y = yCenter > contentY ? yCenter : contentY;
199
- cmd->text.maxWidth = contentW;
251
+ cmd->text.maxWidth = scrolled ? textW + 1 : contentW;
200
252
  cmd->text.color = color;
201
253
  cmd->text.scale = textScale;
202
- cmd->text.align = n.computedStyle().text_align;
203
- cmd->text.textTransform = n.computedStyle().text_transform;
204
- cmd->text.lineHeight = n.computedStyle().line_height;
205
- cmd->text.containerWidth = contentW;
206
- cmd->text.fontId = n.computedStyle().font_id;
207
- // append() hands back uninitialized scratch — set these explicitly so
208
- // the deferred draw doesn't read stale white-space/text-overflow.
209
- cmd->text.whiteSpace = n.computedStyle().white_space;
210
- cmd->text.textOverflow = n.computedStyle().text_overflow;
254
+ cmd->text.align = scrolled ? 0 : style.text_align;
255
+ cmd->text.textTransform = style.text_transform;
256
+ cmd->text.lineHeight = style.line_height;
257
+ cmd->text.containerWidth = scrolled ? textW + 1 : contentW;
258
+ cmd->text.fontId = style.font_id;
259
+ // append() hands back uninitialized scratch — set these explicitly.
260
+ // white-space is always nowrap: wrapping put long text on a second
261
+ // line that spilled out of the box.
262
+ cmd->text.whiteSpace = 1;
263
+ cmd->text.textOverflow = scrolled ? 0 : style.text_overflow;
211
264
  cmd->text.maxHeight = 0;
212
265
  cmd->text.firstLineIndent = 0;
213
266
  }
@@ -218,27 +271,22 @@ void InputRenderer::record(int id)
218
271
  // which Tree::activeInputCaretVisible() returns. Showing the caret while
219
272
  // unfocused would be misleading on targets where the framework handles
220
273
  // the input's visual editing state.
221
- if (tree.activeInputId() == id && tree.activeInputCaretVisible()) {
222
- // At the caret: the width of what is shown before it (bullets on a
223
- // password), from the content's left edge; at the start when the
224
- // placeholder shows.
225
- const char *valueAttr = tree.getAttribute(id, "value");
226
- const bool hasValue = valueAttr && valueAttr[0];
274
+ if (focused && tree.activeInputCaretVisible()) {
275
+ // At the caret, from the content's left edge, less the scroll; at the
276
+ // start when the placeholder shows.
227
277
  int caretX = contentX - 1;
228
- if (hasValue) {
229
- const int caret = tree.activeInputCaret();
230
- const std::string prefix = isPasswordInput(id) ? passwordDisplay(id, valueAttr, caret) : std::string(valueAttr, caret);
231
- const int prefixWidth = TextRenderer::measureWidth(prefix.c_str(), n.computedStyle().font_id, n.computedStyle().font_size, n.computedStyle().text_transform);
232
- caretX += prefixWidth < contentW ? prefixWidth : contentW - kInputCaretWidth;
278
+ if (caretPrefixW >= 0) {
279
+ const int shown = caretPrefixW - scroll;
280
+ caretX += shown < room ? shown : room;
233
281
  }
234
- const int fontSize = n.computedStyle().font_size > 0 ? n.computedStyle().font_size : 16;
235
- const int lineHeight = TextRenderer::measureHeight("M", n.computedStyle().font_id, n.computedStyle().font_size, n.computedStyle().text_transform, n.computedStyle().line_height);
282
+ const int fontSize = style.font_size > 0 ? style.font_size : 16;
283
+ const int lineHeight = TextRenderer::measureHeight("M", style.font_id, style.font_size, style.text_transform, style.line_height);
236
284
  int textY = contentY + (contentH - fontSize) / 2;
237
285
  if (textY < contentY) textY = contentY;
238
286
  const int caretY = textY - kInputCaretOutset;
239
287
  const int caretH = lineHeight + kInputCaretOutset * 2;
240
288
  // caret-color, else the text colour (a placeholder's grey is not it).
241
- gea::framework::graphics::pixel::native_t caretColor = n.computedStyle().text_color ? n.computedStyle().text_color : gea::framework::graphics::pixel::nativeColor(255, 255, 255);
289
+ gea::framework::graphics::pixel::native_t caretColor = style.text_color ? style.text_color : gea::framework::graphics::pixel::nativeColor(255, 255, 255);
242
290
  if (const char *cc = tree.getAttribute(id, "caret-color"); cc && cc[0] == '#' && std::strlen(cc) >= 7) {
243
291
  const unsigned long rgb = std::strtoul(cc + 1, nullptr, 16);
244
292
  caretColor = gea::framework::graphics::pixel::nativeColor((rgb >> 16) & 0xff, (rgb >> 8) & 0xff, rgb & 0xff);
@@ -255,6 +303,15 @@ void InputRenderer::record(int id)
255
303
  cmd->fill.color = caretColor;
256
304
  }
257
305
  }
306
+
307
+ if (clip) {
308
+ if (DisplayCommand *end = DisplayList::instance().append()) {
309
+ end->type = DisplayCommandType::PopClip;
310
+ end->bx = static_cast<int16_t>(clipX); end->by = static_cast<int16_t>(y);
311
+ end->bw = static_cast<int16_t>(clipW); end->bh = static_cast<int16_t>(h);
312
+ end->clip.nodeId = -1;
313
+ }
314
+ }
258
315
  }
259
316
 
260
317
  } // namespace gea::embedded::ui
@@ -176,6 +176,11 @@ public:
176
176
  // Bumped on every mount()/refresh(); native renderers diff against the last
177
177
  // value they synced to decide whether a re-sync is needed at all.
178
178
  uint64_t refreshSerial() const;
179
+ // A host that presents the tree with its own native views (the iOS/tvOS
180
+ // UIKit renderer) never shows the software framebuffer: while suppressed,
181
+ // refresh() still lays out and records, but skips rasterizing and flushing.
182
+ // The first refresh after suppression ends repaints the whole viewport.
183
+ void setSoftwareRasterSuppressed(bool suppressed);
179
184
  void setDisplayListRebuildRequired(bool required);
180
185
  bool nodeDisplayCommandsDirty(int node) const;
181
186
  void clearNodeDisplayCommandDirty(int node);
@@ -2161,6 +2161,13 @@ namespace gea::embedded::ui
2161
2161
  }
2162
2162
  } // namespace
2163
2163
 
2164
+ namespace {
2165
+ bool gSoftwareRasterSuppressed = false;
2166
+ bool gSoftwareRasterStale = false; // frames went unrasterized since the last repaint
2167
+ }
2168
+
2169
+ void Tree::setSoftwareRasterSuppressed(bool suppressed) { gSoftwareRasterSuppressed = suppressed; }
2170
+
2164
2171
  void Tree::refresh(int root, int width, int height)
2165
2172
  {
2166
2173
  #if defined(ESP_PLATFORM) && CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
@@ -2180,7 +2187,10 @@ namespace gea::embedded::ui
2180
2187
  #endif
2181
2188
  const bool viewportChanged = gLayoutViewportRoot != root ||
2182
2189
  gLayoutViewportWidth != width || gLayoutViewportHeight != height;
2183
- if (viewportChanged) {
2190
+ const bool rasterResumed = gSoftwareRasterStale && !gSoftwareRasterSuppressed;
2191
+ if (rasterResumed)
2192
+ gSoftwareRasterStale = false;
2193
+ if (viewportChanged || rasterResumed) {
2184
2194
  state.displayListDirty = true;
2185
2195
  state.displayListRebuildStructural = true;
2186
2196
  state.nodes[root].render.dirty = true;
@@ -2741,6 +2751,22 @@ namespace gea::embedded::ui
2741
2751
  if (reprojected)
2742
2752
  GEA_REFRESH_PERF(perf.treeReprojects++);
2743
2753
  GEA_REFRESH_PERF(perf.treeDisplayListUs += refreshPerfNowUs() - displayListStartUs);
2754
+ if (gSoftwareRasterSuppressed)
2755
+ {
2756
+ // The host shows native views, not the framebuffer: finish the frame's
2757
+ // bookkeeping (as the end of a rasterized refresh does) without painting.
2758
+ gSoftwareRasterStale = true;
2759
+ LayoutSnapshot::capture();
2760
+ state.canvases.forEach([](CanvasSurfaceState &surface)
2761
+ {
2762
+ if (auto *canvas = surface.canvas()) canvas->resetDirty(); });
2763
+ CanvasRenderingContext2D::clearRetainedCanvasDamage();
2764
+ #if !defined(GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT) || !GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT
2765
+ if (displayCanvas)
2766
+ displayCanvas->resetDirty();
2767
+ #endif
2768
+ return;
2769
+ }
2744
2770
 
2745
2771
  // Horizontal-pan fast path: when a camera/world wrapper translated the viewport
2746
2772
  // this frame (and nothing structural changed), memcpy-shift the viewport instead
@@ -1055,6 +1055,11 @@ void onKeyboardPress(gea::framework::events::PointerEvent &event)
1055
1055
  const int code = gState.keyCodes[slot];
1056
1056
  if (code == 0) return;
1057
1057
  applyKeyToActiveInput(code);
1058
+ // The keyboard / OK keys (and return on the wide layout) drop focus. A tap
1059
+ // inside the keyboard skips touch_runtime's focus block, which is what
1060
+ // normally calls sync() -- so without this the keys stayed on screen bound
1061
+ // to no input, and every later key did nothing.
1062
+ VirtualKeyboard::instance().sync();
1058
1063
  }
1059
1064
 
1060
1065
  } // namespace