浏览代码

fix mem leak on the usage of commandbuffercanvas in raster_cache

/main
xingwei.zhu 5 年前
当前提交
d91c4ea1
共有 5 个文件被更改,包括 24 次插入9 次删除
  1. 1
      Runtime/flow/raster_cache.cs
  2. 18
      Runtime/ui/utils/basic_types/canvas_impl.cs
  3. 4
      Runtime/ui/utils/basic_types/canvas_shader.cs
  4. 4
      Runtime/ui/utils/basic_types/command_buffer_canvas.cs
  5. 6
      Runtime/ui/utils/basic_types/render_cmd.cs

1
Runtime/flow/raster_cache.cs


canvas.concat(transform);
canvas.drawPicture(picture);
canvas.flush();
canvas.dispose();
return new RasterCacheResult(new Image(renderTexture), picture.paintBounds, devicePixelRatio);
}

18
Runtime/ui/utils/basic_types/canvas_impl.cs


RenderLayer _currentLayer;
Rect _lastScissor;
public void dispose() {
if (this._currentLayer != null) {
this._clearLayer(this._currentLayer);
this._currentLayer.dispose();
this._currentLayer = null;
this._lastScissor = null;
this._layers.Clear();
}
}
public PictureFlusher(RenderTexture renderTexture, float devicePixelRatio, MeshPool meshPool) {
D.assert(renderTexture);
D.assert(devicePixelRatio > 0);

case CmdDraw cmd:
this._setRenderTarget(cmdBuf, layer.rtID, ref toClear);
if (cmd.layer != null) {
if (cmd.layer.rtID == 0) {
if (cmd.layerId != null) {
if (cmd.layerId == 0) {
cmdBuf.SetGlobalTexture(CmdDraw.texId, cmd.layer.rtID);
cmdBuf.SetGlobalTexture(CmdDraw.texId, cmd.layerId.Value);
}
}

}
cmdBuf.DrawMesh(cmd.meshObj, CmdDraw.idMat, cmd.material, 0, cmd.pass, cmd.properties);
if (cmd.layer != null) {
if (cmd.layerId != null) {
cmdBuf.SetGlobalTexture(CmdDraw.texId, BuiltinRenderTextureType.None);
}

4
Runtime/ui/utils/basic_types/canvas_shader.cs


pass : pass,
material : mat,
properties : props,
layer : renderLayer
layerId : renderLayer.rtID
);
}

pass : pass,
material : mat,
properties : props,
layer : renderLayer
layerId : renderLayer.rtID
);
}
}

4
Runtime/ui/utils/basic_types/command_buffer_canvas.cs


this._recorder.reset();
this._flusher.flush(picture);
}
public void dispose() {
this._flusher.dispose();
}
}
}

6
Runtime/ui/utils/basic_types/render_cmd.cs


public TextBlobMesh textMesh;
public int pass;
public MaterialPropertyBlock properties;
public RenderLayer layer;
public int? layerId;
public Material material;
public Image image; // just to keep a reference to avoid GC.
public Mesh meshObj;

}
public static CmdDraw create(uiMeshMesh mesh = null, TextBlobMesh textMesh = null, int pass = 0,
MaterialPropertyBlock properties = null, RenderLayer layer = null, Material material = null,
MaterialPropertyBlock properties = null, int? layerId = null, Material material = null,
Image image = null, Mesh meshObj = null,
bool meshObjCreated = false) {
CmdDraw newCmd = ItemPoolManager.alloc<CmdDraw>();

newCmd.properties = properties;
newCmd.layer = layer;
newCmd.layerId = layerId;
newCmd.material = material;
newCmd.image = image;
newCmd.meshObj = meshObj;

正在加载...
取消
保存