Mercurial > mplayer.hg
annotate libvo/mga_common.c @ 7618:555ef64dfe1c
sync, shorter messages in help screen
author | rtognimp |
---|---|
date | Sun, 06 Oct 2002 13:19:21 +0000 |
parents | c4434bdf6e51 |
children | 711b3d844c47 |
rev | line source |
---|---|
413 | 1 |
566 | 2 #include "fastmemcpy.h" |
2625 | 3 #include "../mmx_defs.h" |
5405 | 4 #include "../postproc/rgb2rgb.h" |
1 | 5 |
6 // mga_vid drawing functions | |
6335
e9bd97d5c5cc
warning & newline fixes by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
6311
diff
changeset
|
7 #ifdef VO_XMGA |
6382
86d5fc5b54e2
fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents:
6335
diff
changeset
|
8 static void set_window( void ); /* forward declaration to kill warnings */ |
6335
e9bd97d5c5cc
warning & newline fixes by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
6311
diff
changeset
|
9 #endif |
1 | 10 |
56 | 11 static int mga_next_frame=0; |
12 | |
13 static mga_vid_config_t mga_vid_config; | |
14 static uint8_t *vid_data, *frames[4]; | |
5389
7296c4262457
quick hack to make vo_mga accept multiple calls to config
rfelker
parents:
5335
diff
changeset
|
15 static int f = -1; |
56 | 16 |
202 | 17 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ |
18 uint32_t bespitch = (mga_vid_config.src_width + 31) & ~31; | |
466 | 19 switch(mga_vid_config.format){ |
20 case MGA_VID_FORMAT_YV12: | |
470 | 21 case MGA_VID_FORMAT_IYUV: |
22 case MGA_VID_FORMAT_I420: | |
326 | 23 vo_draw_alpha_yv12(w,h,src,srca,stride,vid_data+bespitch*y0+x0,bespitch); |
466 | 24 break; |
25 case MGA_VID_FORMAT_YUY2: | |
326 | 26 vo_draw_alpha_yuy2(w,h,src,srca,stride,vid_data+2*(bespitch*y0+x0),2*bespitch); |
466 | 27 break; |
28 case MGA_VID_FORMAT_UYVY: | |
29 vo_draw_alpha_yuy2(w,h,src,srca,stride,vid_data+2*(bespitch*y0+x0)+1,2*bespitch); | |
30 break; | |
31 } | |
1 | 32 } |
33 | |
34 //static void | |
35 //write_slice_g200(uint8_t *y,uint8_t *cr, uint8_t *cb,uint32_t slice_num) | |
36 | |
37 static void | |
38 draw_slice_g200(uint8_t *image[], int stride[], int width,int height,int x,int y) | |
39 { | |
40 uint8_t *dest; | |
7472
c4434bdf6e51
tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents:
6799
diff
changeset
|
41 uint32_t bespitch = (mga_vid_config.src_width + 31) & ~31; |
1 | 42 |
284 | 43 dest = vid_data + bespitch*y + x; |
4949 | 44 mem2agpcpy_pic(dest, image[0], width, height, bespitch, stride[0]); |
1 | 45 |
46 width/=2;height/=2;x/=2;y/=2; | |
47 | |
284 | 48 dest = vid_data + bespitch*mga_vid_config.src_height + bespitch*y + 2*x; |
5405 | 49 |
50 interleaveBytes(image[1],image[2],dest, | |
5406 | 51 width, height, |
5405 | 52 stride[1], stride[2], bespitch); |
1 | 53 } |
54 | |
55 static void | |
56 draw_slice_g400(uint8_t *image[], int stride[], int w,int h,int x,int y) | |
57 { | |
58 uint8_t *dest; | |
5317 | 59 uint8_t *dest2; |
1 | 60 uint32_t bespitch,bespitch2; |
61 | |
62 bespitch = (mga_vid_config.src_width + 31) & ~31; | |
63 bespitch2 = bespitch/2; | |
64 | |
65 dest = vid_data + bespitch * y + x; | |
4949 | 66 mem2agpcpy_pic(dest, image[0], w, h, bespitch, stride[0]); |
1 | 67 |
68 w/=2;h/=2;x/=2;y/=2; | |
5317 | 69 |
1 | 70 dest = vid_data + bespitch*mga_vid_config.src_height + bespitch2 * y + x; |
5317 | 71 dest2= dest + bespitch2*mga_vid_config.src_height / 2; |
1 | 72 |
5317 | 73 if(mga_vid_config.format==MGA_VID_FORMAT_YV12){ |
74 // mga_vid's YV12 assumes Y,U,V order (insteda of Y,V,U) :( | |
75 mem2agpcpy_pic(dest, image[1], w, h, bespitch2, stride[1]); | |
76 mem2agpcpy_pic(dest2,image[2], w, h, bespitch2, stride[2]); | |
77 } else { | |
4949 | 78 mem2agpcpy_pic(dest, image[2], w, h, bespitch2, stride[2]); |
5317 | 79 mem2agpcpy_pic(dest2,image[1], w, h, bespitch2, stride[1]); |
80 } | |
1 | 81 |
82 } | |
83 | |
84 static uint32_t | |
85 draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y) | |
86 { | |
4949 | 87 |
88 #if 0 | |
89 printf("vo: %p/%d %p/%d %p/%d %dx%d/%d;%d \n", | |
90 src[0],stride[0], | |
91 src[1],stride[1], | |
92 src[2],stride[2], | |
93 w,h,x,y); | |
94 #endif | |
95 | |
1 | 96 if (mga_vid_config.card_type == MGA_G200) |
97 draw_slice_g200(src,stride,w,h,x,y); | |
98 else | |
99 draw_slice_g400(src,stride,w,h,x,y); | |
100 return 0; | |
101 } | |
102 | |
103 static void | |
31 | 104 vo_mga_flip_page(void) |
1 | 105 { |
47 | 106 |
107 // printf("-- flip to %d --\n",mga_next_frame); | |
1 | 108 |
47 | 109 #if 1 |
110 ioctl(f,MGA_VID_FSEL,&mga_next_frame); | |
56 | 111 mga_next_frame=(mga_next_frame+1)%mga_vid_config.num_frames; |
47 | 112 vid_data=frames[mga_next_frame]; |
113 #endif | |
1 | 114 |
115 } | |
116 | |
117 | |
118 static void | |
119 write_frame_yuy2(uint8_t *y) | |
120 { | |
121 int len=2*mga_vid_config.src_width; | |
4949 | 122 uint32_t bespitch = (mga_vid_config.src_width + 31) & ~31; |
1 | 123 |
4949 | 124 mem2agpcpy_pic(vid_data, y, len, mga_vid_config.src_height, 2*bespitch, len); |
1 | 125 } |
126 | |
127 static uint32_t | |
128 draw_frame(uint8_t *src[]) | |
129 { | |
448
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
130 switch(mga_vid_config.format){ |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
131 case MGA_VID_FORMAT_YUY2: |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
132 case MGA_VID_FORMAT_UYVY: |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
133 write_frame_yuy2(src[0]);break; |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
134 } |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
135 return 0; |
1 | 136 } |
137 | |
138 static uint32_t | |
4971 | 139 get_image(mp_image_t *mpi){ |
140 uint32_t bespitch = (mga_vid_config.src_width + 31) & ~31; | |
141 uint32_t bespitch2 = bespitch/2; | |
142 // printf("mga: get_image() called\n"); | |
4975 | 143 if(mpi->type==MP_IMGTYPE_STATIC && mga_vid_config.num_frames>1) return VO_FALSE; // it is not static |
4971 | 144 if(mpi->flags&MP_IMGFLAG_READABLE) return VO_FALSE; // slow video ram |
5335 | 145 if(mga_vid_config.card_type == MGA_G200 && mpi->flags&MP_IMGFLAG_PLANAR) return VO_FALSE; |
4971 | 146 // printf("width=%d vs. bespitch=%d, flags=0x%X \n",mpi->width,bespitch,mpi->flags); |
147 if((mpi->width==bespitch) || | |
148 (mpi->flags&(MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH))){ | |
149 // we're lucky or codec accepts stride => ok, let's go! | |
150 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
151 mpi->planes[0]=vid_data; | |
5317 | 152 if(mpi->flags&MP_IMGFLAG_SWAPPED){ |
153 mpi->planes[1]=vid_data + bespitch*mga_vid_config.src_height; | |
154 mpi->planes[2]=mpi->planes[1] + bespitch2*mga_vid_config.src_height/2; | |
155 } else { | |
156 mpi->planes[2]=vid_data + bespitch*mga_vid_config.src_height; | |
157 mpi->planes[1]=mpi->planes[2] + bespitch2*mga_vid_config.src_height/2; | |
158 } | |
4971 | 159 mpi->width=mpi->stride[0]=bespitch; |
160 mpi->stride[1]=mpi->stride[2]=bespitch2; | |
161 } else { | |
162 mpi->planes[0]=vid_data; | |
163 mpi->width=bespitch; | |
164 mpi->stride[0]=mpi->width*(mpi->bpp/8); | |
165 } | |
166 mpi->flags|=MP_IMGFLAG_DIRECT; | |
167 // printf("mga: get_image() SUCCESS -> Direct Rendering ENABLED\n"); | |
168 return VO_TRUE; | |
169 } | |
170 return VO_FALSE; | |
171 } | |
172 | |
173 static uint32_t | |
1 | 174 query_format(uint32_t format) |
175 { | |
176 switch(format){ | |
177 case IMGFMT_YV12: | |
470 | 178 case IMGFMT_I420: |
179 case IMGFMT_IYUV: | |
1 | 180 case IMGFMT_YUY2: |
448
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
181 case IMGFMT_UYVY: |
1 | 182 // case IMGFMT_RGB|24: |
183 // case IMGFMT_BGR|24: | |
5566 | 184 return 3 | VFCAP_OSD|VFCAP_HWSCALE_UP|VFCAP_HWSCALE_DOWN; |
1 | 185 } |
186 return 0; | |
187 } | |
188 | |
5987 | 189 static void mga_fullscreen() |
190 { | |
191 uint32_t w,h; | |
192 if ( !vo_fs ) { | |
193 vo_fs=VO_TRUE; | |
194 w=vo_screenwidth; h=vo_screenheight; | |
195 aspect(&w,&h,A_ZOOM); | |
196 } else { | |
197 vo_fs=VO_FALSE; | |
198 w=vo_dwidth; h=vo_dheight; | |
199 aspect(&w,&h,A_NOZOOM); | |
200 } | |
201 mga_vid_config.dest_width = w; | |
202 mga_vid_config.dest_height= h; | |
203 if (vo_screenwidth && vo_screenheight) { | |
204 mga_vid_config.x_org=(vo_screenwidth-w)/2; | |
205 mga_vid_config.y_org=(vo_screenheight-h)/2; | |
206 } else { | |
207 mga_vid_config.x_org= 0; | |
208 mga_vid_config.y_org= 0; | |
209 } | |
210 if ( ioctl( f,MGA_VID_CONFIG,&mga_vid_config ) ) | |
211 printf( "Error in mga_vid_config ioctl (wrong mga_vid.o version?)" ); | |
212 } | |
213 | |
4970 | 214 static uint32_t control(uint32_t request, void *data, ...) |
215 { | |
216 switch (request) { | |
217 case VOCTRL_QUERY_FORMAT: | |
218 return query_format(*((uint32_t*)data)); | |
4971 | 219 case VOCTRL_GET_IMAGE: |
220 return get_image(data); | |
6799 | 221 case VOCTRL_SET_EQUALIZER: |
222 { | |
223 va_list ap; | |
224 short value; | |
225 uint32_t luma,prev; | |
6382
86d5fc5b54e2
fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents:
6335
diff
changeset
|
226 |
6799 | 227 if ( strcmp( data,"brightness" ) && strcmp( data,"contrast" ) ) return VO_FALSE; |
228 | |
229 if (ioctl(f,MGA_VID_GET_LUMA,&prev)) { | |
230 perror("Error in mga_vid_config ioctl()"); | |
231 printf("Could not get luma values from the kernel module!\n"); | |
232 return VO_FALSE; | |
233 } | |
234 | |
235 // printf("GET: 0x%4X 0x%4X \n",(prev>>16),(prev&0xffff)); | |
236 | |
237 va_start(ap, data); | |
238 value = va_arg(ap, int); | |
239 va_end(ap); | |
240 | |
241 // printf("value: %d -> ",value); | |
242 value=((value+100)*255)/200-128; // maps -100=>-128 and +100=>127 | |
243 // printf("%d \n",value); | |
244 | |
245 if(!strcmp(data,"contrast")) | |
246 luma = (prev&0xFFFF0000)|(value&0xFFFF); | |
247 else | |
248 luma = (prev&0xFFFF)|(value<<16); | |
249 | |
250 if (ioctl(f,MGA_VID_SET_LUMA,luma)) { | |
251 perror("Error in mga_vid_config ioctl()"); | |
252 printf("Could not set luma values in the kernel module!\n"); | |
253 return VO_FALSE; | |
254 } | |
255 | |
256 return VO_TRUE; | |
257 } | |
258 | |
259 case VOCTRL_GET_EQUALIZER: | |
260 { | |
261 va_list ap; | |
262 int * value; | |
263 short val; | |
264 uint32_t luma; | |
265 | |
266 if ( strcmp( data,"brightness" ) && strcmp( data,"contrast" ) ) return VO_FALSE; | |
267 | |
268 if (ioctl(f,MGA_VID_GET_LUMA,&luma)) { | |
269 perror("Error in mga_vid_config ioctl()"); | |
270 printf("Could not get luma values from the kernel module!\n"); | |
271 return VO_FALSE; | |
272 } | |
273 | |
274 if ( !strcmp( data,"contrast" ) ) | |
275 val=(luma & 0xFFFF); | |
276 else | |
277 val=(luma >> 16); | |
278 | |
279 va_start(ap, data); | |
280 value = va_arg(ap, int*); | |
281 va_end(ap); | |
282 | |
283 *value = (val*200)/255; | |
284 | |
285 return VO_TRUE; | |
286 } | |
287 | |
6382
86d5fc5b54e2
fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents:
6335
diff
changeset
|
288 #ifndef VO_XMGA |
5987 | 289 case VOCTRL_FULLSCREEN: |
290 mga_fullscreen(); | |
6382
86d5fc5b54e2
fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents:
6335
diff
changeset
|
291 return VO_TRUE; |
5987 | 292 #endif |
6382
86d5fc5b54e2
fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents:
6335
diff
changeset
|
293 |
6009 | 294 #if defined( VO_XMGA ) && defined( HAVE_NEW_GUI ) |
295 case VOCTRL_GUISUPPORT: | |
296 return VO_TRUE; | |
297 #endif | |
6382
86d5fc5b54e2
fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents:
6335
diff
changeset
|
298 |
6307 | 299 #ifdef VO_XMGA |
300 case VOCTRL_GET_PANSCAN: | |
6311
da2dda48b7ec
add mute support ( step 1 ) and fixed panscan bugs (1000l for me)
pontscho
parents:
6307
diff
changeset
|
301 if ( !inited || !vo_fs ) return VO_FALSE; |
6307 | 302 return VO_TRUE; |
6382
86d5fc5b54e2
fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents:
6335
diff
changeset
|
303 case VOCTRL_FULLSCREEN: |
86d5fc5b54e2
fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents:
6335
diff
changeset
|
304 vo_x11_fullscreen(); |
86d5fc5b54e2
fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents:
6335
diff
changeset
|
305 vo_panscan_amount=0; |
86d5fc5b54e2
fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents:
6335
diff
changeset
|
306 /* indended, fallthrough to update panscan on fullscreen/windowed switch */ |
6307 | 307 case VOCTRL_SET_PANSCAN: |
6382
86d5fc5b54e2
fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents:
6335
diff
changeset
|
308 if ( vo_fs && ( vo_panscan != vo_panscan_amount ) ) // || ( !vo_fs && vo_panscan_amount ) ) |
6307 | 309 { |
6382
86d5fc5b54e2
fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents:
6335
diff
changeset
|
310 int old_y = vo_panscan_y; |
6307 | 311 panscan_calc(); |
6382
86d5fc5b54e2
fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents:
6335
diff
changeset
|
312 // if ( old_y != vo_panscan_y ) |
86d5fc5b54e2
fix panscan support and add Jesper Svennevid's <mplayer@svennevid.net> patch
pontscho
parents:
6335
diff
changeset
|
313 set_window(); |
6307 | 314 } |
315 return VO_TRUE; | |
316 #endif | |
4970 | 317 } |
318 return VO_NOTIMPL; | |
319 } | |
320 | |
321 | |
56 | 322 static int mga_init(){ |
323 | |
5432 | 324 mga_vid_config.num_frames=(vo_directrendering && !vo_doublebuffering)?1:3; |
56 | 325 mga_vid_config.version=MGA_VID_VERSION; |
326 if (ioctl(f,MGA_VID_CONFIG,&mga_vid_config)) | |
327 { | |
275 | 328 perror("Error in mga_vid_config ioctl()"); |
329 printf("Your mga_vid driver version is incompatible with this MPlayer version!\n"); | |
56 | 330 return -1; |
331 } | |
332 ioctl(f,MGA_VID_ON,0); | |
5432 | 333 |
334 printf("[mga] Using %d buffers.\n",mga_vid_config.num_frames); | |
56 | 335 |
336 frames[0] = (char*)mmap(0,mga_vid_config.frame_size*mga_vid_config.num_frames,PROT_WRITE,MAP_SHARED,f,0); | |
337 frames[1] = frames[0] + 1*mga_vid_config.frame_size; | |
338 frames[2] = frames[0] + 2*mga_vid_config.frame_size; | |
339 frames[3] = frames[0] + 3*mga_vid_config.frame_size; | |
340 mga_next_frame = 0; | |
341 vid_data = frames[mga_next_frame]; | |
342 | |
343 //clear the buffer | |
344 memset(frames[0],0x80,mga_vid_config.frame_size*mga_vid_config.num_frames); | |
345 | |
346 return 0; | |
347 | |
348 } | |
349 | |
1637 | 350 static int mga_uninit(){ |
351 ioctl( f,MGA_VID_OFF,0 ); | |
352 munmap(frames[0],mga_vid_config.frame_size*mga_vid_config.num_frames); | |
353 close(f); | |
5389
7296c4262457
quick hack to make vo_mga accept multiple calls to config
rfelker
parents:
5335
diff
changeset
|
354 f = -1; |
7472
c4434bdf6e51
tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents:
6799
diff
changeset
|
355 return 0; |
1637 | 356 } |
4970 | 357 |
358 static uint32_t preinit(const char *arg) | |
359 { | |
5433 | 360 char *devname=vo_subdevice?vo_subdevice:"/dev/mga_vid"; |
361 | |
362 f = open(devname,O_RDWR); | |
363 if(f == -1) | |
364 { | |
365 perror("open"); | |
366 printf("Couldn't open %s\n",devname); | |
367 return(-1); | |
368 } | |
4970 | 369 return 0; |
370 } | |
371 |