vo_x11.c

来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 803 行 · 第 1/2 页

C
803
字号
        xswa.background_pixel = 0;        xswa.border_pixel = 0;        xswa.colormap = theCmap;        xswamask = CWBackPixel | CWBorderPixel | CWColormap;#ifdef HAVE_XF86VM        if (vm)        {            xswa.override_redirect = True;            xswamask |= CWOverrideRedirect;        }#endif        if (WinID >= 0)        {            vo_window = WinID ? ((Window) WinID) : mRootWin;            if (WinID)            {                int border;                XUnmapWindow(mDisplay, vo_window);                XChangeWindowAttributes(mDisplay, vo_window, xswamask,                                        &xswa);                vo_x11_selectinput_witherr(mDisplay, vo_window,                                           StructureNotifyMask |                                           KeyPressMask |                                           PropertyChangeMask |                                           PointerMotionMask |                                           ButtonPressMask |                                           ButtonReleaseMask |                                           ExposureMask);                XMapWindow(mDisplay, vo_window);                XGetGeometry(mDisplay, vo_window, &mRootWin,                             &vo_dx, &vo_dy, &vo_dwidth, &vo_dheight,                             &border, &depth);            } else                XSelectInput(mDisplay, vo_window, ExposureMask);        } else        {            vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height,                    flags, theCmap, "x11", title);        }        XSync(mDisplay, False);        vo_x11_selectinput_witherr(mDisplay, vo_window,                                   StructureNotifyMask | KeyPressMask |                                   PropertyChangeMask | ExposureMask |                                   ((WinID ==                                     0) ? 0 : (ButtonPressMask |                                               ButtonReleaseMask |                                               PointerMotionMask)));#ifdef HAVE_XF86VM        if (vm)        {            /* Grab the mouse pointer in our window */            if (vo_grabpointer)                XGrabPointer(mDisplay, vo_window, True, 0,                             GrabModeAsync, GrabModeAsync,                             vo_window, None, CurrentTime);            XSetInputFocus(mDisplay, vo_window, RevertToNone, CurrentTime);        }#endif    }    if (vo_gc != None)        XFreeGC(mDisplay, vo_gc);    vo_gc = XCreateGC(mDisplay, vo_window, 0L, &xgcv);    if (myximage)    {        freeMyXImage();        sws_freeContext(swsContext);    }    getMyXImage();    if (!WinID)    {        vo_dwidth = vo_screenwidth;        vo_dheight = vo_screenheight;    }    while (fmte->mpfmt) {      if (IMGFMT_RGB_DEPTH(fmte->mpfmt) == myximage->bits_per_pixel &&          fmte->byte_order == myximage->byte_order &&          fmte->red_mask   == myximage->red_mask   &&          fmte->green_mask == myximage->green_mask &&          fmte->blue_mask  == myximage->blue_mask)        break;      fmte++;    }    if (!fmte->mpfmt) {      mp_msg(MSGT_VO, MSGL_ERR,             "X server image format not supported, please contact the developers\n");      return -1;    }    out_format = fmte->mpfmt;    switch ((bpp = myximage->bits_per_pixel))    {        case 24:            draw_alpha_fnc = draw_alpha_24;            break;        case 32:            draw_alpha_fnc = draw_alpha_32;            break;        case 15:        case 16:            if (depth == 15)                draw_alpha_fnc = draw_alpha_15;            else                draw_alpha_fnc = draw_alpha_16;            break;        default:            draw_alpha_fnc = draw_alpha_null;    }    out_offset = 0;    // for these formats conversion is currently not support and    // we can easily "emulate" them.    if (out_format & 64 && (IMGFMT_IS_RGB(out_format) || IMGFMT_IS_BGR(out_format))) {      out_format &= ~64;#ifdef WORDS_BIGENDIAN      out_offset = 1;#else      out_offset = -1;#endif    }    /* always allocate swsContext as size could change between frames */    swsContext =        sws_getContextFromCmdLine(width, height, in_format, width, height,                                  out_format);    if (!swsContext)        return -1;    dst_width = width;    //printf( "X11 bpp: %d  color mask:  R:%lX  G:%lX  B:%lX\n",bpp,myximage->red_mask,myximage->green_mask,myximage->blue_mask );    if (vo_ontop)        vo_x11_setlayer(mDisplay, vo_window, vo_ontop);    return 0;}static void Display_Image(XImage * myximage, uint8_t * ImageData){    myximage->data += out_offset;#ifdef HAVE_SHM    if (Shmem_Flag)    {        XShmPutImage(mDisplay, vo_window, vo_gc, myximage,                     0, 0,                     (vo_dwidth - dst_width) / 2,                     (vo_dheight - myximage->height) / 2, dst_width,                     myximage->height, True);    } else#endif    {        XPutImage(mDisplay, vo_window, vo_gc, myximage,                  0, 0,                  (vo_dwidth - dst_width) / 2,                  (vo_dheight - myximage->height) / 2, dst_width,                  myximage->height);    }    myximage->data -= out_offset;}static void draw_osd(void){    vo_draw_text(image_width, image_height, draw_alpha_fnc);}static void flip_page(void){    Display_Image(myximage, ImageData);    XSync(mDisplay, False);}static int draw_slice(uint8_t * src[], int stride[], int w, int h,                           int x, int y){    uint8_t *dst[3];    int dstStride[3];    if ((old_vo_dwidth != vo_dwidth         || old_vo_dheight != vo_dheight) /*&& y==0 */  && zoomFlag)    {        int newW = vo_dwidth;        int newH = vo_dheight;        int newAspect = (newW * (1 << 16) + (newH >> 1)) / newH;        struct SwsContext *oldContext = swsContext;        if (newAspect > aspect)            newW = (newH * aspect + (1 << 15)) >> 16;        else            newH = ((newW << 16) + (aspect >> 1)) / aspect;        old_vo_dwidth = vo_dwidth;        old_vo_dheight = vo_dheight;        if (sws_flags == 0)            newW &= (~31);      // not needed but, if the user wants the FAST_BILINEAR SCALER, then its needed        swsContext = sws_getContextFromCmdLine(srcW, srcH, in_format,                                               newW, newH, out_format);        if (swsContext)        {            image_width = (newW + 7) & (~7);            image_height = newH;            freeMyXImage();            getMyXImage();            sws_freeContext(oldContext);        } else        {            swsContext = oldContext;        }        dst_width = newW;    }    dstStride[1] = dstStride[2] = 0;    dst[1] = dst[2] = NULL;    dstStride[0] = image_width * ((bpp + 7) / 8);    dst[0] = ImageData;    if (Flip_Flag)    {        dst[0] += dstStride[0] * (image_height - 1);        dstStride[0] = -dstStride[0];    }    sws_scale_ordered(swsContext, src, stride, y, h, dst, dstStride);    return 0;}static int draw_frame(uint8_t * src[]){#if 0    int stride[3] = { 0, 0, 0 };    if (in_format == IMGFMT_YUY2)        stride[0] = srcW * 2;    else if (in_format == IMGFMT_BGR8)        stride[0] = srcW;    else if (in_format == IMGFMT_BGR15)        stride[0] = srcW * 2;    else if (in_format == IMGFMT_BGR16)        stride[0] = srcW * 2;    else if (in_format == IMGFMT_BGR24)        stride[0] = srcW * 3;    else if (in_format == IMGFMT_BGR32)        stride[0] = srcW * 4;    return draw_slice(src, stride, srcW, srcH, 0, 0);#else    mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_X11_DrawFrameCalled);    return -1;#endif}static uint32_t get_image(mp_image_t * mpi){    if (zoomFlag ||        !IMGFMT_IS_BGR(mpi->imgfmt) ||        (IMGFMT_BGR_DEPTH(mpi->imgfmt) != vo_depthonscreen) ||        ((mpi->type != MP_IMGTYPE_STATIC)         && (mpi->type != MP_IMGTYPE_TEMP))        || (mpi->flags & MP_IMGFLAG_PLANAR)        || (mpi->flags & MP_IMGFLAG_YUV) || (mpi->width != image_width)        || (mpi->height != image_height))        return (VO_FALSE);    if (Flip_Flag)    {        mpi->stride[0] = -image_width * ((bpp + 7) / 8);        mpi->planes[0] = ImageData - mpi->stride[0] * (image_height - 1);    } else    {        mpi->stride[0] = image_width * ((bpp + 7) / 8);        mpi->planes[0] = ImageData;    }    mpi->flags |= MP_IMGFLAG_DIRECT;    return (VO_TRUE);}static int query_format(uint32_t format){    mp_msg(MSGT_VO, MSGL_DBG2,           "vo_x11: query_format was called: %x (%s)\n", format,           vo_format_name(format));    if (IMGFMT_IS_BGR(format))    {        if (IMGFMT_BGR_DEPTH(format) <= 8)            return 0;           // TODO 8bpp not yet fully implemented        if (IMGFMT_BGR_DEPTH(format) == vo_depthonscreen)            return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD | VFCAP_SWSCALE | VFCAP_FLIP |                VFCAP_ACCEPT_STRIDE;        else            return VFCAP_CSP_SUPPORTED | VFCAP_OSD | VFCAP_SWSCALE | VFCAP_FLIP |                VFCAP_ACCEPT_STRIDE;    }    switch (format)    {//   case IMGFMT_BGR8:  //   case IMGFMT_BGR15://   case IMGFMT_BGR16://   case IMGFMT_BGR24://   case IMGFMT_BGR32://    return 0x2;//   case IMGFMT_YUY2:         case IMGFMT_I420:        case IMGFMT_IYUV:        case IMGFMT_YV12:            return VFCAP_CSP_SUPPORTED | VFCAP_OSD | VFCAP_SWSCALE | VFCAP_ACCEPT_STRIDE;    }    return 0;}static void uninit(void){    if (!myximage)        return;    freeMyXImage();#ifdef HAVE_XF86VM    vo_vm_close(mDisplay);#endif    zoomFlag = 0;    vo_x11_uninit();    sws_freeContext(swsContext);}static int preinit(const char *arg){    if (arg)    {        mp_msg(MSGT_VO, MSGL_ERR, "vo_x11: Unknown subdevice: %s\n", arg);        return ENOSYS;    }    if (!vo_init())        return -1;              // Can't open X11    return 0;}static int control(uint32_t request, void *data, ...){    switch (request)    {        case VOCTRL_PAUSE:            return (int_pause = 1);        case VOCTRL_RESUME:            return (int_pause = 0);        case VOCTRL_QUERY_FORMAT:            return query_format(*((uint32_t *) data));        case VOCTRL_GUISUPPORT:            return VO_TRUE;        case VOCTRL_GET_IMAGE:            return get_image(data);        case VOCTRL_SET_EQUALIZER:            {                va_list ap;                int value;                va_start(ap, data);                value = va_arg(ap, int);                va_end(ap);                return vo_x11_set_equalizer(data, value);            }        case VOCTRL_GET_EQUALIZER:            {                va_list ap;                int *value;                va_start(ap, data);                value = va_arg(ap, int *);                va_end(ap);                return vo_x11_get_equalizer(data, value);            }        case VOCTRL_ONTOP:            vo_x11_ontop();            return VO_TRUE;        case VOCTRL_FULLSCREEN:            {                vo_x11_fullscreen();                vo_x11_clearwindow(mDisplay, vo_window);            }            return VO_TRUE;        case VOCTRL_UPDATE_SCREENINFO:            update_xinerama_info();            return VO_TRUE;    }    return VO_NOTIMPL;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?