gralloc
接口定义
源代码:
hardware/libhardware/include/hardware/gralloc.h
hardware/libhardware/include/hardware/fb.h
- gralloc_module_t("gralloc")
- alloc_device_t("gpu0")
- framebuffer_device_t("fb0")
gralloc_module_t的接口:
成员 | 类型 | 说明 |
registerBuffer | int(*) | 其他进程获得缓存句柄后,需要注册 |
unregisterBuffer | int(*) | 注销缓存 |
lock | int(*) | 通过lock获得缓存的地址 |
unlock | int(*) | 解除锁定,让其他模块能够锁定缓存 |
perform | int(*) | 保留将来使用 |
lock_ycbcr | int(*) |
alloc_device_t的接口:
成员 | 类型 | 说明 |
alloc | int(*) | 申请一个缓存 |
free | int(*) | 释放一个缓存 |
dump | void(*) |
framebuffer_device_t的接口:
成员 | 类型 | 说明 |
flags | uint32_t | 标志位,指示framebuffer的属性配置 |
width height | uint32_t uint32_t | framebuffer的宽和高,以像素为单位 |
format | int | framebuffer的像素格式,比如:HAL_PIXEL_FORMAT_RGBA_8888 HAL_PIXEL_FORMAT_RGBX_8888 HAL_PIXEL_FORMAT_RGB_888 HAL_PIXEL_FORMAT_RGB_565等等 |
xdpi ydpi | float float | x和y轴的密度(pixel per inch) |
fps | float | 屏幕的每秒刷新频率,假如无法正常从设备获取的话,默认设置为60Hz |
minSwapInterval maxSwapInterval | Int int | 该framebuffer支持的最小和最大缓冲交换时间 |
setSwapInterval | int(*) | |
setUpdateRect | int(*) | |
post | int(*) | |
compositionComplete | int(*) | |
dump | void(*) | |
enableScreen | int(*) |
很多接口与buffer_handle_t有关系,buffer_handle_t描述了一个缓存句柄。其定义可能位于system/core/include/system/window.h:
typedef const native_handle_t* buffer_handle_t;
-
-
-
- 接口实现
-
-
源代码位于:hardware/libhardware/modules/gralloc
这里只是简单的默认实现。
private_module_t实现了gralloc_module_t
private_handle_t实现了 buffer_handle_t,他继承native_handle_t。
native_handle_t是libcutils提供的Native句柄,通过Binder驱动能够实现跨进程复制该句柄,句柄内的文件描述符会在目标进程重新打开,其他字段通过内存拷贝复制。
缓存有两种实现,一是fb的硬件存储,一个是ashm共享内存。如果fb不支持双缓冲,其中一个缓存用ashm共享内存代替,在缓存翻转时使用内存拷贝实现。
-
-
- hwcomposer
- 接口定义
- hwcomposer
-
源代码:
hardware/libhardware/include/hardware/hwcomposer.h
- hwc_module_t("hwcomposer")
- hwc_composer_device_1_t("composer")
hwc_composer_device_1_t的接口:
成员 | 类型 | 说明 |
prepare | int(*) | |
set | int(*) | |
eventControl | int (*) | |
blank | int (*) | |
query | int (*) | |
registerProcs | void(*) | |
dump | void(*) | 可以为NULL |
getDisplayConfigs | int (*) | 1.1及以上支持 |
getDisplayAttributes | int (*) | 1.1及以上支持,1.0需要通过fb获取属性 |
-
-
-
- 版本历史
-
-
- 1.0
版本 | 多设备 | 透明 | 虚拟输出 |
1.0 | 1个主设备 | 不支持 | 不支持 |
1.1 | 多个内建设备 | 不支持 | 不支持 |
1.2 | 多个内建设备 | 支持 | 不支持 |
1.3 | 增加虚拟设备 | 支持 | 支持 |
只支持一个显示设备,OpenGL ES目标层通过hwc_display_contents_1的dpy、sur成员传递。
- 1.1
支持多个显示设备,OpenGL ES目标层HWC_FRAMEBUFFER_TARGET特殊hwc_layer_t层传递,hwc_display_contents_1的dpy、sur成员无效。
- 1.2
支持透明度(planeAlpha)。
- 1.3
支持虚拟设备,hwc_display_contents_1的dpy、sur成员改为outbuf、outbufAcquireFenceFd。
-
-
-
- 接口实现
-
-
源代码位于:hardware/libhardware/modules/hwcomposer,不过这里只有一个空实现。
网上提到通过下面的调用等待vsync中断:
ioctl(mFbFd, FBIO_WAITFORVSYNC, NULL)