Android 12(S) 图像显示系统

您所在的位置:网站首页 qti进程 Android 12(S) 图像显示系统

Android 12(S) 图像显示系统

2023-08-15 18:41| 来源: 网络整理| 查看: 265

必读:

Android 12(S) 图像显示系统 - 开篇

 

接口定义

源码位置:/hardware/interfaces/graphics/composer/

在源码目录下可以看到4个版本的HIDL Interface定义,最新版本是2.4,也是目前我的测试平台在用的,不同版本使用带有版本号的包名来区分,例如 :package [email protected]各版本中均有相同的接口,并且具有继承关系,新版本继承旧版接口并扩展了新方法。

/frameworks/native/services/surfaceflinger/DisplayHardware/ 中 android::Hwc2::impl::Composer 相当于HIDL的客户端,framework通过impl::Composer中的方法看跨进程和 hwc hal 互动。

各个版本接口的继承关系

 

Composer HIDL Service

代码位置/hardware/interfaces/graphics/composer/2.4/default/service.cpp/hardware/interfaces/graphics/composer/2.4/default/[email protected]

开机启动时,init进程解析rc文件带起服务进程,在service.cpp的main函数中,注册服务

int main() { ... android::sp composer = HwcLoader::load(); if (composer == nullptr) { return 1; } if (composer->registerAsService() != android::NO_ERROR) { ALOGE("failed to register service"); return 1; } ... }

 

可以看到其中调用了一个非常重要的方法HwcLoader::load(),看其代码:

[/hardware/interfaces/graphics/composer/2.4/utils/passthrough/include/composer-passthrough/2.4/HwcLoader.h] static IComposer* load() { const hw_module_t* module = loadModule(); if (!module) { return nullptr; } auto hal = createHalWithAdapter(module); if (!hal) { return nullptr; } return createComposer(std::move(hal)).release(); }

 

再看loadModule的定义,去找HAL library中定义的HAL_MODULE_INFO_SYM结构体变量

[/hardware/interfaces/graphics/composer/2.1/utils/passthrough/include/composer-passthrough/2.1/HwcLoader.h] static const hw_module_t* loadModule() { const hw_module_t* module; int error = hw_get_module(HWC_HARDWARE_MODULE_ID, &module); if (error) { ALOGI("falling back to gralloc module"); error = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module); } if (error) { ALOGE("failed to get hwcomposer or gralloc module"); return nullptr; } return module; }

 

可以看到基本的调用流程:开机启动 ==> HwcLoader::load() ==> HwcLoader::loadModule() ==> hw_get_module

hw_get_module就是去打开Vendor厂商实现的HWC HAL模块,这个流程本质上还是旧有的HAL打开方式,只是外包装了一层HIDL。最终得到一个指向HWC module的hw_module_t指针

再回到HwcLoader::load()方法中,接下来就是  createHalWithAdapter ==>  createComposer

 

先看 createHalWithAdapter 做了哪些工作

[/hardware/interfaces/graphics/composer/2.4/utils/passthrough/include/composer-passthrough/2.4/HwcLoader.h] // create a ComposerHal instance, insert an adapter if necessary static std::unique_ptr createHalWithAdapter(const hw_module_t* module) { bool adapted; hwc2_device_t* device = openDeviceWithAdapter(module, &adapted); if (!device) { return nullptr; } auto hal = std::make_unique(); return hal->initWithDevice(std::move(device), !adapted) ? std::move(hal) : nullptr; }

 

其中调用了openDeviceWithAdapter去打开 hwc2_device_t

[/hardware/interfaces/graphics/composer/2.1/utils/passthrough/include/composer-passthrough/2.1/HwcLoader.h] // open hwcomposer2 device, install an adapter if necessary static hwc2_device_t* openDeviceWithAdapter(const hw_module_t* module, bool* outAdapted) { if (module->id && std::string(module->id) == GRALLOC_HARDWARE_MODULE_ID) { *outAdapted = true; return adaptGrallocModule(module); } hw_device_t* device; int error = module->methods->open(module, HWC_HARDWARE_COMPOSER, &device); if (error) { ALOGE("failed to open hwcomposer device: %s", strerror(-error)); return nullptr; } int major = (device->version >> 24) & 0xf; if (major != 2) { *outAdapted = true; return adaptHwc1Device(std::move(reinterpret_cast(device))); } *outAdapted = false; return reinterpret_cast(device); }

 

openDeviceWithAdapter中调用了open方法

hw_device_t* device; int error = module->methods->open(module, HWC_HARDWARE_COMPOSER, &device);

 

这样就获取到了 hwc2_device

typedef struct hwc2_device { 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;

 

回到createHalWithAdapter中再调用initWithDevice及保存到了HwcHal中的mDevice这个变量中

bool initWithDevice(hwc2_device_t* device, bool requireReliablePresentFence) { // we own the device from this point on mDevice = device; …. }

getFunction函数关联到了 vendor 厂商实现的hwc hal中具体实现,这个函数通过函数描述符来获取对应的函数指针。 

initDispatch的作用介绍

initDispatch()来初始化HWC通用的函数指针

 

2.4 handle; } mWriter.setClientTarget(slot, handle, acquireFence, dataspace, damage); return Error::NONE; }

 

中转站:

[/hardware/interfaces/graphics/composer/2.1/utils/command-buffer/include/composer-command-buffer/2.1/ComposerCommandBuffer.h] void setClientTargetInternal(...) { beginCommand(IComposerClient::Command::SET_CLIENT_TARGET, length); ... endCommand(); } 跨进程了 [/hardware/interfaces/graphics/composer/2.1/utils/hal/include/composer-hal/2.1/ComposerCommandEngine.h] virtual bool executeCommand(IComposerClient::Command command, uint16_t length) { switch (command) { ... case IComposerClient::Command::SET_CLIENT_TARGET: return executeSetClientTarget(length); } } bool executeSetClientTarget(uint16_t length) { ... err = mHal->setClientTarget(mCurrentDisplay, clientTarget, fence, dataspace, damage); ... }

 

处理终端:

Vendor厂商实现的HAL,具体实现setClientTarget的功能 

 

 

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3