Mobile Safari中是否可以加速2D转换硬件? [英] Are 2D transforms hardware accelerated in Mobile Safari?

查看:99
本文介绍了Mobile Safari中是否可以加速2D转换硬件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常被告知CSS 3D变换在Mobile Safari中是硬件加速的,这使我想知道这是否意味着2D变换不是?我想不出为什么它们不会成为现实,因为它们基本上都可以实现为3D变换,但是我想肯定知道.

I've often been told that CSS 3D transforms are hardware accelerated in Mobile Safari which makes me wonder if the implication is that 2D transforms are not? I can think of no reason why they wouldn't be, since they can basically all be implemented as 3D transforms, but I would like to know for sure.

如果事实证明2D转换不是硬件加速的,那么对于任何原因的任何见解都将不胜感激.

If it turns out that 2D transforms are not hardware accelerated, any insight as to why would be much appreciated.

推荐答案

您是正确的,CSS 2D变换在Mobile Safari中不是硬件加速的,而3D变换是.我不确定为什么会这样,但是也许他们认为这对于大多数2D转换来说是过大的.不必要地使用GPU可能会对电池寿命产生不利影响.

You're right, CSS 2D transforms aren't hardware accelerated in Mobile Safari, but 3D transforms are. I'm not sure why it's that way, but perhaps they decided it was overkill for most 2D transforms. Using the GPU unnecessarily could adversely affect battery life.

将2D转换转换为3D转换非常容易,因此这并不是什么大问题.一种技巧是使用如下所述的translateZ(0): http://creativejs.com/2011/12/day-2-gpu-accelerate-your-dom-elements/

It's very easy to convert a 2D transform to a 3D transform so it isn't much of a problem. One trick is to use translateZ(0) as described here: http://creativejs.com/2011/12/day-2-gpu-accelerate-your-dom-elements/

编辑

Apple在他们的文档中没有说任何有关它的信息,因此很难获得权威的消息来源.这是苹果公司的Dean Jackson所说的(摘自 http://mir.aculo.us/2010/08/05/html5-buzzwords-in-action/):

Apple doesn't say anything about it in their documentation, so it is difficult to get an authoritative source. Here is what Dean Jackson from Apple had to say about it (from http://mir.aculo.us/2010/08/05/html5-buzzwords-in-action/):

本质上,任何将3D操作作为其功能之一的变换都将触发硬件合成,即使实际的变换是2D或根本不做任何事情(例如translate3d(0,0,0)).请注意,这只是目前的行为,将来可能会改变(这就是我们不记录或鼓励这样做的原因).但这在某些情况下非常有用,并且可以显着提高重绘性能.

In essence, any transform that has a 3D operation as one of its functions will trigger hardware compositing, even when the actual transform is 2D, or not doing anything at all (such as translate3d(0,0,0)). Note this is just current behaviour, and could change in the future (which is why we don’t document or encourage it). But it is very helpful in some situations and can significantly improve redraw performance.

Sencha的Ariya Hidayat写了一篇帖子,解释了移动浏览器上的硬件加速:

Ariya Hidayat from Sencha wrote a post explaining hardware acceleration on mobile browsers: http://www.sencha.com/blog/understanding-hardware-acceleration-on-mobile-browsers/. Here's a snippet from the post:

将CSS转换矩阵设置为translation3d或scale3d(即使不涉及3-D)的最佳实践来自以下事实:这些类型的矩阵会将动画元素切换为具有自己的图层,然后将其设置为与网页的其余部分和其他层组合在一起.但是您应该注意,创建和合成层要付出一定的代价,即内存分配.为了硬件加速,盲目地组合网页中的每个小元素是不明智的,这样会占用内存.

The best practice of setting the CSS transformation matrix to translate3d or scale3d (even though there is no 3-D involved) comes from the fact that those types of matrix will switch the animated element to have its own layer which will then be composited together with the rest of the web page and other layers. But you should note that creating and compositing layers come with a price, namely memory allocation. It is not wise to blindly composite every little element in the web page for the sake of hardware acceleration, you’ll eat memory.

这是html5rocks.com上的一篇文章,讨论了硬件加速: http://www.html5rocks.com/en/tutorials/speed/html5/.这是它的摘录:

Here is an article from html5rocks.com that discusses hardware acceleration: http://www.html5rocks.com/en/tutorials/speed/html5/. Here's a snippet from it:

当前大多数浏览器仅在有强烈迹象表明HTML元素将从中受益时才使用GPU加速.最有力的迹象表明已对其应用了3D变换.现在您可能并不想真正应用3D变换,但仍然可以从GPU加速中获得好处-没问题.只需应用身份转换即可:

-webkit-transform:translateZ(0);

Currently most browsers only use GPU acceleration when they have a strong indication that an HTML element would benefit from it. The strongest indication is that a 3D transformation was applied to it. Now you might not really want to apply a 3D transformation, but still gain the benefits from GPU acceleration - no problem. Simply apply the identity transformation:

-webkit-transform: translateZ(0);

Firefox和Internet Explorer已经使用硬件加速进行2D转换,因此如果WebKit浏览器(Chrome,Safari)在不久的将来将其包含在内,我也不会感到惊讶.

Firefox and Internet Explorer already use hardware acceleration for 2D transforms, so I wouldn't be surprised if the WebKit browsers (Chrome, Safari) include it in the near future.

这篇关于Mobile Safari中是否可以加速2D转换硬件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆