开发学院手机开发Android 开发 Android 图形系统详解 阅读

Android 图形系统详解

 2010-09-06 08:33:00 来源:WEB开发网   
核心提示:本文试图讲述Android图形系统的底层实现,Android图形系统底层实现非常复杂,Android 图形系统详解,文档较少,没有使用比较流行的图形组建如X window, Cairo等,需要更新时,则将back buffer和front buffer互换,图片在附件中Android中的图形系统采用Client/Ser

本文试图讲述Android图形系统的底层实现。Android图形系统底层实现非常复杂,文档较少,没有使用比较流行的图形组建如X window, Cairo等。


Android中的图形系统采用Client/Server架构。Server (即SurfaceFlinger)主要由c++代码编写而成。Client端代码分为两部分,一部分是由Java提供的供应用使用的api,另一部分则是由c++写成的底层实现。下图概要介绍了android图形系统的架构以及使用到的主要组件。

Android图形系统中一个重要的概念和线索是surface。View及其子类(如TextView, Button)要画在surface上。每个surface创建一个Canvas对象(但属性时常改变),用来管理view在surface上的绘图操作,如画点画线。每个canvas对象对应一个bitmap,存储画在surface上的内容。

每个Surface通常对应两个buffer,一个front buffer, 一个back buffer。其中,back buffer就是canvas绘图时对应的bitmap (研究android_view_Surface.cpp::lockCanvas)。因此,绘画总是在back buffer上,需要更新时,则将back buffer和front buffer互换。

The window is tied to a Surface and the ViewRoot asks the Surface for a

Canvas that is then used by the Views to draw onto. After View draw its data to canvas, ViewRoot

will call surface.unlockCanvasAndPost(canvas) to schedule surfaceFlinger::composeSurfaces() which do the actually display to display panel. SurfaceFlinger handles to transfers drawn data in canvas to surface front buffer or backbuffer

Except for SurfaceViews, different views within the same ViewRoot share the same surface.


每个surface又对应一个layer, SurfaceFlinger负责将各个layer的front buffer合成(composite)绘制到屏幕上。

A Layer is something that can be composited by SurfaceFlinger (should have been called LayerFlinger). There are several types of Layers if you look in the code, in particular the regular ones (Layer.cpp) , they are backed by a Surface, and the LayerBuffer (very badly chosen name) which don't have a backing store, but receive one from their client. . Note that the GGLSurface type, should have

1 2 3 4  下一页

Tags:Android 图形

编辑录入:coldstar [复制链接] [打 印]