High-Level Overview
Application Layer
↓
Surface Flinger
↓
HWComposer (HAL)
↓
Display Hardware
Detailed Relationship
SurfaceFlinger’s Role:
Acts as the display server in Android
Manages all visible surfaces (windows) in the system
Decides how and when to composite different surfaces
Maintains the screen’s buffer queue
Coordinates with multiple clients (apps)
HWComposer’s Role:
Hardware abstraction layer (HAL) for display hardware
Provides hardware-specific composition capabilities
Handles VSYNC timing
Manages display properties and configurations
Their Interaction:
SurfaceFlinger calls HWComposer in two main phases:
// Phase 1: Prepare
hwc_prepare() // HWComposer suggests composition strategy
// Phase 2: Set
hwc_set() // Actually compose the layers
Composition Types:
HWComposer can handle layers in different ways:
HWC_OVERLAY // Handled by hardware
HWC_FRAMEBUFFER // Handled by GPU
HWC_BACKGROUND // Background layer
HWC_FRAMEBUFFER_TARGET // Final composed buffer
VSYNC Coordination:
// HWComposer generates VSYNC events
pdev->procs->vsync(pdev->procs, 0, timestamp);
// SurfaceFlinger receives these events to time compositions
Example Flow:
1. App draws content → Surface
2. SurfaceFlinger collects all visible surfaces
3. SurfaceFlinger asks HWComposer how to compose (prepare)
4. HWComposer suggests composition strategy
5. SurfaceFlinger follows strategy (GPU or Hardware composition)
6. HWComposer handles final composition (set)
7. Display shows the frame
Key Benefits of This Architecture
Key Benefits of This Architecture
- SurfaceFlinger doesn’t need to know hardware details
- Different devices can optimize composition differently
Performance Optimization:
- Hardware composition can be more efficient than GPU
- Smart layer management reduces power consumption
Flexibility:
- Can fall back to GPU composition when needed
- Supports various display configurations
This relationship allows Android to efficiently manage displays across many different hardware platforms while maintaining consistent behavior at the application level.

1540

被折叠的 条评论
为什么被折叠?



