学习版本:AOSP 8.1.0_r1(对应Android 8.1系统)流程上一节说到bootanimation的main方法执行frameworks/base/cmds/bootanimation/bootanimation_main.cppnew BootAnimation对象,sp初始化时执行onFirstRef方法surfaceflinger跨进程提供屏幕相关及surface画布frameworks/base/cmds/bootanimation/BootAnimation.cpponFirstRef方法中执行run方法,run方法继承Tread(class BootAnimation : public Thread),在执行readyToRun()①获取画布 ②openGL init ③获取文件动画,在执行threadLoop(),在走android()流程frameworks/base/cmds/bootanimation/BootAnimation.h/BootAnimation、OpenGL准备绘制纹理、opengl绘制frameworks/base/cmds/bootanimation/BootAnimation.cppstatic const char* bootFiles[] = {OEM_BOOTANIMATION_FILE, SYSTEM_BOOTANIMATION_FILE}其中:static const char OEM_BOOTANIMATION_FILE[] = “/oem/media/bootanimation.zip”;static const char SYSTEM_BOOTANIMATION_FILE[] = “/system/media/bootanimation.zip”;status_t BootAnimation::readyToRun(){mAssets.addDefaultAssets();spIBinderdtoken(SurfaceComposerClient::getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain));DisplayInfo dinfo;status_t status=SurfaceComposerClient::getDisplayInfo(dtoken,dinfo);if(status)return-1;// create the native surfacespSurfaceControlcontrol=session()-createSurface(String8("BootAnimation"),dinfo.w,dinfo.h,PIXEL_FORMAT_RGB_565);SurfaceComposerClient::openGlobalTransaction();control-setLayer(0x40000000);SurfaceComposerClient::closeGlobalTransaction();spSurfaces=control-getSurface();// initialize opengl and eglconstEGLint attribs[]={EGL_RED_SIZE,8,EGL_GREEN_SIZE,8,EGL_BLUE_SIZE,8,EGL_DEPTH_SIZE,0,EGL_NONE};EGLint w,h;EGLint numConfigs;EGLConfig config;EGLSurface surface;EGLContext context;EGLDisplay display=eglGetDisplay(EGL_DEFAULT_DISPLAY);eglInitialize(display,0,0);eglChooseConfig(display,attribs,config,1,numConfigs);surface=eglCreateWindowSurface(display,config,s.get(),NULL);context=eglCreateContext(display,config,NULL,NULL);eglQuerySurface(display,surface,EGL_WIDTH,w);eglQuerySurface(display,surface,EGL_HEIGHT,h);if(eglMakeCurrent(display,surface,surface,context)==EGL_FALSE)returnNO_INIT;mDisplay=display;mContext=context;mSurface=surface;mWidth=w;mHeight=h;mFlingerSurfaceControl=control;mFlingerSurface=s;// If the device has encryption turned on or is in process// of being encrypted we show the encrypted boot animation.char decrypt[PROPERTY_VALUE_MAX];property_get("vold.decrypt",decrypt,"");bool encryptedAnimation=atoi(decrypt)!=0||!