浏览代码

fix new uiPath bugs

MeshKey, MeshInfo => PoolItem
/main
xingwei.zhu 5 年前
当前提交
1e490043
共有 5 个文件被更改,包括 85 次插入43 次删除
  1. 16
      Runtime/ui/matrix.cs
  2. 27
      Runtime/ui/painting/shadow_utils.cs
  3. 70
      Runtime/ui/painting/txt/mesh_generator.cs
  4. 14
      Runtime/ui/utils/renderer/common/base_canvas.cs
  5. 1
      Runtime/ui/utils/renderer/geometry/path/path.cs

16
Runtime/ui/matrix.cs


return prod == 0; // if prod is NaN, this check will return false
}
static byte[] _scalar_as_2s_compliment_vars = new byte[4];
static unsafe int GetBytesToInt32(float value) {
var intVal = *(int*) &value;
fixed (byte* b = _scalar_as_2s_compliment_vars) {
*((int*) b) = intVal;
}
fixed (byte* pbyte = &_scalar_as_2s_compliment_vars[0]) {
return *((int*) pbyte);
}
}
var result = BitConverter.ToInt32(BitConverter.GetBytes(x), 0);
var result = GetBytesToInt32(x);
if (result < 0) {
result &= 0x7FFFFFFF;
result = -result;

27
Runtime/ui/painting/shadow_utils.cs


static class ShadowUtils {
public const bool kUseFastShadow = false;
public const float kAmbientHeightFactor = 1.0f / 128.0f;
public const float kAmbientGeomFactor = 64.0f;
const float kAmbientHeightFactor = 1.0f / 128.0f;
const float kAmbientGeomFactor = 64.0f;
public const float kBlurSigmaScale = 0.57735f;
const float kBlurSigmaScale = 0.57735f;
public const float kMaxAmbientRadius = 300 * kAmbientHeightFactor * kAmbientGeomFactor;
const float kMaxAmbientRadius = 300 * kAmbientHeightFactor * kAmbientGeomFactor;
public static float divideAndPin(float numer, float denom, float min, float max) {
static float divideAndPin(float numer, float denom, float min, float max) {
public static float ambientBlurRadius(float height) {
static float ambientBlurRadius(float height) {
public static float ambientRecipAlpha(float height) {
static float ambientRecipAlpha(float height) {
public static float spotBlurRadius(float occluderZ, float lightZ, float lightRadius) {
static float spotBlurRadius(float occluderZ, float lightZ, float lightRadius) {
public static void getSpotParams(float occluderZ, float lightX, float lightY, float lightZ,
static void getSpotParams(float occluderZ, float lightX, float lightY, float lightZ,
float lightRadius,
ref float blurRadius, ref float scale, ref Vector2 translate) {
float zRatio = divideAndPin(occluderZ, lightZ - occluderZ, 0.0f, 0.95f);

}
public static float convertRadiusToSigma(float radius) {
static float convertRadiusToSigma(float radius) {
return radius > 0 ? kBlurSigmaScale * radius + 0.5f : 0.0f;
}

outSpotColor = inSpotColor;
}
static Matrix3 _toHomogeneous = Matrix3.I();
public static bool getSpotShadowTransform(Vector3 lightPos, float lightRadius, Matrix3 ctm,
static readonly Matrix3 _toHomogeneous = Matrix3.I();
static bool getSpotShadowTransform(Vector3 lightPos, float lightRadius, Matrix3 ctm,
Vector3 zPlaneParams, Rect pathBounds, Matrix3 shadowTransform, ref float radius) {
float heightFunc(float x, float y) {
return zPlaneParams.x * x + zPlaneParams.y * y + zPlaneParams.z;

return true;
}
static Path _devSpacePath = new Path();
static readonly Path _devSpacePath = new Path();
public static void drawShadow(Canvas canvas, Path path, Vector3 zPlaneParams, Vector3 devLightPos,
float lightRadius, uiColor ambientColor, uiColor spotColor, int flags) {
if (kUseFastShadow) {

70
Runtime/ui/painting/txt/mesh_generator.cs


using System;
using System.Collections.Generic;
using System.Linq;
using Unity.UIWidgets.foundation;
class MeshKey : IEquatable<MeshKey> {
public readonly long textBlobId;
public readonly float scale;
class MeshKey : PoolItem, IEquatable<MeshKey> {
public long textBlobId;
public float scale;
public MeshKey() {
}
public MeshKey(long textBlobId, float scale) {
this.textBlobId = textBlobId;
this.scale = scale;
public static MeshKey create(long textBlobId, float scale) {
var newKey = ItemPoolManager.alloc<MeshKey>();
newKey.textBlobId = textBlobId;
newKey.scale = scale;
return newKey;
}
public bool Equals(MeshKey other) {

}
}
class MeshInfo {
public readonly MeshKey key;
public readonly long textureVersion;
public readonly uiMeshMesh mesh;
class MeshInfo : PoolItem {
public MeshKey key;
public long textureVersion;
public uiMeshMesh mesh;
public MeshInfo(MeshKey key, uiMeshMesh mesh, long textureVersion, int timeToLive = 5) {
this.mesh = mesh;
this.key = key;
this.textureVersion = textureVersion;
this.touch(timeToLive);
public MeshInfo() {
}
public static MeshInfo create(MeshKey key, uiMeshMesh mesh, long textureVersion, int timeToLive = 5) {
var meshInfo = ItemPoolManager.alloc<MeshInfo>();
meshInfo.mesh = mesh;
meshInfo.key = key;
meshInfo.textureVersion = textureVersion;
meshInfo.touch(timeToLive);
return meshInfo;
}
public override void clear() {
this.key.dispose();
this.mesh.dispose();
}
public long timeToLive {

get { return _meshes.Count; }
}
static List<MeshKey> _keysToRemove = new List<MeshKey>();
var keysToRemove = _meshes.Values.Where(info => info.timeToLive < _frameCount)
.Select(info => info.key).ToList();
foreach (var key in keysToRemove) {
_meshes[key].mesh.dispose();
D.assert(_keysToRemove.Count == 0);
foreach (var key in _meshes.Keys) {
if (_meshes[key].timeToLive < _frameCount) {
_keysToRemove.Add(key);
}
}
foreach (var key in _keysToRemove)
{
_meshes[key].dispose();
_keysToRemove.Clear();
}
public uiMeshMesh resovleMesh() {

var style = this.textBlob.style;
var fontInfo = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle);
var key = new MeshKey(this.textBlob.instanceId, this.scale);
var key = MeshKey.create(this.textBlob.instanceId, this.scale);
key.dispose();
meshInfo.touch();
this._mesh = meshInfo.mesh.transform(this.matrix);
return this._mesh;

}
uiMeshMesh mesh = vertices.Count > 0 ? uiMeshMesh.create(null, vertices, triangles, uv) : null;
//_meshes[key] = new MeshInfo(key, mesh, fontInfo.textureVersion);
_meshes[key] = MeshInfo.create(key, mesh, fontInfo.textureVersion);
mesh.dispose();
return this._mesh;
}
}

14
Runtime/ui/utils/renderer/common/base_canvas.cs


}
public void drawLine(Offset from, Offset to, Paint paint) {
var path = new uiPath();
var path = uiPath.create();
path.moveTo(from.dx, from.dy);
path.lineTo(to.dx, to.dy);

return;
}
var path = new uiPath();
var path = uiPath.create();
path.addRect(rect);
this._recorder.addDrawCmd(uiDrawPath.create(

}
public void drawRRect(RRect rrect, Paint paint) {
var path = new uiPath();
var path = uiPath.create();
path.addRRect(rrect);
this._recorder.addDrawCmd(uiDrawPath.create(
path : path,

public void drawDRRect(RRect outer, RRect inner, Paint paint) {
var path = new uiPath();
var path = uiPath.create();
path.addRRect(outer);
path.addRRect(inner);
path.winding(PathWinding.clockwise);

public void drawOval(Rect rect, Paint paint) {
var w = rect.width / 2;
var h = rect.height / 2;
var path = new uiPath();
var path = uiPath.create();
path.addEllipse(rect.left + w, rect.top + h, w, h);
this._recorder.addDrawCmd(uiDrawPath.create(

}
public void drawCircle(Offset c, float radius, Paint paint) {
var path = new uiPath();
var path = uiPath.create();
path.addCircle(c.dx, c.dy, radius);
this._recorder.addDrawCmd(uiDrawPath.create(

}
public void drawArc(Rect rect, float startAngle, float sweepAngle, bool useCenter, Paint paint) {
var path = new uiPath();
var path = uiPath.create();
if (useCenter) {
var center = rect.center;

1
Runtime/ui/utils/renderer/geometry/path/path.cs


this._commands.dispose();
this._cache?.dispose();
this._cache = null;
this._commands = null;
}
void _reset() {

正在加载...
取消
保存