38
|
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
|
354
|
25 //#include "fastmemcpy.h"
|
38
|
26
|
|
27 #include "linux/keycodes.h"
|
|
28 #include "config.h"
|
|
29 #include "video_out.h"
|
|
30 #include "video_out_internal.h"
|
|
31 #include "yuv2rgb.h"
|
|
32
|
|
33 LIBVO_EXTERN( fsdga )
|
|
34
|
|
35 #include <X11/Xlib.h>
|
|
36 #include <X11/extensions/xf86dga.h>
|
|
37
|
|
38 #include "x11_common.h"
|
|
39
|
|
40 static vo_info_t vo_info =
|
|
41 {
|
|
42 "FullScreen DGA ( Direct Graphic Access )",
|
|
43 "fsdga",
|
|
44 "A'rpi/ESP-team & Andreas Ackermann <acki@acki-netz.de>",
|
|
45 ""
|
|
46 };
|
|
47
|
|
48 static int vo_dga_width; // bytes per line in framebuffer
|
|
49 static int vo_dga_vp_width; // visible pixels per line in framebuffer
|
|
50 static int vo_dga_vp_height; // visible lines in framebuffer
|
|
51 static int vo_dga_is_running = 0;
|
|
52 static int vo_dga_src_width; // width of video in pixels
|
|
53 static int vo_dga_src_height; // height of video in pixels
|
|
54 static int vo_dga_bpp; // bytes per pixel in framebuffer
|
|
55 static int vo_dga_src_offset=0; // offset in src
|
|
56 static int vo_dga_vp_offset=0; // offset in dest
|
|
57 static int vo_dga_bytes_per_line; // longwords per line to copy
|
|
58 static int vo_dga_src_skip; // bytes to skip after copying one line
|
|
59 // (not supported yet) in src
|
|
60 static int vo_dga_vp_skip; // dto. for dest
|
|
61 static int vo_dga_lines; // num of lines to copy
|
|
62 static int vo_dga_src_format;
|
|
63
|
|
64 static unsigned char *vo_dga_base;
|
|
65 static Display *vo_dga_dpy;
|
|
66
|
|
67
|
|
68 #if defined (HAVE_SSE) || defined (HAVE_3DNOW)
|
|
69 #define movntq "movntq" // use this for processors that have SSE or 3Dnow
|
|
70 #else
|
|
71 #define movntq "movq" // for MMX-only processors
|
|
72 #endif
|
|
73
|
|
74
|
|
75 #define rep_movsl(dest, src, numwords, d_add, count) \
|
|
76 __asm__ __volatile__( \
|
|
77 " \
|
|
78 xfer: \n\t\
|
|
79 movl %%edx, %%ecx \n\t \
|
|
80 cld\n\t \
|
|
81 rep\n\t \
|
|
82 movsl \n\t\
|
|
83 add %%eax, %%edi \n\t\
|
|
84 dec %%ebx \n\t\
|
|
85 jnz xfer \n\t\
|
|
86 " \
|
|
87 : \
|
|
88 : "a" (d_add), "b" (count), "S" (src), "D" (dest), "d" (numwords) \
|
|
89 : "memory" )
|
|
90
|
|
91 #if 0
|
|
92 : "S" (src), "D" (dest), "c" (numwords) \
|
|
93 movq (%%eax), %%mm0 \n\t \
|
|
94 add $64, %%edx \n\t \
|
|
95 movq 8(%%eax), %%mm1 \n\t \
|
|
96 add $64, %%eax \n\t \
|
|
97 movq -48(%%eax), %%mm2 \n\t \
|
|
98 movq %%mm0, -64(%%edx) \n\t \
|
|
99 movq -40(%%eax), %%mm3 \n\t \
|
|
100 movq %%mm1, -56(%%edx) \n\t \
|
|
101 movq -32(%%eax), %%mm4 \n\t \
|
|
102 movq %%mm2, -48(%%edx) \n\t \
|
|
103 movq -24(%%eax), %%mm5 \n\t \
|
|
104 movq %%mm3, -40(%%edx) \n\t \
|
|
105 movq -16(%%eax), %%mm6 \n\t \
|
|
106 movq %%mm4, -32(%%edx) \n\t \
|
|
107 movq -8(%%eax), %%mm7 \n\t \
|
|
108 movq %%mm5, -24(%%edx) \n\t \
|
|
109 movq %%mm6, -16(%%edx) \n\t \
|
|
110 dec %%ecx \n\t \
|
|
111 movq %%mm7, -8(%%edx) \n\t \
|
|
112 jnz xfer \n\t \
|
|
113
|
|
114 #endif
|
|
115
|
|
116 #define mmx_movsl(dest, src, numwords) \
|
|
117 __asm__ __volatile__( \
|
|
118 " \
|
|
119 \n\t \
|
|
120 xfer: \n\t \
|
|
121 movq (%%eax), %%mm0 \n\t \
|
|
122 add $64, %%edx \n\t \
|
|
123 movq 8(%%eax), %%mm1 \n\t \
|
|
124 add $64, %%eax \n\t \
|
|
125 movq -48(%%eax), %%mm2 \n\t \
|
|
126 movq %%mm0, -64(%%edx) \n\t \
|
|
127 movq -40(%%eax), %%mm3 \n\t \
|
|
128 movq %%mm1, -56(%%edx) \n\t \
|
|
129 movq -32(%%eax), %%mm4 \n\t \
|
|
130 movq %%mm2, -48(%%edx) \n\t \
|
|
131 movq -24(%%eax), %%mm5 \n\t \
|
|
132 movq %%mm3, -40(%%edx) \n\t \
|
|
133 movq -16(%%eax), %%mm6 \n\t \
|
|
134 movq %%mm4, -32(%%edx) \n\t \
|
|
135 movq -8(%%eax), %%mm7 \n\t \
|
|
136 movq %%mm5, -24(%%edx) \n\t \
|
|
137 movq %%mm6, -16(%%edx) \n\t \
|
|
138 dec %%ecx \n\t \
|
|
139 movq %%mm7, -8(%%edx) \n\t \
|
|
140 jnz xfer \n\t \
|
|
141 \
|
|
142 " \
|
|
143 : \
|
|
144 : "a" (src), "d" (dest), "c" (numwords) \
|
|
145 : "memory" )
|
|
146
|
|
147 // src <= eax
|
|
148 // dst <= edx
|
|
149 // num <= ecx
|
|
150
|
|
151 static uint32_t draw_frame( uint8_t *src[] ){
|
|
152
|
|
153 int vp_skip = vo_dga_vp_skip;
|
|
154 int lpl = vo_dga_bytes_per_line >> 2;
|
|
155 int numlines = vo_dga_lines;
|
|
156
|
|
157 char *s, *d;
|
|
158
|
|
159 if( vo_dga_src_format==IMGFMT_YV12 ){
|
|
160 // We'll never reach this point, because YV12 codecs always calls draw_slice
|
|
161 printf("vo_dga: draw_frame() doesn't support IMGFMT_YV12 (yet?)\n");
|
|
162 }else{
|
|
163 s = *src;
|
|
164 d = (&((char *)vo_dga_base)[vo_dga_vp_offset]);
|
|
165 rep_movsl(d, s, lpl, vo_dga_vp_skip, numlines );
|
|
166 }
|
|
167
|
|
168 return 0;
|
|
169 }
|
|
170
|
|
171 static void check_events(void)
|
|
172 {
|
|
173 int e=vo_x11_check_events(vo_dga_dpy);
|
|
174 }
|
|
175
|
|
176 static void flip_page( void ){
|
|
177 check_events();
|
|
178 // printf("vo_dga: In flippage\n");
|
|
179
|
|
180 }
|
|
181
|
|
182 static unsigned int pix_buf_y[4][2048];
|
|
183 static unsigned int pix_buf_uv[2][2048*2];
|
|
184 static int dga_srcypos=0;
|
|
185 static int dga_ypos=0;
|
|
186 static int dga_last_ypos=-1;
|
|
187 static unsigned int dga_xinc,dga_yinc,dga_xinc2;
|
|
188
|
|
189 static unsigned char clip_table[768];
|
|
190
|
|
191 static int yuvtab_2568[256];
|
|
192 static int yuvtab_3343[256];
|
|
193 static int yuvtab_0c92[256];
|
|
194 static int yuvtab_1a1e[256];
|
|
195 static int yuvtab_40cf[256];
|
|
196
|
|
197
|
|
198 static uint32_t draw_slice( uint8_t *srcptr[],int stride[],
|
|
199 int w,int h,int x,int y )
|
|
200 {
|
|
201
|
|
202 if(y==0){
|
|
203 dga_srcypos=-2*dga_yinc;
|
|
204 dga_ypos=-2;
|
|
205 dga_last_ypos=-2;
|
|
206 } // reset counters
|
|
207
|
|
208 while(1){
|
|
209 unsigned char *dest=vo_dga_base+(vo_dga_width * dga_ypos)*vo_dga_bpp;
|
|
210 int y0=2+(dga_srcypos>>16);
|
|
211 int y1=1+(dga_srcypos>>17);
|
|
212 int yalpha=(dga_srcypos&0xFFFF)>>8;
|
|
213 int yalpha1=yalpha^255;
|
|
214 int uvalpha=((dga_srcypos>>1)&0xFFFF)>>8;
|
|
215 int uvalpha1=uvalpha^255;
|
|
216 unsigned int *buf0=pix_buf_y[y0&3];
|
|
217 unsigned int *buf1=pix_buf_y[((y0+1)&3)];
|
|
218 unsigned int *uvbuf0=pix_buf_uv[y1&1];
|
|
219 unsigned int *uvbuf1=pix_buf_uv[(y1&1)^1];
|
|
220 int i;
|
|
221
|
|
222 if(y0>=y+h) break;
|
|
223
|
|
224 dga_ypos++; dga_srcypos+=dga_yinc;
|
|
225
|
|
226 if(dga_last_ypos!=y0){
|
|
227 unsigned char *src=srcptr[0]+(y0-y)*stride[0];
|
|
228 unsigned int xpos=0;
|
|
229 dga_last_ypos=y0;
|
|
230 // this loop should be rewritten in MMX assembly!!!!
|
|
231 for(i=0;i<vo_dga_vp_width;i++){
|
|
232 register unsigned int xx=xpos>>8;
|
|
233 register unsigned int xalpha=xpos&0xFF;
|
|
234 buf1[i]=(src[xx]*(xalpha^255)+src[xx+1]*xalpha);
|
|
235 xpos+=dga_xinc;
|
|
236 }
|
|
237 if(!(y0&1)){
|
|
238 unsigned char *src1=srcptr[1]+(y1-y/2)*stride[1];
|
|
239 unsigned char *src2=srcptr[2]+(y1-y/2)*stride[2];
|
|
240 xpos=0;
|
|
241 // this loop should be rewritten in MMX assembly!!!!
|
|
242 for(i=0;i<vo_dga_vp_width;i++){
|
|
243 register unsigned int xx=xpos>>8;
|
|
244 register unsigned int xalpha=xpos&0xFF;
|
|
245 uvbuf1[i]=(src1[xx]*(xalpha^255)+src1[xx+1]*xalpha);
|
|
246 uvbuf1[i+2048]=(src2[xx]*(xalpha^255)+src2[xx+1]*xalpha);
|
|
247 xpos+=dga_xinc2;
|
|
248 }
|
|
249 }
|
|
250 if(!y0) continue;
|
|
251 }
|
|
252
|
|
253 // this loop should be rewritten in MMX assembly!!!!
|
|
254 for(i=0;i<vo_dga_vp_width;i++){
|
|
255 // linear interpolation && yuv2rgb in a single step:
|
|
256 int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>16)];
|
|
257 int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>16);
|
|
258 int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>16);
|
|
259 dest[0]=clip_table[((Y + yuvtab_3343[U]) >>13)];
|
|
260 dest[1]=clip_table[((Y + yuvtab_0c92[V] + yuvtab_1a1e[U]) >>13)];
|
|
261 dest[2]=clip_table[((Y + yuvtab_40cf[V]) >>13)];
|
|
262 dest+=vo_dga_bpp;
|
|
263 }
|
|
264
|
|
265 }
|
|
266
|
|
267
|
|
268 return 0;
|
|
269 };
|
|
270
|
|
271 static void Terminate_Display_Process( void ){
|
|
272
|
|
273 printf("vo_dga: Terminating display process\n");
|
|
274 }
|
|
275
|
|
276 static const vo_info_t* get_info( void )
|
|
277 { return &vo_info; }
|
|
278
|
|
279 static uint32_t query_format( uint32_t format )
|
|
280 {
|
|
281 printf("vo_dga: query_format\n");
|
|
282
|
|
283 if( !vo_init() ) return 0; // Can't open X11
|
|
284 printf("Format: %lx\n", format);
|
|
285
|
|
286 if( format==IMGFMT_YV12 ) return 1;
|
|
287 if( ( format&IMGFMT_BGR_MASK )==IMGFMT_BGR &&
|
|
288 ( format&0xFF )==vo_depthonscreen ) return 1;
|
|
289 return 0;
|
|
290 }
|
|
291
|
|
292
|
|
293 static void
|
|
294 uninit(void)
|
|
295 {
|
|
296
|
|
297 vo_dga_is_running = 0;
|
|
298 printf("vo_dga: in uninit\n");
|
|
299 XUngrabPointer (vo_dga_dpy, CurrentTime);
|
|
300 XUngrabKeyboard (vo_dga_dpy, CurrentTime);
|
|
301 XF86DGADirectVideo (vo_dga_dpy, XDefaultScreen(vo_dga_dpy), 0);
|
|
302 XCloseDisplay(vo_dga_dpy);
|
|
303 }
|
|
304
|
|
305
|
|
306
|
|
307
|
|
308 static uint32_t init( uint32_t width, uint32_t height,
|
|
309 uint32_t d_width,uint32_t d_height,
|
|
310 uint32_t fullscreen,char *title,uint32_t format )
|
|
311 {
|
|
312
|
|
313 int bank, ram;
|
|
314 int x_off, y_off;
|
|
315
|
|
316 if( vo_dga_is_running )return -1;
|
|
317
|
|
318 if( !vo_init() ){
|
|
319 printf("vo_dga: vo_init() failed!\n");
|
|
320 return 0;
|
|
321 }
|
|
322
|
|
323 if((vo_dga_dpy = XOpenDisplay(0))==NULL)
|
|
324 {
|
|
325 printf ("vo_dga: Can't open display\n");
|
|
326 return 1;
|
|
327 }
|
|
328
|
|
329 XF86DGAGetVideo (vo_dga_dpy, XDefaultScreen(vo_dga_dpy),
|
|
330 (char **)&vo_dga_base, &vo_dga_width, &bank, &ram);
|
|
331 XF86DGAGetViewPortSize (vo_dga_dpy, XDefaultScreen (vo_dga_dpy),
|
|
332 &vo_dga_vp_width, &vo_dga_vp_height);
|
|
333
|
|
334
|
|
335 // do some more checkings here ...
|
|
336 if( format==IMGFMT_YV12 )
|
|
337 yuv2rgb_init( vo_depthonscreen, MODE_RGB );
|
|
338
|
|
339 vo_dga_src_format = format;
|
|
340 vo_dga_src_width = width;
|
|
341 vo_dga_src_height = height;
|
|
342 vo_dga_bpp = (vo_depthonscreen+7) >> 3;
|
|
343
|
|
344 printf("vo_dga: bytes/line: %d, screen res: %dx%d, depth: %d, base: %08x, bpp: %d\n",
|
|
345 vo_dga_width, vo_dga_vp_width,
|
|
346 vo_dga_vp_height, vo_depthonscreen, vo_dga_base,
|
|
347 vo_dga_bpp);
|
|
348 printf("vo_dga: video res: %dx%d\n", vo_dga_src_width, vo_dga_src_height);
|
|
349
|
|
350 if(vo_dga_src_width > vo_dga_vp_width ||
|
|
351 vo_dga_src_height > vo_dga_vp_height){
|
|
352 printf("vo_dga: Sorry, video larger than viewport is not yet supported!\n");
|
|
353 // ugly, do something nicer in the future ...
|
|
354 return 1;
|
|
355 }
|
|
356
|
|
357 x_off = (vo_dga_vp_width - vo_dga_src_width)>>1;
|
|
358 y_off = (vo_dga_vp_height - vo_dga_src_height)>>1;
|
|
359
|
|
360 vo_dga_bytes_per_line = vo_dga_src_width * vo_dga_bpp; // todo
|
|
361 vo_dga_lines = vo_dga_src_height; // todo
|
|
362
|
|
363
|
|
364 vo_dga_src_offset = 0;
|
|
365 vo_dga_vp_offset = (y_off * vo_dga_width + x_off ) * vo_dga_bpp;
|
|
366
|
|
367 vo_dga_vp_skip = (vo_dga_width - vo_dga_src_width) * vo_dga_bpp; // todo
|
|
368
|
|
369 printf("vo_dga: vp_off=%d, vp_skip=%d, bpl=%d\n",
|
|
370 vo_dga_vp_offset, vo_dga_vp_skip, vo_dga_bytes_per_line);
|
|
371
|
|
372
|
|
373
|
|
374 XF86DGASetViewPort (vo_dga_dpy, XDefaultScreen(vo_dga_dpy), 0, 0);
|
|
375 XF86DGADirectVideo (vo_dga_dpy, XDefaultScreen(vo_dga_dpy),
|
|
376 XF86DGADirectGraphics | XF86DGADirectMouse |
|
|
377 XF86DGADirectKeyb);
|
|
378
|
|
379 XGrabKeyboard (vo_dga_dpy, DefaultRootWindow(vo_dga_dpy), True,
|
|
380 GrabModeAsync,GrabModeAsync, CurrentTime);
|
|
381 XGrabPointer (vo_dga_dpy, DefaultRootWindow(vo_dga_dpy), True,
|
|
382 ButtonPressMask,GrabModeAsync, GrabModeAsync,
|
|
383 None, None, CurrentTime);
|
|
384
|
|
385 // now clear screen
|
|
386
|
|
387 memset(vo_dga_base, 0, vo_dga_width * vo_dga_vp_height * vo_dga_bpp);
|
|
388
|
|
389 dga_yinc=(vo_dga_src_height<<16)/vo_dga_vp_height;
|
|
390 dga_xinc=(vo_dga_src_width<<8)/vo_dga_vp_width;
|
|
391 dga_xinc2=dga_xinc>>1;
|
|
392
|
|
393 { int i;
|
|
394 for(i=0;i<256;i++){
|
|
395 clip_table[i]=0;
|
|
396 clip_table[i+256]=i;
|
|
397 clip_table[i+512]=255;
|
|
398 yuvtab_2568[i]=(0x2568*(i-16))+(256<<13);
|
|
399 yuvtab_3343[i]=0x3343*(i-128);
|
|
400 yuvtab_0c92[i]=-0x0c92*(i-128);
|
|
401 yuvtab_1a1e[i]=-0x1a1e*(i-128);
|
|
402 yuvtab_40cf[i]=0x40cf*(i-128);
|
|
403 }
|
|
404 }
|
|
405
|
|
406 vo_dga_is_running = 1;
|
|
407 return 0;
|
|
408 }
|
|
409
|
|
410 #if 0
|
|
411 int vo_dga_query_event(void){
|
|
412
|
|
413 XEvent myevent;
|
|
414 char text[10];
|
|
415 KeySym mykey;
|
|
416 int retval = 0;
|
|
417 int i;
|
|
418
|
|
419 if( vo_dga_is_running ){
|
|
420 if(XPending(vo_dga_dpy)>0)
|
|
421 {
|
|
422 XNextEvent(vo_dga_dpy, &myevent);
|
|
423 switch (myevent.type)
|
|
424 {
|
|
425 case ButtonPress:
|
|
426 /* Reaktion auf Knopfdruck ---> Textausgabe an der
|
|
427 Mauscursorposition */
|
|
428
|
|
429 retval = 'q';
|
|
430 break;
|
|
431 case KeyPress:
|
|
432 /* Reaktion auf Tastendruck --> Testen ob Taste == "q",
|
|
433 falls ja: Programmende */
|
|
434 i=XLookupString(&myevent, text, 10, &mykey, 0);
|
|
435
|
|
436 if (mykey&0xff00 != 0) mykey=mykey&0x00ff + 256;
|
|
437
|
|
438 switch ( mykey )
|
|
439 {
|
|
440 case wsLeft: retval=KEY_LEFT; break;
|
|
441 case wsRight: retval=KEY_RIGHT; break;
|
|
442 case wsUp: retval=KEY_UP; break;
|
|
443 case wsDown: retval=KEY_DOWN; break;
|
|
444 case wsSpace: retval=' '; break;
|
|
445 case wsEscape: retval=KEY_ESC; break;
|
|
446 case wsEnter: retval=KEY_ENTER; break;
|
|
447 case wsq:
|
|
448 case wsQ: retval='q'; break;
|
|
449 case wsp:
|
|
450 case wsP: retval='p'; break;
|
|
451 case wsMinus:
|
|
452 case wsGrayMinus: retval='-'; break;
|
|
453 case wsPlus:
|
|
454 case wsGrayPlus: retval='+'; break;
|
|
455 }
|
|
456 break;
|
|
457 }
|
|
458 }
|
|
459 }
|
|
460 return retval;
|
|
461 }
|
|
462 #endif
|
|
463
|
|
464
|
|
465
|
|
466
|
|
467
|
|
468
|