本文介绍了为什么没有浏览器足够聪明硬件加速没有技巧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些天有大量的网页建议您将这些规则添加到您的内容中,以使其硬件加速:

There are tons of webpages these days recommending you add these rules to your content to make it hardware accelerated:

transform: translate3d(0,0,0);
-webkit-transform: translate3d(0,0,0);

这总是让我很可笑。为什么浏览器需要我的帮助来决定硬件加速?它会更快,对吧?那么为什么不只是做呢?为什么要等我把浏览器欺骗进去?

This always struck me as ridiculous. Why should the browser need my help to decide to hardware accelerate? It's going to be faster, right? So why not just do it? Why wait for me to "trick" the browser into it?

另一种提出这个问题的方法可能是,每个基线/重置样式表都包含这些行

Another way of asking this question might be, why doesn't every baseline/reset stylesheet include the lines

* {
    transform: translate3d(0,0,0);
    -webkit-transform: translate3d(0,0,0);
}


推荐答案

不能或不够智能使用硬件加速。相反,你所指的只是真正适用于WebKit,尤其是WebKit的移动版本。 Firefox和IE都是硬件加速的,它们自动将页面分割成在GPU上合成的图层。这就是为什么他们通常吹过Chrome渲染速度测试。

It's not so much that browsers can't be or aren't smart enough to use hardware-acceleration. Instead, what you are referring to only really applies to WebKit, and especially to mobile versions of WebKit. Firefox and IE both hardware-accelerate everything, and they automatically split the page into "layers" that are composited on the GPU. That's why they usually blow past Chrome on rendering speed tests. WebKit, on the other hand, has never really been adapted to have more than simple layers acceleration.

因为Firefox和IE可以利用Windows平台上的Direct2D渲染(其中每个绘图操作都是硬件加速的),它本质上是一个要求,他们能够做硬件加速合成。如果他们只是加速绘图操作而不是合成,他们将失去大部分的速度优势从使用Direct2D在第一,因为它将需要在GPU和系统内存之间的复制,这是慢的。另一方面,我知道的所有WebKit渲染后端在软件中完全渲染,并且当它们复合时(如果正在使用GPU合成),会导致拷贝到GPU的损失。所以,它最终是一个权衡。如果你正在合成的图层不需要很多时间在CPU上渲染,在GPU上执行复制和复合并不总是有意义的。

Because Firefox and IE can take advantage of Direct2D rendering on Windows platforms (where every single drawing operation is hardware-accelerated), it was essentially a requirement that they be able to do hardware-accelerated compositing as well. If they had only accelerated the drawing operations and not the compositing, they would have lost most of the speed advantage from using Direct2D in the first place because it would have required copying between GPU and system memory, which is slow. On the other hand, all WebKit rendering backends that I'm aware of perform rendering completely in software, and incur the copy-to-GPU penalty when they composite (if GPU compositing is being used). So, it ends up being a tradeoff. If the layer you are compositing doesn't take much time to render on the CPU, it doesn't always make sense to perform the copy and composite on the GPU at all.

由于这一点,以及移动GPU的极其有限的性质,没有一个WebKit浏览器还没有开始做自动硬件加速,除非绝对需要(例如,当设置3D变换时)。如果你想要我的意见,我还补充说,我认为懒惰的WebKit开发商和支持公司这方面也是一个因素。使用GPU是错误的主要来源,所以它们更容易只是不使用它而不是解决问题。

Due to this, and also to the extremely limited nature of mobile GPU's, none of the WebKit browsers have yet begun to do automatic hardware-acceleration except when it's absolutely required (e.g. when setting a 3D transform). If you wanted my opinion, I would also add that I think laziness on the part of WebKit developers and supporting companies is a bit of a factor here as well. Using the GPU is a major source of bugs, so it is easier for them to just not use it rather than fix the problems.

顺便说一下,Firefox for Android可以做GPU合成所有的时间,虽然你可能需要启用它在about:config;我不知道它是否默认启用。对于电脑,我建议使用Firefox或IE来快速渲染。

By the way, Firefox for Android can do GPU compositing all the time, although you might have to enable it in about:config; I don't know if it's on by default. For PCs, I would recommend using Firefox or IE for really fast rendering.

编辑:我还应该在最新版本的Android中添加硬件,加速到Skia,它处理几乎所有的2D渲染在操作系统上。在野外没有很多设备,但它的确意味着性能将提高在Android上的一切在不久的将来。也就是说,我不知道他们的Skia实现是否与我们可能喜欢的OpenGL无缝连接。合成仍然可能会产生一些额外的副本,直到它们处理它。

I should also add that in the very latest versions of Android, Google has added hardware-acceleration to Skia, which handles nearly all 2D rendering on the OS. Not many devices in the wild have this yet, but it does mean that performance will improve for everything on Android in the near future. That said, I don't know whether their Skia implementation works as seamlessly with OpenGL as we may like. Compositing still might incur some extra copies until they deal with it.

这篇关于为什么没有浏览器足够聪明硬件加速没有技巧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-02 21:06
查看更多