2011-01-18 2 views
9

RHEL 6.0 OS에서 실행되는 내장 그래픽 가속기 GMA-HD가있는 i5 코어를 사용하고 있습니다. 필자는 그래픽 드라이버의 그래픽 가속 기능을 테스트해야했습니다 (필자의 PC에서는 i915라는 사실을 알게되었습니다). 프레임 버퍼에 쓰기 위해 다음 코드를 사용했습니다.프레임 버퍼에 쓰기

#include <unistd.h> 
#include <stdio.h> 
#include <fcntl.h> 
#include <linux/fb.h> 
#include <sys/mman.h> 

int main() 
{ 
     int fbfd = 0; 
     struct fb_var_screeninfo vinfo; 
     struct fb_fix_screeninfo finfo; 
     long int screensize = 0; 
     char *fbp = 0; 
     int x = 0, y = 0; 
     long int location = 0; 
     int count ; 

     /* Open the file for reading and writing */ 
     fbfd = open("/dev/fb0", O_RDWR); 
     if (!fbfd) { 
       printf("Error: cannot open framebuffer device.\n"); 
       exit(1); 
     } 
     printf("The framebuffer device was opened successfully.\n"); 
    /* Get fixed screen information */ 
     if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) { 
       printf("Error reading fixed information.\n"); 
       exit(2); 
     } 

     /* Get variable screen information */ 
     if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) { 
       printf("Error reading variable information.\n"); 
       exit(3); 
     } 

     /* Figure out the size of the screen in bytes */ 
     screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel/8; 
     printf("\nScreen size is %d",screensize); 
     printf("\nVinfo.bpp = %d",vinfo.bits_per_pixel); 

     /* Map the device to memory */ 
     fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED,fbfd, 0); 
     if ((int)fbp == -1) { 
       printf("Error: failed to map framebuffer device to memory.\n"); 
       exit(4); 
     } 
     printf("The framebuffer device was mapped to memory successfully.\n"); 


     x = 100; y = 100; /* Where we are going to put the pixel */ 

     /* Figure out where in memory to put the pixel */ 
     location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) + (y+vinfo.yoffset) * finfo.line_length; 
     for(count = 1 ;count < 100 ;count++) 
     { 
       *(fbp + location) = 255; /* Some blue */ 
       *(fbp + location + count) = 0; /* A little green */ 
       *(fbp + location + count + 1) = 0; /* A lot of red */ 
       *(fbp + location + count + 2) = 0; /* No transparency */ 
     } 
     munmap(fbp, screensize); 
     close(fbfd); 
     return 0; 
} 

는 변화가 표시하지만, '고양이는/dev/FB0'에서 발견 된 위의 코드를 실행 한 후 일부 데이터를 보여 주었다. 화면에 아무 것도 보이지 않는 이유를 설명 할 수 있습니까? 는

Neeraj N.T에게 사전에

감사

+0

화면이 한 번 깜박습니까? (어둠 속에서 촬영하십시오) – drahnr

+0

나는 야생의 추측을하고, 255/65535 적색 강도의 픽셀을 썼다고 말 할 것입니다. 그 Vinfo.bpp printf의 결과는 무엇입니까? – ninjalj

답변

9
당신은 위치를 증가하지 않는

를 (또한 FB0는 프레임 버퍼 'inteldrmfb'.에 대응 발견)! 그래서 255 만 1 픽셀에, 그리고 모든 다른 사람이 대신 0으로 시도됩니다

 location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) + (y+vinfo.yoffset) * finfo.line_length; 
     for(count = 1 ;count < 100 ;count++) 
     { 
       *(fbp + location) = 255; /* Some blue */ 
       *(fbp + location + 1) = 0; /* A little green */ 
       *(fbp + location + 2) = 0; /* A lot of red */ 
       *(fbp + location + 3) = 0; /* No transparency */ 
       location += 4; 
     } 

그러나, 테스트를 위해 옳은 일이 될 수 있습니다 그것은 일부 프레임 버퍼 성능 테스트와 을 제공 directfb을 사용하는 것입니다

+1

왜 -1일까요? 추악한 실수를 저질렀습니까? – shodanex

+2

필자는 aplha 요소 (4 바이트)에 약간의 불투명도를 추가해야했습니다. 또한 위치를 증가시켜야했습니다. '/ dev/fb0'의 출력물은 'fbdump'를 사용하여 캡처 한 결과입니다 (fbdump -fb/dev/fb0> image.ppm). 내 screnn에서 framebufer 출력을 보려면 FBIO_PAN_DISPLAY ioctl 호출을 호출해야했습니다. – NRJ

+2

directfb에 대한 올바른 링크가 이제 http://directfb.net/이라고 생각합니다. 대답의 링크가 현재 다른 사이트로 리디렉션됩니다. –

관련 문제