Surface Flinger && HWComposer

High-Level Overview

Application LayerSurface FlingerHWComposer (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

  1. SurfaceFlinger doesn’t need to know hardware details
  2. Different devices can optimize composition differently

Performance Optimization:

  1. Hardware composition can be more efficient than GPU
  2. Smart layer management reduces power consumption

Flexibility:

  1. Can fall back to GPU composition when needed
  2. 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.

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值