surfaceflinger中surface与layer的关系

本文通过BootAnimation实例解析Surface与Layer在Android系统中的关联。首先,通过SurfaceComposerClient创建Layer,然后SurfaceControl利用创建的Layer实例化。在SurfaceControl的getSurface()方法中,Surface使用Layer的GraphicBufferProducer初始化,建立起两者之间的联系。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

以BootAnimation为例说明下surface与layer的关系:
在BootAnimation中
1:在BootAnimation的构造函数中
BootAnimation::BootAnimation(int animType) : Thread(false), mZip(NULL)
{
mAnimationType = animType;
mSession = new SurfaceComposerClient(); //创建SurfaceComposerClient
}
2:在BootAnimation的readyToRun()函数中:
// create the native surface 创建layer的地方
sp control = session()->createSurface(String8(“BootAnimation”),
dinfo.w, dinfo.h, PIXEL_FORMAT_RGB_565);
3:在createSurface中,注意gbp,这就是surface的producter
sp SurfaceComposerClient::createSurface(
const String8& name,
uint32_t w,
uint32_t h,
PixelFormat format,
uint32_t flags)
{
sp sur;
if (mStatus == NO_ERROR) {
sp handle;
sp gbp;
//最终会在surfaceflinger中创建layer,这个gdb会在layer的onFirstRef里面创建出来
status_t err = mClient->createSurface(name, w, h, format, flags,
&handle, &gbp);
ALOGE_IF(err, “SurfaceComposerClient::createSurface error

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值