Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Framebuffer

Introduction to Framebuffer

台灣樹莓派

July 10, 2016
Tweet

More Decks by 台灣樹莓派

Other Decks in Technology

Transcript

  1. 姓名標示 — 非商業性 — 相同方式分享 CC (Creative Commons) 姓名標示 —

    你必須給予 適當表彰、提供指向本授權 條款的連結,以及 指出(本作品的原始版本)是否已 被變更。你可以任何合理方式為前述表彰,但不得以 任何方式暗示授權人為你或你的使用方式背書。 非商業性 — 你不得將本素材進行商業目的之使 用。 相同方式分享 — 若你重混、轉換本素材,或依本 素材建立新素材,你必須依本素材的授權條款來 散布你的貢獻物。
  2. • The frame buffer device provides an abstraction for the

    graphics hardware. • It represents the frame buffer of some video hardware and allows application software to access the graphics hardware through a well-defined interface. 什麼是 Fraembuffer ? https://www.kernel.org/doc/Documentation/fb/framebuffer.txt
  3. • The frame buffer device provides an abstraction for the

    graphics hardware. • It represents the frame buffer of some video hardware and allows application software to access the graphics hardware through a well-defined interface. 一塊記憶體 , 目的是抽象化顯示卡的硬體 什麼是 Fraembuffer ? https://www.kernel.org/doc/Documentation/fb/framebuffer.txt
  4. • 掛在 /dev 的裝置檔 , 預設 X server 會使用 /dev/fb0

    • 截圖: $ cp /dev/fb0 fb.raw • 還原: $ sudo cp fb.raw /dev/fb0 • 將 raw 轉成 PNG 格式 • 預設 320x240, 影像深度 16-bit • $ sudo apt-get install libnetpbm10 • $ perl iraw2png < screen.raw > screen.png 螢幕截圖與還原 https://blackfin.uclinux.org/doku.php?id=uclinux-dist:framebuffer
  5. • fbi - Linux framebuffer imageviewer • 步驟 • $

    sudo apt-get install fbi • 建立一個 sysvinit 服務 , 包含以下指令 • /usr/bin/fbi -T 1 -noverbose -a /etc/splash.png • 設定開機就啟動 顯示開機畫面 http://www.raspberry-projects.com/pi/pi-operating-systems/raspbian/custom-boot-up-screen
  6. #include <linux/fb.h> int main(int argc, char* argv[]) { int fbfd

    = 0; struct fb_var_screeninfo var_info; fbfd = open("/dev/fb0", O_RDWR); ioctl(fbfd, FBIOGET_VSCREENINFO, &var_info); printf("%dx%d, %d bpp\n", var_info.xres, var_info.yres, var_info.bits_per_pixel); close(fbfd); return 0; } https://github.com/rst-/raspberry-compote
  7. • 將檔案映射到虛擬記憶體 • void *mmap( void *addr, size_t len, int

    prot, int flag, int filedes, off_t off); mmap http://docs.linuxtone.org/ebooks/C&CPP/c/ch28s08.html
  8. #include <linux/fb.h> int main(int argc, char* argv[]) { int fbfd

    = 0; • struct fb_fix_screeninfo finfo; • long int screensize = 0; • char *fbp = 0; • fbfd = open("/dev/fb0", O_RDWR); • ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo); • screensize = finfo.smem_len; • fbp = (char*)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0); • memset(fbp, 0xff, screensize/2); • memset(fbp + screensize/2, 0x18, screensize/2); • • munmap(fbp, screensize); • close(fbfd); • return 0; } https://github.com/rst-/raspberry-compote
  9. 24