幀緩衝庫

幀緩衝驅動程式在很大程度上依賴於四個資料結構。這些結構在 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。