浏览代码

cache uipath for reuse

/main
xingwei.zhu 5 年前
当前提交
401a5864
共有 8 个文件被更改,包括 127 次插入15 次删除
  1. 43
      Runtime/ui/painting/path.cs
  2. 10
      Runtime/ui/utils/renderer/cmdbufferCanvas/rendering/canvas_impl.cs
  3. 6
      Runtime/ui/utils/renderer/common/draw_cmd.cs
  4. 15
      Runtime/ui/utils/renderer/common/geometry/path/path.cs
  5. 1
      Runtime/widgets/binding.cs
  6. 2
      Samples/UIWidgetSample/NavigationSample.cs
  7. 2
      Samples/UIWidgetSample/TextInput.unity
  8. 63
      Runtime/ui/utils/renderer/allocUtils/uipath_cache_manager.cs

43
Runtime/ui/painting/path.cs


PathCache _cache;
static uint pathGlobalKey = 0;
uint _pathKey = 0;
public uint pathKey {
get {
return this._pathKey;
}
}
public Path(int capacity = 128) {
this._commands = new List<float>(capacity);
this._reset();

this._minY = float.MaxValue;
this._maxX = float.MinValue;
this._maxY = float.MinValue;
this._cache = null;
if (this._cache != null) {
this._pathKey = pathGlobalKey++;
this._cache = null;
}
}
internal PathCache flatten(float scale) {

this._commandx = x;
this._commandy = y;
this._cache = null;
if (this._cache != null) {
this._pathKey = pathGlobalKey++;
this._cache = null;
}
}
void _appendLineTo(float x, float y) {

this._commandx = x;
this._commandy = y;
this._cache = null;
if (this._cache != null) {
this._pathKey = pathGlobalKey++;
this._cache = null;
}
}
void _appendBezierTo(float x1, float y1, float x2, float y2, float x3, float y3) {

this._commandx = x3;
this._commandy = y3;
this._cache = null;
if (this._cache != null) {
this._pathKey = pathGlobalKey++;
this._cache = null;
}
this._cache = null;
this._pathKey = pathGlobalKey++;
if (this._cache != null) {
this._pathKey = pathGlobalKey++;
this._cache = null;
}
this._cache = null;
this._pathKey = pathGlobalKey++;
if (this._cache != null) {
this._pathKey = pathGlobalKey++;
this._cache = null;
}
}
public void relativeMoveTo(float x, float y) {

10
Runtime/ui/utils/renderer/cmdbufferCanvas/rendering/canvas_impl.cs


var path = uiPath.create();
path.addRect(uiRectHelper.fromRect(rect));
this._clipPath(path);
ObjectPool<uiPath>.release(path);
uiPathCacheManager.putToCache(path);
}
void _clipUIRect(uiRect rect) {

ObjectPool<uiPath>.release(path);
uiPathCacheManager.putToCache(path);
}
void _clipRRect(RRect rrect) {

ObjectPool<uiPath>.release(path);
uiPathCacheManager.putToCache(path);
}
void _clipPath(uiPath path) {

case DrawClipPath cmd: {
var uipath = uiPath.fromPath(cmd.path);
this._clipPath(uipath);
ObjectPool<uiPath>.release(uipath);
uiPathCacheManager.putToCache(uipath);
ObjectPool<uiPath>.release(uipath);
uiPathCacheManager.putToCache(uipath);
break;
}
case DrawImage cmd: {

6
Runtime/ui/utils/renderer/common/draw_cmd.cs


}
public override void clear() {
ObjectPool<uiPath>.release(this.path);
//ObjectPool<uiPath>.release(this.path);
uiPathCacheManager.putToCache(this.path);
this.path = null;
}

}
public override void clear() {
ObjectPool<uiPath>.release(this.path);
//ObjectPool<uiPath>.release(this.path);
uiPathCacheManager.putToCache(this.path);
this.path = null;
}

15
Runtime/ui/utils/renderer/common/geometry/path/path.cs


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

float _maxX, _maxY;
uiPathCache _cache;
public uint pathKey = 0;
public bool needCache = false;
public static uiPath create(int capacity = 128) {
uiPath newPath = ObjectPool<uiPath>.alloc();

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

public static uiPath fromPath(Path path) {
D.assert(path != null);
uiPath uipath = uiPath.create();
uiPath uipath;
bool exists = uiPathCacheManager.tryGetUiPath(path.pathKey, out uipath);
if (exists) {
return uipath;
}
var i = 0;
var _commands = path.commands;

1
Runtime/widgets/binding.cs


TextBlobMesh.tickNextFrame();
TessellationGenerator.tickNextFrame();
uiTessellationGenerator.tickNextFrame();
uiPathCacheManager.tickNextFrame();
});
}

2
Samples/UIWidgetSample/NavigationSample.cs


using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using DialogUtils = Unity.UIWidgets.widgets.DialogUtils;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace UIWidgetsSample {

2
Samples/UIWidgetSample/TextInput.unity


m_EditorClassIdentifier:
m_UiScaleMode: 0
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ScaleFactor: 1.5
m_ReferenceResolution: {x: 800, y: 600}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 0

63
Runtime/ui/utils/renderer/allocUtils/uipath_cache_manager.cs


using System.Collections.Generic;
using UnityEngine;
namespace Unity.UIWidgets.ui {
public static class uiPathCacheManager {
static Dictionary<uint, uiPath> cache = new Dictionary<uint, uiPath>(256);
//remove unused cache items every 30 frame
static Dictionary<uint, bool> touched = new Dictionary<uint, bool>(256);
static float curFrame;
static readonly List<uint> untouched = new List<uint>();
public static void tickNextFrame() {
curFrame++;
if (curFrame < 30) {
return;
}
curFrame = 0;
untouched.Clear();
foreach (var key in cache.Keys) {
if (!touched.ContainsKey(key)) {
untouched.Add(key);
}
}
foreach (var key in untouched) {
ObjectPool<uiPath>.release(cache[key]);
cache.Remove(key);
}
touched.Clear();
}
public static void putToCache(uiPath uipath) {
if (!uipath.needCache) {
ObjectPool<uiPath>.release(uipath);
}
}
public static bool tryGetUiPath(uint pathKey, out uiPath outpath) {
if (cache.ContainsKey(pathKey)) {
touched[pathKey] = true;
outpath = cache[pathKey];
return true;
}
var uipath = uiPath.create();
cache[pathKey] = uipath;
touched[pathKey] = true;
uipath.needCache = true;
uipath.pathKey = pathKey;
outpath = uipath;
return false;
}
}
}
正在加载...
取消
保存