~ubuntu-branches/ubuntu/intrepid/gpac/intrepid-proposed

« back to all changes in this revision

Viewing changes to modules/x11_out/x11_out.c

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2007-01-24 23:34:57 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070124233457-zzlls8afkt0nyakj
Tags: 0.4.2~rc2-0ubuntu1
* New upstream release
  * Most notably MP4 tagging support via MP4Box -itags
* debian/patches/01_64bits.dpatch: dropped; included upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 * Flush video: draw main image(surface/pixmap) -> os_handle
34
34
 */
35
35
//=====================================
36
 
GF_Err X11_FlushVideo (struct _video_out *vout, GF_Window * dest)
 
36
GF_Err X11_Flush(struct _video_out *vout, GF_Window * dest)
37
37
{
38
38
        Window cur_wnd;
39
39
        /*
441
441
GF_Err X11_ProcessEvent (struct _video_out * vout, GF_Event * evt)
442
442
{
443
443
        X11VID ();
444
 
        GF_Window a_wnd;
445
 
 
446
444
 
447
445
        if (!xWindow->setup_done) X11_SetupWindow(vout);
448
446
 
449
447
        if (evt) {
450
448
 
451
449
        switch (evt->type) {
452
 
        case GF_EVT_REFRESH:
453
 
                a_wnd.w = evt->size.width;
454
 
                a_wnd.h = evt->size.height;
455
 
                a_wnd.x = a_wnd.y = 0;
456
 
                X11_FlushVideo (vout, &a_wnd);
457
 
                break;
458
450
        case GF_EVT_SET_CURSOR:
459
451
                break;
460
452
        case GF_EVT_SET_CAPTION:
 
453
                if (!xWindow->par_wnd) XStoreName (xWindow->display, xWindow->wnd, evt->caption.caption);
461
454
                break;
462
455
        case GF_EVT_SHOWHIDE:
463
456
                break;
464
457
        case GF_EVT_SIZE:
465
458
                /*if owning the window and not in fullscreen, resize it (initial scene size)*/
 
459
        xWindow->w_width = evt->size.width;
 
460
        xWindow->w_height = evt->size.height;
466
461
          if (!xWindow->fullscreen) {
467
462
            if (xWindow->par_wnd) {
468
463
              XWindowAttributes pwa;
473
468
                XResizeWindow (xWindow->display, xWindow->wnd, evt->size.width, evt->size.height);
474
469
            }
475
470
          }
 
471
          break;
476
472
        case GF_EVT_VIDEO_SETUP:
477
 
                xWindow->w_width = evt->size.width;
478
 
                xWindow->w_height = evt->size.height;
479
 
                /*and resetup OpenGL*/
 
473
                /*and resetup HW*/
480
474
#ifdef GPAC_HAS_OPENGL
481
 
                if (xWindow->is_3D_out) X11_SetupGL(vout);
 
475
                if (xWindow->is_3D_out) return X11_SetupGL(vout);
482
476
#endif
483
 
                break;
 
477
                return X11_ResizeBackBuffer(vout, evt->size.width, evt->size.height);
484
478
        }
485
479
        } else {
486
480
          X11_HandleEvents(vout);
501
495
        if (bFullScreenOn) {
502
496
                xWindow->store_width = *screen_width;
503
497
                xWindow->store_height = *screen_height;
504
 
                xWindow->w_width = xWindow->display_width;
505
 
                xWindow->w_height = xWindow->display_height;
 
498
 
 
499
                xWindow->w_width = vout->max_screen_width;
 
500
                xWindow->w_height = vout->max_screen_height;
506
501
 
507
502
                XFreeGC (xWindow->display, xWindow->the_gc);
508
503
                xWindow->the_gc = XCreateGC (xWindow->display, xWindow->full_wnd, 0, NULL);
509
504
 
510
505
                XMoveResizeWindow (xWindow->display,
511
506
                                   (Window) xWindow->full_wnd, 0, 0,
512
 
                                   xWindow->display_width,
513
 
                                   xWindow->display_height);
 
507
                                   vout->max_screen_width,
 
508
                                   vout->max_screen_height);
514
509
                *screen_width = xWindow->w_width;
515
510
                *screen_height = xWindow->w_height;
516
511
                XUnmapWindow (xWindow->display, xWindow->wnd);
535
530
        return GF_OK;
536
531
}
537
532
 
538
 
GF_Err X11_Clear (struct _video_out * vout, u32 color)
539
 
{
540
 
        X11VID ();
541
 
        Window the_window;
542
 
 
543
 
        the_window = xWindow->fullscreen ? xWindow->full_wnd : xWindow->wnd;
544
 
        switch (xWindow->videoaccesstype) {
545
 
        case VIDEO_XI_STANDARD:
546
 
                // TODO convert color to PIXEL
547
 
                XSetWindowBackground (xWindow->display, the_window, color);
548
 
                XClearWindow (xWindow->display, the_window);
549
 
                break;
550
 
        }
551
 
        return GF_OK;
552
 
}
553
 
 
554
533
/*
555
534
 * lock video mem
556
535
 */
557
 
GF_Err X11_LockSurface (struct _video_out * vout, u32 surface_id, GF_VideoSurface * vi)
 
536
GF_Err X11_LockBackBuffer(struct _video_out * vout, GF_VideoSurface * vi, u32 do_lock)
558
537
{
559
 
        u32 i;
560
538
        X11VID ();
561
539
 
562
 
        if (!surface_id) {
 
540
        if (do_lock) {
 
541
                if (!vi) return GF_BAD_PARAM;
563
542
                vi->width = xWindow->back_buffer->width;
564
543
                vi->height = xWindow->back_buffer->height;
565
544
                vi->pitch = xWindow->back_buffer->pitch;
566
545
                vi->pixel_format = xWindow->pixel_format;
567
 
                vi->os_handle = NULL;
568
546
                vi->video_buffer = xWindow->back_buffer->buffer;
569
 
                return GF_OK;
570
 
        }
571
 
 
572
 
        for (i = 0; i < gf_list_count(xWindow->surfaces); i++) {
573
 
                X11WrapSurface *ptr = (X11WrapSurface *) gf_list_get(xWindow->surfaces, i);
574
 
                if (ptr->id == surface_id) { 
575
 
                        vi->width = ptr->width;
576
 
                        vi->height = ptr->height;
577
 
                        vi->pitch = ptr->pitch;
578
 
                        vi->pixel_format = ptr->pixel_format;
579
 
                        vi->os_handle = NULL;
580
 
                        vi->video_buffer = ptr->buffer;
581
 
                        return GF_OK;
582
 
                }
583
 
        }
584
 
        return GF_BAD_PARAM;
585
 
}
586
 
 
587
 
GF_Err X11_UnlockSurface (struct _video_out * vout, u32 surface_id)
588
 
{
589
 
        /*for now nothing to do (offscreen surfaces are not on video memory yet...)*/
590
 
        return GF_OK;
591
 
}
592
 
 
593
 
/*
594
 
 * creates a offscreen video surface and setup surface id - pixel format
595
 
 * MUST be respected except for YUV formats, where the hardware is free to 
596
 
 * choose the fastest format for blit
597
 
 */
598
 
static GF_Err X11_CreateSurface (struct _video_out *vout, u32 width, u32 height, u32 pixel_format, u32 * surfaceID)
599
 
{
600
 
        u32 size;
601
 
        X11WrapSurface *surf;
602
 
        X11VID ();
603
 
 
604
 
 
605
 
        GF_SAFEALLOC(surf, sizeof (X11WrapSurface));
606
 
 
607
 
        switch (pixel_format) {
608
 
        case GF_PIXEL_RGB_555:          
609
 
                surf->BPP = 2;
610
 
                break;
611
 
        case GF_PIXEL_RGB_565:
612
 
                surf->BPP = 2;
613
 
                break;
614
 
        case GF_PIXEL_RGB_24:           
615
 
                surf->BPP = 3;
616
 
                break;
617
 
        case GF_PIXEL_RGB_32:           
618
 
                surf->BPP = 4;
619
 
                break;
620
 
        }
621
 
        surf->pitch = width * surf->BPP;
622
 
        size = height * surf->pitch;
623
 
        surf->buffer = (unsigned char *) malloc (sizeof (unsigned char) * size);
624
 
        surf->pixel_format = pixel_format;
625
 
        surf->id = (u32) surf;
626
 
        gf_list_add(xWindow->surfaces, surf);
627
 
        *surfaceID = surf->id;
628
 
        return GF_OK;
629
 
}
630
 
 
631
 
X11WrapSurface *X11_GetSurface (struct _video_out *vout, u32 surface_id)
632
 
{
633
 
        s32 i;
634
 
        X11WrapSurface *surf;
635
 
        X11VID ();
636
 
        if (!surface_id) return NULL;
637
 
        surf = (X11WrapSurface *)surface_id;
638
 
        i = gf_list_find(xWindow->surfaces, surf);
639
 
        if (i<0) return NULL;
640
 
        return surf;
641
 
}
642
 
 
643
 
GF_Err X11_DeleteSurface (struct _video_out * vout, u32 surface_id)
644
 
{
645
 
        X11WrapSurface *surf;
646
 
        X11VID ();
647
 
        if (!surface_id) return GF_BAD_PARAM;
648
 
        surf = X11_GetSurface(vout, surface_id);
649
 
        if (surf) {
650
 
                gf_list_del_item(xWindow->surfaces, surf);
651
 
                if (surf->buffer) free(surf->buffer);
652
 
                free(surf);
653
 
                return GF_OK;
654
 
        }
655
 
        return GF_BAD_PARAM;
656
 
}
657
 
 
658
 
 
659
 
/*
660
 
 * checks if the surface is valid - this is used to discard surfaces when
661
 
 * changing video mode (fullscreen)
662
 
 */
663
 
u32
664
 
X11_IsSurfaceValid (struct _video_out * vout, u32 surface_id)
665
 
{
666
 
        return (X11_GetSurface(vout, surface_id) != NULL) ? 1 : 0;
667
 
}
668
 
 
669
 
/*
670
 
 * resize surface - the resulting surface can still be larger than what
671
 
 * requested
672
 
 */
673
 
GF_Err
674
 
X11_ResizeSurface (struct _video_out * vout, u32 surface_id,
675
 
                   u32 width, u32 height)
676
 
{
677
 
        X11WrapSurface *wrap;
678
 
        if (!surface_id) return X11_ResizeBackBuffer(vout, width, height);
679
 
 
680
 
        wrap = X11_GetSurface(vout, surface_id);
681
 
        if (!wrap || !wrap->BPP) return GF_BAD_PARAM;
682
 
        if ((wrap->width>= width) && (wrap->height>=height)) return GF_OK;
683
 
        free(wrap->buffer);
684
 
        wrap->pitch = wrap->BPP * width;
685
 
        wrap->width = width;
686
 
        wrap->height = height;
687
 
        wrap->buffer = malloc(sizeof(char) * wrap->pitch * wrap->height);
688
 
        return GF_OK;
689
 
}
690
 
 
691
 
 
692
 
/*
693
 
 * blit surface src to surface dest - if a window is not specified, the
694
 
 * full surface is used _ can be NULL
695
 
 */
696
 
GF_Err
697
 
X11_Blit (struct _video_out * vout, u32 src_id, u32 dst_id,
698
 
          GF_Window * src, GF_Window * dst)
699
 
{
700
 
        void *pdst, *psrc;
701
 
        X11VID ();
702
 
        if (dst_id) return GF_NOT_SUPPORTED;
703
 
 
704
 
        X11WrapSurface *dest_surf = xWindow->back_buffer;
705
 
        X11WrapSurface *src_surf = X11_GetSurface (vout, src_id);
706
 
 
707
 
        pdst = dest_surf->buffer + dst->y * xWindow->back_buffer->pitch + dst->x * xWindow->bpp;
708
 
        int dst_depth = xWindow->bpp*8;
709
 
        int src_depth = src_surf->BPP*8;
710
 
        int src_bpp = src_surf->BPP;
711
 
        
712
 
        psrc = src_surf->buffer + src->y * src_surf->pitch + src->x * src_bpp;
713
 
        StretchBits (pdst, dst_depth, dst->w, dst->h, dest_surf->pitch,
714
 
                                        psrc, src_depth, src->w, src->h, src_surf->pitch, 
715
 
                                        0);
716
 
        return GF_OK;
717
 
}
718
 
 
719
 
/*
720
 
 * returns pixel format of the surface - if surfaceID is 0, the main video
721
 
 * memory format is requested
722
 
 */
723
 
GF_Err
724
 
X11_GetPixelFormat (struct _video_out * vout, u32 surfaceID,
725
 
                    u32 * pixel_format)
726
 
{
727
 
        u32 i;
728
 
        X11VID ();
729
 
 
730
 
        if (!surfaceID) {
731
 
                *pixel_format = xWindow->pixel_format;
732
 
                return GF_OK;
733
 
        }
734
 
 
735
 
        for (i = 0; i < gf_list_count (xWindow->surfaces); i++) {
736
 
                X11WrapSurface *ptr = (X11WrapSurface *) gf_list_get (xWindow->surfaces, i);
737
 
                if (ptr->id == surfaceID) {
738
 
                        *pixel_format = ptr->pixel_format;
739
 
                        return GF_OK;
740
 
                }
741
 
        }
742
 
        return GF_OK;
743
 
}
 
547
                vi->is_hardware_memory = (xWindow->videoaccesstype==VIDEO_XI_STANDARD) ? 0 : 1;
 
548
                return GF_OK;
 
549
        } else {
 
550
                return GF_OK;
 
551
        }
 
552
}
 
553
 
744
554
 
745
555
static XErrorHandler old_handler = NULL;
746
556
static int selectinput_err = 0;
770
580
X11_SetupWindow (GF_VideoOutput * vout)
771
581
{
772
582
        X11VID ();
 
583
        const char *sOpt;
773
584
 
774
585
        xWindow->display = XOpenDisplay (NULL);
775
586
        xWindow->screennum = DefaultScreen (xWindow->display);
794
605
        xWindow->bpp = xWindow->depth / 8;
795
606
        xWindow->bpp = xWindow->bpp == 3 ? 4 : xWindow->bpp;
796
607
 
797
 
        xWindow->display_width = DisplayWidth (xWindow->display, xWindow->screennum);
798
 
        xWindow->display_height = DisplayHeight (xWindow->display, xWindow->screennum);
 
608
        vout->max_screen_width = DisplayWidth(xWindow->display, xWindow->screennum);
 
609
        vout->max_screen_height = DisplayHeight(xWindow->display, xWindow->screennum);
799
610
 
800
611
        /*
801
612
         * Full screen wnd
803
614
        xWindow->full_wnd = XCreateWindow (xWindow->display,
804
615
                                                                   RootWindowOfScreen (xWindow->screenptr),
805
616
                                                                   0, 0,
806
 
                                                                   xWindow->display_width,
807
 
                                                                   xWindow->display_height, 0,
 
617
                                                                   vout->max_screen_width,
 
618
                                                                   vout->max_screen_height, 0,
808
619
                                                                   xWindow->depth, InputOutput,
809
620
                                                                   xWindow->visual, 0, NULL);
810
621
 
874
685
        xWindow->videoaccesstype = VIDEO_XI_STANDARD;
875
686
 
876
687
#ifdef GPAC_HAS_X11_SHM
877
 
        int XShmMajor, XShmMinor;
878
 
        Bool XShmPixmaps;
879
 
        if (XShmQueryVersion(xWindow->display, &XShmMajor, &XShmMinor, &XShmPixmaps)) {
880
 
          /*this is disabled due to flip pb (we cannot reposition backbuffer)*/
881
 
                if (0 && XShmPixmaps && (XShmPixmapFormat(xWindow->display) == ZPixmap)) {
882
 
                        xWindow->videoaccesstype = VIDEO_XI_SHMPIXMAP;
883
 
                } else {
884
 
                        xWindow->videoaccesstype = VIDEO_XI_SHMSTD;
885
 
                }
886
 
 
 
688
        sOpt = gf_modules_get_option((GF_BaseInterface *)vout, "Video", "UseHardwareMemory");
 
689
        if (sOpt && !strcmp(sOpt, "yes")) {
 
690
          int XShmMajor, XShmMinor;
 
691
          Bool XShmPixmaps;
 
692
          if (XShmQueryVersion(xWindow->display, &XShmMajor, &XShmMinor, &XShmPixmaps)) {
 
693
            /*this is disabled due to flip pb (we cannot reposition backbuffer)*/
 
694
            if (0 && XShmPixmaps && (XShmPixmapFormat(xWindow->display) == ZPixmap)) {
 
695
                xWindow->videoaccesstype = VIDEO_XI_SHMPIXMAP;
 
696
            } else {
 
697
              xWindow->videoaccesstype = VIDEO_XI_SHMSTD;
 
698
              //fprintf(stdout, "\nUsing X11 Hardware Blit\n");
 
699
            }
 
700
          }
887
701
        }
888
702
#endif
889
703
 
953
767
        /*OSMOZILLA HACK*/
954
768
        if (os_display) xWindow->no_select_input = 1;
955
769
        if (cfg) {
956
 
          xWindow->is_3D_out = 1;
 
770
#ifdef GPAC_HAS_OPENGL
 
771
                xWindow->is_3D_out = 1;
957
772
          xWindow->gl_cfg = *cfg;
 
773
#else
 
774
          return GF_NOT_SUPPORTED;
 
775
#endif
958
776
        } else {
959
777
          xWindow->is_3D_out = 0;
960
778
        }
967
785
{
968
786
        X11VID ();
969
787
 
970
 
        while (gf_list_count (xWindow->surfaces)) {
971
 
                X11WrapSurface *ptr = (X11WrapSurface *) gf_list_get(xWindow->surfaces, 0);
972
 
                gf_list_rem(xWindow->surfaces, 0);
973
 
                if (ptr) {
974
 
                        if (ptr->buffer) free (ptr->buffer);
975
 
                        free (ptr);
976
 
                }
977
 
        }
978
 
        gf_list_del(xWindow->surfaces);
979
788
        if (xWindow->is_3D_out) {
980
789
#ifdef GPAC_HAS_OPENGL
981
790
                X11_ReleaseGL(xWindow);
1005
814
                return NULL;
1006
815
        }
1007
816
        GF_REGISTER_MODULE_INTERFACE(driv, GF_VIDEO_OUTPUT_INTERFACE, "X11 Video Output", "gpac distribution")
1008
 
        xWindow->surfaces = gf_list_new();
 
817
 
1009
818
        driv->opaque = xWindow;
1010
819
 
1011
 
        driv->Blit = X11_Blit;
1012
 
        driv->Clear = X11_Clear;
1013
 
        driv->CreateSurface = X11_CreateSurface;
1014
 
        driv->DeleteSurface = X11_DeleteSurface;
1015
 
        driv->FlushVideo = X11_FlushVideo;
1016
 
        driv->GetPixelFormat = X11_GetPixelFormat;
1017
 
        driv->LockSurface = X11_LockSurface;
1018
 
        driv->IsSurfaceValid = X11_IsSurfaceValid;
 
820
        driv->Flush = X11_Flush;
1019
821
        driv->SetFullScreen = X11_SetFullScreen;
1020
822
        driv->Setup = X11_Setup;
1021
823
        driv->Shutdown = X11_Shutdown;
1022
 
        driv->UnlockSurface = X11_UnlockSurface;
1023
 
        driv->ResizeSurface = X11_ResizeSurface;
 
824
        driv->LockBackBuffer = X11_LockBackBuffer;
1024
825
        driv->ProcessEvent = X11_ProcessEvent;
1025
 
        driv->bHas3DSupport = 1;
 
826
        driv->hw_caps = GF_VIDEO_HW_HAS_OPENGL;
1026
827
        return (void *) driv;
1027
828
 
1028
829
}