浏览代码

offset => uioffset (struct)

optimize some new with cache
remove lambda function (which will generate 10K gc per frame)
/main
xingwei.zhu 5 年前
当前提交
c7999bb9
共有 11 个文件被更改,包括 190 次插入1453 次删除
  1. 2
      Runtime/ui/utils/basic_types/canvas_clip.cs
  2. 197
      Runtime/ui/utils/basic_types/canvas_impl.cs
  3. 2
      Runtime/ui/utils/basic_types/canvas_utils.cs
  4. 2
      Runtime/ui/utils/basic_types/pool_items.cs
  5. 366
      Runtime/ui/utils/basic_types/rect.cs
  6. 6
      Runtime/ui/utils/basic_types/render_layer.cs
  7. 44
      Runtime/ui/utils/basic_types/ui_matrix.cs
  8. 2
      Runtime/ui/utils/basic_types/offset.cs.meta
  9. 21
      Runtime/ui/utils/basic_types/offset.cs
  10. 1001
      Runtime/ui/utils/basic_types/matrix.cs
  11. 0
      /Runtime/ui/utils/basic_types/offset.cs.meta

2
Runtime/ui/utils/basic_types/canvas_clip.cs


public const uint wideOpenGenID = 2;
public readonly List<ClipElement> stack = new List<ClipElement>();
public readonly List<ClipElement> stack = new List<ClipElement>(32);
ClipElement _lastElement;
uiRect _bound;

197
Runtime/ui/utils/basic_types/canvas_impl.cs


layer.clipStack.save();
}
readonly uiOffset[] _saveLayer_Points = new uiOffset[4];
void _saveLayer(uiRect bounds, Paint paint) {
D.assert(bounds.width > 0);
D.assert(bounds.height > 0);

if (paint.backdrop is _BlurImageFilter) {
var filter = (_BlurImageFilter) paint.backdrop;
if (!(filter.sigmaX == 0 && filter.sigmaY == 0)) {
var points = new[] {bounds.topLeft, bounds.bottomLeft, bounds.bottomRight, bounds.topRight};
state.matrix.Value.mapPoints(points);
this._saveLayer_Points[0] = bounds.topLeft;
this._saveLayer_Points[1] = bounds.bottomLeft;
this._saveLayer_Points[2] = bounds.bottomRight;
this._saveLayer_Points[3] = bounds.topRight;
state.matrix.Value.mapPoints(this._saveLayer_Points);
points[i] = new Offset(
(points[i].dx - parentBounds.left) / parentBounds.width,
(points[i].dy - parentBounds.top) / parentBounds.height
this._saveLayer_Points[i] = new uiOffset(
(this._saveLayer_Points[i].dx - parentBounds.left) / parentBounds.width,
(this._saveLayer_Points[i].dy - parentBounds.top) / parentBounds.height
points[0], points[1], points[2], points[3],
this._saveLayer_Points[0],
this._saveLayer_Points[1],
this._saveLayer_Points[2],
this._saveLayer_Points[3],
bounds);
var renderDraw = CanvasShader.texRT(layer, layer.layerPaint, mesh, parentLayer);
layer.draws.Add(renderDraw);

var filter = (_MatrixImageFilter) paint.backdrop;
if (!filter.transform.isIdentity()) {
layer.filterMode = filter.filterMode;
var points = new[] {bounds.topLeft, bounds.bottomLeft, bounds.bottomRight, bounds.topRight};
state.matrix.Value.mapPoints(points);
this._saveLayer_Points[0] = bounds.topLeft;
this._saveLayer_Points[1] = bounds.bottomLeft;
this._saveLayer_Points[2] = bounds.bottomRight;
this._saveLayer_Points[3] = bounds.topRight;
state.matrix.Value.mapPoints(this._saveLayer_Points);
points[i] = new Offset(
(points[i].dx - parentBounds.left) / parentBounds.width,
(points[i].dy - parentBounds.top) / parentBounds.height
this._saveLayer_Points[i] = new uiOffset(
(this._saveLayer_Points[i].dx - parentBounds.left) / parentBounds.width,
(this._saveLayer_Points[i].dy - parentBounds.top) / parentBounds.height
);
}

var mesh = ImageMeshGenerator.imageMesh(
matrix,
points[0], points[1], points[2], points[3],
this._saveLayer_Points[0],
this._saveLayer_Points[1],
this._saveLayer_Points[2],
this._saveLayer_Points[3],
bounds);
var renderDraw = CanvasShader.texRT(layer, layer.layerPaint, mesh, parentLayer);
layer.draws.Add(renderDraw);

state.matrix = matrix;
}
void _rotate(float radians, Offset offset = null) {
void _rotate(float radians, uiOffset? offset = null) {
var state = this._currentLayer.currentState;
if (offset == null) {
var matrix = uiMatrix3.makeRotate(radians);

else {
var matrix = uiMatrix3.makeRotate(radians, offset.dx, offset.dy);
var matrix = uiMatrix3.makeRotate(radians, offset.Value.dx, offset.Value.dy);
matrix.postConcat(state.matrix.Value);
state.matrix = matrix;
}

return layer.lastClipGenId != clipGenId || !uiRectHelper.equals(layer.lastClipBounds, clipBounds);
}
RenderLayer _createMaskLayer(RenderLayer parentLayer, uiRect maskBounds, Action<Paint> drawCallback,
Paint paint) {
RenderLayer _createMaskLayer(RenderLayer parentLayer, uiRect maskBounds, _drawPathDrawMeshCallbackDelegate drawCallback,
Paint paint, bool convex, float alpha, Texture tex, uiRect texBound, TextBlobMesh textMesh, uiMeshMesh mesh) {
var textureWidth = Mathf.CeilToInt(maskBounds.width * this._devicePixelRatio);
if (textureWidth < 1) {
textureWidth = 1;

var maskState = maskLayer.states[maskLayer.states.Count - 1];
maskState.matrix = parentState.matrix;
drawCallback(Paint.shapeOnly(paint));
drawCallback.Invoke(Paint.shapeOnly(paint), mesh, convex, alpha, tex, texBound, textMesh);
var removed = this._layers.removeLast();
D.assert(removed == maskLayer);

return blurYLayer;
}
void _drawWithMaskFilter(uiRect meshBounds, Action<Paint> drawAction, Paint paint, MaskFilter maskFilter,
Action onQuit = null) {
void _drawWithMaskFilter(uiRect meshBounds, Paint paint, MaskFilter maskFilter,
uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect texBound, TextBlobMesh textMesh,
_drawPathDrawMeshCallbackDelegate drawCallback) {
var layer = this._currentLayer;
var clipBounds = layer.layerBounds;

}
if (clipBounds.isEmpty) {
onQuit?.Invoke();
this._drawPathDrawMeshQuit(mesh);
return;
}

onQuit?.Invoke();
this._drawPathDrawMeshQuit(mesh);
return;
}

if (maskBounds.isEmpty) {
onQuit?.Invoke();
this._drawPathDrawMeshQuit(mesh);
var maskLayer = this._createMaskLayer(layer, maskBounds, drawAction, paint);
var maskLayer = this._createMaskLayer(layer, maskBounds, drawCallback, paint, convex, alpha, tex, texBound, textMesh, mesh);
var blurLayer = this._createBlurLayer(maskLayer, sigma, sigma, layer);

onQuit?.Invoke();
this._drawPathDrawMeshQuit(mesh);
return;
}

delegate void _drawPathDrawMeshCallbackDelegate(Paint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh);
void _drawPathDrawMeshCallback(Paint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh) {
if (!this._applyClip(mesh.bounds)) {
mesh.dispose();
return;
}
var layer = this._currentLayer;
if (convex) {
layer.draws.Add(CanvasShader.convexFill(layer, p, mesh));
}
else {
layer.draws.Add(CanvasShader.fill0(layer, mesh));
layer.draws.Add(CanvasShader.fill1(layer, p, mesh.boundsMesh));
}
}
void _drawPathDrawMeshCallback2(Paint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh) {
if (!this._applyClip(mesh.bounds)) {
mesh.dispose();
return;
}
var layer = this._currentLayer;
layer.draws.Add(CanvasShader.stroke0(layer, p, alpha, mesh));
layer.draws.Add(CanvasShader.stroke1(layer, mesh.duplicate()));
}
void _drawTextDrawMeshCallback(Paint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh) {
if (!this._applyClip(textBlobBounds)) {
textMesh.dispose();
return;
}
var layer = this._currentLayer;
layer.draws.Add(CanvasShader.texAlpha(layer, p, textMesh, tex));
}
void _drawPathDrawMeshQuit(uiMeshMesh mesh) {
mesh.dispose();
}
void _drawPath(uiPath path, Paint paint) {
D.assert(path != null);
D.assert(paint != null);

fillMesh.dispose();
cache.dispose();
Action<Paint> drawMesh = p => {
if (!this._applyClip(mesh.bounds)) {
mesh.dispose();
return;
}
var layer = this._currentLayer;
if (convex) {
layer.draws.Add(CanvasShader.convexFill(layer, p, mesh));
}
else {
layer.draws.Add(CanvasShader.fill0(layer, mesh));
layer.draws.Add(CanvasShader.fill1(layer, p, mesh.boundsMesh));
}
};
this._drawWithMaskFilter(mesh.bounds, drawMesh, paint, paint.maskFilter, () => { mesh.dispose(); });
this._drawWithMaskFilter(mesh.bounds, paint, paint.maskFilter, mesh, convex, 0, null, uiRectHelper.zero, null, this._drawPathDrawMeshCallback);
drawMesh(paint);
this._drawPathDrawMeshCallback(paint, mesh, convex, 0, null, uiRectHelper.zero, null);
}
else {
var state = this._currentLayer.currentState;

strokenMesh.dispose();
cache.dispose();
Action<Paint> drawMesh = p => {
if (!this._applyClip(mesh.bounds)) {
mesh.dispose();
return;
}
var layer = this._currentLayer;
layer.draws.Add(CanvasShader.stroke0(layer, p, alpha, mesh));
layer.draws.Add(CanvasShader.stroke1(layer, mesh.duplicate()));
};
this._drawWithMaskFilter(mesh.bounds, drawMesh, paint, paint.maskFilter, () => { mesh.dispose(); });
this._drawWithMaskFilter(mesh.bounds, paint, paint.maskFilter, mesh, false, alpha, null, uiRectHelper.zero, null, this._drawPathDrawMeshCallback2);
drawMesh(paint);
this._drawPathDrawMeshCallback2(paint, mesh, false, alpha, null, uiRectHelper.zero, null);
void _drawImage(Image image, Offset offset, Paint paint) {
void _drawImage(Image image, uiOffset offset, Paint paint) {
D.assert(offset != null);
D.assert(paint != null);
this._drawImageRect(image,

break;
}
case DrawRotate cmd: {
this._rotate(cmd.radians, cmd.offset);
this._rotate(cmd.radians, uiOffset.fromOffset(cmd.offset));
break;
}
case DrawSkew cmd: {

break;
}
case DrawImage cmd: {
this._drawImage(cmd.image, cmd.offset, cmd.paint);
this._drawImage(cmd.image, (uiOffset.fromOffset(cmd.offset)).Value, cmd.paint);
break;
}
case DrawImageRect cmd: {

break;
}
case DrawTextBlob cmd: {
this._drawTextBlob(cmd.textBlob, cmd.offset, cmd.paint);
this._drawTextBlob(cmd.textBlob, (uiOffset.fromOffset(cmd.offset)).Value, cmd.paint);
break;
}
default:

}
}
void _drawTextBlob(TextBlob textBlob, Offset offset, Paint paint) {
void _drawTextBlob(TextBlob textBlob, uiOffset offset, Paint paint) {
D.assert(offset != null);
D.assert(paint != null);
var state = this._currentLayer.currentState;

var tex = font.material.mainTexture;
Action<Paint> drawMesh = (Paint p) => {
if (!this._applyClip(textBlobBounds)) {
mesh.dispose();
return;
}
var layer = this._currentLayer;
layer.draws.Add(CanvasShader.texAlpha(layer, p, mesh, tex));
};
this._drawWithMaskFilter(textBlobBounds, drawMesh, paint, paint.maskFilter, () => { mesh.dispose(); });
this._drawWithMaskFilter(textBlobBounds, paint, paint.maskFilter, null, false, 0, tex, textBlobBounds, mesh, this._drawTextDrawMeshCallback);
drawMesh(paint);
this._drawTextDrawMeshCallback(paint, null, false, 0, tex, textBlobBounds, mesh);
}
public void flush(Picture picture) {

}
}
readonly float[] _drawLayer_matArray = new float[9];
void _drawLayer(RenderLayer layer, CommandBuffer cmdBuf) {
bool toClear = true;

}
else {
var mat = mesh.matrix.Value;
var array = new[] {
mat.kMScaleX, //0
mat.kMSkewX, //1
mat.kMTransX, //2
mat.kMSkewY, //3
mat.kMScaleY, //4
mat.kMTransY, //5
mat.kMPersp0, //6
mat.kMPersp1, //7
mat.kMPersp2 //8
};
cmd.properties.SetFloatArray(CmdDraw.matId, array);
this._drawLayer_matArray[0] = mat.kMScaleX;
this._drawLayer_matArray[1] = mat.kMSkewX;
this._drawLayer_matArray[2] = mat.kMTransX;
this._drawLayer_matArray[3] = mat.kMSkewY;
this._drawLayer_matArray[4] = mat.kMScaleY;
this._drawLayer_matArray[5] = mat.kMTransY;
this._drawLayer_matArray[6] = mat.kMPersp0;
this._drawLayer_matArray[7] = mat.kMPersp1;
this._drawLayer_matArray[8] = mat.kMPersp2;
cmd.properties.SetFloatArray(CmdDraw.matId, this._drawLayer_matArray);
}
cmdBuf.DrawMesh(cmd.meshObj, CmdDraw.idMat, cmd.material, 0, cmd.pass, cmd.properties.mpb);

2
Runtime/ui/utils/basic_types/canvas_utils.cs


};
public static uiMeshMesh imageMesh(uiMatrix3? matrix,
Offset srcTL, Offset srcBL, Offset srcBR, Offset srcTR,
uiOffset srcTL, uiOffset srcBL, uiOffset srcBR, uiOffset srcTR,
uiRect dst) {
var vertices = ItemPoolManager.alloc<uiList<Vector3>>();
vertices.SetCapacity(4);

2
Runtime/ui/utils/basic_types/pool_items.cs


static readonly Dictionary<Type, List<PoolItem>> poolDict = new Dictionary<Type, List<PoolItem>>();
static readonly Dictionary<Type, ItemDebugInfo> debugInfo = new Dictionary<Type, ItemDebugInfo>();
const bool _debugFlag = true;
const bool _debugFlag = false;
static int _allocTick = 0;

366
Runtime/ui/utils/basic_types/rect.cs


using System;
using UnityEngine;
namespace Unity.UIWidgets.ui {

get { return this.bottom - this.top; }
}
public Offset topLeft {
get { return new Offset(this.left, this.top); }
public uiOffset topLeft {
get { return new uiOffset(this.left, this.top); }
public Offset topCenter {
get { return new Offset(this.left + this.width / 2.0f, this.top); }
public uiOffset topCenter {
get { return new uiOffset(this.left + this.width / 2.0f, this.top); }
public Offset topRight {
get { return new Offset(this.right, this.top); }
public uiOffset topRight {
get { return new uiOffset(this.right, this.top); }
public Offset centerLeft {
get { return new Offset(this.left, this.top + this.height / 2.0f); }
public uiOffset centerLeft {
get { return new uiOffset(this.left, this.top + this.height / 2.0f); }
public Offset center {
get { return new Offset(this.left + this.width / 2.0f, this.top + this.height / 2.0f); }
public uiOffset center {
get { return new uiOffset(this.left + this.width / 2.0f, this.top + this.height / 2.0f); }
public Offset centerRight {
get { return new Offset(this.right, this.bottom); }
public uiOffset centerRight {
get { return new uiOffset(this.right, this.bottom); }
public Offset bottomLeft {
get { return new Offset(this.left, this.bottom); }
public uiOffset bottomLeft {
get { return new uiOffset(this.left, this.bottom); }
public Offset bottomCenter {
get { return new Offset(this.left + this.width / 2.0f, this.bottom); }
public uiOffset bottomCenter {
get { return new uiOffset(this.left + this.width / 2.0f, this.bottom); }
public Offset bottomRight {
get { return new Offset(this.right, this.bottom); }
public uiOffset bottomRight {
get { return new uiOffset(this.right, this.bottom); }
}
}

}
public static Offset[] toQuad(uiRect a) {
Offset[] dst = new Offset[4];
dst[0] = new Offset(a.left, a.top);
dst[1] = new Offset(a.right, a.top);
dst[2] = new Offset(a.right, a.bottom);
dst[3] = new Offset(a.left, a.bottom);
public static uiOffset[] toQuad(uiRect a) {
uiOffset[] dst = new uiOffset[4];
dst[0] = new uiOffset(a.left, a.top);
dst[1] = new uiOffset(a.right, a.top);
dst[2] = new uiOffset(a.right, a.bottom);
dst[3] = new uiOffset(a.left, a.bottom);
public static bool contains(uiRect a, Offset offset) {
public static bool contains(uiRect a, uiOffset offset) {
return offset.dx >= a.left && offset.dx < a.right && offset.dy >= a.top && offset.dy < a.bottom;
}

return new UnityEngine.Rect(rect.left, rect.top, rect.width, rect.height);
}
}
/*public struct uiRect : IEquatable<uiRect> {
uiRect(float left, float top, float right, float bottom) {
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
public static uiRect fromLTRB(float left, float top, float right, float bottom) {
return new uiRect(left, top, right, bottom);
}
public static uiRect fromLTWH(float left, float top, float width, float height) {
return new uiRect(left, top, left + width, top + height);
}
public static uiRect fromCircle(Offset center, float radius) {
return new uiRect(center.dx - radius, center.dy - radius, center.dx + radius, center.dy + radius);
}
public static uiRect fromPoints(Offset a, Offset b) {
return new uiRect(
Mathf.Min(a.dx, b.dx),
Mathf.Min(a.dy, b.dy),
Mathf.Max(a.dx, b.dx),
Mathf.Max(a.dy, b.dy)
);
}
public readonly float left;
public readonly float top;
public readonly float right;
public readonly float bottom;
public float width {
get { return this.right - this.left; }
}
public float height {
get { return this.bottom - this.top; }
}
public Size size {
get { return new Size(this.width, this.height); }
}
public static readonly uiRect zero = new uiRect(0, 0, 0, 0);
public static readonly uiRect one = new uiRect(0, 0, 1, 1);
public static readonly uiRect infinity = new uiRect(float.NegativeInfinity, float.NegativeInfinity,
float.PositiveInfinity, float.PositiveInfinity);
public const float _giantScalar = 1.0E+9f;
public static readonly uiRect largest =
fromLTRB(-_giantScalar, -_giantScalar, _giantScalar, _giantScalar);
public bool isInfinite {
get {
return float.IsInfinity(this.left)
|| float.IsInfinity(this.top)
|| float.IsInfinity(this.right)
|| float.IsInfinity(this.bottom);
}
}
public bool isFinite {
get { return !this.isInfinite; }
}
public bool isEmpty {
get { return this.left >= this.right || this.top >= this.bottom; }
}
public uiRect shift(Offset offset) {
return fromLTRB(this.left + offset.dx, this.top + offset.dy, this.right + offset.dx,
this.bottom + offset.dy);
}
public uiRect translate(float translateX, float translateY) {
return fromLTRB(this.left + translateX, this.top + translateY, this.right + translateX,
this.bottom + translateY);
}
public uiRect scale(float scaleX, float? scaleY = null) {
scaleY = scaleY ?? scaleX;
return fromLTRB(
this.left * scaleX, this.top * scaleY.Value,
this.right * scaleX, this.bottom * scaleY.Value);
}
public uiRect outset(float dx, float dy) {
return new uiRect(this.left - dx, this.top - dy, this.right + dx, this.bottom + dy);
}
public uiRect inflate(float delta) {
return fromLTRB(this.left - delta, this.top - delta, this.right + delta, this.bottom + delta);
}
public uiRect deflate(float delta) {
return this.inflate(-delta);
}
public uiRect intersect(Rect other) {
return fromLTRB(
Mathf.Max(this.left, other.left),
Mathf.Max(this.top, other.top),
Mathf.Min(this.right, other.right),
Mathf.Min(this.bottom, other.bottom)
);
}
public uiRect expandToInclude(uiRect other) {
if (this.isEmpty) {
return other;
}
if (other == null || other.isEmpty) {
return this;
}
return fromLTRB(
Mathf.Min(this.left, other.left),
Mathf.Min(this.top, other.top),
Mathf.Max(this.right, other.right),
Mathf.Max(this.bottom, other.bottom)
);
}
public bool overlaps(Rect other) {
if (this.right <= other.left || other.right <= this.left) {
return false;
}
if (this.bottom <= other.top || other.bottom <= this.top) {
return false;
}
return true;
}
public float shortestSide {
get { return Mathf.Min(Mathf.Abs(this.width), Mathf.Abs(this.height)); }
}
public float longestSide {
get { return Mathf.Max(Mathf.Abs(this.width), Mathf.Abs(this.height)); }
}
public Offset topLeft {
get { return new Offset(this.left, this.top); }
}
public Offset topCenter {
get { return new Offset(this.left + this.width / 2.0f, this.top); }
}
public Offset topRight {
get { return new Offset(this.right, this.top); }
}
public Offset centerLeft {
get { return new Offset(this.left, this.top + this.height / 2.0f); }
}
public Offset center {
get { return new Offset(this.left + this.width / 2.0f, this.top + this.height / 2.0f); }
}
public Offset centerRight {
get { return new Offset(this.right, this.bottom); }
}
public Offset bottomLeft {
get { return new Offset(this.left, this.bottom); }
}
public Offset bottomCenter {
get { return new Offset(this.left + this.width / 2.0f, this.bottom); }
}
public Offset bottomRight {
get { return new Offset(this.right, this.bottom); }
}
public bool contains(Offset offset) {
return offset.dx >= this.left && offset.dx < this.right && offset.dy >= this.top && offset.dy < this.bottom;
}
public bool containsInclusive(Offset offset) {
return offset.dx >= this.left && offset.dx <= this.right && offset.dy >= this.top &&
offset.dy <= this.bottom;
}
public bool contains(Rect rect) {
return this.contains(rect.topLeft) && this.contains(rect.bottomRight);
}
public uiRect round() {
return fromLTRB(
Mathf.Round(this.left), Mathf.Round(this.top),
Mathf.Round(this.right), Mathf.Round(this.bottom));
}
public uiRect roundOut() {
return fromLTRB(
Mathf.Floor(this.left), Mathf.Floor(this.top),
Mathf.Ceil(this.right), Mathf.Ceil(this.bottom));
}
public uiRect roundOut(float devicePixelRatio) {
return fromLTRB(
Mathf.Floor(this.left * devicePixelRatio) / devicePixelRatio,
Mathf.Floor(this.top * devicePixelRatio) / devicePixelRatio,
Mathf.Ceil(this.right * devicePixelRatio) / devicePixelRatio,
Mathf.Ceil(this.bottom * devicePixelRatio) / devicePixelRatio);
}
public uiRect roundIn() {
return fromLTRB(
Mathf.Ceil(this.left), Mathf.Ceil(this.top),
Mathf.Floor(this.right), Mathf.Floor(this.bottom));
}
public uiRect normalize() {
if (this.left <= this.right && this.top <= this.bottom) {
return this;
}
return fromLTRB(
Mathf.Min(this.left, this.right),
Mathf.Min(this.top, this.bottom),
Mathf.Max(this.left, this.right),
Mathf.Max(this.top, this.bottom)
);
}
public static uiRect lerp(uiRect a, uiRect b, float t) {
if (a == null && b == null) {
Debug.Assert(false, "uiRect cannot be lerpped between two nulls!");
return zero;
}
if (a == null) {
return fromLTRB(b.left * t, b.top * t, b.right * t, b.bottom * t);
}
if (b == null) {
float k = 1.0f - t;
return fromLTRB(a.left * k, a.top * k, a.right * k, a.bottom * k);
}
return fromLTRB(
MathUtils.lerpFloat(a.left, b.left, t),
MathUtils.lerpFloat(a.top, b.top, t),
MathUtils.lerpFloat(a.right, b.right, t),
MathUtils.lerpFloat(a.bottom, b.bottom, t)
);
}
public bool Equals(Rect other) {
if (ReferenceEquals(null, other)) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
return this.left.Equals(other.left) && this.top.Equals(other.top) && this.right.Equals(other.right) &&
this.bottom.Equals(other.bottom);
}
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) {
return false;
}
if (ReferenceEquals(this, obj)) {
return true;
}
if (obj.GetType() != this.GetType()) {
return false;
}
return this.Equals((Rect) obj);
}
public override int GetHashCode() {
unchecked {
var hashCode = this.left.GetHashCode();
hashCode = (hashCode * 397) ^ this.top.GetHashCode();
hashCode = (hashCode * 397) ^ this.right.GetHashCode();
hashCode = (hashCode * 397) ^ this.bottom.GetHashCode();
return hashCode;
}
}
public static bool operator ==(uiRect left, uiRect right) {
return Equals(left, right);
}
public static bool operator !=(uiRect left, uiRect right) {
return !Equals(left, right);
}
public override string ToString() {
return "Rect.fromLTRB(" + this.left.ToString("0.0") + ", " + this.top.ToString("0.0") + ", " +
this.right.ToString("0.0") + ", " + this.bottom.ToString("0.0") + ")";
}
}*/
}

6
Runtime/ui/utils/basic_types/render_layer.cs


public bool noMSAA = false;
public uiRect layerBounds;
public Paint layerPaint;
public readonly List<RenderCmd> draws = new List<RenderCmd>();
public readonly List<RenderLayer> layers = new List<RenderLayer>();
public readonly List<State> states = new List<State>();
public readonly List<RenderCmd> draws = new List<RenderCmd>(128);
public readonly List<RenderLayer> layers = new List<RenderLayer>(16);
public readonly List<State> states = new List<State>(16);
public State currentState;
public ClipStack clipStack;
public uint lastClipGenId;

44
Runtime/ui/utils/basic_types/ui_matrix.cs


}
public partial struct uiMatrix3 {
public void mapPoints(Offset[] dst, Offset[] src) {
public void mapPoints(uiOffset[] dst, uiOffset[] src) {
public void mapPoints(Offset[] pts) {
public void mapPoints(uiOffset[] pts) {
delegate void MapPtsProc(uiMatrix3 mat, Offset[] dst, Offset[] src, int count);
delegate void MapPtsProc(uiMatrix3 mat, uiOffset[] dst, uiOffset[] src, int count);
static readonly MapPtsProc[] gMapPtsProcs = {
Identity_pts, Trans_pts,

return GetMapPtsProc(this._getType());
}
static void Identity_pts(uiMatrix3 m, Offset[] dst, Offset[] src, int count) {
static void Identity_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
D.assert(m._getType() == 0);
if (dst != src && count > 0) {

static void Trans_pts(uiMatrix3 m, Offset[] dst, Offset[] src, int count) {
static void Trans_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
dst[i] = new Offset(src[i].dx + tx, src[i].dy + ty);
dst[i] = new uiOffset(src[i].dx + tx, src[i].dy + ty);
static void Scale_pts(uiMatrix3 m, Offset[] dst, Offset[] src, int count) {
static void Scale_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
D.assert(m._getType() <= (TypeMask.kScale_Mask | TypeMask.kTranslate_Mask));
if (count > 0) {
var tx = m.getTranslateX();

for (int i = 0; i < count; ++i) {
dst[i] = new Offset(src[i].dx * sx + tx, src[i].dy * sy + ty);
dst[i] = new uiOffset(src[i].dx * sx + tx, src[i].dy * sy + ty);
static void Persp_pts(uiMatrix3 m, Offset[] dst, Offset[] src, int count) {
static void Persp_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
D.assert(m._hasPerspective());
if (count > 0) {

z = 1 / z;
}
dst[i] = new Offset(x * z, y * z);
dst[i] = new uiOffset(x * z, y * z);
static void Affine_pts(uiMatrix3 m, Offset[] dst, Offset[] src, int count) {
static void Affine_pts(uiMatrix3 m, uiOffset[] dst, uiOffset[] src, int count) {
D.assert(m._getType() != TypeMask.kPerspective_Mask);
if (count > 0) {
var tx = m.getTranslateX();

var ky = m.getSkewY();
for (int i = 0; i < count; ++i) {
dst[i] = new Offset(
dst[i] = new uiOffset(
src[i].dx * sx + src[i].dy * kx + tx,
src[i].dx * ky + src[i].dy * sy + ty);
}

return m;
}
public static uiMatrix3 makeTrans(Offset offset) {
public static uiMatrix3 makeTrans(uiOffset offset) {
var m = new uiMatrix3();
m.setTranslate(offset.dx, offset.dy);
return m;

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);
}
}
//TODO: [ALLOCATOR] find a way to avoid the gc here
var result = BitConverter.ToInt32(BitConverter.GetBytes(x), 0);
var result = GetBytesToInt32(x);
return result;
}

2
Runtime/ui/utils/basic_types/offset.cs.meta


fileFormatVersion: 2
guid: 7e52d776bf55e48ccaac813e464a6882
guid: a26d34118ea79461da3c97812b10608a
MonoImporter:
externalObjects: {}
serializedVersion: 2

21
Runtime/ui/utils/basic_types/offset.cs


namespace Unity.UIWidgets.ui {
public struct uiOffset {
public uiOffset(float dx, float dy) {
this.dx = dx;
this.dy = dy;
}
public readonly float dx;
public readonly float dy;
public static uiOffset? fromOffset(Offset offset) {
if (offset == null) {
return null;
}
var newOffset = new uiOffset(offset.dx, offset.dy);
return newOffset;
}
}
}

1001
Runtime/ui/utils/basic_types/matrix.cs
文件差异内容过多而无法显示
查看文件

/Runtime/ui/utils/basic_types/matrix.cs.meta → /Runtime/ui/utils/basic_types/offset.cs.meta

正在加载...
取消
保存