Android UI Internal : UI Composition with Hardware Composer (HWC)

We ended last article with the statement that to reduce  power and increase  performance, surfaceFlinger will offload layer composition to display hardware. This is the so called Hardware Composer. How this offloading works and what is the benifit can be illustrated with following diagram.

composition using GLES and hardware composer

In case 1, all the layers are composited using openGL. The composited image goes to display controller and finally the phone screen.

In case 2, layer 1 goes to display controller directly while layer 2 & 3 are composited by openGL; the display hardware will then blend layer 1 and the composition result of layer 2 & 3 and finally output it to phone screen. 

Apparently, to enable case 2 more sophiscated display controller was needed so as to be able to accept two input and to blend them. What's the benefit to make this added complexity pays off? 

In the first case, every time layer 1 updates, openGL composition will be trigged for all three layers even layer 2/3 does not change; However, in the second case, if only layer 1 updates, it will goes directly to display controller and no openGL composition will happen. Keeping the openGL/3D hardware idle as much as possible is THE most important thing to ensure a long batter life which our customer will be happy with. In addition to this power benefit, composition using display controller is usually more performant than using openGL since display controller can do it parallel with dedicated hardware. To sum up, using hardware composer, we have decreased power consumption and increased performance. 

Whether a layer could be composited using hardware composer depend on the hardware capability and layer's attributions. Nowadays, smart phone's display hardwares support at least 2 simultaneous input, or overlay - a more jargon word.  Google suggests phone should at lease support 4 overlays to cover status bar, system bar, application and live wallpaper effectively. Layer attributions are things like color format(RGB or YUV), alpha value and angle (portrait or landscape). Only when there is available overlay and the capability of the overlay match the the layer attribution, this layer will go to hardware composer.  Usually, video playback using SurfaceView always goes to overlay since its performance and power  is an important KPI (Key Performance Index)  each and every phone strive to get it looks good. Full screen game is another case. 

Check out other articles in Android UI Internal series