Checking hardware acceleration availability? (Testing available)

后端 未结 1 841
独厮守ぢ
独厮守ぢ 2021-01-13 17:55

I\'ve written CSS that uses -webkit-transform, -webkit-perspective and several similar. My design looks the bees knees on machines where hardware acceleration is available b

相关标签:
1条回答
  • 2021-01-13 18:18

    Sadly, the answer seems to be 'you can't (yet)'.

    The Modernizr project lists HW acceleration amongst its 'undetectables': https://github.com/Modernizr/Modernizr/wiki/Undetectables.

    Part of the problem seems to be that HW acceleration is used on a case-by-case basis when rendering anything on the page. So, even though a browser may theoretically support HW acceleration, whether or not it will be used for any given operation (translation, transition, repaint, etc) won't be known in advance.

    You could imagine a detection scheme that used profiling to detect the change in performance with/without HW acceleration - but the things that use HW acceleration happen in a layer out of the page's view. You can't, for instance detect the frame-rate of a transition, even if you could reliably enable/disable HW acceleration.

    The webkit rendering API looks like the place this information might be available, but it doesn't look to be accessible via page-level Javascript (even though nodes in the DOM have RenderObjects attached to them): https://www.webkit.org/blog/114/webcore-rendering-i-the-basics/

    Looks like the only viable option is user-agent sniffing against a list of known accelerated browsers (yuck).

    0 讨论(0)
提交回复
热议问题