通过前面的篇文章我们简单了解了 Surface 和 Layer,并且知道了 SurfaceComposerClient 的 createSurface() 方法最终创建的其实是一个 Layer,这里我们来看一下真正的获取 Surface 的方法。
一、获取Surface
通过系统动画的播放流程中我们知道真正获取 Surface 的方法是 SurfaceControl 中的 getSurface() 函数,这里我们先来看一下 SurfaceControl 的构造函数。
1、SurfaceControl
源码位置:/frameworks/native/libs/gui/SurfaceControl.cpp
SurfaceControl::SurfaceControl(const sp<SurfaceComposerClient>& client, const sp<IBinder>& handle,
const sp<IGraphicBufferProducer>& gbp, int32_t layerId, uint32_t w, uint32_t h,
PixelFormat format, uint32_t transform, uint32_t flags)
: mClient(client),
mHandle(handle),
mGraphicBufferProducer(gbp),
mLayerId(layerId),
mTransformHint(transform),
mWidth(w),
mHeight(h),
mFormat(format),
mCreateFlags(flags) {}
此时 SurfaceControl 同时持有了 Client 的 Binder,图元生