浏览代码

Optimize memory alloc of layout, and fix some warnings.

/main
Yuncong Zhang 5 年前
当前提交
96a4830a
共有 7 个文件被更改,包括 41 次插入25 次删除
  1. 2
      Runtime/ui/painting/picture.cs
  2. 21
      Runtime/ui/painting/txt/text_blob.cs
  3. 18
      Runtime/ui/txt/layout.cs
  4. 2
      Runtime/ui/txt/paint_record.cs
  5. 19
      Runtime/ui/txt/paragraph.cs
  6. 1
      Samples/UIWidgetSample/MaterialThemeSample.cs
  7. 3
      Samples/UIWidgetsGallery/demo/animation/home.cs

2
Runtime/ui/painting/picture.cs


case DrawTextBlob cmd: {
var state = this._getState();
var scale = XformUtils.getScale(state.xform);
var rect = cmd.textBlob.boundsInText.shift(cmd.offset);
var rect = cmd.textBlob.shiftedBoundsInText(cmd.offset);
rect = state.xform.mapRect(rect);
var paint = cmd.paint;

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


namespace Unity.UIWidgets.ui {
public class TextBlob {
internal TextBlob(string text, int textOffset, int textSize, Vector2d[] positions, Rect bounds, TextStyle style) {
internal TextBlob(string text, int textOffset, int textSize, Vector2d[] positions, Rect bounds,
TextStyle style) {
this.instanceId = ++_nextInstanceId;
this.positions = positions;
this.text = text;

}
public Rect boundsInText {
get { return this.bounds.shift(new Offset(this.positions[0].x, this.positions[0].y)); }
get { return this.bounds.translate(this.positions[0].x, this.positions[0].y); }
}
public Rect shiftedBoundsInText(Offset offset) {
return this.bounds.translate(this.positions[0].x + offset.dx, this.positions[0].y + offset.dy);
static long _nextInstanceId = 0;
static long _nextInstanceId;
internal readonly long instanceId;
internal readonly string text;
internal readonly int textOffset;

int _size;
Rect _bounds;
public void allocRunPos(painting.TextStyle style, string text, int offset, int size, float textScaleFactor = 1.0f) {
public void allocRunPos(painting.TextStyle style, string text, int offset, int size,
float textScaleFactor = 1.0f) {
this.allocPos(size);
}
internal void allocPos(int size) {
if (this.positions == null || this.positions.Length < size) {
this.positions = new Vector2d[size];
}

18
Runtime/ui/txt/layout.cs


public void doLayout(float offset, TextBuff buff, int start, int count, TextStyle style) {
this._start = start;
this._count = count;
if (this._advances == null || this._advances.Length < count) {
this._advances = new float[count];
}
if (this._positions == null || this._positions.Length < count) {
this._positions = new float[count];
}
this.allocAdvancesAndPositions(count);
_x = _y = _maxX = _maxY = 0;
this._advance = _doLayout(offset, buff, start, count, style, this._advances, this._positions, 0,

public void setTabStops(TabStops tabStops) {
this._tabStops = tabStops;
}
public void allocAdvancesAndPositions(int count) {
if (this._advances == null || this._advances.Length < count) {
this._advances = new float[count];
}
if (this._positions == null || this._positions.Length < count) {
this._positions = new float[count];
}
}
public int nGlyphs() {

2
Runtime/ui/txt/paint_record.cs


this._metrics = metrics;
this._dx = dx;
this._dy = dy;
this._offset = null;
}
public TextBlob text {

TextStyle _style;
TextBlob _text;
float _runWidth;
Offset _offset;
float _dx;
float _dy;
FontMetrics _metrics;

19
Runtime/ui/txt/paragraph.cs


? 0
: (this._width - this._lineWidths[lineNumber]) / (words.Count - 1);
int totalTextCount = this._computeLineStyleRuns(lineStyleRuns, lineRange, ref styleRunIndex);
this._computeLineStyleRuns(lineStyleRuns, lineRange, ref styleRunIndex, out int totalTextCount, out int maxTextCount);
bool mayConsiderEllipsis = lineNumber == lineLimit - 1 || this._paragraphStyle.maxLines == null;
int ellipsisLength = this._paragraphStyle.ellipsis.Length;
maxTextCount = mayConsiderEllipsis ? maxTextCount + ellipsisLength : maxTextCount;
layout.allocAdvancesAndPositions(maxTextCount);
GlyphPosition[] lineGlyphPositions = lineNumber == lineLimit - 1 || this._paragraphStyle.maxLines == null
? new GlyphPosition[totalTextCount + this._paragraphStyle.ellipsis.Length]
GlyphPosition[] lineGlyphPositions = mayConsiderEllipsis
? new GlyphPosition[totalTextCount + ellipsisLength]
: new GlyphPosition[totalTextCount];
int pLineGlyphPositions = 0;
for (int i = 0; i < lineStyleRuns.Count; ++i) {

this._addPaintRecordsWithOffset(paintRecords, lineXOffset, yOffset);
}
int _computeLineStyleRuns(List<LineStyleRun> lineStyleRuns, LineRange lineRange, ref int styleRunIndex) {
void _computeLineStyleRuns(List<LineStyleRun> lineStyleRuns, LineRange lineRange, ref int styleRunIndex, out int totalTextCount, out int maxTextCount) {
// Exclude trailing whitespace from right-justified lines so the last
// visible character in the line will be flush with the right margin.
int lineEndIndex = this._paragraphStyle.textAlign == TextAlign.right ||

int totalTextCount = 0;
totalTextCount = maxTextCount = 0;
while (styleRunIndex < this._runs.size) {
var styleRun = this._runs.getRun(styleRunIndex);
if (styleRun.start < lineEndIndex && styleRun.end > lineRange.start) {

if (start < end) {
lineStyleRuns.Add(new LineStyleRun(start, end, styleRun.style));
totalTextCount += end - start;
maxTextCount = Math.Max(end - start, maxTextCount);
}
}

styleRunIndex++;
}
return totalTextCount;
}
PaintRecord _generatePaintRecordFromLineStyleRun(

1
Samples/UIWidgetSample/MaterialThemeSample.cs


}
class _MaterialThemeSampleWidgetState : State<MaterialThemeSampleWidget> {
int _currentIndex = 0;
public override Widget build(BuildContext context) {
return new Theme(
data: new ThemeData(

3
Samples/UIWidgetsGallery/demo/animation/home.cs


float scrollFactor = 5.0f
) : base(key: key) {
D.assert(maxHeight != null && maxHeight >= 0.0f);
D.assert(scrollFactor != null && scrollFactor >= 1.0f);
D.assert(scrollFactor >= 1.0f);
this.maxHeight = maxHeight;
this.scrollFactor = scrollFactor;
}

float? midScrollOffset = null
) : base(parent: parent) {
D.assert(midScrollOffset != null);
this.midScrollOffset = midScrollOffset ?? 0.0f;
}
public readonly float midScrollOffset;

正在加载...
取消
保存