使用具有“不透明”属性的图像可以获得更好的性能。财产?为什么?

发布于 2024-10-26 11:30:05 字数 258 浏览 4 评论 0 原文

我刚刚在该网站上找到了一些内容:iphoneexamples.com。 看着“显示图像”,我发现了一些新东西。

myImage.opaque = YES; // 对于性能来说明显不透明

有人可以向我解释一下吗?它适用于哪种类型(或用例)的图像?什么时候不呢? 很高兴知道。感谢您抽出时间...

i just found something on that site: iphoneexamples.com.
Looking to "Display images" i found something new to me.

myImage.opaque = YES; // explicitly opaque for performance

Could someone explain it to me, please? And for which kind (or usecase) of images does it work? When not?
Would be great to know. Thanks for your time...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

故人的歌 2024-11-02 11:30:05

iPhone GPU 是基于图块的渲染器。如果覆盖层在整个图块上完全不透明,则 GPU 可以忽略设置和处理与该特定图块下面的层相关的任何图形命令,并且不必对该图块中的像素进行合成。

如果您的图像没有覆盖完整的图块,GPU 仍然需要处理多个层。图块的大小取决于实现,但是微小的图形图像覆盖图块的可能性要小得多。覆盖多个图块的巨大图像将显示出不透明的最大优势。

The iPhone GPU is a tile-based renderer. If an overlaying layer is completely opaque over an entire tile, the GPU can ignore setting up and processing any graphics commands related to the layer underneath for that particular tile, in addition to not having to do compositing of the pixels in that tile.

If your image doesn't cover a complete tile, the GPU will still have to potentially process multiple layers. The size of a tile is implementation dependent, but tiny graphics images are far less likely to cover a tile. Huge images that cover multiple tiles will show the greatest advantage from being opaque.

痴者 2024-11-02 11:30:05

来自查看 iOS 编程指南

无论何时都将视图声明为不透明
可能

UIKit 使用不透明
每个视图的属性来确定
视图是否可以优化
合成操作。设置
将此属性的值设置为 YES
自定义视图告诉 UIKit 它确实如此
后面不需要渲染任何内容
你的观点。较少的渲染可能会导致
提高绘图性能
代码并普遍受到鼓励。的
当然,如果你设置了 opaque 属性
是,您的视图必须填充其
完全包围矩形
不透明的内容。

hotpaw2 指出了其幕后原因,可以在 iOS 版 OpenGL ES 编程指南

延迟的另一个优点
渲染是它允许 GPU
之前执行隐藏表面去除
片段被处理。像素
不可见的被丢弃而没有
采样纹理或执行
片段处理,显着
减少GPU的计算量
必须执行渲染图块。到
从中获得最大的利益
特征,绘制尽可能多的框架
内容尽可能不透明,并且
尽量减少混合、alpha 的使用
测试和丢弃指令
在 GLSL 着色器中。因为硬件
执行隐藏表面去除,它是
您的申请不需要
从前往后对基元进行排序。

From the View Programming Guide for iOS:

Declare Views as Opaque Whenever
Possible

UIKit uses the opaque
property of each view to determine
whether the view can optimize
compositing operations. Setting the
value of this property to YES for a
custom view tells UIKit that it does
not need to render any content behind
your view. Less rendering can lead to
increased performance for your drawing
code and is generally encouraged. Of
course, if you set the opaque property
to YES, your view must fills its
bounds rectangle completely with fully
opaque content.

hotpaw2 points out the behind-the-scenes reason for this, which can be found in the OpenGL ES Programming Guide for iOS:

Another advantage of deferred
rendering is that it allows the GPU to
perform hidden surface removal before
fragments are processed. Pixels that
are not visible are discarded without
sampling textures or performing
fragment processing, significantly
reducing the calculations that the GPU
must perform to render the tile. To
gain the most benefit from this
feature, draw as much of the frame
with opaque content as possible and
minimize use of blending, alpha
testing, and the discard instruction
in GLSL shaders. Because the hardware
performs hidden surface removal, it is
not necessary for your application to
sort primitives from front to back.

柏拉图鍀咏恒 2024-11-02 11:30:05

当视图或图层不透明时,您可以获得比不透明时更好的性能。如果它不是不透明的,图形系统必须将该层与下面的层合成以生成最终图像。如果它是不透明的,那么只需将像素复制到帧缓冲区即可。

You get better performance when a view or layer is opaque than when it's not. If it's not opaque, the graphics system has to composite that layer with the layers below to produce the final image. If it is opaque, then it's just a matter of copying the pixels to the frame buffer.

柠北森屋 2024-11-02 11:30:05

需要注意的一个棘手问题是,每当图像属性更改为新的 UIImage 时,UIImageView 都会将 opaque 属性重置为 FALSE。您可以显式签入代码并在对图像属性进行任何更改后设置不透明属性,或者您可以扩展 UIImageView 并提供自己的 setImage 实现,该实现在调用超级 setImage 方法后设置不透明。我只是偶然才知道这件事。

A little tricky issue to be aware of is that UIImageView will reset the opaque property to FALSE any time the image property is changed to a new UIImage. You could explicitly check in your code and set the opaque property after any change to the image property, or you could extend UIImageView and provide you own implementation of setImage that sets opaque after calling the super setImage method. I only found out about this by accident.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文