Gralloc.default.so 的实现


默认的Gralloc模块实现的代码路径如下:
hardware/libhardware/modules/gralloc/*

  1. $ ls hardware/libhardware/modules/gralloc/
  2. Android.mk framebuffer.cpp gralloc.cpp gralloc_priv.h gr.h mapper.cpp
1. gralloc.c, 实现了 gralloc_module_t 模块和 alloc_device_t 设备
    int gralloc_device_open(const hw_module_t* module, const char* name,
            hw_device_t** device)
    {
        int status = -EINVAL;
        if (!strcmp(name, GRALLOC_HARDWARE_GPU0)) {    //打开alloc_device_t设备
            gralloc_context_t *dev;
            dev = (gralloc_context_t*)malloc(sizeof(*dev));
            /* initialize our state here */
            memset(dev, 0, sizeof(*dev));
            /* initialize the procs */
            dev->device.common.tag = HARDWARE_DEVICE_TAG;
            dev->device.common.version = 0;
            dev->device.common.module = const_cast<hw_module_t*>(module);
            dev->device.common.close = gralloc_close;
            dev->device.alloc = gralloc_alloc;   //alloc_device_t的alloc接口
            dev->device.free = gralloc_free;     //alloc_device_t的free接口
            *device = &dev->device.common;
            status = 0;
        } else {
            status = fb_device_open(module, name, device);   //打开framebuffer_device_t设备
        }
        return status;
    }

private_module_t 扩展了 gralloc_module_t 结构:
    struct private_module_t HAL_MODULE_INFO_SYM= {
        base:{                   //base 就是gralloc_module_t
            common:{
                tag: HARDWARE_MODULE_TAG,
                version_major: 1,
                version_minor: 0,
                id: GRALLOC_HARDWARE_MODULE_ID,
                name:"Graphics Memory Allocator Module",
                author:"The Android Open Source Project",
                methods:&gralloc_module_methods
            },
            registerBuffer: gralloc_register_buffer,    //都是gralloc_module_t的方法,这些方法都在mapper.cpp中实现。
            unregisterBuffer: gralloc_unregister_buffer,
            lock: gralloc_lock,
            unlock: gralloc_unlock,
        },
        framebuffer: 0,
        flags: 0,
        numBuffers: 0,
        bufferMask: 0,
        lock: PTHREAD_MUTEX_INITIALIZER,
        currentBuffer: 0,
    };

private_module_t 原型定义在gralloc_priv.h中
    struct private_module_t{
        gralloc_module_t base;    
        
        private_handle_t* framebuffer;
        uint32_t flags;
        uint32_t numBuffers;
        uint32_t bufferMask;
        pthread_mutex_t lock;
        buffer_handle_t currentBuffer;
        int pmem_master;
        void* pmem_master_
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值