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

Commit 905cf69

Browse files
committed
fix gc problem
1 parent 9bb232b commit 905cf69

File tree

2 files changed

+36
-45
lines changed

2 files changed

+36
-45
lines changed

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

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

97+
static uiOffset[] _cachedPoints = new uiOffset[4];
98+
9799
void _saveLayer(uiRect bounds, uiPaint paint) {
98100
D.assert(bounds.width > 0);
99101
D.assert(bounds.height > 0);
@@ -125,32 +127,31 @@ void _saveLayer(uiRect bounds, uiPaint paint) {
125127
this._currentLayer = layer;
126128

127129
if (paint.backdrop != null) {
128-
var points = new uiOffset[4];
129130

130131
if (paint.backdrop is _uiBlurImageFilter) {
131132
var filter = (_uiBlurImageFilter) paint.backdrop;
132133
if (!(filter.sigmaX == 0 && filter.sigmaY == 0)) {
133-
points[0] = bounds.topLeft;
134-
points[1] = bounds.bottomLeft;
135-
points[2] = bounds.bottomRight;
136-
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-
points = state.matrix.Value.mapPoints(points);
139+
state.matrix.Value.mapPoints(ref _cachedPoints);
139140

140141
var parentBounds = parentLayer.layerBounds;
141142
for (int i = 0; i < 4; i++) {
142-
points[i] = new uiOffset(
143-
(points[i].dx - parentBounds.left) / parentBounds.width,
144-
(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-
points[0],
151-
points[1],
152-
points[2],
153-
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);
@@ -165,18 +166,18 @@ void _saveLayer(uiRect bounds, uiPaint paint) {
165166
if (!filter.transform.isIdentity()) {
166167
layer.filterMode = filter.filterMode;
167168

168-
points[0] = bounds.topLeft;
169-
points[1] = bounds.bottomLeft;
170-
points[2] = bounds.bottomRight;
171-
points[3] = bounds.topRight;
169+
_cachedPoints[0] = bounds.topLeft;
170+
_cachedPoints[1] = bounds.bottomLeft;
171+
_cachedPoints[2] = bounds.bottomRight;
172+
_cachedPoints[3] = bounds.topRight;
172173

173-
points = state.matrix.Value.mapPoints(points);
174+
state.matrix.Value.mapPoints(ref _cachedPoints);
174175

175176
var parentBounds = parentLayer.layerBounds;
176177
for (int i = 0; i < 4; i++) {
177-
points[i] = new uiOffset(
178-
(points[i].dx - parentBounds.left) / parentBounds.width,
179-
(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
180181
);
181182
}
182183

@@ -186,10 +187,10 @@ void _saveLayer(uiRect bounds, uiPaint paint) {
186187

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

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

Lines changed: 10 additions & 20 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 uiOffset[] 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-
return this._getMapPtsProc()(this, dst, src, src.Length);
9+
this._getMapPtsProc()(this, ref dst, ref src, src.Length);
1010
}
1111

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

16-
delegate uiOffset[] 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,17 +36,15 @@ MapPtsProc _getMapPtsProc() {
3636
return GetMapPtsProc(this._getType());
3737
}
3838

39-
static uiOffset[] 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
}
45-
46-
return dst;
4745
}
4846

49-
static uiOffset[] 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) {
5048
D.assert(m._getType() <= TypeMask.kTranslate_Mask);
5149
if (count > 0) {
5250
var tx = m.getTranslateX();
@@ -55,11 +53,9 @@ static uiOffset[] Trans_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int cou
5553
dst[i] = new uiOffset(src[i].dx + tx, src[i].dy + ty);
5654
}
5755
}
58-
59-
return dst;
6056
}
6157

62-
static uiOffset[] 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) {
6359
D.assert(m._getType() <= (TypeMask.kScale_Mask | TypeMask.kTranslate_Mask));
6460
if (count > 0) {
6561
var tx = m.getTranslateX();
@@ -71,11 +67,9 @@ static uiOffset[] Scale_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int cou
7167
dst[i] = new uiOffset(src[i].dx * sx + tx, src[i].dy * sy + ty);
7268
}
7369
}
74-
75-
return dst;
7670
}
7771

78-
static uiOffset[] 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) {
7973
D.assert(m._hasPerspective());
8074

8175
if (count > 0) {
@@ -95,11 +89,9 @@ static uiOffset[] Persp_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int cou
9589
dst[i] = new uiOffset(x * z, y * z);
9690
}
9791
}
98-
99-
return dst;
10092
}
10193

102-
static uiOffset[] 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) {
10395
D.assert(m._getType() != TypeMask.kPerspective_Mask);
10496
if (count > 0) {
10597
var tx = m.getTranslateX();
@@ -115,8 +107,6 @@ static uiOffset[] Affine_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int co
115107
src[i].dx * ky + src[i].dy * sy + ty);
116108
}
117109
}
118-
119-
return dst;
120110
}
121111
}
122112

0 commit comments

Comments
 (0)