annotate Renderer/test_render/fb.h @ 503:516d5c91d5b4 draft double-linked-task-list

comment
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 11 Oct 2009 19:35:33 +0900
parents 768452fab95e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
283
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
1 #if defined(__linux__)
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
2 #include <unistd.h>
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
3 #include <stdio.h>
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
4 #include <fcntl.h>
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
5 #include <linux/fb.h>
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
6 #include <linux/fs.h>
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
7 #include <sys/mman.h>
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
8 #include <sys/ioctl.h>
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
9 #include <stdlib.h>
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
10 #include <iostream>
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
11 using namespace std;
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
12
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
13 #define DEVICE_NAME "/dev/fb0"
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
14 #define DIV_BYTE 8
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
15
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
16 /* function prototype */
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
17 void send_current_error_msg(const char *ptr);
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
18 void send_current_information(const char *ptr);
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
19
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
20 int get_fbdev_addr(void)
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
21 {
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
22 int fd_framebuffer ;
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
23 struct fb_var_screeninfo vinfo;
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
24 struct fb_fix_screeninfo finfo;
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
25 long int screensize ;
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
26 //long int location;
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
27 char *fbptr ;
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
28 char tmp[DIV_BYTE*10];
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
29
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
30 //int x , y ;
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
31 int xres,yres,vbpp,line_len;
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
32 //unsigned short tcolor ;
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
33
298
768452fab95e from EUC to UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 283
diff changeset
34 /* 読み書き用にファイルを開く */
283
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
35 fd_framebuffer = open( DEVICE_NAME , O_RDWR);
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
36 if ( !fd_framebuffer ) {
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
37 send_current_error_msg("Framebuffer device open error !");
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
38 exit(1);
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
39 }
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
40 send_current_information("The framebuffer device was opened !");
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
41
298
768452fab95e from EUC to UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 283
diff changeset
42 /* 固定スクリーン情報取得 */
283
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
43 if ( ioctl( fd_framebuffer , FBIOGET_FSCREENINFO , &finfo ) ) {
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
44 send_current_error_msg("Fixed information not gotton !");
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
45 exit(2);
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
46 }
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
47
298
768452fab95e from EUC to UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 283
diff changeset
48 /* 変動スクリーン情報取得 */
283
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
49 if ( ioctl( fd_framebuffer , FBIOGET_VSCREENINFO , &vinfo ) ) {
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
50 send_current_error_msg("Variable information not gotton !");
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
51 exit(3);
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
52 }
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
53 xres = vinfo.xres ;
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
54 yres = vinfo.yres ;
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
55 vbpp = vinfo.bits_per_pixel ;
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
56 line_len = finfo.line_length ;
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
57 sprintf( tmp , "%d(pixel)x%d(line), %dbpp(bits per pixel)",xres,yres,vbpp);
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
58 send_current_information( tmp );
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
59
298
768452fab95e from EUC to UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 283
diff changeset
60 /* バイト単位でのスクリーンのサイズを計算 */
283
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
61 screensize = xres * yres * vbpp / DIV_BYTE ;
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
62
298
768452fab95e from EUC to UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 283
diff changeset
63 /* デバイスをメモリにマップする */
283
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
64 fbptr = (char *)mmap(0,screensize,PROT_READ | PROT_WRITE,MAP_SHARED,fd_framebuffer,0);
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
65 if ( (int)fbptr == -1 ) {
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
66 send_current_error_msg("Don't get framebuffer device to memory !");
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
67 exit(4);
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
68 }
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
69 send_current_information("The framebuffer device was mapped !");
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
70
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
71 printf("fb: 0x%x \n", (unsigned int)fbptr);
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
72 return (int)fbptr;
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
73 //munmap(fbptr,screensize);
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
74 //close(fd_framebuffer);
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
75 //return 0;
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
76 }
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
77
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
78 void send_current_error_msg(const char *ptr)
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
79 {
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
80 fprintf( stderr , "%s\n" , ptr );
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
81 }
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
82
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
83 void send_current_information(const char *ptr)
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
84 {
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
85 fprintf( stdout , "%s\n" , ptr );
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
86 }
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
87 #else /* !defined(__linux__) */
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
88 int get_fbdev_addr(void) {return 0;}
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
89 #endif /* defined(__linux__) */
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
90
15bfacccde99 fix test_render
e065746@localhost.localdomain
parents:
diff changeset
91 extern int get_fbdev_addr(void);