分类: 嵌入式
2011-08-27 10:45:20
Copybit HAL模块分析报告
Rockie Cheng
aokikyon@gmail.com
1、copybit模块的继承关系图
2、copybit模块支持的图像格式
注意,并不是所有硬件都支持这么多格式
COPYBIT_FORMAT_RGBA_8888 = HAL_PIXEL_FORMAT_RGBA_8888,
COPYBIT_FORMAT_RGBX_8888 = HAL_PIXEL_FORMAT_RGBX_8888,
COPYBIT_FORMAT_RGB_888 = HAL_PIXEL_FORMAT_RGB_888,
COPYBIT_FORMAT_RGB_565 = HAL_PIXEL_FORMAT_RGB_565,
COPYBIT_FORMAT_BGRA_8888 = HAL_PIXEL_FORMAT_BGRA_8888,
COPYBIT_FORMAT_RGBA_5551 = HAL_PIXEL_FORMAT_RGBA_5551,
COPYBIT_FORMAT_RGBA_4444 = HAL_PIXEL_FORMAT_RGBA_4444,
COPYBIT_FORMAT_YCbCr_422_SP = HAL_PIXEL_FORMAT_YCbCr_422_SP,
COPYBIT_FORMAT_YCbCr_420_SP = HAL_PIXEL_FORMAT_YCbCr_420_SP,
3、copybit支持的功能
u 图像旋转
Ø 90°、180°、270°、水平翻转、垂直翻转
u Alpha Blending
Ø 数值范围0-255
u 抖动
u 透明
u 模糊
u 剪裁
u Stretch(缩放)
u Bit Blit(块拷贝,支持xy坐标)
4、图像结构体
struct copybit_image_t {
/* width 宽度*/
uint32_t w;
/* height 高度 */
uint32_t h;
/* format COPYBIT_FORMAT_xxx格式 */
int32_t format;
/* base of buffer with image 基址*/
void *base;
/* handle to the image 图像句柄,Native_handle.h (system\core\include\cutils)中定义*/
native_handle_t* handle;
};
5、copybit模块支持的函数接口
(1)设置参数
int (*set_parameter)(struct copybit_device_t *dev, int name, int value);
(2)获取信息
int (*get)(struct copybit_device_t *dev, int name);
(3)Blit操作
int (*blit)(struct copybit_device_t
*dev,
struct copybit_image_t const *dst,
struct copybit_image_t const *src,
struct copybit_region_t const *region);
(4)Stretch操作
int (*stretch)(struct
copybit_device_t *dev,
struct copybit_image_t const *dst,
struct copybit_image_t const *src,
struct copybit_rect_t const *dst_rect,
struct copybit_rect_t const *src_rect,
struct copybit_region_t const *region);
高通Copybit 模块 HAL分析
1、Copybit Module写法
struct copybit_module_t HAL_MODULE_INFO_SYM = {
common: {
tag: HARDWARE_MODULE_TAG,
version_major: 1,
version_minor: 0,
id: COPYBIT_HARDWARE_MODULE_ID,
name: "QCT MSM7K COPYBIT Module",
author: "Google, Inc.",
methods: ©bit_module_methods
}
};
2、私有函数
(1)min(int a, int b)
(2)max(int a, int b)
(3)void MULDIV(uint32_t *a, uint32_t *b, int mul, int div)
(4)void intersect(struct copybit_rect_t *out,
const struct copybit_rect_t *lhs,
const struct copybit_rect_t *rhs)
作用:Clip函数
(5)get_format(int format)
作用:获取图形格式
(6)void set_image(struct mdp_img *img, const struct copybit_image_t *rhs)
作用:将Copybitimage结构体转换为mdp image结构
(7)void set_rects(struct copybit_context_t *dev,
struct mdp_blit_req *e,
const struct copybit_rect_t *dst,
const struct copybit_rect_t *src,
const struct copybit_rect_t *scissor)
作用:设置矩形框
(8)void set_infos(struct copybit_context_t *dev, struct mdp_blit_req *req)
作用:设置mdp请求
(9)int msm_copybit(struct copybit_context_t *dev, void const *list)
作用:执行copybit操作
3、共有函数
(1)int set_parameter_copybit(
struct copybit_device_t *dev,
int name,
int value)
作用:设置参数
参数类型:
旋转 0 90 180 270
Alpha 0-255
抖动 使能/禁止
模糊 使能/禁止
透明 0-7
(2) int get(struct copybit_device_t *dev, int name)
作用:获取固定参数
参数:
最小缩放小数位4-msm7k 8-msm8k
最大缩放小数位4-msm7k 8-msm8k
Copybit缩放小数位32
Copybit旋转步进角度(90°)
(3)int stretch_copybit(
struct copybit_device_t *dev,
struct copybit_image_t const *dst,
struct copybit_image_t const *src,
struct copybit_rect_t const *dst_rect,
struct copybit_rect_t const *src_rect,
struct copybit_region_t const *region)
作用,做stretch 和blit操作
通过一个while循环,积攒12个region,一次调用硬件驱动ioctl函数,将数据传入驱动,进行stretch操作。
(4)int blit_copybit(
struct copybit_device_t *dev,
struct copybit_image_t const *dst,
struct copybit_image_t const *src,
struct copybit_region_t const *region)
作用:该操作没有stretch操作
4、高通驱动中的不足之处:
查看内核2D驱动可知,MSM7k的做法是将buffer数据通过copy from user函数复制到内核态,再由硬件驱动进行搬运。这样在一定程度上会导致硬件加速效率降低。不过MSM7K使用了一个折中的做法,搬运的数据积攒到一定程度(12个),在一次调用硬件驱动,统一传输,可以起到一定的缓冲作用。