浏览代码

format cleanup

/main
xingwei.zhu 5 年前
当前提交
c9445639
共有 40 个文件被更改,包括 539 次插入508 次删除
  1. 9
      Runtime/ui/renderer/allocator/debug.cs
  2. 11
      Runtime/ui/renderer/allocator/generic_list.cs
  3. 36
      Runtime/ui/renderer/allocator/pool_object.cs
  4. 9
      Runtime/ui/renderer/allocator/uipath_cache_manager.cs
  5. 26
      Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_clip.cs
  6. 85
      Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_impl.cs
  7. 116
      Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shader.cs
  8. 1
      Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shader_utils.cs
  9. 22
      Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_utils.cs
  10. 14
      Runtime/ui/renderer/cmdbufferCanvas/rendering/render_cmd.cs
  11. 23
      Runtime/ui/renderer/cmdbufferCanvas/rendering/render_layer.cs
  12. 125
      Runtime/ui/renderer/common/base_canvas.cs
  13. 14
      Runtime/ui/renderer/common/color.cs
  14. 81
      Runtime/ui/renderer/common/draw_cmd.cs
  15. 14
      Runtime/ui/renderer/common/geometry/matrix/ui_matrix.cs
  16. 1
      Runtime/ui/renderer/common/geometry/matrix/ui_matrix_utils.cs
  17. 11
      Runtime/ui/renderer/common/geometry/mesh_mesh.cs
  18. 7
      Runtime/ui/renderer/common/geometry/offset.cs
  19. 72
      Runtime/ui/renderer/common/geometry/path/path.cs
  20. 108
      Runtime/ui/renderer/common/geometry/path/path_cache.cs
  21. 8
      Runtime/ui/renderer/common/geometry/path/path_utils.cs
  22. 5
      Runtime/ui/renderer/common/geometry/path/tessellation_generator.cs
  23. 61
      Runtime/ui/renderer/common/geometry/rect.cs
  24. 45
      Runtime/ui/renderer/common/paint.cs
  25. 41
      Runtime/ui/renderer/common/picture.cs
  26. 4
      Runtime/ui/renderer/common/utils.cs
  27. 2
      Runtime/ui/renderer/compositeCanvas/compositing.cs
  28. 5
      Runtime/ui/renderer/compositeCanvas/flow/backdrop_filter_layer.cs
  29. 3
      Runtime/ui/renderer/compositeCanvas/flow/clip_path_layer.cs
  30. 7
      Runtime/ui/renderer/compositeCanvas/flow/clip_rect_layer.cs
  31. 5
      Runtime/ui/renderer/compositeCanvas/flow/clip_rrect_layer.cs
  32. 5
      Runtime/ui/renderer/compositeCanvas/flow/container_layer.cs
  33. 3
      Runtime/ui/renderer/compositeCanvas/flow/instrumentation.cs
  34. 2
      Runtime/ui/renderer/compositeCanvas/flow/layer_tree.cs
  35. 21
      Runtime/ui/renderer/compositeCanvas/flow/opacity_layer.cs
  36. 4
      Runtime/ui/renderer/compositeCanvas/flow/physical_shape_layer.cs
  37. 15
      Runtime/ui/renderer/compositeCanvas/flow/picture_layer.cs
  38. 13
      Runtime/ui/renderer/compositeCanvas/flow/raster_cache.cs
  39. 5
      Runtime/ui/renderer/compositeCanvas/flow/texture_layer.cs
  40. 8
      Runtime/ui/renderer/compositeCanvas/flow/transform_layer.cs

9
Runtime/ui/renderer/allocator/debug.cs


using UnityEngine;
namespace Unity.UIWidgets.ui {
class DebugMeta {
public string objName;
public int watermark;

this.allocated = allocatedCount;
}
}
static readonly Dictionary<int, DebugMeta> debugInfos = new Dictionary<int, DebugMeta>();
public static void onFrameEnd() {

allocCount++;
if (allocCount >= 120) {
allocCount = 0;

if (debugInfo == "Alloc Stats: ") {
return;
}
Debug.Log(debugInfo);
}
}

11
Runtime/ui/renderer/allocator/generic_list.cs


using System.Collections.Generic;
namespace Unity.UIWidgets.ui {
public class uiList<T> : PoolObject {
List<T> list;

public uiList() {
}
public List<T> data => this.list;
public List<T> data {
get { return this.list; }
}
public void Add(T item) {
this.list.Add(item);

public void SetCapacity(int capacity) {
this.list.Capacity = Math.Max(capacity, this.list.Capacity);
}
get {
return this.list[index];
}
get { return this.list[index]; }
set { this.list[index] = value; }
}
}

36
Runtime/ui/renderer/allocator/pool_object.cs


using System.Diagnostics;
namespace Unity.UIWidgets.ui {
public abstract class PoolObject
{
public abstract class PoolObject {
public virtual void setup() {}
public virtual void clear() {}
public virtual void setup() {
}
public virtual void clear() {
}
public static class ObjectPool<TObject> where TObject :PoolObject, new() {
public static class ObjectPool<TObject> where TObject : PoolObject, new() {
public static TObject alloc() {
if (pool.Count == 0) {
for (int i = 0; i < 128; i++) {

allocatedCount += 128;
}
return ret;
}

}
obj.clear();
if (pool.Count > 256) {
allocatedCount--;

}
//For debugger
static bool _debugInfoReady = false;
static string _debugName = null;

_debugInfoReady = true;
}
if(_debugInfoReady)
{
if (_debugInfoReady) {
_generateDebugInfo();
return _debugName;
}

if (_debugInfoReady) {
return _debugKey;
}
_generateDebugInfo();
return _debugKey;
}

9
Runtime/ui/renderer/allocator/uipath_cache_manager.cs


using System.Collections.Generic;
namespace Unity.UIWidgets.ui {
//remove unused cache items every 1 frame
static Dictionary<uint, bool> touched = new Dictionary<uint, bool>(256);

public static void tickNextFrame() {
untouched.Clear();
foreach (var key in cache.Keys) {

ObjectPool<uiPath>.release(cache[key]);
cache.Remove(key);
}
touched.Clear();
}

var uipath = uiPath.create();
cache[pathKey] = uipath;
touched[pathKey] = true;
uipath.needCache = true;
uipath.pathKey = pathKey;

26
Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_clip.cs


uiMatrix3? _invMat;
public ClipElement() {
}
public override void clear() {

public static ClipElement create(int saveCount, uiPath uiPath, uiMatrix3 matrix, float scale) {
ClipElement newElement = ObjectPool<ClipElement>.alloc();
var vertices = newElement.mesh.vertices;
if (newElement.convex && vertices.Count == 4 && matrix.rectStaysRect() &&
(Mathf.Abs(vertices[0].x - vertices[1].x) < 1e-6 && Mathf.Abs(vertices[1].y - vertices[2].y) < 1e-6 &&

if (this.mesh.vertices.Count <= 2) {
return false;
}
if ((xT < yL) || (xT < yR) || (xB < yL) || (xB < yR)) {
return false;
}

if (this._invMat == null) {
this._invMat = this.mesh.matrix.Value.invert();
}
rect = this._invMat.Value.mapRect(rect);
}

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

foreach (var clipelement in this.stack) {
ObjectPool<ClipElement>.release(clipelement);
}
this.stack.Clear();
}

var lastelement = this.stack[this.stack.Count - 1];
ObjectPool<ClipElement>.release(lastelement);
this.stack.RemoveAt(this.stack.Count - 1);
this._lastElement = this.stack.Count == 0 ? null : this.stack[this.stack.Count - 1];
}

return;
}
if (!uiRectHelper.overlaps(prior.getBound(),element.getBound())) {
if (!uiRectHelper.overlaps(prior.getBound(), element.getBound())) {
prior.setEmpty();
ObjectPool<ClipElement>.release(element);
return;

}
public ReducedClip() {
}
public override void clear() {

return clip;
}
stackBounds = uiRectHelper.intersect(layerBounds,stackBounds.Value);
stackBounds = uiRectHelper.intersect(layerBounds, stackBounds.Value);
if (iior) {
clip.scissor = stackBounds;
return clip;

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


this._fringeWidth = 1.0f / devicePixelRatio;
this._devicePixelRatio = devicePixelRatio;
this._meshPool = meshPool;
readonly _drawPathDrawMeshCallbackDelegate ___drawTextDrawMeshCallback;
readonly _drawPathDrawMeshCallbackDelegate ___drawPathDrawMeshCallback2;
readonly _drawPathDrawMeshCallbackDelegate ___drawPathDrawMeshCallback;

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);
var parentBounds = parentLayer.layerBounds;

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

var filter = (_MatrixImageFilter) paint.backdrop;
if (!filter.transform.isIdentity()) {
layer.filterMode = filter.filterMode;
this._saveLayer_Points[0] = bounds.topLeft;
this._saveLayer_Points[1] = bounds.bottomLeft;
this._saveLayer_Points[2] = bounds.bottomRight;

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

this._clipPath(path);
uiPathCacheManager.putToCache(path);
}
void _clipUIRect(uiRect rect) {
var path = uiPath.create();
path.addRect(rect);

var scissor = reducedClip.scissor;
var physicalRect = uiRectHelper.fromLTRB(0, 0, layer.width, layer.height);
if (uiRectHelper.equals(scissor,layerBounds)) {
if (uiRectHelper.equals(scissor, layerBounds)) {
this._tryAddScissor(layer, null);
}
else {

);
deviceScissor = uiRectHelper.scale(deviceScissor, layer.width / layerBounds.width, layer.height / layerBounds.height);
deviceScissor = uiRectHelper.scale(deviceScissor, layer.width / layerBounds.width,
layer.height / layerBounds.height);
deviceScissor = uiRectHelper.roundOut(deviceScissor);
deviceScissor = uiRectHelper.intersect(deviceScissor, physicalRect);

return layer.lastClipGenId != clipGenId || !uiRectHelper.equals(layer.lastClipBounds, clipBounds);
}
RenderLayer _createMaskLayer(RenderLayer parentLayer, uiRect maskBounds, _drawPathDrawMeshCallbackDelegate drawCallback,
uiPaint paint, bool convex, float alpha, Texture tex, uiRect texBound, TextBlobMesh textMesh, uiMeshMesh mesh) {
RenderLayer _createMaskLayer(RenderLayer parentLayer, uiRect maskBounds,
_drawPathDrawMeshCallbackDelegate drawCallback,
uiPaint 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;

layer.clipStack.getBounds(out stackBounds, out iior);
if (stackBounds != null) {
clipBounds = uiRectHelper.intersect(clipBounds,stackBounds.Value);
clipBounds = uiRectHelper.intersect(clipBounds, stackBounds.Value);
}
if (clipBounds.isEmpty) {

float sigma3 = 3 * sigma;
var maskBounds = uiRectHelper.inflate(meshBounds, sigma3);
maskBounds = uiRectHelper.intersect(maskBounds, uiRectHelper.inflate(clipBounds,sigma3));
maskBounds = uiRectHelper.intersect(maskBounds, uiRectHelper.inflate(clipBounds, sigma3));
var maskLayer = this._createMaskLayer(layer, maskBounds, drawCallback, paint, convex, alpha, tex, texBound, textMesh, mesh);
var maskLayer = this._createMaskLayer(layer, maskBounds, drawCallback, paint, convex, alpha, tex, texBound,
textMesh, mesh);
var blurLayer = this._createBlurLayer(maskLayer, sigma, sigma, layer);

layer.draws.Add(CanvasShader.texRT(layer, paint, blurMesh, blurLayer));
}
delegate void _drawPathDrawMeshCallbackDelegate(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh);
delegate void _drawPathDrawMeshCallbackDelegate(uiPaint p, uiMeshMesh mesh, bool convex, float alpha,
Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh);
void _drawPathDrawMeshCallback(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh) {
void _drawPathDrawMeshCallback(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex,
uiRect textBlobBounds, TextBlobMesh textMesh) {
if (!this._applyClip(mesh.bounds)) {
ObjectPool<uiMeshMesh>.release(mesh);
return;

}
}
void _drawPathDrawMeshCallback2(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh) {
void _drawPathDrawMeshCallback2(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex,
uiRect textBlobBounds, TextBlobMesh textMesh) {
if (!this._applyClip(mesh.bounds)) {
ObjectPool<uiMeshMesh>.release(mesh);
return;

layer.draws.Add(CanvasShader.stroke1(layer, mesh.duplicate()));
}
void _drawTextDrawMeshCallback(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh) {
void _drawTextDrawMeshCallback(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex,
uiRect textBlobBounds, TextBlobMesh textMesh) {
if (!this._applyClip(textBlobBounds)) {
ObjectPool<TextBlobMesh>.release(textMesh);
return;

var mesh = fillMesh.transform(state.matrix);
if (paint.maskFilter != null && paint.maskFilter.Value.sigma != 0) {
this._drawWithMaskFilter(mesh.bounds, paint, paint.maskFilter.Value, mesh, convex, 0, null, uiRectHelper.zero, null, this.___drawPathDrawMeshCallback);
this._drawWithMaskFilter(mesh.bounds, paint, paint.maskFilter.Value, mesh, convex, 0, null,
uiRectHelper.zero, null, this.___drawPathDrawMeshCallback);
return;
}

var mesh = strokenMesh.transform(state.matrix);
if (paint.maskFilter != null && paint.maskFilter.Value.sigma != 0) {
this._drawWithMaskFilter(mesh.bounds, paint, paint.maskFilter.Value, mesh, false, alpha, null, uiRectHelper.zero, null, this.___drawPathDrawMeshCallback2);
this._drawWithMaskFilter(mesh.bounds, paint, paint.maskFilter.Value, mesh, false, alpha, null,
uiRectHelper.zero, null, this.___drawPathDrawMeshCallback2);
return;
}

var layer = this._currentLayer;
var state = layer.currentState;
var mesh = ImageMeshGenerator.imageNineMesh(state.matrix, src.Value, center, image.width, image.height, dst);
var mesh = ImageMeshGenerator.imageNineMesh(state.matrix, src.Value, center, image.width, image.height,
dst);
if (!this._applyClip(mesh.bounds)) {
ObjectPool<uiMeshMesh>.release(mesh);
return;

}
void _drawPicture(Picture picture, bool needsSave = true) {
if (needsSave) {
this._save();

break;
}
case DrawImage cmd: {
this._drawImage(cmd.image, (uiOffset.fromOffset(cmd.offset)).Value, uiPaint.fromPaint(cmd.paint));
this._drawImage(cmd.image, (uiOffset.fromOffset(cmd.offset)).Value,
uiPaint.fromPaint(cmd.paint));
this._drawImageRect(cmd.image, uiRectHelper.fromRect(cmd.src), uiRectHelper.fromRect(cmd.dst), uiPaint.fromPaint(cmd.paint));
this._drawImageRect(cmd.image, uiRectHelper.fromRect(cmd.src), uiRectHelper.fromRect(cmd.dst),
uiPaint.fromPaint(cmd.paint));
this._drawImageNine(cmd.image, uiRectHelper.fromRect(cmd.src), uiRectHelper.fromRect(cmd.center), uiRectHelper.fromRect(cmd.dst), uiPaint.fromPaint(cmd.paint));
this._drawImageNine(cmd.image, uiRectHelper.fromRect(cmd.src),
uiRectHelper.fromRect(cmd.center), uiRectHelper.fromRect(cmd.dst),
uiPaint.fromPaint(cmd.paint));
break;
}
case DrawPicture cmd: {

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

this._restore();
}
}
void _drawUIPicture(uiPicture picture, bool needsSave = true) {
if (needsSave) {

var tex = font.material.mainTexture;
if (paint.maskFilter != null && paint.maskFilter.Value.sigma != 0) {
this._drawWithMaskFilter(textBlobBounds, paint, paint.maskFilter.Value, null, false, 0, tex, textBlobBounds, mesh, this.___drawTextDrawMeshCallback);
this._drawWithMaskFilter(textBlobBounds, paint, paint.maskFilter.Value, null, false, 0, tex,
textBlobBounds, mesh, this.___drawTextDrawMeshCallback);
return;
}

Graphics.ExecuteCommandBuffer(cmdBuf);
}
D.assert(this._layers.Count == 0 || (this._layers.Count == 1 && this._layers[0] == this._currentLayer));
if (this._currentLayer != null) {
this._clearLayer(this._currentLayer);

116
Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shader.cs


using System;
using Unity.UIWidgets.painting;
using UnityEngine;
using UnityEngine.Rendering;

_stencilMat = new Material(stencilShader) {hideFlags = HideFlags.HideAndDontSave};
_filterMat = new Material(filterShader) {hideFlags = HideFlags.HideAndDontSave};
}
static readonly int _viewportId = Shader.PropertyToID("_viewport");
static readonly int _alphaId = Shader.PropertyToID("_alpha");
static readonly int _colorId = Shader.PropertyToID("_color");

c.alpha / 255f
);
}
static Vector4 _colorToVector4(Color c) {
return new Vector4(
c.red / 255f,

_getShaderPassAndProps(layer, paint, mesh.matrix, 1.0f, out var pass, out var props);
return PictureFlusher.CmdDraw.create(
mesh : mesh,
pass : pass,
material : mat,
properties : props
mesh: mesh,
pass: pass,
material: mat,
properties: props
);
}

props.SetVector(_viewportId, viewport);
return PictureFlusher.CmdDraw.create(
mesh : mesh,
pass : pass,
material : mat,
properties : props
mesh: mesh,
pass: pass,
material: mat,
properties: props
);
}

_getShaderPassAndProps(layer, paint, mesh.matrix, 1.0f, out var pass, out var props);
var ret = PictureFlusher.CmdDraw.create(
mesh : mesh.boundsMesh,
pass : pass,
material : mat,
properties : props
mesh: mesh.boundsMesh,
pass: pass,
material: mat,
properties: props
ObjectPool<uiMeshMesh>.release(mesh);
return ret;
}

_getShaderPassAndProps(layer, paint, mesh.matrix, alpha, out var pass, out var props);
return PictureFlusher.CmdDraw.create(
mesh : mesh,
pass : pass,
material : mat,
properties : props
mesh: mesh,
pass: pass,
material: mat,
properties: props
);
}

props.SetVector(_viewportId, viewport);
return PictureFlusher.CmdDraw.create(
mesh : mesh,
pass : pass,
material : mat,
properties : props
mesh: mesh,
pass: pass,
material: mat,
properties: props
);
}

props.SetVector(_viewportId, viewport);
return PictureFlusher.CmdDraw.create(
mesh : mesh,
pass : pass,
material : mat,
properties : props
mesh: mesh,
pass: pass,
material: mat,
properties: props
);
}

props.SetVector(_viewportId, viewport);
return PictureFlusher.CmdDraw.create(
mesh : mesh,
pass : pass,
material : mat,
properties : props
mesh: mesh,
pass: pass,
material: mat,
properties: props
);
}

props.SetVector(_viewportId, viewport);
return PictureFlusher.CmdDraw.create(
mesh : mesh,
pass : pass,
material : mat,
properties : props
mesh: mesh,
pass: pass,
material: mat,
properties: props
);
}

props.SetInt(_texModeId, image.texture is RenderTexture ? 1 : 0); // pre alpha if RT else post alpha
return PictureFlusher.CmdDraw.create(
mesh : mesh,
pass : pass,
material : mat,
properties : props,
image : image // keep a reference to avoid GC.
mesh: mesh,
pass: pass,
material: mat,
properties: props,
image: image // keep a reference to avoid GC.
);
}

props.SetInt(_texModeId, 1); // pre alpha
return PictureFlusher.CmdDraw.create(
mesh : mesh,
pass : pass,
material : mat,
properties : props,
layerId : renderLayer.rtID
mesh: mesh,
pass: pass,
material: mat,
properties: props,
layerId: renderLayer.rtID
);
}

}
var mat = _texMat.getMaterial(paint.blendMode, layer.ignoreClip);
var meshMatrix = mesh != null ? mesh.matrix : textMesh.matrix;
_getShaderPassAndProps(layer, paint, meshMatrix, 1.0f, out var pass, out var props);

return PictureFlusher.CmdDraw.create(
mesh : mesh,
textMesh : textMesh,
pass : pass,
material : mat,
properties : props
mesh: mesh,
textMesh: textMesh,
pass: pass,
material: mat,
properties: props
);
}

props.SetFloatArray(_mfKernelId, kernel);
return PictureFlusher.CmdDraw.create(
mesh : mesh,
pass : pass,
material : mat,
properties : props,
layerId : renderLayer.rtID
mesh: mesh,
pass: pass,
material: mat,
properties: props,
layerId: renderLayer.rtID
);
}
}

1
Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shader_utils.cs


using UnityEngine;
namespace Unity.UIWidgets.ui {
public class MaterialPropertyBlockWrapper : PoolObject {
public readonly MaterialPropertyBlock mpb;

22
Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_utils.cs


using UnityEngine;
namespace Unity.UIWidgets.ui {
static class BlurUtils {
static readonly Dictionary<int, float[]> _gaussianKernels
= new Dictionary<int, float[]>();

public static float[] get1DGaussianKernel(float gaussianSigma, int radius) {
var width = 2 * radius + 1;
D.assert(width <= 25);
int key = (int)(gaussianSigma * 1000000) + radius;
int key = (int) (gaussianSigma * 1000000) + radius;
float[] value;
if (_gaussianKernels.TryGetValue(key, out value)) {
return value;

return uiMeshMesh.create(matrix, vertices, _triangles, uv);
}
public static uiMeshMesh imageMesh(uiMatrix3? matrix, uiRect src, uiRect dst) {
var vertices = ObjectPool<uiList<Vector3>>.alloc();
vertices.SetCapacity(4);

uv.Add(new Vector2(uvx1, uvy1));
vertices.Add(new Vector2(dst.right, dst.top));
uv.Add(new Vector2(uvx1, uvy0));
var _triangles = ObjectPool<uiList<int>>.alloc();
_triangles.AddRange(_imageTriangles);

public static uiMeshMesh imageNineMesh(uiMatrix3? matrix, uiRect src, uiRect center, int srcWidth, int srcHeight, uiRect dst) {
public static uiMeshMesh imageNineMesh(uiMatrix3? matrix, uiRect src, uiRect center, int srcWidth,
int srcHeight, uiRect dst) {
float x0 = dst.left;
float x3 = dst.right;
float x1 = x0 + ((center.left - src.left) * srcWidth);

uv.Add(new Vector2(tx2, ty3));
vertices.Add(new Vector2(x3, y3));
uv.Add(new Vector2(tx3, ty3));
}
}
}
}

14
Runtime/ui/renderer/cmdbufferCanvas/rendering/render_cmd.cs


internal abstract class RenderCmd : PoolObject {
public abstract void release();
}
internal class CmdLayer : RenderCmd {
public RenderLayer layer;

ObjectPool<CmdLayer>.release(this);
}
}
internal class CmdDraw : RenderCmd {
public uiMeshMesh mesh;
public TextBlobMesh textMesh;

public static readonly int texId = Shader.PropertyToID("_tex");
public static readonly int matId = Shader.PropertyToID("_mat");
public override void clear() {
ObjectPool<uiMeshMesh>.release(this.mesh);
ObjectPool<TextBlobMesh>.release(this.textMesh);

newCmd.image = image;
newCmd.meshObj = meshObj;
newCmd.meshObjCreated = meshObjCreated;
public override void release() {
ObjectPool<CmdDraw>.release(this);
}

public CmdScissor() {
}
public override void clear() {
this.deviceScissor = null;
}

newCmd.deviceScissor = deviceScissor;
return newCmd;
}
public override void release() {
ObjectPool<CmdScissor>.release(this);
}

23
Runtime/ui/renderer/cmdbufferCanvas/rendering/render_layer.cs


namespace Unity.UIWidgets.ui {
public partial class PictureFlusher {
internal class RenderLayer : PoolObject {
public int rtID;
public int width;

this.layerBounds.width,
this.layerBounds.height);
}
public static RenderLayer create(int rtID = 0, int width = 0, int height = 0, FilterMode filterMode = FilterMode.Point,
public static RenderLayer create(int rtID = 0, int width = 0, int height = 0,
FilterMode filterMode = FilterMode.Point,
bool noMSAA = false, uiRect? layerBounds = null, uiPaint? layerPaint = null, bool ignoreClip = true) {
D.assert(layerBounds != null);
var newLayer = ObjectPool<RenderLayer>.alloc();

newLayer.currentState = State.create();
newLayer.states.Add(newLayer.currentState);
newLayer.clipStack = ClipStack.create();
this.draws.Add(CmdLayer.create(layer : layer));
this.draws.Add(CmdLayer.create(layer: layer));
}
public override void clear() {

foreach (var state in this.states) {
ObjectPool<State>.release(state);
}
this.states.Clear();
ObjectPool<ClipStack>.release(this.clipStack);
this._viewport = null;

internal class State : PoolObject {
uiMatrix3? _matrix;
float? _scale;
uiMatrix3? _invMatrix;

newState._matrix = matrix ?? _id;
newState._scale = scale;
newState._invMatrix = invMatrix;
return newState;
}

if (this._scale == null) {
this._scale = uiXformUtils.getScale(this._matrix.Value);
}
return this._invMatrix.Value;
}
}

125
Runtime/ui/renderer/common/base_canvas.cs


public void saveLayer(Rect rect, Paint paint) {
this._saveCount++;
this._recorder.addDrawCmd(uiDrawSaveLayer.create(
rect : uiRectHelper.fromRect(rect),
paint : uiPaint.fromPaint(paint)
rect: uiRectHelper.fromRect(rect),
paint: uiPaint.fromPaint(paint)
));
}

public void translate(float dx, float dy) {
this._recorder.addDrawCmd(uiDrawTranslate.create(
dx : dx,
dy : dy
dx: dx,
dy: dy
sx : sx,
sy : sy
sx: sx,
sy: sy
radians : radians,
offset : uiOffset.fromOffset(offset)
radians: radians,
offset: uiOffset.fromOffset(offset)
sx : sx,
sy : sy
sx: sx,
sy: sy
matrix : uiMatrix3.fromMatrix3(matrix)
matrix: uiMatrix3.fromMatrix3(matrix)
localMatrix.kMSkewY, localMatrix.kMScaleY, localMatrix.kMTransY,
localMatrix.kMPersp0, localMatrix.kMPersp1, localMatrix.kMPersp2);
localMatrix.kMSkewY, localMatrix.kMScaleY, localMatrix.kMTransY,
localMatrix.kMPersp0, localMatrix.kMPersp1, localMatrix.kMPersp2);
return this._totalMatrix;
}

public void setMatrix(Matrix3 matrix) {
this._recorder.addDrawCmd(uiDrawSetMatrix.create(
matrix : uiMatrix3.fromMatrix3(matrix)
matrix: uiMatrix3.fromMatrix3(matrix)
));
}

public void clipRect(Rect rect) {
this._recorder.addDrawCmd(uiDrawClipRect.create(
rect : uiRectHelper.fromRect(rect)
rect: uiRectHelper.fromRect(rect)
rrect : rrect
rrect: rrect
path : uiPath.fromPath(path)
path: uiPath.fromPath(path)
));
}

path.lineTo(to.dx, to.dy);
this._recorder.addDrawCmd(uiDrawPath.create(
path : path,
paint : uiPaint.fromPaint(paint)
path: path,
paint: uiPaint.fromPaint(paint)
));
}

path.addRect(rect);
this._recorder.addDrawCmd(uiDrawPath.create(
path : path,
paint : uiPaint.fromPaint(paint)
path: path,
paint: uiPaint.fromPaint(paint)
));
}

this._recorder.addDrawCmd(uiDrawPath.create(
path : path,
paint : uiPaint.fromPaint(paint)
path: path,
paint: uiPaint.fromPaint(paint)
));
}

path.winding(PathWinding.clockwise);
this._recorder.addDrawCmd(uiDrawPath.create(
path : path,
paint : uiPaint.fromPaint(paint)
path: path,
paint: uiPaint.fromPaint(paint)
));
}

path.addEllipse(rect.left + w, rect.top + h, w, h);
this._recorder.addDrawCmd(uiDrawPath.create(
path : path,
paint : uiPaint.fromPaint(paint)
path: path,
paint: uiPaint.fromPaint(paint)
));
}

this._recorder.addDrawCmd(uiDrawPath.create(
path : path,
paint : uiPaint.fromPaint(paint)
path: path,
paint: uiPaint.fromPaint(paint)
));
}

if (useCenter) {
var center = rect.center;
path.moveTo(center.dx, center.dy);
path.moveTo(center.dx, center.dy);
}
bool forceMoveTo = !useCenter;

forceMoveTo = false;
sweepAngle += Mathf.PI * 2;
}
while (sweepAngle >= Mathf.PI * 2) {
path.arcTo(rect, startAngle, Mathf.PI, forceMoveTo);
startAngle += Mathf.PI;

}
this._recorder.addDrawCmd(uiDrawPath.create(
path : path,
paint : uiPaint.fromPaint(paint)
path: path,
paint: uiPaint.fromPaint(paint)
path : uiPath.fromPath(path),
paint : uiPaint.fromPaint(paint)
path: uiPath.fromPath(path),
paint: uiPaint.fromPaint(paint)
image : image,
offset : uiOffset.fromOffset(offset),
paint : uiPaint.fromPaint(paint)
image: image,
offset: uiOffset.fromOffset(offset),
paint: uiPaint.fromPaint(paint)
image : image,
src : null,
dst : uiRectHelper.fromRect(dst),
paint : uiPaint.fromPaint(paint)
image: image,
src: null,
dst: uiRectHelper.fromRect(dst),
paint: uiPaint.fromPaint(paint)
image : image,
src : uiRectHelper.fromRect(src),
dst : uiRectHelper.fromRect(dst),
paint : uiPaint.fromPaint(paint)
image: image,
src: uiRectHelper.fromRect(src),
dst: uiRectHelper.fromRect(dst),
paint: uiPaint.fromPaint(paint)
image : image,
src : null,
center : uiRectHelper.fromRect(center),
dst : uiRectHelper.fromRect(dst),
paint : uiPaint.fromPaint(paint)
image: image,
src: null,
center: uiRectHelper.fromRect(center),
dst: uiRectHelper.fromRect(dst),
paint: uiPaint.fromPaint(paint)
image : image,
src : uiRectHelper.fromRect(src),
center : uiRectHelper.fromRect(center),
dst : uiRectHelper.fromRect(dst),
paint : uiPaint.fromPaint(paint)
image: image,
src: uiRectHelper.fromRect(src),
center: uiRectHelper.fromRect(center),
dst: uiRectHelper.fromRect(dst),
paint: uiPaint.fromPaint(paint)
picture : picture
picture: picture
textBlob : textBlob,
offset : uiOffset.fromOffset(offset),
paint : uiPaint.fromPaint(paint)
textBlob: textBlob,
offset: uiOffset.fromOffset(offset),
paint: uiPaint.fromPaint(paint)
public void drawParagraph(Paragraph paragraph, Offset offset) {
D.assert(paragraph != null);
D.assert(PaintingUtils._offsetIsValid(offset));

14
Runtime/ui/renderer/common/color.cs


using UnityEngine;
namespace Unity.UIWidgets.ui {
public int alpha {
get { return (int) ((0xff000000 & this.value) >> 24); }
}

public static uiColor fromColor(Color color) {
return new uiColor(color.value);
}
public static uiColor fromARGB(int a, int r, int g, int b) {
return new uiColor(
(((a & 0xff) << 24) |

((g & 0xff) << 8) |
((b & 0xff) << 0)) & 0xFFFFFFFF);
}
public uiColor withAlpha(int a) {
return fromARGB(a, this.red, this.green, this.blue);
}

}
static float _linearizeColorComponent(float component) {
if (component <= 0.03928f) {
return component / 12.92f;

81
Runtime/ui/renderer/common/draw_cmd.cs


using System.Runtime.CompilerServices;
namespace Unity.UIWidgets.ui {
public abstract class uiDrawCmd : PoolObject {
public abstract void release();

drawSaveLayer.paint = paint;
return drawSaveLayer;
}
public override void release() {
ObjectPool<uiDrawSaveLayer>.release(this);
}

var drawRestore = ObjectPool<uiDrawRestore>.alloc();
return drawRestore;
}
public override void release() {
ObjectPool<uiDrawRestore>.release(this);
}

drawTranslate.dy = dy;
return drawTranslate;
}
public float dx;
public float dy;
}

}
public static uiDrawScale create(float sx, float? sy) {

return drawScale;
}
public float sx;
public float? sy;
}

}
public static uiDrawRotate create(float radians, uiOffset? offset) {

return drawRotate;
}
public float radians;
public uiOffset? offset;
}

}
public static uiDrawSkew create(float sx, float sy) {

return drawSkew;
}
public float sx;
public float sy;
}

}
public static uiDrawConcat create(uiMatrix3? matrix) {

}
}
public static uiDrawResetMatrix create() {

public override void release() {
ObjectPool<uiDrawResetMatrix>.release(this);
}

public uiDrawSetMatrix() {
}
public static uiDrawSetMatrix create(uiMatrix3? matrix) {

}
}
public static uiDrawClipRect create(uiRect? rect) {

}
}
public static uiDrawClipRRect create(RRect rrect) {

}
}
public static uiDrawClipPath create(uiPath path) {

}
public override void release() {
ObjectPool<uiDrawClipPath>.release(this);
}

public class uiDrawPath : uiDrawCmd {
public uiDrawPath() {
}
public static uiDrawPath create(uiPath path, uiPaint paint) {

return drawPath;
}
public override void release() {
ObjectPool<uiDrawPath>.release(this);
}

public class uiDrawImage : uiDrawCmd {
public uiDrawImage() {
}
public static uiDrawImage create(Image image, uiOffset? offset, uiPaint paint) {

drawImage.paint = paint;
return drawImage;
}
public override void release() {
ObjectPool<uiDrawImage>.release(this);
}

this.offset = null;
}
public Image image;
public uiOffset? offset;
public uiPaint paint;

public uiDrawImageRect() {
}
public static uiDrawImageRect create(Image image, uiRect? src, uiRect? dst, uiPaint paint) {

drawImageRect.paint = paint;
return drawImageRect;
}
public override void release() {
ObjectPool<uiDrawImageRect>.release(this);
}

public class uiDrawImageNine : uiDrawCmd {
public uiDrawImageNine() {
}
public static uiDrawImageNine create(Image image, uiRect? src, uiRect? center, uiRect? dst, uiPaint paint) {

drawImageNine.paint = paint;
return drawImageNine;
}
public override void release() {
ObjectPool<uiDrawImageNine>.release(this);
}

public class uiDrawPicture : uiDrawCmd {
public uiDrawPicture() {
}
public static uiDrawPicture create(Picture picture) {

}
public override void release() {
ObjectPool<uiDrawPicture>.release(this);
}

public class uiDrawTextBlob : uiDrawCmd {
public uiDrawTextBlob() {
}
public static uiDrawTextBlob create(TextBlob textBlob, uiOffset? offset, uiPaint paint) {

drawTextBlob.paint = paint;
return drawTextBlob;
}
public override void release() {
ObjectPool<uiDrawTextBlob>.release(this);
}

14
Runtime/ui/renderer/common/geometry/matrix/ui_matrix.cs


using System;
using Unity.UIWidgets.foundation;
using UnityEngine;

(kUnknown_Mask | kOnlyPerspectiveValid_Mask));
this.fTypeMask = mask;
}
void _orTypeMask(int mask) {
D.assert((mask & kORableMasks) == mask);
this.fTypeMask |= mask;

this._setConcat(this, other);
}
}
public void preScale(float sx, float sy, float px, float py) {
if (1 == sx && 1 == sy) {
return;

this.kMPersp1 *= sy;
if (this.kMScaleX == 1 && this.kMScaleY == 1 && (this.fTypeMask &
(int) (TypeMask.kPerspective_Mask | TypeMask.kAffine_Mask)) == 0) {
(int) (TypeMask.kPerspective_Mask | TypeMask.kAffine_Mask)
) == 0) {
this._clearTypeMask((int) TypeMask.kScale_Mask);
}
else {

public void preRotate(float radians, float px, float py) {
var m = new uiMatrix3();
m.setRotate(radians, px, py);

m.setRotate(radians);
this.preConcat(m);
}
public void setScale(float sx, float sy, float px, float py) {
if (1 == sx && 1 == sy) {
this.reset();

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


namespace Unity.UIWidgets.ui {
public partial struct uiMatrix3 {
public void mapPoints(uiOffset[] dst, uiOffset[] src) {
D.assert(dst != null && src != null && dst.Length == src.Length);
this._getMapPtsProc()(this, dst, src, src.Length);

11
Runtime/ui/renderer/common/geometry/mesh_mesh.cs


};
public uiMeshMesh boundsMesh {
get {
return create(this.bounds);
}
get { return create(this.bounds); }
}
public uiMeshMesh() {

return newMesh;
}
public static uiMeshMesh create(uiMatrix3? matrix, uiList<Vector3> vertices, uiList<int> triangles, uiList<Vector2> uv = null,
public static uiMeshMesh create(uiMatrix3? matrix, uiList<Vector3> vertices, uiList<int> triangles,
uiList<Vector2> uv = null,
uiRect? rawBounds = null) {
D.assert(vertices != null);
D.assert(vertices.Count >= 0);

uiMeshMesh newMesh = ObjectPool<uiMeshMesh>.alloc();
newMesh.matrix = matrix;
newMesh.vertices = vertices;

var vertices = ObjectPool<uiList<Vector3>>.alloc();
vertices.SetCapacity(this.vertices.Count);
vertices.AddRange(this.vertices.data);
var triangles = ObjectPool<uiList<int>>.alloc();
triangles.SetCapacity(this.triangles.Count);
triangles.AddRange(this.triangles.data);

7
Runtime/ui/renderer/common/geometry/offset.cs


if (offset == null) {
return null;
}
}
}

72
Runtime/ui/renderer/common/geometry/path/path.cs


using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Unity.UIWidgets.foundation;
using UnityEngine;

float _commandy;
float _minX, _minY;
float _maxX, _maxY;
uiPathCache _cache;
public uint pathKey = 0;

ObjectPool<uiPathCache>.release(this._cache);
this._cache = null;
this._commands = null;
}
void _reset() {

internal uiPathCache flatten(float scale) {
scale = Mathf.Round(scale * 2.0f) / 2.0f; // round to 0.5f
var _cache = uiPathCache.create(scale);
var i = 0;

if (x < this._minX) {
this._minX = x;
}
if (y < this._minY) {
this._minY = y;
}

}
if (y > this._maxY) {
this._maxY = y;
}

this._commandx = x;
this._commandy = y;
ObjectPool<uiPathCache>.release(this._cache);
this._cache = null;
}

this._commandx = x;
this._commandy = y;
ObjectPool<uiPathCache>.release(this._cache);
this._cache = null;
}

this._expandBounds(x1, y1);
this._expandBounds(x2, y2);
this._expandBounds(x3, y3);
this._commands.Add((float) uiPathCommand.bezierTo);
this._commands.Add(x1);
this._commands.Add(y1);

this._commands.Add(y3);
ObjectPool<uiPathCache>.release(this._cache);
this._cache = null;
}

this._commands.Add(winding);
ObjectPool<uiPathCache>.release(this._cache);
this._cache = null;
}

this._appendLineTo(rect.right, rect.top);
this._appendClose();
}
public void addRect(Rect rect) {
this._appendMoveTo(rect.left, rect.top);
this._appendLineTo(rect.left, rect.bottom);

x, y + ryTL * (1 - _KAPPA90), x, y + ryTL);
this._appendClose();
}
public void addEllipse(float cx, float cy, float rx, float ry) {
this._appendMoveTo(cx - rx, cy);
this._appendBezierTo(cx - rx, cy + ry * _KAPPA90,

cx - rx, cy - ry * _KAPPA90, cx - rx, cy);
this._appendClose();
}
public void arcTo(Rect rect, float startAngle, float sweepAngle, bool forceMoveTo = true) {
var mat = Matrix3.makeScale(rect.width / 2, rect.height / 2);
var center = rect.center;

sweepAngle >= 0 ? PathWinding.clockwise : PathWinding.counterClockwise, forceMoveTo, mat);
}
void _addArcCommands(
float cx, float cy, float r, float a0, float a1,
PathWinding dir, bool forceMoveTo, Matrix3 transform = null) {

if (Mathf.Abs(da) >= Mathf.PI * 2) {
da = Mathf.PI * 2;
} else {
}
else {
} else {
}
else {
} else {
}
else {
// Split arc into max 90 degree segments.
int ndivs = Mathf.Max(1, Mathf.Min((int) (Mathf.Abs(da) / (Mathf.PI * 0.5f) + 0.5f), 5));
float hda = (da / ndivs) / 2.0f;

if (move == PathCommand.moveTo) {
this._appendMoveTo(x1, y1);
} else {
}
else {
} else {
}
else {
float c1x = px + ptanx;
float c1y = py + ptany;
float c2x = x - tanx;

this._appendBezierTo(c1x, c1y, c2x, c2y, x1, y1);
}
px = x;
py = y;
ptanx = tanx;

case uiPathCommand.lineTo: {
float x = _commands[i + 1];
float y = _commands[i + 2];
uipath._appendLineTo(x, y);
}
i += 3;

float c2y = _commands[i + 4];
float x1 = _commands[i + 5];
float y1 = _commands[i + 6];
uipath._appendBezierTo(c1x, c1y, c2x, c2y, x1, y1);
}
i += 7;

break;
}
}
return uipath;
}
}

108
Runtime/ui/renderer/common/geometry/path/path_cache.cs


using UnityEngine;
namespace Unity.UIWidgets.ui {
class uiPathCache : PoolObject {
float _distTol;
float _tessTol;

float _scale;
//mesh cache
uiMeshMesh _fillMesh;
bool _fillConvex;

newPathCache._scale = scale;
return newPathCache;
}
public bool canReuse(float scale) {
if (this._scale != scale) {
return false;

this._points.Clear();
ObjectPool<uiMeshMesh>.release(this._fillMesh);
this._fillMesh = null;
ObjectPool<uiMeshMesh>.release(this._strokeMesh);
this._strokeMesh = null;
}

public void addPath() {
this._paths.Add(uiPathPath.create(
first : this._points.Count,
winding : uiPathWinding.counterClockwise
first: this._points.Count,
winding: uiPathWinding.counterClockwise
this._addPoint(uiPathPoint.create(x : x, y : y, flags : flags));
this._addPoint(uiPathPoint.create(x: x, y: y, flags: flags));
}
void _addPoint(uiPathPoint point) {

}
var path = this._paths[this._paths.Count - 1];
if (path.count > 0) {
var pt = this._points[this._points.Count - 1];

var point = points[i];
if (i == points.Count - 1) {
this._addPoint(uiPathPoint.create(
x : point.x + x1,
y : point.y + y1,
flags : flags
x: point.x + x1,
y: point.y + y1,
flags: flags
} else {
}
else {
x : point.x + x1,
y : point.y + y1
x: point.x + x1,
y: point.y + y1
));
}
}

return;
}
var path = this._paths[this._paths.Count - 1];
var path = this._paths[this._paths.Count - 1];
path.winding = winding;
this._paths[this._paths.Count - 1] = path;
}

var paths = this._paths;
var paths = this._paths;
var path = paths[j];
var path = paths[j];
if (path.count <= 1) {
continue;
}

var p0 = points[ip0];
var p1 = points[ip1];
var p0 = points[ip0];
var p1 = points[ip1];
if (uiPathUtils.ptEquals(p0.x, p0.y, p1.x, p1.y, this._distTol)) {
path.count--;
path.closed = true;

var points = this._points;
var paths = this._paths;
for (var j = 0; j < paths.Count; j++) {
var path = paths[j];
var path = paths[j];
if (path.count <= 2) {
continue;
}

for (var i = 0; i < path.count; i++) {
var p0 = points[ip0];
var p1 = points[ip1];
var p0 = points[ip0];
var p1 = points[ip1];
p0.dx = p1.x - p0.x; // no need to normalize
p0.dy = p1.y - p0.y;
points[ip0] = p0;

ip0 = path.first + path.count - 1;
ip1 = path.first;
for (var i = 0; i < path.count; i++) {
var p0 = points[ip0];
var p1 = points[ip1];
var p0 = points[ip0];
var p1 = points[ip1];
float cross = p1.dx * p0.dy - p0.dx * p1.dy;
if (cross < 0.0f) {

var cvertices = 0;
for (var i = 0; i < paths.Count; i++) {
var path = paths[i];
var path = paths[i];
if (path.count <= 2) {
continue;
}

var _vertices = ObjectPool<uiList<Vector3>>.alloc();
_vertices.SetCapacity(cvertices);
for (var i = 0; i < paths.Count; i++) {
var path = paths[i];
var path = paths[i];
if (path.count <= 2) {
continue;
}

var p = points[path.first + j];
var p = points[path.first + j];
_vertices.Add(new Vector2(p.x, p.y));
}

convex = this._fillConvex;
return this._fillMesh;
}
var path = paths[i];
var path = paths[i];
if (path.count <= 2) {
continue;
}

var indices = ObjectPool<uiList<int>>.alloc();
indices.SetCapacity(cindices);
for (var i = 0; i < paths.Count; i++) {
var path = paths[i];
var path = paths[i];
if (path.count <= 2) {
continue;
}

var mesh = uiMeshMesh.create(null, vertices, indices);
this._fillMesh = mesh;
this._fillConvex = false;
this._fillConvex = false;
var path = paths[i];
var path = paths[i];
if (path.count <= 2) {
continue;
}

var points = this._points;
var paths = this._paths;
for (var i = 0; i < paths.Count; i++) {
var path = paths[i];
var path = paths[i];
if (path.count <= 1) {
continue;
}

for (var j = 0; j < path.count; j++) {
var p0 = points[ip0];
var p1 = points[ip1];
var p0 = points[ip0];
var p1 = points[ip1];
p0.dx = p1.x - p0.x;
p0.dy = p1.y - p0.y;
p0.len = uiPathUtils.normalize(ref p0.dx, ref p0.dy);

ip0 = path.first + path.count - 1;
ip1 = path.first;
for (var j = 0; j < path.count; j++) {
var p0 = points[ip0];
var p1 = points[ip1];
var p0 = points[ip0];
var p1 = points[ip1];
float dlx0 = p0.dy;
float dly0 = -p0.dx;
float dlx1 = p1.dy;

p1.flags |= uiPointFlags.bevel;
}
}
points[ip1] = p1;
points[ip1] = p1;
ip0 = ip1++;
}

var cvertices = 0;
for (var i = 0; i < paths.Count; i++) {
var path = paths[i];
var path = paths[i];
if (path.count <= 1) {
continue;
}

var _vertices = ObjectPool<uiList<Vector3>>.alloc();
_vertices.SetCapacity(cvertices);
for (var i = 0; i < paths.Count; i++) {
var path = paths[i];
var path = paths[i];
if (path.count <= 1) {
continue;
}

e = path.count - 1;
}
var p0 = points[ip0];
var p1 = points[ip1];
var p0 = points[ip0];
var p1 = points[ip1];
if (!path.closed) {
if (lineCap == StrokeCap.butt) {

}
for (var j = s; j < e; j++) {
p0 = points[ip0];
p1 = points[ip1];
p0 = points[ip0];
p1 = points[ip1];
if ((p1.flags & (uiPointFlags.bevel | uiPointFlags.innerBevel)) != 0) {
if (lineJoin == StrokeJoin.round) {

}
if (!path.closed) {
p0 = points[ip0];
p1 = points[ip1];
p0 = points[ip0];
p1 = points[ip1];
if (lineCap == StrokeCap.butt) {
_vertices.buttCapEnd(p1, p0.dx, p0.dy, w, 0.0f);
}

this._miterLimit == miterLimit) {
return this._strokeMesh;
}
var path = paths[i];
var path = paths[i];
if (path.count <= 1) {
continue;
}

var indices = ObjectPool<uiList<int>>.alloc();
indices.SetCapacity(cindices);
for (var i = 0; i < paths.Count; i++) {
var path = paths[i];
var path = paths[i];
if (path.count <= 1) {
continue;
}

this._strokeWidth = strokeWidth;
this._lineCap = lineCap;
this._lineJoin = lineJoin;
this._miterLimit = miterLimit;
this._miterLimit = miterLimit;
return this._strokeMesh;
}
}

8
Runtime/ui/renderer/common/geometry/path/path_utils.cs


using UnityEngine;
namespace Unity.UIWidgets.ui {
enum uiPathCommand {
moveTo,
lineTo,

newPath.nstroke = nstroke;
newPath.winding = winding;
newPath.convex = convex;
static class uiPathUtils {
public static bool ptEquals(float x1, float y1, float x2, float y2, float tol) {
float dx = x2 - x1;

5
Runtime/ui/renderer/common/geometry/path/tessellation_generator.cs


}
public uiTessellationKey() {
}
public bool Equals(uiTessellationKey other) {

public static int tessellationCount {
get { return _tessellations.Count; }
}
public static void tickNextFrame() {
_frameCount++;

uiTessellationInfo.touch();
return uiTessellationInfo.points;
}
var points = _tessellateBezier(x1, y1, x2, y2, x3, y3, x4, y4, tessTol);
_tessellations[key] = uiTessellationInfo.create(key, points);

61
Runtime/ui/renderer/common/geometry/rect.cs


using UnityEngine;
namespace Unity.UIWidgets.ui {
public uiRect(float left, float top, float right, float bottom) {
this.left = left;
this.top = top;

public float width {
get { return this.right - this.left; }
}

}
public uiOffset topLeft {
get { return new uiOffset(this.left, this.top); }
}

public uiOffset bottomRight {
get { return new uiOffset(this.right, this.bottom); }
}
public uiRect intersect(uiRect other) {
return uiRectHelper.fromLTRB(
Mathf.Max(this.left, other.left),

public static uiRect fromRect(Rect rect) {
return new uiRect(rect.left, rect.top, rect.right, rect.bottom);
}
if (a == null && b == null) return true;
if (a == null || b == null) return false;
if (a == null && b == null) {
return true;
}
if (a == null || b == null) {
return false;
}
return aval.left == bval.left && aval.right == bval.right && aval.top == bval.top && aval.bottom == bval.bottom;
return aval.left == bval.left && aval.right == bval.right && aval.top == bval.top &&
aval.bottom == bval.bottom;
public static uiRect scale(uiRect a, float scaleX, float? scaleY = null) {
scaleY = scaleY ?? scaleX;
return fromLTRB(

public static uiRect inflate(uiRect a, float delta) {
return fromLTRB(a.left - delta, a.top - delta, a.right + delta, a.bottom + delta);
}

}
public static uiRect intersect(uiRect a, uiRect other) {
return fromLTRB(
Mathf.Max(a.left, other.left),

);
}
public static uiRect round(uiRect a) {
return fromLTRB(
Mathf.Round(a.left), Mathf.Round(a.top),

public static uiRect roundOut(uiRect a, float devicePixelRatio) {
return fromLTRB(
Mathf.Floor(a.left * devicePixelRatio) / devicePixelRatio,
Mathf.Floor(a.left * devicePixelRatio) / devicePixelRatio,
Mathf.Ceil(a.right * devicePixelRatio) / devicePixelRatio,
Mathf.Ceil(a.right * devicePixelRatio) / devicePixelRatio,
Mathf.Ceil(a.bottom * devicePixelRatio) / devicePixelRatio);
}

Mathf.Floor(a.right), Mathf.Floor(a.bottom));
}
public static uiRect normalize(uiRect a) {
if (a.left <= a.right && a.top <= a.bottom) {
return a;

Mathf.Max(a.top, a.bottom)
);
}
public static uiOffset[] toQuad(uiRect a) {
uiOffset[] dst = new uiOffset[4];
dst[0] = new uiOffset(a.left, a.top);

return dst;
}
public static bool overlaps(uiRect a, uiRect other) {
if (a.right <= other.left || other.right <= a.left) {
return false;

return true;
}
public static UnityEngine.Rect toRect(uiRect rect) {
return new UnityEngine.Rect(rect.left, rect.top, rect.width, rect.height);
}

45
Runtime/ui/renderer/common/paint.cs


public readonly BlurStyle style;
public readonly float sigma;
}
public struct uiColorFilter {
uiColorFilter(uiColor color, BlendMode blendMode) {
this.color = color;

public readonly uiColor color;
public readonly BlendMode blendMode;
}
}
public static class uiImageFilterHelper {

this.sigmaX = sigmaX;
this.sigmaY = sigmaY;
}
public readonly float sigmaX;
public readonly float sigmaY;
}

public readonly uiMatrix3 transform;
public readonly FilterMode filterMode;
}
public uiColor color;
public BlendMode blendMode;
public PaintingStyle style;

public bool invertColors;
public uiPaint(
uiColor? color = null,
BlendMode blendMode = BlendMode.srcOver,
uiColor? color = null,
BlendMode blendMode = BlendMode.srcOver,
PaintingStyle style = PaintingStyle.fill,
float strokeWidth = 0f,
StrokeCap strokeCap = StrokeCap.butt,

uiImageFilter backdrop = null,
PaintShader shader = null,
bool invertColors = false
) {
) {
this.color = color ?? _kColorDefault;
this.blendMode = blendMode;
this.style = style;

public static uiPaint shapeOnly(uiPaint paint) {
return new uiPaint(
style : paint.style,
strokeWidth : paint.strokeWidth,
strokeCap : paint.strokeCap,
strokeJoin : paint.strokeJoin,
strokeMiterLimit : paint.strokeMiterLimit
style: paint.style,
strokeWidth: paint.strokeWidth,
strokeCap: paint.strokeCap,
strokeJoin: paint.strokeJoin,
strokeMiterLimit: paint.strokeMiterLimit
} else if (paint.backdrop is _MatrixImageFilter) {
}
else if (paint.backdrop is _MatrixImageFilter) {
color : paint.color == null ? (uiColor?)null : uiColor.fromColor(paint.color),
color: paint.color == null ? (uiColor?) null : uiColor.fromColor(paint.color),
blendMode: paint.blendMode,
style: paint.style,
strokeWidth: paint.strokeWidth,

filterMode: paint.filterMode,
colorFilter: paint.colorFilter == null ? (uiColorFilter?) null : uiColorFilter.mode(uiColor.fromColor(paint.colorFilter.color), paint.colorFilter.blendMode),
maskFilter: paint.maskFilter == null ? (uiMaskFilter?) null : uiMaskFilter.blur(paint.maskFilter.style, paint.maskFilter.sigma),
colorFilter: paint.colorFilter == null
? (uiColorFilter?) null
: uiColorFilter.mode(uiColor.fromColor(paint.colorFilter.color), paint.colorFilter.blendMode),
maskFilter: paint.maskFilter == null
? (uiMaskFilter?) null
: uiMaskFilter.blur(paint.maskFilter.style, paint.maskFilter.sigma),
);
);
}
}
}

41
Runtime/ui/renderer/common/picture.cs


using System.Collections.Generic;
using Unity.UIWidgets.foundation;
public static uiPicture create(List<uiDrawCmd> drawCmds, uiRect paintBounds) {
var picture = ObjectPool<uiPicture>.alloc();
picture.drawCmds = drawCmds;

foreach (var drawCmd in this._drawCmds) {
drawCmd.release();
}
this._drawCmds.Clear();
this._states.Clear();
this._states.Add(new uiCanvasState {

throw new Exception("unmatched save/restore commands");
}
var state = this._getState();
var state = this._getState();
return uiPicture.create(this._drawCmds, state.paintBounds);
}

if (!stateToRestore.saveLayer) {
state.paintBounds = stateToRestore.paintBounds;
} else {
}
else {
this._setState(state);
break;
}

state.xform = new uiMatrix3(state.xform);
if (cmd.offset == null) {
state.xform.preRotate(cmd.radians);
} else {
}
else {
this._setState(state);
break;
}

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

paint.strokeCap,
paint.strokeJoin,
paint.strokeMiterLimit);
} else {
}
else {
ObjectPool<uiMeshMesh>.release(mesh);
break;
}

var scale = uiXformUtils.getScale(state.xform);
var rect = uiRectHelper.fromRect(cmd.textBlob.boundsInText).shift(cmd.offset.Value);
rect = state.xform.mapRect(rect);
} else {
}
else {
break;
}
default:

if (state.paintBounds.isEmpty) {
state.paintBounds = paintBounds.Value;
} else {
}
else {
this._setState(state);
}

public uiRect paintBounds;
public uiCanvasState copy() {
return new uiCanvasState{
return new uiCanvasState {
xform = this.xform,
scissor = this.scissor,
saveLayer = false,

4
Runtime/ui/renderer/common/utils.cs


if (matrix.getSkewY() == 0) {
return matrix.getScaleX();
}
return Mathf.Sqrt(x * x + y * y);
}

2
Runtime/ui/renderer/compositeCanvas/compositing.cs


return layer;
}
public void addRetained(Layer layer) {
if (this._currentLayer == null) {
return;

5
Runtime/ui/renderer/compositeCanvas/flow/backdrop_filter_layer.cs


try {
this.paintChildren(context);
} finally {
}
finally {
}
}

3
Runtime/ui/renderer/compositeCanvas/flow/clip_path_layer.cs


try {
this.paintChildren(context);
} finally {
}
finally {
canvas.restore();
}
}

7
Runtime/ui/renderer/compositeCanvas/flow/clip_rect_layer.cs


this.paintBounds = childPaintBounds;
}
}
var canvas = context.canvas;
canvas.save();

this.paintChildren(context);
} finally {
}
finally {
canvas.restore();
}
}

5
Runtime/ui/renderer/compositeCanvas/flow/clip_rrect_layer.cs


public override void paint(PaintContext context) {
D.assert(this.needsPainting);
var canvas = context.canvas;
canvas.save();

this.paintChildren(context);
} finally {
}
finally {
canvas.restore();
}
}

5
Runtime/ui/renderer/compositeCanvas/flow/container_layer.cs


if (childPaintBounds == null || childPaintBounds.isEmpty) {
childPaintBounds = layer.paintBounds;
} else {
}
else {
childPaintBounds = childPaintBounds.expandToInclude(layer.paintBounds);
}
}

D.assert(this.needsPainting);
foreach (var layer in this._layers) {
if (layer.needsPainting) {
layer.paint(context);

3
Runtime/ui/renderer/compositeCanvas/flow/instrumentation.cs


}
var pb = new ParagraphBuilder(new ParagraphStyle { });
pb.addText("Current Frame Cost: " + costFrames[curFrame] * 1000 + "ms" + " ; Max(in last 120 frames): " + this.maxDelta() * 1000 + "ms");
pb.addText("Current Frame Cost: " + costFrames[curFrame] * 1000 + "ms" +
" ; Max(in last 120 frames): " + this.maxDelta() * 1000 + "ms");
var paragraph = pb.build();
paragraph.layout(new ParagraphConstraints(width: 800));

2
Runtime/ui/renderer/compositeCanvas/flow/layer_tree.cs


get { return this._devicePixelRatio; }
set { this._devicePixelRatio = value; }
}
int _antiAliasing;
public int antiAliasing {

21
Runtime/ui/renderer/compositeCanvas/flow/opacity_layer.cs


public Offset offset {
set { this._offset = value; }
}
int _alpha;
public int alpha {

public override void preroll(PrerollContext context, Matrix3 matrix) {
var childMatrix = new Matrix3(matrix);
childMatrix.preTranslate(this._offset.dx, this._offset.dy); // TOOD: pre or post? https://github.com/flutter/engine/pull/7945
childMatrix.preTranslate(this._offset.dx,
this._offset.dy); // TOOD: pre or post? https://github.com/flutter/engine/pull/7945
var saveLayerBounds = this.paintBounds.shift(-this._offset).roundOut();
var saveLayerBounds = this.paintBounds.shift(-this._offset).roundOut();
try {
this.paintChildren(context);
}

4
Runtime/ui/renderer/compositeCanvas/flow/physical_shape_layer.cs


Rect bounds = path.getBounds();
float shadow_x = (bounds.left + bounds.right) / 2f;
float shadow_y = bounds.top - 600.0f;
uiColor inAmbient = uicolor.withAlpha((int) (kAmbientAlpha * uicolor.alpha));
uiColor inSpot = uicolor.withAlpha((int) (kSpotAlpha * uicolor.alpha));
uiColor? ambientColor = null;

15
Runtime/ui/renderer/compositeCanvas/flow/picture_layer.cs


public override void preroll(PrerollContext context, Matrix3 matrix) {
if (context.rasterCache != null) {
Matrix3 ctm = new Matrix3(matrix);
ctm.preTranslate(this._offset.dx, this._offset.dy); // TOOD: pre or post? https://github.com/flutter/engine/pull/7945
ctm.preTranslate(this._offset.dx,
this._offset.dy); // TOOD: pre or post? https://github.com/flutter/engine/pull/7945
this._picture, ctm, context.devicePixelRatio, context.antiAliasing, this._isComplex, this._willChange);
} else {
this._picture, ctm, context.devicePixelRatio, context.antiAliasing, this._isComplex,
this._willChange);
}
else {
this._rasterCacheResult = null;
}

try {
if (this._rasterCacheResult != null) {
this._rasterCacheResult.draw(canvas);
} else {
}
else {
} finally {
}
finally {
canvas.restore();
}
}

13
Runtime/ui/renderer/compositeCanvas/flow/raster_cache.cs


var y = this.matrix[5] * devicePixelRatio;
this.matrix[2] = (x - (int) x) / devicePixelRatio; // x
this.matrix[5] = (y - (int) y) / devicePixelRatio; // y
this.matrix[5] = 0.0f;
this.matrix[5] = 0.0f;
this.devicePixelRatio = devicePixelRatio;
this.antiAliasing = antiAliasing;
}

readonly Dictionary<_RasterCacheKey, _RasterCacheEntry> _cache;
MeshPool _meshPool;
Picture picture, Matrix3 transform, float devicePixelRatio, int antiAliasing, bool isComplex, bool willChange) {
Picture picture, Matrix3 transform, float devicePixelRatio, int antiAliasing, bool isComplex,
bool willChange) {
if (this.threshold == 0) {
return null;
}

if (entry.image == null) {
D.assert(this._meshPool != null);
entry.image = this._rasterizePicture(picture, transform, devicePixelRatio, antiAliasing, this._meshPool);
entry.image =
this._rasterizePicture(picture, transform, devicePixelRatio, antiAliasing, this._meshPool);
}
return entry.image;

5
Runtime/ui/renderer/compositeCanvas/flow/texture_layer.cs


namespace Unity.UIWidgets.flow {
public class TextureLayer : Layer {
Offset _offset = Offset.zero;
public Offset offset {

if (this._texture == null) {
return;
}
}
var image = new Image(this._texture, noDispose: true);

}
}
}

8
Runtime/ui/renderer/compositeCanvas/flow/transform_layer.cs


Matrix3 inverseTransform = Matrix3.I();
if (this._transform.invert(inverseTransform)) {
context.cullRect = inverseTransform.mapRect(context.cullRect);
} else {
}
else {
context.cullRect = Rect.largest;
}

try {
canvas.concat(this._transform);
this.paintChildren(context);
} finally {
}
finally {
}
}
正在加载...
取消
保存