在iOS上,CALayer位图(CGImage对象)如何显示在图形卡上? [英] On iOS, how do CALayer bitmaps (CGImage objects) get displayed onto Graphics Card?

查看:201
本文介绍了在iOS上,CALayer位图(CGImage对象)如何显示在图形卡上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS上,我可以创建3 CGImage 对象,并使用60fps下的 CADisplayLink 来执行

  self.view.layer.contents =(__bridge id)imageArray [counter ++%3]; 

里面的 ViewController ,并且每次,图像被设置为视图的CALayer 内容,这是一个位图。

这一切都可以改变屏幕显示的内容。屏幕将以60fps循环播放这3张图片。没有UIView的 drawRect ,没有CALayer的 display drawInContext ,或CALayer的委托的 drawLayerInContext 。它所做的只是改变CALayer的内容



我也尝试添加一个较小尺寸的子层到 self.view.layer ,并设置该子层的内容。这个子图层将循环显示这3张图片。



所以这与以前甚至在苹果电脑上都很相似,甚至在King's Quest III时代也是如此是DOS视频游戏,其中有1位图,屏幕只是不断显示位图是什么。



除了这个时候,它不是1位图,而是一棵树或位图链接列表,并且显卡不断使用Painter's Model将这些位图(位置和不透明度)绘制到主屏幕上。所以看起来, drawRect ,CALayer,一切,都是为了实现这个最终目的而设计的。

有用?显卡是否需要一个有序的位图列表或位图树? (然后不断显示它们,为了简化,我们没有考虑CA框架中的隐式动画)图形卡处理层实际发生了什么? (实际上,这种方法在iOS,Mac OS X和PC上几乎相同?)

例如,如果我们需要了解UIView和CALayer的工作方式,或者直接使用CALayer的位图,我们需要了解图形架构。)



在过去的日子(例如Windows 9x, Mac OS Classic等),屏幕基本上是一个大的帧缓冲区,并且例如所暴露的一切移动窗口必须由每个应用程序手动重新绘制。重绘主要由CPU完成,这对动画性能提出了上限。由于涉及重新绘制,动画通常非常闪烁。这种技术主要适用于没有太多动画的桌面应用程序。值得注意的是,Android使用(或至少曾经用过)这种技术,这是将iOS应用程序移植到Android时遇到的一个大问题。

过去的日子例如DOS,街机等等,也在Mac OS上使用很多),一些名为 sprite动画被用来提高性能并减少闪烁,方法是将运动图像保存在由硬件渲染的屏幕缓冲区中,并与显示器的vblank同步,这意味着即使在非常低端的系统上,动画也能保持平滑。但是,这些图像的尺寸非常有限,屏幕分辨率也很低,只有今天iPhone屏幕的10-15%左右。

On iOS, I was able to create 3 CGImage objects, and use a CADisplayLink at 60fps to do

self.view.layer.contents = (__bridge id) imageArray[counter++ % 3];

inside the ViewController, and each time, an image is set to the view's CALayer contents, which is a bitmap.

And this all by itself, can alter what the screen shows. The screen will just loop through these 3 images, at 60fps. There is no UIView's drawRect, no CALayer's display, drawInContext, or CALayer's delegate's drawLayerInContext. All it does is to change the CALayer's contents.

I also tried adding a smaller size sublayer to self.view.layer, and set that sublayer's contents instead. And that sublayer will cycle through those 3 images.

So this is very similar to back in the old days even on Apple ][ or even in King's Quest III era, which are DOS video games, where there is 1 bitmap, and the screen just constantly shows what the bitmap is.

Except this time, it is not 1 bitmap, but a tree or a linked list of bitmaps, and the graphics card constantly use the Painter's Model to paint those bitmaps (with position and opacity), onto the main screen. So it seems that drawRect, CALayer, everything, were all designed to achieve this final purpose.

Is that how it works? Does the graphics card take an ordered list of bitmaps or a tree of bitmaps? (and then constantly show them. To simplify, we don't consider the Implicit animation in the CA framework) What is actually happening down in the graphics card handling layer? (and actually, is this method almost the same on iOS, Mac OS X, and on the PCs?)

(this question aims to understand how our graphics programming actually get rendered in modern graphics cards, since for example, if we need to understand UIView and how CALayer works, or even use CALayer's bitmap directly, we do need to understand the graphics architecture.)

解决方案

Modern display libraries (such as Quartz used in iOS and Mac OS) use hardware accelerated compositing. The workings is very similar to how computer graphics libraries such as OpenGL work. In essence, each CALayer is kept in as a separate surface that is buffered and rendered by the video hardware much like a texture in a 3D game. This is exceptionally well implemented in iOS and this is why the iPhone is so well-known for having a smooth UI.

In the "old days" (i.e. Windows 9x, Mac OS Classic, etc), the screen was essentially one big framebuffer, and everything that was exposed by e.g. moving a window had to be redrawn manually by each application. The redrawing was mostly done by the CPU, which put an upper limit on animation performance. Animation were usually very "flickery" due to the redrawing involved. This technique was mostly suited for desktop applications without too much animation. Notably, Android uses (or at least used to use) this technique, which is a big problem when porting iOS applications over to Android.

Games of the old days days (e.g. DOS, arcade machines, etc, also used a lot on Mac OS classic), something called sprite animation was used to improve performance and reduce flickering by keeping the moving images in offscreen buffers that were rendered by the hardware and synchronized with the monitor's vblank, which meant that animations were smooth even on very low-end systems. However, the size of these images were very limited and the screen resolutions were low, only about 10-15% of the pixels of even an iPhone screen of today.

这篇关于在iOS上,CALayer位图(CGImage对象)如何显示在图形卡上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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