(转载)了解Android 4.1,之三:黄油项目 —— 运作机理及新鲜玩意

news/2023/12/4 21:54:54

 

Welcome back to GTKA, everyone's favorite investigative series where we learn all about the newest version of Android (with a heavy emphasis on "all"). The previous two episodes, if you didn't catch them, are here and here.

欢迎回到人见人爱的《了解Android》系列文章。从这个系列中,我们会了解Android新版本的所有(注意,是所有喔!)内容。如果你还没看过之前两篇的话,它们在这里和这里。

Today we'll be doing something a little different and looking at something near and dear to everyone's hearts: performance. Jelly Bean is crazy fast. Slap it on a Galaxy Nexus and it'll feel like a brand new phone. Scrolling is faster and smoother, and the touch response is hyper-sensitive. In addition to all the smoothness work, there are new transitions all over the place.

今天,我们要关注一些跟以前不同的内容,更贴近我们需求的东西:性能! Jelly Bean快的很疯狂啊!把它搞到一部Galaxy Nexus里,你会感觉好像拿了一台新手机一样。卷动是那么的迅速顺畅、而触摸响应是那么的敏感。此外,还多了很多动画效果! 

I'm sure you've all seen a sweeping overview of this, but those are boring. What exactly is new, and how did they do it? That's what we're here to figure out. So, grab your popcorn, kids; it's time to learn all about Project Butter.     How They Did It

我知道你们已经看过一些关于这个的说明,但它们写的都弱透了。到底哪些是新的,而它们又是如何做到的?我们马上就能搞清这些。好,抓上你的爆米花,孩子;我们来了解一下传说中的“黄油项目”吧。他们是怎么干的

So how do you make an 8 month old Galaxy Nexus run like a Galaxy S III? Lots of hard work. Hard work that was thoughtfully detailed to us at Google I/O by two of my favorite I/O presenters, Chet Haase and Romain Guy. An hour long PowerPoint presentation geared towards developers is not the most accessible thing in the world, so I'm going steal some slides and try to cover the more interesting parts, and (hopefully) condense it down to a few minutes. Doesn't that sound like fun?     VSync Turns Frame Drawing Into A Well-Oiled Machine

怎么才能让一部寿命已达八个月的老Galaxy Nexus跑的好似Galaxy S III一样呢?嗯,这需要很多努力。在Google I/O上,我最爱的两个I/O演讲者——Chet Haase 和Romain Guy为我们详细阐述了这些努力。长达一个小时的PPT演示着眼于说明开发者是怎样一群不容于世的存在,所以我干脆偷出一些包含有趣内容的页面,把它们压缩到几分钟内(希望如此),听起来很爽吧?垂直同步为帧绘制加油

_0006_Layer-2 _0007_Layer-1

_0006_Layer-2_0007_Layer-1

 

PC Gamers are probably familiar with the term "VSync." It's that graphics option checkbox that will stop your screen from tearing in a video game.

PC游戏玩家大概对垂直同步这个词很熟悉了。包含这个词的钩选框可以帮助你的游戏避免画面撕裂的问题。 

To understand what exactly VSync is, we're going to need a quick display primer: Video (ie a phone display doing stuff) is made of individual pictures called "frames." Smooth animation is usually 60 frames per second. Frames are made of pixels, and, when the display draws a frame, the pixels are filled in row by row. Got it? Good.

为了理解垂直同步到底是个什么东西,我们需要对显示系统做一个新手教学:视象(比如说手机屏幕显示的东西)是由一系列叫做“帧”的独立图片所组成的。平滑的动画一般需要每秒六十帧。而帧是由像素点构成的。当屏幕绘制一帧的时候,像素点是一行一行的进行填充的。明白?很好。

The display (LCD, AMOLED, whatever) gets each frame from the graphics chip, and starts drawing it line by line. Ideally, you want the display to get a new frame from the graphics chip after it is finished drawing the previous frame. Tearing occurs when the graphics chip loads a new frame in the middle of the LCD draw, so you get half of one frame and half of another.

显示屏(LCD,AMOLED或者别的什么)从图形芯片获取每帧的数据,然后一行一行的进行绘制。理想状况下,你期望显示屏在绘制完一帧之后,图形芯片整好能提供新帧的数据。图像撕裂的状况就发生在图形芯片在图像绘制到一半的时候,就载入了新一帧的数据,以致你最终得到的数据帧是半个帧的新数据和半个帧的老数据。 

VSync, well, synchronizes things. It tells the GPU to wait for the screen to finish its line by line drawing before loading the next frame.

而垂直同步,顾名思义,就是用来同步的。它告知GPU在载入新帧之前,要等待屏幕绘制完成前一帧。 

Android has always used VSync to stop screen tearing, but Jelly Bean takes things a step further. The VSync pulse is now used to start all the processing for the next frame.

Android一直使用垂直同步来避免屏幕撕裂。而Jelly Bean更进一步。垂直同步脉冲现在会贯穿于所有的图形运作过程。 

Most Android displays run at or around 60 frames per second (or 60 Hz, in display jargon). In order to have a smooth animation, you have to actually be able to process 60 frames per second - that means you've got 16ms to process each frame. If you take longer than 16ms, the animation will stutter, and that buttery smooth feeling we're aiming for melts away.

大多数Android显示系统是以每秒钟60帧的频率工作的(专业点说,叫60Hz)。为获得更平滑的动画,就必须具有每秒钟处理60帧的能力——意味着每帧只能花费16毫秒的时间。如果这个过程超过16毫秒,动画显示就会有停滞感,我们期待的如丝般顺滑的体验也就消失无踪了。

16 milliseconds isn't a lot of time, so you're going to want to make the most of it. In Ice Cream Sandwich, processing for the next frame would just kind-of lazily start whenever the system got around to it. In Jelly Bean, the whole process of making the next frame starts as soon as the last frame is finished, at the beginning of the VSync pulse. In other words, they're using as much of the 16ms as they can. Here's an example:

16毫秒不是很长的一段时间,所以你会希望充分利用它。在ICS中,系统对下一帧的处理有点懒加载的意思,需要的时候才进行处理。而在Jelly Bean中,整个进程将在上一帧刚结束时,在垂直同步脉冲开始时,就立刻开始下一帧的处理过程。换句话说,系统会尽量充分的利用那16毫秒。举个例子说:

Untitled-1

Untitled-1

 

This is what life is like without running everything off of VSync. In these slides, the numbers are frames. First the frame is processed by the CPU and GPU, and, when it's finished, it's handed to the display at the beginning of the next VSync.

这就是在没有进行全面垂直同步时的状态。在图片中,数字代表着帧。首先,帧由CPU和GPU进行处理,当处理完成后,在下一个垂直同步开始时交付显示。

So in this picture, Frame 0 is displayed, and, during the 16ms of display time, the CPU and GPU prepare the next frame. The calculations get done in time, and at the next VSync pulse, they hand over the next frame, "Frame 1." Great.

在例图里,先显示了第0帧,在16毫秒的显示时间内,CPU和GPU准备下一帧。运算按时完成了,在下一个垂直同步脉冲到达时,它们交付了下一帧:第1帧。很好。

We're now showing frame 1, and it's time to start working on frame 2. Something slows the system down, though, and processing for the next frame doesn't start until we're well into our 16ms time limit. The system now only has about 4ms to figure out frame 2, so the processing for it doesn't get finished in time. With no frame 2, the display is forced to show frame 1 again, for another 16ms. Team Android has dubbed this "Jank," and it basically means any animations happening during this time won't be fluid; the user will see stuttering.

显示了第一帧后,是时间完成第二帧了。但某些因素导致了系统变慢,所以,直到16毫秒即将过去时,下一帧的处理工作才刚刚开始。此时,仅剩4毫秒来绘制第二帧了。毫无意外的,这工作没及时完成。此时,显示屏在第二帧没完成的情况下,只能在后面的16毫秒内再次显示第一帧。Android小组将这种情况称为”废帧“,标示着此其间内所有的屏幕动效都无法及时传递,而用户会体验到停滞感。 

_0003_Layer-5

_0003_Layer-5

 

Here's the new way of doing things in Jelly Bean. All the processing for the next frame starts at the VSync pulse, so you're now making the most of your 16ms of render time.

这幅图展示了在Jelly Bean中事情是如何运作的。所有下一帧的运算工作都在垂直同步脉冲抵达时开始。这样16毫秒的渲染时间就会被充分利用了。 

Frame processing has moved from "Yeah whenever we get around to it," to a rigidly scheduled, highly organized affair. Sort of like the difference between a car mechanic and a NASCAR pit crew. In this example, all the processing happens within the 16ms time limit, all the frames get delivered on time, and you get a smooth, buttery experience.     Triple Buffering Stops Jank From Snowballing

帧处理由”不管三七二十一,反正我搞完了“,变成了高度组织,严格按照时间表执行。有点类似街边修汽车的和云斯顿赛车维修站的区别。在这个例子中,所有的处理都在16毫秒限制内发生,所有帧都按时交付,而用户则获得了平滑、流畅的体验。三倍缓冲解决了画面撕裂问题

VSync isn't the only thing that helps out animation smoothness, Android is also able to recover from a slowdown more smoothly.

除了垂直同步外,Android还使用了其它方式来使动效更顺畅。 

_0002_Layer-6

_0002_Layer-6

 

So what the heck is a "buffer"? Put simply, a buffer is the container the frame is built and stored in. We've been referring to frames by number, but really, those frames sit in one of the two buffers. Android is double buffered, a pretty typical setup, meaning it can display 1 frame while working on another. In this picture the buffers are labeled "A" and "B."  While displaying buffer A, the system starts building a new frame in buffer B. When that's ready, they swap buffers. B gets displayed, and A gets cleared and a new frame is worked on.

那么,到底什么是“缓冲”呢?简单的说,缓冲就是帧构建和保存的容器。我们在前面用序号指代帧,但实际上,这些帧其实是在两个缓冲中的。遵循惯例,Anroid采用双缓冲机制,意味着它可以在显示一帧的同时进行另一帧的处理。在图中,就是缓冲A和B。当显示缓冲A时,系统在缓冲B中构建新的帧。完成后,则交换缓冲。显示缓冲B,而A则被清空,继续下一帧的绘制。

_0001_Layer-7

_0001_Layer-7

 

The problem with double buffer arises when you take longer than 16ms to draw your frame. Here the processing on buffer B runs over, which means a stutter (Jank!) happens. Stuttering is bad and all, but the real problem here is all the white space in the CPU and GPU graphs, that's wasted time. In the first frame, buffer B runs over, so that buffer is in use until it can be displayed, buffer A is also in use, because it is being displayed for 2 frames in a row, and remember, you can only switch frames (and hence, buffers) at the VSync pulse. The CPU and GPU are out of usable buffers, so they just sit there. One slowdown puts the system behind, which causes more slowdowns. This was how Ice Cream Sandwich worked.

当某帧的绘制时间超过16毫秒时,双缓冲的问题就暴露出来了。如图所示,当缓冲B超时后,一个卡顿发生了。卡顿总是不好的,但更严重的问题在于图中代表CPU和GPU的图片之间的空白,这是对时间的浪费。在第一帧中,缓冲B超时,则在它被显示之前,都处于使用中的状态,而缓冲A因为为了填补空白,仍在显示,则也处于使用中的状态。我们知道,仅在收到垂直同步脉冲时,才会进行帧(缓冲)切换。则CPU和GPU受限于可以使用的缓冲数,不得不消极怠工。一步慢步步慢,这就是ICS的缺陷。 

_0000_Layer-8

_0000_Layer-8

 

In Jelly Bean, we've got a solution for 2 full buffers, a third one! Same situation as before, buffer B takes too long, and A is in use displaying the current frame. This time though, instead of wasting processing time during the repeated buffer, the systems creates a C buffer, and gets to work on the next frame. Triple buffering stops the stutter fest, and after the initial skip, the user sees a smooth animation. It's all about presenting a stiff upper lip to the user even though things aren't going so smoothly under the hood.

在Jelly Bean中,我们有了解决双缓冲问题的办法:再加入第三个缓冲!在前述的情况下,B缓冲超时,而A缓冲用于当前帧的显示中。此时,不会因前述原因造成时间的浪费,系统会新创建缓冲C,并继续下一帧的工作。三倍缓冲结束了频繁卡顿的产生,在初始化跳顿后,用户得到了平滑的动画效果。即便有些问题发生了,但系统还会努力给用户满意的结果

So why don't they just do triple buffering all the time? Well, as you can see from the diagram, triple buffering introduces a bit of input lag into the process. Look, for instance, at the distance between the rendering of buffer C (the blue/green part), and the displaying of it. So, when things are misbehaving, you get a choice of 2 evils: input lag (your touches taking longer to have an effect) or choppy animation.

那么,为什么不干脆一直用三倍缓冲呢?正如你在图中看到的,三倍缓冲在整个过程中引入了一些输入延迟。比如说,在缓冲C(暗绿色部分)渲染过程与它被显示之间。所以,当出现某些错误行为时,你有两个选项: 输入延迟(你的触摸操作生效时间会延长)或者画面卡顿。 

To address this, Jelly Bean doesn't do triple buffering all the time. It normally runs a double buffer, but that third one is around whenever you need it. This way you get less input lag, and when things go wrong, you've got a third buffer at the ready to help you recover.     The Results

为解决这个问题,Jelly Bean没有一直使用三倍缓冲。一般情况下,它只使用了双缓冲,但当需要的时候,会用三倍缓冲来进行增强。这样,即将输入延迟降低到最少,又能在发生意外的情况下保持画面流畅。结果 

The result of all this hard work is buttery smooth animation. The team was so impressed with their new animation aptitude that they spruced up many of the transition animations, which I will now present to you in excruciating detail. Check out ICS vs Jelly Bean, in super slow-mo.     New Animations

以上努力的结果是得到了顺畅的动画。我们都为簇新的动画效果震惊了,过会儿我会展示这些动画的详情。相对于Jelly Bean, ICS简直就像拉车的老牛一样。新动画 

Icon Launch Transitions - Left: ICS's no-frills app launch transition. Right: JB zooms in from the location of the icon

 

There isn't much to say about these videos, but I'll try my best. Ice Cream Sandwich (left) has an absolutely boring icon launch transition. It's just a simple stretch and fade to the center of the screen. In Jelly Bean (right), applications zoom out from the icon position. This manages to be both neater looking and more communicative: "You pressed this icon, and this is opening from it." I like it.

 

Uninstalling - Left: ICS just uses the standard screen transition. Right: Jelly Bean's fun "toilet flush" animation

 

Uninstall gets a cool transition too. It's a slide/fade/shrink animation to the bottom of the screen. It sort of reminds me of a toilet flush. The previous screen also gracefully slides into view when the app is gone.

 

Launching from within an app - Left: ICS does a simple fade. Right:  JB slides things all over the place.

 

This transition is pretty much the uninstall animation in reverse, and it is used all over the place. I think it's triggered whenever an app opens another app. So here, you see the play store launching an app, and you'll see it when something like Google Reader launches a web browser, it's all over the place.

 

Update: Googler Clarification!

 

The always-helpful Dianne Hackborn, an Android Framework Engineer, stopped by our Google+ page (you are following us on G+ right?) with some insight on this animation:

 

"One thing I'd like to clarify -- the "uninstall" and "launch" animations are actually the same thing. This is the animation set for a "task switch". That is, moving in the UI from one task to another. A task is the thing you see in recent tasks, so this effectively tells you that you are moving between tasks that would be seen in the recent tasks UI."

 

So there's even more communication through animation. Thanks Dianne!

 

Recent Apps - Left: ICS oddly fades to a blank desktop. Right: JB's awesome transition

 

Recent apps probably has the coolest animation out of the bunch. The app grows out of the thumbnail, which is, again, neat looking and communicative - the perfect use of an animation system like this.

 

And finally, the new Jelly Bean camera animation. Snapping a picture sends your still flying off to the right, and a swipe will bring it back. I didn't bother showing you the ICS version because, well, nothing happens.

 

That's about it for Project Butter. You really have to experience it to get the full effect. Everything is smooth and fast. It really is impressive how much more power they've managed to squeeze out of my old Nexus.

转载于:https://www.cnblogs.com/pang-blog/p/4875047.html


http://www.ppmy.cn/news/925233.html

相关文章

了解Android 4.1,之三:黄油项目 —— 运作机理及新鲜玩意

了解Android 4.1,之三:黄油项目 —— 运作机理及新鲜玩意 译者:biAji 原文作者: Ron Amadeo 发布:2012-07-27 13:55:39 挑错 How They Did It VSync Turns Frame Drawing Into A Well-Oiled Machine Triple Bufferin…

赛场计算机配置要求,云斯顿赛车2014 配置要求 电脑PC版配置要求高吗

云斯顿赛车2014 配置要求 电脑PC版配置要求高吗 来至STEAM的配置要求: Minimum: Processor: AMD Athlon 64 X2 6000 (2*3000 MHz) Memory: 2048 MB RAM Graphics: GeForce 8800 GT Recommended: Processor: Intel Core I5-760 (4*2800 MHz) Memory: 4096 MB RAM Gra…

杨辉三角 II

给定一个非负索引 rowIndex,返回「杨辉三角」的第 rowIndex 行。 在「杨辉三角」中,每个数是它左上方和右上方的数的和。 示例 1: 输入: rowIndex 3 输出: [1,3,3,1] 示例 2: 输入: rowIndex 0 输出: [1] 示例 3: 输入: rowIndex 1 输出: [1,1]…

Android性能优化篇[谷歌官方]

网上看到了个和Android性能优化相关的系列文章,觉的还不错,和大家分享下。 在Android领域,性能永远是一块大头。市场对这类人才的需求也是有增不减,而且薪资待遇也不错。如果大家想深入学习Android某个领域, 那性能这块…

QQ2012 for Linux (2012-12-21 07:50:57)

from : http://blog.sina.com.cn/s/blog_4e9471e50101cb8x.html QQ2012 for Linux? 对,都丢到那坑爹的发行版QQ把,QQ2012属于你! 第一步按照下面的提示执行即可 # cd /root # tar -zxvf qq2012.tar.gz -C/opt # cd /opt # ls # …

用 QQ-Plot 验证正太分布

一、问题&#xff1a; 检验一序列是否服从正态分布 序列为X {x1,x2...xN} 二、QQ图验证法&#xff1a; 1、将原序列按开序重新排列 x1<x2<...xi...<xN 2、计算QQ序列&#xff1a; &#xff08;1&#xff09;、样本均值和标准差 &#xff08;2&#xff09;、分…

Window向指定QQ客户端窗口发送消息

键盘上0~9的ASCII public static final int VK_0 0x30;public static final int VK_1 0x31;public static final int VK_2 0x32;public static final int VK_3 0x33;public static final int VK_4 0x3…

spring security整合QQ登录

最近在了解第三方登录的内容,尝试对接了一下QQ登录,此次记录一下如何实现QQ登录的过程,在这个例子中是和spring secuirty整合的,不整合spring secuirty也是一样的。 需求: 整合QQ登录 步骤: 1、在QQ互联上注册开发者身份 2、开发者身份审核通过后,创建一个自己的应用,…

特定用户QQ群聊天记录导出的实现

一、把QQ群的聊天记录txt格式导出 消息管理器 -> 选择要导出的群 -> 右击、导出 这里要注意 &#xff1a; 导出之后的 文本是 unicode 编码的&#xff0c;需要转换 || 之前不知道&#xff0c;搞了大半天。 重新建一个txt &#xff0c; 把原来的 txt 内容 复制 到 新的 tx…

QQ坦白说v1.1 软件 源码 解析

前言&#xff1a; 4.2号 精易论坛某大佬 发了一个关于 QQ坦白说的js代码&#xff0c;秒被和谐。。如图~ 正文 一&#xff1a;&#xff08;https我简用http表达&#xff09; 发现&#xff0c;腾讯只是和谐页面&#xff0c;并未和谐 http.get的发包。抓手机包吧&#xff0c;过…

如何用Java写QQ机器人 v2.0

如何用Java写QQ机器人 v2.0 前提simple-robot框架官方文档simple-robot mirai组件构建项目配置文件写一个监听器类编写启动类成功了失败了支持与赞助 这次我想不到什么开场白了&#xff0c;直接开始吧。 前提 IDE : IntelliJ IDEA JDK : JDK8 Maven: 3.6.0 simple-robot框架…

Java基础之【字符串操作以及自增自减操作】

加油&#xff0c;新时代打工人&#xff01; 基础不牢&#xff0c;地动天摇。对于刚毕业的大学生来说&#xff0c;基础不牢的话&#xff0c;很难轻松胜任一份工作。工作中用到很多基础性的语法。 虽然&#xff0c;工作了一年多&#xff0c;我们一起重新温习一下基础吧 一、Java…

duilib的通用窗口类WindowImplBase

文章目录 前言1、WindowImplBase类2、优点3、缺点4、示例5、自定义消息和事件消息的区别 前言 duilib程序中&#xff0c;编写自己的窗口类一般的继承关系有两种&#xff0c;一种是继承自CWindowWnd、INotifyUI、IMessageFilterUI&#xff0c;而第二种方式是继承自duilib封装好…

ps42k20服务器出现问题_使用高防服务器时需要注意哪些地方?

对于高防服务器来说&#xff0c;需要有一个稳定且硬件先进的机房&#xff0c;其次就是主机的速度跟选择服务器的信誉与售后服务要好&#xff0c;口碑的好还一定程度上反映了服务器的优劣&#xff0c;下面我就来具体讲解一下。 1、高防服务器安全稳定性高防服务器本身对于安全防…

ps42k20服务器出现问题_关于双机热备,你应该了解这些问题

双机热备是什么意思&#xff1f; 双机热备包括了广义与狭义两种意义。 从广义上讲&#xff0c;就是对于重要的服务&#xff0c;使用两台服务器&#xff0c;互相备份&#xff0c;共同执行同一服务。当一台服务器出现故障时&#xff0c;可以由另一台服务器承担服务任务&#xff0…

Redmi K20 Pro如何编译内核

Android 9 编译的环境: ubuntu 18.04 步骤一、安装编译内核需要的依赖 sudo apt-get install git ccache automake flex lzop bison \ gperf build-essential zip curl zlib1g-dev zlib1g-dev:i386 \ g-multilib python-networkx libxml2-utils bzip2 libbz2-dev \ libbz2-1.…

ps42k20服务器出现问题_鸿图之下什么时候开服?10月开服时间表一览|安卓|服务器|ios|游戏...

鸿图之下什么时候才能正式下载玩&#xff1f;10月21日正式开不删档不限号上线&#xff0c;玩家们想要知道的是几点钟正式开服&#xff0c;为此小编在下面给大家准备了一些开服时间表&#xff0c;包括服务器的详细介绍&#xff0c;玩家们都可以提前先了解一下哦&#xff01; 鸿图…

使用docker简单编译k20pro内核

简介# 本文将介绍一下如何使用docker编译红米k20pro的内核。作者当时尝试构建内核的原因是为了将3年前&#xff08;好像是吧&#xff09;购买的k20pro至尊版&#xff08;已退役&#xff0c;12GB内存&#xff0c;512GB硬盘&#xff09;制作成一个小的服务器。而如果只有安卓系统…

红米k20适配android q,比谷歌还快,红米K20 PRO首发安卓Q稳定版,只有华为心里苦...

原标题&#xff1a;比谷歌还快&#xff0c;红米K20 PRO首发安卓Q稳定版&#xff0c;只有华为心里苦 翘首以盼的安卓 Q终于在今天凌晨正式发布&#xff0c;作为安卓又一个新的版本&#xff0c;安卓Q在许多方面都带来了很多改变。按照以往的惯例来看&#xff0c;一般都是谷歌自己…

Redmi k20解锁/刷TWRP_Recovery/刷Magisk获取root

主要记录下全过程踩坑的点&#xff0c;以及解决办法&#xff0c;所有提到的工具&#xff0c;都统一打包存放到了度盘&#xff0c;链接如下&#xff0c;自取&#xff1a; 链接: https://pan.baidu.com/s/1h15Q5aJ32W2pu7_G1KQ8Xg 提取码: 9ass k20解锁 在开始之前&#xff0c;…
最新文章