Mercurial > mplayer.hg
annotate libvo/mga_common.c @ 4981:bfc652fc7f43
rewrite fullscreen support in some libvo driver
author | pontscho |
---|---|
date | Thu, 07 Mar 2002 17:50:25 +0000 |
parents | 877f0f643fef |
children | 4458e43871d3 |
rev | line source |
---|---|
413 | 1 |
566 | 2 #include "fastmemcpy.h" |
2625 | 3 #include "../mmx_defs.h" |
4971 | 4 #include "../mp_image.h" |
1 | 5 |
6 // mga_vid drawing functions | |
7 | |
56 | 8 static int mga_next_frame=0; |
9 | |
10 static mga_vid_config_t mga_vid_config; | |
11 static uint8_t *vid_data, *frames[4]; | |
12 static int f; | |
13 | |
202 | 14 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ |
15 int x,y; | |
16 uint32_t bespitch = (mga_vid_config.src_width + 31) & ~31; | |
466 | 17 switch(mga_vid_config.format){ |
18 case MGA_VID_FORMAT_YV12: | |
470 | 19 case MGA_VID_FORMAT_IYUV: |
20 case MGA_VID_FORMAT_I420: | |
326 | 21 vo_draw_alpha_yv12(w,h,src,srca,stride,vid_data+bespitch*y0+x0,bespitch); |
466 | 22 break; |
23 case MGA_VID_FORMAT_YUY2: | |
326 | 24 vo_draw_alpha_yuy2(w,h,src,srca,stride,vid_data+2*(bespitch*y0+x0),2*bespitch); |
466 | 25 break; |
26 case MGA_VID_FORMAT_UYVY: | |
27 vo_draw_alpha_yuy2(w,h,src,srca,stride,vid_data+2*(bespitch*y0+x0)+1,2*bespitch); | |
28 break; | |
29 } | |
1 | 30 } |
31 | |
32 | |
33 //static void | |
34 //write_slice_g200(uint8_t *y,uint8_t *cr, uint8_t *cb,uint32_t slice_num) | |
35 | |
36 static void | |
37 draw_slice_g200(uint8_t *image[], int stride[], int width,int height,int x,int y) | |
38 { | |
39 uint8_t *src; | |
40 uint8_t *src2; | |
41 uint8_t *dest; | |
42 uint32_t bespitch,h,w; | |
43 | |
284 | 44 bespitch = (mga_vid_config.src_width + 31) & ~31; |
1 | 45 |
284 | 46 dest = vid_data + bespitch*y + x; |
4949 | 47 mem2agpcpy_pic(dest, image[0], width, height, bespitch, stride[0]); |
1 | 48 |
49 width/=2;height/=2;x/=2;y/=2; | |
50 | |
284 | 51 dest = vid_data + bespitch*mga_vid_config.src_height + bespitch*y + 2*x; |
1 | 52 src = image[1]; |
53 src2 = image[2]; | |
54 for(h=0; h < height; h++) | |
55 { | |
2625 | 56 #ifdef HAVE_MMX |
57 asm( | |
58 "xorl %%eax, %%eax \n\t" | |
59 "1: \n\t" | |
60 PREFETCH" 64(%1, %%eax) \n\t" | |
61 PREFETCH" 64(%2, %%eax) \n\t" | |
62 "movq (%1, %%eax), %%mm0 \n\t" | |
63 "movq 8(%1, %%eax), %%mm2 \n\t" | |
64 "movq %%mm0, %%mm1 \n\t" | |
65 "movq %%mm2, %%mm3 \n\t" | |
66 "movq (%2, %%eax), %%mm4 \n\t" | |
67 "movq 8(%2, %%eax), %%mm5 \n\t" | |
68 "punpcklbw %%mm4, %%mm0 \n\t" | |
69 "punpckhbw %%mm4, %%mm1 \n\t" | |
70 "punpcklbw %%mm5, %%mm2 \n\t" | |
71 "punpckhbw %%mm5, %%mm3 \n\t" | |
72 MOVNTQ" %%mm0, (%0, %%eax, 2) \n\t" | |
73 MOVNTQ" %%mm1, 8(%0, %%eax, 2) \n\t" | |
74 MOVNTQ" %%mm2, 16(%0, %%eax, 2) \n\t" | |
75 MOVNTQ" %%mm3, 24(%0, %%eax, 2) \n\t" | |
76 "addl $16, %%eax \n\t" | |
77 "cmpl %3, %%eax \n\t" | |
78 " jb 1b \n\t" | |
79 ::"r"(dest), "r"(src), "r"(src2), "r" (width-15) | |
80 : "memory", "%eax" | |
81 ); | |
82 for(w= (width&(~15)); w < width; w++) | |
83 { | |
84 dest[2*w+0] = src[w]; | |
85 dest[2*w+1] = src2[w]; | |
86 } | |
87 #else | |
1 | 88 for(w=0; w < width; w++) |
89 { | |
90 dest[2*w+0] = src[w]; | |
91 dest[2*w+1] = src2[w]; | |
92 } | |
2625 | 93 #endif |
1 | 94 dest += bespitch; |
284 | 95 src += stride[1]; |
96 src2+= stride[2]; | |
1 | 97 } |
2625 | 98 #ifdef HAVE_MMX |
99 asm( | |
100 EMMS" \n\t" | |
101 SFENCE" \n\t" | |
102 ::: "memory" | |
103 ); | |
104 #endif | |
1 | 105 } |
106 | |
107 static void | |
108 draw_slice_g400(uint8_t *image[], int stride[], int w,int h,int x,int y) | |
109 { | |
110 uint8_t *src; | |
111 uint8_t *dest; | |
112 uint32_t bespitch,bespitch2; | |
113 int i; | |
114 | |
115 bespitch = (mga_vid_config.src_width + 31) & ~31; | |
116 bespitch2 = bespitch/2; | |
117 | |
118 dest = vid_data + bespitch * y + x; | |
4949 | 119 mem2agpcpy_pic(dest, image[0], w, h, bespitch, stride[0]); |
1 | 120 |
121 w/=2;h/=2;x/=2;y/=2; | |
122 | |
123 dest = vid_data + bespitch*mga_vid_config.src_height + bespitch2 * y + x; | |
4949 | 124 mem2agpcpy_pic(dest, image[1], w, h, bespitch2, stride[1]); |
1 | 125 |
126 dest = vid_data + bespitch*mga_vid_config.src_height | |
127 + bespitch*mga_vid_config.src_height / 4 | |
128 + bespitch2 * y + x; | |
4949 | 129 mem2agpcpy_pic(dest, image[2], w, h, bespitch2, stride[2]); |
1 | 130 |
131 } | |
132 | |
133 static uint32_t | |
134 draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y) | |
135 { | |
4949 | 136 |
137 #if 0 | |
138 printf("vo: %p/%d %p/%d %p/%d %dx%d/%d;%d \n", | |
139 src[0],stride[0], | |
140 src[1],stride[1], | |
141 src[2],stride[2], | |
142 w,h,x,y); | |
143 #endif | |
144 | |
1 | 145 if (mga_vid_config.card_type == MGA_G200) |
146 draw_slice_g200(src,stride,w,h,x,y); | |
147 else | |
148 draw_slice_g400(src,stride,w,h,x,y); | |
149 return 0; | |
150 } | |
151 | |
152 static void | |
31 | 153 vo_mga_flip_page(void) |
1 | 154 { |
47 | 155 |
156 // printf("-- flip to %d --\n",mga_next_frame); | |
1 | 157 |
47 | 158 #if 1 |
159 ioctl(f,MGA_VID_FSEL,&mga_next_frame); | |
56 | 160 mga_next_frame=(mga_next_frame+1)%mga_vid_config.num_frames; |
47 | 161 vid_data=frames[mga_next_frame]; |
162 #endif | |
1 | 163 |
164 } | |
165 | |
166 | |
167 static void | |
168 write_frame_yuy2(uint8_t *y) | |
169 { | |
170 int len=2*mga_vid_config.src_width; | |
4949 | 171 uint32_t bespitch = (mga_vid_config.src_width + 31) & ~31; |
1 | 172 |
4949 | 173 mem2agpcpy_pic(vid_data, y, len, mga_vid_config.src_height, 2*bespitch, len); |
1 | 174 } |
175 | |
176 static uint32_t | |
177 draw_frame(uint8_t *src[]) | |
178 { | |
448
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
179 switch(mga_vid_config.format){ |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
180 case MGA_VID_FORMAT_YUY2: |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
181 case MGA_VID_FORMAT_UYVY: |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
182 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
|
183 } |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
184 return 0; |
1 | 185 } |
186 | |
187 static uint32_t | |
4971 | 188 get_image(mp_image_t *mpi){ |
189 uint32_t bespitch = (mga_vid_config.src_width + 31) & ~31; | |
190 uint32_t bespitch2 = bespitch/2; | |
191 // printf("mga: get_image() called\n"); | |
4975 | 192 if(mpi->type==MP_IMGTYPE_STATIC && mga_vid_config.num_frames>1) return VO_FALSE; // it is not static |
4971 | 193 if(mpi->flags&MP_IMGFLAG_READABLE) return VO_FALSE; // slow video ram |
194 // printf("width=%d vs. bespitch=%d, flags=0x%X \n",mpi->width,bespitch,mpi->flags); | |
195 if((mpi->width==bespitch) || | |
196 (mpi->flags&(MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH))){ | |
197 // we're lucky or codec accepts stride => ok, let's go! | |
198 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
199 mpi->planes[0]=vid_data; | |
200 mpi->planes[1]=vid_data + bespitch*mga_vid_config.src_height; | |
201 mpi->planes[2]=vid_data + bespitch*mga_vid_config.src_height | |
202 + bespitch*mga_vid_config.src_height / 4; | |
203 mpi->width=mpi->stride[0]=bespitch; | |
204 mpi->stride[1]=mpi->stride[2]=bespitch2; | |
205 } else { | |
206 mpi->planes[0]=vid_data; | |
207 mpi->width=bespitch; | |
208 mpi->stride[0]=mpi->width*(mpi->bpp/8); | |
209 } | |
210 mpi->flags|=MP_IMGFLAG_DIRECT; | |
211 // printf("mga: get_image() SUCCESS -> Direct Rendering ENABLED\n"); | |
212 return VO_TRUE; | |
213 } | |
214 return VO_FALSE; | |
215 } | |
216 | |
217 static uint32_t | |
1 | 218 query_format(uint32_t format) |
219 { | |
220 switch(format){ | |
221 case IMGFMT_YV12: | |
470 | 222 case IMGFMT_I420: |
223 case IMGFMT_IYUV: | |
1 | 224 case IMGFMT_YUY2: |
448
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
225 case IMGFMT_UYVY: |
1 | 226 // case IMGFMT_RGB|24: |
227 // case IMGFMT_BGR|24: | |
228 return 1; | |
229 } | |
230 return 0; | |
231 } | |
232 | |
4970 | 233 static uint32_t control(uint32_t request, void *data, ...) |
234 { | |
235 switch (request) { | |
236 case VOCTRL_QUERY_FORMAT: | |
237 return query_format(*((uint32_t*)data)); | |
4971 | 238 case VOCTRL_GET_IMAGE: |
239 return get_image(data); | |
4981 | 240 #ifdef VO_XMGA |
241 case VOCTRL_FULLSCREEN: | |
242 vo_x11_fullscreen(); | |
243 return VO_TRUE; | |
244 #endif | |
4970 | 245 } |
246 return VO_NOTIMPL; | |
247 } | |
248 | |
249 | |
56 | 250 static int mga_init(){ |
251 char *frame_mem; | |
252 | |
253 mga_vid_config.num_frames=4; | |
254 mga_vid_config.version=MGA_VID_VERSION; | |
255 if (ioctl(f,MGA_VID_CONFIG,&mga_vid_config)) | |
256 { | |
275 | 257 perror("Error in mga_vid_config ioctl()"); |
258 printf("Your mga_vid driver version is incompatible with this MPlayer version!\n"); | |
56 | 259 return -1; |
260 } | |
261 ioctl(f,MGA_VID_ON,0); | |
262 | |
263 frames[0] = (char*)mmap(0,mga_vid_config.frame_size*mga_vid_config.num_frames,PROT_WRITE,MAP_SHARED,f,0); | |
264 frames[1] = frames[0] + 1*mga_vid_config.frame_size; | |
265 frames[2] = frames[0] + 2*mga_vid_config.frame_size; | |
266 frames[3] = frames[0] + 3*mga_vid_config.frame_size; | |
267 mga_next_frame = 0; | |
268 vid_data = frames[mga_next_frame]; | |
269 | |
270 //clear the buffer | |
271 memset(frames[0],0x80,mga_vid_config.frame_size*mga_vid_config.num_frames); | |
272 | |
273 return 0; | |
274 | |
275 } | |
276 | |
1637 | 277 static int mga_uninit(){ |
278 ioctl( f,MGA_VID_OFF,0 ); | |
279 munmap(frames[0],mga_vid_config.frame_size*mga_vid_config.num_frames); | |
280 close(f); | |
281 } | |
4970 | 282 |
283 static uint32_t preinit(const char *arg) | |
284 { | |
285 return 0; | |
286 } | |
287 |