Improve flattening logic
1. Decide do we need writeback-based flattening considering we already have GPU-based.
Writeback Pros:
a. Less power consumption required to render composition
(Difference in mAH should be really tiny, considering that switching to flattening mode occurs not so often, and it is planned to reduce it by an order of magnitude. See items 2 below.)
Writeback Cons:
a. A lot of extra code. High maintenance cost(effort). Nobody tests it as for now.
b. Writeback isn't implemented by most of KMS drivers
c. Require separate memory buffer to be allocated
Also I am not sure can both readback feature and writeback-based flattening co-exist.
And currently writeback-based flattening doesn't work on RPI4. Does it work anywhere today?
2. Exit from flattening mode only if really needed:
Sometime AOSP just updating clock on top, or text cursor is blinking;
We do not need to offload the GPU in this cases, since DU will draw more power while counting down to flatten again.
My proposal is to use screen damage region as a flag. In case it exceeds some value (e.g. 30% of whole screen) then enable flattening. In this case power consumption can be further saved by implementing composing which respects the damage region. (Unfortunately SurfaceFlinger can't do it at this moment).
In addition, we can ignore single-frame events.
3. Implement partial flattening.
Merge layers which aren't updating by the apps. SurfaceFlinger should store such layers cached and do not waste GPU energy/time to merge them again. Thus making only layers which require to redraw will be composed by DU.