In the previous article, we mainly analyzed the creation of surface, and did not delve into the analysis of layer layers. This article analyzes the creation of layer layers and analyzes the origins of the two variables, handle GBP.
A different layer is created in Surfaceflinger based on the value of flags. This is mainly to create a common layer as an example for analysis.
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<igraphicbufferpro ducer>* GBP, sp<layer>* outlayer) {//Initialize the surfaces switch (format) {case PIXEL_FORMAT_TRANSP Arent: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;}
- Create a Layer object Outlayer
- Call the GetHandle () method of the Layer object to assign a value to handle
- Call the Getproducer () method of the Layer object to assign the value to GBP
Feel fast to the source, looking at the Onfirstref method of the Layer class
void Layer::onfirstref () {//Creates a custom bufferqueue for Surfaceflingerconsumer to use Sp<igraph Icbufferproducer> 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); #endif const sp<const displaydevice> HW (Mflinger->getdefaultdisplaydevice ()); Updatetransformhint (HW);}
- Call the Bufferqueue::createbufferqueue () method to create an image buffer queue
- Create the Creator object Monitoredproducer and assign it to Mproducer
- Create a Consumer object Surfaceflingerconsumer and assign it to Msurfaceflingerconsumer
Look at the GetHandle method of layer
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);}
- Eventually returns a binder object of the handle class, not knowing what to use
To summarize, when the client creates surface, the Surfaceflinger server creates the corresponding layer layers. and assigns the producer interface of the layer's image buffer to the member variable mgraphicbufferproducer of the Surface object. This allows the client to submit the picture to the Surfaceflinger service for processing.
Android Surfaceflinger Service (iii)-----This map layers layer creation