Android GUI Architecture

来源:互联网 发布:诲女知之乎悔的意思 编辑:程序博客网 时间:2024/04/29 23:37


androidGUI Architecture as follow:




androidGUI系统由C语言的框架和JAVA语言的框架组成。

C语言的核心如下:

  1. PixelFlinger

  2. libui(框架库)

  3. SurfaceFlinger(Surface的管理)

  4. Skia图形图像引擎

  5. OpenGL3D引擎

  6. 各种JNI


java语言的核心如下:

  1. android.graphic(对应SKia图形库)

  2. android.view.Surface(构造各种介面)

  3. android.view.View及其继承类

  4. OpenGL的功能类

Android图形框架也可以分这么分为两部分:用于应用程序图形UI显示的上层View体系和用于图形渲染的底层图形驱动。

View/GLSurfaceView体系就是用于构建ApplicationUI的图形控件;而SkiaOpenGL| ES则是实际进行图形渲染的图形驱动,其中,Skia2D图形库,而OpenGL|ES则是2D/3D图形库。Canvas可以看做是ViewSkia之间的一个接口,其实它就是一套2D图形API,供Application进行2D图形绘制。

Android中,图形系统由2D图形库Skia2D/3D图形库OpenGL| ES来驱动。对于3D图形库OpenGL| ES来说,从Android1.0开始,就已经支持OpenGLES 1.01.1,从Android2.2开始,实现了对OpenGLES 2.0的支持;从Android3.0开始,系统又新增了android.renderscript包及相关技术来支持3D图形渲染。
 
   
2D图形相关的几个包有:

android.graphics.drawableandroid.viewandroid.view.animationandroid.graphicsandroid.graphics.drawable.shapes
 
   
3D图形相关的几个包有:
   android.opengl
   javax.microedition.khronos.egl
   javax.microedition.khronos.opengles

 
   
不同的应用场景,需要用到的图形技术是不同的,比如,如果您的应用程序仅仅需要绘制一些相对静态的图形及简单动画,可能2D图形技术就能够满足您的需求;如果您的程序是一个交互式的游戏动画等,可能就得需要使用3D图形技术了。

如下图为surfaceSurfaceFlinger关系图:


SurfaceFlinger

SurfaceFlinger在整个图形系统中担任server角色,它负责将各个surface根据Zorder合成(composer)起来。

Surface

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

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

Thewindow is tied to a Surface and the ViewRoot asks the Surface for aCanvas that is then used by the Views to draw onto. After View drawits data to canvas, ViewRoot will callsurface.unlockCanvasAndPost(canvas) to schedulesurfaceFlinger::composeSurfaces() which do the actually display todisplay panel. SurfaceFlinger handles to transfers drawn data incanvas to surface front buffer or backbuffer.

Exceptfor SurfaceViews, different views within the same ViewRoot share thesame surface.

Layer

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

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

Multiplelayers are just composited to the final buffer in their Z order.


与图形相关的代码主要位于下列目录:


1.frameworks/base/graphics/java/android/graphics


2.frameworks/base/core/java/android/view


3.frameworks/base/core/java/android/widget


4.frameworks/base/opengl/


5.frameworks/base/libs/ui


6.frameworks/base/libs/surfaceflinger


7.frameworks/base/core/jni/android/graphics


8.frameworks/base/core/jni/android/opengl


9.frameworks/base/core/jni/android/android_view_*.cpp


10.external/skia


android.graphics,android.viewandroid.widget


1.frameworks/base/graphics/java/android/graphics


2.frameworks/base/core/java/android/view


3.frameworks/base/core/java/android/widget