Skip to content

Commit af4c441

Browse files
committed
TextBlockTextRenderer: does not update texture snapshot until render() is called to avoid multiple texture snapshot updates in the same frame, which should slightly improve performance
1 parent 42b8ce9 commit af4c441

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

source/feathers/controls/text/TextBlockTextRenderer.as

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ package feathers.controls.text
310310
*/
311311
protected var _needsNewTexture:Boolean = false;
312312

313+
/**
314+
* @private
315+
*/
316+
protected var _needsUpdateSnapshot:Boolean = false;
317+
313318
/**
314319
* @private
315320
*/
@@ -1351,6 +1356,14 @@ package feathers.controls.text
13511356
*/
13521357
override public function render(painter:Painter):void
13531358
{
1359+
if(this._needsUpdateSnapshot)
1360+
{
1361+
this._needsUpdateSnapshot = false;
1362+
if(this._content !== null)
1363+
{
1364+
this.refreshSnapshot();
1365+
}
1366+
}
13541367
if(this.textSnapshot !== null)
13551368
{
13561369
var starling:Starling = this.stage !== null ? this.stage.starling : Starling.current;
@@ -1404,11 +1417,13 @@ package feathers.controls.text
14041417
if(snapshotIndex < 0)
14051418
{
14061419
var snapshot:Image = this.textSnapshot;
1420+
snapshot.visible = this._snapshotWidth > 0 && this._snapshotHeight > 0 && this._content !== null;
14071421
}
14081422
else
14091423
{
14101424
snapshot = this.textSnapshots[snapshotIndex];
14111425
}
1426+
snapshot.pixelSnapping = this._pixelSnapping;
14121427
snapshot.x = xPosition / scaleFactor;
14131428
snapshot.y = yPosition / scaleFactor;
14141429
snapshotIndex++;
@@ -1711,22 +1726,11 @@ package feathers.controls.text
17111726

17121727
if(contentStateChanged || this._needsNewTexture)
17131728
{
1714-
if(this._content !== null)
1715-
{
1716-
this.refreshSnapshot();
1717-
}
1718-
if(this.textSnapshot !== null)
1719-
{
1720-
this.textSnapshot.visible = this._snapshotWidth > 0 && this._snapshotHeight > 0 && this._content !== null;
1721-
this.textSnapshot.pixelSnapping = this._pixelSnapping;
1722-
}
1723-
if(this.textSnapshots !== null)
1724-
{
1725-
for each(var snapshot:Image in this.textSnapshots)
1726-
{
1727-
snapshot.pixelSnapping = this._pixelSnapping;
1728-
}
1729-
}
1729+
//we're going to update the texture in render() because
1730+
//there's a chance that it will be updated more than once per
1731+
//frame if we do it here.
1732+
this._needsUpdateSnapshot = true;
1733+
this.setRequiresRedraw();
17301734
}
17311735
}
17321736

0 commit comments

Comments
 (0)