@geastack/engine 0.1.21 → 0.1.23
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 +24 -0
- package/image_store.cpp +308 -1
- package/package.json +1 -1
- package/ui/canvas_element.cpp +12 -16
- package/ui/canvas_store.cpp +7 -0
- package/ui/core.cpp +10 -7
- package/ui/document.cpp +25 -0
- package/ui/input.cpp +332 -11
- package/ui/input_render.cpp +62 -17
- package/ui/input_retirement.h +3 -0
- package/ui/internal.h +34 -0
- package/ui/layout.cpp +68 -16
- package/ui/layout_snapshot.cpp +119 -70
- package/ui/layout_snapshot.h +1 -0
- package/ui/node_model.h +6 -1
- package/ui/render.cpp +1126 -64
- package/ui/root_scroll_refresh.cpp +372 -66
- package/ui/root_scroll_refresh.h +4 -0
- package/ui/style.cpp +38 -21
- package/ui/svg_element.h +5 -2
- package/ui/svg_element_impl.h +475 -36
- package/ui/svg_geometry.h +78 -13
- package/ui/text.cpp +7 -6
- package/ui/tree_internal.h +17 -0
- package/ui/tree_nodes.cpp +1 -0
- package/ui/tree_render.cpp +290 -24
- package/ui/tree_state.h +9 -0
- package/ui/tree_style.cpp +8 -0
- package/ui/view.cpp +27 -9
- package/ui/viewport_region.cpp +53 -0
- package/ui/viewport_region.h +3 -0
- package/ui/virtual_keyboard.cpp +279 -23
- package/ui/virtual_keyboard_icons.h +114 -0
package/canvas.cpp
CHANGED
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
|
|
20
20
|
// For the compile-gated GEA_EMBEDDED_TEXT_SPRITE_DIAG counters (see the diag
|
|
21
21
|
// block above Canvas::drawRasterizedText). Includes must stay at file scope.
|
|
22
|
+
#ifndef GEA_EMBEDDED_TTF_RUNTIME_FONTS
|
|
23
|
+
#define GEA_EMBEDDED_TTF_RUNTIME_FONTS 0
|
|
24
|
+
#endif
|
|
22
25
|
#ifndef GEA_EMBEDDED_TEXT_SPRITE_DIAG
|
|
23
26
|
#define GEA_EMBEDDED_TEXT_SPRITE_DIAG 0
|
|
24
27
|
#endif
|
|
@@ -3324,6 +3327,27 @@ void Canvas::drawRasterizedText(const char *text, int x, int y, pixel::native_t
|
|
|
3324
3327
|
std::uint8_t *fbNib = packedRow(rowToPhysical(py));
|
|
3325
3328
|
#else
|
|
3326
3329
|
pixel::native_t *fb_row = &pixels_[rowToPhysical(py) * stride_ + gx];
|
|
3330
|
+
#if !GEA_EMBEDDED_TTF_RUNTIME_FONTS
|
|
3331
|
+
// Baked 8-bit atlas: read the glyph row directly. RasterizedFont::
|
|
3332
|
+
// coverage lives in another translation unit, so going through it
|
|
3333
|
+
// cost an out-of-line call plus its bounds checks per pixel — most
|
|
3334
|
+
// of a small label's draw time. row/col are already clipped inside
|
|
3335
|
+
// the glyph, which is all coverage() checks for.
|
|
3336
|
+
if (font.data()->atlasBits == 8) {
|
|
3337
|
+
const RasterizedFontData *fd = font.data();
|
|
3338
|
+
const std::uint8_t *covRow = fd->atlas + static_cast<std::size_t>(glyph.sourceY + row) * fd->atlasWidth + glyph.sourceX;
|
|
3339
|
+
const int ga = globalAlpha_;
|
|
3340
|
+
for (int col = col_start; col <= col_end; col++) {
|
|
3341
|
+
const int alpha = covRow[col];
|
|
3342
|
+
if (alpha == 0) continue;
|
|
3343
|
+
const std::uint8_t a = (ga == 255) ? alpha : (alpha * ga) / 255;
|
|
3344
|
+
if (a == 0) continue;
|
|
3345
|
+
pixel::native_t *pixel = &fb_row[col];
|
|
3346
|
+
*pixel = (a == 255) ? c : pixel::blendNative(c, *pixel, a);
|
|
3347
|
+
}
|
|
3348
|
+
continue;
|
|
3349
|
+
}
|
|
3350
|
+
#endif
|
|
3327
3351
|
#endif
|
|
3328
3352
|
for (int col = col_start; col <= col_end; col++) {
|
|
3329
3353
|
int alpha = font.coverage(glyph, row, col);
|
package/image_store.cpp
CHANGED
|
@@ -32,6 +32,17 @@
|
|
|
32
32
|
#include "esp_jpeg_dec.h"
|
|
33
33
|
#endif
|
|
34
34
|
|
|
35
|
+
// PNGs can stream through the S3 ROM's inflater straight into native pixels,
|
|
36
|
+
// so a decode needs the result plus ~45 KB rather than stb's whole inflated
|
|
37
|
+
// image and an RGBA copy (3.4 MB for an 800x480 picture).
|
|
38
|
+
#if !defined(GEA_EMBEDDED_ROM_PNG_STREAM) && defined(ESP_PLATFORM) && defined(CONFIG_IDF_TARGET_ESP32S3) && \
|
|
39
|
+
__has_include("miniz.h")
|
|
40
|
+
#define GEA_EMBEDDED_ROM_PNG_STREAM 1
|
|
41
|
+
#endif
|
|
42
|
+
#if defined(GEA_EMBEDDED_ROM_PNG_STREAM) && GEA_EMBEDDED_ROM_PNG_STREAM
|
|
43
|
+
#include "miniz.h"
|
|
44
|
+
#endif
|
|
45
|
+
|
|
35
46
|
// Route stb_image's allocations through the framework allocator (PSRAM-first
|
|
36
47
|
// on embedded targets). Plain malloc would land on the tiny SRAM newlib heap
|
|
37
48
|
// on the rp2350 — where pico_malloc PANICS on failure — so decoding a large
|
|
@@ -260,7 +271,7 @@ int convertRgbaToNative(const std::uint8_t *rgba, pixel::native_t *out, std::uin
|
|
|
260
271
|
|
|
261
272
|
ImageStore &ImageStore::instance()
|
|
262
273
|
{
|
|
263
|
-
static ImageStore store;
|
|
274
|
+
GEA_EXT_BSS static ImageStore store;
|
|
264
275
|
return store;
|
|
265
276
|
}
|
|
266
277
|
|
|
@@ -535,6 +546,265 @@ int ImageStore::decodeJpegTjpgd(ImageSlot &image, const std::uint8_t *data, int
|
|
|
535
546
|
}
|
|
536
547
|
#endif
|
|
537
548
|
|
|
549
|
+
#if defined(GEA_EMBEDDED_ROM_PNG_STREAM) && GEA_EMBEDDED_ROM_PNG_STREAM
|
|
550
|
+
namespace {
|
|
551
|
+
|
|
552
|
+
// Streaming PNG decode: the IDAT stream inflates through a 32 KB wrapping
|
|
553
|
+
// window, each scanline is unfiltered against the previous one as it
|
|
554
|
+
// completes and converted straight to native pixels. Peak memory is the
|
|
555
|
+
// result (plus an alpha plane when the image has transparency), two
|
|
556
|
+
// scanlines, the window and the inflater -- not the whole inflated image
|
|
557
|
+
// and an RGBA copy, which is what stb holds. Handles what assets are made
|
|
558
|
+
// of: 8-bit, non-interlaced gray, RGB, palette, gray+alpha and RGBA.
|
|
559
|
+
// Anything else returns kPngUnsupported and stays on stb.
|
|
560
|
+
constexpr int kPngUnsupported = -2;
|
|
561
|
+
|
|
562
|
+
std::uint32_t pngU32(const std::uint8_t *p)
|
|
563
|
+
{
|
|
564
|
+
return (std::uint32_t(p[0]) << 24) | (std::uint32_t(p[1]) << 16) | (std::uint32_t(p[2]) << 8) | p[3];
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
struct PngStream {
|
|
568
|
+
int width = 0;
|
|
569
|
+
int height = 0;
|
|
570
|
+
int colorType = 0;
|
|
571
|
+
int channels = 0;
|
|
572
|
+
std::size_t stride = 0; // bytes per scanline, filter byte excluded
|
|
573
|
+
std::uint8_t palette[256][4] = {};
|
|
574
|
+
bool opaqueHint = false;
|
|
575
|
+
pixel::native_t *pixels = nullptr;
|
|
576
|
+
std::uint8_t *alpha = nullptr;
|
|
577
|
+
bool hasZero = false;
|
|
578
|
+
std::uint8_t *prev = nullptr;
|
|
579
|
+
std::uint8_t *cur = nullptr; // filter byte + stride
|
|
580
|
+
std::size_t filled = 0;
|
|
581
|
+
int row = 0;
|
|
582
|
+
bool failed = false;
|
|
583
|
+
|
|
584
|
+
void emitPixel(int index, std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a)
|
|
585
|
+
{
|
|
586
|
+
pixels[index] = rgbaToNative(r, g, b, a);
|
|
587
|
+
// Same alpha plane convertRgbaToNative builds: opaque-hinted images
|
|
588
|
+
// keep only fully transparent pixels, others every non-255 value.
|
|
589
|
+
const bool keep = opaqueHint ? a == 0 : a != 255;
|
|
590
|
+
if (!keep) {
|
|
591
|
+
if (alpha) alpha[index] = 255;
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
if (a == 0) hasZero = true;
|
|
595
|
+
if (!alpha) {
|
|
596
|
+
const std::size_t count = static_cast<std::size_t>(width) * height;
|
|
597
|
+
alpha = ImageMemory::allocate<std::uint8_t>(count);
|
|
598
|
+
if (!alpha) {
|
|
599
|
+
failed = true;
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
std::memset(alpha, 255, count);
|
|
603
|
+
}
|
|
604
|
+
alpha[index] = opaqueHint ? 0 : a;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
void finishRow()
|
|
608
|
+
{
|
|
609
|
+
const int bpp = channels;
|
|
610
|
+
const std::uint8_t filter = cur[0];
|
|
611
|
+
std::uint8_t *line = cur + 1;
|
|
612
|
+
const std::uint8_t *up = prev + 1;
|
|
613
|
+
for (std::size_t i = 0; i < stride; i++) {
|
|
614
|
+
const int left = i >= static_cast<std::size_t>(bpp) ? line[i - bpp] : 0;
|
|
615
|
+
const int above = up[i];
|
|
616
|
+
const int corner = i >= static_cast<std::size_t>(bpp) ? up[i - bpp] : 0;
|
|
617
|
+
int predictor = 0;
|
|
618
|
+
switch (filter) {
|
|
619
|
+
case 0: predictor = 0; break;
|
|
620
|
+
case 1: predictor = left; break;
|
|
621
|
+
case 2: predictor = above; break;
|
|
622
|
+
case 3: predictor = (left + above) >> 1; break;
|
|
623
|
+
case 4: {
|
|
624
|
+
const int p = left + above - corner;
|
|
625
|
+
const int pa = p > left ? p - left : left - p;
|
|
626
|
+
const int pb = p > above ? p - above : above - p;
|
|
627
|
+
const int pc = p > corner ? p - corner : corner - p;
|
|
628
|
+
predictor = (pa <= pb && pa <= pc) ? left : (pb <= pc ? above : corner);
|
|
629
|
+
break;
|
|
630
|
+
}
|
|
631
|
+
default: failed = true; return;
|
|
632
|
+
}
|
|
633
|
+
line[i] = static_cast<std::uint8_t>(line[i] + predictor);
|
|
634
|
+
}
|
|
635
|
+
const int base = row * width;
|
|
636
|
+
for (int x = 0; x < width && !failed; x++) {
|
|
637
|
+
const std::uint8_t *px = line + static_cast<std::size_t>(x) * channels;
|
|
638
|
+
switch (colorType) {
|
|
639
|
+
case 0: emitPixel(base + x, px[0], px[0], px[0], 255); break;
|
|
640
|
+
case 2: emitPixel(base + x, px[0], px[1], px[2], 255); break;
|
|
641
|
+
case 3: {
|
|
642
|
+
const std::uint8_t *e = palette[px[0]];
|
|
643
|
+
emitPixel(base + x, e[0], e[1], e[2], e[3]);
|
|
644
|
+
break;
|
|
645
|
+
}
|
|
646
|
+
case 4: emitPixel(base + x, px[0], px[0], px[0], px[1]); break;
|
|
647
|
+
default: emitPixel(base + x, px[0], px[1], px[2], px[3]); break;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
std::uint8_t *swap = prev;
|
|
651
|
+
prev = cur;
|
|
652
|
+
cur = swap;
|
|
653
|
+
filled = 0;
|
|
654
|
+
row++;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
void consume(const std::uint8_t *bytes, std::size_t count)
|
|
658
|
+
{
|
|
659
|
+
while (count > 0 && row < height && !failed) {
|
|
660
|
+
const std::size_t need = stride + 1 - filled;
|
|
661
|
+
const std::size_t take = count < need ? count : need;
|
|
662
|
+
std::memcpy(cur + filled, bytes, take);
|
|
663
|
+
filled += take;
|
|
664
|
+
bytes += take;
|
|
665
|
+
count -= take;
|
|
666
|
+
if (filled == stride + 1) finishRow();
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
// Offset of the next IDAT chunk at or after `pos`, or -1.
|
|
672
|
+
long nextIdat(const std::uint8_t *data, int length, long pos)
|
|
673
|
+
{
|
|
674
|
+
while (pos + 12 <= length) {
|
|
675
|
+
const std::uint32_t size = pngU32(data + pos);
|
|
676
|
+
if (size > static_cast<std::uint32_t>(length) || pos + 12 + static_cast<long>(size) > length) return -1;
|
|
677
|
+
if (std::memcmp(data + pos + 4, "IDAT", 4) == 0) return pos;
|
|
678
|
+
if (std::memcmp(data + pos + 4, "IEND", 4) == 0) return -1;
|
|
679
|
+
pos += 12 + static_cast<long>(size);
|
|
680
|
+
}
|
|
681
|
+
return -1;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
int decodePngStreaming(ImageSlot &image, const std::uint8_t *data, int length, bool opaqueHint)
|
|
685
|
+
{
|
|
686
|
+
static const std::uint8_t kSignature[8] = {0x89, 'P', 'N', 'G', '\r', '\n', 0x1a, '\n'};
|
|
687
|
+
if (length < 33 || std::memcmp(data, kSignature, 8) != 0 || std::memcmp(data + 12, "IHDR", 4) != 0) return kPngUnsupported;
|
|
688
|
+
const std::uint32_t width = pngU32(data + 16);
|
|
689
|
+
const std::uint32_t height = pngU32(data + 20);
|
|
690
|
+
const int depth = data[24];
|
|
691
|
+
const int colorType = data[25];
|
|
692
|
+
const int interlace = data[28];
|
|
693
|
+
int channels = 0;
|
|
694
|
+
switch (colorType) {
|
|
695
|
+
case 0: channels = 1; break;
|
|
696
|
+
case 2: channels = 3; break;
|
|
697
|
+
case 3: channels = 1; break;
|
|
698
|
+
case 4: channels = 2; break;
|
|
699
|
+
case 6: channels = 4; break;
|
|
700
|
+
default: return kPngUnsupported;
|
|
701
|
+
}
|
|
702
|
+
if (depth != 8 || interlace != 0 || width == 0 || height == 0 || width > 16384 || height > 16384) return kPngUnsupported;
|
|
703
|
+
|
|
704
|
+
PngStream png;
|
|
705
|
+
png.width = static_cast<int>(width);
|
|
706
|
+
png.height = static_cast<int>(height);
|
|
707
|
+
png.colorType = colorType;
|
|
708
|
+
png.channels = channels;
|
|
709
|
+
png.stride = static_cast<std::size_t>(width) * channels;
|
|
710
|
+
png.opaqueHint = opaqueHint;
|
|
711
|
+
|
|
712
|
+
// Palette and tRNS precede the image data.
|
|
713
|
+
bool havePalette = false;
|
|
714
|
+
for (long pos = 33; pos + 12 <= length;) {
|
|
715
|
+
const std::uint32_t size = pngU32(data + pos);
|
|
716
|
+
if (pos + 12 + static_cast<long>(size) > length) return kPngUnsupported;
|
|
717
|
+
const std::uint8_t *body = data + pos + 8;
|
|
718
|
+
if (std::memcmp(data + pos + 4, "IDAT", 4) == 0 || std::memcmp(data + pos + 4, "IEND", 4) == 0) break;
|
|
719
|
+
if (std::memcmp(data + pos + 4, "PLTE", 4) == 0) {
|
|
720
|
+
for (std::uint32_t i = 0; i < size / 3 && i < 256; i++) {
|
|
721
|
+
png.palette[i][0] = body[i * 3];
|
|
722
|
+
png.palette[i][1] = body[i * 3 + 1];
|
|
723
|
+
png.palette[i][2] = body[i * 3 + 2];
|
|
724
|
+
png.palette[i][3] = 255;
|
|
725
|
+
}
|
|
726
|
+
havePalette = true;
|
|
727
|
+
} else if (std::memcmp(data + pos + 4, "tRNS", 4) == 0) {
|
|
728
|
+
// Colour-key transparency on gray/RGB is rare in assets; leave it to stb.
|
|
729
|
+
if (colorType != 3) return kPngUnsupported;
|
|
730
|
+
for (std::uint32_t i = 0; i < size && i < 256; i++) png.palette[i][3] = body[i];
|
|
731
|
+
}
|
|
732
|
+
pos += 12 + static_cast<long>(size);
|
|
733
|
+
}
|
|
734
|
+
if (colorType == 3 && !havePalette) return kPngUnsupported;
|
|
735
|
+
long idat = nextIdat(data, length, 33);
|
|
736
|
+
if (idat < 0) return kPngUnsupported;
|
|
737
|
+
|
|
738
|
+
const std::size_t pixelCount = static_cast<std::size_t>(width) * height;
|
|
739
|
+
png.pixels = ImageMemory::allocate<pixel::native_t>(pixelCount);
|
|
740
|
+
png.prev = ImageMemory::allocate<std::uint8_t>(png.stride + 1);
|
|
741
|
+
png.cur = ImageMemory::allocate<std::uint8_t>(png.stride + 1);
|
|
742
|
+
auto *inflator = ImageMemory::allocate<tinfl_decompressor>();
|
|
743
|
+
auto *window = ImageMemory::allocate<std::uint8_t>(TINFL_LZ_DICT_SIZE);
|
|
744
|
+
auto cleanup = [&](bool keepResult) {
|
|
745
|
+
ImageMemory::release(png.prev);
|
|
746
|
+
ImageMemory::release(png.cur);
|
|
747
|
+
ImageMemory::release(inflator);
|
|
748
|
+
ImageMemory::release(window);
|
|
749
|
+
if (!keepResult) {
|
|
750
|
+
ImageMemory::release(png.pixels);
|
|
751
|
+
ImageMemory::release(png.alpha);
|
|
752
|
+
}
|
|
753
|
+
};
|
|
754
|
+
if (!png.pixels || !png.prev || !png.cur || !inflator || !window) {
|
|
755
|
+
cleanup(false);
|
|
756
|
+
return -1;
|
|
757
|
+
}
|
|
758
|
+
std::memset(png.prev, 0, png.stride + 1);
|
|
759
|
+
tinfl_init(inflator);
|
|
760
|
+
|
|
761
|
+
std::size_t windowOffset = 0;
|
|
762
|
+
const std::uint8_t *in = data + idat + 8;
|
|
763
|
+
std::size_t inLeft = pngU32(data + idat);
|
|
764
|
+
long following = nextIdat(data, length, idat + 12 + static_cast<long>(inLeft));
|
|
765
|
+
tinfl_status status = TINFL_STATUS_NEEDS_MORE_INPUT;
|
|
766
|
+
while (!png.failed) {
|
|
767
|
+
std::size_t inSize = inLeft;
|
|
768
|
+
std::size_t outSize = TINFL_LZ_DICT_SIZE - windowOffset;
|
|
769
|
+
const mz_uint32 flags = TINFL_FLAG_PARSE_ZLIB_HEADER | (following >= 0 ? TINFL_FLAG_HAS_MORE_INPUT : 0);
|
|
770
|
+
status = tinfl_decompress(inflator, in, &inSize, window, window + windowOffset, &outSize, flags);
|
|
771
|
+
in += inSize;
|
|
772
|
+
inLeft -= inSize;
|
|
773
|
+
png.consume(window + windowOffset, outSize);
|
|
774
|
+
windowOffset = (windowOffset + outSize) & (TINFL_LZ_DICT_SIZE - 1);
|
|
775
|
+
if (status == TINFL_STATUS_DONE || png.row >= png.height) break;
|
|
776
|
+
if (status < 0) break;
|
|
777
|
+
if (status == TINFL_STATUS_NEEDS_MORE_INPUT && inLeft == 0) {
|
|
778
|
+
if (following < 0) break;
|
|
779
|
+
idat = following;
|
|
780
|
+
in = data + idat + 8;
|
|
781
|
+
inLeft = pngU32(data + idat);
|
|
782
|
+
following = nextIdat(data, length, idat + 12 + static_cast<long>(inLeft));
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
if (png.failed || png.row < png.height) {
|
|
786
|
+
cleanup(false);
|
|
787
|
+
return -1;
|
|
788
|
+
}
|
|
789
|
+
if (opaqueHint && png.alpha && !png.hasZero) {
|
|
790
|
+
ImageMemory::release(png.alpha);
|
|
791
|
+
png.alpha = nullptr;
|
|
792
|
+
}
|
|
793
|
+
cleanup(true);
|
|
794
|
+
image.width = png.width;
|
|
795
|
+
image.height = png.height;
|
|
796
|
+
image.frameCount = 1;
|
|
797
|
+
image.pixels = png.pixels;
|
|
798
|
+
image.ownsPixels = true;
|
|
799
|
+
image.alpha = png.alpha;
|
|
800
|
+
image.loopCount = 0;
|
|
801
|
+
image.playing = false;
|
|
802
|
+
return 0;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
} // namespace
|
|
806
|
+
#endif
|
|
807
|
+
|
|
538
808
|
int ImageStore::decodeStatic(ImageSlot &image, const std::uint8_t *data, int length, bool opaqueHint)
|
|
539
809
|
{
|
|
540
810
|
int width = 0;
|
|
@@ -638,6 +908,13 @@ int ImageStore::decodeStatic(ImageSlot &image, const std::uint8_t *data, int len
|
|
|
638
908
|
}
|
|
639
909
|
#endif
|
|
640
910
|
|
|
911
|
+
#if defined(GEA_EMBEDDED_ROM_PNG_STREAM) && GEA_EMBEDDED_ROM_PNG_STREAM
|
|
912
|
+
if (detectFormat(data, length) == ImageFormat::Png) {
|
|
913
|
+
const int rc = decodePngStreaming(image, data, length, opaqueHint);
|
|
914
|
+
if (rc != kPngUnsupported) return rc;
|
|
915
|
+
}
|
|
916
|
+
#endif
|
|
917
|
+
|
|
641
918
|
stbi_uc *rgba = stbi_load_from_memory(data, length, &width, &height, &components, 4);
|
|
642
919
|
if (!rgba) return -1;
|
|
643
920
|
|
|
@@ -761,9 +1038,39 @@ void ImageStore::materializeDeferred(int id) const
|
|
|
761
1038
|
image->deferredData = nullptr;
|
|
762
1039
|
image->deferredLength = 0;
|
|
763
1040
|
image->deferredOpaque = false;
|
|
1041
|
+
image->sourceData = data;
|
|
1042
|
+
image->sourceLength = length;
|
|
1043
|
+
image->sourceOpaque = opaque;
|
|
764
1044
|
self->decodeStatic(*image, data, length, opaque);
|
|
765
1045
|
}
|
|
766
1046
|
|
|
1047
|
+
#ifndef GEA_IMAGE_IDLE_DECODE_RELEASE_BYTES
|
|
1048
|
+
#define GEA_IMAGE_IDLE_DECODE_RELEASE_BYTES (256 * 1024)
|
|
1049
|
+
#endif
|
|
1050
|
+
|
|
1051
|
+
void ImageStore::releaseIdleDecodes()
|
|
1052
|
+
{
|
|
1053
|
+
ImageStoreLock lock(slotMutex_);
|
|
1054
|
+
for (int id = 0; id < kImageMax; ++id) {
|
|
1055
|
+
ImageSlot &image = images_[id];
|
|
1056
|
+
if (!used_[id] || references_[id] != 0 || retired_[id]) continue;
|
|
1057
|
+
if (!image.sourceData || !image.ownsPixels || !image.pixels || image.mutablePixels) continue;
|
|
1058
|
+
const std::size_t bytes = static_cast<std::size_t>(image.width) * static_cast<std::size_t>(image.height) *
|
|
1059
|
+
sizeof(pixel::native_t);
|
|
1060
|
+
if (bytes < GEA_IMAGE_IDLE_DECODE_RELEASE_BYTES) continue;
|
|
1061
|
+
ImageMemory::release(image.pixels);
|
|
1062
|
+
ImageMemory::release(image.alpha);
|
|
1063
|
+
image.pixels = nullptr;
|
|
1064
|
+
image.alpha = nullptr;
|
|
1065
|
+
image.ownsPixels = false;
|
|
1066
|
+
image.deferredData = image.sourceData;
|
|
1067
|
+
image.deferredLength = image.sourceLength;
|
|
1068
|
+
image.deferredOpaque = image.sourceOpaque;
|
|
1069
|
+
image.sourceData = nullptr;
|
|
1070
|
+
image.sourceLength = 0;
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
|
|
767
1074
|
int ImageStore::decode(const std::uint8_t *data, int length, int preferredSlot)
|
|
768
1075
|
{
|
|
769
1076
|
return decodeWithHint(data, length, preferredSlot, false);
|
package/package.json
CHANGED
package/ui/canvas_element.cpp
CHANGED
|
@@ -980,20 +980,18 @@ void CanvasRenderingContext2D::drawImage(int imageId, int dx, int dy, int dw, in
|
|
|
980
980
|
gCanvasPerfStats.drawImageUs += nowUs() - started;
|
|
981
981
|
}
|
|
982
982
|
void CanvasRenderingContext2D::drawImage(int imageId, double x, double y, double w, double h) { drawImage(imageId, rounded(x), rounded(y), rounded(w), rounded(h)); }
|
|
983
|
+
// Measuring reads font metrics only. Asking for a drawing surface here would
|
|
984
|
+
// replay the batch recorded so far and drop it off the display present path.
|
|
983
985
|
double CanvasRenderingContext2D::measureTextInkCenter(const std::string &text)
|
|
984
986
|
{
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
if (!surface) return 0.0;
|
|
988
|
-
return static_cast<double>(surface->measureTextInkCenterFontFamily(text.c_str(), state_->fontFamilyId_, state_->fontSizePx_));
|
|
987
|
+
return static_cast<double>(
|
|
988
|
+
gea::framework::graphics::Canvas::measureTextInkCenterFontFamily(text.c_str(), state_->fontFamilyId_, state_->fontSizePx_));
|
|
989
989
|
}
|
|
990
990
|
|
|
991
991
|
double CanvasRenderingContext2D::measureText(const std::string &text)
|
|
992
992
|
{
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
if (!surface) return 0.0;
|
|
996
|
-
return static_cast<double>(surface->measureTextFontFamily(text.c_str(), state_->fontFamilyId_, state_->fontSizePx_));
|
|
993
|
+
return static_cast<double>(
|
|
994
|
+
gea::framework::graphics::Canvas::measureTextFontFamily(text.c_str(), state_->fontFamilyId_, state_->fontSizePx_));
|
|
997
995
|
}
|
|
998
996
|
|
|
999
997
|
void CanvasRenderingContext2D::drawImageCircle(int imageId, int dx, int dy, int dw, int dh)
|
|
@@ -2350,20 +2348,18 @@ void CanvasRenderingContext2D::drawImage(int imageId, double dx, double dy, doub
|
|
|
2350
2348
|
drawImage(imageId, rounded(dx), rounded(dy), rounded(dw), rounded(dh));
|
|
2351
2349
|
}
|
|
2352
2350
|
|
|
2351
|
+
// Measuring reads font metrics only. Asking for a drawing surface here would
|
|
2352
|
+
// replay the batch recorded so far and drop it off the display present path.
|
|
2353
2353
|
double CanvasRenderingContext2D::measureTextInkCenter(const std::string &text)
|
|
2354
2354
|
{
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
if (!surface) return 0.0;
|
|
2358
|
-
return static_cast<double>(surface->measureTextInkCenterFontFamily(text.c_str(), state_->fontFamilyId_, state_->fontSizePx_));
|
|
2355
|
+
return static_cast<double>(
|
|
2356
|
+
gea::framework::graphics::Canvas::measureTextInkCenterFontFamily(text.c_str(), state_->fontFamilyId_, state_->fontSizePx_));
|
|
2359
2357
|
}
|
|
2360
2358
|
|
|
2361
2359
|
double CanvasRenderingContext2D::measureText(const std::string &text)
|
|
2362
2360
|
{
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
if (!surface) return 0.0;
|
|
2366
|
-
return static_cast<double>(surface->measureTextFontFamily(text.c_str(), state_->fontFamilyId_, state_->fontSizePx_));
|
|
2361
|
+
return static_cast<double>(
|
|
2362
|
+
gea::framework::graphics::Canvas::measureTextFontFamily(text.c_str(), state_->fontFamilyId_, state_->fontSizePx_));
|
|
2367
2363
|
}
|
|
2368
2364
|
|
|
2369
2365
|
void CanvasRenderingContext2D::drawImageCircle(int imageId, int dx, int dy, int dw, int dh)
|
package/ui/canvas_store.cpp
CHANGED
|
@@ -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/core.cpp
CHANGED
|
@@ -130,13 +130,16 @@ bool Tree::refreshRequired() const
|
|
|
130
130
|
}
|
|
131
131
|
#if !defined(GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT) || !GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT
|
|
132
132
|
if (!reason && !Document::directCanvasContextUsed()) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
133
|
+
// A display-backed canvas owns every display pixel (it is only granted
|
|
134
|
+
// when it covers the panel and nothing else draws), so the display's dirty
|
|
135
|
+
// box says nothing a refresh could repaint. Reading it is not free either:
|
|
136
|
+
// a double-buffered panel's canvas() waits for the scanout to release the
|
|
137
|
+
// buffer just swapped in, which stalled every frame of a full-screen canvas
|
|
138
|
+
// app under a wrapper element by up to two panel periods.
|
|
139
|
+
bool displayBackedCanvas = false;
|
|
140
|
+
for (int i = 0; i < state.nodeCount && !displayBackedCanvas; i++)
|
|
141
|
+
displayBackedCanvas = state.nodes[i].type == NodeType::Canvas && isDisplayBackedCanvas(i);
|
|
142
|
+
if (!displayBackedCanvas) {
|
|
140
143
|
if (auto *canvas = gea::platform::display::Display::canvas()) {
|
|
141
144
|
if (canvas->dirty(nullptr, nullptr, nullptr, nullptr)) reason = 3;
|
|
142
145
|
}
|
package/ui/document.cpp
CHANGED
|
@@ -320,6 +320,7 @@ namespace
|
|
|
320
320
|
gea::framework::display::Underlay::Paint underlayPaint = nullptr;
|
|
321
321
|
void *underlayUser = nullptr;
|
|
322
322
|
int underlayX0 = 0, underlayY0 = 0, underlayX1 = -1, underlayY1 = -1;
|
|
323
|
+
bool underlayOpaque = false;
|
|
323
324
|
} // namespace
|
|
324
325
|
|
|
325
326
|
bool gea::framework::display::Underlay::composited()
|
|
@@ -335,12 +336,24 @@ void gea::framework::display::Underlay::set(Paint paint, void *user, int x0, int
|
|
|
335
336
|
underlayY0 = y0;
|
|
336
337
|
underlayX1 = x1;
|
|
337
338
|
underlayY1 = y1;
|
|
339
|
+
underlayOpaque = false;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
void gea::framework::display::Underlay::setOpaque(bool opaque)
|
|
343
|
+
{
|
|
344
|
+
underlayOpaque = opaque;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
bool gea::framework::display::Underlay::covers(int x0, int y0, int x1, int y1)
|
|
348
|
+
{
|
|
349
|
+
return underlayPaint && underlayOpaque && x0 >= underlayX0 && y0 >= underlayY0 && x1 <= underlayX1 && y1 <= underlayY1;
|
|
338
350
|
}
|
|
339
351
|
|
|
340
352
|
void gea::framework::display::Underlay::clear()
|
|
341
353
|
{
|
|
342
354
|
underlayPaint = nullptr;
|
|
343
355
|
underlayUser = nullptr;
|
|
356
|
+
underlayOpaque = false;
|
|
344
357
|
}
|
|
345
358
|
|
|
346
359
|
bool gea::framework::display::Underlay::active()
|
|
@@ -357,4 +370,16 @@ void gea::framework::display::Underlay::paint(int x0, int y0, int x1, int y1)
|
|
|
357
370
|
y1 = std::min(y1, underlayY1);
|
|
358
371
|
if (x0 > x1 || y0 > y1) return;
|
|
359
372
|
underlayPaint(x0, y0, x1, y1, underlayUser);
|
|
373
|
+
// The painter writes pixels directly, so the canvas has no record of them.
|
|
374
|
+
// A display that stages the replay in a strip copies back only the canvas's
|
|
375
|
+
// dirty box, which left the frame black under everything but the HUD text.
|
|
376
|
+
if (auto *canvas = gea::platform::display::Display::canvas()) {
|
|
377
|
+
int cx0 = 0, cy0 = 0, cx1 = -1, cy1 = -1;
|
|
378
|
+
canvas->currentClip(&cx0, &cy0, &cx1, &cy1);
|
|
379
|
+
x0 = std::max(x0, cx0);
|
|
380
|
+
y0 = std::max(y0, cy0);
|
|
381
|
+
x1 = std::min(x1, cx1);
|
|
382
|
+
y1 = std::min(y1, cy1);
|
|
383
|
+
if (x0 <= x1 && y0 <= y1) canvas->markDirty(x0, y0, x1, y1);
|
|
384
|
+
}
|
|
360
385
|
}
|