Surface、SurfaceFlinger和Canvas的关系

简单描述下三者间的关系:

1、Surface和Canvas:

       Canvas为在画布的意思。Android的APP作图几乎都通过Canvas实例来完成,其实Canvas更多是各种画图接口的包装类,比如:drawPaints,drawPoints,drawRect,drawBitmap等接口函数,其调用流程如下所示:

而Surface简单的说,对应了一块屏幕缓冲区,每个window对应一个Surface,任何View都要画在Surface的Canvas上。传统的view共享一块屏幕缓冲区,所有的绘制必须在UI线程中进行。

2 、SurfaceFlinger和Surface:

SurfaceFlinger英文直译就是surface的投递者,surface就不用翻译了,翻译了反而不好理解。SurfaceFlinger是android的一个服务进程,其负责管理应用端的surface,将所有的surface复合。 首先要明确的是SurfaceFlinger只是负责合并 Surface的控制,比如说计算出两个Surface重叠的区域,至于Surface需要显示的内容,则通过skia,opengl和 pixflinger来计算他是介于图形库和应用之间的一层。每个应用在它自己的surface完成各种图形操作后,请求SurfaceFlinger显示到屏幕,surfaceflinger就会将所有的surface叠加起来,并且反映到framebuffer。

SuffaceFlinger和Surface和Canvas的应用实例就是RootViewImpl的drawSoftware中的mSurface.lockCanvas函数既建立了SurfaceFlinger连接。

public Canvas lockCanvas(Rect inOutDirty)

            throwsSurface.OutOfResourcesException, IllegalArgumentException {

        synchronized (mLock) {

           checkNotReleasedLocked();

            if (mLockedObject != 0) {

                throw new IllegalStateException("Surface wasalready locked");

            }

            mLockedObject = nativeLockCanvas(mNativeObject, mCanvas, inOutDirty);

            return mCanvas;

        }

    }


发布了9 篇原创文章 · 获赞 0 · 访问量 8486
展开阅读全文

IllegalStateException: Surface was already locked

05-05

53 D WindowManager: lid state 1, true 05-05 09:08:04.482 939 953 D WindowManager: lid state 1, true 05-05 09:08:04.512 1982 1982 D AndroidRuntime: Shutting down VM 05-05 09:08:04.512 1982 1982 W dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41671d58) 05-05 09:08:04.512 1982 1982 E AndroidRuntime: FATAL EXCEPTION: main 05-05 09:08:04.512 1982 1982 E AndroidRuntime: Process: com.android.contacts, PID: 1982 05-05 09:08:04.512 1982 1982 E AndroidRuntime: java.lang.IllegalStateException: Surface was already locked 05-05 09:08:04.512 1982 1982 E AndroidRuntime: at android.view.Surface.lockCanvas(Surface.java:252) 05-05 09:08:04.512 1982 1982 E AndroidRuntime: at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2431) 05-05 09:08:04.512 1982 1982 E AndroidRuntime: at android.view.ViewRootImpl.draw(ViewRootImpl.java:2405) 05-05 09:08:04.512 1982 1982 E AndroidRuntime: at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2249) 05-05 09:08:04.512 1982 1982 E AndroidRuntime: at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1879) 05-05 09:08:04.512 1982 1982 E AndroidRuntime: at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996) 05-05 09:08:04.512 1982 1982 E AndroidRuntime: at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5602) 05-05 09:08:04.512 1982 1982 E AndroidRuntime: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:762) 05-05 09:08:04.512 1982 1982 E AndroidRuntime: at android.view.Choreographer.doCallbacks(Choreographer.java:575) 05-05 09:08:04.512 1982 1982 E AndroidRuntime: at android.view.Choreographer.doFrame(Choreographer.java:545) 05-05 09:08:04.512 1982 1982 E AndroidRuntime: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:748) 05-05 09:08:04.512 1982 1982 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:733) 05-05 09:08:04.512 1982 1982 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95) 05-05 09:08:04.512 1982 1982 E AndroidRuntime: at android.os.Looper.loop(Looper.java:136) 05-05 09:08:04.512 1982 1982 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5119) 05-05 09:08:04.512 1982 1982 E AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method) 05-05 09:08:04.512 1982 1982 E AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515) 05-05 09:08:04.512 1982 1982 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 05-05 09:08:04.512 1982 1982 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605) 05-05 09:08:04.512 1982 1982 E AndroidRuntime: at dalvik.system.NativeStart.main(Native Method) 05-05 09:08:04.512 939 1153 W ActivityManager: Force finishing activity com.android.contacts/.activities.ContactEditorActivity 05-05 09:08:04.512 939 1153 I am_crash: [1982,0,com.android.contacts,1086897669,java.lang.IllegalStateException,Surface was already locked,Surface.java,252] 05-05 09:08:04.512 939 1153 I am_finish_activity: [0,1102585736,4,com.android.contacts/.activities.ContactEditorActivity,crashed] 05-05 09:08:04.512 939 1153 I am_pause_activity: [0,1102585736,com.android.contacts/.activities.ContactEditorActivity] 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览