Below is an example “call stack” (or more precisely, a layered invocation flow) that shows how a display update initiated in an Android application eventually results in pixels being sent to the display hardware. Note that the exact functions and layer implementations can vary by Android version and vendor, but the following diagram illustrates a typical high‐level flow:
1. Application Layer (Your App Code)
- Example: An activity calls
setContentView() or a custom view’s invalidate()/draw() is triggered.
- What Happens:
- The app’s UI thread builds or updates the view hierarchy.
- The drawing commands (e.g., via
Canvas API) are issued within methods like onDraw().
2. Android Framework Layer
- Key Components Involved:
- View System:
- The
ViewRootImpl (which is tied to the window) receives invalidation events.
- It schedules a drawing pass (often coordinated by the
Choreographer for vsync timing).
- Window Manager / Surface Session:
- The drawing instructions eventually get rendered into a buffer (using OpenGL ES, Vulkan, or the Canvas 2D API).
- When the buffer is ready, the framework submits it to the system compositor.
- Flow Details:
- The framework posts an update via a message queue.
- The drawing thread (often a RenderThread) begins rendering the next frame.
- The resulting buffer is handed off to a Surface (and underlying BufferQueue) for further processing.
- A Binder IPC call occurs from the application process into the system process that hosts SurfaceFlinger.
3. System Service – SurfaceFlinger
- What It Does:
- SurfaceFlinger is the system compositor responsible for composing the final image on screen.
- It collects buffers submitted by various applications (or parts of the system) and composes them into the display framebuffer.
- Important Steps:
- SurfaceFlinger receives the buffer update via the BufferQueue.
- It computes the layer composition (and may decide to use hardware overlays, GPU composition, or both).
- SurfaceFlinger then calls Hardware Composer (HWC) HAL APIs to offload composition tasks to dedicated hardware if available.
4. HAL Layer – Hardware Composer (HWC HAL)
- Role of HWC:
- The Hardware Composer HAL is a vendor-supplied module that defines a standard interface (like HWC1 or HWC2) for low-level display composition.
- Invocation:
- SurfaceFlinger calls functions such as
hwcPrepare() and hwcSet() on the HWC HAL module.
- These functions determine which layers can be composed by hardware and then instruct the GPU or display controller accordingly.
- Example Flow:
- SurfaceFlinger:
prepareFrame() → hwcPrepare() (asks the HAL which layers to offload)
composeFrame() → hwcSet() (commands the hardware to assemble the final image)
5. Kernel and Device Driver Layer
- Last Mile to the Hardware:
- The HWC HAL, implemented as a shared library, interacts with the Linux kernel.
- Device Drivers:
- The HAL calls into kernel-level drivers—for example, DRM (Direct Rendering Manager) or other graphics drivers—to set display modes, handle buffer flips, and manage memory.
- Result:
- The final composed frame is written to the framebuffer or sent to the display controller hardware for output.
Summary Diagram
[ Application Code ]
│
▼
[ Android Framework ]
- View system (onDraw, ViewRootImpl)
- Window Manager / Surface (BufferQueue)
│ (Binder IPC)
▼
[ SurfaceFlinger (System Service) ]
│
▼
[ Hardware Composer (HWC HAL) ]
- hwcPrepare(), hwcSet(), etc.
│
▼
[ Kernel & Device Drivers ]
- DRM/Graphics drivers, framebuffer, display controller
│
▼
[ Display Hardware ]
Additional Notes:
-
Binder IPC:
The communication from an app (in its own process) to key system services (like SurfaceFlinger) usually involves Binder IPC. This means that control passes between processes while still following the layered abstraction.
-
Hardware Abstraction:
The HAL (Hardware Abstraction Layer) provides a standard interface to the diverse hardware. Vendors implement their hardware-specific logic behind these HAL interfaces so that SurfaceFlinger can remain hardware agnostic.
-
Variability:
The above flow is a generalization. In some scenarios (especially with more modern APIs like Vulkan, or with asynchronous composition on newer hardware), parts of this flow may change; however, the overall layered architecture remains similar.
This is a conceptual “call stack” and flow of control from an Android application’s UI event, through the framework and system compositor, down through the HAL, and finally to the display hardware.