Debian Codegraph @

drivers/mga_vid_test.c

raw
1 /*
2 *
3 * mga_vid_test.c
4 *
5 * Aaron Holtzman <[email protected]>
6 * Sept 1999
7 *
8 * This software has been released under the terms of the GNU Public
9 * license. See http://www.gnu.org/copyleft/gpl.html for details.
10 */
11
12 //#include <stddef.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <sys/ioctl.h>
16 #include <unistd.h>
17 #include <fcntl.h>
18 #include <sys/mman.h>
19 #include "mga_vid.h"
20
21 mga_vid_config_t config;
22 uint8_t *mga_vid_base;
23 uint32_t is_g400;
24
25 #define SRC_IMAGE_WIDTH 256
26 #define SRC_IMAGE_HEIGHT 256
27
28 uint8_t y_image[SRC_IMAGE_WIDTH * SRC_IMAGE_HEIGHT];
29 uint8_t cr_image[SRC_IMAGE_WIDTH * SRC_IMAGE_HEIGHT];
30 uint8_t cb_image[SRC_IMAGE_WIDTH * SRC_IMAGE_HEIGHT];
31
32
33 void
34 write_frame_g200(uint8_t *y,uint8_t *cr, uint8_t *cb)
35 {
36 uint8_t *dest;
37 uint32_t bespitch,h,w;
38
39 dest = mga_vid_base;
40 bespitch = (config.src_width + 31) & ~31;
41
42 for(h=0; h < config.src_height; h++)
43 {
44 memcpy(dest, y, config.src_width);
45 y += config.src_width;
46 dest += bespitch;
47 }
48
49 for(h=0; h < config.src_height/2; h++)
50 {
51 for(w=0; w < config.src_width/2; w++)
52 {
53 *dest++ = *cb++;
54 *dest++ = *cr++;
55 }
56 dest += bespitch - config.src_width;
57 }
58 }
59
60 void
61 write_frame_g400(uint8_t *y,uint8_t *cr, uint8_t *cb)
62 {
63 uint8_t *dest;
64 uint32_t bespitch,h;
65
66 dest = mga_vid_base;
67 bespitch = (config.src_width + 31) & ~31;
68
69 for(h=0; h < config.src_height; h++)
70 {
71 memcpy(dest, y, config.src_width);
72 y += config.src_width;
73 dest += bespitch;
74 }
75
76 for(h=0; h < config.src_height/2; h++)
77 {
78 memcpy(dest, cb, config.src_width/2);
79 cb += config.src_width/2;
80 dest += bespitch/2;
81 }
82
83 for(h=0; h < config.src_height/2; h++)
84 {
85 memcpy(dest, cr, config.src_width/2);
86 cr += config.src_width/2;
87 dest += bespitch/2;
88 }
89 }
90
91 void write_frame(uint8_t *y,uint8_t *cr, uint8_t *cb)
92 {
93 if(is_g400)
94 write_frame_g400(y,cr,cb);
95 else
96 write_frame_g200(y,cr,cb);
97 }
98
99 void
100 draw_cool_pattern(void)
101 {
102 int i,x,y;
103
104 i = 0;
105 for (y=0; y<config.src_height; y++) {
106 for (x=0; x<config.src_width; x++) {
107 y_image[i++] = x*x/2 + y*y/2 - 128;
108 }
109 }
110
111 i = 0;
112 for (y=0; y<config.src_height/2; y++)
113 for (x=0; x<config.src_width/2; x++)
114 {
115 cr_image[i++] = x - 128;
116 }
117
118 i = 0;
119 for (y=0; y<config.src_height/2; y++)
120 for (x=0; x<config.src_width/2; x++)
121 {
122 cb_image[i++] = y - 128;
123 }
124 }
125
126 void
127 draw_color_blend(void)
128 {
129 int i,x,y;
130
131 i = 0;
132 for (y=0; y<config.src_height; y++) {
133 for (x=0; x<config.src_width; x++) {
134 y_image[i++] = 0;
135 }
136 }
137
138 i = 0;
139 for (y=0; y<config.src_height/2; y++)
140 for (x=0; x<config.src_width/2; x++)
141 {
142 cr_image[i++] = x - 128;
143 }
144
145 i = 0;
146 for (y=0; y<config.src_height/2; y++)
147 for (x=0; x<config.src_width/2; x++)
148 {
149 cb_image[i++] = y - 128;
150 }
151 }
152
153 void
154 test_write(int f)
155 {
156 config.version = MGA_VID_VERSION;
157 config.src_width = SRC_IMAGE_WIDTH;
158 config.src_height= SRC_IMAGE_HEIGHT;
159 config.dest_width = SRC_IMAGE_WIDTH;
160 config.dest_height = SRC_IMAGE_HEIGHT;
161 config.x_org= 10;
162 config.y_org= 10;
163 config.colkey_on = 0;
164 config.format = MGA_VID_FORMAT_YV12;
165 config.frame_size=SRC_IMAGE_WIDTH*SRC_IMAGE_HEIGHT*2;
166 config.num_frames=1;
167
168 if (ioctl(f,MGA_VID_CONFIG,&config))
169 {
170 perror("Error in config ioctl");
171 }
172
173 if (config.card_type == MGA_G200)
174 {
175 printf("Testing MGA G200 Backend Scaler with %d MB of RAM\n", config.ram_size);
176 is_g400 = 0;
177 }
178 else
179 {
180 printf("Testing MGA G400 Backend Scaler with %d MB of RAM\n", config.ram_size);
181 is_g400 = 1;
182 }
183
184 ioctl(f,MGA_VID_ON,0);
185 mga_vid_base = (uint8_t*)mmap(0,256 * 4096,PROT_WRITE,MAP_SHARED,f,0);
186 printf("mga_vid_base = %8p\n",mga_vid_base);
187
188
189 //memset(y_image,80,256 * 128);
190 //memset(cr_image,80,256/2 * 20);
191 //memset(cb_image,80,256/2 * 20);
192 write_frame(y_image,cr_image,cb_image);
193 printf("(1) There should be a green square, offset by 10 pixels from\n"
194 " the upper left corner displayed\n");
195 sleep(3);
196
197
198 draw_cool_pattern();
199 write_frame(y_image,cr_image,cb_image);
200 printf("(2) There should be a cool mosaic like pattern now.\n");
201 sleep(3);
202
203 draw_color_blend();
204 write_frame(y_image,cr_image,cb_image);
205 printf("(3) There should be a color blend with black, red, purple, blue\n"
206 " corners (starting top left going CW)\n");
207 sleep(3);
208
209 ioctl(f,MGA_VID_OFF,0);
210
211 }
212
213 void
214 test_irq(int f)
215 {
216 int i = 2500;
217 unsigned long buf[4];
218
219 ioctl(f,MGA_VID_IRQ2_ON,0);
220
221 while (--i) {
222 if (read(f, buf, 8) > 0)
223 printf("c: %ld %ld\n", buf[0], buf[1]);
224 }
225
226
227 ioctl(f,MGA_VID_IRQ2_OFF,0);
228 }
229
230 int
231 main(int argc, char *argv[])
232 {
233 int f;
234
235 f = open("/dev/mga_vid",O_RDWR);
236
237 if(f == -1)
238 {
239 fprintf(stderr,"Couldn't open driver\n");
240 exit(1);
241 }
242
243 //test_write(f);
244 test_irq(f);
245
246 close(f);
247 return 0;
248 }