浏览代码

more object => PoolItem (clipelement remove bug)

/main
xingwei.zhu 5 年前
当前提交
10d03d7b
共有 4 个文件被更改,包括 114 次插入32 次删除
  1. 112
      Runtime/ui/painting/canvas_clip.cs
  2. 12
      Runtime/ui/painting/canvas_impl.cs
  3. 20
      Runtime/ui/utils/basic_types/no_alloc_item.cs
  4. 2
      Runtime/ui/utils/basic_types/path.cs

112
Runtime/ui/painting/canvas_clip.cs


using UnityEngine;
namespace Unity.UIWidgets.ui {
class ClipElement {
public readonly int saveCount;
public readonly uiMeshMesh mesh;
public readonly bool convex;
public readonly bool isRect;
class ClipElement : PoolItem {
public int saveCount;
public uiMeshMesh mesh;
public bool convex;
public bool isRect;
public Rect rect { get; private set; }
uint _genId;

public ClipElement(int saveCount, uiPath uiPath, uiMatrix3 matrix, float scale) {
this.saveCount = saveCount;
public ClipElement() {
}
public override void clear() {
this.mesh.dispose();
this.saveCount = 0;
this.mesh = null;
this.convex = false;
this.isRect = false;
this._genId = 0;
this._isIntersectionOfRects = false;
this._bound = null;
this._invMat = null;
}
public static ClipElement create(int saveCount, uiPath uiPath, uiMatrix3 matrix, float scale) {
ClipElement newElement = ItemPoolManager.alloc<ClipElement>();
newElement.saveCount = saveCount;
this.mesh = pathCache.getFillMesh(out this.convex).transform(matrix);
var fillMesh = pathCache.getFillMesh(out newElement.convex);
newElement.mesh = fillMesh.transform(matrix);
fillMesh.dispose();
var vertices = this.mesh.vertices;
if (this.convex && vertices.Count == 4 && matrix.rectStaysRect() &&
var vertices = newElement.mesh.vertices;
if (newElement.convex && vertices.Count == 4 && matrix.rectStaysRect() &&
this.isRect = true;
this.rect = this.mesh.bounds;
newElement.isRect = true;
newElement.rect = newElement.mesh.bounds;
this.isRect = false;
this.rect = null;
newElement.isRect = false;
newElement.rect = null;
return newElement;
}
public void setRect(Rect rect) {

}
}
class ClipStack {
class ClipStack : PoolItem {
static uint _genId = wideOpenGenID;
public static uint getNextGenID() {

Rect _bound;
int _saveCount;
public static ClipStack create() {
return ItemPoolManager.alloc<ClipStack>();
}
public override void clear() {
this._saveCount = 0;
this._bound = null;
this._lastElement = null;
foreach (var clipelement in this.stack) {
clipelement.dispose();
}
this.stack.Clear();
}
public void save() {
this._saveCount++;
}

break;
}
var lastelement = this.stack[this.stack.Count - 1];
lastelement.dispose();
this.stack.RemoveAt(this.stack.Count - 1);
this._lastElement = this.stack.Count == 0 ? null : this.stack[this.stack.Count - 1];
}

var element = new ClipElement(this._saveCount, uiPath, matrix, scale);
var element = ClipElement.create(this._saveCount, uiPath, matrix, scale);
this._pushElement(element);
}

if (prior.isEmpty()) {
element.dispose();
return;
}

var isectRect = prior.rect.intersect(element.rect);
if (isectRect.isEmpty) {
prior.setEmpty();
element.dispose();
return;
}

element.dispose();
element.dispose();
return;
}
}

}
}
class ReducedClip {
public readonly Rect scissor;
public readonly List<ClipElement> maskElements = new List<ClipElement>();
class ReducedClip : PoolItem {
public Rect scissor;
public List<ClipElement> maskElements = new List<ClipElement>();
ClipElement _lastElement;
public bool isEmpty() {

public ReducedClip() {
}
public override void clear() {
this.scissor = null;
this.maskElements.Clear();
this._lastElement = null;
}
public uint maskGenID() {
var element = this._lastElement;
if (element == null) {

return element.getGenID();
}
public ReducedClip(ClipStack stack, Rect layerBounds, Rect queryBounds) {
public static ReducedClip create(ClipStack stack, Rect layerBounds, Rect queryBounds) {
ReducedClip clip = ItemPoolManager.alloc<ReducedClip>();
this.scissor = layerBounds;
return;
clip.scissor = layerBounds;
return clip;
this.scissor = stackBounds;
return;
clip.scissor = stackBounds;
return clip;
this.scissor = Rect.zero;
return;
clip.scissor = Rect.zero;
return clip;
this.scissor = queryBounds;
this._walkStack(stack, this.scissor);
clip.scissor = queryBounds;
clip._walkStack(stack, clip.scissor);
return clip;
}
void _walkStack(ClipStack stack, Rect queryBounds) {

12
Runtime/ui/painting/canvas_impl.cs


return;
}
//!!!!!!BUG ==> need dispose layer!!!!!!!!
this._layers.RemoveAt(this._layers.Count - 1);
var currentLayer = this._currentLayer = this._layers[this._layers.Count - 1];
var state = currentLayer.currentState;

var layer = this._currentLayer;
var layerBounds = layer.layerBounds;
ReducedClip reducedClip = new ReducedClip(layer.clipStack, layerBounds, queryBounds);
ReducedClip reducedClip = ReducedClip.create(layer.clipStack, layerBounds, queryBounds);
reducedClip.dispose();
return false;
}

deviceScissor = deviceScissor.intersect(physicalRect);
if (deviceScissor.isEmpty) {
reducedClip.dispose();
return false;
}

this._setLastClipGenId(maskGenID, reducedClip.scissor);
}
reducedClip.dispose();
return true;
}

public readonly List<RenderLayer> layers = new List<RenderLayer>();
public readonly List<State> states = new List<State>();
public State currentState;
public ClipStack clipStack = new ClipStack();
public ClipStack clipStack;
public uint lastClipGenId;
public Rect lastClipBounds;
public bool ignoreClip = true;

newLayer.ignoreClip = ignoreClip;
newLayer.currentState = new State();
newLayer.states.Add(newLayer.currentState);
newLayer.clipStack = ClipStack.create();
return newLayer;
}

this.draws.Clear();
this.layers.Clear();
this.states.Clear();
this.clipStack = new ClipStack();
this.clipStack.dispose();
this._viewport = null;
}
}

20
Runtime/ui/utils/basic_types/no_alloc_item.cs


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

const bool _debugFlag = true;
static int _allocTick = 0;
public static void showDebugInfo() {
string info = "";
foreach (var key in debugInfo.Keys) {
info += "| " + key + " = " + debugInfo[key]._watermark + " |\n";
}
Debug.Log(info);
}
if (_allocTick >= 5000) {
showDebugInfo();
_allocTick = 0;
}
_allocTick++;
if (!poolDict.ContainsKey(typeof(T))) {
var pool = new List<PoolItem>(128);

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


}
var ret = uiMeshMesh.create(matrix, vertices, triangles, uv, this.rawBounds);
var ret = create(matrix, vertices, triangles, uv, this.rawBounds);
return ret;
}
}
正在加载...
取消
保存