|
|
|
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using Unity.UIWidgets.foundation; |
|
|
|
using Unity.UIWidgets.material; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.Rendering; |
|
|
|
|
|
|
|
|
|
|
RenderLayer _createMaskLayer(RenderLayer parentLayer, uiRect maskBounds, |
|
|
|
_drawPathDrawMeshCallbackDelegate drawCallback, |
|
|
|
uiPaint paint, bool convex, float alpha, Texture tex, uiRect texBound, TextBlobMesh textMesh, |
|
|
|
uiMeshMesh mesh) { |
|
|
|
uiMeshMesh mesh, bool notEmoji) { |
|
|
|
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(uiPaint.shapeOnly(paint), mesh, convex, alpha, tex, texBound, textMesh); |
|
|
|
drawCallback.Invoke(uiPaint.shapeOnly(paint), mesh, convex, alpha, tex, texBound, textMesh, notEmoji); |
|
|
|
|
|
|
|
var removed = this._layers.removeLast(); |
|
|
|
D.assert(removed == maskLayer); |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void _drawWithMaskFilter(uiRect meshBounds, uiPaint paint, uiMaskFilter maskFilter, |
|
|
|
uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect texBound, TextBlobMesh textMesh, |
|
|
|
uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect texBound, TextBlobMesh textMesh, bool notEmoji, |
|
|
|
_drawPathDrawMeshCallbackDelegate drawCallback) { |
|
|
|
var layer = this._currentLayer; |
|
|
|
var clipBounds = layer.layerBounds; |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var maskLayer = this._createMaskLayer(layer, maskBounds, drawCallback, paint, convex, alpha, tex, texBound, |
|
|
|
textMesh, mesh); |
|
|
|
textMesh, mesh, notEmoji); |
|
|
|
|
|
|
|
var blurLayer = this._createBlurLayer(maskLayer, sigma, sigma, layer); |
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
delegate void _drawPathDrawMeshCallbackDelegate(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, |
|
|
|
Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh); |
|
|
|
Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh, bool notEmoji); |
|
|
|
uiRect textBlobBounds, TextBlobMesh textMesh) { |
|
|
|
uiRect textBlobBounds, TextBlobMesh textMesh, bool notEmoji) { |
|
|
|
if (!this._applyClip(mesh.bounds)) { |
|
|
|
ObjectPool<uiMeshMesh>.release(mesh); |
|
|
|
return; |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void _drawPathDrawMeshCallback2(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, |
|
|
|
uiRect textBlobBounds, TextBlobMesh textMesh) { |
|
|
|
uiRect textBlobBounds, TextBlobMesh textMesh, bool notEmoji) { |
|
|
|
if (!this._applyClip(mesh.bounds)) { |
|
|
|
ObjectPool<uiMeshMesh>.release(mesh); |
|
|
|
return; |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void _drawTextDrawMeshCallback(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, |
|
|
|
uiRect textBlobBounds, TextBlobMesh textMesh) { |
|
|
|
uiRect textBlobBounds, TextBlobMesh textMesh, bool notEmoji) { |
|
|
|
if (!this._applyClip(textBlobBounds)) { |
|
|
|
ObjectPool<TextBlobMesh>.release(textMesh); |
|
|
|
return; |
|
|
|
|
|
|
layer.draws.Add(CanvasShader.texAlpha(layer, p, textMesh, tex)); |
|
|
|
if (notEmoji) { |
|
|
|
layer.draws.Add(CanvasShader.texAlpha(layer, p, textMesh, tex)); |
|
|
|
} |
|
|
|
else { |
|
|
|
uiPaint paintWithWhite = new uiPaint(p); |
|
|
|
paintWithWhite.color = uiColor.white; |
|
|
|
if (EmojiUtils.image == null) return; |
|
|
|
layer.draws.Add(CanvasShader.tex(layer, paintWithWhite, textMesh.resolveMesh(), EmojiUtils.image)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void _drawPathDrawMeshQuit(uiMeshMesh mesh) { |
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
uiRectHelper.zero, null, false, this.___drawPathDrawMeshCallback); |
|
|
|
this._drawPathDrawMeshCallback(paint, mesh, convex, 0, null, uiRectHelper.zero, null); |
|
|
|
this._drawPathDrawMeshCallback(paint, mesh, convex, 0, null, uiRectHelper.zero, null, false); |
|
|
|
} |
|
|
|
else { |
|
|
|
var state = this._currentLayer.currentState; |
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
uiRectHelper.zero, null, false, this.___drawPathDrawMeshCallback2); |
|
|
|
this._drawPathDrawMeshCallback2(paint, mesh, false, alpha, null, uiRectHelper.zero, null); |
|
|
|
this._drawPathDrawMeshCallback2(paint, mesh, false, alpha, null, uiRectHelper.zero, null, false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
var font = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle).font; |
|
|
|
var fontSizeToLoad = Mathf.CeilToInt(style.UnityFontSize * scale); |
|
|
|
var subText = textBlob.text.Substring(textBlob.textOffset, textBlob.textSize); |
|
|
|
font.RequestCharactersInTextureSafe(subText, fontSizeToLoad, style.UnityFontStyle); |
|
|
|
|
|
|
|
var tex = font.material.mainTexture; |
|
|
|
Texture tex = null; |
|
|
|
bool notEmoji = !char.IsHighSurrogate(subText[0]) && !EmojiUtils.isSingleCharEmoji(subText[0]); |
|
|
|
if (notEmoji) { |
|
|
|
font.RequestCharactersInTextureSafe(subText, fontSizeToLoad, style.UnityFontStyle); |
|
|
|
tex = font.material.mainTexture; |
|
|
|
} |
|
|
|
textBlobBounds, mesh, this.___drawTextDrawMeshCallback); |
|
|
|
textBlobBounds, mesh, notEmoji, this.___drawTextDrawMeshCallback); |
|
|
|
this._drawTextDrawMeshCallback(paint, null, false, 0, tex, textBlobBounds, mesh); |
|
|
|
this._drawTextDrawMeshCallback(paint, null, false, 0, tex, textBlobBounds, mesh, notEmoji); |
|
|
|
} |
|
|
|
|
|
|
|
public void flush(uiPicture picture) { |
|
|
|
|
|
|
|
|
|
|
uiMeshMesh mesh = cmd.mesh; |
|
|
|
if (cmd.textMesh != null) { |
|
|
|
mesh = cmd.textMesh.resovleMesh(); |
|
|
|
mesh = cmd.textMesh.resolveMesh(); |
|
|
|
} |
|
|
|
|
|
|
|
if (mesh == null) { |
|
|
|