🚀 优质资源分享 🚀
学习路线指引(点击解锁) | 知识定位 | 人群定位 |
---|---|---|
🧡 Python实战微信订餐小程序 🧡 | 进阶级 | 本课程是python flask+微信小程序的完美结合,从项目搭建到腾讯云部署上线,打造一个全栈订餐系统。 |
💛Python量化交易实战💛 | 入门级 | 手把手带你打造一个易扩展、更安全、效率更高的量化交易系统 |
必读:
Android 12(S) 图像显示系统 - 开篇
前言
Android源码中有包含drm_hwcomposer:/external/drm_hwcomposer/
drm_hwcomposer 这个过程下的代码架构变化还是很频繁的,我这里分析直接去 drm_hwcomposer 的官方地址抓取最新的code来做分析了
解析
这个工程编译后会产生 shared library :/vendor/lib/hw/hwcomposer.drm.so
drm_hwcomposer作为一个HAL module,其写作实现还是遵循了旧有的Android HAL Module的接口实现规则。
看看一些结构体的定义以及他们之间的关系:
结构体hw_device_t的定义
[/hardware/libhardware/include/hardware/hardware.h]
typedef struct hw\_device\_t {
tag; /** tag must be initialized to HARDWARE\_DEVICE\_TAG */
uint32\_t version;
struct hw\_module\_t* module;
uint64\_t reserved[12];
int (*close)(struct hw\_device\_t* device);
} hw_device_t;
结构体hwc2_device_t的定义
[/hardware/libhardware/include/hardware/hwcomposer2.h]
typedef struct hwc2\_device {
/* Must be the first member of this struct, since a pointer to this struct
* will be generated by casting from a hw\_device\_t* */
struct hw\_device\_t common;
void (*getCapabilities)(struct hwc2\_device* device, uint32\_t* outCount,
int32\_t* /*hwc2\_capability\_t*/ outCapabilities);
hwc2\_function\_pointer\_t (*getFunction)(struct hwc2\_device* device,
int32\_t /*hwc2\_function\_descriptor\_t*/ descriptor);
} hwc2_device_t;
结构体DrmHwc2Device的定义
[drm-hwcomposer/hwc2_device/hwc2_device.cpp]
struct Drmhwc2Device : hwc2\_device {
DrmHwcTwo drmhwctwo;
};
按照结构体定义的理解,我们可以认为三个类型,具有如下继承关系
本文作者@二的次方 2022-07-05 发布于博客园
看一个关键的static方法 HookDevOpen,该方法中会去实例化一个Drmhwc2Device对象,其中去创建了一个DrmHwcTwo对象
[drm-hwcomposer/hwc2_device/hwc2_device.cpp]
static int HookDevOpen(const struct hw\_module\_t *module, const char *name,
struct hw\_device\_t **dev) {
...
auto ctx = std::make_unique<Drmhwc2Device>();
if (!ctx) {
ALOGE("Failed to allocate DrmHwcTwo");
return -ENOMEM;
}
ctx->common.tag = HARDWARE_DEVICE_TAG;
ctx->common.version = HWC_DEVICE_API_VERSION_2_0;
ctx->common.close = HookDevClose;
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
ctx->common.module = (hw_module_t *)