因为camera要申请gralloc buf的缘故,打算仔细看看grallocbuf的原理,其实之前大概知道一些,这次梳理一下。因为部分接口封成了库,所以也没有去看相关代码,但是可以理解概念,知道gralloc是什么,怎么用就可以了。
Gralloc封装了用户层对帧缓冲区的操作接口,他可以申请图形缓冲区,然后将个缓冲区映射到应用程序上来,接下来就可以绘制界面。
主要是用于gpu和fb的操作,gpu用于分配图形缓冲,fb用于渲染帧缓冲。
但是rk从安卓7.1之后实现drm驱动,fb部分被删除了,应该是底层包含这部分功能。
先看看gralloc.h里面的结构
typedef struct gralloc_module_t {
struct hw_module_t common;//hal标准定义
//注册图形缓冲区,实际将一块图形缓冲区映射到一个进程的地址空间去
int (*registerBuffer)(struct gralloc_module_t const* module,
buffer_handle_t handle);
int (*unregisterBuffer)(struct gralloc_module_t const* module,
buffer_handle_t handle);
//可以锁定,防止冲突,这里可以锁定缓冲区特定区域
int (*lock)(struct gralloc_module_t const* module,
buffer_handle_t handle, int usage,
int l, int t, int w, int h,
void** vaddr);
int (*unlock)(struct gralloc_module_t const* module,
buffer_handle_t handle);
int (*lock_ycbcr)(struct gralloc_module_t const* module,
buffer_handle_t handle, int usage,
int l, int t, int w, int h,
struct android_ycbcr *ycbcr);
int (*lockAsync)(s