Android研究_Hardware Composer_2 加载HWComposer模块及编译分析

      上文有提到过,HWComposer本质上就是Android的HAL层,用于提供一些api,使得AndroidFramework可以通过HWComposer接口来对硬件混合模块进行操作。这边,我们主要关注的时候HWComposer的信息,而和HAL相关的知识点,请参考文献【6】。

      在HWComposer的构建函数中,通过调用loadHwcModule()来完成HWC模块的加载。             HWC_HARDWARE_MODULE_ID是HAL中识别hwc的id,定义在/hardware/libhardware/include/hardware/HWComposer.h中:

#defineHWC_HARDWARE_MODULE_ID "HWComposer"。

// Load and prepare the hardware composer module.  Sets mHwc.

void HWComposer::loadHwcModule()

{

    hw_module_t const* module;

 

// 根据HAL加载库的规则,会先从"/vendor/lib/hw",再从"/system/lib/hw"目录下面去寻找HWComposer.”subname”.so,其中“subname”是从如下几个属性值获取的,比如"ro.hardware""ro.product.board" "ro.board.platform""ro.arch"。我们以N5为例子,这个过程加载的so库为:system/lib/hw/HWComposer.msm8974.so

    if (hw_get_module(HWC_HARDWARE_MODULE_ID, &module) != 0) {

        ALOGE("%s module not found", HWC_HARDWARE_MODULE_ID);

        return;

    }

 

// 然后打开HWC_HARDWARE_COMPOSER设备。在实际的代码中,这个主要用于module name的校验。

    int err = hwc_open_1(module, &mHwc);

    if (err) {

        ALOGE("%s device failed to initialize (%s)",

              HWC_HARDWARE_COMPOSER, strerror(-err));

        return;

    }

 

    if (!hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_0) ||

            hwcHeaderVersion(mHwc) < MIN_HWC_HEADER_VERSION ||

            hwcHeaderVersion(mHwc) > HWC_HEADER_VERSION) {

        ALOGE("%s device version %#x unsupported, will not be used",

              HWC_HARDWARE_COMPOSER, mHwc->common.version);

        hwc_close_1(mHwc);

        mHwc = NULL;

        return;

    }

}

HWComposer.msm8974.so源码位置为:hardware/qcom/display/msm8974/libHWComposer。并在编译的时候,通过PRODUCT_PACKAGES完成安装。

@device/tencent/hammerhead/device.mk

PRODUCT_PACKAGES += \

    gralloc.msm8974 \

    libgenlock \

    HWComposer.msm8974 \

    memtrack.msm8974 \

    libqdutils \

    libqdMetaData

 

在该目录下的hwc.cpp中,有对HWComposer module做了详细的定义:

static int hwc_device_open(const struct hw_module_t* module,

                           const char* name,

                           struct hw_device_t** device);

 

static struct hw_module_methods_t hwc_module_methods = {

    open: hwc_device_open

};

 

hwc_module_t HAL_MODULE_INFO_SYM = {

    common: {

        tag: HARDWARE_MODULE_TAG, // HAL规定写死

        version_major: 2,

        version_minor: 0,

        id: HWC_HARDWARE_MODULE_ID,

        name: "Qualcomm Hardware Composer Module",

        author: "CodeAurora Forum",

        methods: &hwc_module_methods,

        dso: 0,

        reserved: {0},

    }

};

从上面的代码中可以知道,err = hwc_open_1(module,&mHwc);最后调用的是hwc_device_open。

static int hwc_device_open(const struct hw_module_t* module, const char* name,

                           struct hw_device_t** device)

{

    int status = -EINVAL;

 

    if (!strcmp(name, HWC_HARDWARE_COMPOSER)) {

        struct hwc_context_t *dev;

        dev = (hwc_context_t*)malloc(sizeof(*dev));

        memset(dev, 0, sizeof(*dev));

 

        //Initialize hwc context

        initContext(dev);

 

        //Setup HWC methods

        dev->device.common.tag          = HARDWARE_DEVICE_TAG;

        dev->device.common.version      = HWC_DEVICE_API_VERSION_1_3;

        dev->device.common.module       = const_cast(module);

        dev->device.common.close        = hwc_device_close;

        dev->device.prepare             = hwc_prepare;

        dev->device.set                 = hwc_set;

        dev->device.eventControl        = hwc_eventControl;

        dev->device.blank               = hwc_blank;

        dev->device.query               = hwc_query;

        dev->device.registerProcs       = hwc_registerProcs;

        dev->device.dump                = hwc_dump;

        dev->device.getDisplayConfigs   = hwc_getDisplayConfigs;

        dev->device.getDisplayAttributes = hwc_getDisplayAttributes;

        *device = &dev->device.common;

        status = 0;

    }

    return status;

}

 

你可能感兴趣的:(hwc,android)