本文来自stackoverflow一位网友的解答,感觉非常不错就摘录了。

---------------------------------------------------------------------------

I don't think there is a rule written down anywhere, but hopefully this will help:

First, let's clear up some definitions. I think offscreen vs onscreen rendering is not a good way to think about it because offscreen rendering can be as fast as onscreen. The issue is whether the rendering is done in hardware or software.

There is also no difference between using layers and views. Views are just a thin wrapper around CALayer and they don't introduce any significant performance penalty. You can override the type of layer used by a view using the layerClass method if you want to have a view backed by a CAShapeLayer or CATileLayer, etc.

Generally, on iOS, pixel effects and Quartz / Core Graphics drawing are not hardware accelerated, and most other things are.

The following things are not hardware accelerated, which means that they need to be done in software (offscreen):

1) Anything done in a drawRect. If your view has a drawRect, even an empty one, the drawing is not done in hardware, and there is a performance penalty.

2) Any layer with the shouldRasterize property set to YES.

3) Any layer with a mask or drop shadow.

4) Text (any kind, including UILabels, CATextLayers, Core Text, etc).

5) Any drawing you do yourself (either onscreen or offscreen) using CGContexts.

Most other things are hardware accelerated, so they are much faster. However, this may not mean what you think it does.

Any of the above types of drawing are slow compared to hardware accelerated drawing, however they don't necessarily slow down your app because they don't need to happen every frame. For example, drawing a drop shadow on a view is slow the first time, but after it is drawn it is cached and is only redrawn if the view changes size or shape.

The same goes for rasterised views or views with a custom drawRect: the view typically isn't redrawn every frame, it is drawn once and then cached, so the performance after the view is first set up is no worse, unless the bounds change or you call setNeedsDisplay on it.

For good performance, the trick is to avoid using software drawing for views that change every frame. For example, if you need an animated vector shape you'll get better performance using CAShapeLayer or OpenGL than drawRect and Core Graphics. But if you draw a shape once and then don't need to change it, it won't make much difference.

Similarly, don't put a drop shadow on an animated view because it will slow down your frame rate. But a shadow on a view that doesn't change from frame to frame won't have any negative impact.

Another thing to watch out for is slowing down the view setup time. For example, suppose you have a page of text with drop shadows on all the text. This will take a very long time to draw initially since both the text and shadows all need to be rendered in software, but once drawn it will be fast. You will therefore want to set up this view in advance when your application loads, and keep a copy of it in memory so that the user doesn't have to wait ages for the view to display when it first appears on screen.

This is probably the reason for the apparent contradiction in the WWDC videos. For large, complex views that don't change every frame, drawing them once in software (after which they are cached and don't need to be redrawn) will yield better performance than having the hardware re-composite them every frame, even though it will be slower to draw the first time.

But for views that must be redrawn constantly, like table cells (the cells are recycled so they must be redrawn each time one cell scrolls offscreen and is re-used as it scrolls back onto the other side as a different row), software drawing will slow things down a lot.

onscreen and offscreen的更多相关文章

  1. app 性能优化的那些事(二)

    来源:树下的老男孩 链接:http://www.jianshu.com/p/2a01e5e2141f 这次我们来说说iOS app中滑动的那些事.iOS为了提高滑动的流畅感,特意在滑动的时候将runl ...

  2. 【Qt for Android】OpenGL ES 绘制彩色立方体

    Qt 内置对OpenGL ES的支持.选用Qt进行OpenGL ES的开发是很方便的,很多辅助类都已经具备.从Qt 5.0開始添加了一个QWindow类,该类既能够使用OpenGL绘制3D图形,也能够 ...

  3. iOS 性能优化总结

    卡顿产生的原因 在 VSync信号到来后,系统图形服务会通过 CADisplayLink等机制通知 App,App主线程开始在 CPU中计算显示内容,比如视图的创建.布局计算.图片解码.文本绘制等.随 ...

  4. offscreen-render

    offscreen-render 什么是offscreen-render?offscreen-render涉及的内容比较多,有offscreen-render那就有onscreen render,on ...

  5. 阅读 video on-screen display v6.0笔记

    阅读 video on-screen display v6.0笔记 关于axi总线时钟的区分 需要弄清楚的是aclk, aclken, aresetn 信号是和video 有关的,axi4-lite的 ...

  6. CefSharp.OffScreen.Example

    namespace CefSharp.OffScreen.Example { public class Program { private static ChromiumWebBrowser brow ...

  7. Android OpenGL ES 离屏渲染(offscreen render)

    通常在Android上使用OpenGL ES,都是希望把渲染后的结果显示在屏幕上,例如图片处理.模型显示等.这种情况下,只需要使用Android API中提供的GLSurfaceView类和Rende ...

  8. Delphi GDI对象之脱屏位图(Offscreen Bitmaps),也叫内存位图

    http://www.cnblogs.com/pchmonster/archive/2012/07/09/2583613.html 脱屏位图(Offscreen Bitmaps) 脱屏位图,也叫内存位 ...

  9. [HTML5] Handle Offscreen Accessibility

    Sometime when some component is offscreen, but still get focus when we tab though the page. This can ...

随机推荐

  1. 【剑指offer】二维数组中的查找☆

    题目描述 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数.     自己的思路实在 ...

  2. java gc --- 四种引用

    古龙有<七种武器>,java里有四种引用. 下文主要是对 <understanding-weak-references>这一博文的重点进行翻译 强引用,strong refer ...

  3. (5)ASP.NET HttpResponse 类

    HttpResponse 类用来封装来自 ASP.NET 操作的 HTTP 响应信息 https://msdn.microsoft.com/zh-cn/library/system.web.httpr ...

  4. (3)Django 配置

    一.settings django安装的应用程序 INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.c ...

  5. sprintf 心得

    [string print format]sprintf指的是字符串格式化命令. [主要功能]是把格式化的数据写入某个字符串中. sprintf是个变参函数. 使用sprintf对于写入buffer的 ...

  6. Codeforces 703D Mishka and Interesting sum(离线 + 树状数组)

    题目链接  Mishka and Interesting sum 题意  给定一个数列和$q$个询问,每次询问区间$[l, r]$中出现次数为偶数的所有数的异或和. 设区间$[l, r]$的异或和为$ ...

  7. HashMap之equals和hashCode小陷阱

    先以一段代码开始这篇blog. 01 public class Name { 02   03   private String first; //first name 04   private Str ...

  8. 某考试 T1 fair (18.5.1版)

    转化一下模型:每天可以选1也可以选0,但是任意前i天(i<=n)1的个数都必须>=0的个数,求总方案数/2^n. 然后可以发现这是一个经典题,随便推一下公式发现等于  C(n,n/2)/2 ...

  9. 终端应用变身文件 MD5/SHA1 校验工具

    担心下载的文件被恶意篡改?没有找到 Mac 平台文件校验工具?其实 Mac OS X 系统中已经内置了“文件 MD5/SHA1 校验工具”,它就藏身于终端(Terminal)应用中! 打开终端应用,输 ...

  10. poj 3648 线段树成段更新

    线段树成段更新需要用到延迟标记(或者说懒惰标记),简单来说就是每次更新的时候不要更新到底,用延迟标记使得更新延迟到下次需要更新or询问到的时候.延迟标记的意思是:这个区间的左右儿子都需要被更新,但是当 ...