Google is committed to advancing racial equity for Black communities. See how.

Hardware Composer HAL

The Hardware Composer (HWC) HAL determines the most efficient way to composite buffers with the available hardware. As a HAL, its implementation is device-specific and usually done by the display hardware OEM.

The value of this approach is easy to recognize when you consider overlay planes, which composite multiple buffers in the display hardware rather than the GPU. For example, consider a typical Android phone in portrait orientation, with the status bar on top, navigation bar at the bottom, and app content everywhere else. The contents for each layer are in separate buffers. You can handle composition using either of the following methods:

  • Rendering the app content into a scratch buffer, then rendering the status bar over it, the navigation bar on top of that, and finally passing the scratch buffer to the display hardware.
  • Passing all three buffers to the display hardware and instructing it to read data from different buffers for different parts of the screen.

The latter approach can be significantly more efficient.

Display processor capabilities vary significantly. The number of overlays, whether layers can be rotated or blended, and restrictions on positioning and overlap can be difficult to express through an API. To accommodate these options, the HWC performs following calculations:

  1. SurfaceFlinger provides HWC with a full list of layers and asks, "How do you want to handle this?"
  2. HWC responds by marking each layer as device or client composition.
  3. SurfaceFlinger takes care of any client, passing the output buffer to HWC, and lets HWC handle the rest.

Because hardware vendors can custom tailor decision-making code, it's possible to get the best performance out of every device.

Overlay planes may be less efficient than GL composition when nothing on the screen is changing. This is particularly true when overlay contents have transparent pixels and overlapping layers are blended. In such cases, the HWC can request GLES composition for some or all layers and retain the composited buffer. If SurfaceFlinger asks to composite the same set of buffers, the HWC can show the previously composited scratch buffer. This can improve the battery life of an idle device.

Android devices typically support four overlay planes. Attempting to composite more layers than overlays causes the system to use GLES composition for some of them, meaning the number of layers used by an app can have a measurable impact on power consumption and performance.