在上一篇报告中发现 在_fBatchingRequested = true时
可以触发在容器类SetRenderingOrder()中的DoFairyBatching()
这里我们看一下 在什么情况下_fBatchingRequested会被设置为true 引发自动合批处理
1. 触发Container 中的 UpdateBatchingFlags()
internal void UpdateBatchingFlags()
{
bool oldValue = _fBatchingRoot;
_fBatchingRoot = _fBatching || _clipRect != null || _mask != null || _paintingMode > 0;
if (oldValue != _fBatchingRoot)
{
if (_fBatchingRoot)
_fBatchingRequested = true;
else if (_descendants != null)
_descendants.Clear();
InvalidateBatchingState();
}
}
- 在对组件设置进入绘画模式以及离开绘画模式时(EnterPaintingMode / LeavePaintingMode)
判断当前组件是否为容器类型 容器类型则触发其 UpdateBatchingFlags - Container属性变动时
_fBatching : fairyBatching 属性值
_clipRect : clipRect 裁剪区域
组件设置区域溢出时隐藏 会做默认设置 SetupOverflow(OverflowType overflow)
ScrollPanel HandleSizeChanged() 以及 当有滚动条对象时,为了避免滚动条变化时触发重新合批,给rootContainer也加上剪裁。但这可能会增加额外dc。
InputTextField OnSizeChanged()
_mask : 组件的遮罩物体
_paintingMode : 绘画模式ID //1-滤镜,2-blendMode,4-transformMatrix, 8-cacheAsBitmap
2. 代码中强制触发合批
public void InvalidateBatchingState(bool childrenChanged)
{
if (childrenChanged && _fBatchingRoot)
_fBatchingRequested = true;
else
{
Container p = this.parent;
while (p != null)
{
if (p._fBatchingRoot)
{
p._fBatchingRequested = true;
break;
}
p = p.parent;
}
}
}
在这个阶段 在此检查是否需要合批操作
childrenChanged == true
AddChildAt / RemoveChildAt /
SetChildIndex / SwapChildrenAt / ChangeChildrenOrder /
visible /
Glist - UpdateBounds() /
GProgressBar - Update() /
GSlider - UpdateWithPercent() /
Transition 中存在属性 invalidateBatchingEveryFrame
开启时 会触发自动合批
在播放 XY/Size/Pivot/Rotation/Scale/Skew/Shake未发生网格变动的动效类型时
代码中调用 InvalidateBatchingState(true) 强制触发自动合批