Mercurial > mplayer.hg
annotate libvo/mga_common.c @ 5540:80d8fed6e683
new tdfxfb yuv driver by Mark Zealey <mark@zealos.org>
author | arpi |
---|---|
date | Tue, 09 Apr 2002 14:02:55 +0000 |
parents | d596cf3c54aa |
children | e01c664def74 |
rev | line source |
---|---|
413 | 1 |
566 | 2 #include "fastmemcpy.h" |
2625 | 3 #include "../mmx_defs.h" |
4971 | 4 #include "../mp_image.h" |
5405 | 5 #include "../postproc/rgb2rgb.h" |
1 | 6 |
7 // mga_vid drawing functions | |
8 | |
56 | 9 static int mga_next_frame=0; |
10 | |
11 static mga_vid_config_t mga_vid_config; | |
12 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
|
13 static int f = -1; |
56 | 14 |
202 | 15 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ |
16 int x,y; | |
17 uint32_t bespitch = (mga_vid_config.src_width + 31) & ~31; | |
466 | 18 switch(mga_vid_config.format){ |
19 case MGA_VID_FORMAT_YV12: | |
470 | 20 case MGA_VID_FORMAT_IYUV: |
21 case MGA_VID_FORMAT_I420: | |
326 | 22 vo_draw_alpha_yv12(w,h,src,srca,stride,vid_data+bespitch*y0+x0,bespitch); |
466 | 23 break; |
24 case MGA_VID_FORMAT_YUY2: | |
326 | 25 vo_draw_alpha_yuy2(w,h,src,srca,stride,vid_data+2*(bespitch*y0+x0),2*bespitch); |
466 | 26 break; |
27 case MGA_VID_FORMAT_UYVY: | |
28 vo_draw_alpha_yuy2(w,h,src,srca,stride,vid_data+2*(bespitch*y0+x0)+1,2*bespitch); | |
29 break; | |
30 } | |
1 | 31 } |
32 | |
5014
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
33 static int mga_set_video_eq( const vidix_video_eq_t *info) |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
34 { |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
35 |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
36 uint32_t luma; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
37 float factor = 256.0 / 2000; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
38 |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
39 luma = ((int)(info->brightness * factor) << 16) + |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
40 ((int)(info->contrast * factor) & 0xFFFF); |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
41 if (ioctl(f,MGA_VID_SET_LUMA,luma)) { |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
42 perror("Error in mga_vid_config ioctl()"); |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
43 printf("Could not set luma values in the kernel module!\n"); |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
44 return -1; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
45 } |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
46 return 0; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
47 |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
48 } |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
49 |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
50 static int mga_get_video_eq( vidix_video_eq_t *info) |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
51 { |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
52 |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
53 uint32_t luma; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
54 float factor = 2000.0 / 256; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
55 |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
56 if (ioctl(f,MGA_VID_GET_LUMA,&luma)) { |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
57 perror("Error in mga_vid_config ioctl()"); |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
58 printf("Could not get luma values from the kernel module!\n"); |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
59 return -1; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
60 } |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
61 info->brightness = (luma >> 16) * factor; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
62 info->cap |= VEQ_CAP_BRIGHTNESS; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
63 |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
64 info->contrast = (luma & 0xFFFF) * factor; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
65 info->cap |= VEQ_CAP_CONTRAST; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
66 |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
67 return 0; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
68 } |
1 | 69 |
70 //static void | |
71 //write_slice_g200(uint8_t *y,uint8_t *cr, uint8_t *cb,uint32_t slice_num) | |
72 | |
73 static void | |
74 draw_slice_g200(uint8_t *image[], int stride[], int width,int height,int x,int y) | |
75 { | |
76 uint8_t *src; | |
77 uint8_t *src2; | |
78 uint8_t *dest; | |
79 uint32_t bespitch,h,w; | |
80 | |
284 | 81 bespitch = (mga_vid_config.src_width + 31) & ~31; |
1 | 82 |
284 | 83 dest = vid_data + bespitch*y + x; |
4949 | 84 mem2agpcpy_pic(dest, image[0], width, height, bespitch, stride[0]); |
1 | 85 |
86 width/=2;height/=2;x/=2;y/=2; | |
87 | |
284 | 88 dest = vid_data + bespitch*mga_vid_config.src_height + bespitch*y + 2*x; |
5405 | 89 |
90 interleaveBytes(image[1],image[2],dest, | |
5406 | 91 width, height, |
5405 | 92 stride[1], stride[2], bespitch); |
1 | 93 } |
94 | |
95 static void | |
96 draw_slice_g400(uint8_t *image[], int stride[], int w,int h,int x,int y) | |
97 { | |
98 uint8_t *src; | |
99 uint8_t *dest; | |
5317 | 100 uint8_t *dest2; |
1 | 101 uint32_t bespitch,bespitch2; |
102 int i; | |
103 | |
104 bespitch = (mga_vid_config.src_width + 31) & ~31; | |
105 bespitch2 = bespitch/2; | |
106 | |
107 dest = vid_data + bespitch * y + x; | |
4949 | 108 mem2agpcpy_pic(dest, image[0], w, h, bespitch, stride[0]); |
1 | 109 |
110 w/=2;h/=2;x/=2;y/=2; | |
5317 | 111 |
1 | 112 dest = vid_data + bespitch*mga_vid_config.src_height + bespitch2 * y + x; |
5317 | 113 dest2= dest + bespitch2*mga_vid_config.src_height / 2; |
1 | 114 |
5317 | 115 if(mga_vid_config.format==MGA_VID_FORMAT_YV12){ |
116 // mga_vid's YV12 assumes Y,U,V order (insteda of Y,V,U) :( | |
117 mem2agpcpy_pic(dest, image[1], w, h, bespitch2, stride[1]); | |
118 mem2agpcpy_pic(dest2,image[2], w, h, bespitch2, stride[2]); | |
119 } else { | |
4949 | 120 mem2agpcpy_pic(dest, image[2], w, h, bespitch2, stride[2]); |
5317 | 121 mem2agpcpy_pic(dest2,image[1], w, h, bespitch2, stride[1]); |
122 } | |
1 | 123 |
124 } | |
125 | |
126 static uint32_t | |
127 draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y) | |
128 { | |
4949 | 129 |
130 #if 0 | |
131 printf("vo: %p/%d %p/%d %p/%d %dx%d/%d;%d \n", | |
132 src[0],stride[0], | |
133 src[1],stride[1], | |
134 src[2],stride[2], | |
135 w,h,x,y); | |
136 #endif | |
137 | |
1 | 138 if (mga_vid_config.card_type == MGA_G200) |
139 draw_slice_g200(src,stride,w,h,x,y); | |
140 else | |
141 draw_slice_g400(src,stride,w,h,x,y); | |
142 return 0; | |
143 } | |
144 | |
145 static void | |
31 | 146 vo_mga_flip_page(void) |
1 | 147 { |
47 | 148 |
149 // printf("-- flip to %d --\n",mga_next_frame); | |
1 | 150 |
47 | 151 #if 1 |
152 ioctl(f,MGA_VID_FSEL,&mga_next_frame); | |
56 | 153 mga_next_frame=(mga_next_frame+1)%mga_vid_config.num_frames; |
47 | 154 vid_data=frames[mga_next_frame]; |
155 #endif | |
1 | 156 |
157 } | |
158 | |
159 | |
160 static void | |
161 write_frame_yuy2(uint8_t *y) | |
162 { | |
163 int len=2*mga_vid_config.src_width; | |
4949 | 164 uint32_t bespitch = (mga_vid_config.src_width + 31) & ~31; |
1 | 165 |
4949 | 166 mem2agpcpy_pic(vid_data, y, len, mga_vid_config.src_height, 2*bespitch, len); |
1 | 167 } |
168 | |
169 static uint32_t | |
170 draw_frame(uint8_t *src[]) | |
171 { | |
448
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
172 switch(mga_vid_config.format){ |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
173 case MGA_VID_FORMAT_YUY2: |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
174 case MGA_VID_FORMAT_UYVY: |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
175 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
|
176 } |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
177 return 0; |
1 | 178 } |
179 | |
180 static uint32_t | |
4971 | 181 get_image(mp_image_t *mpi){ |
182 uint32_t bespitch = (mga_vid_config.src_width + 31) & ~31; | |
183 uint32_t bespitch2 = bespitch/2; | |
184 // printf("mga: get_image() called\n"); | |
4975 | 185 if(mpi->type==MP_IMGTYPE_STATIC && mga_vid_config.num_frames>1) return VO_FALSE; // it is not static |
4971 | 186 if(mpi->flags&MP_IMGFLAG_READABLE) return VO_FALSE; // slow video ram |
5335 | 187 if(mga_vid_config.card_type == MGA_G200 && mpi->flags&MP_IMGFLAG_PLANAR) return VO_FALSE; |
4971 | 188 // printf("width=%d vs. bespitch=%d, flags=0x%X \n",mpi->width,bespitch,mpi->flags); |
189 if((mpi->width==bespitch) || | |
190 (mpi->flags&(MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH))){ | |
191 // we're lucky or codec accepts stride => ok, let's go! | |
192 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
193 mpi->planes[0]=vid_data; | |
5317 | 194 if(mpi->flags&MP_IMGFLAG_SWAPPED){ |
195 mpi->planes[1]=vid_data + bespitch*mga_vid_config.src_height; | |
196 mpi->planes[2]=mpi->planes[1] + bespitch2*mga_vid_config.src_height/2; | |
197 } else { | |
198 mpi->planes[2]=vid_data + bespitch*mga_vid_config.src_height; | |
199 mpi->planes[1]=mpi->planes[2] + bespitch2*mga_vid_config.src_height/2; | |
200 } | |
4971 | 201 mpi->width=mpi->stride[0]=bespitch; |
202 mpi->stride[1]=mpi->stride[2]=bespitch2; | |
203 } else { | |
204 mpi->planes[0]=vid_data; | |
205 mpi->width=bespitch; | |
206 mpi->stride[0]=mpi->width*(mpi->bpp/8); | |
207 } | |
208 mpi->flags|=MP_IMGFLAG_DIRECT; | |
209 // printf("mga: get_image() SUCCESS -> Direct Rendering ENABLED\n"); | |
210 return VO_TRUE; | |
211 } | |
212 return VO_FALSE; | |
213 } | |
214 | |
215 static uint32_t | |
1 | 216 query_format(uint32_t format) |
217 { | |
218 switch(format){ | |
219 case IMGFMT_YV12: | |
470 | 220 case IMGFMT_I420: |
221 case IMGFMT_IYUV: | |
1 | 222 case IMGFMT_YUY2: |
448
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
223 case IMGFMT_UYVY: |
1 | 224 // case IMGFMT_RGB|24: |
225 // case IMGFMT_BGR|24: | |
226 return 1; | |
227 } | |
228 return 0; | |
229 } | |
230 | |
5014
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
231 static void query_vaa(vo_vaa_t *vaa) |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
232 { |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
233 memset(vaa,0,sizeof(vo_vaa_t)); |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
234 vaa->get_video_eq = mga_get_video_eq; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
235 vaa->set_video_eq = mga_set_video_eq; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
236 } |
4970 | 237 static uint32_t control(uint32_t request, void *data, ...) |
238 { | |
239 switch (request) { | |
5014
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
240 case VOCTRL_QUERY_VAA: |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
241 query_vaa((vo_vaa_t*)data); |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
242 return VO_TRUE; |
4970 | 243 case VOCTRL_QUERY_FORMAT: |
244 return query_format(*((uint32_t*)data)); | |
4971 | 245 case VOCTRL_GET_IMAGE: |
246 return get_image(data); | |
4981 | 247 #ifdef VO_XMGA |
248 case VOCTRL_FULLSCREEN: | |
249 vo_x11_fullscreen(); | |
250 return VO_TRUE; | |
251 #endif | |
4970 | 252 } |
253 return VO_NOTIMPL; | |
254 } | |
255 | |
256 | |
56 | 257 static int mga_init(){ |
258 char *frame_mem; | |
259 | |
5432 | 260 mga_vid_config.num_frames=(vo_directrendering && !vo_doublebuffering)?1:3; |
56 | 261 mga_vid_config.version=MGA_VID_VERSION; |
262 if (ioctl(f,MGA_VID_CONFIG,&mga_vid_config)) | |
263 { | |
275 | 264 perror("Error in mga_vid_config ioctl()"); |
265 printf("Your mga_vid driver version is incompatible with this MPlayer version!\n"); | |
56 | 266 return -1; |
267 } | |
268 ioctl(f,MGA_VID_ON,0); | |
5432 | 269 |
270 printf("[mga] Using %d buffers.\n",mga_vid_config.num_frames); | |
56 | 271 |
272 frames[0] = (char*)mmap(0,mga_vid_config.frame_size*mga_vid_config.num_frames,PROT_WRITE,MAP_SHARED,f,0); | |
273 frames[1] = frames[0] + 1*mga_vid_config.frame_size; | |
274 frames[2] = frames[0] + 2*mga_vid_config.frame_size; | |
275 frames[3] = frames[0] + 3*mga_vid_config.frame_size; | |
276 mga_next_frame = 0; | |
277 vid_data = frames[mga_next_frame]; | |
278 | |
279 //clear the buffer | |
280 memset(frames[0],0x80,mga_vid_config.frame_size*mga_vid_config.num_frames); | |
281 | |
282 return 0; | |
283 | |
284 } | |
285 | |
1637 | 286 static int mga_uninit(){ |
287 ioctl( f,MGA_VID_OFF,0 ); | |
288 munmap(frames[0],mga_vid_config.frame_size*mga_vid_config.num_frames); | |
289 close(f); | |
5389
7296c4262457
quick hack to make vo_mga accept multiple calls to config
rfelker
parents:
5335
diff
changeset
|
290 f = -1; |
1637 | 291 } |
4970 | 292 |
293 static uint32_t preinit(const char *arg) | |
294 { | |
5433 | 295 char *devname=vo_subdevice?vo_subdevice:"/dev/mga_vid"; |
296 | |
297 f = open(devname,O_RDWR); | |
298 if(f == -1) | |
299 { | |
300 perror("open"); | |
301 printf("Couldn't open %s\n",devname); | |
302 return(-1); | |
303 } | |
4970 | 304 return 0; |
305 } | |
306 |