comparison libvo/vo_xvmc.c @ 14742:76d461a061df

Unified colorkey code for vo xv and vo xvmc. Made the code also more flexible. Colorkey drawing is now by default done as proposed by Marko Macek. Patch also approved by iive.
author al
date Sun, 20 Feb 2005 22:43:25 +0000
parents 1c277cafd3b1
children 30289c5f3cc6
comparison
equal deleted inserted replaced
14741:c29a660e8bd7 14742:76d461a061df
28 #include "xvmc_render.h" 28 #include "xvmc_render.h"
29 29
30 #include "sub.h" 30 #include "sub.h"
31 #include "aspect.h" 31 #include "aspect.h"
32 32
33 #include "subopt-helper.h"
34
33 #ifdef HAVE_NEW_GUI 35 #ifdef HAVE_NEW_GUI
34 #include "Gui/interface.h" 36 #include "Gui/interface.h"
35 #endif 37 #endif
36 38
37 //no chanse xinerama to be suported in near future 39 //no chanse xinerama to be suported in near future
46 48
47 extern int vo_directrendering; 49 extern int vo_directrendering;
48 extern int vo_verbose; 50 extern int vo_verbose;
49 51
50 static int benchmark; 52 static int benchmark;
51 static int busy_wait; 53 static int use_sleep;
52 static int use_queue; 54 static int use_queue;
55 static int xv_port_request = 0;
53 56
54 static int image_width,image_height; 57 static int image_width,image_height;
55 static uint32_t drwX,drwY; 58 static uint32_t drwX,drwY;
56
57 static XvPortID xv_port;
58
59 #define AUTO_COLORKEY 0
60 #define BACKGROUND_COLORKEY 1
61 #define AUTOPAINT_COLORKEY 2
62 #define MANUALFILL_COLORKEY 3
63 static int keycolor_handling;
64 static unsigned long keycolor;
65 59
66 #define NO_SUBPICTURE 0 60 #define NO_SUBPICTURE 0
67 #define OVERLAY_SUBPICTURE 1 61 #define OVERLAY_SUBPICTURE 1
68 #define BLEND_SUBPICTURE 2 62 #define BLEND_SUBPICTURE 2
69 #define BACKEND_SUBPICTURE 3 63 #define BACKEND_SUBPICTURE 3
191 185
192 XSync(mDisplay, False); 186 XSync(mDisplay, False);
193 return; 187 return;
194 } 188 }
195 //end of vo_xv shm/xvimage code 189 //end of vo_xv shm/xvimage code
196
197
198 static void init_keycolor(){
199 Atom xv_atom;
200 XvAttribute * attributes;
201 int colorkey;
202 int rez;
203 int attrib_count,i;
204
205 keycolor=2110;
206
207 if(keycolor_handling == AUTO_COLORKEY){
208 //XV_AUTOPING_COLORKEY doesn't work for XvMC yet(NVidia 43.63)
209 attributes = XvQueryPortAttributes(mDisplay, xv_port, &attrib_count);
210 if(attributes!=NULL){
211 for (i = 0; i < attrib_count; i++){
212 if (!strcmp(attributes[i].name, "XV_COLORKEY"))
213 {
214 xv_atom = XInternAtom(mDisplay, "XV_COLORKEY", False);
215 if(xv_atom!=None)
216 {
217 rez=XvGetPortAttribute(mDisplay,xv_port, xv_atom, &colorkey);
218 if(rez == Success){
219 keycolor = colorkey;
220 keycolor_handling = MANUALFILL_COLORKEY;
221 }
222 }
223 break;
224 }
225 }
226 XFree(attributes);
227 }
228 }
229 }
230
231 //from vo_xmga
232 static void mDrawColorKey(uint32_t x,uint32_t y, uint32_t w, uint32_t h)
233 {
234 if( (keycolor_handling != AUTOPAINT_COLORKEY) &&
235 (keycolor_handling != MANUALFILL_COLORKEY) )
236 return;
237
238 XSetBackground( mDisplay,vo_gc,0 );
239 XClearWindow( mDisplay,vo_window );
240
241 if(keycolor_handling == MANUALFILL_COLORKEY){
242 XSetForeground( mDisplay,vo_gc,keycolor );
243 XFillRectangle( mDisplay,vo_window,vo_gc,x,y,w,h);
244 }
245 XFlush( mDisplay );
246 }
247
248 190
249 static int xvmc_check_surface_format(uint32_t format, XvMCSurfaceInfo * surf_info){ 191 static int xvmc_check_surface_format(uint32_t format, XvMCSurfaceInfo * surf_info){
250 if ( format == IMGFMT_XVMC_IDCT_MPEG2 ){ 192 if ( format == IMGFMT_XVMC_IDCT_MPEG2 ){
251 if( surf_info->mc_type != (XVMC_IDCT|XVMC_MPEG_2) ) return -1; 193 if( surf_info->mc_type != (XVMC_IDCT|XVMC_MPEG_2) ) return -1;
252 if( surf_info->chroma_format != XVMC_CHROMA_FORMAT_420 ) return -1; 194 if( surf_info->chroma_format != XVMC_CHROMA_FORMAT_420 ) return -1;
348 { 290 {
349 if( width > mc_surf_list[s].max_width ) continue; 291 if( width > mc_surf_list[s].max_width ) continue;
350 if( height > mc_surf_list[s].max_height ) continue; 292 if( height > mc_surf_list[s].max_height ) continue;
351 if( xvmc_check_surface_format(format,&mc_surf_list[s])<0 ) continue; 293 if( xvmc_check_surface_format(format,&mc_surf_list[s])<0 ) continue;
352 //we have match! 294 //we have match!
295 /* respect the users wish */
296 if ( xv_port_request != 0 && xv_port_request != p )
297 {
298 continue;
299 }
353 300
354 if(!query){ 301 if(!query){
355 rez = XvGrabPort(mDisplay,p,CurrentTime); 302 rez = XvGrabPort(mDisplay,p,CurrentTime);
356 if(rez != Success){ 303 if(rez != Success){
357 if (verbose > 2) printf("vo_xvmc: Fail to grab port %ld\n",p); 304 if (verbose > 2) printf("vo_xvmc: Fail to grab port %ld\n",p);
399 346
400 static uint32_t preinit(const char *arg){ 347 static uint32_t preinit(const char *arg){
401 int xv_version,xv_release,xv_request_base,xv_event_base,xv_error_base; 348 int xv_version,xv_release,xv_request_base,xv_event_base,xv_error_base;
402 int mc_eventBase,mc_errorBase; 349 int mc_eventBase,mc_errorBase;
403 int mc_ver,mc_rev; 350 int mc_ver,mc_rev;
351 strarg_t ck_src_arg = { 0, NULL };
352 strarg_t ck_method_arg = { 0, NULL };
353 opt_t subopts [] =
354 {
355 /* name arg type arg var test */
356 { "port", OPT_ARG_INT, &xv_port_request, (opt_test_f)int_pos },
357 { "ck", OPT_ARG_STR, &ck_src_arg, xv_test_ck },
358 { "ck-method", OPT_ARG_STR, &ck_method_arg, xv_test_ckm },
359 { "benchmark", OPT_ARG_BOOL, &benchmark, NULL },
360 { "sleep", OPT_ARG_BOOL, &use_sleep, NULL },
361 { "queue", OPT_ARG_BOOL, &use_queue, NULL },
362 { NULL }
363 };
404 364
405 //Obtain display handler 365 //Obtain display handler
406 if (!vo_init()) return -1;//vo_xv 366 if (!vo_init()) return -1;//vo_xv
407 367
408 //XvMC is subdivision of XVideo 368 //XvMC is subdivision of XVideo
429 return -1; 389 return -1;
430 } 390 }
431 surface_render = NULL; 391 surface_render = NULL;
432 xv_port = 0; 392 xv_port = 0;
433 number_of_surfaces = 0; 393 number_of_surfaces = 0;
434 keycolor_handling = AUTO_COLORKEY;
435 subpicture_alloc = 0; 394 subpicture_alloc = 0;
436 395
437 benchmark = 0; //disable PutImageto allow faster display than screen refresh 396 benchmark = 0; //disable PutImageto allow faster display than screen refresh
438 busy_wait = 1; 397 use_sleep = 0;
439 use_queue = 0; 398 use_queue = 0;
440 if(arg) 399
441 while(*arg){ 400 /* parse suboptions */
442 if(strncmp(arg,"benchmark",9) == 0){ 401 if ( subopt_parse( arg, subopts ) != 0 )
443 arg+=9; 402 {
444 if(*arg == ':') arg++; 403 return -1;
445 benchmark = 1;//disable PutImageto allow faster display than screen refresh 404 }
446 continue; 405
447 } 406 xv_setup_colorkeyhandling( ck_method_arg.str, ck_src_arg.str );
448 if(strncmp(arg,"wait",4) == 0){
449 arg+=4;
450 if(*arg == ':') arg++;
451 busy_wait = 1;
452 continue;
453 }
454 if(strncmp(arg,"sleep",5) == 0){
455 arg+=5;
456 if(*arg == ':') arg++;
457 busy_wait = 0;
458 continue;
459 }
460 if(strncmp(arg,"queue",5) == 0){
461 arg+=5;
462 if(*arg == ':') arg++;
463 use_queue = 1;
464 continue;
465 }
466 break;
467 }
468 407
469 return 0; 408 return 0;
470 } 409 }
471 410
472 static uint32_t config(uint32_t width, uint32_t height, 411 static uint32_t config(uint32_t width, uint32_t height,
503 xvmc_free(); 442 xvmc_free();
504 }; 443 };
505 numblocks=((width+15)/16)*((height+15)/16); 444 numblocks=((width+15)/16)*((height+15)/16);
506 // Find Supported Surface Type 445 // Find Supported Surface Type
507 mode_id = xvmc_find_surface_by_format(format,width,height,&surface_info,0);//false=1 to grab port, not query 446 mode_id = xvmc_find_surface_by_format(format,width,height,&surface_info,0);//false=1 to grab port, not query
447 if ( mode_id == 0 )
448 {
449 return -1;
450 }
508 451
509 rez = XvMCCreateContext(mDisplay, xv_port,mode_id,width,height,XVMC_DIRECT,&ctx); 452 rez = XvMCCreateContext(mDisplay, xv_port,mode_id,width,height,XVMC_DIRECT,&ctx);
510 if( rez != Success ) return -1; 453 if( rez != Success ) return -1;
511 if( ctx.flags & XVMC_DIRECT ){ 454 if( ctx.flags & XVMC_DIRECT ){
512 printf("vo_xvmc: Allocated Direct Context\n"); 455 printf("vo_xvmc: Allocated Direct Context\n");
633 printf("vo_xvmc: OSD support by beckend rendering (fast)\n"); 576 printf("vo_xvmc: OSD support by beckend rendering (fast)\n");
634 printf("vo_xvmc: Pleace send feedback to configrm that it work,otherwise send bugreport!\n"); 577 printf("vo_xvmc: Pleace send feedback to configrm that it work,otherwise send bugreport!\n");
635 break; 578 break;
636 } 579 }
637 580
638 init_keycolor();// take keycolor value and choose method for handling it 581 //take keycolor value and choose method for handling it
582 if ( !vo_xv_init_colorkey() )
583 {
584 return -1; // bail out, colorkey setup failed
585 }
586
639 587
640 //taken from vo_xv 588 //taken from vo_xv
641 panscan_init(); 589 panscan_init();
642 590
643 aspect_save_orig(width,height); 591 aspect_save_orig(width,height);
706 depth=attribs.depth; 654 depth=attribs.depth;
707 if (depth != 15 && depth != 16 && depth != 24 && depth != 32) depth = 24; 655 if (depth != 15 && depth != 16 && depth != 24 && depth != 32) depth = 24;
708 XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo); 656 XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo);
709 657
710 xswa.background_pixel = 0; 658 xswa.background_pixel = 0;
711 if (keycolor_handling == BACKGROUND_COLORKEY) 659 if (xv_ck_info.method == CK_METHOD_BACKGROUND)
712 xswa.background_pixel = keycolor;// 2110; 660 xswa.background_pixel = xv_colorkey;
713 xswa.border_pixel = 0; 661 xswa.border_pixel = 0;
714 xswamask = CWBackPixel | CWBorderPixel; 662 xswamask = CWBackPixel | CWBorderPixel;
715 663
716 if ( WinID>=0 ){ 664 if ( WinID>=0 ){
717 vo_window = WinID ? ((Window)WinID) : mRootWin; 665 vo_window = WinID ? ((Window)WinID) : mRootWin;
1032 int status,rez; 980 int status,rez;
1033 rez = XvMCGetSurfaceStatus(mDisplay,srf,&status); 981 rez = XvMCGetSurfaceStatus(mDisplay,srf,&status);
1034 assert(rez==Success); 982 assert(rez==Success);
1035 if((status & XVMC_RENDERING) == 0) 983 if((status & XVMC_RENDERING) == 0)
1036 return;//surface is already complete 984 return;//surface is already complete
1037 if(!busy_wait){ 985 if(use_sleep){
1038 rez = XvMCFlushSurface(mDisplay, srf); 986 rez = XvMCFlushSurface(mDisplay, srf);
1039 assert(rez==Success); 987 assert(rez==Success);
1040 988
1041 do{ 989 do{
1042 usec_sleep(1000);//1ms (may be 20ms on linux) 990 usec_sleep(1000);//1ms (may be 20ms on linux)
1138 mp_msg(MSGT_VO,MSGL_V, "[xvmc-fs] dx: %d dy: %d dw: %d dh: %d\n",drwX,drwY,vo_dwidth,vo_dheight ); 1086 mp_msg(MSGT_VO,MSGL_V, "[xvmc-fs] dx: %d dy: %d dw: %d dh: %d\n",drwX,drwY,vo_dwidth,vo_dheight );
1139 } 1087 }
1140 } 1088 }
1141 if ( e & VO_EVENT_EXPOSE ) 1089 if ( e & VO_EVENT_EXPOSE )
1142 { 1090 {
1143 mDrawColorKey(drwX,drwY,vo_dwidth,vo_dheight); 1091 vo_xv_draw_colorkey(drwX,drwY,vo_dwidth,vo_dheight);
1144 if(p_render_surface_visible != NULL) 1092 if(p_render_surface_visible != NULL)
1145 XvMCPutSurface(mDisplay, p_render_surface_visible->p_surface,vo_window, 1093 XvMCPutSurface(mDisplay, p_render_surface_visible->p_surface,vo_window,
1146 0, 0, image_width, image_height, 1094 0, 0, image_width, image_height,
1147 drwX,drwY,vo_dwidth,vo_dheight, 1095 drwX,drwY,vo_dwidth,vo_dheight,
1148 3);//,p_render_surface_visible->display_flags);!! 1096 3);//,p_render_surface_visible->display_flags);!!