如何在 HTML5 画布上获取垂直同步回调?
如何在 HTML5 画布上垂直同步回调?
How can I vsync callback on HTML5 canvas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何在 HTML5 画布上垂直同步回调?
How can I vsync callback on HTML5 canvas?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
* 2017 年新答案 *
虽然这是 2011 年的旧答案,并且在当时是准确的,但“不存在这样的事情”的旧答案现在有些过时了。
目前,截至 2017 年,requestAnimationFrame() 在实践中已广泛用于与刷新周期同步,因此它现在实际上已成为 VSYNC 回调。
只要浏览器性能不受限制(例如快速桌面),它就会在 120Hz 游戏显示器上每秒进行 120 次回调,因此它现在可以扩展以监控所有 Web 浏览器中的刷新率(有少数例外,例如 Microsoft IE/Edge 的 105Hz 限制)。
在 Chrome 中,requestAnimationFrame() 的时间参数是 VSYNC 时间,并且根据 www.vsynctester.com,requestAnimationFrame() 的现代实现现在已成为事实上的 VSYNC 回调 - 它通常在上一个 VSYNC 页面翻转后立即回调,以为下一个刷新周期渲染帧(或 Windows 合成管理器,就此而言)。
PS 我现在是 W3C Web 平台工作组的特邀专家,目前有一项修改 HTML 5.2 DRAFT 8 的承诺,以澄清 rAF() 与刷新周期的同步。另外,我还写了一篇文章,用于进一步改进 HTML 5.2 或更高版本的 VSYNC API:http://www.blurbusters.com/blur-busters-working-on-changes-to-html-5-2/
* NEW 2017 answer *
Although this is an old 2011 answer, and accurate for its time, the old answer of "There is no such thing" is somewhat outdated now.
Currently, as of 2017, requestAnimationFrame() is now widely in practice to be synchronized to refresh cycles, so it has now defacto become the VSYNC callback.
It has 120 callbacks per second on 120Hz gaming monitors whenever browser performance is not constrained (e.g. fast desktops), so it now scales to monitor refresh rates in all web browsers (with a few exceptions, such as Microsoft IE/Edge's 105Hz limit).
In Chrome, the time parameter of requestAnimationFrame() is VSYNC time, and according to www.vsynctester.com modern implementations of requestAnimationFrame() has now become the defacto VSYNC callback -- it's typically called back right after the previous VSYNC page flip, to render a frame for the next refresh cycle (or windows compositing manager, for that matter).
P.S. I am now an Invited Expert in W3C Web Platform Working Group and currently have one commit in modifying HTML 5.2 DRAFT 8 to clarify rAF() synchronization to refresh cycles. Also, there's an article I've written for improving a VSYNC API further for HTML 5.2 or later: http://www.blurbusters.com/blur-busters-working-on-changes-to-html-5-2/
没有这样的事。浏览器应该负责执行适当的同步,您可以使用
requestAnimationFrame()
来帮助它 - 例如,请参阅 http://paulirish.com/2011/requestanimationframe-for-smart-animating/ 和 https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame。There's no such thing. The browser should take care of doing the appropriate syncs, and you can help it by using
requestAnimationFrame()
- see, for example, http://paulirish.com/2011/requestanimationframe-for-smart-animating/ and https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame.