帧缓冲库

帧缓冲驱动程序在很大程度上依赖于四个数据结构。这些结构在 include/linux/fb.h 中声明。它们是 fb_info、fb_var_screeninfo、fb_fix_screeninfo 和 fb_monospecs。最后三个可以与用户空间进行交互。

fb_info 定义特定显卡的当前状态。在 fb_info 内部,存在一个 fb_ops 结构,它是使 fbdev 和 fbcon 工作的所需函数的集合。fb_info 仅对内核可见。

fb_var_screeninfo 用于描述用户定义的显卡功能。使用 fb_var_screeninfo,可以定义诸如深度和分辨率之类的内容。

下一个结构是 fb_fix_screeninfo。这定义了在设置模式时创建的卡的属性,否则无法更改。一个很好的例子是帧缓冲内存的开始。这“锁定”了帧缓冲内存的地址,使其无法更改或移动。

最后一个结构是 fb_monospecs。在旧的 API 中,fb_monospecs 几乎不重要。这允许诸如在固定频率监视器上设置 800x600 模式之类的禁止操作。使用新的 API,fb_monospecs 可以防止此类事情发生,如果使用正确,可以防止监视器烧坏。fb_monospecs 在内核 2.5.x 之前不会有用。

帧缓冲内存

int register_framebuffer(struct fb_info *fb_info)

注册帧缓冲设备

参数

struct fb_info *fb_info

帧缓冲信息结构

注册帧缓冲设备 fb_info

出错时返回负 errno,成功时返回零。

void unregister_framebuffer(struct fb_info *fb_info)

释放帧缓冲设备

参数

struct fb_info *fb_info

帧缓冲信息结构

取消注册帧缓冲设备 fb_info

出错时返回负 errno,成功时返回零。

此函数还将通知帧缓冲控制台释放驱动程序。

这应该在驱动程序的 module_exit() 函数中调用。如果在 module_exit() 之外调用此函数,请确保驱动程序实现 fb_open() 和 fb_release() 以检查是否有进程正在使用该设备。

int devm_register_framebuffer(struct device *dev, struct fb_info *fb_info)

资源管理的帧缓冲设备注册

参数

struct device *dev

帧缓冲所属的设备

struct fb_info *fb_info

帧缓冲信息结构

将帧缓冲设备 fb_info 注册到设备 dev

出错时返回负 errno,成功时返回零。

void fb_set_suspend(struct fb_info *info, int state)

底层驱动程序发出暂停信号

参数

struct fb_info *info

受影响的帧缓冲

int state

0 = 恢复,!=0 = 暂停

这应该由底层驱动程序使用,以向核心和客户端发出暂停/恢复信号。必须在持有控制台信号量的情况下调用它

帧缓冲颜色映射

void fb_dealloc_cmap(struct fb_cmap *cmap)

释放颜色映射

参数

struct fb_cmap *cmap

帧缓冲颜色映射结构

释放先前使用 fb_alloc_cmap() 分配的颜色映射。

int fb_copy_cmap(const struct fb_cmap *from, struct fb_cmap *to)

复制颜色映射

参数

const struct fb_cmap *from

帧缓冲颜色映射结构

struct fb_cmap *to

帧缓冲颜色映射结构

将颜色映射的内容从 from 复制到 to

int fb_set_cmap(struct fb_cmap *cmap, struct fb_info *info)

设置颜色映射

参数

struct fb_cmap *cmap

帧缓冲颜色映射结构

struct fb_info *info

帧缓冲信息结构

为设备 info 的屏幕设置颜色映射 cmap

出错时返回负 errno,成功时返回零。

const struct fb_cmap *fb_default_cmap(int len)

获取默认颜色映射

参数

int len

深度的调色板大小

获取特定屏幕深度的默认颜色映射。 len 是特定屏幕深度的调色板大小。

返回指向帧缓冲颜色映射结构的指针。

void fb_invert_cmaps(void)

反转所有默认颜色映射

参数

void

没有参数

描述

反转所有默认颜色映射。

帧缓冲视频模式数据库

int fb_try_mode(struct fb_var_screeninfo *var, struct fb_info *info, const struct fb_videomode *mode, unsigned int bpp)

测试视频模式

参数

struct fb_var_screeninfo *var

用户定义的显示器帧缓冲部分

struct fb_info *info

帧缓冲信息结构

const struct fb_videomode *mode

帧缓冲视频模式结构

unsigned int bpp

每个像素的颜色深度(以位为单位)

尝试一种视频模式,以测试其对设备 info 的有效性。

成功时返回 1。

void fb_delete_videomode(const struct fb_videomode *mode, struct list_head *head)

从模型列表中删除视频模式条目

参数

const struct fb_videomode *mode

要删除的视频模式

struct list_head *head

模型列表的 struct list_head

注意

将删除所有匹配的模式条目

int fb_find_mode(struct fb_var_screeninfo *var, struct fb_info *info, const char *mode_option, const struct fb_videomode *db, unsigned int dbsize, const struct fb_videomode *default_mode, unsigned int default_bpp)

查找有效的视频模式

参数

struct fb_var_screeninfo *var

用户定义的显示器帧缓冲部分

struct fb_info *info

帧缓冲信息结构

const char *mode_option

要查找的字符串视频模式

const struct fb_videomode *db

视频模式数据库

unsigned int dbsize

db 的大小

const struct fb_videomode *default_mode

要回退到的默认视频模式

unsigned int default_bpp

默认颜色深度(以位为单位)

描述

查找合适的视频模式,从 mode_option 中指定的模式开始,回退到 default_mode。如果 default_mode 失败,将尝试视频模式数据库中的所有模式。

mode_option 的有效模式说明符

<xres>x<yres>[M][R][-<bpp>][@<refresh>][i][p][m]

或者

<name>[-<bpp>][@<refresh>]

其中 <xres>、<yres>、<bpp> 和 <refresh> 是十进制数,<name> 是字符串。

如果在 yres 之后(如果在场,则在 refresh/bpp 之前)存在 ‘M’,则该函数将使用 VESA(tm) 协同视频定时 (CVT) 计算定时。 如果在 ‘M’ 之后存在 ‘R’,则将使用减少的消隐(对于平板)进行计算。 如果存在 ‘i’ 或 ‘p’,则计算交错或逐行模式。 如果存在 ‘m’,则添加等于 xres 的 1.8%(向下舍入到 8 像素)和 yres 的 1.8% 的边距。字符 ‘i’、‘p’ 和 ‘m’ 必须在 ‘M’ 和 ‘R’ 之后。示例

1024x768MR-8@60m - Reduced blank with margins at 60Hz.

失败时返回零,如果使用指定的 mode_option 则返回 1,如果使用指定的 mode_option 但忽略了刷新率则返回 2,如果使用默认模式则返回 3,如果回退到任何有效模式则返回 4。

注意

传递的 struct var _未_ 清除! 这使您可以为例如灰度和 accel_flags 字段提供值。

void fb_var_to_videomode(struct fb_videomode *mode, const struct fb_var_screeninfo *var)

将 fb_var_screeninfo 转换为 fb_videomode

参数

struct fb_videomode *mode

指向 struct fb_videomode 的指针

const struct fb_var_screeninfo *var

指向 struct fb_var_screeninfo 的指针

void fb_videomode_to_var(struct fb_var_screeninfo *var, const struct fb_videomode *mode)

将 fb_videomode 转换为 fb_var_screeninfo

参数

struct fb_var_screeninfo *var

指向 struct fb_var_screeninfo 的指针

const struct fb_videomode *mode

指向 struct fb_videomode 的指针

int fb_mode_is_equal(const struct fb_videomode *mode1, const struct fb_videomode *mode2)

比较 2 个视频模式

参数

const struct fb_videomode *mode1

第一个视频模式

const struct fb_videomode *mode2

第二个视频模式

返回值

相等则返回 1,否则返回 0

const struct fb_videomode *fb_find_best_mode(const struct fb_var_screeninfo *var, struct list_head *head)

查找最佳匹配的视频模式

参数

const struct fb_var_screeninfo *var

指向 struct fb_var_screeninfo 的指针

struct list_head *head

指向 modelist 的 struct list_head 的指针

返回值

struct fb_videomode, 如果未找到则为 NULL

描述

重要提示:此函数假定 info->modelist 中的所有 modelist 条目均有效。

注意

查找最佳匹配的视频模式,该视频模式的尺寸等于或大于 var->xres 和 var->yres。 如果找到多个视频模式,将返回刷新率最高的视频模式

const struct fb_videomode *fb_find_nearest_mode(const struct fb_videomode *mode, struct list_head *head)

查找最接近的视频模式

参数

const struct fb_videomode *mode

指向 struct fb_videomode 的指针

struct list_head *head

指向 modelist 的指针

描述

查找尺寸上最佳匹配的视频模式,无论尺寸是较小还是较大。如果找到多个视频模式,将返回刷新率最接近的视频模式。

const struct fb_videomode *fb_match_mode(const struct fb_var_screeninfo *var, struct list_head *head)

查找与 var 中的时序完全匹配的视频模式

参数

const struct fb_var_screeninfo *var

指向 struct fb_var_screeninfo 的指针

struct list_head *head

指向 modelist 的 struct list_head 的指针

返回值

struct fb_videomode, 如果未找到则为 NULL

int fb_add_videomode(const struct fb_videomode *mode, struct list_head *head)

将视频模式条目添加到 modelist

参数

const struct fb_videomode *mode

要添加的视频模式

struct list_head *head

模型列表的 struct list_head

注意

只会添加未匹配的模式条目

void fb_destroy_modelist(struct list_head *head)

销毁 modelist

参数

struct list_head *head

模型列表的 struct list_head

void fb_videomode_to_modelist(const struct fb_videomode *modedb, int num, struct list_head *head)

将模式数组转换为模式列表

参数

const struct fb_videomode *modedb

struct fb_videomode 数组

int num

数组中的条目数

struct list_head *head

模型列表的 struct list_head

帧缓冲 Macintosh 视频模式数据库

int mac_vmode_to_var(int vmode, int cmode, struct fb_var_screeninfo *var)

将 vmode/cmode 对转换为 var 结构

参数

int vmode

MacOS 视频模式

int cmode

MacOS 颜色模式

struct fb_var_screeninfo *var

帧缓冲视频模式结构

将 MacOS vmode/cmode 对转换为帧缓冲视频模式结构。

出错时返回负 errno,成功时返回零。

int mac_map_monitor_sense(int sense)

将监视器感应转换为 vmode

参数

int sense

Macintosh 监视器感应编号

将 Macintosh 监视器感应编号转换为 MacOS vmode 编号。

返回 MacOS vmode 视频模式编号。

int mac_find_mode(struct fb_var_screeninfo *var, struct fb_info *info, const char *mode_option, unsigned int default_bpp)

查找视频模式

参数

struct fb_var_screeninfo *var

用户定义的显示器帧缓冲部分

struct fb_info *info

帧缓冲信息结构

const char *mode_option

视频模式名称(请参阅 mac_modedb[])

unsigned int default_bpp

默认颜色深度(以位为单位)

查找合适的视频模式。尝试设置由 mode_option 指定的模式。如果所需模式的名称以“mac”开头,将使用 Mac 视频模式数据库,否则将回退到标准视频模式数据库。

注意

函数标记为 __init 且只能在

系统启动期间使用。

返回来自 fb_find_mode 的错误代码(请参阅 fb_find_mode 函数)。

帧缓冲字体

有关更多信息,请参阅文件 lib/fonts/fonts.c。