|
|
|
|
|
|
|
|
|
|
readonly uiOffset[] _saveLayer_Points = new uiOffset[4]; |
|
|
|
|
|
|
|
void _saveLayer(uiRect bounds, Paint paint) { |
|
|
|
void _saveLayer(uiRect bounds, uiPaint paint) { |
|
|
|
D.assert(paint != null); |
|
|
|
|
|
|
|
var parentLayer = this._currentLayer; |
|
|
|
var state = parentLayer.currentState; |
|
|
|
|
|
|
this._saveLayer_Points[2], |
|
|
|
this._saveLayer_Points[3], |
|
|
|
bounds); |
|
|
|
var renderDraw = CanvasShader.texRT(layer, layer.layerPaint, mesh, parentLayer); |
|
|
|
var renderDraw = CanvasShader.texRT(layer, layer.layerPaint.Value, mesh, parentLayer); |
|
|
|
layer.draws.Add(renderDraw); |
|
|
|
|
|
|
|
var blurLayer = this._createBlurLayer(layer, filter.sigmaX, filter.sigmaY, layer); |
|
|
|
|
|
|
this._saveLayer_Points[2], |
|
|
|
this._saveLayer_Points[3], |
|
|
|
bounds); |
|
|
|
var renderDraw = CanvasShader.texRT(layer, layer.layerPaint, mesh, parentLayer); |
|
|
|
var renderDraw = CanvasShader.texRT(layer, layer.layerPaint.Value, mesh, parentLayer); |
|
|
|
layer.draws.Add(renderDraw); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
var renderDraw = CanvasShader.texRT(currentLayer, layer.layerPaint, mesh, layer); |
|
|
|
var renderDraw = CanvasShader.texRT(currentLayer, layer.layerPaint.Value, mesh, layer); |
|
|
|
currentLayer.draws.Add(renderDraw); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
RenderLayer _createMaskLayer(RenderLayer parentLayer, uiRect maskBounds, _drawPathDrawMeshCallbackDelegate drawCallback, |
|
|
|
Paint paint, bool convex, float alpha, Texture tex, uiRect texBound, TextBlobMesh textMesh, uiMeshMesh mesh) { |
|
|
|
uiPaint paint, bool convex, float alpha, Texture tex, uiRect texBound, TextBlobMesh textMesh, uiMeshMesh mesh) { |
|
|
|
var textureWidth = Mathf.CeilToInt(maskBounds.width * this._devicePixelRatio); |
|
|
|
if (textureWidth < 1) { |
|
|
|
textureWidth = 1; |
|
|
|
|
|
|
var maskState = maskLayer.states[maskLayer.states.Count - 1]; |
|
|
|
maskState.matrix = parentState.matrix; |
|
|
|
|
|
|
|
drawCallback.Invoke(Paint.shapeOnly(paint), mesh, convex, alpha, tex, texBound, textMesh); |
|
|
|
drawCallback.Invoke(uiPaint.shapeOnly(paint), mesh, convex, alpha, tex, texBound, textMesh); |
|
|
|
|
|
|
|
var removed = this._layers.removeLast(); |
|
|
|
D.assert(removed == maskLayer); |
|
|
|
|
|
|
return blurYLayer; |
|
|
|
} |
|
|
|
|
|
|
|
void _drawWithMaskFilter(uiRect meshBounds, Paint paint, MaskFilter maskFilter, |
|
|
|
void _drawWithMaskFilter(uiRect meshBounds, uiPaint paint, uiMaskFilter maskFilter, |
|
|
|
uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect texBound, TextBlobMesh textMesh, |
|
|
|
_drawPathDrawMeshCallbackDelegate drawCallback) { |
|
|
|
var layer = this._currentLayer; |
|
|
|
|
|
|
layer.draws.Add(CanvasShader.texRT(layer, paint, blurMesh, blurLayer)); |
|
|
|
} |
|
|
|
|
|
|
|
delegate void _drawPathDrawMeshCallbackDelegate(Paint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh); |
|
|
|
delegate void _drawPathDrawMeshCallbackDelegate(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh); |
|
|
|
void _drawPathDrawMeshCallback(Paint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh) { |
|
|
|
void _drawPathDrawMeshCallback(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh) { |
|
|
|
if (!this._applyClip(mesh.bounds)) { |
|
|
|
mesh.dispose(); |
|
|
|
return; |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void _drawPathDrawMeshCallback2(Paint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh) { |
|
|
|
void _drawPathDrawMeshCallback2(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh) { |
|
|
|
if (!this._applyClip(mesh.bounds)) { |
|
|
|
mesh.dispose(); |
|
|
|
return; |
|
|
|
|
|
|
layer.draws.Add(CanvasShader.stroke1(layer, mesh.duplicate())); |
|
|
|
} |
|
|
|
|
|
|
|
void _drawTextDrawMeshCallback(Paint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh) { |
|
|
|
void _drawTextDrawMeshCallback(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh) { |
|
|
|
if (!this._applyClip(textBlobBounds)) { |
|
|
|
textMesh.dispose(); |
|
|
|
return; |
|
|
|
|
|
|
mesh.dispose(); |
|
|
|
} |
|
|
|
|
|
|
|
void _drawPath(uiPath path, Paint paint) { |
|
|
|
void _drawPath(uiPath path, uiPaint paint) { |
|
|
|
D.assert(paint != null); |
|
|
|
|
|
|
|
if (paint.style == PaintingStyle.fill) { |
|
|
|
var state = this._currentLayer.currentState; |
|
|
|
|
|
|
var fillMesh = cache.getFillMesh(out convex); |
|
|
|
var mesh = fillMesh.transform(state.matrix); |
|
|
|
|
|
|
|
if (paint.maskFilter != null && paint.maskFilter.sigma != 0) { |
|
|
|
this._drawWithMaskFilter(mesh.bounds, paint, paint.maskFilter, mesh, convex, 0, null, uiRectHelper.zero, null, this._drawPathDrawMeshCallback); |
|
|
|
if (paint.maskFilter != null && paint.maskFilter.Value.sigma != 0) { |
|
|
|
this._drawWithMaskFilter(mesh.bounds, paint, paint.maskFilter.Value, mesh, convex, 0, null, uiRectHelper.zero, null, this._drawPathDrawMeshCallback); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var mesh = strokenMesh.transform(state.matrix); |
|
|
|
|
|
|
|
if (paint.maskFilter != null && paint.maskFilter.sigma != 0) { |
|
|
|
this._drawWithMaskFilter(mesh.bounds, paint, paint.maskFilter, mesh, false, alpha, null, uiRectHelper.zero, null, this._drawPathDrawMeshCallback2); |
|
|
|
if (paint.maskFilter != null && paint.maskFilter.Value.sigma != 0) { |
|
|
|
this._drawWithMaskFilter(mesh.bounds, paint, paint.maskFilter.Value, mesh, false, alpha, null, uiRectHelper.zero, null, this._drawPathDrawMeshCallback2); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void _drawImage(Image image, uiOffset offset, Paint paint) { |
|
|
|
void _drawImage(Image image, uiOffset offset, uiPaint paint) { |
|
|
|
D.assert(paint != null); |
|
|
|
|
|
|
|
this._drawImageRect(image, |
|
|
|
null, |
|
|
|
|
|
|
paint); |
|
|
|
} |
|
|
|
|
|
|
|
void _drawImageRect(Image image, uiRect? src, uiRect dst, Paint paint) { |
|
|
|
void _drawImageRect(Image image, uiRect? src, uiRect dst, uiPaint paint) { |
|
|
|
D.assert(paint != null); |
|
|
|
|
|
|
|
if (src == null) { |
|
|
|
src = uiRectHelper.one; |
|
|
|
|
|
|
layer.draws.Add(CanvasShader.tex(layer, paint, mesh, image)); |
|
|
|
} |
|
|
|
|
|
|
|
void _drawImageNine(Image image, uiRect? src, uiRect center, uiRect dst, Paint paint) { |
|
|
|
void _drawImageNine(Image image, uiRect? src, uiRect center, uiRect dst, uiPaint paint) { |
|
|
|
D.assert(paint != null); |
|
|
|
|
|
|
|
var scaleX = 1f / image.width; |
|
|
|
var scaleY = 1f / image.height; |
|
|
|
|
|
|
break; |
|
|
|
case DrawSaveLayer cmd: { |
|
|
|
saveCount++; |
|
|
|
this._saveLayer(uiRectHelper.fromRect(cmd.rect), cmd.paint); |
|
|
|
this._saveLayer(uiRectHelper.fromRect(cmd.rect), uiPaint.fromPaint(cmd.paint)); |
|
|
|
break; |
|
|
|
} |
|
|
|
case DrawRestore _: { |
|
|
|
|
|
|
} |
|
|
|
case DrawPath cmd: { |
|
|
|
var uipath = uiPath.fromPath(cmd.path); |
|
|
|
this._drawPath(uipath, cmd.paint); |
|
|
|
this._drawPath(uipath, uiPaint.fromPaint(cmd.paint)); |
|
|
|
this._drawImage(cmd.image, (uiOffset.fromOffset(cmd.offset)).Value, cmd.paint); |
|
|
|
this._drawImage(cmd.image, (uiOffset.fromOffset(cmd.offset)).Value, uiPaint.fromPaint(cmd.paint)); |
|
|
|
this._drawImageRect(cmd.image, uiRectHelper.fromRect(cmd.src), uiRectHelper.fromRect(cmd.dst), cmd.paint); |
|
|
|
this._drawImageRect(cmd.image, uiRectHelper.fromRect(cmd.src), uiRectHelper.fromRect(cmd.dst), uiPaint.fromPaint(cmd.paint)); |
|
|
|
this._drawImageNine(cmd.image, uiRectHelper.fromRect(cmd.src), uiRectHelper.fromRect(cmd.center), uiRectHelper.fromRect(cmd.dst), cmd.paint); |
|
|
|
this._drawImageNine(cmd.image, uiRectHelper.fromRect(cmd.src), uiRectHelper.fromRect(cmd.center), uiRectHelper.fromRect(cmd.dst), uiPaint.fromPaint(cmd.paint)); |
|
|
|
break; |
|
|
|
} |
|
|
|
case DrawPicture cmd: { |
|
|
|
|
|
|
case DrawTextBlob cmd: { |
|
|
|
this._drawTextBlob(cmd.textBlob, (uiOffset.fromOffset(cmd.offset)).Value, cmd.paint); |
|
|
|
this._drawTextBlob(cmd.textBlob, (uiOffset.fromOffset(cmd.offset)).Value, uiPaint.fromPaint(cmd.paint)); |
|
|
|
break; |
|
|
|
} |
|
|
|
default: |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void _drawTextBlob(TextBlob textBlob, uiOffset offset, Paint paint) { |
|
|
|
void _drawTextBlob(TextBlob textBlob, uiOffset offset, uiPaint paint) { |
|
|
|
D.assert(paint != null); |
|
|
|
|
|
|
|
var state = this._currentLayer.currentState; |
|
|
|
var scale = state.scale * this._devicePixelRatio; |
|
|
|
|
|
|
|
|
|
|
var tex = font.material.mainTexture; |
|
|
|
|
|
|
|
if (paint.maskFilter != null && paint.maskFilter.sigma != 0) { |
|
|
|
this._drawWithMaskFilter(textBlobBounds, paint, paint.maskFilter, null, false, 0, tex, textBlobBounds, mesh, this._drawTextDrawMeshCallback); |
|
|
|
if (paint.maskFilter != null && paint.maskFilter.Value.sigma != 0) { |
|
|
|
this._drawWithMaskFilter(textBlobBounds, paint, paint.maskFilter.Value, null, false, 0, tex, textBlobBounds, mesh, this._drawTextDrawMeshCallback); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|