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

Commit f744058

Browse files
committed
some fixes.
1 parent c3886a0 commit f744058

File tree

4 files changed

+113
-88
lines changed

4 files changed

+113
-88
lines changed

Runtime/Unity.UIWidgets.asmdef

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{
22
"name": "Unity.UIWidgets",
33
"references": [],
4+
"optionalUnityReferences": [],
45
"includePlatforms": [],
5-
"excludePlatforms": []
6-
}
6+
"excludePlatforms": [],
7+
"allowUnsafeCode": true,
8+
"overrideReferences": false,
9+
"precompiledReferences": [],
10+
"autoReferenced": true,
11+
"defineConstraints": []
12+
}

Runtime/ui/painting/path.cs

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class Path {
1818

1919
PathCache _cache;
2020

21-
public Path(int capacity = 0) {
21+
public Path(int capacity = 128) {
2222
this._commands = new List<float>(capacity);
2323
this._reset();
2424
}
@@ -1187,30 +1187,6 @@ public enum PathWinding {
11871187
clockwise = 2, // which just means the reversed order.
11881188
}
11891189

1190-
[Flags]
1191-
enum PointFlags {
1192-
corner = 0x01,
1193-
left = 0x02,
1194-
bevel = 0x04,
1195-
innerBevel = 0x08,
1196-
}
1197-
1198-
class PathPoint {
1199-
public float x, y;
1200-
public float dx, dy;
1201-
public float len;
1202-
public float dmx, dmy;
1203-
public PointFlags flags;
1204-
}
1205-
1206-
enum PathCommand {
1207-
moveTo,
1208-
lineTo,
1209-
bezierTo,
1210-
close,
1211-
winding,
1212-
}
1213-
12141190
class _Conic {
12151191
public float x0;
12161192
public float y0;
@@ -1341,6 +1317,30 @@ void _chop(out _Conic c1, out _Conic c2) {
13411317
}
13421318
}
13431319

1320+
enum PathCommand {
1321+
moveTo,
1322+
lineTo,
1323+
bezierTo,
1324+
close,
1325+
winding,
1326+
}
1327+
1328+
[Flags]
1329+
enum PointFlags {
1330+
corner = 0x01,
1331+
left = 0x02,
1332+
bevel = 0x04,
1333+
innerBevel = 0x08,
1334+
}
1335+
1336+
class PathPoint {
1337+
public float x, y;
1338+
public float dx, dy;
1339+
public float len;
1340+
public float dmx, dmy;
1341+
public PointFlags flags;
1342+
}
1343+
13441344
class PathPath {
13451345
public int first;
13461346
public int count;
@@ -1430,11 +1430,27 @@ public void tessellateBezier(
14301430
y1 = pt.y;
14311431
}
14321432

1433+
if (x1 == x2 && x1 == x3 && x1 == x4 &&
1434+
y1 == y2 && y1 == y3 && y1 == y4) {
1435+
return;
1436+
}
1437+
14331438
var points = TessellationGenerator.tessellateBezier(x1, y1, x2, y2, x3, y3, x4, y4, this._tessTol);
1434-
D.assert(points.Count > 0);
1435-
points[points.Count - 1].flags = flags;
1436-
foreach (var point in points) {
1437-
this._addPoint(point);
1439+
D.assert(points.Count > 0);
1440+
for (int i = 0; i < points.Count; i++) {
1441+
var point = points[i];
1442+
if (i == points.Count - 1) {
1443+
this._addPoint(new PathPoint {
1444+
x = point.x + x1,
1445+
y = point.y + y1,
1446+
flags = flags,
1447+
});
1448+
} else {
1449+
this._addPoint(new PathPoint {
1450+
x = point.x + x1,
1451+
y = point.y + y1,
1452+
});
1453+
}
14381454
}
14391455
}
14401456

Runtime/ui/painting/tessellation_generator.cs

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public bool Equals(TessellationKey other) {
3333
return true;
3434
}
3535

36-
return this.x2.Equals(other.x2) && this.y2.Equals(other.y2) && this.x3.Equals(other.x3) &&
37-
this.y3.Equals(other.y3) && this.x4.Equals(other.x4) && this.y4.Equals(other.y4) &&
38-
this.tessTol.Equals(other.tessTol);
36+
return this.x2 == other.x2 && this.y2 == other.y2 && this.x3 == other.x3 &&
37+
this.y3 == other.y3 && this.x4 == other.x4 && this.y4 == other.y4 &&
38+
this.tessTol == other.tessTol;
3939
}
4040

4141
public override bool Equals(object obj) {
@@ -54,15 +54,23 @@ public override bool Equals(object obj) {
5454
return this.Equals((TessellationKey) obj);
5555
}
5656

57-
public override int GetHashCode() {
57+
public override unsafe int GetHashCode() {
5858
unchecked {
59-
var hashCode = this.x2.GetHashCode();
60-
hashCode = (hashCode * 397) ^ this.y2.GetHashCode();
61-
hashCode = (hashCode * 397) ^ this.x3.GetHashCode();
62-
hashCode = (hashCode * 397) ^ this.y3.GetHashCode();
63-
hashCode = (hashCode * 397) ^ this.x4.GetHashCode();
64-
hashCode = (hashCode * 397) ^ this.y4.GetHashCode();
65-
hashCode = (hashCode * 397) ^ this.tessTol.GetHashCode();
59+
var hashCode = 0;
60+
float x = this.x2;
61+
hashCode ^= *(int*) &x;
62+
x = this.y2;
63+
hashCode = (hashCode * 13) ^ *(int*) &x;
64+
x = this.x3;
65+
hashCode = (hashCode * 13) ^ *(int*) &x;
66+
x = this.y3;
67+
hashCode = (hashCode * 13) ^ *(int*) &x;
68+
x = this.x4;
69+
hashCode = (hashCode * 13) ^ *(int*) &x;
70+
x = this.y4;
71+
hashCode = (hashCode * 13) ^ *(int*) &x;
72+
x = this.tessTol;
73+
hashCode = (hashCode * 13) ^ *(int*) &x;
6674
return hashCode;
6775
}
6876
}
@@ -131,34 +139,21 @@ public static void tickNextFrame() {
131139
}
132140
}
133141

134-
public static List<PathPoint> tessellateBezier(float x1, float y1, float x2, float y2,
142+
public static List<Vector2> tessellateBezier(float x1, float y1, float x2, float y2,
135143
float x3, float y3, float x4, float y4, float tessTol) {
136144
var key = new TessellationKey(x1, y1, x2, y2, x3, y3, x4, y4, tessTol);
137145

138146
_tessellations.TryGetValue(key, out var tessellationInfo);
139147
if (tessellationInfo != null) {
140148
tessellationInfo.touch();
141149

142-
return _toPathPoints(tessellationInfo.points, x1, y1);
150+
return tessellationInfo.points;
143151
}
144-
145-
152+
146153
var points = _tessellateBezier(x1, y1, x2, y2, x3, y3, x4, y4, tessTol);
147154
_tessellations[key] = new TessellationInfo(key, points);
148155

149-
return _toPathPoints(points, x1, y1);
150-
}
151-
152-
static List<PathPoint> _toPathPoints(List<Vector2> points, float x1, float y1) {
153-
var pathPoints = new List<PathPoint>(points.Count);
154-
foreach (var point in points) {
155-
pathPoints.Add(new PathPoint {
156-
x = point.x + x1,
157-
y = point.y + y1,
158-
});
159-
}
160-
161-
return pathPoints;
156+
return points;
162157
}
163158

164159
struct _StackData {

Runtime/ui/painting/txt/font_manager.cs

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -152,41 +152,49 @@ void onFontTextureRebuilt(Font font) {
152152

153153
}
154154

155-
class GlyphInfo {
155+
struct GlyphInfo {
156+
public static readonly GlyphInfo empty = new GlyphInfo();
156157

157-
public static GlyphInfo empty = new GlyphInfo(Rect.zero,0, 0, new Vector2(0, 0),
158-
new Vector2(0, 0), new Vector2(0, 0), new Vector2(0, 0));
159-
160-
public readonly Rect rect;
161-
public readonly float advance;
162-
public readonly float glyphHeight;
163-
public readonly Vector2 uvTopLeft;
164-
public readonly Vector2 uvTopRight;
165-
public readonly Vector2 uvBottomLeft;
166-
public readonly Vector2 uvBottomRight;
158+
Rect _rect;
159+
readonly CharacterInfo _info;
167160

168161
public GlyphInfo(CharacterInfo info) {
169-
this.rect = Rect.fromLTRB(info.minX, -info.maxY, info.maxX, -info.minY);
170-
this.advance = info.advance;
171-
this.glyphHeight = info.glyphHeight;
172-
this.uvTopLeft = info.uvTopLeft;
173-
this.uvTopRight = info.uvTopRight;
174-
this.uvBottomLeft = info.uvBottomLeft;
175-
this.uvBottomRight = info.uvBottomRight;
176-
162+
this._rect = null;
163+
this._info = info;
177164
}
178165

179-
public GlyphInfo(Rect rect, float advance, float glyphHeight,
180-
Vector2 uvTopLeft, Vector2 uvTopRight, Vector2 uvBottomLeft, Vector2 uvBottomRight) {
181-
this.rect = rect;
182-
this.advance = advance;
183-
this.glyphHeight = glyphHeight;
184-
this.uvTopLeft = uvTopLeft;
185-
this.uvTopRight = uvTopRight;
186-
this.uvBottomLeft = uvBottomLeft;
187-
this.uvBottomRight = uvBottomRight;
166+
public Rect rect {
167+
get {
168+
if (this._rect == null) {
169+
this._rect = Rect.fromLTRB(this._info.minX, -this._info.maxY, this._info.maxX, -this._info.minY);
170+
}
171+
return this._rect;
172+
}
173+
}
174+
175+
public float advance {
176+
get { return this._info.advance; }
177+
}
178+
179+
public float glyphHeight {
180+
get { return this._info.advance; }
181+
}
182+
183+
public Vector2 uvTopLeft {
184+
get { return this._info.uvTopLeft; }
185+
}
186+
187+
public Vector2 uvTopRight {
188+
get { return this._info.uvTopRight; }
189+
}
190+
191+
public Vector2 uvBottomLeft {
192+
get { return this._info.uvBottomLeft; }
193+
}
194+
195+
public Vector2 uvBottomRight {
196+
get { return this._info.uvBottomRight; }
188197
}
189-
190198
}
191199

192200
public static class FontExtension

0 commit comments

Comments
 (0)