@geastack/engine 0.1.33 → 0.1.34
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/canvas.cpp +197 -18
- package/image_store.cpp +9 -1
- package/package.json +2 -2
- package/rasterized_font.cpp +45 -6
- package/ui/canvas_element.cpp +5 -0
- package/ui/canvas_element.h +1 -0
- package/ui/document.cpp +114 -0
- package/ui/document.h +23 -0
- package/ui/internal.h +1 -1
- package/ui/node.cpp +239 -0
- package/ui/node.h +49 -0
- package/ui/render.cpp +32 -2
- package/ui/style.cpp +87 -2
- package/ui/style.h +11 -0
- package/ui/tree_internal.h +3 -0
- package/ui/tree_nodes.cpp +3 -0
- package/ui/tree_render.cpp +41 -0
- package/ui/tree_state.h +6 -0
- package/ui/view.cpp +36 -2
package/canvas.cpp
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
#include <cstdlib>
|
|
15
15
|
#include <cstring>
|
|
16
16
|
#include <limits>
|
|
17
|
+
#include <new>
|
|
17
18
|
#include <type_traits>
|
|
18
19
|
#include <vector>
|
|
19
20
|
|
|
@@ -208,7 +209,27 @@ struct TextSprite {
|
|
|
208
209
|
bool rleValid = false; // true only when the current sprite has a valid RLE
|
|
209
210
|
};
|
|
210
211
|
|
|
211
|
-
|
|
212
|
+
// One bank per render core. The display's 2-core band split replays a label
|
|
213
|
+
// that straddles the split line on BOTH cores at once; with one shared bank
|
|
214
|
+
// both built, reallocated and freed the same slot concurrently. On the mosaico
|
|
215
|
+
// that corrupted the heap: a later launch faulted in blitGlyphSprite on a
|
|
216
|
+
// garbage pointer, and GEADEV MEM's heap walk faulted. The projected-text
|
|
217
|
+
// cache in render.cpp is split the same way for the same race.
|
|
218
|
+
// Heap-allocated on a core's first label (PSRAM where malloc prefers it):
|
|
219
|
+
// static, the two banks were 8 KB of internal RAM. A bank is created only by
|
|
220
|
+
// its own core, so creation needs no lock.
|
|
221
|
+
TextSprite *gTextSprites[2] = {nullptr, nullptr};
|
|
222
|
+
|
|
223
|
+
inline int textSpriteBank()
|
|
224
|
+
{
|
|
225
|
+
#if GEA_CANVAS_HAS_FREERTOS
|
|
226
|
+
return xPortGetCoreID() & 1;
|
|
227
|
+
#elif GEA_CANVAS_HAS_PICO
|
|
228
|
+
return get_core_num() & 1;
|
|
229
|
+
#else
|
|
230
|
+
return 0;
|
|
231
|
+
#endif
|
|
232
|
+
}
|
|
212
233
|
|
|
213
234
|
// Internal-SRAM staging for the sprite currently being blitted. The RLE blit walks
|
|
214
235
|
// rowX0/rowX1/rleRowStart/rleVal/rleLen several times per frame (once per DMA chunk
|
|
@@ -252,7 +273,7 @@ void adoptHotTextSprite(const TextSprite &s)
|
|
|
252
273
|
// cached sprite blitted through the hot stage). The S3, where this staging
|
|
253
274
|
// was built, has byte-accessible IRAM and never showed it.
|
|
254
275
|
hot.buf = static_cast<std::uint8_t *>(
|
|
255
|
-
heap_caps_malloc(GEA_EMBEDDED_TEXT_SPRITE_HOT_STAGE_BYTES, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT));
|
|
276
|
+
heap_caps_malloc(GEA_EMBEDDED_TEXT_SPRITE_HOT_STAGE_BYTES, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA | MALLOC_CAP_8BIT));
|
|
256
277
|
#else
|
|
257
278
|
hot.buf = static_cast<std::uint8_t *>(std::malloc(GEA_EMBEDDED_TEXT_SPRITE_HOT_STAGE_BYTES));
|
|
258
279
|
#endif
|
|
@@ -282,18 +303,25 @@ void adoptHotTextSprite(const TextSprite &s)
|
|
|
282
303
|
}
|
|
283
304
|
#endif // GEA_EMBEDDED_TEXT_SPRITE_HOT_STAGE_BYTES > 0
|
|
284
305
|
|
|
285
|
-
TextSprite
|
|
306
|
+
TextSprite *textSpriteBankSlots(int bank)
|
|
307
|
+
{
|
|
308
|
+
if (!gTextSprites[bank]) gTextSprites[bank] = new (std::nothrow) TextSprite[kTextSpriteSlots];
|
|
309
|
+
return gTextSprites[bank];
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
TextSprite &textSpriteFor(TextSprite *slots, const char *text, const RasterizedFont &font, int bank)
|
|
286
313
|
{
|
|
287
314
|
// Search every slot: a direct-mapped hash makes alternating labels
|
|
288
315
|
// such as "FPS: 59" and "FPS: 60" evict each other. Hits stay read-only;
|
|
289
316
|
// a four-byte replacement cursor advances only for a new cache key.
|
|
290
|
-
for (
|
|
317
|
+
for (int i = 0; i < kTextSpriteSlots; i++) {
|
|
318
|
+
TextSprite &candidate = slots[i];
|
|
291
319
|
if (candidate.fontData == font.data() && candidate.fontGeneration==font.data()->generation && candidate.sizePx == font.sizePx() &&
|
|
292
320
|
std::strcmp(candidate.text, text) == 0)
|
|
293
321
|
return candidate;
|
|
294
322
|
}
|
|
295
|
-
static std::atomic<unsigned> nextSlot{
|
|
296
|
-
return
|
|
323
|
+
static std::atomic<unsigned> nextSlot[2]{};
|
|
324
|
+
return slots[nextSlot[bank].fetch_add(1, std::memory_order_relaxed) % kTextSpriteSlots];
|
|
297
325
|
}
|
|
298
326
|
|
|
299
327
|
// Rasterize `text` into `sprite`'s coverage buffer in text-relative coordinates
|
|
@@ -530,6 +558,66 @@ bool Canvas::textRasterCacheEnabled()
|
|
|
530
558
|
return gTextRasterCacheEnabled;
|
|
531
559
|
}
|
|
532
560
|
|
|
561
|
+
namespace {
|
|
562
|
+
void freeRoundedCoverageTables();
|
|
563
|
+
} // namespace
|
|
564
|
+
|
|
565
|
+
void Canvas::releaseShapeCaches()
|
|
566
|
+
{
|
|
567
|
+
freeRoundedCoverageTables();
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
#ifdef GEA_EMBEDDED_HAS_GENERATED_FONTS
|
|
571
|
+
namespace {
|
|
572
|
+
void releaseSolidGlyphCache();
|
|
573
|
+
} // namespace
|
|
574
|
+
#endif
|
|
575
|
+
|
|
576
|
+
void Canvas::invalidateTextRasterCache()
|
|
577
|
+
{
|
|
578
|
+
#ifdef GEA_EMBEDDED_HAS_GENERATED_FONTS
|
|
579
|
+
releaseSolidGlyphCache();
|
|
580
|
+
#endif
|
|
581
|
+
// Runs when an app unmounts: its sprites are keyed by its fonts, and a
|
|
582
|
+
// program's fonts leave with it, so the buffers go too rather than holding
|
|
583
|
+
// up to every slot's largest label for the next app.
|
|
584
|
+
#if GEA_EMBEDDED_TEXT_SPRITE_CACHE
|
|
585
|
+
for (TextSprite *bank : gTextSprites)
|
|
586
|
+
for (int i = 0; bank && i < kTextSpriteSlots; i++) {
|
|
587
|
+
TextSprite &sprite = bank[i];
|
|
588
|
+
sprite.text[0] = '\0';
|
|
589
|
+
sprite.fontData = nullptr;
|
|
590
|
+
sprite.sizePx = -1;
|
|
591
|
+
sprite.state = TextSprite::Empty;
|
|
592
|
+
sprite.rleValid = false;
|
|
593
|
+
std::free(sprite.cov);
|
|
594
|
+
std::free(sprite.rowX0);
|
|
595
|
+
std::free(sprite.rowX1);
|
|
596
|
+
std::free(sprite.rleVal);
|
|
597
|
+
std::free(sprite.rleLen);
|
|
598
|
+
std::free(sprite.rleRowStart);
|
|
599
|
+
sprite.cov = nullptr;
|
|
600
|
+
sprite.rowX0 = nullptr;
|
|
601
|
+
sprite.rowX1 = nullptr;
|
|
602
|
+
sprite.rleVal = nullptr;
|
|
603
|
+
sprite.rleLen = nullptr;
|
|
604
|
+
sprite.rleRowStart = nullptr;
|
|
605
|
+
sprite.covCap = 0;
|
|
606
|
+
sprite.extCap = 0;
|
|
607
|
+
sprite.rleCap = 0;
|
|
608
|
+
sprite.rleRowCap = 0;
|
|
609
|
+
}
|
|
610
|
+
#if GEA_EMBEDDED_TEXT_SPRITE_HOT_STAGE_BYTES > 0
|
|
611
|
+
// The hot stage is 12 KB of internal RAM, allocated the first time a large
|
|
612
|
+
// label blits; the launcher an unloaded app returns to has none to spare.
|
|
613
|
+
gHotTextSprite.owner = nullptr;
|
|
614
|
+
std::free(gHotTextSprite.buf);
|
|
615
|
+
gHotTextSprite.buf = nullptr;
|
|
616
|
+
gHotTextSprite.allocFailed = false;
|
|
617
|
+
#endif
|
|
618
|
+
#endif // GEA_EMBEDDED_TEXT_SPRITE_CACHE
|
|
619
|
+
}
|
|
620
|
+
|
|
533
621
|
void Canvas::setTextSolidBackdrop(int rrggbb)
|
|
534
622
|
{
|
|
535
623
|
#if GEA_PIXEL_STORAGE_PACKED_BITS == 4
|
|
@@ -841,6 +929,18 @@ RoundedCoverageTable gRoundedCoverage[kRoundedCoverageTables];
|
|
|
841
929
|
std::atomic_flag gRoundedCoverageLock = ATOMIC_FLAG_INIT;
|
|
842
930
|
std::uint32_t gRoundedCoverageClock = 0;
|
|
843
931
|
|
|
932
|
+
void freeRoundedCoverageTables()
|
|
933
|
+
{
|
|
934
|
+
while (gRoundedCoverageLock.test_and_set(std::memory_order_acquire)) {}
|
|
935
|
+
for (auto &table : gRoundedCoverage) {
|
|
936
|
+
if (table.refs.load(std::memory_order_relaxed) != 0) continue;
|
|
937
|
+
std::free(table.cells);
|
|
938
|
+
table.cells = nullptr;
|
|
939
|
+
table.capacity = 0;
|
|
940
|
+
}
|
|
941
|
+
gRoundedCoverageLock.clear(std::memory_order_release);
|
|
942
|
+
}
|
|
943
|
+
|
|
844
944
|
void *allocRoundedCoverageCells(int bytes)
|
|
845
945
|
{
|
|
846
946
|
#ifdef ESP_PLATFORM
|
|
@@ -1040,8 +1140,25 @@ struct SolidGlyphCacheEntry {
|
|
|
1040
1140
|
};
|
|
1041
1141
|
|
|
1042
1142
|
constexpr int kSolidGlyphCacheSize = 48;
|
|
1043
|
-
|
|
1044
|
-
|
|
1143
|
+
// One bank per render core, heap-allocated by its own core on first use: the
|
|
1144
|
+
// 2-core band split draws the same label on both cores at once, and one shared
|
|
1145
|
+
// bank rebuilt an entry's vectors under the other core's reads.
|
|
1146
|
+
struct SolidGlyphBank {
|
|
1147
|
+
SolidGlyphCacheEntry entries[kSolidGlyphCacheSize];
|
|
1148
|
+
std::uint32_t clock = 1;
|
|
1149
|
+
};
|
|
1150
|
+
SolidGlyphBank *gSolidGlyphBanks[2] = {nullptr, nullptr};
|
|
1151
|
+
|
|
1152
|
+
inline int solidGlyphBank()
|
|
1153
|
+
{
|
|
1154
|
+
#if GEA_CANVAS_HAS_FREERTOS
|
|
1155
|
+
return xPortGetCoreID() & 1;
|
|
1156
|
+
#elif GEA_CANVAS_HAS_PICO
|
|
1157
|
+
return get_core_num() & 1;
|
|
1158
|
+
#else
|
|
1159
|
+
return 0;
|
|
1160
|
+
#endif
|
|
1161
|
+
}
|
|
1045
1162
|
|
|
1046
1163
|
SolidGlyphCacheEntry *solidGlyphCacheEntry(const RasterizedFont &font,
|
|
1047
1164
|
pixel::native_t color,
|
|
@@ -1050,11 +1167,15 @@ SolidGlyphCacheEntry *solidGlyphCacheEntry(const RasterizedFont &font,
|
|
|
1050
1167
|
{
|
|
1051
1168
|
const RasterizedFontData *data = font.data();
|
|
1052
1169
|
if (!data) return nullptr;
|
|
1170
|
+
SolidGlyphBank *&bankSlot = gSolidGlyphBanks[solidGlyphBank()];
|
|
1171
|
+
if (!bankSlot) bankSlot = new (std::nothrow) SolidGlyphBank();
|
|
1172
|
+
if (!bankSlot) return nullptr;
|
|
1173
|
+
SolidGlyphBank &bank = *bankSlot;
|
|
1053
1174
|
|
|
1054
|
-
for (auto &entry :
|
|
1175
|
+
for (auto &entry : bank.entries) {
|
|
1055
1176
|
if (entry.font == data && entry.color == color && entry.background == background &&
|
|
1056
1177
|
entry.codepoint == codepoint) {
|
|
1057
|
-
entry.lastUsed = ++
|
|
1178
|
+
entry.lastUsed = ++bank.clock;
|
|
1058
1179
|
return &entry;
|
|
1059
1180
|
}
|
|
1060
1181
|
}
|
|
@@ -1062,8 +1183,8 @@ SolidGlyphCacheEntry *solidGlyphCacheEntry(const RasterizedFont &font,
|
|
|
1062
1183
|
Glyph glyph{};
|
|
1063
1184
|
if (!font.glyph(codepoint, &glyph)) return nullptr;
|
|
1064
1185
|
|
|
1065
|
-
SolidGlyphCacheEntry *victim = &
|
|
1066
|
-
for (auto &entry :
|
|
1186
|
+
SolidGlyphCacheEntry *victim = &bank.entries[0];
|
|
1187
|
+
for (auto &entry : bank.entries) {
|
|
1067
1188
|
if (!entry.font) {
|
|
1068
1189
|
victim = &entry;
|
|
1069
1190
|
break;
|
|
@@ -1109,10 +1230,20 @@ SolidGlyphCacheEntry *solidGlyphCacheEntry(const RasterizedFont &font,
|
|
|
1109
1230
|
}
|
|
1110
1231
|
}
|
|
1111
1232
|
|
|
1112
|
-
victim->lastUsed = ++
|
|
1233
|
+
victim->lastUsed = ++bank.clock;
|
|
1113
1234
|
return victim;
|
|
1114
1235
|
}
|
|
1115
1236
|
|
|
1237
|
+
// An unloaded program's fonts go with it, and the next program's can land at
|
|
1238
|
+
// the same address: its glyphs must not come back from this cache.
|
|
1239
|
+
void releaseSolidGlyphCache()
|
|
1240
|
+
{
|
|
1241
|
+
for (SolidGlyphBank *&bank : gSolidGlyphBanks) {
|
|
1242
|
+
delete bank;
|
|
1243
|
+
bank = nullptr;
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1116
1247
|
} // namespace
|
|
1117
1248
|
#endif
|
|
1118
1249
|
|
|
@@ -3229,8 +3360,12 @@ void Canvas::drawRasterizedText(const char *text, int x, int y, pixel::native_t
|
|
|
3229
3360
|
#if GEA_EMBEDDED_TEXT_SPRITE_DIAG
|
|
3230
3361
|
if (len == 0 || len > static_cast<std::size_t>(kTextSpriteMaxLen)) gTsDiag.tooLong++;
|
|
3231
3362
|
#endif
|
|
3232
|
-
|
|
3233
|
-
|
|
3363
|
+
const int bank = textSpriteBank();
|
|
3364
|
+
TextSprite *slots = textSpriteBankSlots(bank);
|
|
3365
|
+
if (slots && len > 0 && len <= static_cast<std::size_t>(kTextSpriteMaxLen)) {
|
|
3366
|
+
// The hot stage is one internal-RAM buffer: only the render core's
|
|
3367
|
+
// bank uses it, so the worker core never touches it.
|
|
3368
|
+
TextSprite &slot = textSpriteFor(slots, text, font, bank);
|
|
3234
3369
|
const bool idMatch = slot.fontData == font.data() && slot.fontGeneration==font.data()->generation &&
|
|
3235
3370
|
slot.sizePx == font.sizePx() &&
|
|
3236
3371
|
std::strcmp(slot.text, text) == 0;
|
|
@@ -3252,7 +3387,7 @@ void Canvas::drawRasterizedText(const char *text, int x, int y, pixel::native_t
|
|
|
3252
3387
|
// Only large text stages: with small labels cached too, several
|
|
3253
3388
|
// sprites blit per frame and would steal the one stage from
|
|
3254
3389
|
// each other, re-copying every frame.
|
|
3255
|
-
if (slot.rleValid && slot.sizePx >= 40) {
|
|
3390
|
+
if (bank == 0 && slot.rleValid && slot.sizePx >= 40) {
|
|
3256
3391
|
if (gHotTextSprite.owner != &slot) adoptHotTextSprite(slot);
|
|
3257
3392
|
if (gHotTextSprite.owner == &slot) {
|
|
3258
3393
|
bRowX0 = gHotTextSprite.rowX0;
|
|
@@ -4188,6 +4323,22 @@ void Canvas::fillRoundedRect(int x, int y, int w, int h, int tl, int tr, int br,
|
|
|
4188
4323
|
|
|
4189
4324
|
RoundedCoverageTable *coverageTable = useAntialias ? acquireRoundedCoverage(w, h, tl, tr, br, bl, aaSamples) : nullptr;
|
|
4190
4325
|
struct ReleaseCoverage { RoundedCoverageTable *table; ~ReleaseCoverage() { releaseRoundedCoverage(table); } } releaseCoverage{coverageTable};
|
|
4326
|
+
// Edge coverage on the straight sides, keyed by distance from each side
|
|
4327
|
+
// (-1 = not yet computed). Without it every row of an antialiased box
|
|
4328
|
+
// re-sampled its edge band, through a coverage table that a box whose size
|
|
4329
|
+
// changes every frame (a cover flow) never hits.
|
|
4330
|
+
constexpr int kStraightEdgeSlots = 16;
|
|
4331
|
+
std::int8_t straightLeft[kStraightEdgeSlots];
|
|
4332
|
+
std::int8_t straightRight[kStraightEdgeSlots];
|
|
4333
|
+
std::memset(straightLeft, -1, sizeof(straightLeft));
|
|
4334
|
+
std::memset(straightRight, -1, sizeof(straightRight));
|
|
4335
|
+
const float straightTop = static_cast<float>(y) + static_cast<float>(top_r);
|
|
4336
|
+
const float straightBottom = static_cast<float>(y) + static_cast<float>(h) - static_cast<float>(bot_r);
|
|
4337
|
+
// The top and bottom edges are the transpose: a pixel whose samples all lie
|
|
4338
|
+
// between the left and right corner bands has a coverage that depends on
|
|
4339
|
+
// its row alone, so an edge row computes it once instead of per pixel.
|
|
4340
|
+
const float straightLeftX = static_cast<float>(x) + static_cast<float>(tl > bl ? tl : bl);
|
|
4341
|
+
const float straightRightX = static_cast<float>(x) + static_cast<float>(w) - static_cast<float>(tr > br ? tr : br);
|
|
4191
4342
|
for (int sy = row0; sy <= row1; sy++) {
|
|
4192
4343
|
int sx0 = width_;
|
|
4193
4344
|
int sx1 = -1;
|
|
@@ -4263,10 +4414,38 @@ void Canvas::fillRoundedRect(int x, int y, int w, int h, int tl, int tr, int br,
|
|
|
4263
4414
|
}
|
|
4264
4415
|
if (anyX0 > anyX1) continue;
|
|
4265
4416
|
|
|
4417
|
+
// Every sample of this row lies between the corner bands, so no corner
|
|
4418
|
+
// arc reaches it: edge coverage here is a function of px only.
|
|
4419
|
+
const bool straightRow = useAntialias &&
|
|
4420
|
+
static_cast<float>(sy) + firstOffset >= straightTop &&
|
|
4421
|
+
static_cast<float>(sy) + lastOffset < straightBottom;
|
|
4422
|
+
std::int8_t straightRowCoverage = -1;
|
|
4423
|
+
|
|
4266
4424
|
auto paintCoverageEdge = [&](int px) {
|
|
4267
4425
|
if (px < clip->x0 || px > clip->x1 || px < 0 || px >= width_) return;
|
|
4268
|
-
|
|
4269
|
-
|
|
4426
|
+
// Straight-side row: the answer depends on px alone, so it is
|
|
4427
|
+
// computed once per shape and reused down the whole side.
|
|
4428
|
+
std::int8_t *straightSlot = nullptr;
|
|
4429
|
+
if (straightRow) {
|
|
4430
|
+
const int fromLeft = px - x;
|
|
4431
|
+
const int fromRight = x + w - 1 - px;
|
|
4432
|
+
straightSlot = fromLeft >= 0 && fromLeft < kStraightEdgeSlots ? &straightLeft[fromLeft]
|
|
4433
|
+
: fromRight >= 0 && fromRight < kStraightEdgeSlots ? &straightRight[fromRight]
|
|
4434
|
+
: nullptr;
|
|
4435
|
+
} else if (useAntialias &&
|
|
4436
|
+
static_cast<float>(px) + firstOffset >= straightLeftX &&
|
|
4437
|
+
static_cast<float>(px) + lastOffset < straightRightX) {
|
|
4438
|
+
straightSlot = &straightRowCoverage;
|
|
4439
|
+
}
|
|
4440
|
+
if (straightSlot && *straightSlot < 0) {
|
|
4441
|
+
const int known = roundedRectCoverageDecided(x, y, w, h, tl, tr, br, bl, px, sy,
|
|
4442
|
+
firstOffset, lastOffset, aaSampleCount);
|
|
4443
|
+
*straightSlot = static_cast<std::int8_t>(
|
|
4444
|
+
known >= 0 ? known : roundedRectCoverage(x, y, w, h, tl, tr, br, bl, px, sy, aaSamples, kernelWidth));
|
|
4445
|
+
}
|
|
4446
|
+
std::uint8_t *cell = !straightSlot && coverageTable ? &coverageTable->cells[(sy - y) * w + (px - x)] : nullptr;
|
|
4447
|
+
int decided = straightSlot ? *straightSlot
|
|
4448
|
+
: cell && *cell != 0xff ? *cell
|
|
4270
4449
|
: useAntialias ? roundedRectCoverageDecided(x, y, w, h, tl, tr, br, bl, px, sy,
|
|
4271
4450
|
firstOffset, lastOffset, aaSampleCount)
|
|
4272
4451
|
: -1;
|
package/image_store.cpp
CHANGED
|
@@ -564,7 +564,8 @@ int ImageStore::decodeJpegTjpgd(ImageSlot &image, const std::uint8_t *data, int
|
|
|
564
564
|
constexpr std::size_t poolSize = 8 * 1024;
|
|
565
565
|
void *pool = nullptr;
|
|
566
566
|
#ifdef ESP_PLATFORM
|
|
567
|
-
|
|
567
|
+
// MALLOC_CAP_DMA keeps it out of the S31/P4 LP RAM, slower than PSRAM.
|
|
568
|
+
pool = heap_caps_malloc(poolSize, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA | MALLOC_CAP_8BIT);
|
|
568
569
|
#endif
|
|
569
570
|
if (!pool) pool = memory::Allocator::allocatePreferSpiram(poolSize, alignof(std::max_align_t));
|
|
570
571
|
if (!pool) return -1;
|
|
@@ -1320,6 +1321,13 @@ void ImageStore::disposeAll()
|
|
|
1320
1321
|
}
|
|
1321
1322
|
}
|
|
1322
1323
|
|
|
1324
|
+
void ImageStore::disposeEverything()
|
|
1325
|
+
{
|
|
1326
|
+
ImageStoreLock lock(slotMutex_);
|
|
1327
|
+
for (int i = 0; i < kImageMax; i++)
|
|
1328
|
+
if (used_[i]) disposeLocked(i);
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1323
1331
|
int ImageStore::registerBuffer(pixel::native_t *pixels, int width, int height, int preferredSlot, bool takeOwnership)
|
|
1324
1332
|
{
|
|
1325
1333
|
if (!pixels || width <= 0 || height <= 0) return -1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geastack/engine",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.34",
|
|
4
4
|
"description": "GeaStack rendering engine, intrinsic JSX primitives, and native engine backends.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -57,6 +57,6 @@
|
|
|
57
57
|
},
|
|
58
58
|
"sideEffects": false,
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@geastack/core": "^0.1.
|
|
60
|
+
"@geastack/core": "^0.1.67"
|
|
61
61
|
}
|
|
62
62
|
}
|
package/rasterized_font.cpp
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
#include "graphics/font.h"
|
|
3
|
+
#include "program.h"
|
|
3
4
|
|
|
4
5
|
namespace {
|
|
5
6
|
const gea::framework::graphics::RuntimeFontProvider *runtimeFontProvider = nullptr;
|
|
@@ -103,11 +104,43 @@ namespace {
|
|
|
103
104
|
|
|
104
105
|
void ensureGeneratedFontsLinked()
|
|
105
106
|
{
|
|
107
|
+
if (const auto *loaded = program::loaded()) {
|
|
108
|
+
if (loaded->fontsEnsureLinked) loaded->fontsEnsureLinked();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
106
111
|
#ifdef GEA_EMBEDDED_HAS_GENERATED_FONTS
|
|
107
112
|
generated::ensureLinked();
|
|
108
113
|
#endif
|
|
109
114
|
}
|
|
110
115
|
|
|
116
|
+
// A loaded program (program.h) brings its own font registry; otherwise the
|
|
117
|
+
// firmware's generated one answers.
|
|
118
|
+
const RasterizedFontData *programLookupFont(int fontId)
|
|
119
|
+
{
|
|
120
|
+
if (const auto *loaded = program::loaded()) return loaded->lookupFont ? loaded->lookupFont(fontId) : nullptr;
|
|
121
|
+
return generated::lookupFont(fontId);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const RasterizedFontData *programLookupFontForFamily(int familyId, int sizePx)
|
|
125
|
+
{
|
|
126
|
+
if (const auto *loaded = program::loaded())
|
|
127
|
+
return loaded->lookupFontForFamily ? loaded->lookupFontForFamily(familyId, sizePx) : nullptr;
|
|
128
|
+
return generated::lookupFontForFamily(familyId, sizePx);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
int programLookupFontFamily(const char *family)
|
|
132
|
+
{
|
|
133
|
+
if (const auto *loaded = program::loaded()) return loaded->lookupFontFamily ? loaded->lookupFontFamily(family) : -1;
|
|
134
|
+
return generated::lookupFontFamily(family);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const char *programLookupFontFamilyName(int familyId)
|
|
138
|
+
{
|
|
139
|
+
if (const auto *loaded = program::loaded())
|
|
140
|
+
return loaded->lookupFontFamilyName ? loaded->lookupFontFamilyName(familyId) : nullptr;
|
|
141
|
+
return generated::lookupFontFamilyName(familyId);
|
|
142
|
+
}
|
|
143
|
+
|
|
111
144
|
#if GEA_EMBEDDED_TTF_RUNTIME_FONTS
|
|
112
145
|
|
|
113
146
|
#if GEA_EMBEDDED_TTF_RUNTIME_TRACE
|
|
@@ -211,7 +244,9 @@ int runtimeCodepointAt(int index)
|
|
|
211
244
|
// Declared codepoints the fixed set already covers leave a gap (-1) rather
|
|
212
245
|
// than a duplicate entry.
|
|
213
246
|
int count = 0;
|
|
214
|
-
const
|
|
247
|
+
const auto *loaded = program::loaded();
|
|
248
|
+
const int *declared = loaded ? (loaded->runtimeTtfDeclaredCodepoints ? loaded->runtimeTtfDeclaredCodepoints(&count) : nullptr)
|
|
249
|
+
: generated::runtimeTtfDeclaredCodepoints(&count);
|
|
215
250
|
if (!declared || index >= count) return -1;
|
|
216
251
|
const int codepoint = declared[index];
|
|
217
252
|
return codepoint > 0 && !runtimeFixedCodepoint(codepoint) ? codepoint : -1;
|
|
@@ -271,7 +306,11 @@ bool buildRuntimeFontSlot(RuntimeRasterizedFontSlot &slot, int familyId, int siz
|
|
|
271
306
|
|
|
272
307
|
unsigned long fontLength = 0;
|
|
273
308
|
const std::uint8_t *fontBytes = runtimeFontProvider ? runtimeFontProvider->fontBytes(familyId, &fontLength) : nullptr;
|
|
274
|
-
if (!fontBytes)
|
|
309
|
+
if (!fontBytes) {
|
|
310
|
+
const auto *loaded = program::loaded();
|
|
311
|
+
fontBytes = loaded ? (loaded->lookupRuntimeTtfFontForFamily ? loaded->lookupRuntimeTtfFontForFamily(familyId, &fontLength) : nullptr)
|
|
312
|
+
: generated::lookupRuntimeTtfFontForFamily(familyId, &fontLength);
|
|
313
|
+
}
|
|
275
314
|
runtimeTtfTrace("slot.lookup family=%d bytes=%p len=%lu", familyId, static_cast<const void *>(fontBytes), fontLength);
|
|
276
315
|
if (!fontBytes || fontLength == 0) return false;
|
|
277
316
|
|
|
@@ -683,7 +722,7 @@ std::uint8_t RasterizedFont::coverage(const Glyph &glyph, int row, int col) cons
|
|
|
683
722
|
RasterizedFont FontRegistry::rasterized(int fontId)
|
|
684
723
|
{
|
|
685
724
|
ensureGeneratedFontsLinked();
|
|
686
|
-
return RasterizedFont(
|
|
725
|
+
return RasterizedFont(programLookupFont(fontId));
|
|
687
726
|
}
|
|
688
727
|
|
|
689
728
|
RasterizedFont FontRegistry::rasterizedFamily(int familyId, int sizePx)
|
|
@@ -699,7 +738,7 @@ RasterizedFont FontRegistry::rasterizedFamily(int familyId, int sizePx,int weigh
|
|
|
699
738
|
return RasterizedFont(data);
|
|
700
739
|
}
|
|
701
740
|
#endif
|
|
702
|
-
return RasterizedFont(
|
|
741
|
+
return RasterizedFont(programLookupFontForFamily(familyId, sizePx));
|
|
703
742
|
}
|
|
704
743
|
|
|
705
744
|
void FontRegistry::invalidateRuntimeFonts()
|
|
@@ -729,7 +768,7 @@ int FontRegistry::familyId(const char *family)
|
|
|
729
768
|
const int id = runtimeFontProvider->lookupFamily(family);
|
|
730
769
|
if (id >= 0) return id;
|
|
731
770
|
}
|
|
732
|
-
return
|
|
771
|
+
return programLookupFontFamily(family);
|
|
733
772
|
}
|
|
734
773
|
|
|
735
774
|
const char *FontRegistry::familyName(int familyId)
|
|
@@ -738,7 +777,7 @@ const char *FontRegistry::familyName(int familyId)
|
|
|
738
777
|
if (runtimeFontProvider) {
|
|
739
778
|
if (const char *name = runtimeFontProvider->familyName(familyId)) return name;
|
|
740
779
|
}
|
|
741
|
-
return
|
|
780
|
+
return programLookupFontFamilyName(familyId);
|
|
742
781
|
}
|
|
743
782
|
|
|
744
783
|
namespace generated {
|
package/ui/canvas_element.cpp
CHANGED
|
@@ -142,6 +142,11 @@ std::shared_ptr<CanvasContextState> CanvasRenderingContext2D::stateFor(int nodeI
|
|
|
142
142
|
|
|
143
143
|
void CanvasRenderingContext2D::releaseState(int nodeId) { contextStates().erase(nodeId); }
|
|
144
144
|
|
|
145
|
+
// An unmounting app's canvases are gone; their states are freed with the map's
|
|
146
|
+
// buckets, which would otherwise stay in internal RAM, in the middle of the
|
|
147
|
+
// block the next app allocates its large buffers from.
|
|
148
|
+
void CanvasRenderingContext2D::releaseAllStates() { std::unordered_map<int, std::shared_ptr<CanvasContextState>>().swap(contextStates()); }
|
|
149
|
+
|
|
145
150
|
namespace
|
|
146
151
|
{
|
|
147
152
|
|
package/ui/canvas_element.h
CHANGED
|
@@ -202,6 +202,7 @@ public:
|
|
|
202
202
|
static std::shared_ptr<CanvasContextState> stateFor(int nodeId);
|
|
203
203
|
// Drops canvas `nodeId`'s state, so a node id reused later starts clean.
|
|
204
204
|
static void releaseState(int nodeId);
|
|
205
|
+
static void releaseAllStates();
|
|
205
206
|
static void materializeRetainedCanvas(int nodeId);
|
|
206
207
|
static bool replayRetainedCanvas(int nodeId, std::uint32_t identity, int x, int y, int width, int height);
|
|
207
208
|
static bool hasRetainedCanvas(int nodeId);
|
package/ui/document.cpp
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
#include "document.h"
|
|
3
|
+
#include "child_node_list.h"
|
|
3
4
|
#include "selector.h"
|
|
4
5
|
#include "tree_state.h"
|
|
5
6
|
|
|
@@ -12,11 +13,14 @@
|
|
|
12
13
|
|
|
13
14
|
#include <algorithm>
|
|
14
15
|
#include <cctype>
|
|
16
|
+
#include <cmath>
|
|
15
17
|
#include <cstdlib>
|
|
16
18
|
#include <cstring>
|
|
19
|
+
#include <limits>
|
|
17
20
|
#include <utility>
|
|
18
21
|
#include <vector>
|
|
19
22
|
#include <string>
|
|
23
|
+
#include <string_view>
|
|
20
24
|
|
|
21
25
|
namespace gea::embedded::ui {
|
|
22
26
|
|
|
@@ -65,6 +69,45 @@ ViewElement Document::body() const
|
|
|
65
69
|
return ViewElement();
|
|
66
70
|
}
|
|
67
71
|
|
|
72
|
+
NodeHandle Document::documentElement() const
|
|
73
|
+
{
|
|
74
|
+
return NodeHandle(Tree::instance().mountedRoot());
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
int Document::viewportScrollX() const
|
|
78
|
+
{
|
|
79
|
+
const auto &tree = Tree::instance();
|
|
80
|
+
return tree.scrollLeft(tree.mountedRoot());
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
int Document::viewportScrollY() const
|
|
84
|
+
{
|
|
85
|
+
const auto &tree = Tree::instance();
|
|
86
|
+
return tree.scrollTop(tree.mountedRoot());
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
void Document::scrollViewportTo(double x, double y) const
|
|
90
|
+
{
|
|
91
|
+
auto &tree = Tree::instance();
|
|
92
|
+
const int root = tree.mountedRoot();
|
|
93
|
+
if (root < 0) return;
|
|
94
|
+
const auto offset = [](double value) {
|
|
95
|
+
return std::isfinite(value) ? static_cast<int>(std::clamp(value, 0.0, static_cast<double>(std::numeric_limits<int>::max()))) : 0;
|
|
96
|
+
};
|
|
97
|
+
tree.setScrollLeft(root, offset(x));
|
|
98
|
+
tree.setScrollTop(root, offset(y));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
NodeHandle Document::head() const
|
|
102
|
+
{
|
|
103
|
+
const NodeHandle root = documentElement();
|
|
104
|
+
if (!root.valid() || std::strcmp(root.tagName(), "html") != 0) return {};
|
|
105
|
+
for (NodeHandle child = root.firstChildHandle(); child.valid(); child = child.nextSiblingHandle()) {
|
|
106
|
+
if (std::strcmp(child.tagName(), "head") == 0) return child;
|
|
107
|
+
}
|
|
108
|
+
return {};
|
|
109
|
+
}
|
|
110
|
+
|
|
68
111
|
ViewElement Document::createView() const
|
|
69
112
|
{
|
|
70
113
|
return ViewElement::create();
|
|
@@ -142,6 +185,23 @@ NodeHandle Document::activeElement() const {
|
|
|
142
185
|
return node.valid()&&node.isConnected()?node:NodeHandle();
|
|
143
186
|
}
|
|
144
187
|
|
|
188
|
+
DocumentSelection Document::selection() const
|
|
189
|
+
{
|
|
190
|
+
if (!selection_.anchorNode.isConnected() || !selection_.focusNode.isConnected()) selection_ = {};
|
|
191
|
+
return selection_;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
void Document::selectAllChildren(const NodeHandle &node)
|
|
195
|
+
{
|
|
196
|
+
if (!node.isConnected()) return;
|
|
197
|
+
selection_ = {node, node, 0, node.childNodesHandle().length()};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
void Document::clearSelection()
|
|
201
|
+
{
|
|
202
|
+
selection_ = {};
|
|
203
|
+
}
|
|
204
|
+
|
|
145
205
|
NodeHandle Document::createElement(const char *tag) const
|
|
146
206
|
{
|
|
147
207
|
std::string lowered = tag ? tag : "";
|
|
@@ -158,6 +218,46 @@ NodeHandle Document::createElement(const char *tag) const
|
|
|
158
218
|
return node;
|
|
159
219
|
}
|
|
160
220
|
|
|
221
|
+
NodeHandle Document::createElementNS(const std::string &namespaceUri, const std::string &qualifiedName) const
|
|
222
|
+
{
|
|
223
|
+
constexpr std::string_view html = "http://www.w3.org/1999/xhtml";
|
|
224
|
+
constexpr std::string_view xml = "http://www.w3.org/XML/1998/namespace";
|
|
225
|
+
constexpr std::string_view xmlns = "http://www.w3.org/2000/xmlns/";
|
|
226
|
+
const auto colon = qualifiedName.find(':');
|
|
227
|
+
const bool prefixed = colon != std::string::npos;
|
|
228
|
+
const auto prefix = prefixed ? qualifiedName.substr(0, colon) : std::string{};
|
|
229
|
+
const auto local = prefixed ? qualifiedName.substr(colon + 1) : qualifiedName;
|
|
230
|
+
const auto alpha = [](unsigned char ch) { return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'); };
|
|
231
|
+
const auto nameStart = [&](unsigned char ch) { return alpha(ch) || ch == '_' || ch >= 0x80; };
|
|
232
|
+
const auto restrictedName = [&](unsigned char ch) {
|
|
233
|
+
return nameStart(ch) || (ch >= '0' && ch <= '9') || ch == '.' || ch == '-';
|
|
234
|
+
};
|
|
235
|
+
constexpr std::string_view forbidden("\0\t\n\f\r />", 8);
|
|
236
|
+
const bool validPrefix = !prefixed || (!prefix.empty() && prefix.find_first_of(forbidden) == std::string::npos);
|
|
237
|
+
const bool validLocal = !local.empty() &&
|
|
238
|
+
(alpha(local.front()) ? local.find_first_of(forbidden) == std::string::npos
|
|
239
|
+
: (nameStart(local.front()) || local.front() == ':') &&
|
|
240
|
+
std::all_of(local.begin(), local.end(), [&](unsigned char ch) { return restrictedName(ch) || ch == ':'; }));
|
|
241
|
+
if (!validPrefix || !validLocal) throw std::invalid_argument("InvalidCharacterError: invalid qualified element name");
|
|
242
|
+
if ((prefixed && namespaceUri.empty()) || (prefix == "xml" && namespaceUri != xml) ||
|
|
243
|
+
((prefix == "xmlns" || qualifiedName == "xmlns") != (namespaceUri == xmlns)))
|
|
244
|
+
throw std::invalid_argument("NamespaceError: invalid qualified element namespace");
|
|
245
|
+
const auto uriAtom = internCssAtom(namespaceUri);
|
|
246
|
+
const auto prefixAtom = internCssAtom(prefix);
|
|
247
|
+
if ((!namespaceUri.empty() && uriAtom == kInvalidCssAtom) || (prefixed && prefixAtom == kInvalidCssAtom))
|
|
248
|
+
throw std::length_error("Native namespace table exhausted");
|
|
249
|
+
auto node = namespaceUri == html && std::none_of(local.begin(), local.end(), [](char ch) { return ch >= 'A' && ch <= 'Z'; })
|
|
250
|
+
? createElement(local)
|
|
251
|
+
: NodeHandle(createView());
|
|
252
|
+
if (!node.valid()) return node;
|
|
253
|
+
auto &metadata = ensureRareData(node.id());
|
|
254
|
+
metadata.hasExplicitNamespace = true;
|
|
255
|
+
metadata.namespaceUri = uriAtom;
|
|
256
|
+
metadata.namespacePrefix = prefixAtom;
|
|
257
|
+
node.setTagName(local.c_str());
|
|
258
|
+
return node;
|
|
259
|
+
}
|
|
260
|
+
|
|
161
261
|
NodeHandle Document::getElementById(const char *id) const
|
|
162
262
|
{
|
|
163
263
|
if (!id || !*id) return {};
|
|
@@ -258,8 +358,22 @@ ViewElement Document::ensureAppRoot(const char *id) const
|
|
|
258
358
|
return root;
|
|
259
359
|
}
|
|
260
360
|
|
|
361
|
+
std::shared_ptr<void> Document::propertyStorage(const std::shared_ptr<void> &initial) const
|
|
362
|
+
{
|
|
363
|
+
std::lock_guard lock(propertyStorageMutex_);
|
|
364
|
+
if (!propertyStorage_) propertyStorage_ = initial;
|
|
365
|
+
return propertyStorage_;
|
|
366
|
+
}
|
|
367
|
+
|
|
261
368
|
void Document::clear() const
|
|
262
369
|
{
|
|
370
|
+
selection_ = {};
|
|
371
|
+
std::shared_ptr<void> retiredProperties;
|
|
372
|
+
{
|
|
373
|
+
std::lock_guard lock(propertyStorageMutex_);
|
|
374
|
+
retiredProperties.swap(propertyStorage_);
|
|
375
|
+
}
|
|
376
|
+
retiredProperties.reset();
|
|
263
377
|
g_direct_canvas_context_used = false;
|
|
264
378
|
Tree::instance().clear();
|
|
265
379
|
}
|