别裁伪体亲风雅,转益多师是汝师。这篇文章主要讲述Android SurfaceFlinger服务 ----- 本地图层Layer创建相关的知识,希望能为你提供帮助。
在上一篇文章中,主要分析了Surface的创建过程,对于Layer图层的创建并没有深入跟踪分析。这篇文章将分析Layer图层的创建,并分析handle gbp这两个变量的来源。
在SurfaceFlinger中会根据flags的值创建不同的layer。这里主要以创建普通layer为例进行分析。
status_t SurfaceFlinger::createNormalLayer(const sp<
Client>
&
client,
const String8&
name, uint32_t w, uint32_t h, uint32_t flags, PixelFormat&
format,
sp<
IBinder>
* handle, sp<
IGraphicBufferProducer>
* gbp, sp<
Layer>
* outLayer)
{
// initialize the surfaces
switch (format) {
case PIXEL_FORMAT_TRANSPARENT:
case PIXEL_FORMAT_TRANSLUCENT:
format = PIXEL_FORMAT_RGBA_8888;
break;
case PIXEL_FORMAT_OPAQUE:
format = PIXEL_FORMAT_RGBX_8888;
break;
}*outLayer = new Layer(this, client, name, w, h, flags);
status_t err = (*outLayer)->
setBuffers(w, h, format, flags);
if (err == NO_ERROR) {
*handle = (*outLayer)->
getHandle();
*gbp = (*outLayer)->
getProducer();
}ALOGE_IF(err, "createNormalLayer() failed (%s)", strerror(-err));
return err;
}
- 创建一个Layer对象outLayer
- 调用Layer对象的getHandle()方法赋值给handle
- 调用Layer对象的getProducer()方法赋值给gbp
void Layer::onFirstRef() {
// Creates a custom BufferQueue for SurfaceFlingerConsumer to use
sp<
IGraphicBufferProducer>
producer;
sp<
IGraphicBufferConsumer>
consumer;
BufferQueue::createBufferQueue(&
producer, &
consumer);
mProducer = new MonitoredProducer(producer, mFlinger);
mSurfaceFlingerConsumer = new SurfaceFlingerConsumer(consumer, mTextureName);
mSurfaceFlingerConsumer->
setConsumerUsageBits(getEffectiveUsage(0));
mSurfaceFlingerConsumer->
setContentsChangedListener(this);
mSurfaceFlingerConsumer->
setName(mName);
#ifdef TARGET_DISABLE_TRIPLE_BUFFERING
#warning "disabling triple buffering"
mSurfaceFlingerConsumer->
setDefaultMaxBufferCount(2);
#else
mSurfaceFlingerConsumer->
setDefaultMaxBufferCount(3);
#endifconst sp<
const DisplayDevice>
hw(mFlinger->
getDefaultDisplayDevice());
updateTransformHint(hw);
}
- 调用BufferQueue::createBufferQueue()方法创建图像缓冲区队列
- 创建产生者对象MonitoredProducer,并赋值给mProducer
- 创建消费者对象SurfaceFlingerConsumer,并赋值给mSurfaceFlingerConsumer
sp<
IBinder>
Layer::getHandle() {
Mutex::Autolock _l(mLock);
LOG_ALWAYS_FATAL_IF(mHasSurface,
"Layer::getHandle() has already been called");
mHasSurface = true;
/*
* The layer handle is just a BBinder object passed to the client
* (remote process) -- we don‘t keep any reference on our side such that
* the dtor is called when the remote side let go of its reference.
*
* LayerCleaner ensures that mFlinger->
onLayerDestroyed() is called for
* this layer when the handle is destroyed.
*/class Handle : public BBinder, public LayerCleaner {
wp<
const Layer>
mOwner;
public:
Handle(const sp<
SurfaceFlinger>
&
flinger, const sp<
Layer>
&
layer)
: LayerCleaner(flinger, layer), mOwner(layer) {
}
};
return new Handle(mFlinger, this);
}
- 最终返回一个Handle类的binder对象,不知道有什么用
推荐阅读
- Spring Boot—07应用application.properties中的配置
- [Android Security]DEX文件格式分析
- Android 代码设置RelativeLayout元素居中
- android-samples-mvp
- 使用mybatis反向自动生成实体类和mapper映射文件和接口文件
- 背单词app评估测试
- 避免死锁
- FCFS中的车队效应
- 磁盘的连续分配