1.1.1 Handletransaction
There are two similar functions, handletransaction need to acquire Mstatelock locks, perform handletransactionlocked, and finally place Mhwworklistdirty to true.
The last handletransactionlocked is the place to really deal with the business. From our previous explanation of transactionflags, it is inferred that its specific work should be divided into two parts, namely traversal (corresponding etraversalneeded) and transaction (corresponding to etransactionneeded).
void surfaceflinger::handletransactionlocked (Uint32_ttransactionflags)
{
Const layervector¤tlayers (MCURRENTSTATE.LAYERSSORTEDBYZ);
Const size_t Count =currentlayers.size ();
/* First part, traversal all layer*/
Const Boollayersneedtransaction = transactionflags & etraversalneeded;
if (layersneedtransaction) {//if required traversal
For (size_t i=0 i<count; i++) {//layer to process one by one
constsp<layerbase>& layer = Currentlayers[i];
uint32_t trflags = Layer->gettransactionflags (etransactionneeded);/* This layer whether
Need dotransaction*/
if (!trflags) continue;//if not required, go directly to the next
Const UINT32_TFLAGS = layer->dotransaction (0),//by each layer to do the internal processing, the following will do a detailed analysis
if (flags &layer::evisibleregion)//Each Layer calculates whether the visible region changes
Mvisibleregionsdirty = true;//Visible area changed
}
}
/* Part II, Surfaceflinger executive transaction*/
if (Transactionflags &etransactionneeded) {
if (mcurrentstate.orientation!= mdrawingstate.orientation) {
/* angle changes, you need to recalculate all the visible areas, and redraw */
const int DPY = 0;//First display
Const Intorientation = mcurrentstate.orientation; The new orientation
Graphicplane&plane (Graphicplane (dpy));
Plane.setorientation (orientation);//Set the changed rotation angle to the bottom manager
Update theshared control block
constdisplayhardware& HW (Plane.displayhardware ());
/* The following dcblk is a "service provider" for the application to query the current display properties, and therefore needs to be updated synchronously.
volatiledisplay_cblk_t* dcblk = mservercblk->displays + dpy;
Dcblk->orientation = orientation;
Dcblk->w =plane.getwidth ();
Dcblk->h =plane.getheight ();
mvisibleregionsdirty= true; Rotation angle changes, of course, the visible area will also change
Mdirtyregion.set (Hw.bounds ());//The entire screen area is "dirty."
}
if (Currentlayers.size () > MDrawingState.layersSortedByZ.size ()) {//New layer added
Mvisibleregionsdirty = true;//visible area needs recalculation
}
if (mlayersremoved) {/* may also have layers removed, the visible area will also change.
For example, the part of the original cover may be exposed.
Mlayersremoved =false; //
Mvisibleregionsdirty = true;
constlayervector& previouslayers (Mdrawingstate.layerssortedbyz);
Const size_t count= previouslayers.size ();
for (size_t i=0; i<count; i++) {
constsp<layerbase>& layer (previouslayers[i]);
if (Currentlayers.indexof (layer) < 0) {/* is present in the previous state and cannot be found in the existing state.
means it's been removed.
Mdirtyregionremovedlayer.orself (Layer->visibleregionscreen);/* Removed from layer visible
Area * *
}
}
}
}
CommitTransaction ()//And Layer::d otransaction () The practice is basically the same, a few more steps
}