linux framebuffer 例子

http://blog.csdn.net/fyzhao/archive/2008/12/11/3499805.aspx

 

昨天做的一个极简单的framebuffer的例子,用来学习怎样操作fb设备。

  这段代码是在picogl的vesafb backend部分的基础上简出来的,所以变量名还保留着。

流程如下:

1 打开framebuffer设备;

2 通过ioctl取得fixed screen information;

3 通过ioctl取得variable screen information;

4 通过mmap映射设备内存到进程空间;

5 写framebuffer;

6 终止。

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <fcntl.h>
  5. #include <linux/fb.h>
  6. #include <sys/mman.h>
  7. struct fb_fix_screeninfo FixedInfo;
  8. struct fb_var_screeninfo OrigVarInfo;
  9. static int FrameBufferFD = -1;
  10. void *FrameBuffer = (void *) -1;
  11. void openFBDEV(void) {
  12.     /* open the framebuffer device */
  13.     FrameBufferFD = open("/dev/fb0", O_RDWR);
  14.     if (FrameBufferFD < 0) {
  15.         fprintf(stderr, "Error opening /dev/fb0/n");
  16.         exit(1);
  17.     }
  18.     /* Get the fixed screen info */
  19.     if (ioctl(FrameBufferFD, FBIOGET_FSCREENINFO, &FixedInfo)) {
  20.         fprintf(stderr, "error: ioctl(FBIOGET_FSCREENINFO) failed/n");
  21.         exit(1);
  22.     }
  23.     /* get the variable screen info */
  24.     if (ioctl(FrameBufferFD, FBIOGET_VSCREENINFO, &OrigVarInfo)) {
  25.         fprintf(stderr, "error: ioctl(FBIOGET_VSCREENINFO) failed/n");
  26.         exit(1);
  27.     }
  28.        
  29.     if (FixedInfo.visual != FB_VISUAL_TRUECOLOR && FixedInfo.visual != FB_VISUAL_DIRECTCOLOR) {
  30.         fprintf(stderr, "non-TRUE/DIRECT-COLOR visuals (0x%x) not supported by this demo./n", FixedInfo.visual);
  31.         exit(1);
  32.     }
  33.     /*
  34.      * fbdev says the frame buffer is at offset zero, and the mmio region
  35.      * is immediately after.
  36.      */
  37.     /* mmap the framebuffer into our address space */
  38.     FrameBuffer = (void *) mmap(0, /* start */
  39.         FixedInfo.smem_len, /* bytes */
  40.         PROT_READ | PROT_WRITE, /* prot */
  41.         MAP_SHARED, /* flags */
  42.         FrameBufferFD, /* fd */
  43.         0 /* offset */);
  44.     if (FrameBuffer == (void *) - 1) {
  45.         fprintf(stderr, "error: unable to mmap framebuffer/n");
  46.         exit(1);
  47.     }
  48. }
  49. void closeFBDEV(void) {
  50.     munmap(FrameBuffer, FixedInfo.smem_len);
  51.     close(FrameBufferFD);
  52. }
  53. int main() {
  54.     openFBDEV();
  55.     fprintf(stderr, "openFBDEV finish/n");
  56.     memset(FrameBuffer, 128, FixedInfo.smem_len);
  57.     sleep(5);
  58.     closeFBDEV();
  59.     fprintf(stderr, "closeFBDEV finish/n");
  60.     return 0;
  61. }
  62. 补充一点,比如直接写屏操作:
  63. u_int * screen_memory = (u_int*)mmap(0,
                                            buffer_size,//fixinfo.smem_len,
                                          PROT_READ | PROT_WRITE,
                                          MAP_SHARED,
                                          fbdev,
                                          0);
  64. for(i=0;i<buffer_size/4;i++)    //buffer_size以字节为单位
            *(screen_memory+i) = 0xff;    //red
        sleep(2);
        for(i=0;i<buffer_size/4;i++)
            *(screen_memory+i) = 0xff00;//green
        sleep(2);
        for(i=0;i<buffer_size/4;i++)
            *(screen_memory+i) = 0xff0000;//blue
        sleep(2);

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Qt is a popular cross-platform framework for developing graphical user interfaces (GUI) and applications. It provides support for Linux framebuffer, which allows you to create GUI applications that can run directly on the Linux framebuffer without the need for an X server. To use Qt with Linux framebuffer, you can follow these general steps: 1. Install the required dependencies: Make sure you have the necessary libraries and development packages installed on your Linux system. This may include framebuffer-related libraries like `libdrm` and `libgbm`. 2. Configure Qt with framebuffer support: When building Qt from source, you can enable framebuffer support by passing the `-qt-libinput` flag to the `configure` script. For example: ``` ./configure -qt-libinput ``` 3. Build your Qt application: Once Qt is configured with framebuffer support, you can build your application using the `qmake` and `make` commands as usual. Make sure to set the appropriate target platform, such as `linuxfb`. 4. Run your Qt application on the Linux framebuffer: After building your application, you can run it directly on the Linux framebuffer by setting the appropriate environment variables. For example: ``` export QT_QPA_PLATFORM=linuxfb export QT_QPA_FB_TTY=/dev/fb0 ./your_application ``` By following these steps, you should be able to develop and run Qt applications using the Linux framebuffer as the target platform. Keep in mind that framebuffer support may vary depending on your specific Linux distribution and hardware setup.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值