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

Commit 9a3788f

Browse files
author
Yuncong Zhang
authored
Merge pull request #299 from UnityTech/backdropbugfix
backdrop mask bug fix
2 parents 6b09363 + 905cf69 commit 9a3788f

File tree

2 files changed

+42
-40
lines changed

2 files changed

+42
-40
lines changed

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

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

97-
readonly uiOffset[] _saveLayer_Points = new uiOffset[4];
97+
static uiOffset[] _cachedPoints = new uiOffset[4];
9898

9999
void _saveLayer(uiRect bounds, uiPaint paint) {
100100
D.assert(bounds.width > 0);
@@ -127,30 +127,31 @@ void _saveLayer(uiRect bounds, uiPaint paint) {
127127
this._currentLayer = layer;
128128

129129
if (paint.backdrop != null) {
130-
if (paint.backdrop is _BlurImageFilter) {
131-
var filter = (_BlurImageFilter) paint.backdrop;
130+
131+
if (paint.backdrop is _uiBlurImageFilter) {
132+
var filter = (_uiBlurImageFilter) paint.backdrop;
132133
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;
134+
_cachedPoints[0] = bounds.topLeft;
135+
_cachedPoints[1] = bounds.bottomLeft;
136+
_cachedPoints[2] = bounds.bottomRight;
137+
_cachedPoints[3] = bounds.topRight;
137138

138-
state.matrix.Value.mapPoints(this._saveLayer_Points);
139+
state.matrix.Value.mapPoints(ref _cachedPoints);
139140

140141
var parentBounds = parentLayer.layerBounds;
141142
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
143+
_cachedPoints[i] = new uiOffset(
144+
(_cachedPoints[i].dx - parentBounds.left) / parentBounds.width,
145+
(_cachedPoints[i].dy - parentBounds.top) / parentBounds.height
145146
);
146147
}
147148

148149
var mesh = ImageMeshGenerator.imageMesh(
149150
null,
150-
this._saveLayer_Points[0],
151-
this._saveLayer_Points[1],
152-
this._saveLayer_Points[2],
153-
this._saveLayer_Points[3],
151+
_cachedPoints[0],
152+
_cachedPoints[1],
153+
_cachedPoints[2],
154+
_cachedPoints[3],
154155
bounds);
155156
var renderDraw = CanvasShader.texRT(layer, layer.layerPaint.Value, mesh, parentLayer);
156157
layer.draws.Add(renderDraw);
@@ -160,35 +161,36 @@ void _saveLayer(uiRect bounds, uiPaint paint) {
160161
layer.draws.Add(CanvasShader.texRT(layer, paint, blurMesh, blurLayer));
161162
}
162163
}
163-
else if (paint.backdrop is _MatrixImageFilter) {
164-
var filter = (_MatrixImageFilter) paint.backdrop;
164+
else if (paint.backdrop is _uiMatrixImageFilter) {
165+
var filter = (_uiMatrixImageFilter) paint.backdrop;
165166
if (!filter.transform.isIdentity()) {
166167
layer.filterMode = filter.filterMode;
167168

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);
169+
_cachedPoints[0] = bounds.topLeft;
170+
_cachedPoints[1] = bounds.bottomLeft;
171+
_cachedPoints[2] = bounds.bottomRight;
172+
_cachedPoints[3] = bounds.topRight;
173+
174+
state.matrix.Value.mapPoints(ref _cachedPoints);
173175

174176
var parentBounds = parentLayer.layerBounds;
175177
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
178+
_cachedPoints[i] = new uiOffset(
179+
(_cachedPoints[i].dx - parentBounds.left) / parentBounds.width,
180+
(_cachedPoints[i].dy - parentBounds.top) / parentBounds.height
179181
);
180182
}
181183

182184
var matrix = uiMatrix3.makeTrans(-bounds.left, -bounds.top);
183-
matrix.postConcat(uiMatrix3.fromMatrix3(filter.transform));
185+
matrix.postConcat(filter.transform);
184186
matrix.postTranslate(bounds.left, bounds.top);
185187

186188
var mesh = ImageMeshGenerator.imageMesh(
187189
matrix,
188-
this._saveLayer_Points[0],
189-
this._saveLayer_Points[1],
190-
this._saveLayer_Points[2],
191-
this._saveLayer_Points[3],
190+
_cachedPoints[0],
191+
_cachedPoints[1],
192+
_cachedPoints[2],
193+
_cachedPoints[3],
192194
bounds);
193195
var renderDraw = CanvasShader.texRT(layer, layer.layerPaint.Value, mesh, parentLayer);
194196
layer.draws.Add(renderDraw);

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

Lines changed: 10 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 void mapPoints(ref uiOffset[] dst, ref uiOffset[] src) {
88
D.assert(dst != null && src != null && dst.Length == src.Length);
9-
this._getMapPtsProc()(this, dst, src, src.Length);
9+
this._getMapPtsProc()(this, ref dst, ref src, src.Length);
1010
}
1111

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

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

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

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

4242
if (dst != src && count > 0) {
4343
Array.Copy(src, dst, count);
4444
}
4545
}
4646

47-
static void Trans_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
47+
static void Trans_pts(uiMatrix3 m, ref uiOffset[] dst, ref uiOffset[] src, int count) {
4848
D.assert(m._getType() <= TypeMask.kTranslate_Mask);
4949
if (count > 0) {
5050
var tx = m.getTranslateX();
@@ -55,7 +55,7 @@ static void Trans_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
5555
}
5656
}
5757

58-
static void Scale_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
58+
static void Scale_pts(uiMatrix3 m, ref uiOffset[] dst, ref uiOffset[] src, int count) {
5959
D.assert(m._getType() <= (TypeMask.kScale_Mask | TypeMask.kTranslate_Mask));
6060
if (count > 0) {
6161
var tx = m.getTranslateX();
@@ -69,7 +69,7 @@ static void Scale_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
6969
}
7070
}
7171

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

7575
if (count > 0) {
@@ -91,7 +91,7 @@ static void Persp_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
9191
}
9292
}
9393

94-
static void Affine_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
94+
static void Affine_pts(uiMatrix3 m, ref uiOffset[] dst, ref uiOffset[] src, int count) {
9595
D.assert(m._getType() != TypeMask.kPerspective_Mask);
9696
if (count > 0) {
9797
var tx = m.getTranslateX();

0 commit comments

Comments
 (0)