Skip to content

Commit

Permalink
TextBlockTextRenderer: does not update texture snapshot until render(…
Browse files Browse the repository at this point in the history
…) is called to avoid multiple texture snapshot updates in the same frame, which should slightly improve performance
  • Loading branch information
joshtynjala committed Apr 13, 2017
1 parent 42b8ce9 commit af4c441
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions source/feathers/controls/text/TextBlockTextRenderer.as
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ package feathers.controls.text
*/
protected var _needsNewTexture:Boolean = false;

/**
* @private
*/
protected var _needsUpdateSnapshot:Boolean = false;

/**
* @private
*/
Expand Down Expand Up @@ -1351,6 +1356,14 @@ package feathers.controls.text
*/
override public function render(painter:Painter):void
{
if(this._needsUpdateSnapshot)
{
this._needsUpdateSnapshot = false;
if(this._content !== null)
{
this.refreshSnapshot();
}
}
if(this.textSnapshot !== null)
{
var starling:Starling = this.stage !== null ? this.stage.starling : Starling.current;
Expand Down Expand Up @@ -1404,11 +1417,13 @@ package feathers.controls.text
if(snapshotIndex < 0)
{
var snapshot:Image = this.textSnapshot;
snapshot.visible = this._snapshotWidth > 0 && this._snapshotHeight > 0 && this._content !== null;
}
else
{
snapshot = this.textSnapshots[snapshotIndex];
}
snapshot.pixelSnapping = this._pixelSnapping;
snapshot.x = xPosition / scaleFactor;
snapshot.y = yPosition / scaleFactor;
snapshotIndex++;
Expand Down Expand Up @@ -1711,22 +1726,11 @@ package feathers.controls.text

if(contentStateChanged || this._needsNewTexture)
{
if(this._content !== null)
{
this.refreshSnapshot();
}
if(this.textSnapshot !== null)
{
this.textSnapshot.visible = this._snapshotWidth > 0 && this._snapshotHeight > 0 && this._content !== null;
this.textSnapshot.pixelSnapping = this._pixelSnapping;
}
if(this.textSnapshots !== null)
{
for each(var snapshot:Image in this.textSnapshots)
{
snapshot.pixelSnapping = this._pixelSnapping;
}
}
//we're going to update the texture in render() because
//there's a chance that it will be updated more than once per
//frame if we do it here.
this._needsUpdateSnapshot = true;
this.setRequiresRedraw();
}
}

Expand Down

0 comments on commit af4c441

Please sign in to comment.