From af4c441e29bca1c1824ca43427881d5e7dd564dd Mon Sep 17 00:00:00 2001 From: Josh Tynjala Date: Thu, 13 Apr 2017 10:28:22 -0700 Subject: [PATCH] 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 --- .../controls/text/TextBlockTextRenderer.as | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/source/feathers/controls/text/TextBlockTextRenderer.as b/source/feathers/controls/text/TextBlockTextRenderer.as index 0c8aa9417b..e30854ff95 100644 --- a/source/feathers/controls/text/TextBlockTextRenderer.as +++ b/source/feathers/controls/text/TextBlockTextRenderer.as @@ -310,6 +310,11 @@ package feathers.controls.text */ protected var _needsNewTexture:Boolean = false; + /** + * @private + */ + protected var _needsUpdateSnapshot:Boolean = false; + /** * @private */ @@ -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; @@ -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++; @@ -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(); } }