浏览代码

Make all text blobs share the position buffer.

/main
Yuncong Zhang 5 年前
当前提交
052e0678
共有 3 个文件被更改,包括 24 次插入11 次删除
  1. 6
      Runtime/ui/painting/txt/mesh_generator.cs
  2. 23
      Runtime/ui/painting/txt/text_blob.cs
  3. 6
      Runtime/ui/txt/paragraph.cs

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


continue;
}
var uvRect = EmojiUtils.getUVRect(code);
var pos = this.textBlob.positions[i];
var pos = this.textBlob.getPosition(i);
int baseIndex = vert.Count;
vert.Add(new Vector3(pos.x + minX, pos.y + minY, 0));

for (int charIndex = 0; charIndex < length; ++charIndex) {
var ch = text[charIndex + this.textBlob.textOffset];
// first char as origin for mesh position
var position = this.textBlob.positions[charIndex];
var position = this.textBlob.getPosition(charIndex);
if (LayoutUtils.isWordSpace(ch) || LayoutUtils.isLineEndSpace(ch) || ch == '\t') {
continue;
}

23
Runtime/ui/painting/txt/text_blob.cs


internal TextBlob(string text, int textOffset, int textSize, Vector2d[] positions, Rect bounds,
TextStyle style) {
this.instanceId = ++_nextInstanceId;
this.positions = positions;
this._positions = positions;
get { return this.bounds.translate(this.positions[0].x, this.positions[0].y); }
get { return this.bounds.translate(this._positions[this.textOffset].x, this._positions[this.textOffset].y); }
return this.bounds.translate(this.positions[0].x + offset.dx, this.positions[0].y + offset.dy);
return this.bounds.translate(this._positions[this.textOffset].x + offset.dx,
this._positions[this.textOffset].y + offset.dy);
}
public Vector2d getPosition(int i) {
return this._positions[this.textOffset + i];
}
static long _nextInstanceId;

internal readonly int textSize;
internal readonly Vector2d[] positions;
readonly Vector2d[] _positions;
}
public class TextBlobBuilder {

this._text = text;
this._textOffset = offset;
this._size = size;
this.allocPos(size);
// Allocate a single buffer for all text blobs that share this text, to save memory and GC.
// It is assumed that all of `text` is being used. This may cause great waste if a long text is passed
// but only a small part of it is to be rendered, which is not the case for now.
this.allocPos(text.Length);
}
internal void allocPos(int size) {

}
public void setPosition(int i, Vector2d position) {
this.positions[this._textOffset + i] = position;
}
public void setBounds(Rect bounds) {
this._bounds = bounds;
}

this._size, this.positions, this._bounds, this._style);
this.positions = null;
return result;
}
}

6
Runtime/ui/txt/paragraph.cs


Layout layout = new Layout();
TextBlobBuilder builder = new TextBlobBuilder();
GlyphPosition[] glyphPositions = new GlyphPosition[this._text.Length + (this._paragraphStyle.ellipsis?.Length ?? 0)];
int ellipsizedLength = this._text.Length + (this._paragraphStyle.ellipsis?.Length ?? 0);
builder.allocPos(ellipsizedLength);
GlyphPosition[] glyphPositions = new GlyphPosition[ellipsizedLength];
int pGlyphPositions = 0;
for (int lineNumber = 0; lineNumber < lineLimit; ++lineNumber) {

for (int glyphIndex = 0; glyphIndex < textCount; ++glyphIndex) {
float glyphXOffset = layout.getX(glyphIndex) + justifyXOffset;
float glyphAdvance = layout.getCharAdvance(glyphIndex);
builder.positions[glyphIndex] = new Vector2d(glyphXOffset);
builder.setPosition(glyphIndex, new Vector2d(glyphXOffset));
glyphPositions[pLineGlyphPositions++] = new GlyphPosition(runXOffset + glyphXOffset,
glyphAdvance, new Range<int>(textStart + glyphIndex, textStart + glyphIndex + 1));
if (words != null && wordIndex < words.Length) {

正在加载...
取消
保存