Created
November 13, 2017 18:34
-
-
Save SignpostMarv/add3bc35476fa2648bef63538158cc79 to your computer and use it in GitHub Desktop.
RequestHertzFrame.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RequestHertzFrame | |
{ | |
static get DEFAULT_UNKNOWN_HZ () | |
{ | |
return { | |
hz: NaN, | |
request: requestAnimationFrame, | |
cancel: cancelAnimationFrame, | |
}; | |
} | |
static get KNOWN_50_HZ () | |
{ | |
return { | |
hz: 50, | |
request: cb => setTimeout(cb, 1000 / 50), | |
cancel: id => clearTimeout(id), | |
}; | |
} | |
static get KNOWN_60_HZ () | |
{ | |
return { | |
hz: 60, | |
request: cb => requestAnimationFrame, | |
cancel: id => clearAnimationFrame, | |
}; | |
} | |
static InRange(min = 60, max = 60) | |
{ | |
return new Promise((yup, nope) => { | |
if (isNaN(min) || isNaN(max)) { | |
nope('min & max requested rate must be Numbers'); | |
} else if(min === min && 60 === max) { | |
yup(RequestHertzFrame.DEFAULT_UNKNOWN_HZ); | |
} else if (-Infinity === min) { | |
// do some race between rAF & rIC ? | |
} else if (false) { // replace with hardware detection | |
} else { | |
nope('Unsupported'); | |
} | |
}); | |
} | |
static MultipleOf(mode=0, ...hz=60) | |
{ | |
// do magic gubbins to figure out closest appropriate hz | |
// i.e. RequestHertzFrame.MultipleOf(12,15,50,60), | |
// where mode determines whether a 120hz monitor gives a 60fps requester or a 120fps requester | |
// where a tab has fullscreen content AND a monitor supports variable refresh rates, | |
// some value of mode should allow the previous example to drive a 48/96/144fps requester over a 50/100/60/120fps requester | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment