资源描述:
《Android 用户进程绘制过程》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Android用户进程绘制过程下面我们来看下这个函数,它先调用了Surface的lockCanvas获取一个Canvas,然后再调用surface.unlockCanvasAndPost来表示绘制结束。[cpp]viewplaincopy在CODE上查看代码片派生到我的代码片privatebooleandrawSoftware(Surfacesurface,AttachInfoattachInfo,intxoff,intyoff,booleanscalingRequired,Rectdirty){//Drawwithsoftwarerenderer.fi
2、nalCanvascanvas;try{finalintleft=dirty.left;finalinttop=dirty.top;finalintright=dirty.right;finalintbottom=dirty.bottom;canvas=mSurface.lockCanvas(dirty);//获取一个Canvas......finally{try{surface.unlockCanvasAndPost(canvas);//绘制结束}catch(IllegalArgumentExceptione){Log.e(TAG,"Couldnotu
3、nlocksurface",e);mLayoutRequested=true;//askwmforanewsurfacenexttime.//noinspectionReturnInsideFinallyBlockreturnfalse;}if(LOCAL_LOGV){Log.v(TAG,"Surface"+surface+"unlockCanvasAndPost");}}returntrue;}一、应用进程申请buffer我们先来看Surface的lockCanvas函数,其调用了native函数nativeLockCanvas[cpp]viewpla
4、incopy在CODE上查看代码片派生到我的代码片publicCanvaslockCanvas(RectinOutDirty)throwsSurface.OutOfResourcesException,IllegalArgumentException{synchronized(mLock){checkNotReleasedLocked();if(mLockedObject!=0){//Ideally,nativeLockCanvas()wouldthrowinthissituationandpreventthe//double-lock,butthatw
5、on'thappenifmNativeObjectwasupdated.Wecan't//abandontheoldmLockedObjectbecauseitmightstillbeinuse,soinstead//wejustrefusetore-locktheSurface.thrownewIllegalArgumentException("Surfacewasalreadylocked");}mLockedObject=nativeLockCanvas(mNativeObject,mCanvas,inOutDirty);returnmCanvas
6、;}}这个函数在android_view_Surface.cpp中,这个函数内容很多,我们先调用了Surface的lock函数来申请buffer,然后新建了一个SkBitmap,设置了内存地址,并且把这个bitmap放入了Canvas中。[cpp]viewplaincopy在CODE上查看代码片派生到我的代码片staticjlongnativeLockCanvas(JNIEnv*env,jclassclazz,jlongnativeObject,jobjectcanvasObj,jobjectdirtyRectObj){spsurfac
7、e(reinterpret_cast(nativeObject));if(!isSurfaceValid(surface)){doThrowIAE(env);return0;}RectdirtyRect;Rect*dirtyRectPtr=NULL;if(dirtyRectObj){dirtyRect.left=env->GetIntField(dirtyRectObj,gRectClassInfo.left);dirtyRect.top=env->GetIntField(dirtyRectObj,gRectClassInfo.top
8、);dirtyRect.right=env->GetIntField(dirty