comparison libvo/vo_directfb.c @ 6717:9d34c286f0ba

Patch by Jiri Svoboda: -should not fail if keyboard not present -preparation for vsync flipping -card capabilities should be reported better at query format
author atmos4
date Fri, 12 Jul 2002 10:27:08 +0000
parents ae3cfbfc8e3f
children 447ee5862f5d
comparison
equal deleted inserted replaced
6716:c9e526d4f60e 6717:9d34c286f0ba
162 int uyvy; 162 int uyvy;
163 int brightness; 163 int brightness;
164 int saturation; 164 int saturation;
165 int contrast; 165 int contrast;
166 int hue; 166 int hue;
167 int hwscale;
167 } videolayercaps; 168 } videolayercaps;
168 // workabout for DirectFB bug 169 // workabout for DirectFB bug
169 static int buggyYV12BitBlt=0; 170 static int buggyYV12BitBlt=0;
170 static int memcpyBitBlt=0; 171 static int memcpyBitBlt=0;
172 //
173 static int hwstretchblit=0;
171 #define DIRECTRENDER 174 #define DIRECTRENDER
172 #ifdef DIRECTRENDER 175 #ifdef DIRECTRENDER
173 static int dr_enabled=0; 176 static int dr_enabled=0;
174 static int framelocked=0; 177 static int framelocked=0;
178 #endif
179 #define FLIPPING
180 #ifdef FLIPPING
181 static int do_flipping=0; // turn (on) off flipping - prepared for cmd line switch
182 static int wait_vsync_after_flip=0;
183 static int flipping=0; // flipping is active
184 static int invram=0; // backbuffer in video memory
185 static int blitperformed=0; // in case of temporary frame we will blit before drawing osd
175 #endif 186 #endif
176 // primary & frame stuff 187 // primary & frame stuff
177 static int frameallocated=0; 188 static int frameallocated=0;
178 static int primaryallocated=0; 189 static int primaryallocated=0;
179 190
191 modes[index].valid=1; 202 modes[index].valid=1;
192 modes[index].width=width; 203 modes[index].width=width;
193 modes[index].height=height; 204 modes[index].height=height;
194 modes[index].overx=overx; 205 modes[index].overx=overx;
195 modes[index].overy=overy; 206 modes[index].overy=overy;
207 if (verbose) printf("DirectFB: Mode added %i %i %i\n",width,height,bpp);
196 } 208 }
197 if ((modes[index].overy<0)||(modes[index].overx<0)) we_are_under=1; // stored mode is smaller than req mode 209 if ((modes[index].overy<0)||(modes[index].overx<0)) we_are_under=1; // stored mode is smaller than req mode
198 if (abs(overx*overy)<abs(modes[index].overx * modes[index].overy)) closer=1; // current mode is closer to desired res 210 if (abs(overx*overy)<abs(modes[index].overx * modes[index].overy)) closer=1; // current mode is closer to desired res
199 if ((overx>=0)&&(overy>=0)) over=1; // current mode is bigger or equaul to desired res 211 if ((overx>=0)&&(overy>=0)) over=1; // current mode is bigger or equaul to desired res
200 if ((closer && (over || we_are_under)) || (we_are_under && over)) { 212 if ((closer && (over || we_are_under)) || (we_are_under && over)) {
201 modes[index].valid=1; 213 modes[index].valid=1;
202 modes[index].width=width; 214 modes[index].width=width;
203 modes[index].height=height; 215 modes[index].height=height;
204 modes[index].overx=overx; 216 modes[index].overx=overx;
205 modes[index].overy=overy; 217 modes[index].overy=overy;
206 if (verbose) printf("DirectFB:Better mode added %i %i %i\n",width,height,bpp); 218 if (verbose) printf("DirectFB: Better mode added %i %i %i\n",width,height,bpp);
207 }; 219 };
208 220
209 return DFENUM_OK; 221 return DFENUM_OK;
210 } 222 }
211 223
236 #endif 248 #endif
237 249
238 if (caps & DLCAPS_FLICKER_FILTERING) 250 if (caps & DLCAPS_FLICKER_FILTERING)
239 printf( " - Supports flicker filtering.\n" ); 251 printf( " - Supports flicker filtering.\n" );
240 252
253 /* renamed in dfb v. 0.9.13
241 if (caps & DLCAPS_INTERLACED_VIDEO) 254 if (caps & DLCAPS_INTERLACED_VIDEO)
242 printf( " - Can natively display interlaced video.\n" ); 255 printf( " - Can natively display interlaced video.\n" );
243 256 */
244 if (caps & DLCAPS_OPACITY) 257 if (caps & DLCAPS_OPACITY)
245 printf( " - Supports blending based on global alpha factor.\n" ); 258 printf( " - Supports blending based on global alpha factor.\n" );
246 259
247 if (caps & DLCAPS_SCREEN_LOCATION) 260 if (caps & DLCAPS_SCREEN_LOCATION)
248 printf( " - Can be positioned on the screen.\n" ); 261 printf( " - Can be positioned on the screen.\n" );
287 300
288 if (verbose) printf("DirectFB: Preinit entered\n"); 301 if (verbose) printf("DirectFB: Preinit entered\n");
289 302
290 DFBCHECK (DirectFBInit (NULL,NULL)); 303 DFBCHECK (DirectFBInit (NULL,NULL));
291 304
292 if ((directfb_major_version >= 0) && 305 if (!((directfb_major_version <= 0) &&
293 (directfb_minor_version >= 9) && 306 (directfb_minor_version <= 9) &&
294 (directfb_micro_version >= 7)) 307 (directfb_micro_version < 7)))
295 { 308 {
296 if (!fb_dev_name && !(fb_dev_name = getenv("FRAMEBUFFER"))) fb_dev_name = "/dev/fb0"; 309 if (!fb_dev_name && !(fb_dev_name = getenv("FRAMEBUFFER"))) fb_dev_name = "/dev/fb0";
297 DFBCHECK (DirectFBSetOption ("fbdev",fb_dev_name)); 310 DFBCHECK (DirectFBSetOption ("fbdev",fb_dev_name));
298 } 311 }
299 312
300 // disable YV12 for dfb until 0.9.11 - there is a bug in dfb! should be revised with every dfb version until bug is fixed in dfb. 313 // use own bitblt for YV12 beacuse bug in dfb till 0.9.11
301 if ((directfb_major_version <= 0) && 314 if ((directfb_major_version <= 0) &&
302 (directfb_minor_version <= 9) && 315 (directfb_minor_version <= 9) &&
303 (directfb_micro_version <= 11)) { 316 (directfb_micro_version <= 11)) {
304 buggyYV12BitBlt=1; 317 buggyYV12BitBlt=1;
305 if (verbose) printf("DirectFB: Buggy YV12BitBlt!\n"); 318 if (verbose) printf("DirectFB: Buggy YV12BitBlt!\n");
306 } 319 }
307 320
321 #ifdef FLIPPING
322 // activate flipping from release 0.9.11
323 if ((directfb_major_version <= 0) &&
324 (directfb_minor_version <= 9) &&
325 (directfb_micro_version <= 10)) {
326 do_flipping=0;
327 } else {
328 // (de)activated by default - should be overwritten by cmd line option
329 // do_flipping=1;
330 }
331 // wait for vsync if ver <0.9.13
332 if ((directfb_major_version <= 0) &&
333 (directfb_minor_version <= 9) &&
334 (directfb_micro_version <= 12)) {
335 wait_vsync_after_flip=1;
336 if (verbose) printf("DirectFB: Manual wait for vsync enabled!\n");
337 } else {
338 wait_vsync_after_flip=0;
339 }
340 #endif
341
308 // uncomment this if you do not wish to create a new vt for DirectFB 342 // uncomment this if you do not wish to create a new vt for DirectFB
309 DFBCHECK (DirectFBSetOption ("no-vt-switch","")); 343 // DFBCHECK (DirectFBSetOption ("no-vt-switch",""));
310 344
311 // uncomment this if you want to allow vt switching 345 // uncomment this if you want to allow vt switching
312 DFBCHECK (DirectFBSetOption ("vt-switching","")); 346 // DFBCHECK (DirectFBSetOption ("vt-switching",""));
313 #ifdef HAVE_DIRECTFB099 347 #ifdef HAVE_DIRECTFB099
314 // uncomment this if you want to hide gfx cursor (req dfb >=0.9.9) 348 // uncomment this if you want to hide gfx cursor (req dfb >=0.9.9)
315 DFBCHECK (DirectFBSetOption ("no-cursor","")); 349 DFBCHECK (DirectFBSetOption ("no-cursor",""));
316 #endif 350 #endif
317 351
330 // no videolayer found 364 // no videolayer found
331 // printf( "\nNo additional layers have been found.\n" ); 365 // printf( "\nNo additional layers have been found.\n" );
332 videolayeractive=0; 366 videolayeractive=0;
333 367
334 } else { 368 } else {
369 // just to be sure that layer is hidden during config
370 videolayer->SetOpacity(videolayer,0);
335 371
336 // there is an additional layer so test it for YUV formats 372 // there is an additional layer so test it for YUV formats
337 // some videolayers support RGB formats - not used now 373 // some videolayers support RGB formats - not used now
338 if (verbose) printf("DirectFB: Testing videolayer caps\n"); 374 if (verbose) printf("DirectFB: Testing videolayer caps\n");
339 375
408 videolayercaps.saturation=1; 444 videolayercaps.saturation=1;
409 } else { 445 } else {
410 videolayercaps.saturation=0; 446 videolayercaps.saturation=0;
411 }; 447 };
412 448
449 // test if layer can change size/position
450 if (caps & DLCAPS_SCREEN_LOCATION) {
451 videolayercaps.hwscale=1;
452 } else {
453 videolayercaps.hwscale=0;
454 };
455
413 456
414 } 457 }
415 458
416 459
417 // is there a working yuv ? if no we will not use videolayer 460 // is there a working yuv ? if no we will not use videolayer
423 } else { 466 } else {
424 videolayerpresent=1; 467 videolayerpresent=1;
425 }; 468 };
426 } 469 }
427 470
471 // check generic card capabilities (for hw scaling)
472 {
473 DFBCardCapabilities caps;
474 DFBCHECK (dfb->GetCardCapabilities(dfb,&caps));
475 if (caps.acceleration_mask & DFXL_STRETCHBLIT) hwstretchblit=1; else hwstretchblit=0;
476 if (verbose) printf("DirectFB: Card supports hw stretch blit\n");
477 }
478
428 // just look at RGB things for main layer 479 // just look at RGB things for main layer
429 modes[0].valid=0; 480 modes[0].valid=0;
430 modes[1].valid=0; 481 modes[1].valid=0;
431 modes[2].valid=0; 482 modes[2].valid=0;
432 modes[3].valid=0; 483 modes[3].valid=0;
433 DFBCHECK (dfb->EnumVideoModes(dfb,enum_modes_callback,NULL)); 484 DFBCHECK (dfb->EnumVideoModes(dfb,enum_modes_callback,NULL));
434 485
486
435 /* 487 /*
436 * (Get keyboard) 488 * (Get keyboard)
437 */ 489 */
438 DFBCHECK (dfb->GetInputDevice (dfb, DIDID_KEYBOARD, &keyboard)); 490 ret = dfb->GetInputDevice (dfb, DIDID_KEYBOARD, &keyboard);
491
492 if (ret==DFB_OK) {
493 if (verbose) {
494 printf("DirectFB: Keyboard init OK\n");
495 }
496 } else {
497 keyboard = NULL;
498 printf("DirectFB: Keyboard init FAILED\n");
499 }
439 500
440 /* 501 /*
441 * Create an input buffer for the keyboard. 502 * Create an input buffer for the keyboard.
442 */ 503 */
443 #ifdef HAVE_DIRECTFB099 504 #ifdef HAVE_DIRECTFB099
444 DFBCHECK (keyboard->CreateEventBuffer (keyboard, &buffer)); 505 if (keyboard) DFBCHECK (keyboard->CreateEventBuffer (keyboard, &buffer));
445 #else 506 #else
446 DFBCHECK (keyboard->CreateInputBuffer (keyboard, &buffer)); 507 if (keyboard) DFBCHECK (keyboard->CreateInputBuffer (keyboard, &buffer));
447 #endif 508 #endif
448 // just to start with clean ... 509 // just to start with clean ...
449 buffer->Reset(buffer); 510 if (buffer) buffer->Reset(buffer);
450 return 0; 511 return 0;
451 512
452 } 513 }
453 514
454 515
517 dfb->SetVideoMode(dfb,modes[1].width,modes[1].height,16); 578 dfb->SetVideoMode(dfb,modes[1].width,modes[1].height,16);
518 if (verbose) printf("DirectFB: Trying to set videomode [%ix%i 16 bpp]\n",modes[1].width,modes[1].height); 579 if (verbose) printf("DirectFB: Trying to set videomode [%ix%i 16 bpp]\n",modes[1].width,modes[1].height);
519 }; 580 };
520 break; 581 break;
521 582
522 default: // try all of them in order 16bit 24bit 32bit 8bit 583 default: // try all of them in order 24bit 16bit 32bit 8bit
523 if (modes[1].valid) { 584 if (modes[2].valid) {
585 dfb->SetVideoMode(dfb,modes[2].width,modes[2].height,24);
586 if (verbose) printf("DirectFB: Trying to set videomode [%ix%i 24 bpp]\n",modes[2].width,modes[2].height);
587 }
588 else if (modes[1].valid) {
524 dfb->SetVideoMode(dfb,modes[1].width,modes[1].height,16); 589 dfb->SetVideoMode(dfb,modes[1].width,modes[1].height,16);
525 if (verbose) printf("DirectFB: Trying to set videomode [%ix%i 16 bpp]\n",modes[1].width,modes[1].height); 590 if (verbose) printf("DirectFB: Trying to set videomode [%ix%i 16 bpp]\n",modes[1].width,modes[1].height);
526 }
527 else if (modes[2].valid) {
528 dfb->SetVideoMode(dfb,modes[2].width,modes[2].height,24);
529 if (verbose) printf("DirectFB: Trying to set videomode [%ix%i 24 bpp]\n",modes[2].width,modes[2].height);
530 } 591 }
531 else if (modes[3].valid) { 592 else if (modes[3].valid) {
532 dfb->SetVideoMode(dfb,modes[3].width,modes[3].height,32); 593 dfb->SetVideoMode(dfb,modes[3].width,modes[3].height,32);
533 if (verbose) printf("DirectFB: Trying to set videomode [%ix%i 32 bpp]\n",modes[3].width,modes[3].height); 594 if (verbose) printf("DirectFB: Trying to set videomode [%ix%i 32 bpp]\n",modes[3].width,modes[3].height);
534 } 595 }
634 } 695 }
635 696
636 ret =videolayer->SetConfiguration( videolayer, &dlc ); 697 ret =videolayer->SetConfiguration( videolayer, &dlc );
637 if (!ret) { 698 if (!ret) {
638 if (verbose) printf("DirectFB: SetConfiguration for layer OK\n"); 699 if (verbose) printf("DirectFB: SetConfiguration for layer OK\n");
700
701 #ifdef FLIPPING
702 // try to set flipping for videolayer
703 if (do_flipping) {
704 dlc.flags = DLCONF_BUFFERMODE;
705 dlc.buffermode = DLBM_BACKVIDEO;
706 invram = 1;
707 flipping = 1;
708 ret =videolayer->SetConfiguration( videolayer, &dlc );
709 if (ret!=DFB_OK) {
710 invram = 0;
711 if (!((directfb_major_version <= 0) &&
712 (directfb_minor_version <= 9) &&
713 (directfb_micro_version <= 11))) {
714
715 dlc.buffermode = DLBM_BACKSYSTEM;
716 ret =videolayer->SetConfiguration( videolayer, &dlc );
717 if (ret!=DFB_OK) {
718 flipping = 0;
719 }
720 } else { flipping = 0; };
721 }
722 if (verbose) if (flipping) {
723 printf("DirectFB: SetFlipping for layer: OK (vram=%i)\n",invram);
724 } else {
725 printf("DirectFB: SetFlipping for layer: FAILED\n");
726 }
727 } else flipping=0;
728 #endif
639 ret = videolayer->GetSurface( videolayer, &primary ); 729 ret = videolayer->GetSurface( videolayer, &primary );
640 if (!ret){ 730 if (!ret){
641 videolayeractive=1; 731 videolayeractive=1;
642 if (verbose) printf("DirectFB: Get surface for layer OK\n"); 732 if (verbose) printf("DirectFB: Get surface for layer: OK\n");
643 primaryallocated=1; 733 primaryallocated=1;
734 // set videolayer to be visible
735 videolayer->SetOpacity(videolayer,0xFF);
644 } else { 736 } else {
645 videolayeractive=0; 737 videolayeractive=0;
646 if (videolayer) videolayer->SetOpacity(videolayer,0); 738 if (videolayer) videolayer->SetOpacity(videolayer,0);
647 }; 739 };
648 } else { 740 } else {
650 if (videolayer) videolayer->SetOpacity(videolayer,0); 742 if (videolayer) videolayer->SetOpacity(videolayer,0);
651 }; 743 };
652 744
653 } 745 }
654 746
655 // for flipping we will use BitBlt not integrated directfb flip 747 // for flipping we will use BitBlt not integrated directfb flip (if necessary)
656 dsc.flags = DSDESC_CAPS | DSDESC_PIXELFORMAT; 748 dsc.flags = DSDESC_CAPS | DSDESC_PIXELFORMAT;
657 dsc.caps = DSCAPS_PRIMARY | DSCAPS_VIDEOONLY;//| DSCAPS_FLIPPING; 749 dsc.caps = DSCAPS_PRIMARY /*| DSCAPS_VIDEOONLY*/;
658 750
659 switch (format) { 751 switch (format) {
660 case IMGFMT_RGB32: dsc.pixelformat = DSPF_ARGB; source_pixel_size= 4; break; 752 case IMGFMT_RGB32: dsc.pixelformat = DSPF_ARGB; source_pixel_size= 4; break;
661 case IMGFMT_BGR32: dsc.pixelformat = DSPF_ARGB; source_pixel_size= 4; break; 753 case IMGFMT_BGR32: dsc.pixelformat = DSPF_ARGB; source_pixel_size= 4; break;
662 case IMGFMT_RGB24: dsc.pixelformat = DSPF_RGB24; source_pixel_size= 3; break; 754 case IMGFMT_RGB24: dsc.pixelformat = DSPF_RGB24; source_pixel_size= 3; break;
667 case IMGFMT_BGR15: dsc.pixelformat = DSPF_RGB15; source_pixel_size= 2; break; 759 case IMGFMT_BGR15: dsc.pixelformat = DSPF_RGB15; source_pixel_size= 2; break;
668 default: dsc.pixelformat = DSPF_RGB24; source_pixel_size=2; break; //YUV formats 760 default: dsc.pixelformat = DSPF_RGB24; source_pixel_size=2; break; //YUV formats
669 }; 761 };
670 762
671 if (!videolayeractive) { 763 if (!videolayeractive) {
764 #ifdef FLIPPING
765 if (do_flipping) {
766 flipping = 1;
767 invram = 0;
768 dsc.caps |= DSCAPS_FLIPPING;
769 ret = dfb->CreateSurface( dfb, &dsc, &primary );
770 if (ret!=DFB_OK) {
771 dsc.caps &= ~DSCAPS_FLIPPING;
672 DFBCHECK (dfb->CreateSurface( dfb, &dsc, &primary )); 772 DFBCHECK (dfb->CreateSurface( dfb, &dsc, &primary ));
673 if (verbose) printf("DirectFB: Get primary surface OK\n"); 773 flipping = 0;
774 } else {
775 // test flipping again
776 DFBCHECK (primary->GetCapabilities(primary,&dsc.caps));
777 if (!(dsc.caps & DSCAPS_FLIPPING)) {
778 printf("DirectFB: Error - surface sucesfully created with flipping flag, but doesn't support it.\n");
779 flipping = 0;
780 } else {
781 // test fliping in real - sometimes flips fails even if shouldn't
782 DFBResult ret;
783 ret = primary->Flip(primary,NULL,0);
784 if (ret!=DFB_OK) {
785 // recreate surface as non flipping
786 printf("DirectFB: Error - surface sucesfully created with flipping flag, but test flip failed.\n");
787 flipping = 0;
788 dsc.caps &= ~DSCAPS_FLIPPING;
789 primary->Release(primary);
790 DFBCHECK (dfb->CreateSurface( dfb, &dsc, &primary ));
791 }
792
793 }
794 }
795 /* if (verbose) if (flipping) {
796 printf("DirectFB: Flipping for primary: OK\n");
797 } else {
798 printf("DirectFB: Flipping for primary: FAILED\n");
799 }
800 */ } else {
801 flipping = 0;
802 #endif
803 DFBCHECK (dfb->CreateSurface( dfb, &dsc, &primary ));
804 #ifdef FLIPPING
805 }
806 #endif
807
808 if (verbose) printf("DirectFB: Get primary surface: OK\n");
809
674 primaryallocated=1; 810 primaryallocated=1;
675 } 811 }
812
813 #ifdef FLIPPING
814 // final check for flipping - based on real caps
815
816 DFBCHECK (primary->GetCapabilities(primary,&dsc.caps));
817 if (!(dsc.caps & DSCAPS_FLIPPING)) {
818 printf("DirectFB: Flipping si NOT active.\n");
819 flipping = 0;
820 } else {
821 printf("DirectFB: Flipping is active.\n");
822 flipping = 1;
823 }
824 // }
825 #endif
676 826
677 DFBCHECK (primary->GetSize (primary, &screen_width, &screen_height)); 827 DFBCHECK (primary->GetSize (primary, &screen_width, &screen_height));
678 828
679 DFBCHECK (primary->GetPixelFormat (primary, &frame_format)); 829 DFBCHECK (primary->GetPixelFormat (primary, &frame_format));
680 830
710 }; 860 };
711 #else 861 #else
712 memcpyBitBlt = 0; 862 memcpyBitBlt = 0;
713 #endif 863 #endif
714 864
865
715 // release frame if it is already allocated 866 // release frame if it is already allocated
716 if (frameallocated) { 867 if (frameallocated) {
717 if (verbose ) printf("DirectFB: Release frame\n"); 868 if (verbose ) printf("DirectFB: Release frame\n");
718 frame->Release (frame); 869 frame->Release (frame);
719 frameallocated=0; 870 frameallocated=0;
720 }; 871 };
721 872
722 873 // picture size and position
723 // prevent from memcpy from videomemory to videomemory 874
724 /* if (memcpyBitBlt) { 875 aspect_save_orig(in_width,in_height);
876 aspect_save_prescale(d_width,d_height);
877 if (videolayeractive) {// try to set pos for YUY2 layer and proper aspect ratio
878 aspect_save_screenres(10000,10000);
879 aspect(&out_width,&out_height,A_ZOOM);
880
881 ret = videolayer->SetScreenLocation(videolayer,(1-(float)out_width/10000)/2,(1-(float)out_height/10000)/2,((float)out_width/10000),((float)out_height/10000));
882
883 xoffset = 0;
884 yoffset = 0;
885 } else {
886 // aspect ratio correction for zoom to fullscreen
887 aspect_save_screenres(screen_width,screen_height);
888
889 if(fs) /* -fs */
890 aspect(&out_width,&out_height,A_ZOOM);
891 else
892 aspect(&out_width,&out_height,A_NOZOOM);
893
894
895 xoffset = (screen_width - out_width) / 2;
896 yoffset = (screen_height - out_height) / 2;
897 }
898
899 if (((out_width != in_width) || (out_height != in_height)) && (!videolayeractive)) {stretch = 1;} else stretch=0; //yuy doesn't like strech and should not be needed
900
901 #ifdef FLIPPING
902 // frame will not be allocated in case of overlay or nonstrech blit on primary
903 if (flipping && (!stretch)) {
904 frame = primary;
905 frameallocated = 0;
906 if (verbose) printf("DirectFB: Frame is NOT used (flipping is active).\n");
907 } else {
908 #endif
909 /*
725 dsc.caps = DSCAPS_SYSTEMONLY; 910 dsc.caps = DSCAPS_SYSTEMONLY;
726 } else { 911 //let dfb decide where frame should be - preparation for AGP support
727 dsc.caps = DSCAPS_VIDEOONLY; 912 */
728 } 913 dsc.flags &=~DSDESC_CAPS;
729 ret = dfb->CreateSurface( dfb, &dsc, &frame); 914
730 if (ret) {
731 if (verbose) printf ("DirectFB: Trying do create buffer in system memory (2)\n");*/
732 dsc.caps = DSCAPS_SYSTEMONLY;
733 DFBCHECK (dfb->CreateSurface( dfb, &dsc, &frame)); 915 DFBCHECK (dfb->CreateSurface( dfb, &dsc, &frame));
734 frameallocated=1; 916 frameallocated=1;
735 // } 917 #ifdef FLIPPING
918 if (verbose) if (flipping) {
919 printf("DirectFB: Frame created (flipping&stretch is active).\n");
920 } else {
921 printf("DirectFB: Frame created (flipping is NOT active).\n");
922 };
923 };
924 #endif
736 925
737 DFBCHECK (frame->GetPixelFormat (frame, &frame_format)); 926 DFBCHECK (frame->GetPixelFormat (frame, &frame_format));
738 927
739 switch (frame_format) { 928 switch (frame_format) {
740 case DSPF_ARGB: if (verbose) printf("DirectFB: frame format ARGB\n"); 929 case DSPF_ARGB: if (verbose) printf("DirectFB: frame format ARGB\n");
778 967
779 // yuv2rgb transform init 968 // yuv2rgb transform init
780 969
781 if (((format == IMGFMT_YV12) || (format == IMGFMT_YUY2)) && (!videolayeractive)){ yuv2rgb_init(frame_pixel_size * 8,MODE_RGB);}; 970 if (((format == IMGFMT_YV12) || (format == IMGFMT_YUY2)) && (!videolayeractive)){ yuv2rgb_init(frame_pixel_size * 8,MODE_RGB);};
782 971
783 // picture size and position
784
785 aspect_save_orig(in_width,in_height);
786 aspect_save_prescale(d_width,d_height);
787 if (videolayeractive) {// try to set pos for YUY2 layer and proper aspect ratio
788 aspect_save_screenres(10000,10000);
789 aspect(&out_width,&out_height,A_ZOOM);
790
791 ret = videolayer->SetScreenLocation(videolayer,(1-(float)out_width/10000)/2,(1-(float)out_height/10000)/2,((float)out_width/10000),((float)out_height/10000));
792
793 xoffset = 0;
794 yoffset = 0;
795 } else {
796 // aspect ratio correction for zoom to fullscreen
797 aspect_save_screenres(screen_width,screen_height);
798
799 if(fs) /* -fs */
800 aspect(&out_width,&out_height,A_ZOOM);
801 else
802 aspect(&out_width,&out_height,A_NOZOOM);
803
804
805 xoffset = (screen_width - out_width) / 2;
806 yoffset = (screen_height - out_height) / 2;
807 }
808
809 if (((out_width != in_width) || (out_height != in_height)) && (!videolayeractive)) {stretch = 1;} else stretch=0; //yuy doesn't like strech and should not be needed
810
811 if ((verbose)&&(memcpyBitBlt)) printf("DirectFB: Using memcpyBitBlt\n"); 972 if ((verbose)&&(memcpyBitBlt)) printf("DirectFB: Using memcpyBitBlt\n");
812 #ifdef DIRECTRENDER 973 #ifdef DIRECTRENDER
813 //direct rendering is enabled in case of sane buffer and im format 974 //direct rendering is enabled in case of same buffer and img format
814 if ((format==IMGFMT_RGB32)&&(frame_format ==DSPF_ARGB) || 975 if ((format==IMGFMT_RGB32)&&(frame_format ==DSPF_ARGB) ||
815 (format==IMGFMT_BGR32)&&(frame_format ==DSPF_ARGB) || 976 (format==IMGFMT_BGR32)&&(frame_format ==DSPF_ARGB) ||
816 (format==IMGFMT_RGB24)&&(frame_format ==DSPF_RGB24) || 977 (format==IMGFMT_RGB24)&&(frame_format ==DSPF_RGB24) ||
817 (format==IMGFMT_BGR24)&&(frame_format ==DSPF_RGB24) || 978 (format==IMGFMT_BGR24)&&(frame_format ==DSPF_RGB24) ||
818 (format==IMGFMT_RGB16)&&(frame_format ==DSPF_RGB16) || 979 (format==IMGFMT_RGB16)&&(frame_format ==DSPF_RGB16) ||
845 int ret = VFCAP_CSP_SUPPORTED|VFCAP_OSD; /* osd/sub is supported on every bpp */ 1006 int ret = VFCAP_CSP_SUPPORTED|VFCAP_OSD; /* osd/sub is supported on every bpp */
846 1007
847 // preinit(NULL); 1008 // preinit(NULL);
848 1009
849 if (verbose ) printf("DirectFB: Format query: %s\n",vo_format_name(format)); 1010 if (verbose ) printf("DirectFB: Format query: %s\n",vo_format_name(format));
1011
1012 switch (format) {
1013 // primary
1014 case IMGFMT_RGB32:
1015 case IMGFMT_BGR32:
1016 case IMGFMT_RGB24:
1017 case IMGFMT_BGR24:
1018 case IMGFMT_RGB16:
1019 case IMGFMT_BGR16:
1020 case IMGFMT_RGB15:
1021 case IMGFMT_BGR15: if (hwstretchblit) ret |=VFCAP_HWSCALE_UP|VFCAP_HWSCALE_DOWN;
1022 break;
1023 // overlay
1024 case IMGFMT_YUY2:
1025 case IMGFMT_YV12: if (videolayercaps.hwscale) ret |=VFCAP_HWSCALE_UP|VFCAP_HWSCALE_DOWN;
1026 break;
1027 }
1028
1029
850 switch (format) { 1030 switch (format) {
851 1031
852 // RGB mode works only if color depth is same as on screen and this driver doesn't know before init 1032 // RGB mode works only if color depth is same as on screen and this driver doesn't know before init
853 // so we couldn't report supported formats well 1033 // so we couldn't report supported formats well
854 1034
863 case IMGFMT_BGR16: 1043 case IMGFMT_BGR16:
864 case IMGFMT_RGB15: 1044 case IMGFMT_RGB15:
865 case IMGFMT_BGR15: if (modes[1].valid) return ret; 1045 case IMGFMT_BGR15: if (modes[1].valid) return ret;
866 break; 1046 break;
867 case IMGFMT_YUY2: if (videolayerpresent) { 1047 case IMGFMT_YUY2: if (videolayerpresent) {
1048 if (videolayercaps.hwscale) ret |=VFCAP_HWSCALE_UP|VFCAP_HWSCALE_DOWN;
868 if (videolayercaps.yuy2) { 1049 if (videolayercaps.yuy2) {
869 return ret|VFCAP_CSP_SUPPORTED_BY_HW; 1050 return ret|VFCAP_CSP_SUPPORTED_BY_HW;
870 } else { 1051 // disabled - MPlayer will do conversion automatically
1052 /* } else {
871 return ret; 1053 return ret;
872 }; 1054 */ };
873 }; 1055 };
874 break; 1056 break;
875 case IMGFMT_YV12: if ((videolayerpresent) && 1057 case IMGFMT_YV12: if ((videolayerpresent) &&
876 (videolayercaps.i420 || videolayercaps.iv12)) 1058 (videolayercaps.i420 || videolayercaps.iv12))
877 return ret|VFCAP_CSP_SUPPORTED_BY_HW; 1059 return ret|VFCAP_CSP_SUPPORTED_BY_HW;
878 else return ret; 1060 // disabled - MPlayer will do conversion automatically
879 break; 1061 /* else return ret;
880 // YV12 should work in all cases 1062 */ break;
881 } 1063 }
882 1064
883 return 0; 1065 return 0;
884 } 1066 }
885 1067
892 unsigned char *srca, int stride) 1074 unsigned char *srca, int stride)
893 { 1075 {
894 void *dst; 1076 void *dst;
895 int pitch; 1077 int pitch;
896 int len; 1078 int len;
1079 static IDirectFBSurface *surface = NULL;
1080
897 1081
898 #ifdef DIRECTRENDER 1082 #ifdef DIRECTRENDER
899 if(framelocked) { 1083 if(framelocked) {
900 frame->Unlock(frame); 1084 frame->Unlock(frame);
901 framelocked=0; 1085 framelocked=0;
902 }; 1086 };
903 #endif 1087 #endif
1088 #ifdef FLIPPING
1089 if (flipping && stretch) {
1090 DFBCHECK (primary->Lock(primary,DSLF_WRITE,&dst,&pitch));
1091 } else {
1092 #endif
904 DFBCHECK (frame->Lock(frame,DSLF_WRITE,&dst,&pitch)); 1093 DFBCHECK (frame->Lock(frame,DSLF_WRITE,&dst,&pitch));
905 1094 #ifdef FLIPPING
1095 }
1096 #endif
906 switch(frame_format) { 1097 switch(frame_format) {
907 case DSPF_RGB32: 1098 case DSPF_RGB32:
908 case DSPF_ARGB: 1099 case DSPF_ARGB:
909 vo_draw_alpha_rgb32(w,h,src,srca,stride,((uint8_t *) dst)+pitch*y0 + frame_pixel_size*x0,pitch); 1100 vo_draw_alpha_rgb32(w,h,src,srca,stride,((uint8_t *) dst)+pitch*y0 + frame_pixel_size*x0,pitch);
910 break; 1101 break;
934 case DSPF_YV12: 1125 case DSPF_YV12:
935 vo_draw_alpha_yv12(w,h,src,srca,stride,((uint8_t *) dst) + pitch*y0 + frame_pixel_size*x0,pitch); 1126 vo_draw_alpha_yv12(w,h,src,srca,stride,((uint8_t *) dst) + pitch*y0 + frame_pixel_size*x0,pitch);
936 break; 1127 break;
937 #endif 1128 #endif
938 } 1129 }
1130 #ifdef FLIPPING
1131 if (flipping && stretch) {
1132 DFBCHECK (primary->Unlock(primary));
1133 } else {
1134 #endif
939 DFBCHECK (frame->Unlock(frame)); 1135 DFBCHECK (frame->Unlock(frame));
1136 #ifdef FLIPPING
1137 }
1138 #endif
940 } 1139 }
941 1140
942 static uint32_t draw_frame(uint8_t *src[]) 1141 static uint32_t draw_frame(uint8_t *src[])
943 { 1142 {
944 void *dst; 1143 void *dst;
1206 #include "../linux/keycodes.h" 1405 #include "../linux/keycodes.h"
1207 1406
1208 static void check_events(void) 1407 static void check_events(void)
1209 { 1408 {
1210 1409
1410 if (buffer) {
1411
1211 DFBInputEvent event; 1412 DFBInputEvent event;
1212 //if (verbose) printf ("DirectFB: Check events entered\n"); 1413 //if (verbose) printf ("DirectFB: Check events entered\n");
1213 #ifdef HAVE_DIRECTFB0910 1414 #ifdef HAVE_DIRECTFB0910
1214 if (buffer->GetEvent(buffer, DFB_EVENT (&event)) == DFB_OK) { 1415 if (buffer->GetEvent(buffer, DFB_EVENT (&event)) == DFB_OK) {
1215 #else 1416 #else
1257 default:mplayer_put_key(event.key_ascii); 1458 default:mplayer_put_key(event.key_ascii);
1258 }; 1459 };
1259 #endif 1460 #endif
1260 }; 1461 };
1261 }; 1462 };
1463 }
1262 // empty buffer, because of repeating (keyboard repeat is faster than key handling 1464 // empty buffer, because of repeating (keyboard repeat is faster than key handling
1263 // and this causes problems during seek) 1465 // and this causes problems during seek)
1264 // temporary workabout should be solved in the future 1466 // temporary workabout should be solved in the future
1265 1467
1266 buffer->Reset(buffer); 1468 if (buffer) buffer->Reset(buffer);
1267 //if (verbose) printf ("DirectFB: Check events finished\n"); 1469 //if (verbose) printf ("DirectFB: Check events finished\n");
1268 1470
1269 } 1471 }
1270 1472
1271 static void draw_osd(void) 1473 static void draw_osd(void)
1272 { 1474 {
1475 // if flipping is active we will draw directly to primary
1476 // we will also blit from frame to primary if necessary
1477 #ifdef FLIPPING
1478 if (stretch && flipping) {
1479 DFBRectangle rect;
1480 rect.x=xoffset;
1481 rect.y=yoffset;
1482 rect.w=out_width;
1483 rect.h=out_height;
1484 #ifdef DIRECTRENDER
1485 if(framelocked) {
1486 frame->Unlock(frame);
1487 framelocked=0;
1488 };
1489 #endif
1490 // lets clear blackborders
1491 primary->SetColor(primary,0,0,0,0);
1492 // top
1493 primary->FillRectangle(primary,0,0,screen_width,yoffset);
1494 // bottom
1495 primary->FillRectangle(primary,0,screen_height-yoffset,screen_width,yoffset);
1496 //left
1497 // primary->FillRectangle(primary,0,yoffset,xoffset,screen_height-2*yoffset);
1498 //right
1499 // primary->FillRectangle(primary,screen_width-xoffset-1,yoffset,xoffset,screen_height-2*yoffset);
1500
1501 DFBCHECK (primary->StretchBlit(primary,frame,NULL,&rect));
1502 blitperformed=1;
1503 vo_draw_text(screen_width, screen_height, draw_alpha);
1504 } else {
1505 #endif
1273 vo_draw_text(in_width, in_height, draw_alpha); 1506 vo_draw_text(in_width, in_height, draw_alpha);
1507 #ifdef FLIPPING
1508 }
1509 #endif
1274 } 1510 }
1275 1511
1276 static void flip_page(void) 1512 static void flip_page(void)
1277 { 1513 {
1278 DFBSurfaceBlittingFlags flags=DSBLIT_NOFX; 1514 DFBSurfaceBlittingFlags flags=DSBLIT_NOFX;
1285 if(framelocked) { 1521 if(framelocked) {
1286 frame->Unlock(frame); 1522 frame->Unlock(frame);
1287 framelocked=0; 1523 framelocked=0;
1288 }; 1524 };
1289 #endif 1525 #endif
1290 if (stretch) { 1526 if (stretch
1527 #ifdef FLIPPING
1528 && (!blitperformed)
1529 #endif
1530 ) {
1291 DFBRectangle rect; 1531 DFBRectangle rect;
1292 rect.x=xoffset; 1532 rect.x=xoffset;
1293 rect.y=yoffset; 1533 rect.y=yoffset;
1294 rect.w=out_width; 1534 rect.w=out_width;
1295 rect.h=out_height; 1535 rect.h=out_height;
1296 1536
1297 DFBCHECK (primary->StretchBlit(primary,frame,NULL,&rect)); 1537 DFBCHECK (primary->StretchBlit(primary,frame,NULL,&rect));
1538 #ifdef FLIPPING
1539 blitperformed=0;
1540 #endif
1298 } 1541 }
1299 else { 1542 else {
1543 #ifdef FLIPPING
1544 if (!flipping) {
1545 #endif
1300 #ifdef HAVE_DIRECTFB099 1546 #ifdef HAVE_DIRECTFB099
1301 if (!memcpyBitBlt) { 1547 if (!memcpyBitBlt) {
1302 #endif 1548 #endif
1303 DFBCHECK (primary->Blit(primary,frame,NULL,xoffset,yoffset)); 1549 DFBCHECK (primary->Blit(primary,frame,NULL,xoffset,yoffset));
1304 #ifdef HAVE_DIRECTFB099 1550 #ifdef HAVE_DIRECTFB099
1339 } 1585 }
1340 frame->Unlock(frame); 1586 frame->Unlock(frame);
1341 primary->Unlock(primary); 1587 primary->Unlock(primary);
1342 }; 1588 };
1343 #endif 1589 #endif
1590 #ifdef FLIPPING
1344 }; 1591 };
1345 // DFBCHECK (primary->Flip (primary, NULL, DSFLIP_WAITFORSYNC)); 1592 #endif
1593 };
1594 #ifdef FLIPPING
1595 if (flipping) {
1596 if (videolayeractive && wait_vsync_after_flip) {
1597 DFBCHECK (primary->Flip (primary, NULL, /*DSFLIP_WAITFORSYNC*/0));
1598 /* workabout for videolayer
1599 flip will take place on next vsync, but pointers are updated instanlty ->
1600 -> decoding goes into "new" buffer which is still displayed ->
1601 -> so wait for vsync to be safe (and have surfaces REALLY flipped)
1602 */
1603 dfb->WaitForSync(dfb);
1604 } else {
1605 DFBCHECK (primary->Flip (primary, NULL, DSFLIP_WAITFORSYNC));
1606 };
1607 };
1608 #endif
1346 } 1609 }
1347 1610
1348 static void uninit(void) 1611 static void uninit(void)
1349 { 1612 {
1350 if (verbose ) printf("DirectFB: uninit entered\n"); 1613 if (verbose ) printf("DirectFB: uninit entered\n");
1351 /* 1614 /*
1352 * (Release) 1615 * (Release)
1353 */ 1616 */
1354 if (verbose ) printf("DirectFB: Release buffer\n"); 1617 if (verbose ) printf("DirectFB: Release buffer\n");
1355 buffer->Release (buffer); 1618 if (buffer) buffer->Release (buffer);
1356 if (verbose ) printf("DirectFB: Release keyboard\n"); 1619 if (verbose ) printf("DirectFB: Release keyboard\n");
1357 keyboard->Release (keyboard); 1620 if (keyboard) keyboard->Release (keyboard);
1358 if (frameallocated) { 1621 if (frameallocated) {
1359 if (verbose ) printf("DirectFB: Release frame\n"); 1622 if (verbose ) printf("DirectFB: Release frame\n");
1360 frame->Release (frame); 1623 frame->Release (frame);
1361 frameallocated=0; 1624 frameallocated=0;
1362 }; 1625 };
1465 int pitch; 1728 int pitch;
1466 1729
1467 // printf("DirectFB: get_image() called\n"); 1730 // printf("DirectFB: get_image() called\n");
1468 1731
1469 // now we are always in system memory (in this version - mybe will change in future) 1732 // now we are always in system memory (in this version - mybe will change in future)
1470 // if(mpi->flags&MP_IMGFLAG_READABLE) return VO_FALSE; // slow video ram 1733 #ifdef FLIPPING
1471 1734 if((mpi->flags&MP_IMGFLAG_READABLE) && invram) return VO_FALSE; // slow video ram
1735 #endif
1472 // printf("width=%d vs. pitch=%d, flags=0x%X \n",mpi->width,pitch,mpi->flags); 1736 // printf("width=%d vs. pitch=%d, flags=0x%X \n",mpi->width,pitch,mpi->flags);
1473 if((mpi->width==pitch/frame_pixel_size) || 1737 if((mpi->width==pitch/frame_pixel_size) ||
1474 (mpi->flags&(MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH))){ 1738 (mpi->flags&(MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH))){
1475 // we're lucky or codec accepts stride => ok, let's go! 1739 // we're lucky or codec accepts stride => ok, let's go!
1476 if(mpi->flags&MP_IMGFLAG_PLANAR){ 1740 if(mpi->flags&MP_IMGFLAG_PLANAR){