“CGLayer不再推荐”;(“CGLayer no longer recommended”; Is this the general consensus?)

编程入门 行业动态 更新时间:2024-10-13 00:37:30
“CGLayer不再推荐”;(“CGLayer no longer recommended”; Is this the general consensus?)

我写了一个iOS应用程序,我正在使用CGLayer非常成功。 在研究从这个应用程序中挤出更多性能的方法时,我发现了这篇博客文章: http : CGLayer其中作者非常广泛地声明CGLayer是永远不会被使用。 单独一个人的职位不值得关注,但我也发现有人认为这篇文章是值得关注的。

没有提供真正的细节。 例如,作者声称“有时它更快,有时它更慢”。 这让我想知道一般来说程序员是否会正确使用这个对象。

我想这个问题适合经验丰富的Cocoa / Cocoa Touch开发人员。 这有什么好处吗? CGLayer确实需要避免吗?如果有的话,是否存在具体的,可衡量的原因?

I've written an iOS app in which I'm using CGLayer quite successfully. While researching ways to squeeze a bit more performance out of this app, I came across this blog post: http://iosptl.com/posts/cglayer-no-longer-recommended/ in which the author very broadly states that CGLayer is to never be used. An individual post alone is not cause for concern, but I've also found people referring to this post as something to abide by.

No real specifics are offered. For instance, the author states that "sometimes it's faster, sometimes it's slower". This makes me wonder if the concern is that, in general, programmers will not use this object correctly.

I suppose this question is for the seasoned Cocoa/Cocoa Touch developers. Is there any merit to this? Is CGLayer indeed something to avoid and if so, are there specific, measurable reasons as to why?

最满意答案

从我的回答开始,我想得出结论,完全是你自己的设计决定,你是否会在你的应用程序中使用CGLayer 。

真实的是,如果你在屏幕上绘图,它可能会在iOS平台上没有任何东西。 在iOS上,基本屏幕组成块是CALayer 。 CALayer采用Quartz(CG)图形上下文在屏幕上绘制,这可能是CGLayer本身创建的上下文。 现在, CALayer本身就是硬件加速,会尝试将任何图形内容缓存到显卡并重用它们。 这就是我们之前使用CGLayer的目的。

此外,如果涉及屏幕外渲染, CALayer可以在shouldRasterize设置为YES并且在某些其他情况下执行此操作。 但是,请记住,在将呈现的内容移交给GPU之前,屏幕外组合也是CPU执行的另一项任务。 所以再没有明显的赢家。

在创建不会在屏幕上绘制的CG上下文时, CGLayer会特别方便,就像PDF上下文一样。

我不确定为什么Apple开发团队要求完全避开CGLayer 。 可能存在一些潜在的架构缺陷,但这是无证的,直到约会。 但是,在我们确定并且我们已经在CGLayer架构上设计现有应用程序CGLayer ,我没有找到完全放弃它的任何具体原因。

To start with my answer, I would like to conclude that its totally your own design decision that whether you would use CGLayer in your app or not.

The real thing is that if you are drawing something on-screen, it will possibly buy you nothing on iOS platform. On iOS, the basic screen composition block is a CALayer. CALayer takes a Quartz(CG) graphics context to draw that on screen and that might be a context created by CGLayer itself. Now, CALayer being hardware accelerated by itself, would try to cache any graphics content to graphics card and reuse them. And that's the purpose what we had used a CGLayer previously.

Also, if offscreen rendering is concerned, a CALayer can do that when shouldRasterize is set to YES and under some other circumstances. However, keep in mind that offscreen composition is again another task performed by CPU before handing over the rendered content to GPU. So again there is no clear winner.

CGLayer would be particularly handy when creating a CG context that wont be drawn on screen, like a PDF context.

I'm not sure why Apple development team has asked one to avoid CGLayer completely. Might be there are some underlying architectural flaw but that is undocumented, till date. However, until we are sure about that and we have existing apps designed over CGLayer architecture, I dont find any specific reason to completely abandon that.

更多推荐

本文发布于:2023-08-04 23:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1423406.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:longer   CGLayer   recommended   consensus   general

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!