support for Geforce FX5500 based on patch by Pascal Yu <yu_pascal at hotmail.com>
[mplayer/greg.git] / drivers / mga_vid_test.c
blob997a6829e503ed5e985a4d0e6c40f38da1a2e427
1 /*
3 * mga_vid_test.c
5 * Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
6 * Sept 1999
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.
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 <inttypes.h>
20 #include <string.h>
21 #include "mga_vid.h"
23 mga_vid_config_t config;
24 uint8_t *mga_vid_base;
25 uint32_t is_g400;
27 #define SRC_IMAGE_WIDTH 256
28 #define SRC_IMAGE_HEIGHT 256
30 uint8_t y_image[SRC_IMAGE_WIDTH * SRC_IMAGE_HEIGHT];
31 uint8_t cr_image[SRC_IMAGE_WIDTH * SRC_IMAGE_HEIGHT];
32 uint8_t cb_image[SRC_IMAGE_WIDTH * SRC_IMAGE_HEIGHT];
35 void
36 write_frame_g200(uint8_t *y,uint8_t *cr, uint8_t *cb)
38 uint8_t *dest;
39 uint32_t bespitch,h,w;
41 dest = mga_vid_base;
42 bespitch = (config.src_width + 31) & ~31;
44 for(h=0; h < config.src_height; h++)
46 memcpy(dest, y, config.src_width);
47 y += config.src_width;
48 dest += bespitch;
51 for(h=0; h < config.src_height/2; h++)
53 for(w=0; w < config.src_width/2; w++)
55 *dest++ = *cb++;
56 *dest++ = *cr++;
58 dest += bespitch - config.src_width;
62 void
63 write_frame_g400(uint8_t *y,uint8_t *cr, uint8_t *cb)
65 uint8_t *dest;
66 uint32_t bespitch,h;
68 dest = mga_vid_base;
69 bespitch = (config.src_width + 31) & ~31;
71 for(h=0; h < config.src_height; h++)
73 memcpy(dest, y, config.src_width);
74 y += config.src_width;
75 dest += bespitch;
78 for(h=0; h < config.src_height/2; h++)
80 memcpy(dest, cb, config.src_width/2);
81 cb += config.src_width/2;
82 dest += bespitch/2;
85 for(h=0; h < config.src_height/2; h++)
87 memcpy(dest, cr, config.src_width/2);
88 cr += config.src_width/2;
89 dest += bespitch/2;
93 void write_frame(uint8_t *y,uint8_t *cr, uint8_t *cb)
95 if(is_g400)
96 write_frame_g400(y,cr,cb);
97 else
98 write_frame_g200(y,cr,cb);
101 void
102 draw_cool_pattern(void)
104 int i,x,y;
106 i = 0;
107 for (y=0; y<config.src_height; y++) {
108 for (x=0; x<config.src_width; x++) {
109 y_image[i++] = x*x/2 + y*y/2 - 128;
113 i = 0;
114 for (y=0; y<config.src_height/2; y++)
115 for (x=0; x<config.src_width/2; x++)
117 cr_image[i++] = x - 128;
120 i = 0;
121 for (y=0; y<config.src_height/2; y++)
122 for (x=0; x<config.src_width/2; x++)
124 cb_image[i++] = y - 128;
128 void
129 draw_color_blend(void)
131 int i,x,y;
133 i = 0;
134 for (y=0; y<config.src_height; y++) {
135 for (x=0; x<config.src_width; x++) {
136 y_image[i++] = 0;
140 i = 0;
141 for (y=0; y<config.src_height/2; y++)
142 for (x=0; x<config.src_width/2; x++)
144 cr_image[i++] = x - 128;
147 i = 0;
148 for (y=0; y<config.src_height/2; y++)
149 for (x=0; x<config.src_width/2; x++)
151 cb_image[i++] = y - 128;
156 int
157 main(int argc, char *argv[])
159 int f;
161 f = open("/dev/mga_vid",O_RDWR);
163 if(f == -1)
165 fprintf(stderr,"Couldn't open driver\n");
166 exit(1);
169 config.version = MGA_VID_VERSION;
170 config.src_width = SRC_IMAGE_WIDTH;
171 config.src_height= SRC_IMAGE_HEIGHT;
172 config.dest_width = SRC_IMAGE_WIDTH;
173 config.dest_height = SRC_IMAGE_HEIGHT;
174 config.x_org= 10;
175 config.y_org= 10;
176 config.colkey_on = 0;
177 config.format = MGA_VID_FORMAT_YV12;
178 config.frame_size=SRC_IMAGE_WIDTH*SRC_IMAGE_HEIGHT*2;
179 config.num_frames=1;
181 if (ioctl(f,MGA_VID_CONFIG,&config))
183 perror("Error in config ioctl");
186 if (config.card_type == MGA_G200)
188 printf("Testing MGA G200 Backend Scaler with %d MB of RAM\n", config.ram_size);
189 is_g400 = 0;
191 else
193 printf("Testing MGA G400 Backend Scaler with %d MB of RAM\n", config.ram_size);
194 is_g400 = 1;
197 ioctl(f,MGA_VID_ON,0);
198 mga_vid_base = (uint8_t*)mmap(0,256 * 4096,PROT_WRITE,MAP_SHARED,f,0);
199 printf("mga_vid_base = %8p\n",mga_vid_base);
202 //memset(y_image,80,256 * 128);
203 //memset(cr_image,80,256/2 * 20);
204 //memset(cb_image,80,256/2 * 20);
205 write_frame(y_image,cr_image,cb_image);
206 printf("(1) There should be a green square, offset by 10 pixels from\n"
207 " the upper left corner displayed\n");
208 sleep(3);
211 draw_cool_pattern();
212 write_frame(y_image,cr_image,cb_image);
213 printf("(2) There should be a cool mosaic like pattern now.\n");
214 sleep(3);
216 draw_color_blend();
217 write_frame(y_image,cr_image,cb_image);
218 printf("(3) There should be a color blend with black, red, purple, blue\n"
219 " corners (starting top left going CW)\n");
220 sleep(3);
222 ioctl(f,MGA_VID_OFF,0);
224 close(f);
225 return 0;