@geastack/engine 0.1.5 → 0.1.6
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 +34 -0
- package/css/animation.h +64 -0
- package/css/engine.h +6 -1
- package/package.json +2 -2
- package/ui/absolute_leaf_refresh.cpp +32 -31
- package/ui/core.cpp +9 -1
- package/ui/display_invalidation.cpp +29 -0
- package/ui/flex_balance.h +73 -0
- package/ui/image_node.cpp +24 -20
- package/ui/input.cpp +66 -36
- package/ui/input_render.cpp +13 -13
- package/ui/internal.h +51 -5
- package/ui/layout.cpp +2472 -400
- package/ui/layout_snapshot.cpp +21 -5
- package/ui/node_lifecycle.cpp +28 -3
- package/ui/node_model.h +323 -23
- package/ui/render.cpp +638 -265
- package/ui/root_scroll_refresh.cpp +15 -10
- package/ui/style.cpp +3254 -935
- package/ui/style.h +143 -6
- package/ui/style_values.h +16 -0
- package/ui/text.cpp +378 -103
- package/ui/tree_events.cpp +6 -3
- package/ui/tree_events.h +1 -0
- package/ui/tree_internal.h +19 -0
- package/ui/tree_nodes.cpp +6 -0
- package/ui/tree_render.cpp +71 -21
- package/ui/tree_state.h +54 -0
- package/ui/tree_style.cpp +287 -27
- package/ui/view.cpp +612 -251
package/ui/view.cpp
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
#include "internal.h"
|
|
3
3
|
#include "state_init.h"
|
|
4
|
+
#include "style_values.h"
|
|
4
5
|
#include "tree_state.h"
|
|
5
6
|
#include <pixel.h>
|
|
6
7
|
|
|
@@ -24,6 +25,17 @@
|
|
|
24
25
|
|
|
25
26
|
namespace gea::embedded::ui {
|
|
26
27
|
|
|
28
|
+
class TextBackgroundClipScope {
|
|
29
|
+
int previous_ = -1;
|
|
30
|
+
bool active_ = false;
|
|
31
|
+
public:
|
|
32
|
+
TextBackgroundClipScope(const Node &node, int clip) : active_(clip == 3) {
|
|
33
|
+
if (active_) previous_ = DisplayList::instance().setRecordingTextClipOwner(
|
|
34
|
+
static_cast<int>(&node - Tree::instance().nodes()));
|
|
35
|
+
}
|
|
36
|
+
~TextBackgroundClipScope() { if (active_) DisplayList::instance().setRecordingTextClipOwner(previous_); }
|
|
37
|
+
};
|
|
38
|
+
|
|
27
39
|
constexpr double kPi = 3.14159265358979323846;
|
|
28
40
|
constexpr float kPiF = 3.14159265358979323846f;
|
|
29
41
|
// Reciprocal constants so the per-corner transform math uses hardware FPU
|
|
@@ -48,10 +60,11 @@ uint8_t combineAlpha(uint8_t parentAlpha, uint8_t localAlpha)
|
|
|
48
60
|
|
|
49
61
|
bool borderIsSameOpaqueSolidBackground(const Node &node, uint8_t parentAlpha)
|
|
50
62
|
{
|
|
51
|
-
return node.style.has_bg &&
|
|
52
|
-
node.style.
|
|
53
|
-
node.style
|
|
54
|
-
|
|
63
|
+
return !hasBorderRelief(node.style) && node.style.has_bg &&
|
|
64
|
+
StyleValues::backgroundClip(node.style, rstyle(node.style).bg_image_layer_count - 1) == 0 &&
|
|
65
|
+
!styleHasBackgroundImage(node.style) &&
|
|
66
|
+
node.style.bg_color == borderPaintColor(node.style, 0) &&
|
|
67
|
+
combineAlpha(parentAlpha, node.style.bg_alpha) == combineAlpha(parentAlpha, borderPaintAlpha(node.style, 0));
|
|
55
68
|
}
|
|
56
69
|
|
|
57
70
|
void appendAlphaCommand(uint8_t alpha, int bx, int by, int bw, int bh)
|
|
@@ -270,13 +283,13 @@ void appendFillQuadStrokeSegmentRaw(const int16_t *xs, const int16_t *ys, uint16
|
|
|
270
283
|
|
|
271
284
|
void boundsFromCorners(const int16_t *xs, const int16_t *ys, int *x0, int *y0, int *x1, int *y1);
|
|
272
285
|
|
|
273
|
-
|
|
286
|
+
DisplayCommand *appendLinearGradientRectRaw(const Node &node, int x, int y, int w, int h,
|
|
274
287
|
uint16_t fromColor, uint16_t midColor, uint16_t toColor,
|
|
275
288
|
uint16_t midStop, uint16_t toStop, int16_t angle, uint8_t fromAlpha,
|
|
276
289
|
uint8_t midAlpha, uint8_t toAlpha, uint8_t hasMid)
|
|
277
290
|
{
|
|
278
291
|
DisplayCommand *cmd = DisplayList::instance().append();
|
|
279
|
-
if (!cmd) return;
|
|
292
|
+
if (!cmd) return nullptr;
|
|
280
293
|
cmd->type = DisplayCommandType::FillLinearGradient;
|
|
281
294
|
cmd->bx = x;
|
|
282
295
|
cmd->by = y;
|
|
@@ -300,11 +313,12 @@ void appendLinearGradientRectRaw(const Node &node, int x, int y, int w, int h,
|
|
|
300
313
|
cmd->gradient.midAlpha = midAlpha;
|
|
301
314
|
cmd->gradient.toAlpha = toAlpha;
|
|
302
315
|
cmd->gradient.hasMid = hasMid;
|
|
316
|
+
return cmd;
|
|
303
317
|
}
|
|
304
318
|
|
|
305
|
-
|
|
319
|
+
DisplayCommand *appendLinearGradientRectRaw(const Node &node, int x, int y, int w, int h)
|
|
306
320
|
{
|
|
307
|
-
appendLinearGradientRectRaw(node,
|
|
321
|
+
return appendLinearGradientRectRaw(node,
|
|
308
322
|
x,
|
|
309
323
|
y,
|
|
310
324
|
w,
|
|
@@ -321,10 +335,10 @@ void appendLinearGradientRectRaw(const Node &node, int x, int y, int w, int h)
|
|
|
321
335
|
rstyle(node.style).bg_gradient_has_mid);
|
|
322
336
|
}
|
|
323
337
|
|
|
324
|
-
|
|
338
|
+
DisplayCommand *appendRadialGradientRectRaw(const Node &node, int x, int y, int w, int h)
|
|
325
339
|
{
|
|
326
340
|
DisplayCommand *cmd = DisplayList::instance().append();
|
|
327
|
-
if (!cmd) return;
|
|
341
|
+
if (!cmd) return nullptr;
|
|
328
342
|
cmd->type = DisplayCommandType::FillRadialGradient;
|
|
329
343
|
cmd->bx = x;
|
|
330
344
|
cmd->by = y;
|
|
@@ -347,6 +361,7 @@ void appendRadialGradientRectRaw(const Node &node, int x, int y, int w, int h)
|
|
|
347
361
|
cmd->radialGradient.stopPermille = rstyle(node.style).bg_radial_gradient_stop;
|
|
348
362
|
cmd->radialGradient.fromAlpha = rstyle(node.style).bg_radial_gradient_from_alpha;
|
|
349
363
|
cmd->radialGradient.toAlpha = rstyle(node.style).bg_radial_gradient_to_alpha;
|
|
364
|
+
return cmd;
|
|
350
365
|
}
|
|
351
366
|
|
|
352
367
|
void appendDrawLineRaw(int x0, int y0, int x1, int y1, uint16_t color)
|
|
@@ -551,6 +566,7 @@ bool resolvedCircularBorderRadii(const Node &node, int radii[4])
|
|
|
551
566
|
for (int i = 0; i < 4; i++) {
|
|
552
567
|
if (std::abs(static_cast<int>(rx8[i]) - static_cast<int>(ry8[i])) > 4) return false;
|
|
553
568
|
const int radius8 = (static_cast<int>(rx8[i]) + static_cast<int>(ry8[i])) / 2;
|
|
569
|
+
if (radius8 > std::min(node.layout.width, node.layout.height) * 4) return false;
|
|
554
570
|
radii[i] = std::max(0, std::min(32767, (radius8 + 4) / 8));
|
|
555
571
|
}
|
|
556
572
|
return true;
|
|
@@ -659,7 +675,7 @@ void appendFillCircleWithAlpha(int cx, int cy, int r, gea::framework::graphics::
|
|
|
659
675
|
|
|
660
676
|
void appendStrokeWithAlpha(const Node &node, uint8_t parentAlpha)
|
|
661
677
|
{
|
|
662
|
-
const uint8_t effectiveAlpha = combineAlpha(parentAlpha, node.style
|
|
678
|
+
const uint8_t effectiveAlpha = combineAlpha(parentAlpha, borderPaintAlpha(node.style, 0));
|
|
663
679
|
if (effectiveAlpha != parentAlpha)
|
|
664
680
|
appendAlphaCommand(effectiveAlpha, node.layout.x, node.layout.y, node.layout.width, node.layout.height);
|
|
665
681
|
|
|
@@ -670,6 +686,7 @@ void appendStrokeWithAlpha(const Node &node, uint8_t parentAlpha)
|
|
|
670
686
|
// with zero radii instead of silently collapsing border-width to 1px.
|
|
671
687
|
if (hasAnyRadius(node) || node.style.border_width > 1) {
|
|
672
688
|
cmd->type = DisplayCommandType::StrokeRoundedRect;
|
|
689
|
+
cmd->strokeRoundedRect = {};
|
|
673
690
|
cmd->bx = node.layout.x; cmd->by = node.layout.y; cmd->bw = node.layout.width; cmd->bh = node.layout.height;
|
|
674
691
|
cmd->strokeRoundedRect.x = node.layout.x; cmd->strokeRoundedRect.y = node.layout.y;
|
|
675
692
|
cmd->strokeRoundedRect.w = node.layout.width; cmd->strokeRoundedRect.h = node.layout.height;
|
|
@@ -678,13 +695,19 @@ void appendStrokeWithAlpha(const Node &node, uint8_t parentAlpha)
|
|
|
678
695
|
cmd->strokeRoundedRect.br = node.style.border_radius[2];
|
|
679
696
|
cmd->strokeRoundedRect.bl = node.style.border_radius[3];
|
|
680
697
|
cmd->strokeRoundedRect.lineWidth = node.style.border_width;
|
|
681
|
-
cmd->strokeRoundedRect.
|
|
698
|
+
resolvedBorderRadii8(node, cmd->strokeRoundedRect.rx8, cmd->strokeRoundedRect.ry8);
|
|
699
|
+
cmd->strokeRoundedRect.cssRadii = hasAnyPercentRadius(node);
|
|
700
|
+
for (int i = 0; i < 4; ++i)
|
|
701
|
+
if (cmd->strokeRoundedRect.rx8[i] > std::min(node.layout.width, node.layout.height) * 4 ||
|
|
702
|
+
cmd->strokeRoundedRect.ry8[i] > std::min(node.layout.width, node.layout.height) * 4)
|
|
703
|
+
cmd->strokeRoundedRect.cssRadii = 1;
|
|
704
|
+
cmd->strokeRoundedRect.color = borderPaintColor(node.style, 0);
|
|
682
705
|
} else {
|
|
683
706
|
cmd->type = DisplayCommandType::StrokeRect;
|
|
684
707
|
cmd->bx = node.layout.x; cmd->by = node.layout.y; cmd->bw = node.layout.width; cmd->bh = node.layout.height;
|
|
685
708
|
cmd->stroke.x = node.layout.x; cmd->stroke.y = node.layout.y;
|
|
686
709
|
cmd->stroke.w = node.layout.width; cmd->stroke.h = node.layout.height;
|
|
687
|
-
cmd->stroke.color = node.style
|
|
710
|
+
cmd->stroke.color = borderPaintColor(node.style, 0);
|
|
688
711
|
}
|
|
689
712
|
}
|
|
690
713
|
|
|
@@ -723,20 +746,35 @@ public:
|
|
|
723
746
|
return index >= 0 && index < Tree::instance().nodeCount() ? static_cast<int>(index) : -1;
|
|
724
747
|
}
|
|
725
748
|
|
|
749
|
+
// CSS Transforms applies to transformable boxes, which excludes non-replaced
|
|
750
|
+
// inline-level boxes. The layout classifier also includes inline replaced
|
|
751
|
+
// elements such as images, so retain those while excluding ordinary inline
|
|
752
|
+
// wrappers and text nodes.
|
|
753
|
+
static bool hasTransformableBox(const Node &node)
|
|
754
|
+
{
|
|
755
|
+
if (node.style.display == kDisplayNone) return false;
|
|
756
|
+
if (node.type == NodeType::Text) return false;
|
|
757
|
+
if (node.type == NodeType::Image) return true;
|
|
758
|
+
return !LayoutEngine::isCssInlineLevelBox(node);
|
|
759
|
+
}
|
|
760
|
+
|
|
726
761
|
static bool nodeHasLocalTransform(const Node &node, bool usePrevious)
|
|
727
762
|
{
|
|
763
|
+
if (usePrevious ? !node.render.previous_transformable_box : !hasTransformableBox(node)) return false;
|
|
728
764
|
const RareStyle &rs = rstyle(node.style); // one pool lookup, not 10
|
|
729
765
|
const int rotate = usePrevious ? node.render.previous_transform_rotate : rs.transform_rotate;
|
|
730
766
|
const int rotateX = usePrevious ? node.render.previous_transform_rotate_x : rs.transform_rotate_x;
|
|
731
767
|
const int rotateY = usePrevious ? node.render.previous_transform_rotate_y : rs.transform_rotate_y;
|
|
732
|
-
const int tx = usePrevious ? node.render.previous_transform_translate_x : rs
|
|
733
|
-
const int ty = usePrevious ? node.render.previous_transform_translate_y : rs
|
|
734
|
-
const int tz = usePrevious ? node.render.previous_transform_translate_z : rs
|
|
735
|
-
const int txPercent = usePrevious ? node.render.previous_transform_translate_x_percent : rs
|
|
736
|
-
const int tyPercent = usePrevious ? node.render.previous_transform_translate_y_percent : rs
|
|
768
|
+
const int tx = usePrevious ? node.render.previous_transform_translate_x : composedTranslateX(rs);
|
|
769
|
+
const int ty = usePrevious ? node.render.previous_transform_translate_y : composedTranslateY(rs);
|
|
770
|
+
const int tz = usePrevious ? node.render.previous_transform_translate_z : composedTranslateZ(rs);
|
|
771
|
+
const int txPercent = usePrevious ? node.render.previous_transform_translate_x_percent : composedTranslateXPercent(rs);
|
|
772
|
+
const int tyPercent = usePrevious ? node.render.previous_transform_translate_y_percent : composedTranslateYPercent(rs);
|
|
737
773
|
const int sx = usePrevious ? node.render.previous_transform_scale_x : rs.transform_scale_x;
|
|
738
774
|
const int sy = usePrevious ? node.render.previous_transform_scale_y : rs.transform_scale_y;
|
|
739
|
-
|
|
775
|
+
const int sz = usePrevious ? node.render.previous_transform_scale_z : rs.transform_scale_z;
|
|
776
|
+
return (usePrevious ? hadIndividualLinearTransform(node.render) : hasIndividualLinearTransform(rs)) ||
|
|
777
|
+
(rotate % 3600) != 0 ||
|
|
740
778
|
(rotateX % 3600) != 0 ||
|
|
741
779
|
(rotateY % 3600) != 0 ||
|
|
742
780
|
tx != 0 ||
|
|
@@ -745,7 +783,8 @@ public:
|
|
|
745
783
|
txPercent != 0 ||
|
|
746
784
|
tyPercent != 0 ||
|
|
747
785
|
sx != 1000 ||
|
|
748
|
-
sy != 1000
|
|
786
|
+
sy != 1000 ||
|
|
787
|
+
sz != 1000;
|
|
749
788
|
}
|
|
750
789
|
|
|
751
790
|
// True iff any node carries a non-identity transform/perspective this frame
|
|
@@ -770,7 +809,8 @@ public:
|
|
|
770
809
|
for (int i = 0; i < state.nodeCount; i++) {
|
|
771
810
|
const Node &n = state.nodes[i];
|
|
772
811
|
if (nodeHasLocalTransform(n, false) || nodeHasLocalTransform(n, true) ||
|
|
773
|
-
rstyle(n.style).perspective > 0 ||
|
|
812
|
+
(hasTransformableBox(n) && rstyle(n.style).perspective > 0) ||
|
|
813
|
+
(n.render.previous_transformable_box && n.render.previous_perspective > 0)) {
|
|
774
814
|
present = true;
|
|
775
815
|
break;
|
|
776
816
|
}
|
|
@@ -787,6 +827,7 @@ public:
|
|
|
787
827
|
auto &state = treeState();
|
|
788
828
|
for (int id = nodeIndex(node); id >= 0 && id < state.nodeCount; id = state.nodes[id].parent) {
|
|
789
829
|
if (nodeHasLocalTransform(state.nodes[id], usePrevious)) return true;
|
|
830
|
+
if (usePrevious ? !state.nodes[id].render.previous_transformable_box : !hasTransformableBox(state.nodes[id])) continue;
|
|
790
831
|
const int perspective = usePrevious ? state.nodes[id].render.previous_perspective : rstyle(state.nodes[id].style).perspective;
|
|
791
832
|
if (perspective > 0) return true;
|
|
792
833
|
}
|
|
@@ -831,24 +872,13 @@ public:
|
|
|
831
872
|
#endif
|
|
832
873
|
int nodeId = -1;
|
|
833
874
|
int x = 0, y = 0, w = 0, h = 0;
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
float ox = 0.0f, oy = 0.0f; // transform-origin in absolute coords
|
|
838
|
-
float scaleX = 1.0f, scaleY = 1.0f;
|
|
839
|
-
float transX = 0.0f, transY = 0.0f, transZ = 0.0f; // translate (incl % of size)
|
|
840
|
-
float sinZ = 0.0f, cosZ = 1.0f, sinY = 0.0f, cosY = 1.0f, sinX = 0.0f, cosX = 1.0f;
|
|
841
|
-
// Previous-frame coefficients (from render.previous_* / layout.previous_*),
|
|
842
|
-
// filled LAZILY on first dirty-bounds (previous-frame) access so the hot
|
|
843
|
-
// reproject path never pays for them. Lets the dirty-collect pass project
|
|
844
|
-
// previous-frame corners with the same pure-FPU cached apply as the current
|
|
845
|
-
// frame instead of re-walking the ancestor chain + recomputing 6 software
|
|
846
|
-
// trig per corner (the css-3d-cube dirty cost).
|
|
875
|
+
float ox = 0.0f, oy = 0.0f;
|
|
876
|
+
float transX = 0.0f, transY = 0.0f, transZ = 0.0f;
|
|
877
|
+
float matrix[9] = {1, 0, 0, 0, 1, 0, 0, 0, 1};
|
|
847
878
|
bool prevValid = false;
|
|
848
879
|
float pOx = 0.0f, pOy = 0.0f;
|
|
849
|
-
float pScaleX = 1.0f, pScaleY = 1.0f;
|
|
850
880
|
float pTransX = 0.0f, pTransY = 0.0f, pTransZ = 0.0f;
|
|
851
|
-
float
|
|
881
|
+
float previousMatrix[9] = {1, 0, 0, 0, 1, 0, 0, 0, 1};
|
|
852
882
|
};
|
|
853
883
|
|
|
854
884
|
struct AverageDepthCacheEntry {
|
|
@@ -916,117 +946,104 @@ public:
|
|
|
916
946
|
for (int i = 0; i < count; i++) entries[i].nodeId = -1;
|
|
917
947
|
}
|
|
918
948
|
|
|
949
|
+
static Point3 applyLinear(const float *m, Point3 p)
|
|
950
|
+
{
|
|
951
|
+
return {m[0] * p.x + m[1] * p.y + m[2] * p.z,
|
|
952
|
+
m[3] * p.x + m[4] * p.y + m[5] * p.z,
|
|
953
|
+
m[6] * p.x + m[7] * p.y + m[8] * p.z};
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
static void fillLinear(float *m, int rx, int ry, int rz, int sx, int sy, int sz = 1000)
|
|
957
|
+
{
|
|
958
|
+
const float ax = rx * kPiF * kInv1800f, ay = ry * kPiF * kInv1800f, az = rz * kPiF * kInv1800f;
|
|
959
|
+
const float sinX = sinf(ax), cosX = cosf(ax), sinY = sinf(ay), cosY = cosf(ay), sinZ = sinf(az), cosZ = cosf(az);
|
|
960
|
+
for (int column = 0; column < 3; ++column) {
|
|
961
|
+
Point3 basis{column == 0 ? sx * kInv1000f : 0.0f, column == 1 ? sy * kInv1000f : 0.0f, column == 2 ? sz * kInv1000f : 0.0f};
|
|
962
|
+
rotateZ(basis, sinZ, cosZ); rotateY(basis, sinY, cosY); rotateX(basis, sinX, cosX);
|
|
963
|
+
m[column] = basis.x; m[3 + column] = basis.y; m[6 + column] = basis.z;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
static Point3 listTranslation(Point3 shift, unsigned outerAxes, int rx, int ry, int rz)
|
|
968
|
+
{
|
|
969
|
+
Point3 inner{(outerAxes & 1) ? 0.0f : shift.x, (outerAxes & 2) ? 0.0f : shift.y, (outerAxes & 4) ? 0.0f : shift.z};
|
|
970
|
+
float rotation[9]; fillLinear(rotation, rx, ry, rz, 1000, 1000);
|
|
971
|
+
inner = applyLinear(rotation, inner);
|
|
972
|
+
return {inner.x + ((outerAxes & 1) ? shift.x : 0.0f), inner.y + ((outerAxes & 2) ? shift.y : 0.0f), inner.z + ((outerAxes & 4) ? shift.z : 0.0f)};
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
// CSS order is individual translate, rotate, scale, then the transform list.
|
|
976
|
+
// Left-multiply the list's linear map and offset once when filling the cache;
|
|
977
|
+
// per-point projection then needs only one affine matrix application.
|
|
978
|
+
static void composeIndividual(float *matrix, Point3 &shift, int angle, int axisX, int axisY, int axisZ,
|
|
979
|
+
int sx, int sy, int sz, Point3 translation)
|
|
980
|
+
{
|
|
981
|
+
float x = static_cast<float>(axisX), y = static_cast<float>(axisY), z = static_cast<float>(axisZ);
|
|
982
|
+
const float length = sqrtf(x*x + y*y + z*z);
|
|
983
|
+
float r[9] = {1, 0, 0, 0, 1, 0, 0, 0, 1};
|
|
984
|
+
if (length > 0 && angle % 3600 != 0) {
|
|
985
|
+
x /= length; y /= length; z /= length;
|
|
986
|
+
const float a = angle * kPiF * kInv1800f, c = cosf(a), sine = sinf(a), t = 1 - c;
|
|
987
|
+
r[0] = c+x*x*t; r[1] = x*y*t-z*sine; r[2] = x*z*t+y*sine;
|
|
988
|
+
r[3] = y*x*t+z*sine; r[4] = c+y*y*t; r[5] = y*z*t-x*sine;
|
|
989
|
+
r[6] = z*x*t-y*sine; r[7] = z*y*t+x*sine; r[8] = c+z*z*t;
|
|
990
|
+
}
|
|
991
|
+
for (int row = 0; row < 3; ++row) { r[row*3] *= sx*kInv1000f; r[row*3+1] *= sy*kInv1000f; r[row*3+2] *= sz*kInv1000f; }
|
|
992
|
+
for (int column = 0; column < 3; ++column) {
|
|
993
|
+
const auto v = applyLinear(r, {matrix[column], matrix[3+column], matrix[6+column]});
|
|
994
|
+
matrix[column] = v.x; matrix[3+column] = v.y; matrix[6+column] = v.z;
|
|
995
|
+
}
|
|
996
|
+
shift = applyLinear(r, shift);
|
|
997
|
+
shift.x += translation.x; shift.y += translation.y; shift.z += translation.z;
|
|
998
|
+
}
|
|
999
|
+
|
|
919
1000
|
static void fillNodeTransform(NodeTransformCache &e, const Node &node, int id)
|
|
920
1001
|
{
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
e.
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
e.
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
e.
|
|
941
|
-
e.
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
const float fh = static_cast<float>(node.layout.height);
|
|
945
|
-
e.ox = static_cast<float>(node.layout.x) + fw * static_cast<float>(rs.transform_origin_x) * kInv1000f;
|
|
946
|
-
e.oy = static_cast<float>(node.layout.y) + fh * static_cast<float>(rs.transform_origin_y) * kInv1000f;
|
|
947
|
-
e.scaleX = static_cast<float>(rs.transform_scale_x) * kInv1000f;
|
|
948
|
-
e.scaleY = static_cast<float>(rs.transform_scale_y) * kInv1000f;
|
|
949
|
-
e.transX = static_cast<float>(rs.transform_translate_x) +
|
|
950
|
-
fw * static_cast<float>(rs.transform_translate_x_percent) * kInv1000f;
|
|
951
|
-
e.transY = static_cast<float>(rs.transform_translate_y) +
|
|
952
|
-
fh * static_cast<float>(rs.transform_translate_y_percent) * kInv1000f;
|
|
953
|
-
e.transZ = static_cast<float>(rs.transform_translate_z);
|
|
954
|
-
const float az = static_cast<float>(rs.transform_rotate) * kPiF * kInv1800f;
|
|
955
|
-
const float ay = static_cast<float>(rs.transform_rotate_y) * kPiF * kInv1800f;
|
|
956
|
-
const float ax = static_cast<float>(rs.transform_rotate_x) * kPiF * kInv1800f;
|
|
957
|
-
e.sinZ = sinf(az); e.cosZ = cosf(az);
|
|
958
|
-
e.sinY = sinf(ay); e.cosY = cosf(ay);
|
|
959
|
-
e.sinX = sinf(ax); e.cosX = cosf(ax);
|
|
960
|
-
// Previous-frame coefficients are filled lazily (only the dirty-bounds pass
|
|
961
|
-
// needs them); mark invalid so the first prev access recomputes for this id.
|
|
962
|
-
e.prevValid = false;
|
|
963
|
-
e.nodeId = id;
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
// Previous-frame analogue of fillNodeTransform: precompute one node's transform
|
|
967
|
-
// coefficients from its SNAPSHOTTED previous-frame fields (render.previous_* +
|
|
968
|
-
// layout.previous_*). Lets transformRectCorners' previous-frame path gather the
|
|
969
|
-
// chain ONCE and apply pure-FPU to all 4 corners — instead of re-walking the
|
|
970
|
-
// ancestor chain and recomputing 6 software trig PER CORNER (the css-3d-cube
|
|
971
|
-
// dirty-collect's dominant cost: ~280 applyNodeTransform calls/frame). The math
|
|
972
|
-
// mirrors applyNodeTransform's usePrevious branch exactly, so the projected
|
|
973
|
-
// corners are bit-identical — no visual change.
|
|
1002
|
+
const RareStyle &r = rstyle(node.style);
|
|
1003
|
+
e.x = node.layout.x; e.y = node.layout.y; e.w = node.layout.width; e.h = node.layout.height;
|
|
1004
|
+
e.ox = e.x + e.w * r.transform_origin_x * kInv1000f;
|
|
1005
|
+
e.oy = e.y + e.h * r.transform_origin_y * kInv1000f;
|
|
1006
|
+
if (!hasTransformableBox(node)) {
|
|
1007
|
+
std::fill(std::begin(e.matrix), std::end(e.matrix), 0.0f);
|
|
1008
|
+
e.matrix[0] = e.matrix[4] = e.matrix[8] = 1.0f;
|
|
1009
|
+
e.transX = e.transY = e.transZ = 0.0f;
|
|
1010
|
+
e.prevValid = false; e.nodeId = id;
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
fillLinear(e.matrix, r.transform_rotate_x, r.transform_rotate_y, r.transform_rotate,
|
|
1014
|
+
r.transform_scale_x, r.transform_scale_y, r.transform_scale_z);
|
|
1015
|
+
auto shift = listTranslation({r.transform_translate_x + e.w*r.transform_translate_x_percent*kInv1000f,
|
|
1016
|
+
r.transform_translate_y + e.h*r.transform_translate_y_percent*kInv1000f, static_cast<float>(r.transform_translate_z)},
|
|
1017
|
+
r.transform_translate_outer_axes, r.transform_rotate_x, r.transform_rotate_y, r.transform_rotate);
|
|
1018
|
+
composeIndividual(e.matrix, shift, r.rotate_angle, r.rotate_axis_x, r.rotate_axis_y, r.rotate_axis_z,
|
|
1019
|
+
r.scale_x, r.scale_y, r.scale_z,
|
|
1020
|
+
{r.translate_x + e.w*r.translate_x_percent*kInv1000f, r.translate_y + e.h*r.translate_y_percent*kInv1000f, static_cast<float>(r.translate_z)});
|
|
1021
|
+
e.transX = shift.x; e.transY = shift.y; e.transZ = shift.z;
|
|
1022
|
+
e.prevValid = false; e.nodeId = id;
|
|
1023
|
+
}
|
|
1024
|
+
|
|
974
1025
|
static void fillNodeTransformPrev(NodeTransformCache &e, const Node &node)
|
|
975
1026
|
{
|
|
976
|
-
const
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
const
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
e.
|
|
996
|
-
e.pScaleX = static_cast<float>(sx) * kInv1000f;
|
|
997
|
-
e.pScaleY = static_cast<float>(sy) * kInv1000f;
|
|
998
|
-
e.pTransX = static_cast<float>(tx) + fw * static_cast<float>(txPercent) * kInv1000f;
|
|
999
|
-
e.pTransY = static_cast<float>(ty) + fh * static_cast<float>(tyPercent) * kInv1000f;
|
|
1000
|
-
e.pTransZ = static_cast<float>(tz);
|
|
1001
|
-
const float az = static_cast<float>(rotate) * kPiF * kInv1800f;
|
|
1002
|
-
const float ay = static_cast<float>(rotateYValue) * kPiF * kInv1800f;
|
|
1003
|
-
const float ax = static_cast<float>(rotateXValue) * kPiF * kInv1800f;
|
|
1004
|
-
e.pSinZ = sinf(az); e.pCosZ = cosf(az);
|
|
1005
|
-
e.pSinY = sinf(ay); e.pCosY = cosf(ay);
|
|
1006
|
-
e.pSinX = sinf(ax); e.pCosX = cosf(ax);
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
[[maybe_unused]] static bool nodeTransformMatches(const NodeTransformCache &e, const Node &node, int id)
|
|
1010
|
-
{
|
|
1011
|
-
// One RareStyle pool lookup, not one per compared field (see fillNodeTransform).
|
|
1012
|
-
const RareStyle &rs = rstyle(node.style);
|
|
1013
|
-
return e.nodeId == id &&
|
|
1014
|
-
e.x == node.layout.x &&
|
|
1015
|
-
e.y == node.layout.y &&
|
|
1016
|
-
e.w == node.layout.width &&
|
|
1017
|
-
e.h == node.layout.height &&
|
|
1018
|
-
e.rotate == rs.transform_rotate &&
|
|
1019
|
-
e.rotateX == rs.transform_rotate_x &&
|
|
1020
|
-
e.rotateY == rs.transform_rotate_y &&
|
|
1021
|
-
e.tx == rs.transform_translate_x &&
|
|
1022
|
-
e.ty == rs.transform_translate_y &&
|
|
1023
|
-
e.tz == rs.transform_translate_z &&
|
|
1024
|
-
e.txPercent == rs.transform_translate_x_percent &&
|
|
1025
|
-
e.tyPercent == rs.transform_translate_y_percent &&
|
|
1026
|
-
e.sx == rs.transform_scale_x &&
|
|
1027
|
-
e.sy == rs.transform_scale_y &&
|
|
1028
|
-
e.originX == rs.transform_origin_x &&
|
|
1029
|
-
e.originY == rs.transform_origin_y;
|
|
1027
|
+
const auto &r = node.render;
|
|
1028
|
+
if (!r.previous_transformable_box) {
|
|
1029
|
+
e.pOx = e.pOy = e.pTransX = e.pTransY = e.pTransZ = 0.0f;
|
|
1030
|
+
std::fill(std::begin(e.previousMatrix), std::end(e.previousMatrix), 0.0f);
|
|
1031
|
+
e.previousMatrix[0] = e.previousMatrix[4] = e.previousMatrix[8] = 1.0f;
|
|
1032
|
+
return;
|
|
1033
|
+
}
|
|
1034
|
+
const float w = node.layout.previous_width, h = node.layout.previous_height;
|
|
1035
|
+
e.pOx = node.layout.previous_x + w*r.previous_transform_origin_x*kInv1000f;
|
|
1036
|
+
e.pOy = node.layout.previous_y + h*r.previous_transform_origin_y*kInv1000f;
|
|
1037
|
+
fillLinear(e.previousMatrix, r.previous_transform_rotate_x, r.previous_transform_rotate_y, r.previous_transform_rotate,
|
|
1038
|
+
r.previous_transform_scale_x, r.previous_transform_scale_y, r.previous_transform_scale_z);
|
|
1039
|
+
auto shift = listTranslation({r.previous_transform_translate_x - r.previous_translate_x + w*(r.previous_transform_translate_x_percent-r.previous_translate_x_percent)*kInv1000f,
|
|
1040
|
+
r.previous_transform_translate_y - r.previous_translate_y + h*(r.previous_transform_translate_y_percent-r.previous_translate_y_percent)*kInv1000f,
|
|
1041
|
+
static_cast<float>(r.previous_transform_translate_z-r.previous_translate_z)}, r.previous_transform_translate_outer_axes,
|
|
1042
|
+
r.previous_transform_rotate_x, r.previous_transform_rotate_y, r.previous_transform_rotate);
|
|
1043
|
+
composeIndividual(e.previousMatrix, shift, r.previous_rotate_angle, r.previous_rotate_axis_x, r.previous_rotate_axis_y, r.previous_rotate_axis_z,
|
|
1044
|
+
r.previous_scale_x, r.previous_scale_y, r.previous_scale_z,
|
|
1045
|
+
{r.previous_translate_x + w*r.previous_translate_x_percent*kInv1000f, r.previous_translate_y + h*r.previous_translate_y_percent*kInv1000f, static_cast<float>(r.previous_translate_z)});
|
|
1046
|
+
e.pTransX = shift.x; e.pTransY = shift.y; e.pTransZ = shift.z;
|
|
1030
1047
|
}
|
|
1031
1048
|
|
|
1032
1049
|
static NodeTransformCache *cachedNodeTransform(const Node &node)
|
|
@@ -1095,18 +1112,42 @@ public:
|
|
|
1095
1112
|
// the per-node cache lookup out of its 4-corner loop and calls this directly.
|
|
1096
1113
|
static void applyCachedTransform(const NodeTransformCache &t, Point3 &p)
|
|
1097
1114
|
{
|
|
1098
|
-
p.x -= t.ox;
|
|
1099
|
-
p
|
|
1100
|
-
p.x
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1115
|
+
p.x -= t.ox; p.y -= t.oy;
|
|
1116
|
+
p = applyLinear(t.matrix, p);
|
|
1117
|
+
p.x += t.transX + t.ox; p.y += t.transY + t.oy; p.z += t.transZ;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
// Facing of a plane within its own CSS 3D rendering context.
|
|
1121
|
+
static bool backFacing(const Node &node)
|
|
1122
|
+
{
|
|
1123
|
+
auto &state = treeState();
|
|
1124
|
+
Point3 normal{0, 0, 1};
|
|
1125
|
+
float offset = 0;
|
|
1126
|
+
for (int id = nodeIndex(node); id >= 0 && id < state.nodeCount;) {
|
|
1127
|
+
const auto &t = nodeTransform(state.nodes[id]);
|
|
1128
|
+
const float *m = t.matrix;
|
|
1129
|
+
const float cofactors[9] = {
|
|
1130
|
+
m[4]*m[8]-m[5]*m[7], m[5]*m[6]-m[3]*m[8], m[3]*m[7]-m[4]*m[6],
|
|
1131
|
+
m[2]*m[7]-m[1]*m[8], m[0]*m[8]-m[2]*m[6], m[1]*m[6]-m[0]*m[7],
|
|
1132
|
+
m[1]*m[5]-m[2]*m[4], m[2]*m[3]-m[0]*m[5], m[0]*m[4]-m[1]*m[3]};
|
|
1133
|
+
const float determinant = m[0]*cofactors[0] + m[1]*cofactors[1] + m[2]*cofactors[2];
|
|
1134
|
+
if (determinant == 0) return true;
|
|
1135
|
+
offset += normal.x*t.ox + normal.y*t.oy;
|
|
1136
|
+
normal = applyLinear(cofactors, normal);
|
|
1137
|
+
normal.x /= determinant; normal.y /= determinant; normal.z /= determinant;
|
|
1138
|
+
offset -= normal.x*(t.transX+t.ox) + normal.y*(t.transY+t.oy) + normal.z*t.transZ;
|
|
1139
|
+
id = state.nodes[id].parent;
|
|
1140
|
+
if (id < 0 || id >= state.nodeCount) break;
|
|
1141
|
+
const auto &parent = state.nodes[id];
|
|
1142
|
+
const auto &rare = rstyle(parent.style);
|
|
1143
|
+
if (hasTransformableBox(parent) && rare.perspective > 0) {
|
|
1144
|
+
const float ox = parent.layout.x + parent.layout.width * rare.perspective_origin_x * 0.001f;
|
|
1145
|
+
const float oy = parent.layout.y + parent.layout.height * rare.perspective_origin_y * 0.001f;
|
|
1146
|
+
normal.z += (offset + normal.x * ox + normal.y * oy) / rare.perspective;
|
|
1147
|
+
}
|
|
1148
|
+
if (!hasTransformableBox(parent) || !preserves3D(parent.style)) break;
|
|
1149
|
+
}
|
|
1150
|
+
return normal.z < -0.00001f;
|
|
1110
1151
|
}
|
|
1111
1152
|
|
|
1112
1153
|
// Previous-frame analogue of applyCachedTransform — pure-FPU application of the
|
|
@@ -1114,18 +1155,9 @@ public:
|
|
|
1114
1155
|
// usePrevious branch, so the projected corner is bit-identical (no visual change).
|
|
1115
1156
|
static void applyCachedTransformPrev(const NodeTransformCache &t, Point3 &p)
|
|
1116
1157
|
{
|
|
1117
|
-
p.x -= t.pOx;
|
|
1118
|
-
p
|
|
1119
|
-
p.x
|
|
1120
|
-
p.y *= t.pScaleY;
|
|
1121
|
-
p.x += t.pTransX;
|
|
1122
|
-
p.y += t.pTransY;
|
|
1123
|
-
p.z += t.pTransZ;
|
|
1124
|
-
rotateZ(p, t.pSinZ, t.pCosZ);
|
|
1125
|
-
rotateY(p, t.pSinY, t.pCosY);
|
|
1126
|
-
rotateX(p, t.pSinX, t.pCosX);
|
|
1127
|
-
p.x += t.pOx;
|
|
1128
|
-
p.y += t.pOy;
|
|
1158
|
+
p.x -= t.pOx; p.y -= t.pOy;
|
|
1159
|
+
p = applyLinear(t.previousMatrix, p);
|
|
1160
|
+
p.x += t.pTransX + t.pOx; p.y += t.pTransY + t.pOy; p.z += t.pTransZ;
|
|
1129
1161
|
}
|
|
1130
1162
|
|
|
1131
1163
|
// Gather the ancestor chain's cached transform coefficients for the current
|
|
@@ -1179,39 +1211,9 @@ public:
|
|
|
1179
1211
|
return;
|
|
1180
1212
|
}
|
|
1181
1213
|
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
const int y = node.layout.previous_y;
|
|
1186
|
-
const int w = node.layout.previous_width;
|
|
1187
|
-
const int h = node.layout.previous_height;
|
|
1188
|
-
const int rotate = node.render.previous_transform_rotate;
|
|
1189
|
-
const int rotateXValue = node.render.previous_transform_rotate_x;
|
|
1190
|
-
const int rotateYValue = node.render.previous_transform_rotate_y;
|
|
1191
|
-
const int tx = node.render.previous_transform_translate_x;
|
|
1192
|
-
const int ty = node.render.previous_transform_translate_y;
|
|
1193
|
-
const int tz = node.render.previous_transform_translate_z;
|
|
1194
|
-
const int txPercent = node.render.previous_transform_translate_x_percent;
|
|
1195
|
-
const int tyPercent = node.render.previous_transform_translate_y_percent;
|
|
1196
|
-
const int sx = node.render.previous_transform_scale_x;
|
|
1197
|
-
const int sy = node.render.previous_transform_scale_y;
|
|
1198
|
-
const int originX = node.render.previous_transform_origin_x;
|
|
1199
|
-
const int originY = node.render.previous_transform_origin_y;
|
|
1200
|
-
|
|
1201
|
-
const float ox = static_cast<float>(x) + static_cast<float>(w) * static_cast<float>(originX) * kInv1000f;
|
|
1202
|
-
const float oy = static_cast<float>(y) + static_cast<float>(h) * static_cast<float>(originY) * kInv1000f;
|
|
1203
|
-
p.x -= ox;
|
|
1204
|
-
p.y -= oy;
|
|
1205
|
-
p.x *= static_cast<float>(sx) * kInv1000f;
|
|
1206
|
-
p.y *= static_cast<float>(sy) * kInv1000f;
|
|
1207
|
-
p.x += static_cast<float>(tx) + static_cast<float>(w) * static_cast<float>(txPercent) * kInv1000f;
|
|
1208
|
-
p.y += static_cast<float>(ty) + static_cast<float>(h) * static_cast<float>(tyPercent) * kInv1000f;
|
|
1209
|
-
p.z += tz;
|
|
1210
|
-
rotateZ(p, sinf(static_cast<float>(rotate) * kPiF * kInv1800f), cosf(static_cast<float>(rotate) * kPiF * kInv1800f));
|
|
1211
|
-
rotateY(p, sinf(static_cast<float>(rotateYValue) * kPiF * kInv1800f), cosf(static_cast<float>(rotateYValue) * kPiF * kInv1800f));
|
|
1212
|
-
rotateX(p, sinf(static_cast<float>(rotateXValue) * kPiF * kInv1800f), cosf(static_cast<float>(rotateXValue) * kPiF * kInv1800f));
|
|
1213
|
-
p.x += ox;
|
|
1214
|
-
p.y += oy;
|
|
1214
|
+
NodeTransformCache previous;
|
|
1215
|
+
fillNodeTransformPrev(previous, node);
|
|
1216
|
+
applyCachedTransformPrev(previous, p);
|
|
1215
1217
|
}
|
|
1216
1218
|
|
|
1217
1219
|
static int nearestPerspectiveNode(const Node &node, bool usePrevious)
|
|
@@ -1219,6 +1221,7 @@ public:
|
|
|
1219
1221
|
if (!anyTransformPresent()) return -1;
|
|
1220
1222
|
auto &state = treeState();
|
|
1221
1223
|
for (int id = nodeIndex(node); id >= 0 && id < state.nodeCount; id = state.nodes[id].parent) {
|
|
1224
|
+
if (usePrevious ? !state.nodes[id].render.previous_transformable_box : !hasTransformableBox(state.nodes[id])) continue;
|
|
1222
1225
|
const int perspective = usePrevious ? state.nodes[id].render.previous_perspective : rstyle(state.nodes[id].style).perspective;
|
|
1223
1226
|
if (perspective > 0) return id;
|
|
1224
1227
|
}
|
|
@@ -1480,17 +1483,67 @@ public:
|
|
|
1480
1483
|
}
|
|
1481
1484
|
};
|
|
1482
1485
|
|
|
1486
|
+
void appendReliefBordersWithAlpha(const Node &node, uint8_t parentAlpha)
|
|
1487
|
+
{
|
|
1488
|
+
using namespace gea::framework::graphics;
|
|
1489
|
+
const int w = node.layout.width, h = node.layout.height;
|
|
1490
|
+
if (w <= 0 || h <= 0) return;
|
|
1491
|
+
int widths[4];
|
|
1492
|
+
for (int side = 0; side < 4; ++side)
|
|
1493
|
+
widths[side] = std::min(computedBorderWidth(node.style, side), side % 2 ? w / 2 : h / 2);
|
|
1494
|
+
const bool transformed = ViewGeometry::hasTransformChain(node, false);
|
|
1495
|
+
for (int side = 0; side < 4; ++side) {
|
|
1496
|
+
if (widths[side] <= 0) continue;
|
|
1497
|
+
const int relief = rstyle(node.style).border_relief[side];
|
|
1498
|
+
const int bands = relief == 1 || relief == 2 ? 2 : 1;
|
|
1499
|
+
const auto color = borderPaintColor(node.style, side);
|
|
1500
|
+
int r, g, b; pixel::unpackRgb565(color, &r, &g, &b);
|
|
1501
|
+
r = pixel::expand5To8(r); g = pixel::expand6To8(g); b = pixel::expand5To8(b);
|
|
1502
|
+
// CSS permits UA-defined relief shades. Mixing with white keeps even a
|
|
1503
|
+
// black currentColor border visibly raised or recessed.
|
|
1504
|
+
const auto light = pixel::nativeColor((r * 3 + 510) / 5, (g * 3 + 510) / 5, (b * 3 + 510) / 5);
|
|
1505
|
+
const auto dark = pixel::nativeColor(r * 3 / 5, g * 3 / 5, b * 3 / 5);
|
|
1506
|
+
for (int band = 0; band < bands; ++band) {
|
|
1507
|
+
int16_t ringX[2][4], ringY[2][4];
|
|
1508
|
+
for (int ring = 0; ring < 2; ++ring) {
|
|
1509
|
+
int inset[4];
|
|
1510
|
+
for (int edge = 0; edge < 4; ++edge) inset[edge] = widths[edge] * (band + ring) / bands;
|
|
1511
|
+
const int left = node.layout.x + inset[3], right = node.layout.x + w - inset[1];
|
|
1512
|
+
const int top = node.layout.y + inset[0], bottom = node.layout.y + h - inset[2];
|
|
1513
|
+
const int px[4] = {left, right, right, left}, py[4] = {top, top, bottom, bottom};
|
|
1514
|
+
for (int corner = 0; corner < 4; ++corner) {
|
|
1515
|
+
if (transformed) ViewGeometry::transformPoint(node, false, px[corner], py[corner], 0, &ringX[ring][corner], &ringY[ring][corner]);
|
|
1516
|
+
else { ringX[ring][corner] = px[corner]; ringY[ring][corner] = py[corner]; }
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
const int next = (side + 1) % 4;
|
|
1520
|
+
const int16_t xs[4] = {ringX[0][side], ringX[0][next], ringX[1][next], ringX[1][side]};
|
|
1521
|
+
const int16_t ys[4] = {ringY[0][side], ringY[0][next], ringY[1][next], ringY[1][side]};
|
|
1522
|
+
const bool inset = relief == 3 || (relief == 1 && band == 0) || (relief == 2 && band == 1);
|
|
1523
|
+
const bool shadedDark = (side == 0 || side == 3) == inset;
|
|
1524
|
+
int bx0, by0, bx1, by1; boundsFromCorners(xs, ys, &bx0, &by0, &bx1, &by1);
|
|
1525
|
+
appendFillQuadWithAlpha(xs, ys, relief == 0 ? color : shadedDark ? dark : light,
|
|
1526
|
+
borderPaintAlpha(node.style, side), parentAlpha, bx0, by0, bx1 - bx0 + 1, by1 - by0 + 1);
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1483
1531
|
void appendSideBordersWithAlpha(const Node &node, uint8_t parentAlpha)
|
|
1484
1532
|
{
|
|
1485
1533
|
const int x = node.layout.x;
|
|
1486
1534
|
const int y = node.layout.y;
|
|
1487
1535
|
const int w = node.layout.width;
|
|
1488
1536
|
const int h = node.layout.height;
|
|
1489
|
-
if (
|
|
1537
|
+
if (hasBorderRelief(node.style)) { appendReliefBordersWithAlpha(node, parentAlpha); return; }
|
|
1538
|
+
const bool textClippedTransform = StyleValues::hasTextBackgroundClip(node.style) &&
|
|
1539
|
+
ViewGeometry::hasTransformChain(node, false) && !isFullyRoundedShape(node);
|
|
1540
|
+
if (w <= 0 || h <= 0 || (!hasSideBorder(node.style) && !borderColorsDiffer(node.style) && !textClippedTransform)) return;
|
|
1490
1541
|
|
|
1491
1542
|
const bool transformed = ViewGeometry::hasTransformChain(node, false);
|
|
1492
1543
|
for (int side = 0; side < 4; ++side) {
|
|
1493
|
-
const int borderWidth = rstyle(node.style).border_side_width[side];
|
|
1544
|
+
const int borderWidth = std::max<int>(node.style.border_width, rstyle(node.style).border_side_width[side]);
|
|
1545
|
+
const auto color = borderPaintColor(node.style, side);
|
|
1546
|
+
const auto alpha = borderPaintAlpha(node.style, side);
|
|
1494
1547
|
if (borderWidth <= 0) continue;
|
|
1495
1548
|
int sx = x;
|
|
1496
1549
|
int sy = y;
|
|
@@ -1507,6 +1560,14 @@ void appendSideBordersWithAlpha(const Node &node, uint8_t parentAlpha)
|
|
|
1507
1560
|
} else {
|
|
1508
1561
|
sw = std::min(borderWidth, w);
|
|
1509
1562
|
}
|
|
1563
|
+
// Horizontal edges own the corners. Avoid compositing a translucent
|
|
1564
|
+
// asymmetric border twice where two side rectangles would overlap.
|
|
1565
|
+
if (side == 1 || side == 3) {
|
|
1566
|
+
const int top = std::min<int>(std::max<int>(node.style.border_width, rstyle(node.style).border_side_width[0]), h);
|
|
1567
|
+
const int bottom = std::min<int>(std::max<int>(node.style.border_width, rstyle(node.style).border_side_width[2]), h - top);
|
|
1568
|
+
sy += top;
|
|
1569
|
+
sh -= top + bottom;
|
|
1570
|
+
}
|
|
1510
1571
|
if (sw <= 0 || sh <= 0) continue;
|
|
1511
1572
|
if (transformed) {
|
|
1512
1573
|
int16_t xs[4], ys[4];
|
|
@@ -1515,8 +1576,8 @@ void appendSideBordersWithAlpha(const Node &node, uint8_t parentAlpha)
|
|
|
1515
1576
|
boundsFromCorners(xs, ys, &bx0, &by0, &bx1, &by1);
|
|
1516
1577
|
appendFillQuadWithAlpha(xs,
|
|
1517
1578
|
ys,
|
|
1518
|
-
|
|
1519
|
-
|
|
1579
|
+
color,
|
|
1580
|
+
alpha,
|
|
1520
1581
|
parentAlpha,
|
|
1521
1582
|
bx0,
|
|
1522
1583
|
by0,
|
|
@@ -1532,8 +1593,8 @@ void appendSideBordersWithAlpha(const Node &node, uint8_t parentAlpha)
|
|
|
1532
1593
|
sy,
|
|
1533
1594
|
sw,
|
|
1534
1595
|
sh,
|
|
1535
|
-
|
|
1536
|
-
|
|
1596
|
+
color,
|
|
1597
|
+
alpha,
|
|
1537
1598
|
parentAlpha,
|
|
1538
1599
|
sx,
|
|
1539
1600
|
sy,
|
|
@@ -1600,10 +1661,10 @@ void recordLinearGradientBackground(const Node &node, uint8_t parentAlpha)
|
|
|
1600
1661
|
// span rasterizer paints the first/last edgeWidth px of every span, tracing
|
|
1601
1662
|
// the quad outline). Emitting projected stroke quads instead would disarm
|
|
1602
1663
|
// the transform-reproject fast path every frame.
|
|
1603
|
-
if (node.style.border_width > 0 && node.style.
|
|
1664
|
+
if (!StyleValues::hasTextBackgroundClip(node.style) && node.style.border_width > 0 && !hasBorderRelief(node.style) && !hasSideBorder(node.style) && !borderColorsDiffer(node.style) && borderPaintAlpha(node.style, 0) > 0 &&
|
|
1604
1665
|
!isFullyRoundedShape(node)) {
|
|
1605
|
-
g.edgeColor = node.style
|
|
1606
|
-
g.edgeAlpha = node.style
|
|
1666
|
+
g.edgeColor = borderPaintColor(node.style, 0);
|
|
1667
|
+
g.edgeAlpha = borderPaintAlpha(node.style, 0);
|
|
1607
1668
|
const int ew = node.style.border_width < 1 ? 1 : node.style.border_width;
|
|
1608
1669
|
g.edgeWidth = static_cast<uint8_t>(ew > 8 ? 8 : ew);
|
|
1609
1670
|
} else {
|
|
@@ -1651,6 +1712,77 @@ void recordOverlayLinearGradientBackground(const Node &node)
|
|
|
1651
1712
|
rstyle(node.style).bg_overlay_gradient_has_mid);
|
|
1652
1713
|
}
|
|
1653
1714
|
|
|
1715
|
+
// Background positioning and painting areas are distinct. In particular, the
|
|
1716
|
+
// document canvas paints beyond the root box without stretching its images.
|
|
1717
|
+
bool recordPlacedBackgrounds(const Node &geometry, const Node &source, bool canvas)
|
|
1718
|
+
{
|
|
1719
|
+
const auto &r = rstyle(source.style);
|
|
1720
|
+
if (!canvas && r.bg_size_list < 0 && r.bg_position_list < 0 && r.bg_repeat_list < 0 &&
|
|
1721
|
+
r.bg_attachment_list < 0 && r.bg_origin_list < 0) return false;
|
|
1722
|
+
if (ViewGeometry::hasTransformChain(geometry, false)) return false;
|
|
1723
|
+
const int nodeId = ViewGeometry::nodeIndex(geometry);
|
|
1724
|
+
for (int layer = r.bg_image_layer_count-1; layer >= 0; --layer) {
|
|
1725
|
+
const bool linear = source.style.bg_fill == 1 && layer == r.bg_gradient_layer;
|
|
1726
|
+
const bool overlay = r.bg_overlay_gradient && layer == r.bg_overlay_gradient_layer;
|
|
1727
|
+
const bool radial = r.bg_radial_gradient && layer == r.bg_radial_gradient_layer;
|
|
1728
|
+
if (!linear && !overlay && !radial) continue;
|
|
1729
|
+
const auto p = StyleValues::backgroundPlacement(source.style, nodeId, layer,
|
|
1730
|
+
geometry.layout.x, geometry.layout.y, geometry.layout.width, geometry.layout.height);
|
|
1731
|
+
if (p.width <= 0 || p.height <= 0) continue;
|
|
1732
|
+
int x = canvas ? 0 : geometry.layout.x, y = canvas ? 0 : geometry.layout.y;
|
|
1733
|
+
int w = canvas ? treeState().mountedWidth : geometry.layout.width;
|
|
1734
|
+
int h = canvas ? treeState().mountedHeight : geometry.layout.height;
|
|
1735
|
+
const int clip = canvas ? 0 : StyleValues::backgroundClip(source.style, layer);
|
|
1736
|
+
TextBackgroundClipScope textClip(source, clip);
|
|
1737
|
+
if (clip == 1 || clip == 2) {
|
|
1738
|
+
int inset[4];
|
|
1739
|
+
for (int i = 0; i < 4; ++i) inset[i] = std::max<int>(geometry.style.border_width, rstyle(geometry.style).border_side_width[i]) +
|
|
1740
|
+
(clip == 2 ? std::max<int>(0, geometry.style.padding[i]) : 0);
|
|
1741
|
+
x += inset[3]; y += inset[0]; w -= inset[1]+inset[3]; h -= inset[0]+inset[2];
|
|
1742
|
+
}
|
|
1743
|
+
if (w <= 0 || h <= 0) continue;
|
|
1744
|
+
auto *begin = DisplayList::instance().append();
|
|
1745
|
+
if (!begin) return true;
|
|
1746
|
+
begin->type = DisplayCommandType::PushClip;
|
|
1747
|
+
begin->bx = begin->clip.x = x; begin->by = begin->clip.y = y;
|
|
1748
|
+
begin->bw = begin->clip.w = w; begin->bh = begin->clip.h = h; begin->clip.nodeId = -1;
|
|
1749
|
+
struct TileAxis { double start, step; int count; };
|
|
1750
|
+
auto axis = [](int position, int size, int mode, int area, int areaSize, int clipStart, int clipSize) -> TileAxis {
|
|
1751
|
+
if (mode == 1) return {static_cast<double>(position), static_cast<double>(size), 1};
|
|
1752
|
+
if (mode == 3) {
|
|
1753
|
+
const int count = areaSize/size;
|
|
1754
|
+
if (count < 2) return {static_cast<double>(position), static_cast<double>(size), 1};
|
|
1755
|
+
return {static_cast<double>(area), static_cast<double>(areaSize-size)/(count-1), count};
|
|
1756
|
+
}
|
|
1757
|
+
const int start = position + static_cast<int>(std::floor(static_cast<double>(clipStart-position)/size))*size;
|
|
1758
|
+
return {static_cast<double>(start), static_cast<double>(size), (clipStart+clipSize-start+size-1)/size};
|
|
1759
|
+
};
|
|
1760
|
+
const auto ax = axis(p.x,p.width,p.repeatX,p.areaX,p.areaWidth,x,w), ay = axis(p.y,p.height,p.repeatY,p.areaY,p.areaHeight,y,h);
|
|
1761
|
+
for (int row = 0; row < ay.count; ++row) for (int col = 0; col < ax.count; ++col) {
|
|
1762
|
+
const int tx = std::lround(ax.start+col*ax.step), ty = std::lround(ay.start+row*ay.step);
|
|
1763
|
+
if (tx >= x+w || ty >= y+h || tx+p.width <= x || ty+p.height <= y) continue;
|
|
1764
|
+
DisplayCommand *paint = nullptr;
|
|
1765
|
+
if (linear) paint = appendLinearGradientRectRaw(source,tx,ty,p.width,p.height);
|
|
1766
|
+
else if (radial) paint = appendRadialGradientRectRaw(source,tx,ty,p.width,p.height);
|
|
1767
|
+
else paint = appendLinearGradientRectRaw(source,tx,ty,p.width,p.height,
|
|
1768
|
+
r.bg_overlay_gradient_from_color,r.bg_overlay_gradient_mid_color,r.bg_overlay_gradient_to_color,
|
|
1769
|
+
r.bg_overlay_gradient_mid_stop,r.bg_overlay_gradient_to_stop,r.bg_overlay_gradient_angle,
|
|
1770
|
+
r.bg_overlay_gradient_from_alpha,r.bg_overlay_gradient_mid_alpha,r.bg_overlay_gradient_to_alpha,r.bg_overlay_gradient_has_mid);
|
|
1771
|
+
// Radius belongs to the painting box, never to each repeated image.
|
|
1772
|
+
if (paint) {
|
|
1773
|
+
auto &cmd = *paint;
|
|
1774
|
+
if (radial) cmd.radialGradient.tl = cmd.radialGradient.tr = cmd.radialGradient.br = cmd.radialGradient.bl = 0;
|
|
1775
|
+
else cmd.gradient.tl = cmd.gradient.tr = cmd.gradient.br = cmd.gradient.bl = 0;
|
|
1776
|
+
cmd.bx = std::max(x, tx); cmd.by = std::max(y, ty);
|
|
1777
|
+
cmd.bw = std::min(x+w,tx+p.width)-cmd.bx; cmd.bh = std::min(y+h,ty+p.height)-cmd.by;
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
auto *end = DisplayList::instance().append();
|
|
1781
|
+
if (end) { end->type = DisplayCommandType::PopClip; end->bx = x; end->by = y; end->bw = w; end->bh = h; end->clip.nodeId = -1; }
|
|
1782
|
+
}
|
|
1783
|
+
return true;
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1654
1786
|
void recordTransformedEllipseFill(const Node &node, uint8_t parentAlpha)
|
|
1655
1787
|
{
|
|
1656
1788
|
const int x = node.layout.x;
|
|
@@ -1694,12 +1826,17 @@ void recordTransformedEllipseFill(const Node &node, uint8_t parentAlpha)
|
|
|
1694
1826
|
if (effectiveAlpha != parentAlpha) appendAlphaCommand(parentAlpha, bx0, by0, bx1 - bx0 + 1, by1 - by0 + 1);
|
|
1695
1827
|
}
|
|
1696
1828
|
|
|
1697
|
-
void recordTransformedRoundedRectFill(const Node &node, uint8_t parentAlpha)
|
|
1829
|
+
void recordTransformedRoundedRectFill(const Node &node, uint8_t parentAlpha, int backgroundClip = 0)
|
|
1698
1830
|
{
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1831
|
+
int inset[4]{};
|
|
1832
|
+
if (backgroundClip > 0)
|
|
1833
|
+
for (int i = 0; i < 4; ++i)
|
|
1834
|
+
inset[i] = std::max<int>(node.style.border_width, rstyle(node.style).border_side_width[i]) +
|
|
1835
|
+
(backgroundClip == 2 ? std::max<int>(0, node.style.padding[i]) : 0);
|
|
1836
|
+
const int x = node.layout.x + inset[3];
|
|
1837
|
+
const int y = node.layout.y + inset[0];
|
|
1838
|
+
const int w = node.layout.width - inset[3] - inset[1];
|
|
1839
|
+
const int h = node.layout.height - inset[0] - inset[2];
|
|
1703
1840
|
if (w <= 0 || h <= 0) return;
|
|
1704
1841
|
|
|
1705
1842
|
int16_t xs[4], ys[4];
|
|
@@ -1711,6 +1848,10 @@ void recordTransformedRoundedRectFill(const Node &node, uint8_t parentAlpha)
|
|
|
1711
1848
|
int16_t rx8[4]{};
|
|
1712
1849
|
int16_t ry8[4]{};
|
|
1713
1850
|
resolvedBorderRadii8(node, rx8, ry8);
|
|
1851
|
+
for (int i = 0; i < 4; ++i) {
|
|
1852
|
+
rx8[i] = std::max(0, int(rx8[i]) - 8 * inset[i == 0 || i == 3 ? 3 : 1]);
|
|
1853
|
+
ry8[i] = std::max(0, int(ry8[i]) - 8 * inset[i < 2 ? 0 : 2]);
|
|
1854
|
+
}
|
|
1714
1855
|
DisplayCommand *cmd = DisplayList::instance().append();
|
|
1715
1856
|
if (cmd) {
|
|
1716
1857
|
cmd->type = DisplayCommandType::FillTransformedRoundedRect;
|
|
@@ -1748,7 +1889,7 @@ void recordTransformedEllipseStroke(const Node &node, uint8_t parentAlpha)
|
|
|
1748
1889
|
|
|
1749
1890
|
int bx0, by0, bx1, by1;
|
|
1750
1891
|
ViewRenderer::transformedBounds(node, false, &bx0, &by0, &bx1, &by1);
|
|
1751
|
-
const uint8_t effectiveAlpha = combineAlpha(parentAlpha, node.style
|
|
1892
|
+
const uint8_t effectiveAlpha = combineAlpha(parentAlpha, borderPaintAlpha(node.style, 0));
|
|
1752
1893
|
if (effectiveAlpha != parentAlpha) appendAlphaCommand(effectiveAlpha, bx0, by0, bx1 - bx0 + 1, by1 - by0 + 1);
|
|
1753
1894
|
|
|
1754
1895
|
const float cx = static_cast<float>(x) + static_cast<float>(w) * 0.5f;
|
|
@@ -1776,7 +1917,7 @@ void recordTransformedEllipseStroke(const Node &node, uint8_t parentAlpha)
|
|
|
1776
1917
|
int16_t px, py;
|
|
1777
1918
|
ViewGeometry::projectPoint(projector, localX, localY, 0.0f, &px, &py);
|
|
1778
1919
|
if (i > 0)
|
|
1779
|
-
appendStrokeSegmentBandRaw(prevX, prevY, px, py, screenStroke, node.style
|
|
1920
|
+
appendStrokeSegmentBandRaw(prevX, prevY, px, py, screenStroke, borderPaintColor(node.style, 0),
|
|
1780
1921
|
prevLocalX, prevLocalY, localX, localY, true);
|
|
1781
1922
|
prevX = px;
|
|
1782
1923
|
prevY = py;
|
|
@@ -1844,6 +1985,7 @@ void appendBackgroundGridRectRaw(const Node &node, int x, int y, int w, int h)
|
|
|
1844
1985
|
void recordBackgroundGrid(const Node &node, uint8_t parentAlpha)
|
|
1845
1986
|
{
|
|
1846
1987
|
if (rstyle(node.style).bg_grid_axes == 0) return;
|
|
1988
|
+
const auto placement = StyleValues::backgroundPlacement(node.style, ViewGeometry::nodeIndex(node), 0, node.layout.x, node.layout.y, node.layout.width, node.layout.height);
|
|
1847
1989
|
const int x0 = node.layout.x;
|
|
1848
1990
|
const int y0 = node.layout.y;
|
|
1849
1991
|
const int x1 = node.layout.x + node.layout.width;
|
|
@@ -1857,7 +1999,7 @@ void recordBackgroundGrid(const Node &node, uint8_t parentAlpha)
|
|
|
1857
1999
|
if (effectiveAlpha != parentAlpha) appendAlphaCommand(effectiveAlpha, bx0, by0, bx1 - bx0 + 1, by1 - by0 + 1);
|
|
1858
2000
|
|
|
1859
2001
|
if ((rstyle(node.style).bg_grid_axes & 1) != 0 && rstyle(node.style).bg_grid_line_x > 0) {
|
|
1860
|
-
const int step = rstyle(node.style).bg_grid_step_x > 0 ? rstyle(node.style).bg_grid_step_x : rstyle(node.style).bg_grid_line_x;
|
|
2002
|
+
const int step = rstyle(node.style).bg_size_list >= 0 ? placement.width : rstyle(node.style).bg_grid_step_x > 0 ? rstyle(node.style).bg_grid_step_x : rstyle(node.style).bg_grid_line_x;
|
|
1861
2003
|
if (step > 0) {
|
|
1862
2004
|
for (int x = x0; x < x1; x += step) {
|
|
1863
2005
|
const int w = std::min<int>(rstyle(node.style).bg_grid_line_x, x1 - x);
|
|
@@ -1866,7 +2008,7 @@ void recordBackgroundGrid(const Node &node, uint8_t parentAlpha)
|
|
|
1866
2008
|
}
|
|
1867
2009
|
}
|
|
1868
2010
|
if ((rstyle(node.style).bg_grid_axes & 2) != 0 && rstyle(node.style).bg_grid_line_y > 0) {
|
|
1869
|
-
const int step = rstyle(node.style).bg_grid_step_y > 0 ? rstyle(node.style).bg_grid_step_y : rstyle(node.style).bg_grid_line_y;
|
|
2011
|
+
const int step = rstyle(node.style).bg_size_list >= 0 ? placement.height : rstyle(node.style).bg_grid_step_y > 0 ? rstyle(node.style).bg_grid_step_y : rstyle(node.style).bg_grid_line_y;
|
|
1870
2012
|
if (step > 0) {
|
|
1871
2013
|
for (int y = y0; y < y1; y += step) {
|
|
1872
2014
|
const int h = std::min<int>(rstyle(node.style).bg_grid_line_y, y1 - y);
|
|
@@ -1960,6 +2102,156 @@ void appendInsetShadowBand(const Node &node, uint8_t parentAlpha, int x, int y,
|
|
|
1960
2102
|
flushRun();
|
|
1961
2103
|
}
|
|
1962
2104
|
|
|
2105
|
+
// The inset shadow is the padding contour minus an offset, spread-adjusted
|
|
2106
|
+
// hole. Represent both contours explicitly: independent edge bands overlap at
|
|
2107
|
+
// corners and cannot describe rounded holes or negative spread.
|
|
2108
|
+
struct ShadowContour {
|
|
2109
|
+
float x, y, w, h;
|
|
2110
|
+
float rx[4]{}, ry[4]{};
|
|
2111
|
+
};
|
|
2112
|
+
|
|
2113
|
+
void constrainShadowRadii(ShadowContour &shape)
|
|
2114
|
+
{
|
|
2115
|
+
float scale = 1.0f;
|
|
2116
|
+
auto constrain = [&](float limit, float sum) {
|
|
2117
|
+
if (sum > limit && sum > 0) scale = std::min(scale, std::max(0.0f, limit) / sum);
|
|
2118
|
+
};
|
|
2119
|
+
constrain(shape.w, shape.rx[0] + shape.rx[1]);
|
|
2120
|
+
constrain(shape.w, shape.rx[3] + shape.rx[2]);
|
|
2121
|
+
constrain(shape.h, shape.ry[0] + shape.ry[3]);
|
|
2122
|
+
constrain(shape.h, shape.ry[1] + shape.ry[2]);
|
|
2123
|
+
for (int i = 0; i < 4; ++i) { shape.rx[i] *= scale; shape.ry[i] *= scale; }
|
|
2124
|
+
}
|
|
2125
|
+
|
|
2126
|
+
ShadowContour insetShadowClip(const Node &node)
|
|
2127
|
+
{
|
|
2128
|
+
int border[4];
|
|
2129
|
+
for (int i = 0; i < 4; ++i) border[i] = std::max<int>(node.style.border_width, rstyle(node.style).border_side_width[i]);
|
|
2130
|
+
ShadowContour shape{float(node.layout.x + border[3]), float(node.layout.y + border[0]),
|
|
2131
|
+
float(std::max(0, node.layout.width - border[3] - border[1])),
|
|
2132
|
+
float(std::max(0, node.layout.height - border[0] - border[2]))};
|
|
2133
|
+
int16_t rx8[4], ry8[4];
|
|
2134
|
+
resolvedBorderRadii8(node, rx8, ry8);
|
|
2135
|
+
for (int i = 0; i < 4; ++i) {
|
|
2136
|
+
shape.rx[i] = std::max(0.0f, rx8[i] * 0.125f - border[(i == 0 || i == 3) ? 3 : 1]);
|
|
2137
|
+
shape.ry[i] = std::max(0.0f, ry8[i] * 0.125f - border[i < 2 ? 0 : 2]);
|
|
2138
|
+
}
|
|
2139
|
+
constrainShadowRadii(shape);
|
|
2140
|
+
return shape;
|
|
2141
|
+
}
|
|
2142
|
+
|
|
2143
|
+
ShadowContour insetShadowHole(const ShadowContour &clip, int spread, int ox, int oy)
|
|
2144
|
+
{
|
|
2145
|
+
ShadowContour hole = clip;
|
|
2146
|
+
hole.x += spread + ox;
|
|
2147
|
+
hole.y += spread + oy;
|
|
2148
|
+
hole.w = std::max(0.0f, hole.w - 2 * spread);
|
|
2149
|
+
hole.h = std::max(0.0f, hole.h - 2 * spread);
|
|
2150
|
+
auto radius = [spread](float r) {
|
|
2151
|
+
float adjustment = float(spread);
|
|
2152
|
+
if (spread < 0 && r < -spread) {
|
|
2153
|
+
const float ratio = r / -spread - 1.0f;
|
|
2154
|
+
adjustment *= 1.0f + ratio * ratio * ratio;
|
|
2155
|
+
}
|
|
2156
|
+
return std::max(0.0f, r - adjustment);
|
|
2157
|
+
};
|
|
2158
|
+
for (int i = 0; i < 4; ++i) { hole.rx[i] = radius(hole.rx[i]); hole.ry[i] = radius(hole.ry[i]); }
|
|
2159
|
+
constrainShadowRadii(hole);
|
|
2160
|
+
return hole;
|
|
2161
|
+
}
|
|
2162
|
+
|
|
2163
|
+
bool shadowContourRow(const ShadowContour &shape, int y, int &left, int &right)
|
|
2164
|
+
{
|
|
2165
|
+
const float py = y + 0.5f;
|
|
2166
|
+
if (shape.w <= 0 || shape.h <= 0 || py < shape.y || py >= shape.y + shape.h) return false;
|
|
2167
|
+
float x0 = shape.x, x1 = shape.x + shape.w;
|
|
2168
|
+
for (int i = 0; i < 4; ++i) {
|
|
2169
|
+
const bool top = i < 2, isLeft = i == 0 || i == 3;
|
|
2170
|
+
const float rx = shape.rx[i], ry = shape.ry[i];
|
|
2171
|
+
if (rx <= 0 || ry <= 0) continue;
|
|
2172
|
+
const float cy = top ? shape.y + ry : shape.y + shape.h - ry;
|
|
2173
|
+
if (top ? py >= cy : py <= cy) continue;
|
|
2174
|
+
const float dy = (py - cy) / ry;
|
|
2175
|
+
const float inset = rx * (1.0f - std::sqrt(std::max(0.0f, 1.0f - dy * dy)));
|
|
2176
|
+
if (isLeft) x0 = std::max(x0, shape.x + inset);
|
|
2177
|
+
else x1 = std::min(x1, shape.x + shape.w - inset);
|
|
2178
|
+
}
|
|
2179
|
+
left = static_cast<int>(std::ceil(x0 - 0.5f));
|
|
2180
|
+
right = static_cast<int>(std::ceil(x1 - 0.5f)) - 1;
|
|
2181
|
+
return left <= right;
|
|
2182
|
+
}
|
|
2183
|
+
|
|
2184
|
+
void appendShadowRect(const Node &node, uint8_t parentAlpha, int x, int y, int w, int h)
|
|
2185
|
+
{
|
|
2186
|
+
if (w <= 0 || h <= 0) return;
|
|
2187
|
+
const auto color = rstyle(node.style).box_shadow_color;
|
|
2188
|
+
const auto alpha = rstyle(node.style).box_shadow_alpha;
|
|
2189
|
+
if (!ViewGeometry::hasTransformChain(node, false)) {
|
|
2190
|
+
appendFillRectWithAlpha(x, y, w, h, color, alpha, parentAlpha, x, y, w, h);
|
|
2191
|
+
return;
|
|
2192
|
+
}
|
|
2193
|
+
int16_t xs[4], ys[4];
|
|
2194
|
+
ViewGeometry::transformRectCorners(node, false, x, y, w, h, xs, ys);
|
|
2195
|
+
int x0, y0, x1, y1;
|
|
2196
|
+
boundsFromCorners(xs, ys, &x0, &y0, &x1, &y1);
|
|
2197
|
+
appendFillQuadWithAlpha(xs, ys, color, alpha, parentAlpha, x0, y0, x1 - x0 + 1, y1 - y0 + 1, x, y, w, h, true);
|
|
2198
|
+
}
|
|
2199
|
+
|
|
2200
|
+
void recordSharpInsetShadow(const Node &node, uint8_t parentAlpha, const ShadowContour &clip, int spread, int ox, int oy)
|
|
2201
|
+
{
|
|
2202
|
+
if (clip.w <= 0 || clip.h <= 0) return;
|
|
2203
|
+
const ShadowContour hole = insetShadowHole(clip, spread, ox, oy);
|
|
2204
|
+
// A centered, opaque circular ring can use the same native stroke primitive
|
|
2205
|
+
// as a border. All other contours use disjoint spans, composited exactly once.
|
|
2206
|
+
bool circular = true;
|
|
2207
|
+
for (int i = 0; i < 4; ++i) circular &= clip.rx[i] == clip.ry[i] && clip.rx[i] == std::floor(clip.rx[i]) && clip.rx[i] <= std::min(clip.w, clip.h) * 0.5f;
|
|
2208
|
+
if (ox == 0 && oy == 0 && spread > 0 && hole.w > 0 && hole.h > 0 && circular &&
|
|
2209
|
+
combineAlpha(parentAlpha, rstyle(node.style).box_shadow_alpha) == 255 &&
|
|
2210
|
+
!ViewGeometry::hasTransformChain(node, false)) {
|
|
2211
|
+
DisplayCommand *cmd = DisplayList::instance().append();
|
|
2212
|
+
if (cmd) {
|
|
2213
|
+
cmd->type = DisplayCommandType::StrokeRoundedRect;
|
|
2214
|
+
cmd->strokeRoundedRect = {};
|
|
2215
|
+
cmd->bx = cmd->strokeRoundedRect.x = static_cast<int16_t>(clip.x);
|
|
2216
|
+
cmd->by = cmd->strokeRoundedRect.y = static_cast<int16_t>(clip.y);
|
|
2217
|
+
cmd->bw = cmd->strokeRoundedRect.w = static_cast<int16_t>(clip.w);
|
|
2218
|
+
cmd->bh = cmd->strokeRoundedRect.h = static_cast<int16_t>(clip.h);
|
|
2219
|
+
cmd->strokeRoundedRect.tl = static_cast<int16_t>(clip.rx[0]);
|
|
2220
|
+
cmd->strokeRoundedRect.tr = static_cast<int16_t>(clip.rx[1]);
|
|
2221
|
+
cmd->strokeRoundedRect.br = static_cast<int16_t>(clip.rx[2]);
|
|
2222
|
+
cmd->strokeRoundedRect.bl = static_cast<int16_t>(clip.rx[3]);
|
|
2223
|
+
cmd->strokeRoundedRect.lineWidth = spread;
|
|
2224
|
+
cmd->strokeRoundedRect.color = rstyle(node.style).box_shadow_color;
|
|
2225
|
+
}
|
|
2226
|
+
return;
|
|
2227
|
+
}
|
|
2228
|
+
struct Run { int left = 0, right = -1, y = 0, height = 0; } runs[2];
|
|
2229
|
+
auto flush = [&](Run &run) {
|
|
2230
|
+
if (run.height > 0) appendShadowRect(node, parentAlpha, run.left, run.y, run.right - run.left + 1, run.height);
|
|
2231
|
+
run.height = 0;
|
|
2232
|
+
};
|
|
2233
|
+
for (int y = static_cast<int>(clip.y); y < clip.y + clip.h; ++y) {
|
|
2234
|
+
int left = 0, right = -1, holeLeft = 0, holeRight = -1;
|
|
2235
|
+
const bool hasClip = shadowContourRow(clip, y, left, right);
|
|
2236
|
+
const bool hasHole = shadowContourRow(hole, y, holeLeft, holeRight);
|
|
2237
|
+
int starts[2] = {left, 0}, ends[2] = {right, -1};
|
|
2238
|
+
if (!hasClip) ends[0] = starts[0] - 1;
|
|
2239
|
+
else if (hasHole && holeLeft <= right && holeRight >= left) {
|
|
2240
|
+
ends[0] = std::min(right, holeLeft - 1);
|
|
2241
|
+
starts[1] = std::max(left, holeRight + 1);
|
|
2242
|
+
ends[1] = right;
|
|
2243
|
+
}
|
|
2244
|
+
for (int i = 0; i < 2; ++i) {
|
|
2245
|
+
auto &run = runs[i];
|
|
2246
|
+
if (starts[i] > ends[i]) { flush(run); continue; }
|
|
2247
|
+
if (run.height && run.left == starts[i] && run.right == ends[i]) { ++run.height; continue; }
|
|
2248
|
+
flush(run);
|
|
2249
|
+
run = Run{starts[i], ends[i], y, 1};
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2252
|
+
for (auto &run : runs) flush(run);
|
|
2253
|
+
}
|
|
2254
|
+
|
|
1963
2255
|
void recordInsetBoxShadow(const Node &node, uint8_t parentAlpha)
|
|
1964
2256
|
{
|
|
1965
2257
|
if (!rstyle(node.style).box_shadow_inset || rstyle(node.style).box_shadow_alpha == 0) return;
|
|
@@ -1970,6 +2262,11 @@ void recordInsetBoxShadow(const Node &node, uint8_t parentAlpha)
|
|
|
1970
2262
|
if (w <= 0 || h <= 0) return;
|
|
1971
2263
|
|
|
1972
2264
|
const int blur = std::max<int>(0, rstyle(node.style).box_shadow_blur_radius);
|
|
2265
|
+
if (blur == 0) {
|
|
2266
|
+
recordSharpInsetShadow(node, parentAlpha, insetShadowClip(node), rstyle(node.style).box_shadow_spread,
|
|
2267
|
+
rstyle(node.style).box_shadow_offset_x, rstyle(node.style).box_shadow_offset_y);
|
|
2268
|
+
return;
|
|
2269
|
+
}
|
|
1973
2270
|
const int spread = std::max<int>(0, rstyle(node.style).box_shadow_spread);
|
|
1974
2271
|
const int ox = rstyle(node.style).box_shadow_offset_x;
|
|
1975
2272
|
const int oy = rstyle(node.style).box_shadow_offset_y;
|
|
@@ -2065,6 +2362,18 @@ void GEA_VIEW_HOT_SRAM_SECTION("view_renderer_transformed_point") ViewRenderer::
|
|
|
2065
2362
|
ViewGeometry::transformPoint(node, usePrevious, x, y, z, outX, outY);
|
|
2066
2363
|
}
|
|
2067
2364
|
|
|
2365
|
+
bool ViewRenderer::backfaceSubtreeHidden(const Node &node)
|
|
2366
|
+
{
|
|
2367
|
+
const auto &state = treeState();
|
|
2368
|
+
for (int id = ViewGeometry::nodeIndex(node); id >= 0 && id < state.nodeCount; id = state.nodes[id].parent) {
|
|
2369
|
+
const auto &ancestor = state.nodes[id];
|
|
2370
|
+
if (ViewGeometry::hasTransformableBox(ancestor) && ancestor.style.backface_hidden &&
|
|
2371
|
+
!preserves3D(ancestor.style) && ViewGeometry::backFacing(ancestor))
|
|
2372
|
+
return true;
|
|
2373
|
+
}
|
|
2374
|
+
return false;
|
|
2375
|
+
}
|
|
2376
|
+
|
|
2068
2377
|
void GEA_VIEW_HOT_SRAM_SECTION("view_renderer_transformed_rect_corners") ViewRenderer::transformedRectCorners(const Node &node, bool usePrevious, int x, int y, int w, int h, int16_t *xs, int16_t *ys,
|
|
2069
2378
|
int16_t *xs8, int16_t *ys8)
|
|
2070
2379
|
{
|
|
@@ -2076,6 +2385,11 @@ int GEA_VIEW_HOT_SRAM_SECTION("view_renderer_transformed_depth") ViewRenderer::t
|
|
|
2076
2385
|
return ViewGeometry::averageDepth(node, usePrevious);
|
|
2077
2386
|
}
|
|
2078
2387
|
|
|
2388
|
+
bool ViewRenderer::isTransformableBox(const Node &node)
|
|
2389
|
+
{
|
|
2390
|
+
return ViewGeometry::hasTransformableBox(node);
|
|
2391
|
+
}
|
|
2392
|
+
|
|
2079
2393
|
bool GEA_VIEW_HOT_SRAM_SECTION("view_renderer_any_transform_active") ViewRenderer::anyTransformActive()
|
|
2080
2394
|
{
|
|
2081
2395
|
return ViewGeometry::anyTransformPresent();
|
|
@@ -2088,17 +2402,15 @@ bool ViewRenderer::recordClipBegin(const Node &node)
|
|
|
2088
2402
|
if (!isViewLikeNodeType(n->type) || n->style.overflow == 0) return 0;
|
|
2089
2403
|
if (n->first_child < 0) return 0;
|
|
2090
2404
|
|
|
2405
|
+
int x, y, w, h;
|
|
2406
|
+
overflowClipBounds(node, x, y, w, h);
|
|
2091
2407
|
DisplayCommand *cmd = DisplayList::instance().append();
|
|
2092
2408
|
if (cmd) {
|
|
2093
2409
|
cmd->type = DisplayCommandType::PushClip;
|
|
2094
|
-
cmd->bx =
|
|
2095
|
-
cmd->by =
|
|
2096
|
-
cmd->bw =
|
|
2097
|
-
cmd->bh =
|
|
2098
|
-
cmd->clip.x = n->layout.x;
|
|
2099
|
-
cmd->clip.y = n->layout.y;
|
|
2100
|
-
cmd->clip.w = n->layout.width;
|
|
2101
|
-
cmd->clip.h = n->layout.height;
|
|
2410
|
+
cmd->bx = cmd->clip.x = x;
|
|
2411
|
+
cmd->by = cmd->clip.y = y;
|
|
2412
|
+
cmd->bw = cmd->clip.w = w;
|
|
2413
|
+
cmd->bh = cmd->clip.h = h;
|
|
2102
2414
|
cmd->clip.nodeId = static_cast<int16_t>(&node - Tree::instance().nodes());
|
|
2103
2415
|
}
|
|
2104
2416
|
return 1;
|
|
@@ -2134,6 +2446,22 @@ void ViewRenderer::recordClipEnd(const Node &node)
|
|
|
2134
2446
|
cmd->clip.nodeId = static_cast<int16_t>(&node - Tree::instance().nodes());
|
|
2135
2447
|
}
|
|
2136
2448
|
|
|
2449
|
+
int ViewRenderer::canvasBackgroundSource()
|
|
2450
|
+
{
|
|
2451
|
+
const auto &state = treeState();
|
|
2452
|
+
const int root = state.mountedRoot;
|
|
2453
|
+
if (root < 0 || root >= state.nodeCount || !isDocumentCanvasRoot(state.nodes[root])) return -1;
|
|
2454
|
+
const Node &html = state.nodes[root];
|
|
2455
|
+
// CSS Backgrounds: a transparent root with no images takes the first
|
|
2456
|
+
// direct body's background. Its used background is then transparent.
|
|
2457
|
+
if (!rstyle(html.style).containment && (!html.style.has_bg || html.style.bg_alpha == 0) && !styleHasBackgroundImage(html.style)) {
|
|
2458
|
+
for (int child = html.first_child; child >= 0; child = state.nodes[child].next_sibling)
|
|
2459
|
+
if (std::string_view(tagFromId(state.nodes[child].tag_id)) == "body")
|
|
2460
|
+
return rstyle(state.nodes[child].style).containment ? root : child;
|
|
2461
|
+
}
|
|
2462
|
+
return root;
|
|
2463
|
+
}
|
|
2464
|
+
|
|
2137
2465
|
void GEA_VIEW_HOT_SRAM_SECTION("view_renderer_record_box") ViewRenderer::recordBox(const Node &node, uint8_t parentAlpha)
|
|
2138
2466
|
{
|
|
2139
2467
|
const Node *n = &node;
|
|
@@ -2141,35 +2469,68 @@ void GEA_VIEW_HOT_SRAM_SECTION("view_renderer_record_box") ViewRenderer::recordB
|
|
|
2141
2469
|
int y = n->layout.y;
|
|
2142
2470
|
int w = n->layout.width;
|
|
2143
2471
|
int h = n->layout.height;
|
|
2472
|
+
const int canvasSource = canvasBackgroundSource();
|
|
2473
|
+
const bool canvasRoot = isDocumentCanvasRoot(node);
|
|
2474
|
+
if (canvasRoot && canvasSource >= 0) {
|
|
2475
|
+
const auto &state = treeState();
|
|
2476
|
+
const auto &source = state.nodes[canvasSource].style;
|
|
2477
|
+
if (source.display != 1 && source.has_bg && source.bg_alpha > 0)
|
|
2478
|
+
appendFillRectWithAlpha(0, 0, state.mountedWidth, state.mountedHeight,
|
|
2479
|
+
source.bg_color, source.bg_alpha, parentAlpha, 0, 0, state.mountedWidth, state.mountedHeight);
|
|
2480
|
+
if (source.display != 1) {
|
|
2481
|
+
const auto &imageSource = state.nodes[canvasSource];
|
|
2482
|
+
if (!recordPlacedBackgrounds(node, imageSource, true)) {
|
|
2483
|
+
if (source.bg_fill == 1) recordLinearGradientBackground(imageSource, parentAlpha);
|
|
2484
|
+
recordRadialGradientBackground(imageSource); recordOverlayLinearGradientBackground(imageSource);
|
|
2485
|
+
}
|
|
2486
|
+
recordBackgroundGrid(imageSource, parentAlpha);
|
|
2487
|
+
}
|
|
2488
|
+
}
|
|
2144
2489
|
if (w <= 0 || h <= 0) return;
|
|
2145
2490
|
|
|
2146
2491
|
if (n->style.has_bg) {
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
ViewGeometry::transformCorners(*n, false, xs, ys);
|
|
2160
|
-
appendFillQuadWithAlpha(xs, ys, n->style.bg_color, n->style.bg_alpha, parentAlpha,
|
|
2161
|
-
bx0, by0, bx1 - bx0 + 1, by1 - by0 + 1,
|
|
2162
|
-
x, y, w, h, true);
|
|
2163
|
-
}
|
|
2164
|
-
recordBackgroundGrid(*n, parentAlpha);
|
|
2165
|
-
} else {
|
|
2166
|
-
if (hasAnyRadius(*n)) {
|
|
2167
|
-
if (hasAnyPercentRadius(*n) && !appendResolvedCircularRoundedRectWithAlpha(*n, parentAlpha))
|
|
2492
|
+
// The color is the bottom layer; image longhands never replace it.
|
|
2493
|
+
if (n->style.bg_alpha > 0 && !canvasRoot &&
|
|
2494
|
+
(canvasSource < 0 || &treeState().nodes[canvasSource] != n)) {
|
|
2495
|
+
const int clip = StyleValues::backgroundClip(n->style, rstyle(n->style).bg_image_layer_count - 1);
|
|
2496
|
+
TextBackgroundClipScope textClip(*n, clip);
|
|
2497
|
+
if (clip == 1 || clip == 2) {
|
|
2498
|
+
recordTransformedRoundedRectFill(*n, parentAlpha, clip);
|
|
2499
|
+
} else if (ViewGeometry::hasTransformChain(*n, false)) {
|
|
2500
|
+
int16_t xs[4], ys[4];
|
|
2501
|
+
int bx0, by0, bx1, by1;
|
|
2502
|
+
ViewRenderer::transformedBounds(*n, false, &bx0, &by0, &bx1, &by1);
|
|
2503
|
+
if (hasAnyRadius(*n)) {
|
|
2168
2504
|
recordTransformedRoundedRectFill(*n, parentAlpha);
|
|
2169
|
-
else
|
|
2170
|
-
|
|
2505
|
+
} else {
|
|
2506
|
+
ViewGeometry::transformCorners(*n, false, xs, ys);
|
|
2507
|
+
appendFillQuadWithAlpha(xs, ys, n->style.bg_color, n->style.bg_alpha, parentAlpha,
|
|
2508
|
+
bx0, by0, bx1 - bx0 + 1, by1 - by0 + 1,
|
|
2509
|
+
x, y, w, h, true);
|
|
2510
|
+
}
|
|
2171
2511
|
} else {
|
|
2172
|
-
|
|
2512
|
+
if (hasAnyRadius(*n)) {
|
|
2513
|
+
if (!appendResolvedCircularRoundedRectWithAlpha(*n, parentAlpha))
|
|
2514
|
+
recordTransformedRoundedRectFill(*n, parentAlpha);
|
|
2515
|
+
} else {
|
|
2516
|
+
appendFillRectWithAlpha(x, y, w, h, n->style.bg_color, n->style.bg_alpha, parentAlpha, x, y, w, h);
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
if (!canvasRoot && (canvasSource < 0 || &treeState().nodes[canvasSource] != n)) {
|
|
2521
|
+
if (!recordPlacedBackgrounds(*n, *n, false)) {
|
|
2522
|
+
if (n->style.bg_fill == 1) {
|
|
2523
|
+
TextBackgroundClipScope textClip(*n, StyleValues::backgroundClip(n->style, rstyle(n->style).bg_gradient_layer));
|
|
2524
|
+
recordLinearGradientBackground(*n, parentAlpha);
|
|
2525
|
+
}
|
|
2526
|
+
{
|
|
2527
|
+
TextBackgroundClipScope textClip(*n, StyleValues::backgroundClip(n->style, rstyle(n->style).bg_radial_gradient_layer));
|
|
2528
|
+
recordRadialGradientBackground(*n);
|
|
2529
|
+
}
|
|
2530
|
+
{
|
|
2531
|
+
TextBackgroundClipScope textClip(*n, StyleValues::backgroundClip(n->style, rstyle(n->style).bg_overlay_gradient_layer));
|
|
2532
|
+
recordOverlayLinearGradientBackground(*n);
|
|
2533
|
+
}
|
|
2173
2534
|
}
|
|
2174
2535
|
recordBackgroundGrid(*n, parentAlpha);
|
|
2175
2536
|
}
|
|
@@ -2177,7 +2538,7 @@ void GEA_VIEW_HOT_SRAM_SECTION("view_renderer_record_box") ViewRenderer::recordB
|
|
|
2177
2538
|
|
|
2178
2539
|
recordInsetBoxShadow(*n, parentAlpha);
|
|
2179
2540
|
|
|
2180
|
-
if (n->style.border_width > 0 && !borderIsSameOpaqueSolidBackground(*n, parentAlpha)) {
|
|
2541
|
+
if (n->style.border_width > 0 && !hasBorderRelief(n->style) && !hasSideBorder(n->style) && !borderColorsDiffer(n->style) && !borderIsSameOpaqueSolidBackground(*n, parentAlpha)) {
|
|
2181
2542
|
if (ViewGeometry::hasTransformChain(*n, false)) {
|
|
2182
2543
|
if (isFullyRoundedShape(*n)) recordTransformedEllipseStroke(*n, parentAlpha);
|
|
2183
2544
|
} else {
|