浏览代码

attach fillmesh&strokenmesh to pathcache

/main
xingwei.zhu 5 年前
当前提交
beac5c82
共有 5 个文件被更改,包括 43 次插入18 次删除
  1. 1
      Runtime/ui/utils/renderer/allocUtils/generic_list.cs
  2. 1
      Runtime/ui/utils/renderer/cmdbufferCanvas/rendering/canvas_clip.cs
  3. 2
      Runtime/ui/utils/renderer/cmdbufferCanvas/rendering/canvas_impl.cs
  4. 3
      Runtime/ui/utils/renderer/common/picture.cs
  5. 54
      Runtime/ui/utils/renderer/geometry/path/path_cache.cs

1
Runtime/ui/utils/renderer/allocUtils/generic_list.cs


using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace Unity.UIWidgets.ui {

1
Runtime/ui/utils/renderer/cmdbufferCanvas/rendering/canvas_clip.cs


var fillMesh = pathCache.getFillMesh(out newElement.convex);
newElement.mesh = fillMesh.transform(matrix);
pathCache.dispose();
fillMesh.dispose();
var vertices = newElement.mesh.vertices;
if (newElement.convex && vertices.Count == 4 && matrix.rectStaysRect() &&

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


bool convex;
var fillMesh = cache.getFillMesh(out convex);
var mesh = fillMesh.transform(state.matrix);
fillMesh.dispose();
cache.dispose();
if (paint.maskFilter != null && paint.maskFilter.sigma != 0) {

paint.strokeMiterLimit);
var mesh = strokenMesh.transform(state.matrix);
strokenMesh.dispose();
cache.dispose();
if (paint.maskFilter != null && paint.maskFilter.sigma != 0) {

3
Runtime/ui/utils/renderer/common/picture.cs


var rect = transformedMesh.bounds;
state.scissor = state.scissor == null ? rect : state.scissor.Value.intersect(rect);
rectPathCache.dispose();
rectMesh.dispose();
transformedMesh.dispose();
break;
}

var cache = path.flatten(scale * devicePixelRatio);
var fillMesh = cache.getFillMesh(out _);
mesh = fillMesh.transform(state.xform);
fillMesh.dispose();
cache.dispose();
} else {
float strokeWidth = (paint.strokeWidth * scale).clamp(0, 200.0f);

mesh = strokenMesh.transform(state.xform);
cache.dispose();
strokenMesh.dispose();
}
if (paint.maskFilter != null && paint.maskFilter.sigma != 0) {

54
Runtime/ui/utils/renderer/geometry/path/path_cache.cs


List<uiPathPath> _paths = new List<uiPathPath>();
List<uiPathPoint> _points = new List<uiPathPoint>();
//mesh cache
uiMeshMesh _fillMesh;
bool _fillConvex;
uiMeshMesh _strokeMesh;
float _strokeWidth;
StrokeCap _lineCap;
StrokeJoin _lineJoin;
float _miterLimit;
public static uiPathCache create(float scale) {
uiPathCache newPathCache = ItemPoolManager.alloc<uiPathCache>();

public override void clear() {
this._paths.Clear();
this._points.Clear();
this._fillMesh?.dispose();
this._fillMesh = null;
this._strokeMesh?.dispose();
this._strokeMesh = null;
}
public uiPathCache() {

}
public uiMeshMesh getFillMesh(out bool convex) {
if (this._fillMesh != null) {
convex = this._fillConvex;
return this._fillMesh;
}
var vertices = this._expandFill();
var paths = this._paths;

D.assert(indices.Count == cindices);
var mesh = uiMeshMesh.create(null, vertices, indices);
var _fillMesh = mesh;
var _fillConvex = false;
this._fillMesh = mesh;
this._fillConvex = false;
for (var i = 0; i < paths.Count; i++) {
var path = paths[i];
if (path.count <= 2) {

if (_fillConvex) {
if (this._fillConvex) {
_fillConvex = false;
this._fillConvex = false;
break;
}

}
_fillConvex = true;
this._fillConvex = true;
convex = _fillConvex;
return _fillMesh;
convex = this._fillConvex;
return this._fillMesh;
}
void _calculateJoins(float w, StrokeJoin lineJoin, float miterLimit) {

}
public uiMeshMesh getStrokeMesh(float strokeWidth, StrokeCap lineCap, StrokeJoin lineJoin, float miterLimit) {
if (this._strokeMesh != null &&
this._strokeWidth == strokeWidth &&
this._lineCap == lineCap &&
this._lineJoin == lineJoin &&
this._miterLimit == miterLimit) {
return this._strokeMesh;
}
var vertices = this._expandStroke(strokeWidth, lineCap, lineJoin, miterLimit);
var paths = this._paths;

D.assert(indices.Count == cindices);
var _strokeMesh = uiMeshMesh.create(null, vertices, indices);
return _strokeMesh;
this._strokeMesh?.dispose();
this._strokeMesh = uiMeshMesh.create(null, vertices, indices);
this._strokeWidth = strokeWidth;
this._lineCap = lineCap;
this._lineJoin = lineJoin;
this._miterLimit = miterLimit;
return this._strokeMesh;
}
}
}
正在加载...
取消
保存