Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 3a0ad85

Browse files
committed
fix shadow clip bug
1 parent deda3cd commit 3a0ad85

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shadow_utils.cs

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,44 @@ public partial class PictureFlusher {
77
void _drawRRectShadow(uiPath path, uiPaint paint) {
88
D.assert(path.isNaiveRRect, () => "Cannot draw fast Shadow for non-NaiveRRect shapes");
99
D.assert(paint.style == PaintingStyle.fill, () => "Cannot draw fast Shadow for stroke lines");
10-
var bound = path.getBounds();
11-
if (!this._applyClip(bound)) {
10+
var layer = this._currentLayer;
11+
var state = layer.currentState;
12+
13+
var cache = path.flatten(state.scale * this._devicePixelRatio);
14+
bool convex;
15+
var fillMesh = cache.getFillMesh(out convex);
16+
var meshBounds = fillMesh.transform(state.matrix);
17+
var clipBounds = layer.layerBounds;
18+
19+
uiRect? stackBounds;
20+
bool iior;
21+
layer.clipStack.getBounds(out stackBounds, out iior);
22+
23+
if (stackBounds != null) {
24+
clipBounds = uiRectHelper.intersect(clipBounds, stackBounds.Value);
25+
}
26+
27+
if (clipBounds.isEmpty) {
28+
ObjectPool<uiMeshMesh>.release(meshBounds);
1229
return;
1330
}
1431

15-
var layer = this._currentLayer;
16-
var state = layer.currentState;
17-
float sigma = state.scale * paint.maskFilter.Value.sigma;
32+
var maskBounds = meshBounds.bounds;
33+
maskBounds = uiRectHelper.intersect(maskBounds, clipBounds);
34+
if (maskBounds.isEmpty) {
35+
ObjectPool<uiMeshMesh>.release(meshBounds);
36+
return;
37+
}
38+
39+
var blurMesh = ImageMeshGenerator.imageMesh(null, uiRectHelper.one, maskBounds);
40+
if (!this._applyClip(blurMesh.bounds)) {
41+
ObjectPool<uiMeshMesh>.release(meshBounds);
42+
ObjectPool<uiMeshMesh>.release(blurMesh);
43+
return;
44+
}
45+
46+
var bound = path.getBounds();
47+
var sigma = state.scale * paint.maskFilter.Value.sigma;
1848

1949
var vertices = ObjectPool<uiList<Vector3>>.alloc();
2050
vertices.SetCapacity(4);
@@ -32,6 +62,8 @@ void _drawRRectShadow(uiPath path, uiPaint paint) {
3262
_triangles.Add(1);
3363
_triangles.Add(3);
3464

65+
ObjectPool<uiMeshMesh>.release(meshBounds);
66+
ObjectPool<uiMeshMesh>.release(blurMesh);
3567
var mesh = uiMeshMesh.create(state.matrix, vertices, _triangles);
3668
layer.draws.Add(CanvasShader.fastShadow(layer, mesh, sigma, path.isRect, path.isCircle, path.rRectCorner, new Vector4(bound.left, bound.top, bound.right, bound.bottom), paint.color));
3769
}

0 commit comments

Comments
 (0)