浏览代码

noallocate -- pool based version: step 2

/main
xingwei.zhu 6 年前
当前提交
8baa6c77
共有 6 个文件被更改,包括 2137 次插入72 次删除
  1. 118
      Runtime/ui/painting/canvas_impl.cs
  2. 9
      Runtime/ui/utils/basic_types/generic_list.cs
  3. 1001
      Runtime/ui/utils/basic_types/matrix.cs
  4. 54
      Runtime/ui/utils/basic_types/no_alloc_item.cs
  5. 1001
      Runtime/ui/utils/basic_types/path.cs
  6. 26
      Runtime/ui/utils/basic_types/rect.cs

118
Runtime/ui/painting/canvas_impl.cs


width * this._fringeWidth,
height * this._fringeWidth);
firstLayer = new RenderLayer {
width = width,
height = height,
layerBounds = bounds,
};
firstLayer = RenderLayer.create(
width : width,
height : height,
layerBounds : bounds
);
firstLayer = new RenderLayer {
width = firstLayer.width,
height = firstLayer.height,
layerBounds = firstLayer.layerBounds,
};
firstLayer = RenderLayer.create(
width : firstLayer.width,
height : firstLayer.height,
layerBounds : firstLayer.layerBounds
);
foreach (var layer in this._layers) {
layer.dispose();
}
this._layers.Clear();
this._layers.Add(firstLayer);
this._currentLayer = firstLayer;

textureHeight = 1;
}
var layer = new RenderLayer {
rtID = Shader.PropertyToID("_rtID_" + this._layers.Count + "_" + parentLayer.layers.Count),
width = textureWidth,
height = textureHeight,
layerBounds = bounds,
layerPaint = paint,
};
var layer = RenderLayer.create(
rtID : Shader.PropertyToID("_rtID_" + this._layers.Count + "_" + parentLayer.layers.Count),
width : textureWidth,
height : textureHeight,
layerBounds : bounds,
layerPaint : paint
);
parentLayer.addLayer(layer);
this._layers.Add(layer);

textureHeight = 1;
}
var maskLayer = new RenderLayer {
rtID = Shader.PropertyToID("_rtID_" + this._layers.Count + "_" + parentLayer.layers.Count),
width = textureWidth,
height = textureHeight,
layerBounds = maskBounds,
filterMode = FilterMode.Bilinear,
noMSAA = true,
};
var maskLayer = RenderLayer.create(
rtID : Shader.PropertyToID("_rtID_" + this._layers.Count + "_" + parentLayer.layers.Count),
width : textureWidth,
height : textureHeight,
layerBounds : maskBounds,
filterMode : FilterMode.Bilinear,
noMSAA : true
);
parentLayer.addLayer(maskLayer);
this._layers.Add(maskLayer);

textureHeight = 1;
}
var blurXLayer = new RenderLayer {
rtID = Shader.PropertyToID("_rtID_" + this._layers.Count + "_" + parentLayer.layers.Count),
width = textureWidth,
height = textureHeight,
layerBounds = maskLayer.layerBounds,
filterMode = FilterMode.Bilinear,
noMSAA = true,
};
var blurXLayer = RenderLayer.create(
rtID : Shader.PropertyToID("_rtID_" + this._layers.Count + "_" + parentLayer.layers.Count),
width : textureWidth,
height : textureHeight,
layerBounds : maskLayer.layerBounds,
filterMode : FilterMode.Bilinear,
noMSAA : true
);
var blurYLayer = new RenderLayer {
rtID = Shader.PropertyToID("_rtID_" + this._layers.Count + "_" + parentLayer.layers.Count),
width = textureWidth,
height = textureHeight,
layerBounds = maskLayer.layerBounds,
filterMode = FilterMode.Bilinear,
noMSAA = true,
};
var blurYLayer = RenderLayer.create(
rtID : Shader.PropertyToID("_rtID_" + this._layers.Count + "_" + parentLayer.layers.Count),
width : textureWidth,
height : textureHeight,
layerBounds : maskLayer.layerBounds,
filterMode : FilterMode.Bilinear,
noMSAA : true
);
parentLayer.addLayer(blurYLayer);

foreach (var subLayer in layer.layers) {
this._clearLayer(subLayer);
subLayer.dispose();
}
layer.layers.Clear();

internal class RenderLayer {
internal class RenderLayer : PoolItem {
public int rtID;
public int width;
public int height;

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

}
}
public RenderLayer() {
this.currentState = new State();
this.states.Add(this.currentState);
public static RenderLayer create(int rtID = 0, int width = 0, int height = 0, FilterMode filterMode = FilterMode.Point,
bool noMSAA = false, Rect layerBounds = null, Paint layerPaint = null, bool ignoreClip = true) {
var newLayer = ItemPoolManager.alloc<RenderLayer>();
newLayer.rtID = rtID;
newLayer.width = width;
newLayer.height = height;
newLayer.filterMode = filterMode;
newLayer.noMSAA = noMSAA;
newLayer.layerBounds = layerBounds;
newLayer.layerPaint = layerPaint;
newLayer.ignoreClip = ignoreClip;
newLayer.currentState = new State();
newLayer.states.Add(newLayer.currentState);
return newLayer;
}
public override void dispose() {
this.draws.Clear();
this.layers.Clear();
this.states.Clear();
this.clipStack = new ClipStack();
this._viewport = null;
base.dispose();
}
}

9
Runtime/ui/utils/basic_types/generic_list.cs


public class uiList<T> : PoolItem {
List<T> list;
public void Setup() {
public override void setup() {
base.setup();
this.list = this.list ?? new List<T>(128);
}

public override void Dispose() {
public override void dispose() {
//otherwise, we may clear it in Setup() for lazy action
//otherwise, we may clear it in Setup() for lazy update
base.Dispose();
base.dispose();
}
}
}

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

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


using System;
using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using UnityEngine;
public class ItemDebugInfo {
public int _watermark;
public int _size;
public string _itemKey;
public void consume() {
this._size++;
if (this._size > this._watermark) {
this._watermark = this._size;
Debug.Log("Item watermark increases >>> " + this._itemKey + " = " + this._watermark);
}
}
public void recycle() {
this._size--;
}
}
static readonly Dictionary<Type, ItemDebugInfo> debugInfo = new Dictionary<Type, ItemDebugInfo>();
const bool _debugFlag = true;
public static T alloc<T>() where T : PoolItem, new() {
if (!poolDict.ContainsKey(typeof(T))) {

var item = new T();
item.Setup();
item.setup();
if (_debugFlag) {
debugInfo[typeof(T)] = new ItemDebugInfo {_watermark = 0, _size = 0, _itemKey = typeof(T).ToString()};
}
}
var curPool = poolDict[typeof(T)];

item.Setup();
item.setup();
curPool.Add(item);
}

curPool.RemoveAt(0);
if (_debugFlag) {
debugInfo[typeof(T)].consume();
}
return (T)curItem;
}

D.assert(poolDict.ContainsKey(typeofT));
poolDict[typeofT].Add(item);
if (_debugFlag) {
debugInfo[typeofT].recycle();
}
}
}

TestPoolItem.SetLength(2f);
TestPoolItem.Dispose();
TestPoolItem.dispose();
}
}

this.length = len;
}
public override void Dispose() {
public override void dispose() {
base.Dispose();
base.dispose();
}
}

}
public void Setup() {
public virtual void setup() {
public virtual void Dispose() {
this.Recycle();
public virtual void dispose() {
this.recycle();
public void Recycle() {
public void recycle() {
ItemPoolManager.recycle(this);
}
}

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

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


using UnityEditor.Experimental.UIElements;
public float top;
public float left;
public float width;

left = rect.left,
width = rect.width,
height = rect.height
};
}
}
public struct uiOffset {
public float dx;
public float dy;
public static uiOffset fromOffset(Offset offset) {
return new uiOffset {
dx = offset.dx,
dy = offset.dy
};
}
}
public struct uiSize {
public float width;
public float height;
public static uiSize fromSize(Size size) {
return new uiSize {
width = size.width,
height = size.height
};
}
}
正在加载...
取消
保存