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