@geastack/engine 0.1.13 → 0.1.15
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 +375 -66
- package/image_store.cpp +15 -0
- package/package.json +2 -2
- package/ui/canvas_element.cpp +334 -261
- package/ui/canvas_element.h +56 -33
- package/ui/layout.cpp +6 -2
- package/ui/render.cpp +386 -35
- package/ui/tree_internal.h +21 -0
- package/ui/tree_nodes.cpp +4 -1
- package/ui/tree_render.cpp +244 -6
- package/ui/view.cpp +14 -0
package/canvas.cpp
CHANGED
|
@@ -547,74 +547,309 @@ static inline bool roundedRectSampleContains(int x,
|
|
|
547
547
|
return true;
|
|
548
548
|
}
|
|
549
549
|
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
550
|
+
// `roundedRectSampleContains` over a pixel's whole sample grid, as a bit
|
|
551
|
+
// mask (bit iy * samples + ix). The same zone order and the same float
|
|
552
|
+
// expressions, but each corner's scaled x and y distances are taken once per
|
|
553
|
+
// sample column and row, not once per sample, and only for the corners the
|
|
554
|
+
// grid reaches.
|
|
555
|
+
static inline std::uint32_t roundedRectSampleMask(int x,
|
|
556
|
+
int y,
|
|
557
|
+
int w,
|
|
558
|
+
int h,
|
|
559
|
+
int tl,
|
|
560
|
+
int tr,
|
|
561
|
+
int br,
|
|
562
|
+
int bl,
|
|
563
|
+
int px,
|
|
564
|
+
int py,
|
|
565
|
+
int samples,
|
|
566
|
+
float kernelWidth)
|
|
562
567
|
{
|
|
563
|
-
|
|
568
|
+
const float left = static_cast<float>(x);
|
|
569
|
+
const float top = static_cast<float>(y);
|
|
570
|
+
const float right = left + static_cast<float>(w);
|
|
571
|
+
const float bottom = top + static_cast<float>(h);
|
|
572
|
+
float sx[4], sy[4];
|
|
573
|
+
for (int i = 0; i < samples; ++i) {
|
|
574
|
+
sx[i] = static_cast<float>(px) + antialiasOffsetWithKernel(i, samples, kernelWidth);
|
|
575
|
+
sy[i] = static_cast<float>(py) + antialiasOffsetWithKernel(i, samples, kernelWidth);
|
|
576
|
+
}
|
|
577
|
+
// Corner order matches the sample test: tl, tr, br, bl.
|
|
578
|
+
const int radii[4]{tl, tr, br, bl};
|
|
579
|
+
const bool leftSide[4]{true, false, false, true};
|
|
580
|
+
const bool topSide[4]{true, true, false, false};
|
|
581
|
+
std::uint32_t zoneX[4]{}, zoneY[4]{};
|
|
582
|
+
float dxs[4][4], dys[4][4];
|
|
583
|
+
for (int c = 0; c < 4; ++c) {
|
|
584
|
+
const int radius = radii[c];
|
|
585
|
+
if (radius <= 0) continue;
|
|
586
|
+
const float rf = static_cast<float>(radius);
|
|
587
|
+
const float cx = leftSide[c] ? left + rf : right - rf;
|
|
588
|
+
const float cy = topSide[c] ? top + rf : bottom - rf;
|
|
589
|
+
for (int i = 0; i < samples; ++i) {
|
|
590
|
+
if (leftSide[c] ? sx[i] < cx : sx[i] >= cx) zoneX[c] |= 1u << i;
|
|
591
|
+
if (topSide[c] ? sy[i] < cy : sy[i] >= cy) zoneY[c] |= 1u << i;
|
|
592
|
+
}
|
|
593
|
+
if (!zoneX[c] || !zoneY[c]) {
|
|
594
|
+
zoneX[c] = zoneY[c] = 0;
|
|
595
|
+
continue;
|
|
596
|
+
}
|
|
597
|
+
for (int i = 0; i < samples; ++i) {
|
|
598
|
+
dxs[c][i] = (sx[i] - cx) / rf;
|
|
599
|
+
dys[c][i] = (sy[i] - cy) / rf;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
std::uint32_t mask = 0;
|
|
564
603
|
for (int iy = 0; iy < samples; ++iy) {
|
|
565
|
-
|
|
604
|
+
if (sy[iy] < top || sy[iy] >= bottom) continue;
|
|
566
605
|
for (int ix = 0; ix < samples; ++ix) {
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
606
|
+
if (sx[ix] < left || sx[ix] >= right) continue;
|
|
607
|
+
bool inside = true;
|
|
608
|
+
for (int c = 0; c < 4; ++c) {
|
|
609
|
+
if (!((zoneX[c] >> ix) & 1u) || !((zoneY[c] >> iy) & 1u)) continue;
|
|
610
|
+
const float dx = dxs[c][ix];
|
|
611
|
+
const float dy = dys[c][iy];
|
|
612
|
+
inside = dx * dx + dy * dy <= 1.0f;
|
|
613
|
+
break;
|
|
614
|
+
}
|
|
615
|
+
if (inside) mask |= 1u << (iy * samples + ix);
|
|
572
616
|
}
|
|
573
617
|
}
|
|
574
|
-
return
|
|
618
|
+
return mask;
|
|
575
619
|
}
|
|
576
620
|
|
|
577
|
-
static inline int
|
|
578
|
-
|
|
579
|
-
int w,
|
|
580
|
-
int h,
|
|
581
|
-
int tl,
|
|
582
|
-
int tr,
|
|
583
|
-
int br,
|
|
584
|
-
int bl,
|
|
585
|
-
int lineWidth,
|
|
586
|
-
int px,
|
|
587
|
-
int py,
|
|
588
|
-
int samples,
|
|
589
|
-
float kernelWidth)
|
|
621
|
+
static inline int roundedRectCoverage(int x, int y, int w, int h, int tl, int tr, int br, int bl,
|
|
622
|
+
int px, int py, int samples, float kernelWidth)
|
|
590
623
|
{
|
|
591
|
-
|
|
592
|
-
|
|
624
|
+
return __builtin_popcount(roundedRectSampleMask(x, y, w, h, tl, tr, br, bl, px, py, samples, kernelWidth));
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
static inline int roundedRectStrokeCoverage(int x, int y, int w, int h, int tl, int tr, int br, int bl,
|
|
628
|
+
int lineWidth, int px, int py, int samples, float kernelWidth)
|
|
629
|
+
{
|
|
630
|
+
std::uint32_t band = roundedRectSampleMask(x, y, w, h, tl, tr, br, bl, px, py, samples, kernelWidth);
|
|
593
631
|
const int innerW = w - lineWidth * 2;
|
|
594
632
|
const int innerH = h - lineWidth * 2;
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
633
|
+
if (band && innerW > 0 && innerH > 0)
|
|
634
|
+
band &= ~roundedRectSampleMask(x + lineWidth, y + lineWidth, innerW, innerH, std::max(0, tl - lineWidth),
|
|
635
|
+
std::max(0, tr - lineWidth), std::max(0, br - lineWidth),
|
|
636
|
+
std::max(0, bl - lineWidth), px, py, samples, kernelWidth);
|
|
637
|
+
return __builtin_popcount(band);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
// Whether every sample in [x0, x1] x [y0, y1] passes
|
|
641
|
+
// `roundedRectSampleContains` (1), none does (0), or it varies (-1). Outside
|
|
642
|
+
// the corner zones the shape is its bounds; a span wholly inside one corner
|
|
643
|
+
// zone is decided by its nearest and farthest distance from that corner's
|
|
644
|
+
// centre, with a margin far wider than the float rounding of the per-sample
|
|
645
|
+
// test. Zones are taken in the sample test's order, so overlapping zones
|
|
646
|
+
// resolve the same way.
|
|
647
|
+
static inline int roundedRectSamplesDecided(int x, int y, int w, int h, int tl, int tr, int br, int bl,
|
|
648
|
+
float x0, float y0, float x1, float y1)
|
|
649
|
+
{
|
|
650
|
+
const float left = static_cast<float>(x);
|
|
651
|
+
const float top = static_cast<float>(y);
|
|
652
|
+
const float right = left + static_cast<float>(w);
|
|
653
|
+
const float bottom = top + static_cast<float>(h);
|
|
654
|
+
if (x1 < left || x0 >= right || y1 < top || y0 >= bottom) return 0;
|
|
655
|
+
if (x0 < left || x1 >= right || y0 < top || y1 >= bottom) return -1;
|
|
656
|
+
auto circle = [&](float cx, float cy, int radius) {
|
|
657
|
+
const float r2 = static_cast<float>(radius) * static_cast<float>(radius);
|
|
658
|
+
const float nx = cx < x0 ? x0 - cx : cx > x1 ? cx - x1 : 0.0f;
|
|
659
|
+
const float ny = cy < y0 ? y0 - cy : cy > y1 ? cy - y1 : 0.0f;
|
|
660
|
+
const float fx = std::max(std::fabs(x0 - cx), std::fabs(x1 - cx));
|
|
661
|
+
const float fy = std::max(std::fabs(y0 - cy), std::fabs(y1 - cy));
|
|
662
|
+
if (fx * fx + fy * fy <= r2 * 0.999f) return 1;
|
|
663
|
+
if (nx * nx + ny * ny >= r2 * 1.001f) return 0;
|
|
664
|
+
return -1;
|
|
665
|
+
};
|
|
666
|
+
if (tl > 0 && x0 < left + static_cast<float>(tl) && y0 < top + static_cast<float>(tl)) {
|
|
667
|
+
if (x1 >= left + static_cast<float>(tl) || y1 >= top + static_cast<float>(tl)) return -1;
|
|
668
|
+
return circle(left + static_cast<float>(tl), top + static_cast<float>(tl), tl);
|
|
669
|
+
}
|
|
670
|
+
if (tr > 0 && x1 >= right - static_cast<float>(tr) && y0 < top + static_cast<float>(tr)) {
|
|
671
|
+
if (x0 < right - static_cast<float>(tr) || y1 >= top + static_cast<float>(tr)) return -1;
|
|
672
|
+
return circle(right - static_cast<float>(tr), top + static_cast<float>(tr), tr);
|
|
673
|
+
}
|
|
674
|
+
if (br > 0 && x1 >= right - static_cast<float>(br) && y1 >= bottom - static_cast<float>(br)) {
|
|
675
|
+
if (x0 < right - static_cast<float>(br) || y0 < bottom - static_cast<float>(br)) return -1;
|
|
676
|
+
return circle(right - static_cast<float>(br), bottom - static_cast<float>(br), br);
|
|
677
|
+
}
|
|
678
|
+
if (bl > 0 && x0 < left + static_cast<float>(bl) && y1 >= bottom - static_cast<float>(bl)) {
|
|
679
|
+
if (x1 >= left + static_cast<float>(bl) || y0 < bottom - static_cast<float>(bl)) return -1;
|
|
680
|
+
return circle(left + static_cast<float>(bl), bottom - static_cast<float>(bl), bl);
|
|
681
|
+
}
|
|
682
|
+
return 1;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
// `roundedRectCoverage` without sampling where its answer is decided. -1 =
|
|
686
|
+
// sample it. `o0`/`o1` are the first and last sample offsets.
|
|
687
|
+
static inline int roundedRectCoverageDecided(int x, int y, int w, int h, int tl, int tr, int br, int bl,
|
|
688
|
+
int px, int py, float o0, float o1, int sampleCount)
|
|
689
|
+
{
|
|
690
|
+
const float x0 = static_cast<float>(px) + o0, x1 = static_cast<float>(px) + o1;
|
|
691
|
+
const float y0 = static_cast<float>(py) + o0, y1 = static_cast<float>(py) + o1;
|
|
692
|
+
const int decided = roundedRectSamplesDecided(x, y, w, h, tl, tr, br, bl, x0, y0, x1, y1);
|
|
693
|
+
return decided < 0 ? -1 : decided ? sampleCount : 0;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
// `roundedRectStrokeCoverage` without sampling where its answer is decided:
|
|
697
|
+
// a pixel whose samples are all inside the outer contour and all outside the
|
|
698
|
+
// inner one is fully covered, one whose samples all miss the band is not.
|
|
699
|
+
// -1 = sample it. `o0`/`o1` are the first and last sample offsets.
|
|
700
|
+
static inline int roundedRectStrokeCoverageDecided(int x, int y, int w, int h, int tl, int tr, int br, int bl,
|
|
701
|
+
int lineWidth, int px, int py, float o0, float o1, int sampleCount)
|
|
702
|
+
{
|
|
703
|
+
const float x0 = static_cast<float>(px) + o0, x1 = static_cast<float>(px) + o1;
|
|
704
|
+
const float y0 = static_cast<float>(py) + o0, y1 = static_cast<float>(py) + o1;
|
|
705
|
+
const int outer = roundedRectSamplesDecided(x, y, w, h, tl, tr, br, bl, x0, y0, x1, y1);
|
|
706
|
+
if (outer <= 0) return outer;
|
|
707
|
+
const int innerW = w - lineWidth * 2;
|
|
708
|
+
const int innerH = h - lineWidth * 2;
|
|
709
|
+
if (innerW <= 0 || innerH <= 0) return sampleCount;
|
|
710
|
+
const int inner = roundedRectSamplesDecided(x + lineWidth, y + lineWidth, innerW, innerH, std::max(0, tl - lineWidth),
|
|
711
|
+
std::max(0, tr - lineWidth), std::max(0, br - lineWidth),
|
|
712
|
+
std::max(0, bl - lineWidth), x0, y0, x1, y1);
|
|
713
|
+
return inner < 0 ? -1 : inner ? 0 : sampleCount;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
// The columns of row `py` whose every sample passes `roundedRectSampleContains`,
|
|
717
|
+
// as [*inX0, *inX1] (empty when *inX0 > *inX1). Conservative: a column it
|
|
718
|
+
// leaves out is merely sampled. Each corner insets the row by its chord at the
|
|
719
|
+
// sample row deepest into it, widened by a margin far beyond the per-sample
|
|
720
|
+
// test's float rounding, so whichever zone the test picks, the sample is
|
|
721
|
+
// inside that zone's circle.
|
|
722
|
+
static inline void roundedRectInsideSpan(int x, int y, int w, int h, int tl, int tr, int br, int bl,
|
|
723
|
+
int py, float o0, float o1, int *inX0, int *inX1)
|
|
724
|
+
{
|
|
725
|
+
*inX0 = 0;
|
|
726
|
+
*inX1 = -1;
|
|
727
|
+
const float left = static_cast<float>(x);
|
|
728
|
+
const float top = static_cast<float>(y);
|
|
729
|
+
const float right = left + static_cast<float>(w);
|
|
730
|
+
const float bottom = top + static_cast<float>(h);
|
|
731
|
+
const float y0 = static_cast<float>(py) + o0;
|
|
732
|
+
const float y1 = static_cast<float>(py) + o1;
|
|
733
|
+
if (y0 < top || y1 >= bottom) return;
|
|
734
|
+
auto inset = [](int radius, float depth) {
|
|
735
|
+
if (radius <= 0 || depth <= 0.0f) return 0.0f;
|
|
736
|
+
const float r = static_cast<float>(radius);
|
|
737
|
+
const float chord2 = r * r - depth * depth;
|
|
738
|
+
return r - (chord2 > 0.0f ? std::sqrt(chord2) : 0.0f) + 0.01f;
|
|
739
|
+
};
|
|
740
|
+
const float leftInset = std::max(inset(tl, top + static_cast<float>(tl) - y0),
|
|
741
|
+
inset(bl, y1 - (bottom - static_cast<float>(bl))));
|
|
742
|
+
const float rightInset = std::max(inset(tr, top + static_cast<float>(tr) - y0),
|
|
743
|
+
inset(br, y1 - (bottom - static_cast<float>(br))));
|
|
744
|
+
// px + o0 >= left + leftInset and px + o1 < right - rightInset.
|
|
745
|
+
*inX0 = static_cast<int>(std::ceil(left + leftInset - o0));
|
|
746
|
+
*inX1 = static_cast<int>(std::ceil(right - rightInset - o1)) - 1;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
// Columns of row `py` whose samples ([px + o0, px + o1] squared) can reach the
|
|
750
|
+
// rounded rect [x, x + w) x [y, y + h); every other pixel has zero coverage.
|
|
751
|
+
// The widest the shape gets over the row's sample band is at the band edge
|
|
752
|
+
// nearest each corner's centre; a pixel of margin keeps it conservative.
|
|
753
|
+
static inline bool roundedRectReachSpan(int x, int y, int w, int h, int tl, int tr, int br, int bl,
|
|
754
|
+
int py, float o0, float o1, int *outX0, int *outX1)
|
|
755
|
+
{
|
|
756
|
+
const float left = static_cast<float>(x);
|
|
757
|
+
const float top = static_cast<float>(y);
|
|
758
|
+
const float right = left + static_cast<float>(w);
|
|
759
|
+
const float bottom = top + static_cast<float>(h);
|
|
760
|
+
const float y0 = static_cast<float>(py) + o0;
|
|
761
|
+
const float y1 = static_cast<float>(py) + o1;
|
|
762
|
+
if (y1 < top - 1.0f || y0 > bottom + 1.0f) return false;
|
|
763
|
+
auto inset = [&](int topRadius, int bottomRadius) {
|
|
764
|
+
const float rt = static_cast<float>(topRadius);
|
|
765
|
+
const float rb = static_cast<float>(bottomRadius);
|
|
766
|
+
if (y1 < top + rt) {
|
|
767
|
+
const float d = top + rt - y1;
|
|
768
|
+
return rt - std::sqrt(std::max(0.0f, rt * rt - d * d));
|
|
769
|
+
}
|
|
770
|
+
if (y0 > bottom - rb) {
|
|
771
|
+
const float d = y0 - (bottom - rb);
|
|
772
|
+
return rb - std::sqrt(std::max(0.0f, rb * rb - d * d));
|
|
773
|
+
}
|
|
774
|
+
return 0.0f;
|
|
775
|
+
};
|
|
776
|
+
const float reachLeft = left + inset(tl, bl);
|
|
777
|
+
const float reachRight = right - inset(tr, br);
|
|
778
|
+
*outX0 = static_cast<int>(std::floor(reachLeft - o1)) - 1;
|
|
779
|
+
*outX1 = static_cast<int>(std::ceil(reachRight - o0)) + 1;
|
|
780
|
+
return *outX0 <= *outX1;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
// Antialiased coverage of a rounded rect depends only on its size, radii and
|
|
784
|
+
// sample count and on the pixel's offset inside it: the sample offsets are
|
|
785
|
+
// exact binary fractions and every test works on exact differences, so the same
|
|
786
|
+
// shape at another integer position samples identically. A shape repainted every
|
|
787
|
+
// frame (Ember's glow discs under a pulsing ring, ~2500 edge pixels at ~4 us
|
|
788
|
+
// each on the S31) keeps its edge coverage here, filled lazily per pixel.
|
|
789
|
+
//
|
|
790
|
+
// The band rasterizer runs on both cores. The lock guards only lookup and
|
|
791
|
+
// eviction; an entry in use is pinned by its refcount, and two cores filling
|
|
792
|
+
// the same byte write the same value.
|
|
793
|
+
namespace {
|
|
794
|
+
struct RoundedCoverageTable {
|
|
795
|
+
int key[7] = {};
|
|
796
|
+
std::atomic<int> refs{0};
|
|
797
|
+
std::uint32_t stamp = 0;
|
|
798
|
+
std::uint8_t *cells = nullptr;
|
|
799
|
+
int capacity = 0;
|
|
800
|
+
};
|
|
801
|
+
constexpr int kRoundedCoverageTables = 4;
|
|
802
|
+
constexpr int kRoundedCoverageMaxCells = 160 * 160;
|
|
803
|
+
RoundedCoverageTable gRoundedCoverage[kRoundedCoverageTables];
|
|
804
|
+
std::atomic_flag gRoundedCoverageLock = ATOMIC_FLAG_INIT;
|
|
805
|
+
std::uint32_t gRoundedCoverageClock = 0;
|
|
806
|
+
|
|
807
|
+
void *allocRoundedCoverageCells(int bytes)
|
|
808
|
+
{
|
|
809
|
+
#ifdef ESP_PLATFORM
|
|
810
|
+
void *cells = heap_caps_malloc(static_cast<std::size_t>(bytes), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
|
811
|
+
if (cells) return cells;
|
|
812
|
+
#endif
|
|
813
|
+
return std::malloc(static_cast<std::size_t>(bytes));
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
RoundedCoverageTable *acquireRoundedCoverage(int w, int h, int tl, int tr, int br, int bl, int samples)
|
|
817
|
+
{
|
|
818
|
+
const int cells = w * h;
|
|
819
|
+
if (cells < 32 * 32 || cells > kRoundedCoverageMaxCells) return nullptr;
|
|
820
|
+
const int key[7] = {w, h, tl, tr, br, bl, samples};
|
|
821
|
+
while (gRoundedCoverageLock.test_and_set(std::memory_order_acquire)) {}
|
|
822
|
+
RoundedCoverageTable *found = nullptr;
|
|
823
|
+
RoundedCoverageTable *victim = nullptr;
|
|
824
|
+
for (auto &table : gRoundedCoverage) {
|
|
825
|
+
if (table.cells && std::memcmp(table.key, key, sizeof(key)) == 0) { found = &table; break; }
|
|
826
|
+
if (table.refs.load(std::memory_order_relaxed) == 0 && (!victim || table.stamp < victim->stamp)) victim = &table;
|
|
827
|
+
}
|
|
828
|
+
if (!found && victim) {
|
|
829
|
+
if (victim->capacity < cells) {
|
|
830
|
+
std::free(victim->cells);
|
|
831
|
+
victim->cells = static_cast<std::uint8_t *>(allocRoundedCoverageCells(cells));
|
|
832
|
+
victim->capacity = victim->cells ? cells : 0;
|
|
614
833
|
}
|
|
834
|
+
if (victim->cells) {
|
|
835
|
+
std::memset(victim->cells, 0xff, static_cast<std::size_t>(cells));
|
|
836
|
+
std::memcpy(victim->key, key, sizeof(key));
|
|
837
|
+
found = victim;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
if (found) {
|
|
841
|
+
found->refs.fetch_add(1, std::memory_order_relaxed);
|
|
842
|
+
found->stamp = ++gRoundedCoverageClock;
|
|
615
843
|
}
|
|
616
|
-
|
|
844
|
+
gRoundedCoverageLock.clear(std::memory_order_release);
|
|
845
|
+
return found;
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
void releaseRoundedCoverage(RoundedCoverageTable *table)
|
|
849
|
+
{
|
|
850
|
+
if (table) table->refs.fetch_sub(1, std::memory_order_release);
|
|
617
851
|
}
|
|
852
|
+
} // namespace
|
|
618
853
|
|
|
619
854
|
static inline int coverageAlpha(int alpha, int coverage, int sampleCount)
|
|
620
855
|
{
|
|
@@ -3439,6 +3674,8 @@ void Canvas::fillRoundedRect(int x, int y, int w, int h, int tl, int tr, int br,
|
|
|
3439
3674
|
const float kernelWidth = useAntialias ? roundedRectAntialiasKernelWidth(aaSamples, w, h, tl, tr, br, bl) : 1.0f;
|
|
3440
3675
|
const int edgePad = useAntialias ? antialiasEdgePad(kernelWidth) : 0;
|
|
3441
3676
|
const bool coverageSampleFill = useAntialias && roundedRectShouldCoverageSampleFill(w, h);
|
|
3677
|
+
const float firstOffset = useAntialias ? antialiasOffsetWithKernel(0, aaSamples, kernelWidth) : 0.0f;
|
|
3678
|
+
const float lastOffset = useAntialias ? antialiasOffsetWithKernel(aaSamples - 1, aaSamples, kernelWidth) : 0.0f;
|
|
3442
3679
|
|
|
3443
3680
|
const ClipRect *clip = &clipStack_[clipDepth_];
|
|
3444
3681
|
int row0 = y;
|
|
@@ -3472,8 +3709,10 @@ void Canvas::fillRoundedRect(int x, int y, int w, int h, int tl, int tr, int br,
|
|
|
3472
3709
|
pixel::native_t *dst = &pixels_[rotPhysRow(sx) * stride_ + row0];
|
|
3473
3710
|
#endif
|
|
3474
3711
|
for (int sy = row0; sy <= row1; ++sy) {
|
|
3475
|
-
|
|
3476
|
-
|
|
3712
|
+
int coverage = roundedRectCoverageDecided(x, y, w, h, tl, tr, br, bl, sx, sy,
|
|
3713
|
+
firstOffset, lastOffset, aaSampleCount);
|
|
3714
|
+
if (coverage < 0)
|
|
3715
|
+
coverage = roundedRectCoverage(x, y, w, h, tl, tr, br, bl, sx, sy, aaSamples, kernelWidth);
|
|
3477
3716
|
if (coverage <= 0) {
|
|
3478
3717
|
#if !GEA_PIXEL_STORAGE_PACKED
|
|
3479
3718
|
++dst;
|
|
@@ -3573,6 +3812,8 @@ void Canvas::fillRoundedRect(int x, int y, int w, int h, int tl, int tr, int br,
|
|
|
3573
3812
|
}
|
|
3574
3813
|
#endif
|
|
3575
3814
|
|
|
3815
|
+
RoundedCoverageTable *coverageTable = useAntialias ? acquireRoundedCoverage(w, h, tl, tr, br, bl, aaSamples) : nullptr;
|
|
3816
|
+
struct ReleaseCoverage { RoundedCoverageTable *table; ~ReleaseCoverage() { releaseRoundedCoverage(table); } } releaseCoverage{coverageTable};
|
|
3576
3817
|
for (int sy = row0; sy <= row1; sy++) {
|
|
3577
3818
|
int sx0 = width_;
|
|
3578
3819
|
int sx1 = -1;
|
|
@@ -3642,7 +3883,17 @@ void Canvas::fillRoundedRect(int x, int y, int w, int h, int tl, int tr, int br,
|
|
|
3642
3883
|
|
|
3643
3884
|
auto paintCoverageEdge = [&](int px) {
|
|
3644
3885
|
if (px < clip->x0 || px > clip->x1 || px < 0 || px >= width_) return;
|
|
3645
|
-
|
|
3886
|
+
std::uint8_t *cell = coverageTable ? &coverageTable->cells[(sy - y) * w + (px - x)] : nullptr;
|
|
3887
|
+
int decided = cell && *cell != 0xff ? *cell
|
|
3888
|
+
: useAntialias ? roundedRectCoverageDecided(x, y, w, h, tl, tr, br, bl, px, sy,
|
|
3889
|
+
firstOffset, lastOffset, aaSampleCount)
|
|
3890
|
+
: -1;
|
|
3891
|
+
if (cell && *cell == 0xff && decided < 0)
|
|
3892
|
+
decided = roundedRectCoverage(x, y, w, h, tl, tr, br, bl, px, sy, aaSamples, kernelWidth);
|
|
3893
|
+
if (cell && *cell == 0xff) *cell = static_cast<std::uint8_t>(decided);
|
|
3894
|
+
const int coverage = decided >= 0
|
|
3895
|
+
? decided
|
|
3896
|
+
: useAntialias
|
|
3646
3897
|
? roundedRectCoverage(x, y, w, h, tl, tr, br, bl, px, sy, aaSamples, kernelWidth)
|
|
3647
3898
|
: (roundedRectSampleContains(x,
|
|
3648
3899
|
y,
|
|
@@ -3680,7 +3931,23 @@ void Canvas::fillRoundedRect(int x, int y, int w, int h, int tl, int tr, int br,
|
|
|
3680
3931
|
};
|
|
3681
3932
|
|
|
3682
3933
|
if (coverageSampleFill) {
|
|
3683
|
-
|
|
3934
|
+
// Columns every sample covers take the whole fill alpha: one span,
|
|
3935
|
+
// not a coverage test per pixel.
|
|
3936
|
+
int inX0, inX1;
|
|
3937
|
+
roundedRectInsideSpan(x, y, w, h, tl, tr, br, bl, sy, firstOffset, lastOffset, &inX0, &inX1);
|
|
3938
|
+
if (inX0 < anyX0) inX0 = anyX0;
|
|
3939
|
+
if (inX1 > anyX1) inX1 = anyX1;
|
|
3940
|
+
if (inX0 > inX1) {
|
|
3941
|
+
for (int px = anyX0; px <= anyX1; ++px) paintCoverageEdge(px);
|
|
3942
|
+
continue;
|
|
3943
|
+
}
|
|
3944
|
+
for (int px = anyX0; px < inX0; ++px) paintCoverageEdge(px);
|
|
3945
|
+
fillSpanGlobalAlpha(rowToPhysical(sy), inX0, inX1 - inX0 + 1, color);
|
|
3946
|
+
if (inX0 < dirtyX0) dirtyX0 = inX0;
|
|
3947
|
+
if (sy < dirtyY0) dirtyY0 = sy;
|
|
3948
|
+
if (inX1 > dirtyX1) dirtyX1 = inX1;
|
|
3949
|
+
if (sy > dirtyY1) dirtyY1 = sy;
|
|
3950
|
+
for (int px = inX1 + 1; px <= anyX1; ++px) paintCoverageEdge(px);
|
|
3684
3951
|
continue;
|
|
3685
3952
|
} else if (useAntialias) {
|
|
3686
3953
|
if (sx0 <= sx1) {
|
|
@@ -3779,14 +4046,56 @@ void Canvas::strokeRoundedRect(int x, int y, int w, int h, int tl, int tr, int b
|
|
|
3779
4046
|
int dirtyY1 = -1;
|
|
3780
4047
|
const int aaSampleCount = aaSamples * aaSamples;
|
|
3781
4048
|
const int alpha = globalAlpha_;
|
|
4049
|
+
const float firstOffset = antialiasOffsetWithKernel(0, aaSamples, kernelWidth);
|
|
4050
|
+
const float lastOffset = antialiasOffsetWithKernel(aaSamples - 1, aaSamples, kernelWidth);
|
|
4051
|
+
const int innerW = w - lw * 2;
|
|
4052
|
+
const int innerH = h - lw * 2;
|
|
4053
|
+
const bool hasInner = innerW > 0 && innerH > 0;
|
|
3782
4054
|
for (int sy = row0; sy <= row1; ++sy) {
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
4055
|
+
// Only the band needs a per-pixel test. Columns wholly inside the
|
|
4056
|
+
// inner shape are the hole, and on a row no inner sample reaches,
|
|
4057
|
+
// columns wholly inside the outer shape are the band at full alpha.
|
|
4058
|
+
// Pixels beyond the outer shape's reach have no coverage: an 88px
|
|
4059
|
+
// ring tested its ~1700 corner pixels one by one (3.5 ms on the S31).
|
|
4060
|
+
int reachX0 = 0, reachX1 = -1;
|
|
4061
|
+
if (!roundedRectReachSpan(x, y, w, h, tl, tr, br, bl, sy, firstOffset, lastOffset, &reachX0, &reachX1))
|
|
4062
|
+
continue;
|
|
4063
|
+
const int rowX0 = std::max(col0, reachX0);
|
|
4064
|
+
const int rowX1 = std::min(col1, reachX1);
|
|
4065
|
+
int holeX0 = 0, holeX1 = -1;
|
|
4066
|
+
if (hasInner)
|
|
4067
|
+
roundedRectInsideSpan(x + lw, y + lw, innerW, innerH, std::max(0, tl - lw), std::max(0, tr - lw),
|
|
4068
|
+
std::max(0, br - lw), std::max(0, bl - lw), sy, firstOffset, lastOffset,
|
|
4069
|
+
&holeX0, &holeX1);
|
|
4070
|
+
int solidX0 = 0, solidX1 = -1;
|
|
4071
|
+
const float rowY0 = static_cast<float>(sy) + firstOffset;
|
|
4072
|
+
const float rowY1 = static_cast<float>(sy) + lastOffset;
|
|
4073
|
+
if (!hasInner || rowY1 < static_cast<float>(y + lw) || rowY0 >= static_cast<float>(y + lw + innerH))
|
|
4074
|
+
roundedRectInsideSpan(x, y, w, h, tl, tr, br, bl, sy, firstOffset, lastOffset, &solidX0, &solidX1);
|
|
4075
|
+
for (int sx = rowX0; sx <= rowX1; ++sx) {
|
|
4076
|
+
if (sx >= holeX0 && sx <= holeX1) {
|
|
4077
|
+
sx = holeX1;
|
|
4078
|
+
continue;
|
|
4079
|
+
}
|
|
4080
|
+
if (sx >= solidX0 && sx <= solidX1) {
|
|
4081
|
+
const int end = std::min(solidX1, rowX1);
|
|
4082
|
+
fillSpanGlobalAlpha(rowToPhysical(sy), sx, end - sx + 1, color);
|
|
4083
|
+
if (sx < dirtyX0) dirtyX0 = sx;
|
|
4084
|
+
if (sy < dirtyY0) dirtyY0 = sy;
|
|
4085
|
+
if (end > dirtyX1) dirtyX1 = end;
|
|
4086
|
+
if (sy > dirtyY1) dirtyY1 = sy;
|
|
4087
|
+
sx = end;
|
|
4088
|
+
continue;
|
|
4089
|
+
}
|
|
4090
|
+
int coverage = roundedRectStrokeCoverageDecided(x, y, w, h, tl, tr, br, bl, lw, sx, sy,
|
|
4091
|
+
firstOffset, lastOffset, aaSampleCount);
|
|
4092
|
+
if (coverage < 0)
|
|
4093
|
+
coverage = roundedRectStrokeCoverage(x, y, w, h,
|
|
4094
|
+
tl, tr, br, bl,
|
|
4095
|
+
lw,
|
|
4096
|
+
sx, sy,
|
|
4097
|
+
aaSamples,
|
|
4098
|
+
kernelWidth);
|
|
3790
4099
|
const int effectiveAlpha = coverageAlpha(alpha, coverage, aaSampleCount);
|
|
3791
4100
|
if (effectiveAlpha <= 0) continue;
|
|
3792
4101
|
const pixel::native_t c = color;
|
package/image_store.cpp
CHANGED
|
@@ -781,6 +781,20 @@ bool ImageStore::isAnimated(int id) const { const ImageSlot *image = slot(id); r
|
|
|
781
781
|
ImageFormat ImageStore::format(int id) const { const ImageSlot *image = slot(id); return image ? image->format : ImageFormat::Unknown; }
|
|
782
782
|
bool ImageStore::playing(int id) const { const ImageSlot *image = slot(id); return image && image->playing; }
|
|
783
783
|
int ImageStore::currentFrame(int id) const { const ImageSlot *image = slot(id); return image ? image->currentFrame : 0; }
|
|
784
|
+
bool ImageStore::pixelsMayChange(const pixel::native_t *pixels) const
|
|
785
|
+
{
|
|
786
|
+
if (!pixels) return false;
|
|
787
|
+
for (int i = 0; i < kImageMax; i++) {
|
|
788
|
+
// Anywhere inside the buffer: a dirty-rect putImageData draws rows that
|
|
789
|
+
// start part-way into it (CanvasRenderingContext2D::drawPixelRows).
|
|
790
|
+
const ImageSlot &image = images_[i];
|
|
791
|
+
if (!used_[i] || !image.mutablePixels || !image.pixels) continue;
|
|
792
|
+
const std::size_t count = static_cast<std::size_t>(image.width) * static_cast<std::size_t>(image.height);
|
|
793
|
+
if (pixels >= image.pixels && pixels < image.pixels + count) return true;
|
|
794
|
+
}
|
|
795
|
+
return false;
|
|
796
|
+
}
|
|
797
|
+
|
|
784
798
|
const pixel::native_t *ImageStore::currentPixels(int id) const { materializeDeferred(id); const ImageSlot *image = slot(id); return image ? image->pixels : nullptr; }
|
|
785
799
|
const std::uint8_t *ImageStore::currentAlpha(int id) const { materializeDeferred(id); const ImageSlot *image = slot(id); return image ? image->alpha : nullptr; }
|
|
786
800
|
|
|
@@ -901,6 +915,7 @@ int ImageStore::registerBuffer(pixel::native_t *pixels, int width, int height, i
|
|
|
901
915
|
image.frameCount = 1;
|
|
902
916
|
image.pixels = pixels;
|
|
903
917
|
image.ownsPixels = takeOwnership;
|
|
918
|
+
image.mutablePixels = true;
|
|
904
919
|
image.loopCount = 0;
|
|
905
920
|
image.playing = false;
|
|
906
921
|
used_[id] = true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geastack/engine",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
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.39"
|
|
61
61
|
}
|
|
62
62
|
}
|