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

Commit 9bb232b

Browse files
committed
backdrop mask bug fix
1 parent bbb259f commit 9bb232b

File tree

2 files changed

+52
-41
lines changed

2 files changed

+52
-41
lines changed

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

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ void _save() {
9494
layer.clipStack.save();
9595
}
9696

97-
readonly uiOffset[] _saveLayer_Points = new uiOffset[4];
98-
9997
void _saveLayer(uiRect bounds, uiPaint paint) {
10098
D.assert(bounds.width > 0);
10199
D.assert(bounds.height > 0);
@@ -127,30 +125,32 @@ void _saveLayer(uiRect bounds, uiPaint paint) {
127125
this._currentLayer = layer;
128126

129127
if (paint.backdrop != null) {
130-
if (paint.backdrop is _BlurImageFilter) {
131-
var filter = (_BlurImageFilter) paint.backdrop;
128+
var points = new uiOffset[4];
129+
130+
if (paint.backdrop is _uiBlurImageFilter) {
131+
var filter = (_uiBlurImageFilter) paint.backdrop;
132132
if (!(filter.sigmaX == 0 && filter.sigmaY == 0)) {
133-
this._saveLayer_Points[0] = bounds.topLeft;
134-
this._saveLayer_Points[1] = bounds.bottomLeft;
135-
this._saveLayer_Points[2] = bounds.bottomRight;
136-
this._saveLayer_Points[3] = bounds.topRight;
133+
points[0] = bounds.topLeft;
134+
points[1] = bounds.bottomLeft;
135+
points[2] = bounds.bottomRight;
136+
points[3] = bounds.topRight;
137137

138-
state.matrix.Value.mapPoints(this._saveLayer_Points);
138+
points = state.matrix.Value.mapPoints(points);
139139

140140
var parentBounds = parentLayer.layerBounds;
141141
for (int i = 0; i < 4; i++) {
142-
this._saveLayer_Points[i] = new uiOffset(
143-
(this._saveLayer_Points[i].dx - parentBounds.left) / parentBounds.width,
144-
(this._saveLayer_Points[i].dy - parentBounds.top) / parentBounds.height
142+
points[i] = new uiOffset(
143+
(points[i].dx - parentBounds.left) / parentBounds.width,
144+
(points[i].dy - parentBounds.top) / parentBounds.height
145145
);
146146
}
147147

148148
var mesh = ImageMeshGenerator.imageMesh(
149149
null,
150-
this._saveLayer_Points[0],
151-
this._saveLayer_Points[1],
152-
this._saveLayer_Points[2],
153-
this._saveLayer_Points[3],
150+
points[0],
151+
points[1],
152+
points[2],
153+
points[3],
154154
bounds);
155155
var renderDraw = CanvasShader.texRT(layer, layer.layerPaint.Value, mesh, parentLayer);
156156
layer.draws.Add(renderDraw);
@@ -160,35 +160,36 @@ void _saveLayer(uiRect bounds, uiPaint paint) {
160160
layer.draws.Add(CanvasShader.texRT(layer, paint, blurMesh, blurLayer));
161161
}
162162
}
163-
else if (paint.backdrop is _MatrixImageFilter) {
164-
var filter = (_MatrixImageFilter) paint.backdrop;
163+
else if (paint.backdrop is _uiMatrixImageFilter) {
164+
var filter = (_uiMatrixImageFilter) paint.backdrop;
165165
if (!filter.transform.isIdentity()) {
166166
layer.filterMode = filter.filterMode;
167167

168-
this._saveLayer_Points[0] = bounds.topLeft;
169-
this._saveLayer_Points[1] = bounds.bottomLeft;
170-
this._saveLayer_Points[2] = bounds.bottomRight;
171-
this._saveLayer_Points[3] = bounds.topRight;
172-
state.matrix.Value.mapPoints(this._saveLayer_Points);
168+
points[0] = bounds.topLeft;
169+
points[1] = bounds.bottomLeft;
170+
points[2] = bounds.bottomRight;
171+
points[3] = bounds.topRight;
172+
173+
points = state.matrix.Value.mapPoints(points);
173174

174175
var parentBounds = parentLayer.layerBounds;
175176
for (int i = 0; i < 4; i++) {
176-
this._saveLayer_Points[i] = new uiOffset(
177-
(this._saveLayer_Points[i].dx - parentBounds.left) / parentBounds.width,
178-
(this._saveLayer_Points[i].dy - parentBounds.top) / parentBounds.height
177+
points[i] = new uiOffset(
178+
(points[i].dx - parentBounds.left) / parentBounds.width,
179+
(points[i].dy - parentBounds.top) / parentBounds.height
179180
);
180181
}
181182

182183
var matrix = uiMatrix3.makeTrans(-bounds.left, -bounds.top);
183-
matrix.postConcat(uiMatrix3.fromMatrix3(filter.transform));
184+
matrix.postConcat(filter.transform);
184185
matrix.postTranslate(bounds.left, bounds.top);
185186

186187
var mesh = ImageMeshGenerator.imageMesh(
187188
matrix,
188-
this._saveLayer_Points[0],
189-
this._saveLayer_Points[1],
190-
this._saveLayer_Points[2],
191-
this._saveLayer_Points[3],
189+
points[0],
190+
points[1],
191+
points[2],
192+
points[3],
192193
bounds);
193194
var renderDraw = CanvasShader.texRT(layer, layer.layerPaint.Value, mesh, parentLayer);
194195
layer.draws.Add(renderDraw);

Runtime/ui/renderer/common/geometry/matrix/ui_matrix_utils.cs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
namespace Unity.UIWidgets.ui {
66
public partial struct uiMatrix3 {
7-
public void mapPoints(uiOffset[] dst, uiOffset[] src) {
7+
public uiOffset[] mapPoints(uiOffset[] dst, uiOffset[] src) {
88
D.assert(dst != null && src != null && dst.Length == src.Length);
9-
this._getMapPtsProc()(this, dst, src, src.Length);
9+
return this._getMapPtsProc()(this, dst, src, src.Length);
1010
}
1111

12-
public void mapPoints(uiOffset[] pts) {
13-
this.mapPoints(pts, pts);
12+
public uiOffset[] mapPoints(uiOffset[] pts) {
13+
return this.mapPoints(pts, pts);
1414
}
1515

16-
delegate void MapPtsProc(uiMatrix3 mat, uiOffset[] dst, uiOffset[] src, int count);
16+
delegate uiOffset[] MapPtsProc(uiMatrix3 mat, uiOffset[] dst, uiOffset[] src, int count);
1717

1818
static readonly MapPtsProc[] gMapPtsProcs = {
1919
Identity_pts, Trans_pts,
@@ -36,15 +36,17 @@ MapPtsProc _getMapPtsProc() {
3636
return GetMapPtsProc(this._getType());
3737
}
3838

39-
static void Identity_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
39+
static uiOffset[] Identity_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
4040
D.assert(m._getType() == 0);
4141

4242
if (dst != src && count > 0) {
4343
Array.Copy(src, dst, count);
4444
}
45+
46+
return dst;
4547
}
4648

47-
static void Trans_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
49+
static uiOffset[] Trans_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
4850
D.assert(m._getType() <= TypeMask.kTranslate_Mask);
4951
if (count > 0) {
5052
var tx = m.getTranslateX();
@@ -53,9 +55,11 @@ static void Trans_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
5355
dst[i] = new uiOffset(src[i].dx + tx, src[i].dy + ty);
5456
}
5557
}
58+
59+
return dst;
5660
}
5761

58-
static void Scale_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
62+
static uiOffset[] Scale_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
5963
D.assert(m._getType() <= (TypeMask.kScale_Mask | TypeMask.kTranslate_Mask));
6064
if (count > 0) {
6165
var tx = m.getTranslateX();
@@ -67,9 +71,11 @@ static void Scale_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
6771
dst[i] = new uiOffset(src[i].dx * sx + tx, src[i].dy * sy + ty);
6872
}
6973
}
74+
75+
return dst;
7076
}
7177

72-
static void Persp_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
78+
static uiOffset[] Persp_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
7379
D.assert(m._hasPerspective());
7480

7581
if (count > 0) {
@@ -89,9 +95,11 @@ static void Persp_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
8995
dst[i] = new uiOffset(x * z, y * z);
9096
}
9197
}
98+
99+
return dst;
92100
}
93101

94-
static void Affine_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
102+
static uiOffset[] Affine_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
95103
D.assert(m._getType() != TypeMask.kPerspective_Mask);
96104
if (count > 0) {
97105
var tx = m.getTranslateX();
@@ -107,6 +115,8 @@ static void Affine_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
107115
src[i].dx * ky + src[i].dy * sy + ty);
108116
}
109117
}
118+
119+
return dst;
110120
}
111121
}
112122

0 commit comments

Comments
 (0)