FrameBuffer和android系列(二)

来源:互联网 发布:水性木器漆品牌 知乎 编辑:程序博客网 时间:2024/06/05 00:52

实现一个FB的驱动,听起来很玄乎,那就让我们看看是不是像我们想的那样。

在写驱动之前,应该先看下kernel/kernel/include/linux目录下fb.h,以及kernel/kernel/drivers/video目录下的fbmem.c.

在fb.h中定义了定义了一个重要的内核空间的一个struct,就是fb_info和file_ops.

fbmem.c是我们FB驱动的核心。我们需要实现FB驱动其实就是填充fb_info,在fbmem.c里有registered_fb数组和num_registered_fb,在底层显示设备调用register_framebuffer()的时候,会将fb_info放进数组registered_fb里,num_registered_fb加1.


在register_framebuffer之前,需要实现fb_ops中的一些方法


struct fb_ops {
/* open/release and usage marking */
struct module *owner;
int (*fb_open)(struct fb_info *info, int user);
int (*fb_release)(struct fb_info *info, int user);


/* For framebuffers with strange non linear layouts or that do not
* work with normal memory mapped access
*/
ssize_t (*fb_read)(struct fb_info *info, char __user *buf,
  size_t count, loff_t *ppos);
ssize_t (*fb_write)(struct fb_info *info, const char __user *buf,
   size_t count, loff_t *ppos);


/* checks var and eventually tweaks it to something supported,
* DO NOT MODIFY PAR */
int (*fb_check_var)(struct fb_var_screeninfo *var, struct fb_info *info);


/* set the video mode according to info->var */
int (*fb_set_par)(struct fb_info *info);


/* set color register */
int (*fb_setcolreg)(unsigned regno, unsigned red, unsigned green,
   unsigned blue, unsigned transp, struct fb_info *info);


/* set color registers in batch */
int (*fb_setcmap)(struct fb_cmap *cmap, struct fb_info *info);


/* blank display */
int (*fb_blank)(int blank, struct fb_info *info);


/* pan display */
int (*fb_pan_display)(struct fb_var_screeninfo *var, struct fb_info *info);


/* Draws a rectangle */
void (*fb_fillrect) (struct fb_info *info, const struct fb_fillrect *rect);
/* Copy data from area to another */
void (*fb_copyarea) (struct fb_info *info, const struct fb_copyarea *region);
/* Draws a image to the display */
void (*fb_imageblit) (struct fb_info *info, const struct fb_image *image);


/* Draws cursor */
int (*fb_cursor) (struct fb_info *info, struct fb_cursor *cursor);


/* Rotates the display */
void (*fb_rotate)(struct fb_info *info, int angle);


/* wait for blit idle, optional */
int (*fb_sync)(struct fb_info *info);


/* perform fb specific ioctl (optional) */
int (*fb_ioctl)(struct fb_info *info, unsigned int cmd,
unsigned long arg);


/* Handle 32bit compat ioctl (optional) */
int (*fb_compat_ioctl)(struct fb_info *info, unsigned cmd,
unsigned long arg);


/* perform fb specific mmap */
int (*fb_mmap)(struct fb_info *info, struct vm_area_struct *vma);


/* get capability given var */
void (*fb_get_caps)(struct fb_info *info, struct fb_blit_caps *caps,
   struct fb_var_screeninfo *var);


/* teardown any resources to do with this framebuffer */
void (*fb_destroy)(struct fb_info *info);
};


不是这里面的所有函数都要我们去实现的,有些在fbmem.c中已经帮我们实现了的,比如说是fb_open,fb_release,fb_open,fb_write等。

在fb_info中有一个变量就是指向这个fb_ops,然后将整个fb_info放到registered_fb数组中。具体要实现哪些函数,以需求而定。

下一节将介绍FB在android中的应用。

原创粉丝点击