Android HWC

一、HWC介绍

HWC(hwcomposer)是Android中进行窗口(Layer)合成和显示的HAL层模块,其实现是特定于设备的,而且通常由显示设备制造商 (OEM)完成,为SurfaceFlinger服务提供硬件支持。

SurfaceFlinger可以使用OpenGL ES合成Layer,这需要占用并消耗GPU资源。大多数GPU都没有针对图层合成进行优化,当SurfaceFlinger通过GPU合成图层时,应用程序无法使用GPU进行自己的渲染。而HWC通过硬件设备进行图层合成,可以减轻GPU的合成压力。

显示设备的能力千差万别,很难直接用API表示硬件设备支持合成的Layer数量,Layer是否可以进行旋转和混合模式操作,以及对图层定位和硬件合成的限制等。因此HWC描述上述信息的流程是这样的:

  1. SurfaceFlinger向HWC提供所有Layer的完整列表,让HWC根据其硬件能力,决定如何处理这些Layer。

  2. HWC会为每个Layer标注合成方式,是通过GPU还是通过HWC合成。

  3. SurfaceFlinger负责先把所有注明GPU合成的Layer合成到一个输出Buffer,然后把这个输出Buffer和其他Layer(注明HWC合成的Layer)一起交给HWC,让HWC完成剩余Layer的合成和显示。

虽然每个显示设备的能力不同,但是官方要求每个 HWC 硬件模块都应该支持以下能力:

  1. 至少支持4个叠加层:状态栏、系统栏、应用本身和壁纸或者背景。

  2. 叠加层可以大于显示屏,例如:壁纸

  3. 同时支持预乘每像素(per-pixel)Alpha混合和每平面(per-plane)Alpha混合。

  4. 为了支持受保护的内容,必须提供受保护视频播放的硬件路径。

  5. RGBA packing order, YUV formats, and tiling, swizzling, and stride properties

二、HWC相关类

可以通过类图,直观感受下引用关系。

HWComposer

surfaceflinger中用来于HWComposer交互的类。

HWComposer代码位于:

frameworks/native/services/surfaceflinger/DisplayHardware/HWComposer.cpp

frameworks/native/services/surfaceflinger/DisplayHardware/HWComposer.h

HWComposer的定义:

class HWComposer {}
class HWComposer final : public android::HWComposer {}

HWComposer方法:

status_t presentAndGetReleaseFences(HalDisplayId, std::chrono::steady_clock::time_point earliestPresentTime, const std::shared_ptr<FenceTime>& previousPresentFence) override;
status_t setClientTarget(HalDisplayId, uint32_t slot, const sp<Fence>& acquireFence, const sp<GraphicBuffer>& target, ui::Dataspace) override;
status_t setOutputBuffer(HalVirtualDisplayId, const sp<Fence>& acquireFence, const sp<GraphicBuffer>& buffer) override;
status_t setActiveColorMode(PhysicalDisplayId, ui::ColorMode, ui::RenderIntent) override;
status_t setColorTransform(HalDisplayId, const mat4& transform) override;
void setVsyncEnabled(PhysicalDisplayId, hal::Vsync enabled) override;
bool onVsync(hal::HWDisplayId, int64_t timestamp) override;

Composer

Composer代码位于:

frameworks/native/services/surfaceflinger/DisplayHardware/ComposerHal.cpp

frameworks/native/services/surfaceflinger/DisplayHardware/ComposerHal.h

Composer的定义:

class Composer {}

HWC2

HWC2代码位于:

frameworks/native/services/surfaceflinger/DisplayHardware/HWC2.cpp

frameworks/native/services/surfaceflinger/DisplayHardware/HWC2.h

HWComposer的定义:

struct ComposerCallback {} //Implement this interface to receive hardware composer events.
class Display {} // Convenience C++ class to access per display functions directly.
class Display : public HWC2::Display {}
class Layer {} 
class Layer : public HWC2::Layer {} // Convenience C++ class to access per layer functions directly.

hwc2_device_t

hwc2_device_t代码位于:

hardware/libhardware/include/hardware/hwcomposer2.h

hwc2_device_t的定义:

typedef void (*hwc2_function_pointer_t)();
typedef void* hwc2_callback_data_t;
typedef uint32_t hwc2_config_t;
typedef uint64_t hwc2_display_t;
typedef uint64_t hwc2_layer_t;
typedef uint32_t hwc2_vsync_period_t;
typedef struct hwc2_device {} hwc2_device_t;

ComposerClientWriter

ComposerClientWriter代码位于:

hardware/interfaces/graphics/composer/aidl/include/android/hardware/graphics/composer3/ComposerClientWriter.h

ComposerClientWriter的定义:

class ComposerClientWriter {}

ComposerClientReader

ComposerClientReader代码位于:

hardware/interfaces/graphics/composer/aidl/include/android/hardware/graphics/composer3/ComposerClientReader.h

ComposerClientReader的定义:

class ComposerClientReader {}

HWCDisplay\HWCColorMode

HWCDisplay\HWCColorMode代码位于:

hardware/qcom/display/msm8909/sdm/libs/hwc2/hwc_display.cpp

HWCDisplay\HWCColorMode的定义:

HWCColorMode::HWCColorMode(DisplayInterface *display_intf) : display_intf_(display_intf) {}
std::bitset<kDisplayMax> HWCDisplay::validated_ = 0;
  • 20
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值