From 9fbea8cd83cad1770070e834b1df477f2331e62b Mon Sep 17 00:00:00 2001 From: mattmcclaskey Date: Tue, 14 Nov 2023 09:50:47 -0500 Subject: [PATCH] requestAnimationFrame only when frames are ready --- core/display.js | 21 ++++++++++++--------- tests/README.md | 4 +++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/core/display.js b/core/display.js index 9de4d270..5fb7042c 100644 --- a/core/display.js +++ b/core/display.js @@ -115,7 +115,7 @@ export default class Display { this._screens[0].channel = new BroadcastChannel(`screen_${this._screenID}_channel`); this._screens[0].channel.addEventListener('message', this._handleSecondaryDisplayMessage.bind(this)); } else { - this._animationFrameID = window.requestAnimationFrame( () => { this._pushAsyncFrame(); }); + //this._animationFrameID = window.requestAnimationFrame( () => { this._pushAsyncFrame(); }); } Log.Debug("<< Display.constructor"); @@ -519,7 +519,6 @@ export default class Display { */ flush(onflush_message=true) { //force oldest frame to render - //window.requestAnimationFrame( () => { this._pushAsyncFrame(); }); this._asyncFrameComplete(0, true); if (onflush_message) @@ -898,13 +897,13 @@ export default class Display { } else if (rect.frame_id > newestFrameID) { //frame is newer than any frame in the queue, drop old frame if (this._asyncFrameQueue[0][3] == true) { - this._pushAsyncFrame(true); Log.Warn("Forced frame to canvas"); + this._pushAsyncFrame(true); this._droppedFrames += (rect.frame_id - (newestFrameID + 1)); this._forcedFrameCnt++; } else { - this._asyncFrameQueue.shift(); Log.Warn("Old frame dropped"); + this._asyncFrameQueue.shift(); this._droppedFrames += (rect.frame_id - newestFrameID); } @@ -933,6 +932,10 @@ export default class Display { If marked force, unloaded images will be skipped and the frame will be marked complete and ready for rendering */ _asyncFrameComplete(frameIx, force=false) { + if (frameIx >= this._asyncFrameQueue.length) { + return; + } + let currentFrameRectIx = this._asyncFrameQueue[frameIx][4]; if (force) { @@ -970,7 +973,11 @@ export default class Display { this._asyncFrameQueue[frameIx][4] = currentFrameRectIx; this._asyncFrameQueue[frameIx][3] = true; - //window.requestAnimationFrame( () => { this._pushAsyncFrame(); }); + if (force && frameIx == 0) { + this._pushAsyncFrame(true); + } else { + window.requestAnimationFrame( () => { this._pushAsyncFrame(); }); + } } /* @@ -1066,10 +1073,6 @@ export default class Display { this._pushAsyncFrame(true); } } - - if (!force) { - window.requestAnimationFrame( () => { this._pushAsyncFrame(); }); - } } _processRectScreens(rect) { diff --git a/tests/README.md b/tests/README.md index e1782646..474bc355 100644 --- a/tests/README.md +++ b/tests/README.md @@ -46,4 +46,6 @@ This table keeps track of performance of pre-defined recordings, defined in the | newyork.1 | 08233e6 | Macbook M1 Pro, 32GB RAM | macOS 12.2 | Chrome 106 | False | 2446ms | | losangeles.1 | 08233e6 | Macbook M1 Pro, 32GB RAM | macOS 12.2 | Chrome 106 | False | 2272ms | | newyork.1 | base64opt | Macbook M1 Pro, 32GB RAM | macOS 12.2 | Chrome 106 | False | 2273ms | -| losangeles.1 | base64opt | Macbook M1 Pro, 32GB RAM | macOS 12.2 | Chrome 106 | False | 1847ms | \ No newline at end of file +| losangeles.1 | base64opt | Macbook M1 Pro, 32GB RAM | macOS 12.2 | Chrome 106 | False | 1847ms | +| newyork.1 | 4a6aa73 | Macbook M1 Pro, 32GB RAM | macOS 12.2 | Chrome 119 | False | 2128ms | +| losangeles.1 | 4a6aa73 | Macbook M1 Pro, 32GB RAM | macOS 12.2 | Chrome 119 | False | 1766ms | \ No newline at end of file