Mercurial > mplayer.hg
comparison libvo/vo_dga.c @ 13:36314c7bda8d
initial version
author | arpi_esp |
---|---|
date | Tue, 27 Feb 2001 01:08:44 +0000 |
parents | |
children | 1fc618eba830 |
comparison
equal
deleted
inserted
replaced
12:7400af1c6d44 | 13:36314c7bda8d |
---|---|
1 #define DISP | |
2 | |
3 /* | |
4 * video_out_dga.c, X11 interface | |
5 * | |
6 * | |
7 * Copyright ( C ) 2001, Andreas Ackermann. All Rights Reserved. | |
8 * | |
9 * <acki@acki-netz.de> | |
10 * | |
11 * note well: | |
12 * | |
13 * o this is alpha | |
14 * o covers only common video card formats | |
15 * o works only on intel architectures | |
16 * | |
17 */ | |
18 | |
19 | |
20 | |
21 #include <stdio.h> | |
22 #include <stdlib.h> | |
23 #include <string.h> | |
24 | |
25 | |
26 #include "linux/keycodes.h" | |
27 #include "config.h" | |
28 #include "video_out.h" | |
29 #include "video_out_internal.h" | |
30 #include "yuv2rgb.h" | |
31 | |
32 LIBVO_EXTERN( dga ) | |
33 | |
34 #include <X11/Xlib.h> | |
35 #include <X11/extensions/xf86dga.h> | |
36 | |
37 | |
38 static vo_info_t vo_info = | |
39 { | |
40 "DGA ( Direct Graphic Access )", | |
41 "dga", | |
42 "Andreas Ackermann <acki@acki-netz.de>", | |
43 "" | |
44 }; | |
45 | |
46 int vo_dga_width; // bytes per line in framebuffer | |
47 int vo_dga_vp_width; // visible pixels per line in framebuffer | |
48 int vo_dga_vp_height; // visible lines in framebuffer | |
49 int vo_dga_is_running = 0; | |
50 int vo_dga_src_width; // width of video in pixels | |
51 int vo_dga_src_height; // height of video in pixels | |
52 int vo_dga_bpp; // bytes per pixel in framebuffer | |
53 int vo_dga_src_offset=0; // offset in src | |
54 int vo_dga_vp_offset=0; // offset in dest | |
55 int vo_dga_bytes_per_line; // longwords per line to copy | |
56 int vo_dga_src_skip; // bytes to skip after copying one line | |
57 // (not supported yet) in src | |
58 int vo_dga_vp_skip; // dto. for dest | |
59 int vo_dga_lines; // num of lines to copy | |
60 int vo_dga_src_format; | |
61 | |
62 unsigned char *vo_dga_base; | |
63 Display *vo_dga_dpy; | |
64 | |
65 | |
66 extern void vo_decoration( Display * vo_Display,Window w,int d ); | |
67 | |
68 #include "mmx.h" | |
69 | |
70 #if defined (HAVE_SSE) || defined (HAVE_3DNOW) | |
71 #define movntq "movntq" // use this for processors that have SSE or 3Dnow | |
72 #else | |
73 #define movntq "movq" // for MMX-only processors | |
74 #endif | |
75 | |
76 | |
77 #define rep_movsl(dest, src, numwords, d_add, count) \ | |
78 __asm__ __volatile__( \ | |
79 " \ | |
80 xfer: \n\t\ | |
81 movl %%edx, %%ecx \n\t \ | |
82 cld\n\t \ | |
83 rep\n\t \ | |
84 movsl \n\t\ | |
85 add %%eax, %%edi \n\t\ | |
86 dec %%ebx \n\t\ | |
87 jnz xfer \n\t\ | |
88 " \ | |
89 : \ | |
90 : "a" (d_add), "b" (count), "S" (src), "D" (dest), "d" (numwords) \ | |
91 : "memory" ) | |
92 | |
93 #if 0 | |
94 : "S" (src), "D" (dest), "c" (numwords) \ | |
95 movq (%%eax), %%mm0 \n\t \ | |
96 add $64, %%edx \n\t \ | |
97 movq 8(%%eax), %%mm1 \n\t \ | |
98 add $64, %%eax \n\t \ | |
99 movq -48(%%eax), %%mm2 \n\t \ | |
100 movq %%mm0, -64(%%edx) \n\t \ | |
101 movq -40(%%eax), %%mm3 \n\t \ | |
102 movq %%mm1, -56(%%edx) \n\t \ | |
103 movq -32(%%eax), %%mm4 \n\t \ | |
104 movq %%mm2, -48(%%edx) \n\t \ | |
105 movq -24(%%eax), %%mm5 \n\t \ | |
106 movq %%mm3, -40(%%edx) \n\t \ | |
107 movq -16(%%eax), %%mm6 \n\t \ | |
108 movq %%mm4, -32(%%edx) \n\t \ | |
109 movq -8(%%eax), %%mm7 \n\t \ | |
110 movq %%mm5, -24(%%edx) \n\t \ | |
111 movq %%mm6, -16(%%edx) \n\t \ | |
112 dec %%ecx \n\t \ | |
113 movq %%mm7, -8(%%edx) \n\t \ | |
114 jnz xfer \n\t \ | |
115 | |
116 #endif | |
117 | |
118 #define mmx_movsl(dest, src, numwords) \ | |
119 __asm__ __volatile__( \ | |
120 " \ | |
121 \n\t \ | |
122 xfer: \n\t \ | |
123 movq (%%eax), %%mm0 \n\t \ | |
124 add $64, %%edx \n\t \ | |
125 movq 8(%%eax), %%mm1 \n\t \ | |
126 add $64, %%eax \n\t \ | |
127 movq -48(%%eax), %%mm2 \n\t \ | |
128 movq %%mm0, -64(%%edx) \n\t \ | |
129 movq -40(%%eax), %%mm3 \n\t \ | |
130 movq %%mm1, -56(%%edx) \n\t \ | |
131 movq -32(%%eax), %%mm4 \n\t \ | |
132 movq %%mm2, -48(%%edx) \n\t \ | |
133 movq -24(%%eax), %%mm5 \n\t \ | |
134 movq %%mm3, -40(%%edx) \n\t \ | |
135 movq -16(%%eax), %%mm6 \n\t \ | |
136 movq %%mm4, -32(%%edx) \n\t \ | |
137 movq -8(%%eax), %%mm7 \n\t \ | |
138 movq %%mm5, -24(%%edx) \n\t \ | |
139 movq %%mm6, -16(%%edx) \n\t \ | |
140 dec %%ecx \n\t \ | |
141 movq %%mm7, -8(%%edx) \n\t \ | |
142 jnz xfer \n\t \ | |
143 \ | |
144 " \ | |
145 : \ | |
146 : "a" (src), "d" (dest), "c" (numwords) \ | |
147 : "memory" ) | |
148 | |
149 // src <= eax | |
150 // dst <= edx | |
151 // num <= ecx | |
152 | |
153 static uint32_t draw_frame( uint8_t *src[] ){ | |
154 | |
155 int vp_skip = vo_dga_vp_skip; | |
156 int lpl = vo_dga_bytes_per_line >> 2; | |
157 int numlines = vo_dga_lines; | |
158 | |
159 char *s, *d; | |
160 | |
161 if( vo_dga_src_format==IMGFMT_YV12 ){ | |
162 // We'll never reach this point, because YV12 codecs always calls draw_slice | |
163 printf("vo_dga: draw_frame() doesn't support IMGFMT_YV12 (yet?)\n"); | |
164 }else{ | |
165 s = *src; | |
166 d = (&((char *)vo_dga_base)[vo_dga_vp_offset]); | |
167 rep_movsl(d, s, lpl, vo_dga_vp_skip, numlines ); | |
168 } | |
169 | |
170 return 0; | |
171 } | |
172 | |
173 static void flip_page( void ){ | |
174 | |
175 // printf("vo_dga: In flippage\n"); | |
176 | |
177 } | |
178 | |
179 static uint32_t draw_slice( uint8_t *src[],int stride[], | |
180 int w,int h,int x,int y ) | |
181 { | |
182 // printf("vo_dga: draw_slice() not implemented (yet?)\n"); | |
183 | |
184 yuv2rgb( vo_dga_base + vo_dga_vp_offset + | |
185 (vo_dga_width * y +x) * vo_dga_bpp, | |
186 src[0], src[1], src[2], | |
187 w,h, vo_dga_width * vo_dga_bpp, | |
188 stride[0],stride[1] ); | |
189 return 0; | |
190 | |
191 | |
192 return 0; | |
193 }; | |
194 | |
195 static void Terminate_Display_Process( void ){ | |
196 | |
197 printf("vo_dga: Terminating display process\n"); | |
198 } | |
199 | |
200 static const vo_info_t* get_info( void ) | |
201 { return &vo_info; } | |
202 | |
203 static uint32_t query_format( uint32_t format ) | |
204 { | |
205 printf("vo_dga: query_format\n"); | |
206 | |
207 if( !vo_init() ) return 0; // Can't open X11 | |
208 printf("Format: %lx\n", format); | |
209 | |
210 if( format==IMGFMT_YV12 ) return 1; | |
211 if( ( format&IMGFMT_BGR_MASK )==IMGFMT_BGR && | |
212 ( format&0xFF )==vo_depthonscreen ) return 1; | |
213 return 0; | |
214 } | |
215 | |
216 | |
217 static void | |
218 uninit(void) | |
219 { | |
220 | |
221 vo_dga_is_running = 0; | |
222 printf("vo_dga: in uninit\n"); | |
223 XUngrabPointer (vo_dga_dpy, CurrentTime); | |
224 XUngrabKeyboard (vo_dga_dpy, CurrentTime); | |
225 XF86DGADirectVideo (vo_dga_dpy, XDefaultScreen(vo_dga_dpy), 0); | |
226 XCloseDisplay(vo_dga_dpy); | |
227 } | |
228 | |
229 | |
230 | |
231 | |
232 static uint32_t init( uint32_t width, uint32_t height, | |
233 uint32_t d_width,uint32_t d_height, | |
234 uint32_t fullscreen,char *title,uint32_t format ) | |
235 { | |
236 | |
237 int bank, ram; | |
238 int x_off, y_off; | |
239 | |
240 if( vo_dga_is_running )return -1; | |
241 | |
242 if( !vo_init() ){ | |
243 printf("vo_dga: vo_init() failed!\n"); | |
244 return 0; | |
245 } | |
246 | |
247 if((vo_dga_dpy = XOpenDisplay(0))==NULL) | |
248 { | |
249 printf ("vo_dga: Can't open display\n"); | |
250 return 1; | |
251 } | |
252 | |
253 XF86DGAGetVideo (vo_dga_dpy, XDefaultScreen(vo_dga_dpy), | |
254 (char **)&vo_dga_base, &vo_dga_width, &bank, &ram); | |
255 XF86DGAGetViewPortSize (vo_dga_dpy, XDefaultScreen (vo_dga_dpy), | |
256 &vo_dga_vp_width, &vo_dga_vp_height); | |
257 | |
258 | |
259 // do some more checkings here ... | |
260 if( format==IMGFMT_YV12 ) | |
261 yuv2rgb_init( vo_depthonscreen, MODE_RGB ); | |
262 | |
263 vo_dga_src_format = format; | |
264 vo_dga_src_width = width; | |
265 vo_dga_src_height = height; | |
266 vo_dga_bpp = (vo_depthonscreen+7) >> 3; | |
267 | |
268 printf("vo_dga: bytes/line: %d, screen res: %dx%d, depth: %d, base: %08x, bpp: %d\n", | |
269 vo_dga_width, vo_dga_vp_width, | |
270 vo_dga_vp_height, vo_depthonscreen, vo_dga_base, | |
271 vo_dga_bpp); | |
272 printf("vo_dga: video res: %dx%d\n", vo_dga_src_width, vo_dga_src_height); | |
273 | |
274 if(vo_dga_src_width > vo_dga_vp_width || | |
275 vo_dga_src_height > vo_dga_vp_height){ | |
276 printf("vo_dga: Sorry, video larger than viewport is not yet supported!\n"); | |
277 // ugly, do something nicer in the future ... | |
278 return 1; | |
279 } | |
280 | |
281 x_off = (vo_dga_vp_width - vo_dga_src_width)>>1; | |
282 y_off = (vo_dga_vp_height - vo_dga_src_height)>>1; | |
283 | |
284 vo_dga_bytes_per_line = vo_dga_src_width * vo_dga_bpp; // todo | |
285 vo_dga_lines = vo_dga_src_height; // todo | |
286 | |
287 | |
288 vo_dga_src_offset = 0; | |
289 vo_dga_vp_offset = (y_off * vo_dga_width + x_off ) * vo_dga_bpp; | |
290 | |
291 vo_dga_vp_skip = (vo_dga_width - vo_dga_src_width) * vo_dga_bpp; // todo | |
292 | |
293 printf("vo_dga: vp_off=%d, vp_skip=%d, bpl=%d\n", | |
294 vo_dga_vp_offset, vo_dga_vp_skip, vo_dga_bytes_per_line); | |
295 | |
296 | |
297 | |
298 XF86DGASetViewPort (vo_dga_dpy, XDefaultScreen(vo_dga_dpy), 0, 0); | |
299 XF86DGADirectVideo (vo_dga_dpy, XDefaultScreen(vo_dga_dpy), | |
300 XF86DGADirectGraphics | XF86DGADirectMouse | | |
301 XF86DGADirectKeyb); | |
302 | |
303 XGrabKeyboard (vo_dga_dpy, DefaultRootWindow(vo_dga_dpy), True, | |
304 GrabModeAsync,GrabModeAsync, CurrentTime); | |
305 XGrabPointer (vo_dga_dpy, DefaultRootWindow(vo_dga_dpy), True, | |
306 ButtonPressMask,GrabModeAsync, GrabModeAsync, | |
307 None, None, CurrentTime); | |
308 | |
309 // now clear screen | |
310 | |
311 memset(vo_dga_base, 0, vo_dga_width * vo_dga_vp_height * vo_dga_bpp); | |
312 | |
313 vo_dga_is_running = 1; | |
314 return 0; | |
315 } | |
316 | |
317 | |
318 int vo_dga_query_event(void){ | |
319 | |
320 XEvent myevent; | |
321 char text[10]; | |
322 KeySym mykey; | |
323 int retval = 0; | |
324 int i; | |
325 | |
326 if( vo_dga_is_running ){ | |
327 if(XPending(vo_dga_dpy)>0) | |
328 { | |
329 XNextEvent(vo_dga_dpy, &myevent); | |
330 switch (myevent.type) | |
331 { | |
332 case ButtonPress: | |
333 /* Reaktion auf Knopfdruck ---> Textausgabe an der | |
334 Mauscursorposition */ | |
335 | |
336 retval = 'q'; | |
337 break; | |
338 case KeyPress: | |
339 /* Reaktion auf Tastendruck --> Testen ob Taste == "q", | |
340 falls ja: Programmende */ | |
341 i=XLookupString(&myevent, text, 10, &mykey, 0); | |
342 | |
343 if (mykey&0xff00 != 0) mykey=mykey&0x00ff + 256; | |
344 | |
345 switch ( mykey ) | |
346 { | |
347 case wsLeft: retval=KEY_LEFT; break; | |
348 case wsRight: retval=KEY_RIGHT; break; | |
349 case wsUp: retval=KEY_UP; break; | |
350 case wsDown: retval=KEY_DOWN; break; | |
351 case wsSpace: retval=' '; break; | |
352 case wsEscape: retval=KEY_ESC; break; | |
353 case wsEnter: retval=KEY_ENTER; break; | |
354 case wsq: | |
355 case wsQ: retval='q'; break; | |
356 case wsp: | |
357 case wsP: retval='p'; break; | |
358 case wsMinus: | |
359 case wsGrayMinus: retval='-'; break; | |
360 case wsPlus: | |
361 case wsGrayPlus: retval='+'; break; | |
362 } | |
363 break; | |
364 } | |
365 } | |
366 } | |
367 return retval; | |
368 } | |
369 | |
370 | |
371 | |
372 | |
373 | |
374 |