requestAnimationFrame only when frames are ready

This commit is contained in:
mattmcclaskey 2023-11-14 09:50:47 -05:00
parent 4a6aa73f6d
commit 9fbea8cd83
No known key found for this signature in database
2 changed files with 15 additions and 10 deletions

View File

@ -115,7 +115,7 @@ export default class Display {
this._screens[0].channel = new BroadcastChannel(`screen_${this._screenID}_channel`); this._screens[0].channel = new BroadcastChannel(`screen_${this._screenID}_channel`);
this._screens[0].channel.addEventListener('message', this._handleSecondaryDisplayMessage.bind(this)); this._screens[0].channel.addEventListener('message', this._handleSecondaryDisplayMessage.bind(this));
} else { } else {
this._animationFrameID = window.requestAnimationFrame( () => { this._pushAsyncFrame(); }); //this._animationFrameID = window.requestAnimationFrame( () => { this._pushAsyncFrame(); });
} }
Log.Debug("<< Display.constructor"); Log.Debug("<< Display.constructor");
@ -519,7 +519,6 @@ export default class Display {
*/ */
flush(onflush_message=true) { flush(onflush_message=true) {
//force oldest frame to render //force oldest frame to render
//window.requestAnimationFrame( () => { this._pushAsyncFrame(); });
this._asyncFrameComplete(0, true); this._asyncFrameComplete(0, true);
if (onflush_message) if (onflush_message)
@ -898,13 +897,13 @@ export default class Display {
} else if (rect.frame_id > newestFrameID) { } else if (rect.frame_id > newestFrameID) {
//frame is newer than any frame in the queue, drop old frame //frame is newer than any frame in the queue, drop old frame
if (this._asyncFrameQueue[0][3] == true) { if (this._asyncFrameQueue[0][3] == true) {
this._pushAsyncFrame(true);
Log.Warn("Forced frame to canvas"); Log.Warn("Forced frame to canvas");
this._pushAsyncFrame(true);
this._droppedFrames += (rect.frame_id - (newestFrameID + 1)); this._droppedFrames += (rect.frame_id - (newestFrameID + 1));
this._forcedFrameCnt++; this._forcedFrameCnt++;
} else { } else {
this._asyncFrameQueue.shift();
Log.Warn("Old frame dropped"); Log.Warn("Old frame dropped");
this._asyncFrameQueue.shift();
this._droppedFrames += (rect.frame_id - newestFrameID); 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 If marked force, unloaded images will be skipped and the frame will be marked complete and ready for rendering
*/ */
_asyncFrameComplete(frameIx, force=false) { _asyncFrameComplete(frameIx, force=false) {
if (frameIx >= this._asyncFrameQueue.length) {
return;
}
let currentFrameRectIx = this._asyncFrameQueue[frameIx][4]; let currentFrameRectIx = this._asyncFrameQueue[frameIx][4];
if (force) { if (force) {
@ -970,7 +973,11 @@ export default class Display {
this._asyncFrameQueue[frameIx][4] = currentFrameRectIx; this._asyncFrameQueue[frameIx][4] = currentFrameRectIx;
this._asyncFrameQueue[frameIx][3] = true; 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); this._pushAsyncFrame(true);
} }
} }
if (!force) {
window.requestAnimationFrame( () => { this._pushAsyncFrame(); });
}
} }
_processRectScreens(rect) { _processRectScreens(rect) {

View File

@ -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 | | 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 | | 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 | | 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 | | 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 |