Files
Xune/UIX.RenderApi.Skia/Microsoft/Iris/Render/Common/ObjectCache.cs
T

128 lines
4.6 KiB
C#
Raw Normal View History

2021-07-11 22:59:29 -05:00
// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.Render.Common.ObjectCache
// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1
// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll
using System;
namespace Microsoft.Iris.Render.Common
{
2021-07-11 23:04:40 -05:00
internal class ObjectCache : RenderObject
2021-07-11 22:59:29 -05:00
{
2021-07-11 23:04:40 -05:00
private const int k_nReductionThreshold = 3;
private Vector<CachedRenderObject> m_listObjects;
private int m_nMaxCacheSize;
private int m_nMinCacheSize;
private int m_nStepSize;
private int m_cCacheMisses;
private int m_cCacheHits;
private bool m_fWasCacheFull;
private int m_cReductionRequests;
2021-07-11 22:59:29 -05:00
2021-07-11 23:04:40 -05:00
internal ObjectCache(int nMinSize, int nMaxSize, int nStepSize)
2021-07-11 22:59:29 -05:00
{
2021-07-11 23:04:40 -05:00
this.m_listObjects = new Vector<CachedRenderObject>(nMinSize);
this.m_nMinCacheSize = nMinSize;
this.m_nMaxCacheSize = nMaxSize;
this.m_nStepSize = nStepSize;
2021-07-11 22:59:29 -05:00
}
2021-07-11 23:04:40 -05:00
protected override void Dispose(bool fInDispose)
2021-07-11 22:59:29 -05:00
{
2021-07-11 23:04:40 -05:00
try
2021-07-11 22:59:29 -05:00
{
2021-07-11 23:04:40 -05:00
if (fInDispose)
{
foreach (CachedRenderObject listObject in this.m_listObjects)
{
listObject.Cache = (ObjectCache)null;
listObject.UnregisterUsage((object)this);
}
}
this.m_listObjects = (Vector<CachedRenderObject>)null;
}
finally
{
base.Dispose(fInDispose);
2021-07-11 22:59:29 -05:00
}
}
2021-07-11 23:04:40 -05:00
internal int Size => this.m_listObjects.Count;
internal bool Add(CachedRenderObject obj)
{
if (this.m_listObjects.Count < this.m_listObjects.Capacity)
{
obj.RegisterUsage((object)this);
this.m_listObjects.Add(obj);
return true;
}
this.m_fWasCacheFull = true;
return false;
}
internal CachedRenderObject Remove(object objUser)
{
if (this.m_listObjects.Count > 0)
{
++this.m_cCacheHits;
int index = this.m_listObjects.Count - 1;
CachedRenderObject listObject = this.m_listObjects[index];
this.m_listObjects.RemoveAt(index);
listObject.RegisterUsage(objUser);
listObject.UnregisterUsage((object)this);
return listObject;
}
++this.m_cCacheMisses;
return (CachedRenderObject)null;
}
internal void RemoveAll()
{
foreach (CachedRenderObject listObject in this.m_listObjects)
{
listObject.Cache = (ObjectCache)null;
listObject.UnregisterUsage((object)this);
}
this.m_listObjects.Clear();
}
internal void Update()
{
if (this.ShouldGrowCache())
this.m_listObjects.Capacity = Math.Min(this.m_listObjects.Capacity + this.m_nStepSize, this.m_nMaxCacheSize);
else if (this.ShouldShrinkCache())
{
if (this.m_cReductionRequests > 3)
{
int num = Math.Max(this.m_listObjects.Capacity - this.m_nStepSize, this.m_nMinCacheSize);
if (this.m_listObjects.Count - num > 0)
{
for (int index = this.m_listObjects.Count - 1; index >= num; --index)
{
CachedRenderObject listObject = this.m_listObjects[index];
listObject.Cache = (ObjectCache)null;
listObject.UnregisterUsage((object)this);
this.m_listObjects.RemoveAt(index);
}
}
this.m_listObjects.Capacity = num;
this.m_cReductionRequests = 0;
}
else
++this.m_cReductionRequests;
}
else
this.m_cReductionRequests = 0;
this.m_cCacheMisses = 0;
this.m_cCacheHits = 0;
this.m_fWasCacheFull = false;
}
private bool ShouldGrowCache() => this.m_cCacheMisses > 0 && this.m_fWasCacheFull && this.m_listObjects.Capacity < this.m_nMaxCacheSize;
private bool ShouldShrinkCache() => this.m_cCacheMisses + this.m_cCacheHits == 0 && this.m_listObjects.Capacity > this.m_nMinCacheSize;
2021-07-11 22:59:29 -05:00
}
}