歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Fedora下 DirectFB 開發手記

Fedora下 DirectFB 開發手記

日期:2017/3/1 11:17:46   编辑:Linux編程

系統環境:

虛擬機 Fedora live 13

1、ls /dev/fb* 查看 默認啟動方式 沒有創建 /dev/fb0 設備文件

2、查找資料後,添加fb0 設備:

修改 /boot/grub/menu.lst

在 kernel 啟動參數 最後增加 vga=788

說明:

fedora 13 中沒有 lilo ,所以內核啟動參數 需要修改 grub 中的配置

vga 小寫

788 的含義(網上搜 linux vga 參數)為 800*600 16位真彩色

# Normal VGA console
# vga = normal
# VESA framebuffer console @ 1024x768x64k
# vga=791
# VESA framebuffer console @ 1024x768x32k
# vga=790
# VESA framebuffer console @ 1024x768x256
# vga=773
# VESA framebuffer console @ 800x600x64k
# vga=788
# VESA framebuffer console @ 800x600x32k
# vga=787
# VESA framebuffer console @ 800x600x256
# vga=771
# VESA framebuffer console @ 640x480x64k
# vga=785
# VESA framebuffer console @ 640x480x32k
# vga=784
# VESA framebuffer console @ 640x480x256
# vga=769

3、控制台和圖形界面的切換方法:

ctrl+alt+f1 進入圖形界面

ctrl_alt+f2 進入tty2 控制台

4、切換進入圖形界面

打開控制台

cat /dev/fb0 > /root/screensnap

ls -l /root/screensnap

發現 發現文件大小為 1920000 (???為什麼?)

如果按照 800*600*16位真彩色算 應該是 800*600*2 = 96000

不管了,反正在圖形模式下也有了 fb0 這個設備文件了

想辦法打開這個位圖文件看看結果吧

經過驗證 ctrl+alt+f2 進入到控制台界面 cat /dev/fb0 > /root/aaa 同樣生成的是 1920000

這個跟vga參數設置為 788 不相符??

5、編寫基礎測試程序
參考 http://www.linuxidc.com/Linux/2011-09/43799p2.htm

  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <fcntl.h>
  4. #include <linux/fb.h>
  5. #include <sys/mman.h>
  6. int main () {
  7. int fp=0;
  8. struct fb_var_screeninfo vinfo;
  9. struct fb_fix_screeninfo finfo;
  10. fp = open ("/dev/fb0",O_RDWR);
  11. if (fp < 0){
  12. printf("Error : Can not open framebuffer device/n");
  13. exit(1);
  14. }
  15. if (ioctl(fp,FBIOGET_FSCREENINFO,&finfo)){
  16. printf("Error reading fixed information/n");
  17. exit(2);
  18. }
  19. if (ioctl(fp,FBIOGET_VSCREENINFO,&vinfo)){
  20. printf("Error reading variable information/n");
  21. exit(3);
  22. }
  23. printf("The mem is :%d/n",finfo.smem_len);
  24. printf("The line_length is :%d/n",finfo.line_length);
  25. printf("The xres is :%d/n",vinfo.xres);
  26. printf("The yres is :%d/n",vinfo.yres);
  27. printf("bits_per_pixel is :%d/n",vinfo.bits_per_pixel);
  28. close (fp);
  29. }

執行結果如下:

[root@fedora-xbmc share]# cd fb
[root@fedora-xbmc fb]# ls
test1.c
[root@fedora-xbmc fb]# gcc test1.c -o test1
test1.c: 在函數‘main’中:
test1.c:15: 警告:隱式聲明與內建函數‘exit’不兼容
test1.c:20: 警告:隱式聲明與內建函數‘exit’不兼容
test1.c:25: 警告:隱式聲明與內建函數‘exit’不兼容
[root@fedora-xbmc fb]# ./test1
The mem is :1920000
The line_length is :1600
The xres is :800
The yres is :600
bits_per_pixel is :16
[root@fedora-xbmc fb]#

基本完成fb0 的配置,為後續開發及驗證做好准備,可惜的是 對 cat 的結果還沒搞太懂

最後:

參考http://www.linuxidc.com/Linux/2011-09/43799p2.htm ,基本可以得出 之所以 cat 的結果是整屏的2倍 是因為:

這是因為在現代的圖形系統中大多有緩沖技術,顯存中存有兩頁屏幕數據,這是方便快速的改變屏幕內容實現動畫之類比較高的要求

哪位兄台知道 vga 參數 是否可以被設置為 32 位真彩色?(偶需必須用到透明位) 參數值應該是怎樣的?

Copyright © Linux教程網 All Rights Reserved