onscreen and offscreen
本文来自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的更多相关文章
- app 性能优化的那些事(二)
来源:树下的老男孩 链接:http://www.jianshu.com/p/2a01e5e2141f 这次我们来说说iOS app中滑动的那些事.iOS为了提高滑动的流畅感,特意在滑动的时候将runl ...
- 【Qt for Android】OpenGL ES 绘制彩色立方体
Qt 内置对OpenGL ES的支持.选用Qt进行OpenGL ES的开发是很方便的,很多辅助类都已经具备.从Qt 5.0開始添加了一个QWindow类,该类既能够使用OpenGL绘制3D图形,也能够 ...
- iOS 性能优化总结
卡顿产生的原因 在 VSync信号到来后,系统图形服务会通过 CADisplayLink等机制通知 App,App主线程开始在 CPU中计算显示内容,比如视图的创建.布局计算.图片解码.文本绘制等.随 ...
- offscreen-render
offscreen-render 什么是offscreen-render?offscreen-render涉及的内容比较多,有offscreen-render那就有onscreen render,on ...
- 阅读 video on-screen display v6.0笔记
阅读 video on-screen display v6.0笔记 关于axi总线时钟的区分 需要弄清楚的是aclk, aclken, aresetn 信号是和video 有关的,axi4-lite的 ...
- CefSharp.OffScreen.Example
namespace CefSharp.OffScreen.Example { public class Program { private static ChromiumWebBrowser brow ...
- Android OpenGL ES 离屏渲染(offscreen render)
通常在Android上使用OpenGL ES,都是希望把渲染后的结果显示在屏幕上,例如图片处理.模型显示等.这种情况下,只需要使用Android API中提供的GLSurfaceView类和Rende ...
- Delphi GDI对象之脱屏位图(Offscreen Bitmaps),也叫内存位图
http://www.cnblogs.com/pchmonster/archive/2012/07/09/2583613.html 脱屏位图(Offscreen Bitmaps) 脱屏位图,也叫内存位 ...
- [HTML5] Handle Offscreen Accessibility
Sometime when some component is offscreen, but still get focus when we tab though the page. This can ...
随机推荐
- [SaltStack] 基础介绍
今天有时间把以前研究过的saltstack梳理总结下 -:) salt是干什么的我就不多说了, 大家Google下资料很多的, 简单来说就是func+puppet: 配置文件管理 远程命令调用 Cro ...
- AC日记——营业额统计 codevs 1296 (splay版)
营业额统计 思路: 每次,插入一个点: 然后找前驱后继: 来,上代码: #include <cmath> #include <cstdio> #include <iost ...
- 牛客网 牛客小白月赛1 I.あなたの蛙が帰っています-卡特兰数,组合数阶乘逆元快速幂
I.あなたの蛙が帰っています 链接:https://www.nowcoder.com/acm/contest/85/I来源:牛客网 这个题有点意思,是卡特兰数,自行百度就可以.卡特兰数用处 ...
- 吉首大学 问题 L: 小李子的老年生活
时间限制: 1 Sec 内存限制: 128 MB提交: 719 解决: 27 题目描述 小李子有n-1个朋友,分别编号为1..n-1,小李子的编号是n ,小李子的表面朋友的编号会与小李子编号互质 ...
- Jmeter(五十)_性能测试模拟真实场景下的用户操作
概述 我们在做性能测试的时候,不同的视角看到的结果都不一样. 例如响应时间 用户通过客户端向服务端发出请求的时间为: T1服务端接收到请求,处理该请求的时间为:T2服务端返回数据给客户端时间为: T3 ...
- 屏蔽国内广告的hosts
源码:https://github.com/easonjim/blackhosts bug提交:https://github.com/easonjim/blackhosts/issues
- Mac测试模拟慢网速
先普及一下Kb,KB,Kbps,Mb,Mbps等一些列概念 1Byte = 8bit 1KB (Kilobyte 千字节)=1024Byte 1MB (Megabyte,兆字节,简称“兆”)=1024 ...
- 详解UIView的frame、bounds和center属性
From: http://ios.wpjam.com/2011/08/29/uiview-frame-bounds-center/ 1.概要 翻开ios官方开发文档,赫然发现上面对这三个属性的解释如下 ...
- spring batch的使用和定时器Quart的使用
Spring Batch是一个基于Spring的企业级批处理框架,它通过配合定时器Quartz来轻易实现大批量的数据读取或插入,并且全程自动化,无需人员管理. 在使用spring batch之前,得对 ...
- C# Graphics
Graphics.FillPie 方法 填充由一对坐标.一个宽度.一个高度以及两条射线指定的椭圆所定义的扇形区的内部. Graphics.FillPie (Brush, Int32, Int32, I ...