annotate old/simple_pack/fb.cpp @ 656:66810c71442b draft

branch merge
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 27 Nov 2009 18:27:32 +0900
parents 3bc98f6d31ff
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
91
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
1 /*
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
2 * fbtst.c
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
3 * 2006.7.19 Kensuke Ooyu
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
4 */
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
5 #include <unistd.h>
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
6 #include <stdio.h>
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
7 #include <fcntl.h>
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
8 #include <linux/fb.h>
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
9 #include <linux/fs.h>
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
10 #include <sys/mman.h>
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
11 #include <sys/ioctl.h>
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
12 #include <stdlib.h>
78
3c6dec161ade *** empty log message ***
chiaki
parents:
diff changeset
13 #include <iostream>
3c6dec161ade *** empty log message ***
chiaki
parents:
diff changeset
14 using namespace std;
3c6dec161ade *** empty log message ***
chiaki
parents:
diff changeset
15
91
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
16 #define DEVICE_NAME "/dev/fb0"
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
17 #define DIV_BYTE 8
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
18
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
19 #define X_PIXEL_MAX 320
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
20 #define Y_LINE_MAX 240
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
21
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
22 #define BORDER1 80
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
23 #define BORDER2 160
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
24
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
25 #define COLOR_RED 0xf800
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
26 #define COLOR_GREEN 0x07e0
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
27 #define COLOR_BLUE 0x001f
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
28 #define COLOR_WHITE 0xffff
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
29 #define COLOR_BLACK 0x0000
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
30 #define COLOR_YELLOW 0xffe0
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
31
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
32 /* function prototype */
180
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
33 void send_current_error_msg(const char *ptr);
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
34 void send_current_information(const char *ptr);
91
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
35
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
36 int get_fbdev_addr(void)
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
37 {
180
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
38 int fd_framebuffer ;
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
39 struct fb_var_screeninfo vinfo;
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
40 struct fb_fix_screeninfo finfo;
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
41 long int screensize ;
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
42 long int location;
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
43 char *fbptr ;
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
44 char tmp[DIV_BYTE*10];
91
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
45
180
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
46 int x , y ;
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
47 int xres,yres,vbpp,line_len;
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
48 unsigned short tcolor ;
78
3c6dec161ade *** empty log message ***
chiaki
parents:
diff changeset
49
180
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
50 /* 読み書き用にファイルを開く */
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
51 fd_framebuffer = open( DEVICE_NAME , O_RDWR);
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
52 if ( !fd_framebuffer ) {
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
53 send_current_error_msg("Framebuffer device open error !");
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
54 exit(1);
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
55 }
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
56 send_current_information("The framebuffer device was opened !");
91
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
57
180
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
58 /* 固定スクリーン情報取得 */
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
59 if ( ioctl( fd_framebuffer , FBIOGET_FSCREENINFO , &finfo ) ) {
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
60 send_current_error_msg("Fixed information not gotton !");
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
61 exit(2);
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
62 }
78
3c6dec161ade *** empty log message ***
chiaki
parents:
diff changeset
63
180
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
64 /* 変動スクリーン情報取得 */
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
65 if ( ioctl( fd_framebuffer , FBIOGET_VSCREENINFO , &vinfo ) ) {
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
66 send_current_error_msg("Variable information not gotton !");
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
67 exit(3);
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
68 }
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
69 xres = vinfo.xres ;
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
70 yres = vinfo.yres ;
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
71 vbpp = vinfo.bits_per_pixel ;
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
72 line_len = finfo.line_length ;
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
73 sprintf( tmp , "%d(pixel)x%d(line), %dbpp(bits per pixel)",xres,yres,vbpp);
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
74 send_current_information( tmp );
91
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
75
180
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
76 /* バイト単位でのスクリーンのサイズを計算 */
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
77 screensize = xres * yres * vbpp / DIV_BYTE ;
91
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
78
180
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
79 /* デバイスをメモリにマップする */
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
80 fbptr = (char *)mmap(0,screensize,PROT_READ | PROT_WRITE,MAP_SHARED,fd_framebuffer,0);
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
81 if ( (int)fbptr == -1 ) {
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
82 send_current_error_msg("Don't get framebuffer device to memory !");
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
83 exit(4);
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
84 }
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
85 send_current_information("The framebuffer device was mapped !");
91
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
86
180
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
87 printf("fb: %x \n",fbptr);
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
88 return (int)fbptr;
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
89 //munmap(fbptr,screensize);
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
90 //close(fd_framebuffer);
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
91 //return 0;
78
3c6dec161ade *** empty log message ***
chiaki
parents:
diff changeset
92 }
3c6dec161ade *** empty log message ***
chiaki
parents:
diff changeset
93
180
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
94 void send_current_error_msg(const char *ptr)
91
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
95 {
180
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
96 fprintf( stderr , "%s\n" , ptr );
91
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
97 }
78
3c6dec161ade *** empty log message ***
chiaki
parents:
diff changeset
98
180
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
99 void send_current_information(const char *ptr)
91
4d6bd3c0d90b *** empty log message ***
akira
parents: 78
diff changeset
100 {
180
e3b7776b1420 いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents: 91
diff changeset
101 fprintf( stdout , "%s\n" , ptr );
78
3c6dec161ade *** empty log message ***
chiaki
parents:
diff changeset
102 }