//frameworks/base/core/java/android/view/Surface.java
publicclassSurfaceimplementsParcelable{privatevoidunlockSwCanvasAndPost(Canvascanvas){if(canvas!=mCanvas){thrownewIllegalArgumentException("canvas object must be the same instance that "+"was previously returned by lockCanvas");}if(mNativeObject!=mLockedObject){Log.w(TAG,"WARNING: Surface's mNativeObject (0x"+Long.toHexString(mNativeObject)+") != mLockedObject (0x"+Long.toHexString(mLockedObject)+")");}if(mLockedObject==0){thrownewIllegalStateException("Surface was not locked");}try{nativeUnlockCanvasAndPost(mLockedObject,canvas);}finally{nativeRelease(mLockedObject);mLockedObject=0;}}}
//frameworks/base/core/jni/android_view_Surface.cpp
staticvoidnativeUnlockCanvasAndPost(JNIEnv*env,jclassclazz,jlongnativeObject,jobjectcanvasObj){sp<Surface>surface(reinterpret_cast<Surface*>(nativeObject));if(!isSurfaceValid(surface)){return;}// detach the canvas from the surface
graphics::Canvascanvas(env,canvasObj);canvas.setBuffer(nullptr,ADATASPACE_UNKNOWN);// unlock surface
status_terr=surface->unlockAndPost();if(err<0){jniThrowException(env,IllegalArgumentException,NULL);}}