开发者

Canvas FPS artificially limited to 100fps?

In this page that counts the number of frames rendered and prints the FPS onto the canvas, we can see that it tops out at 100fps, which seems suspicious at the least. Why is this?

<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="utf-8">
  <title>Canvas FPS artificial limiting</title>
 </head>
 <body>
  <canvas id="c" width="320" height="240"></canvas>
  <script>
   var c = document.getElementById('c').getContext('2d'),
    f = 0,
    s = new Date;
   setInter开发者_如何学Pythonval(function() {
    c.clearRect(0, 0, 320, 240);
    c.fillText(++f / ( ((+new Date) - s) / 1000 ), 8, 16);
   }, 0);
  </script>
 </body>
</html>

I'm currently having this problem on Firefox 4.0b6 and Ubuntu 10.10 beta.


I got it! According to this page:

https://developer.mozilla.org/en/window.setTimeout#Minimum_delay_and_timeout_nesting

setTimeout and setInterval are clamped to a minimum of 10ms on Firefox (which is 100 iterations per second) to avoid lock-ups and UI performance degradation. That means, delay values lower than this use 10ms instead (up to 100fps).

This is not a canvas problem; it's artificial limitation of the minimum delay on timers.

Edit: further reading suggests that Chrome does a 4ms clamp, which enables a 250fps artificial limit on timers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜