浏览代码

Merge branch 'master' of github.com:UnityTech/UIWidgets into allocator2 (cont.)

# Conflicts:
#	Runtime/ui/painting/canvas_impl.cs
#	Runtime/ui/painting/txt/mesh_generator.cs
#	Runtime/ui/renderer/compositeCanvas/flow/physical_shape_layer.cs
/main
xingwei.zhu 5 年前
当前提交
00bdcb03
共有 3 个文件被更改,包括 101 次插入24 次删除
  1. 73
      Runtime/ui/painting/txt/mesh_generator.cs
  2. 50
      Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_impl.cs
  3. 2
      Runtime/ui/renderer/compositeCanvas/flow/physical_shape_layer.cs

73
Runtime/ui/painting/txt/mesh_generator.cs


_keysToRemove.Clear();
}
public uiMeshMesh resovleMesh() {
public uiMeshMesh resolveMesh() {
if (this._resolved) {
return this._mesh;
}

var style = this.textBlob.style;
var fontInfo = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle);
var text = this.textBlob.text;
var fontInfo = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle);
var font = fontInfo.font;
_meshes.TryGetValue(key, out var meshInfo);
if (meshInfo != null && meshInfo.textureVersion == fontInfo.textureVersion) {
ObjectPool<MeshKey>.release(key);

}
// Handling Emoji
char startingChar = text[this.textBlob.textOffset];
if (char.IsHighSurrogate(startingChar) || EmojiUtils.isSingleCharEmoji(startingChar)) {
var vert = ObjectPool<uiList<Vector3>>.alloc();
var tri = ObjectPool<uiList<int>>.alloc();
var uvCoord = ObjectPool<uiList<Vector2>>.alloc();
var metrics = FontMetrics.fromFont(font, style.UnityFontSize);
var minMaxRect = EmojiUtils.getMinMaxRect(style.fontSize, metrics.ascent, metrics.descent);
var minX = minMaxRect.left;
var maxX = minMaxRect.right;
var minY = minMaxRect.top;
var maxY = minMaxRect.bottom;
for (int i = 0; i < this.textBlob.textSize; i++) {
char a = text[this.textBlob.textOffset + i];
int code = a;
if (char.IsHighSurrogate(a)) {
D.assert(i+1 < this.textBlob.textSize);
D.assert(this.textBlob.textOffset+i+1 < this.textBlob.text.Length);
char b = text[this.textBlob.textOffset+i+1];
D.assert(char.IsLowSurrogate(b));
code = char.ConvertToUtf32(a, b);
} else if (char.IsLowSurrogate(a) || EmojiUtils.isEmptyEmoji(a)) {
continue;
}
var uvRect = EmojiUtils.getUVRect(code);
var font = fontInfo.font;
var pos = this.textBlob.positions[i];
int baseIndex = vert.Count;
vert.Add(new Vector3(pos.x + minX, pos.y + minY, 0));
vert.Add(new Vector3(pos.x + maxX, pos.y + minY, 0));
vert.Add(new Vector3(pos.x + maxX, pos.y + maxY, 0));
vert.Add(new Vector3(pos.x + minX, pos.y + maxY, 0));
tri.Add(baseIndex);
tri.Add(baseIndex + 1);
tri.Add(baseIndex + 2);
tri.Add(baseIndex);
tri.Add(baseIndex + 2);
tri.Add(baseIndex + 3);
uvCoord.Add(uvRect.bottomLeft.toVector());
uvCoord.Add(uvRect.bottomRight.toVector());
uvCoord.Add(uvRect.topRight.toVector());
uvCoord.Add(uvRect.topLeft.toVector());
if(char.IsHighSurrogate(a)) i++;
}
uiMeshMesh meshMesh = uiMeshMesh.create(null, vert, tri, uvCoord);
if (_meshes.ContainsKey(key)) {
ObjectPool<MeshInfo>.release(_meshes[key]);
_meshes.Remove(key);
}
_meshes[key] = MeshInfo.create(key, meshMesh, 0);
this._mesh = meshMesh.transform(this.matrix);
return this._mesh;
}
var text = this.textBlob.text;
var fontSizeToLoad = Mathf.CeilToInt(style.UnityFontSize * this.scale);
var vertices = ObjectPool<uiList<Vector3>>.alloc();

50
Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_impl.cs


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) {

2
Runtime/ui/renderer/compositeCanvas/flow/physical_shape_layer.cs


Color _shadow_color;
float _device_pixel_ratio;
Path _path;
#pragma warning disable 0414
#pragma warning restore 0414
Rect _frameRRect;
Clip _clip_behavior;

正在加载...
取消
保存