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