收藏 分销(赏)

Android的GUI系统原理与开发要点详解.pdf

上传人:曲**** 文档编号:3145403 上传时间:2024-06-20 格式:PDF 页数:57 大小:3.68MB
下载 相关 举报
Android的GUI系统原理与开发要点详解.pdf_第1页
第1页 / 共57页
Android的GUI系统原理与开发要点详解.pdf_第2页
第2页 / 共57页
Android的GUI系统原理与开发要点详解.pdf_第3页
第3页 / 共57页
Android的GUI系统原理与开发要点详解.pdf_第4页
第4页 / 共57页
Android的GUI系统原理与开发要点详解.pdf_第5页
第5页 / 共57页
点击查看更多>>
资源描述

1、Android 的 GUI 系统Android 的 GUI 系统“口 第一部分 口 第二部分口 第三部分 口 第五部分口 第六部分Android GU!系统综述 pixelflinger 和 libui 库Surface 系统Skia系统OpenGL系统架构V 丿第一部分Android GUI系统综述And roid的GU!系统由C语言的框 架和JAVA语言的框架组成。GU 系统的C语言部分包括:PixelFlinger!ibui(框架库)SurfaceFlinger Surface 的管理)Skia图形图像引擎 OpenGL 3D 引擎口各种JN1(向JAVA提供接口)第一部分Android

2、 GUI系统综述GUI系统JAVA语言的核心包括:android.graphics(寸应 Skia 底层库)android.view.Surface(构建显示介面)android.view.View 及其继承者(用于构建UI元素)OpenGL的功能类j avax.microedition.khronos.opengles com.google.android.gles_jni实现)丿第二部分 pixelflinger 和 libui 库2.1 pixelflinger2.2 libui2.1 pixelflingerlibpixelflingner.so是个下层的工具性的类,这个 类对外的主要

3、内容是GGLContext结构,以及初始化和 卸载的函数。system/core/include/pixelflinge”system/co(e/libpixelflingei7ssize_t gg11 nit(GGLContext*context);ssize_t gglUninit(GGLContext*context);libpixelflingner.so这个库对其他的库没有依赖,也并不提供实际的功能,类似个用于管理工具的库。V)2.2 libuilibui是个框架性质的集成库,它不仅是显示的 中枢,也是整个GUI系统的中枢。UI lib(libui 一!ibpixelflinger)

4、5这个的相关内容在以下的路径中:f rameworks/base/include/ui/framework/base/libs/ui/libui包含了颜色格式,用于实际显示的Egl窗,按键及事件处理,Suface界面,Overlay,Camera等几个方面的接口。V)2.2 libuiformat 部分:这个部分本身定义颜色空间的枚举和数据结构,它需 要充用pixelflinger中的些关于数据格式定义EgIWindows 部分:包含了 EGL头文件构建的egl_native_window_t,它依 赖 OpenGL 的结构,并给 libEGL 使甬的。EGLDisplaySurface 操作

5、了硬件的framebuffer的驱动这也是整个系统显示的基 础。Key/Event 部分:这是Android系统输入的基础,其中定义按键的映射,通过操作event事件设备来实现获取系统的输入的。2.2 libuiSurface:Surface相关的头文件和实现为SurfaceFlinger 定义接口和框架。Overlay:定义视频输出的接口。Camera:定义摄像头的框架和接口。_丿2.3 Android的显示输出系统Android使用标准的framebuffer作为驱动程 序,Android的本地框架中提供了系统和 framebuffer驱动程序之间的适配层(硬件抽象 层)。输出部分的硬件抽

6、象(donut之前):EGLDisplaySurface.cpp调用标准的FrameBuffer驱动V)2.3 Android的显示输出系统Gralloc Module是Eclair版本之后显示 部分的抽象层,它是系统和Framebuffer设备 的接口,以硬件模块的形式存在。头文件路径:hardware/libhardware/include/hardware/grallochGralloc模块实现:hardware/libhardware/modules/gralloc/Gralloc被libui使用V 丿2.3 Android的显示输出系统Gralloc.h中包含了 Gralloc模亏需

7、要具 有的接口。typedef struct gralloc_module_t struct hw_module_t common;int(*registerBuffer)(struct gralloc_module_t const*module,buffer_handle_t handle);int(*unregisterBuffer)(struct gralloc_module_t const*module,buffer_handle_t handle);int(*lock)(struct gralloc_module_t const*module,buffer_handle_t hand

8、le,int usage,int I,int t,int w,int h,void*vaddr);int(*unlock)(struct gralloc_module_t const*module,buffer_handle_t handle);int(*perform)(struct gralloc_module_t const*module,int operation,.);2.3 Android的显示输出系统 入 enum GRALLOC_USAGE_SW_READ_NEVER=0 x00000000,GRALLOC_USAGE_SW_READ_RARELY=0 x00000002,GR

9、ALLOC_USAGE_SW_READ_OFTEN=0 x00000003,GRALLOC_USAGE_SW_READ_MASK=OxOOOOOOOF,GRALLOC_USAGE_SW_WRITE_NEVER=0 x00000000,GRALLOC_USAGE_SW_WRITE_RARELY=0 x00000020,GRALLOC_USAGE_SW_WRITE_OFTEN=0 x00000030,GRALLOC_USAGE_SW_WRITE_MASK=OxOOOOOOFO,/*buffer will be used as an OpenGL ES texture*/GRALLOC_USAGE_

10、HW_TEXTURE=0 x00000100,/*buffer will be used as an OpenGL ES render target*/GRALLOC_USAGE_HW_RENDER=0 x00000200,/*buffer will be used by the 2D hardware blitter*/G R AL LOC_U SAG E_H W_2 D=OxOOOOOCOO,/*buffer will be used with the framebuffer device*/G R AL LOC_U SAG E_H W_F B=0 x00001000,/*mask for

11、 the software usage bit-mask*/GRALLOC USAGE HW MASK=OxOOOOlFOO,u _丿2.3 Android的显示输出系统GraUoc模块是显示模块的实现。其中,一framebuffer,cpp 用于基于 framebuffer 的显示 实现,gralloc是基于pmem的实现int gralloc_device_open(const hw_module_t*module,const char*name,hw_device_t*device)int status=-EINVAL;if(!strcmp(name,GRALLOC_HARDWARE_G

12、PUO)gralloc_context_t*dev;dev=(gralloc_context_t*)malloc(sizeof(*dev);memset(dev,0,sizeof(*dev);dev-mon.tag=HARDWARE_DEVICE_TAG;dev-mon.version=0;dev-mon.module=const_cast(module);dev-mon.close=gralloc_close;dev-device.alloc=gralloc_alloc;dev-device.free=gralloc_free;*device=&dev-mon;status=0;else s

13、tatus=fb_device_open(module,name,device);)return status;2.3 Android的显示输出系统libui对gralloc模块实现了调用,在 ui/FramebufferNativeWindow.cpp 中打开 了 gralloc 设备 FramebufferNativeWindow:FramebufferNativeWindow():BASE(),fbDev(O),grDev(O),mUpdateOnDemand(false)(hw_module_t const*module;if(hw_get_module(GRALLOC_HARDWAR

14、E_MODULEJD,&module)0)int stride;int err;err 二 framebuffer_open(module,&fbDev);LOGE_IF(err,couldnt open framebuffer HAL(%s),strerror(-err);err 二 gralloc_open(module,&grDev);LOGE_IF(err,couldnt open gralloc HAL(%s),strerror(-err);/一)2.4 Android的用户输入系统Android输入系统由Event驱动程 序,libui中的EventHub和JAVA框架中 的几个类

15、组成Event的功能被集成在and roid.view 包的View类中,在应用程序层调用主要通过 View类及其继承者KeyEvent 和 MotionEvent 的处理方法略有不同,KeyEvent通过转化按键码得至1,MotionEvent 通过转化 RawEvent 得至I V)2.4 Android的用户输入系统一一 A A2.4 Android的用户输入系统F输入部分的硬件抽象:EventHub.cpp调用标准的Event设备驱动。KeyCodeLabeLh android/view/KeyEventjava qwert.k!键盘布局文件V 丿2.4 Android的用户输入系统M

16、ulti-Touch是Eclair版本的新特 性。多点触摸的特性,需要从硬件到软件系统 的支持作为Android的GU!系统,最终的就 是将消息从下传递到上面。输入设备中增加了 一个新的类型:TOUCHSCREENMT(EventHub.h 定义),EventHub获得信息只有交由JAVA层处理。V)2.4 Android的用户输入系统android.view.RawInputEvent 增口 多点数据表示,nputDevice作处理,并保 持对非多点触摸的素容性,KeylnputQueue(android/server/KeylnputQueue)进行多点数据的转化。MotionEvent增

17、加了对多点的支持,最多支持同时有3个点触摸。这是上层程序中 用到的接口。注意:没有手势方面的解析,需要应用 程序根据多点信息自己实现解释。V)2.4 Android的用户输入系统Virtual Key 是 Eclair版本的新特性Virtual Key的功能是利 用触摸屏,模拟按键发生的事 件,这样就可以利用触摸屏的边 缘,实现些可以自定义的按键 效果。更2.4 Android的用户输入系统从应用程序的角度,触摸屏设备发送的是 RawInputEvent(原始输入事件),而按键发 送的是KeyEvent(按键事件)。虚拟按键的作 用是在某補情况下,将RawInputEvent转换成 KeyEv

18、ent 按键文件:/sys/boardproDerties/virtualkeys.devicename”代码路径:services/j ava/com/android/server/nputDevice.j ava通过readVirtualKeys,进行消息的转 化,将 RawInputEvent 转换成 KeyEvent 2.4 Android的用户输入系统virtualkeys.devicename是虚拟按键 的适配文件,需要放置在目标系统的以下目录中:/sys/boardproperties/文件的格式如下所示:0 x1:扫描码:X:Y:W:H:0 xl:.V 丿第三部分Surface

19、系统修3.1 Surface系统的结构3.2 SurfaceFlinger 本地代码3.3 Surface 的 Java 和 Jni 代码V 丿3.1 Surface系统结构Surface系统的结构:libui.s。提供与 Surface 接口。libsurfacefilnger.so 提供实现。Java框架层次主要调用Surface向UI提供接口。Navtive(本地调用)部分主要使用!Surface V)3.1 Surface系统的结法Surface-mClient-mSurface+ID()+setLayei()+setPosition()+setSize()+setAlpha()+ge

20、tldentity()+dirtyRegion()+setDirtyRegion()ISurface+registerBuffers()+postBuffer()+unregisterBuffers()SurfaceComposerClient-I SurfaceFlingerClient+createSurfac)ISurf aceC omposerISurf aceF lingerClient+createConnection()+freezeDisplaj()+unfreezeDisplay()+setOrientatior()+bo(Lp!l!Sllcd().+requestGPU()

21、+revokeGPU()A+createSurfac)+destroySurface()BnSurfaceF lingerClientBnSurfaceC omposer3.1 Surface系统的结构Surface系统的头文件(路径为:frameworks/base/include/ui/):ISurface.hISurfaceComposer.hISurfaceFlingerClient.hSurface.hSurfaceComposerClient.hSurface系统的源代码文件(路径为:frameworks/base/libs/surfaceflingei7):ISurfaceFli

22、ngerClient.cppSurfaceComposerClient.cppIsurfaceComposer.cppSurface.cppIsurface.cppSurfaceFlinger 类继承了!SurfaceComposer 5 J强个核心的实现。1 Surface系统的结class ISurfaceComposer:public(Interface(public:enum II(keep in sync with Surface.java)eHidden=0 x00000004,eGPU=0 x00000008,eHardware=0 x00000010,eDestroyBackb

23、uffer=0 x00000020,eSecure=0 x00000080,eNonPremultiplied=0 x00000100,ePushBuffers=0 x00000200,eFXSurfaceNormal=0 x00000000,eFXSurfaceBlur eFXSurfaceDim eFXSurfaceMaskenum ePositionChanged/*/);enum eLayerHidden=0 x00010000,=0 x00020000,=OxOOOFOOOO,;=0 x00000001,=0 x01,I*/;enum eOrientationDefault=0,/*

24、/);y3.2 SurfaceFlinger 本地代码代码的路径:frameworks/base/libs/surfaceflinger/class LayerBaseClient:public LayerBaseclass Surface:public BnSurfaceclass Layer:public LayerBaseClientclass LayerBuffer:public LayerBaseClientclass SurfaceBuffer:public LayerBaseClient:Surfaceclass LayerDim:public LayerBaseClientcl

25、ass LayerBlur:public LayerBaseClientV 丿3.2 SurfaceFlinger 本地代码3.2 SurfaceFlinger 本地代码For Create a Surface:SurfaceComposerClient:createSurface(ISurface-Suface,frameworks/base/libs/ui/SurfaceComposerClient.cpp)一(IsurfaceFlingerClient:createSurface)一 Bclient:createSurface(framework/base/libs/surfacefli

26、nger/SurfaceFlinger.cpp)一 SurfaceFlinger:createSurface(framework/base/libs/surfaceflinger/SurfaceFlinger.cpp)LayerBaseClient*layer=0;sp surfaceHandle;eFXSurfaceNormal-Layer or LayerBuffereFXSurfaceBlur-LayerBlur 算 eFXSurfaceDim-LayerDimsurfaceHandle=layer-getSurface();For setSize:Surface:setSize()-S

27、urfaceComposerClient:setSize()3.3 Surface 的 Java 和 Jni 代码FJNI Code path:frameworks/base/core/jni/android view Surface.cpp#include const char*const kSurfaceSessionClassPathName=android/view/SurfaceSession;const char*const kSurfaceClassPathName=android/view/Surface;static void nativeClassInit(JNIEnv*e

28、nv,jclass clazz);_丿3.3 Surface 的 Java 和 Jni 代码FJNI代码的路径:frameworks/base/core/jni/android view Surface.cpp#include const char*const kSurfaceSessionClassPathName=android/view/SurfaceSession;const char*const kSurfaceClassPathName=android/view/Surface;static void nativeClassInit(JNIEnv*env,jclass clazz)

29、;V 丿3.3 Surface 的 Java 和 Jni 代码Java代码的路径:frameworks/base/core/java/android/view/3个主要的类:S u rface(S u rface.java)Surf ace View(S u rf ace Vi e w.j ava)SurfaceSession(SurfaceSession.java)!个接口:SurfaceHolder(SurfaceSession.java)android.view.Surface表示了一个可以绘制图形的界 面,它是实际调用底层的Suface接口来完成来控制的硬3.3 Surface 的 J

30、ava 和 Jni 代码天于 android.view.View 类:View类呈现了最基本的U!构造块。个视图占据 屏幕上的一个方形区域,并且负责绘制和时间处理。View是widgets的基类,常用来创建交互式的用户图形 界面(GUI)。View中包含了一个Surface,并处理 onDraw(Canvas)事件 V 丿第四部分Skia及android的图形系统 4.1 Skia底层库4.2 Android图形系统的JNI接口4.3 Android的图形类第四部分 统Skia及android的图形系4.1 Skia底层库Skia是Google 个底层的图形,图像,动 画,SVG,文本等多方面

31、的图形库,它是 Android中图形系统的引擎Skia代码的路径:external/skia/Skia主要包含三个库:Core Cg:libcorecg.so GL(Skia Graphic Lib)skia-opengl glue library:liblibsgl.solibskiagl.so4.1 Skia底层库Skia主要包含三个库的代码路径:口核心图形库:libcorecg.sosrc/core/Skia 图形库:liblibsgl.sosrc/effects/src/images/src/ports/src/core/src/utils/skia-opengl glue libra

32、ry:libskiagl.so src/gl/4.2 Android图形系统的JNI接Android的图形系统和Skia底层库的 联系比较紧密。Android的图形系统的 JNI提供了从Skia底层库到JAVA上层的 支持。Android的图形系统的JNI代码的路径:frameworks/base/core/jni/android/graphic/Android的图形系统对JAVA层提供了 冰制基本图用的功能;星。UI系统的其/4.2 Android图形系统的JNI接Canvas.cpp是JNI中核心的接口,为 JAVA 上层的 android.graphics.Canvas 类提供了支持。s

33、tatic SkCanvas*initRaster(JNIEnv*env,jobject,SkBitmap*bitmap)return bitmap?new SkCanvas(*bitmap):new SkCanvas;)static SkCanvas*initGL(JNIEnv*env,jobject)return new SkGLCanvas;)V 丿4.3 Android的图形类Android 的图形类的包是 android.graphic,它通过调用图形系统的JNI提供了对JAVA框架 中图形系统的支持。Android的图形系统的代码的路径:framewoiks/graphic/jav

34、a/android/graphic/V 丿4.3 Android的图形类Canvas.java实现图形系统中最为重要的一个类:android.graphics.Canvas 0Canvas类处理“draw”的调用,当绘制(draw)内容的时候需要4个基本的组件:一 个保持像素的A Bitmap,个处理绘制调用的 Canvas(写入bitmap),绘制的内容(例如 Rect,Path,text,Bitmap)和一个 paint(用来描述颜色和样式)。V),第五部分OpenGL系统r5.1 OpenGL系统结构5.2 OpenGL 的 Native 代码5.3 OpenGL 的 JAVA 和 JN

35、I 代码5.2 OpenGL 的 Native 代码OpenGL的本地代码:frameworks/base/openql/libaql/frameworks/base/opengl/libs/OpenGL的本地头文件:frameworks/base/oDenql/include/EGL/frameworks/base/opengl/include/GLES/OpenGL 的库:libEGL.so(EGL 库)libGLESvl_CM.so OpenGL ES 库的封装)libagLso OpenGL的软件实现库)丿5.2 OpenGL 的 Native 代码测试代码的路径:frameworks

36、/base/openql/tests 使用Surface的代码frameworks/base/libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp另外的一个本地的接口:frameworks/base/operql/irclude/EGL/eqlrativesh struct egl_native_window_t*android_createDisplaySurfaceQ;其实现:frameworks/base/libs/ui/EGLDisplaySurface.cppl_native_window_t*android_createDi

37、splaySurface();5.2 OpenGL 的 Native 代码Android Eclair中版本之后libagl的库名称为 libGLES and roid.so,放置到目标系统的目录 system/lib/egl 新增OpenGL ES2的支持:frameworks/base/opengl/libs/ELGS CM库的名称为 libGLESv2.so,它与!ibGLESvl CM.so 是并列关系。V 丿5.2 OpenGL 的 Native 代码Android Eclair中版本的libegl.so将从 system/lib/egl目录中力口载OpenGL的实王见库,加载 的方

38、式由其中的egLcfg文件来决定,OpenGL的软件 实现libGLES_android.so,通常作为加载的个库。另外还可以选拝加载硬件实现的OpenGL库。egl.cfg文件的实例如下:0 0 android0 1XXXV 丿5.2 OpenGL 的 Native 代码F#include#include include int main(int argc,char*argv)(EGLint s_configAttribs=EGLjRED_SIZE,5,EGL_GREEN_SIZE,6,EGL_BLUE_SIZE,5,EGL_NONE);EGLint numConfigs=-1;EGLint

39、 majorversion;EGLint minorversion;EGLConfig config;EGLContext context;EGLSurface surface;EGLint w,h;EGLDisplay dpy;dpy=eglGetDisplay(EGL_DEFAULT_DISPLAY):egllnitialize(dpy,&majorVersion,&minorVersion);eglChooseConfig(dpy,s_configAttribs,&config,1,&numConfigs);surface=eg IC r eate Wi n d o wS u rf ac

40、e(d py,config,android_createDisplaySurface(),NULL);context=eglCreateContext(dpy,config,NULL,NULL);eglMakeCurrent(dpy,surface,surface,context);eglQuerySurface(dpy,surface,EGL_WIDTH,&w);eglQuerySurface(dpy,surface,EGL_HEIGHT,&h);GLint dim=wh?w:h;5.2 OpenGL 的 Native 代码glBindTexture(GL_TEXTURE_2D,0);glT

41、exParameterx(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);glTexParameterx(GL_TEXTURE_2D,GL_TEXTURE_MINjFILTER,GLJIEAREST);glTexEnvx(GL_TEXTURE_ENV,_GL_TEXTURE_ENvLMODE,GL_REPLACE);glEnable(GL_fEXTURE_ 初glColor4f(l,1,1,1);glDisable(GL_DITHER);glShadeModel(GL_FLAT);return 0;V 丿4.3 OpenGL 的 JAVA 和 J

42、NI 代码卜Android的OpenGL的实现方法是使用 个类来继承OpenGL JAVA的标准类,通过对这 个类的实现,实现OpenGL的功能,在JAVA层 只需要使用标准类。javax.microedition.khronos.opengles(JAVA怀准类):operq1/java/avax/microedition/khroros/eq/(GL10.java GL11.java)ouerql/java/javax/microedition/khronos/oDerqles/(EGL10.java)com.google.android.gles_j ni(Android 的 GLES

43、的实现)opengl/java/com/google/android/gles jni/com.google.android.gles_jni JNI:core/ni/com google android qles jni GLmpl.cppcore/jni/com google android gles jni EGLImpl.cpp5.3 OpenGL的JAVA和JNI代码JAVA代码:javax.microedition.khronos-opengles(JAVA标准类):openql/ava/avax/microedition/khronos/eql/(GL10.java GL11.j

44、ava)openql/ava/avax/microedition/khronos/openqles/(EGL10.java)com.google.android.gles_j ni(Android 的 GLES 的实现类)opengl/java/com/google/android/gles jni/JNI代码:com.google.android.gles_jni JNI:coreni/com google android qles ni_GLmpLcpp core/jni/com google android gles jni EGLImplcp5.3 OpenGL的JAVA和JNI代码A

45、ndroid 的 android.opengl 是个OpenGL相关的包,它主要提供了为OpenGL的 输出界面android.opengl的代码路径:openql/ava/android/openql/核心的文件:opengl/java/android/opengl/GLSurfaceview.javapublic class GLSurfaceView extends Surfaceviewimplements SurfaceHolder.CallbackI _丿5.3 OpenGL 的 JAVA 和 JNI 代码在Android的JAVA应用中使用OpenGL通常需要 javax.mic

46、roedition.khronos.opengles 类和 android.opengl包的结合使用。public class XXXActivity extends Activity Overrideprotected void onCreate(Bundle saved I nstanceState)super.onCreate(savedlnstanceState);mGLSurf ace View 二 new XXXGIS u rf ace Vi e w(t h i s);setContentView(mGLSurfaceView);mGLSurfaceView.requestFocus();mGLSurfaceView.setFocusablelnTouchMode(true);)private GLSurf ace View mGLSurfaceView;)class XXXGISurfaceView extends GLSurfaceView private class CubeRenderer implements GLSurfaceView.Renderer/*.*/*/

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服