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