`
nanapoleon
  • 浏览: 48319 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

How about some Android graphics true facts?--转

 
阅读更多
How about some Android graphics true facts?

I get tired of seeing so much misinformation posted and repeated all over the place about how graphics rendering works on Android. Here is some truth:

• Android has always used some hardware accelerated drawing. Since before 1.0 all window compositing to the display has been done with hardware.

• This means that many of the animations you see have always been hardware accelerated: menus being shown, sliding the notification shade, transitions between activities, pop-ups and dialogs showing and hiding, etc.

• Android did historically use software to render the contents of each window. For example in a UI like http://www.simplemobilereview.com/wp-content/uploads/2010/12/2-home-menu.png there are four windows: the status bar, the wallpaper, the launcher on top of the wallpaper, and the menu. If one of the windows updates its contents, such as highlighting a menu item, then (prior to 3.0) software is used to draw the new contents of that window; however none of the other windows are redrawn at all, and the re-composition of the windows is done in hardware. Likewise, any movement of the windows such as the menu going up and down is all hardware rendering.

• Looking at drawing inside of a window, you don’t necessarily need to do this in hardware to achieve full 60fps rendering. This depends very much on the number of pixels in your display and the speed of your CPU. For example, Nexus S has no trouble doing 60fps rendering of all the normal stuff you see in the Android UI like scrolling lists on its 800x480 screen. The original Droid however struggled with a similar screen resolution.

• "Full" hardware accelerated drawing within a window was added in Android 3.0. The implementation in Android 4.0 is not any more full than in 3.0. Starting with 3.0, if you set the flag in your app saying that hardware accelerated drawing is allowed, then all drawing to the application’s windows will be done with the GPU. The main change in this regard in Android 4.0 is that now apps that are explicitly targeting 4.0 or higher will have acceleration enabled by default rather than having to put android:handwareAccelerated="true" in their manifest. (And the reason this isn’t just turned on for all existing applications is that some types of drawing operations can’t be supported well in hardware and it also impacts the behavior when an application asks to have a part of its UI updated. Forcing hardware accelerated drawing upon existing apps will break a significant number of them, from subtly to significantly.)

• Hardware accelerated drawing is not all full of win. For example on the PVR drivers of devices like the Nexus S and Galaxy Nexus, simply starting to use OpenGL in a process eats about 8MB of RAM. Given that our process overhead is about 2MB, this is pretty huge. That RAM takes away from other things, such as the number of background processes that can be kept running, potentially slowing down things like app switching.

• Because of the overhead of OpenGL, one may very well not want to use it for drawing. For example some of the work we are doing to make Android 4.0 run well on the Nexus S has involved turning off hardware accelerated drawing in parts of the UI so we don’t lose 8MB of RAM in the system process, another 8MB in the phone process, another 8MB in the system UI process, etc. Trust me, you won’t notice -- there is just no benefit on that device in using OpenGL to draw something like the status bar, even with fancy animations going on in there.

• Hardware accelerated drawing is not a magical silver bullet to butter-smooth UI. There are many different efforts that have been going on towards this, such as improved scheduling of foreground vs. background threads in 1.6, rewriting the input system in 2.3, strict mode, concurrent garbage collection, loaders, etc. If you want to achieve 60fps, you have 20 milliseconds to handle each frame. This is not a lot of time. Just touching the flash storage system in the thread that is running the UI can in some cases introduce a delay that puts you out of that timing window, especially if you are writing to storage.

• A recent example of the kinds of interesting things that impact UI smoothness: we noticed that ICS on Nexus S was actually less smooth when scrolling through lists than it was on Gingerbread. It turned out that the reason for this was due to subtle changes in timing, so that sometimes in ICS as the app was retrieving touch events and drawing the screen, it would go to get the next event slightly before it was ready, causing it to visibly miss a frame while tracking the finger even though it was drawing the screen at a solid 60fps.

• When people have historically compared web browser scrolling between Android and iOS, most of the differences they are seeing are not due to hardware accelerated drawing. Originally Android went a different route for its web page rendering and made different compromises: the web page is turned in to a display list, which is continually rendered to the screen, instead of using tiles. This has the benefit that scrolling and zooming never have artifacts of tiles that haven’t yet been drawn. Its downside is that as the graphics on the web page get more complicated to draw the frame rate goes down. As of Android 3.0, the browser now uses tiles, so it can maintain a consistent frame rate as you scroll or zoom, with the negative of having artifacts when newly needed tiles can’t be rendered quickly enough. The tiles themselves are rendered in software, which I believe is the case for iOS as well. (And this tile-based approach could be used prior to 3.0 without hardware accelerated drawing; as mentioned previously, the Nexus S CPU can easily draw the tiles to the window at 60fps.)

• Hardware accleration does not magically make drawing performance problems disappear. There is still a limit to how much the GPU can do. A recent interesting example of this is tablets built with Tegra 2 -- that GPU can touch every pixel of a 1024x800 screen about 2.5 times at 60fps. Now consider the Android 3.0 tablet home screen where you are switching to the all apps list: you need to draw the background (1x all pixels), then the layer of shortcuts and widgets (let’s be nice and say this is .5x all pixels), then the black background of all apps (1x all pixels), and the icons and labels of all apps (.5x all pixels). We’ve already blown our per-pixel budget, and we haven’t even composited the separate windows to the final display yet. To get 60fps animation, Android 3.0 and later use a number of tricks. A big one is that it tries to put all windows into overlays instead of having to copy them to the framebuffer with the GPU. In the case here even with that we are still over-budget, but we have another trick: because the wallpaper on Android is in a separate window, we can make this window larger than the screen to hold the entire bitmap. Now, as you scroll, the movement of the background doesn’t require any drawing, just moving its window... and because this window is in an overlay, it doesn’t even need to be composited to the screen with the GPU.

• As device screen resolution goes up, achieving a 60fps UI is closely related to GPU speed and especially the GPU’s memory bus bandwidth. In fact, if you want to get an idea of the performance of a piece of hardware, always pay close attention to the memory bus bandwidth. There are plenty of times where the CPU (especially with those wonderful NEON instructions) can go a lot faster than the memory bus.
分享到:
评论
1 楼 nanapoleon 2012-02-01  
现在网上满天飞的各类关于Android图像渲染的水文实在让我不爽,下面给大家一些关于Android硬件渲染的事实真相,硬件加速并非大家想的那么完美,而我们也一直在改进!

       1. Android 一直在使用硬件加速。实际上从1.0版本之后,所有的窗口元素的合成与显示都是通过硬件完成的。

       2.这意味着许多你所看见的动画都是被加速过的:按钮的显示、通知栏下拉的阴影、不同Activity之间的切换动画、弹出窗口以及提示框的显示和隐藏等等等等。

       3.Android以前使用软件方式(与硬件加速相对应)来控制各个窗口元素的渲染,例如下图的UI,其中包括四个窗口组件:状态条、壁纸、桌面上的的启动器、以及菜单。如果其中一个元素更改了自身的内容,例如高亮一个菜单条目,对于3.0之前的版本,系统使用软件方式来绘制新的内容,然而并非所有的元素都需要被重新绘制,同时各个窗口元素的拼接也是通过硬件方式完成的。类似的,任何窗口的移动:例如菜单的上下运动是完全通过硬件方式渲染的。


       4. 现在我们来关注窗口元素的内部渲染,实际上为了达到每秒60帧的FPS,你并不一定需要硬件加速。帧速取决于要显示的像素的数量以及CPU的速度。比如说,二儿子完全可以以60FPS的速度在它800*480分辨率的屏幕上完成任何普通的原生UI动画,例如列表的滚动等,完全没有问题。而最初的Droid系列却很难达到这样的速度。

       5.在Android3.0中可以实现窗口的”完全”的硬件加速绘制。而在Android 4.0中也没有引入更多的功能。 从3.0开始,如果在你的应用中设置了一个标志允许硬件加速,那么此时所有的窗口的绘制都会交给GPU来完成。在Android 4.0中最主要的改变就是:在面向Android4.0或更高版本的应用中,硬件加速是被默认开启的,再也不需要在配置文件中设置 android:handwareAccelerated=”true”.(而我们不允许之前的应用默认打开硬件加速,是因为光靠硬件加速,无法很好的完成某些特殊的绘制操作;同时在应用需要其中一部分UI更新的时候,会影响其的一些表现。对于目前现有的很多应用,强制开启硬件加速,会明显的中断应用的运行)

       6.硬件加速并不如大家所认为的那样完美。例如在基于PVR驱动的设备上(比如二儿子跟三儿子),光是在进程中开启OpenGL就得占用8M的RAM。对比一般进程的2M的开销实在是巨大。RAM是有限的,一大部分被拿去绘制,那么其他正在运行的进程就会因为缺少内存而出问题,比如降低应用间切换的速度。

       7.由于OpenGL的额外开销,我们最好不要过多的使用其进行绘制。比如我们现在在做的一些工作,就是为了让Android 4.0能在不使用硬件加速的情况下流畅的在二儿子上使用:这样我们就不需要在系统进程中浪费8MB的内存用,也不需要在手机进程中浪费额外的8M内存,或者是在系统UI进程中的8MB内存 等等等等。相信我,你不会注意到——用OpenGL来绘制一些类似状态栏或是华丽的动画是完全没有好处的。

       8.硬件加速并非流畅UI的“解药”。我们为了UI的流畅尝试了很多不同的方法,比如说在1.6中引入的对前台/后台进程的调度策略,在2.3中的对输入系统的重写,”严厉模式”的使用,并发的垃圾回收机制,载入器等等。如果你想达到60fps的帧速,你只有20毫秒的时间来处理每帧的内容。这时间实在不长,光是在UI进程中读取存储卡的操作产生的延时就会大于这个时限,尤其是在写操作的时候。

       9.举些最近发现的一些影响UI流畅度的例子:我们注意到在二儿子上,使用4.0时列表的滚动就不如使用2.3时流畅。而导致这个现象的原因则是计时器的轻微漂移:有些时候应用正在接收触摸事件并在屏幕上绘制,而在上一个动作还没完成的的时候,就接受到下一个事件并开始绘制,导致它丢失了当前这帧。尽管发生这种现象的时候,帧速能达到稳定的60FPS.(当然,这个问题已经修正)

       10.当人们比较Android跟IOS上浏览器的滚动流畅度的时候,他们所看见的差别并非开没开启硬件加速所导致。 最初的时候,Android使用了一种完全不同的渲染策略,并做了一些折中:网页被转换成一个”显示列表“,持续的在屏幕上进行绘制,而非使用块(Tiles)的形式。它有一个优点:就是在滚动或是缩放的时候不会发生有的块还没被渲染出来的现象(译者注:早期的IOS上这种现象非常明显,快速滚动到底部时要等一会网页才会一块一块的绘制出来)。 而这个方法的不给力之处就在于页面复杂的时候,帧速就明显低了。例如Android3.0,浏览器中现在开始使用块的方式进行渲染,于是它可以在滚动或是放大的时候保持一个稳定的帧速,自然也会出现新的块没有被立即渲染出来的情况。 而每个块都是以软件方式绘制的,我相信在IOS中也是这样的。(在3.0之前的版本中,没有开启硬件加速,基于块的策略也可以使用。而且如我之前提到的,二儿子可以很容易的达到60FPS)

       11.硬件加速不能如大家所想奇迹般的让绘制的问题统统消失。GPU的性能就是一个很重要的限制。最近一个很有趣的例子:基于英伟达的Tegra2的平板可以很容易的以60FPS的速度访问2.5次1280*800分辨率的屏幕中的任何一个像素。现在考虑到在Android 3.0中切换到所有应用列表的情形:你需要绘制背景(1x 所有的像素)、接着是快捷方式和桌面小工具(假设内容不多,花费0.5x),接着是所有应用的黑色背景(1x),接着是所有应用的ICON(0.5x)。显然,我们已经超过了原先的预算了,而此时我们还没完成各个独立窗口元素的拼接并做最后的显示。想要取得60FPS的动画,Android 3.0以及后续版本使用了一系列的小技巧。 其中主要的一个就是: 它将所有的窗口元素平铺在一个层中,而不是挨个拷贝到CPU的缓存中。但即使是这样,我们已然超出预算,幸好我们使用另一个技巧:因为Android中的背景是一个独立的窗口元素,我们可以将它设置的比屏幕更大来放置整幅位图,现在,用户开始滑动,背景跟着运动,此时并不需要任何特殊的绘制,仅仅是移动窗口即可,而由于这个窗口是在一个平铺层上,我们甚至不需要用GPU来将这个窗口元素组织到屏幕中输出。

       12.随着屏幕分辨率的不断升高,能否达到60FPS跟GPU的速度尤其是内存总线带宽息息相关。事实上,如果你想要提升硬件的效力,特别注意要提升内存总线的带宽。很多时候CPU(特别是带有完美的NEON指令集的CPU)会比内存总线块的多。

       UPDATE:下面居然有这么多讨论,但是我木有能力解释清楚相关的所有问题了。不过我会尽力在这里提供一些我认为比较有趣的观点。

       有些人认为盖世兔已经有了一个非常流畅的UI并指出他们已经超越三儿子并做了很多改进。事实上,大家忽略了很多设备的差异,盖世兔的屏幕是480*800而三儿子是720*1280。如果二儿子在它480*800的屏幕上都能达到60FPS,拥有更NB的CPU的盖世兔必须得同样流畅嘛。

       而两者之间最大的差别就是三儿子需要同时绘制2.4倍于盖世兔的像素。这相当于在单核上提升到2.4倍的速度。(需要指出 在UI渲染的时候,多核是没有意义的,因为渲染必须要在一个进程中完成,无法并行)

       这就是为什么硬件加速非常重要:随着像素的提升,GPU通常能更好的处理图像的运算。事实上,这是我们在Android中引入硬件加速的最大动力。在720*1280的屏幕上,现有的ARM CPU达到60FPS很吃力,但是通过GPU渲染就不同了。同样,在与盖世兔的比较中,同时打开没有硬件加速的应用,在三儿子中无法达到盖世兔同样的60FPS,是因为它得渲染2.4倍于盖世兔的像素。

       在最后,还得提及GPU的另外一个优势:许多绘制的效果变得更加容易。比如你要以软件形式绘制一个位图,你除了设置一个位移,不能做任何事。仅仅是缩小就得花上相当多的时间进行渲染。而在GPU中,此类转换则相当容易。这就是为神马新的默认主题Holo使用硬件加速绘制背景。而在没有开启硬件加速的应用中,此类背景会自动去掉~

-------找到了翻译。。。

相关推荐

    商务英语必备句典!下海的都来围观

    How many more minutes will it take for the train to arrive? - **含义**:还需要多少分钟火车才能到达? - **应用场景**:当你等待火车或其他交通工具时,希望了解剩余等待时间。 - **例句**:“请问还需要多少...

    HVDC and FACTS Controllers - Applications of Static Converters in Power Systems

    HVDC and FACTS Controllers: Applications of Static Converters in Power Systems focuses on the technical advances and developments that have taken place in the past ten years or so in the fields of ...

    Source Facts-crx插件

    语言:English (United States) 查看关于您新闻来源的事实。 很难知道哪个网站和新闻网络信任。那里有一个工具试图告诉我们什么是值得信赖的,什么是假新闻,但我们如何知道我们可以信任这些工具的来源?...

    FACTS Placement.rar_FACTS_FACTS-Placement_facts placement_placem

    here is uploaded "facts placement" codes and report.

    Android代码-freebase-cassandra

    This little Java project uploads the freebase-easy facts.txt (after transforming) to Apache Cassandra (3.x). This uploads transformed FreeBase data into a set of indexes and a set of tuples with IDs. ...

    facts-and-figures-2016-fr_FACT_

    本资料“facts-and-figures-2016-fr_FACT_”重点关注了2016年全球可再生能源的发展情况,提供了丰富的数据和事实,旨在帮助我们深入理解这一领域的现状、挑战以及未来趋势。 首先,可再生能源是环保和可持续发展的...

    Vanilla-JS-Numbers-Facts-App---AJAX-Fetch:Vanilla JS Numbers Facts应用程序-AJAX和Fetch

    在本项目"Vanilla-JS-Numbers-Facts-App---AJAX-Fetch"中,我们主要探讨的是如何使用纯JavaScript(Vanilla JS)构建一个数字事实应用,它利用AJAX和Fetch API从远程服务器获取数据并展示在网页上。这个应用展示了...

    Facts and Fallacies of Software Engineering

    While reading Facts and Fallacies of Software Engineering, you may experience moments of "Oh, yes, I had forgotten that," alongside some "Is that really true?" thoughts. The author of this book ...

    Prolog基础PPT学习教案.pptx

    - **事实**(Facts):像`father("Bill", "John")`这样的陈述是事实,它们表示已知的信息。 - **规则**(Rules):例如`grandFather(Person, GrandFather) :- father(Person, Father), father(Father, GrandFather)`...

    而他们是事实「And them's the facts」-crx插件

    每个维基百科文章的末尾添加了一句话 ...基于本文:http://www.clickhole.com/article/man-mission-man-adding-and-thems-facts-end-every-w-2182并应/ u / OgodHOWdisGE的要求。 支持语言:English

    PyPI 官网下载 | facts_generator-0.0.5.tar.gz

    标题中的"PyPI 官网下载 | facts_generator-0.0.5.tar.gz"表明这是一个在Python Package Index(PyPI)官方源上发布的软件包,名为`facts_generator`,版本号为0.0.5,其打包格式为tar.gz。PyPI是Python社区广泛使用...

    Android代码-actions-on-google-kotlin

    Quick Facts Port of the actions-on-google SDK to Kotlin. Kotlin and Java developers can quickly start building Actions for Google Assistant. Used in production for the Ticketmaster Assistant Action ...

    Cat-Facts-Website-Source:#Cat-Facts-Website-Source www.barker.spacecatfacts网站JavaScript和PHP源代码。 处理用于选择事实,关闭音频和其他网站功能的控件-Source website php

    对于"Cat-Facts-Website-Source",开发者可以从中学到实际的Web开发技巧,如前后端交互、数据库管理等。同时,社区成员可以提交改进或新增功能,推动项目不断发展。这种共享和协作的精神也是开源软件生态系统的一大...

    ansible-role-facts:在系统上放置Ansible的自定义事实

    ---- name : converge hosts : all become : yes gather_facts : yes roles : - role : robertdebock.facts facts : - key : datacenter value : Amsterdam - key : availability_zone value : west 机器需要用CI...

    Facts and Definitions about Three-Dimensional Curves

    三维曲线在微分几何中是研究空间轨迹的重要对象,它们由参数方程或者向量方程来描述。这里我们深入探讨这些概念。 1. **可视化**:为了理解三维曲线,可以采用以下方法: - 消去参数t,得到x、y、z之间的关系式,...

    另类的事实「Alternative Facts」-crx插件

    一个简单的扩展,将“替代事实”的所有引用更新为“谎言” 一个简单的扩展程序,将所有“替代事实”的所有引用更新为http://emojione.com免费提供的“谎言”图标表情符号 支持语言:English

    Repustar | Facts Matter-crx插件

    Repustar | Facts Matter是一款专为提升网络信息真实性而设计的Chrome浏览器插件。这款插件的核心功能是帮助用户鉴别并挑战互联网上的错误信息,确保用户接收到的信息基于可靠的数据和文档支持。在当前信息爆炸的...

    PyPI 官网下载 | facts_generator-0.0.6.tar.gz

    "facts_generator-0.0.6.tar.gz"是一个从PyPI(Python Package Index)官网上下载的压缩包,它包含了名为"facts_generator"的Python库的版本0.0.6。PyPI是Python社区的主要软件仓库,开发者可以在这里发布自己的...

    只是事实「Just the facts」-crx插件

    Just Facts以清晰,大胆的颜色突出显示关键信息(引号,名称,数字,日期),使休闲新闻阅读器和铁杆新闻迷都可以一目了然地掌握网页的要旨。切掉杂物,直接了解冷酷的事实。默认情况下,Just the Facts被激活以选择...

    Nutrition Facts Label-crx插件

    语言:English (UK) 营养成分标签 此扩展使食品博主能够在其食谱帖子中添加营养成分标签,并具有营养见解。 ... 这是我们为真棒WordPress社区做出贡献的动力的一部分。 我们发布此扩展程序的动机是基于在美食主题网站上...

Global site tag (gtag.js) - Google Analytics