程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> DirectFB編程,directfb

DirectFB編程,directfb

編輯:關於C語言

DirectFB編程,directfb


一、簡介

DirectFB是一個輕量級的提供硬件圖形加速,輸入設備處理和抽象的圖形庫,它集成了支持半透明的視窗系統以及在LinuxFramebuffer驅動之上的多層顯示。它是一個用軟件封裝當前硬件無法支持的圖形算法來完成硬件加速的層。DirectFB是為嵌入式系統而設計。它是以最小的資源開銷來實現最高的硬件加速性能。

 

DirectFB中的重要術語

1、Blitting
Blitting是在拷貝圖像數據的進程中所引用。舉一個最簡單的例子就是當兩個Surface有相同的大,顏色深度和像素格式時Blitting其中一個Surface到另一個Surface。在這個過程中內存只被復制而沒有被處理(就像復制其他任何類型的數據一樣)。alpha通道的傳輸,或者從一種像素格式到另一種像素格式的傳輸。許多圖形顯卡包含了一個硬件Blitting來完成多種格式的傳輸。

2、Surface
Surface是內存中一個圖像以一種具體的像素格式被保存的一塊保留區域。一個Surface可以位於視頻和/或系統內存中。可以在一個Surface上進行畫圖操作或者把一個Surface Blitting到另一個。(見1.21節)
在全屏模式下時,屏幕中的可視區表示為”主Surface”,所以可以直接在屏幕的可視區完成圖形操作。
每個Surface都可以選擇雙緩沖,圖形操作將首先在輔助緩沖區中執行然後在Flip()被調用之後變得合法。在許多情況下建議在主Surface中使用雙緩沖來防止閃爍。

3、SubSurface
SubSurface使用和正規Surface相同的接口。它代表父類Surface的一個部分並且沒有為自己分配任何系統或視頻存儲空間。

4、Layer
依靠於圖形硬件可以有一個或者多個顯示層。一個標准的PC顯卡只有一個層,但是,就像機頂盒就可能支持2個或更多的層。不同的層在顯存中占據著不同的區域,通常通過alpha混合來組合,這由顯示硬件自動完成。如果最底層的內容發生了改變將不會被重繪,上一層的內容保持不變。今天,許多PC顯卡也支持額外的可以縮放可以從YUV轉為RGB的層(視頻層)。這個層不能進行顏色混合和設置成保持完全的不透明。variosDirectFB圖形驅動支持視頻層。

5、Window / Windowstack
通常一個層的surface的內容受控於集成的窗體系統,這意味著屬於這個層的窗體在一個可配置的背景上。每個窗體有它自己的一個surface,這個surface 被窗體系統用來生成構成重疊窗體的圖像。

 

二、編譯與安裝

1、資源下載

需下載如下資源

DirectFB:DirectFB-1.6.1.tar.gz,
Fusion:   linux-fusion-8.10.2.tar.gz 
Example:  DirectFB-examples-1.6.0.tar.gz

DirectFB 提供3種形式的下載方式: git, cvs 和壓縮包。

地址:http://directfb.org/
或  :git clone git://git.directfb.org/git/directfb/core/DirectFB.git
     git clone git://git.directfb.org/git/directfb/core/linux-fusion.git

 

2、編譯和安裝Fusion

# tar zxf linux-fusion-8.10.2.tar.gz
# cd linux-fusion-8.10.2
# make
# make install

注意:

1) Run 'make' and 'make install'. It builds and installs the module
   for the running kernel version as reported by 'uname -r'.
   If you want to build for another kernel, edit the Makefile.

2) Either run 'modprobe fusion' manually or add "fusion" to "/etc/modules".

3) Create the fusion device(s) if not using devfs or udev:

        mkdir /dev/fusion
        mknod /dev/fusion/0 c 250 0

        ...if you need more than one session

        mknod /dev/fusion/1 c 250 1
        mknod /dev/fusion/2 c 250 2

        ...and so on (currently limited to eight sessions)

4) Add udev rules to /etc/udev/rules.d/40-fusion.rules if using udev:

        KERNEL=="fusion[0-9]*", NAME="fusion/%n", GROUP="video", MODE="0660"

        ...customize to suit your needs

 

3、編譯和安裝DirectFB

# tar zxf DirectFB-1.6.1.tar.gz
# cd DirectFB-1.6.1
# ./configure --enable-x11 --enable-multi --enable-debug --enable-trace
# make
# make install

 

注意:為使pkg-config能夠找到DirectFB,需要添加尋索路徑:/usr/local/lib/,有兩種方式

 

方式1:

首先執行:vi /etc/ld.so.conf.d/qt-i386.conf ,並添加如下內容

/usr/local/lib/

然後執行:

ldconfig

 

方式2:

首先執行:

cd DirectFB-1.6.1
find . -name "*.pc"

然後將搜索出的“*.pc”文件copy至目錄/usr/lib/pkgconfig,執行:

 

4、編譯和安裝Example

# tar -zxvf DirectFB-examples-1.6.0.tar.gz
# cd DirectFB-examples-1.6.0
# ./configure --enable-debug
# make
# make install

 

三、運行示例

# depmod -a
# modprobe fusion # 安裝 fusion 內核模塊
# cd /usr/local/bin
# ./df_window

報錯如下:

~~~~~~~~~~~~~~~~~~~~~~~~~~| DirectFB 1.6.1 |~~~~~~~~~~~~~~~~~~~~~~~~~~
        (c) 2001-2012  The world wide DirectFB Open Source Community
        (c) 2000-2004  Convergence (integrated media) GmbH
      ----------------------------------------------------------------

(*) DirectFB/Core: Multi Application Core. (2015-03-22 11:51) [ DEBUG ][ TRACE ]
(*) Fusion/SHM: Using MADV_REMOVE (2.6.32.0 >= 2.6.19.2)
(*) Direct/Thread: Started 'Fusion Dispatch' (-1) [MESSAGING OTHER/OTHER 0/0] <10485760>...
(*) Direct/Thread: Started 'Fusion Deferred' (-1) [MESSAGING OTHER/OTHER 0/0] <10485760>...
(!) Direct/Util: Opening '/dev/fb0' failed!
    --> The requested operation or an argument is (currently) not supported
(-) [ 3047: -STACK- ]
  #0  0x00e431c3 in direct_try_open () from /usr/local/lib/libdirect-1.6.so.0 [0xe19000]
  #1  0x0044aa61 in dfb_fbdev_open () from /usr/local/lib/directfb-1.6-0/systems/libdirectfb_fbdev.so [0x447000]
  #2  0x0044b2e7 in system_initialize () from /usr/local/lib/directfb-1.6-0/systems/libdirectfb_fbdev.so [0x447000]
  #3  0x007a6178 in dfb_system_core_initialize () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #4  0x00737d5c in dfb_core_part_initialize () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #5  0x00734987 in dfb_core_initialize () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #6  0x006f41aa in DirectFB::ICore_Real::Initialize() () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #7  0x006f106e in CoreDFB_Initialize () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #8  0x007351ea in dfb_core_arena_initialize () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #9  0x0072e303 in dfb_core_create () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #10 0x006efb00 in DirectFBCreate () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]

(!) DirectFB/FBDev: Error opening framebuffer device!
(-) [ 3047: -STACK- ]
  #0  0x0044aa61 in dfb_fbdev_open () from /usr/local/lib/directfb-1.6-0/systems/libdirectfb_fbdev.so [0x447000]
  #1  0x0044b2e7 in system_initialize () from /usr/local/lib/directfb-1.6-0/systems/libdirectfb_fbdev.so [0x447000]
  #2  0x007a6178 in dfb_system_core_initialize () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #3  0x00737d5c in dfb_core_part_initialize () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #4  0x00734987 in dfb_core_initialize () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #5  0x006f41aa in DirectFB::ICore_Real::Initialize() () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #6  0x006f106e in CoreDFB_Initialize () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #7  0x007351ea in dfb_core_arena_initialize () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #8  0x0072e303 in dfb_core_create () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #9  0x006efb00 in DirectFBCreate () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]

(!) DirectFB/FBDev: Use 'fbdev' option or set FRAMEBUFFER environment variable.
(-) [ 3047: -STACK- ]
  #0  0x0044aa61 in dfb_fbdev_open () from /usr/local/lib/directfb-1.6-0/systems/libdirectfb_fbdev.so [0x447000]
  #1  0x0044b2e7 in system_initialize () from /usr/local/lib/directfb-1.6-0/systems/libdirectfb_fbdev.so [0x447000]
  #2  0x007a6178 in dfb_system_core_initialize () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #3  0x00737d5c in dfb_core_part_initialize () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #4  0x00734987 in dfb_core_initialize () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #5  0x006f41aa in DirectFB::ICore_Real::Initialize() () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #6  0x006f106e in CoreDFB_Initialize () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #7  0x007351ea in dfb_core_arena_initialize () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #8  0x0072e303 in dfb_core_create () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #9  0x006efb00 in DirectFBCreate () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]

(!) DirectFB/Core: Could not initialize 'system_core' core!
    --> A general initialization error occured
(-) [ 3047: -STACK- ]
  #0  0x00737d5c in dfb_core_part_initialize () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #1  0x00734987 in dfb_core_initialize () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #2  0x006f41aa in DirectFB::ICore_Real::Initialize() () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #3  0x006f106e in CoreDFB_Initialize () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #4  0x007351ea in dfb_core_arena_initialize () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #5  0x0072e303 in dfb_core_create () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]
  #6  0x006efb00 in DirectFBCreate () from /usr/local/lib/libdirectfb-1.6.so.0 [0x6bd000]

df_window.c <136>:
    (#) DirectFBError [DirectFBCreate( &dfb )]: A general initialization error occured

解決方法:

執行:vi /etc/grub.conf

修改
kernel /vmlinuz-2.6.15-1.2054_FC5 ro root=LABEL=/ rhgb quiet

為:
kernel /vmlinuz-2.6.15-1.2054_FC5 ro root=LABEL=/ rhgb quiet vga= 788

再次運行:

# ./df_window

效果如下

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved