⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dx_drv.cpp

📁 audio-video-codecs.rar语音编解码器
💻 CPP
📖 第 1 页 / 共 3 页
字号:
            drv->dd_srf_primary->Release();
            drv->dd_srf_primary = NULL;
        }
        for (i = 0; i < num_b; ++i) bufs[i] = NULL;
    }
    DBG_SET("-");
    return;
}

/* -------------------------------------------------------------------------- */

/* vm_status */
VIDEO_DRV_SET_VIDEO_MODE_FUNC(umc_dx_SetVideoMode,driver,rect,mode)
{
#undef  FUNCTION
#define FUNCTION "umc_dx_SetVideoMode"
    vm_status   result  = VM_OK;
    DXDrv*      drv     = (DXDrv*)((NULL != driver)? driver->m_pDrv: NULL);
    Ipp32u      dwFlags;

    DBG_SET("+");
    if (VM_OK == result)
    {
        if (NULL == drv)
        {
            ERR_SET(VM_NULL_PTR, "null ptr");
        }
    }
    if (VM_OK == result)
    {
        drv->win_width  = rect->w;
        drv->win_height = rect->h;
        dwFlags = (VideoDrvFullScreen == mode)? DDSCL_EXCLUSIVE     |
                                                DDSCL_FULLSCREEN    |
                                                DDSCL_SETFOCUSWINDOW:
                                                DDSCL_NORMAL;
        if (FAILED(drv->dd_obj->SetCooperativeLevel(drv->win, dwFlags)))
        {
            ERR_SET(VM_OPERATION_FAILED, "IDirectDraw::SetCooperativeLevel");
        }
    }
    DBG_SET("-");
    return result;
}

/* -------------------------------------------------------------------------- */

/* void */
VIDEO_DRV_CLOSE_FUNC (umc_dx_Close, driver)
{
#undef  FUNCTION
#define FUNCTION "umc_dx_Close"
    vm_status   result  = VM_OK;
    DXDrv*      drv     = (DXDrv*)((NULL != driver)? driver->m_pDrv: NULL);

    DBG_SET("+");
    if (NULL == drv)
    {
        ERR_SET(VM_NULL_PTR, "null ptr");
    }
    if (VM_OK == result)
    {
        if (NULL != drv->dd_obj)
        {
            drv->dd_obj->Release();
            drv->dd_obj = NULL;
        }
        ippsFree(drv);
        driver->m_pDrv = NULL;
    }
    DBG_SET("-");
}

/* -------------------------------------------------------------------------- */

/* vm_status */
VIDEO_DRV_LOCK_SURFACE_FUNC(umc_dx_LockSurface,driver,srf,planes)
{
#undef  FUNCTION
#define FUNCTION "umc_dx_LockSurface"
    vm_status           result  = VM_OK;
    DXDrv*              drv     = (DXDrv*)((NULL != driver)? driver->m_pDrv: NULL);
    IDirectDrawSurface* overlay = (IDirectDrawSurface*)srf;
    HRESULT             hRes;
    bool                locked = false;
    Ipp32s              i;

    DBG_SET("+");
    if (NULL == drv)
    {
        ERR_SET(VM_NULL_PTR, "null ptr");
    }
    if (VM_OK == result)
    {
        while (false == locked)
        {
            hRes = overlay->Lock(0, &(drv->dd_srf_desc),
                                 DDLOCK_WAIT | DDLOCK_WRITEONLY, 0);
            switch (hRes)
            {
            case DDERR_SURFACELOST:
                drv->dd_srf_primary->Restore();
                overlay->Restore();
                break;
            case DDERR_WASSTILLDRAWING:
                Sleep(0);
                break;
            case DD_OK:
                planes[0].m_pPlane      = drv->dd_srf_desc.lpSurface;
                planes[0].m_nPitch      = drv->dd_srf_desc.lPitch;
                planes[0].m_nMemSize    = drv->dd_srf_desc.dwLinearSize;
                for (i = 1; i < VIDEO_DRV_MAX_PLANE_NUMBER; ++i)
                {
                    planes[i].m_pPlane      = NULL;
                    planes[i].m_nPitch      = 0;
                    planes[i].m_nMemSize    = 0;
                }
                locked = true;
                break;
            default: /* Error occured. */
                ERR_SET(VM_OPERATION_FAILED, "IDirectDrawSurface::Lock");
                locked = true;
                break;
            }
        }
    }
    DBG_SET("-");
    return result;
}

/* -------------------------------------------------------------------------- */

/* vm_status */
VIDEO_DRV_UNLOCK_SURFACE_FUNC (umc_dx_UnlockSurface, driver, srf)
{
#undef  FUNCTION
#define FUNCTION "umc_dx_UnlockSurface"
    vm_status           result  = VM_OK;
    DXDrv*              drv     = (DXDrv*)((NULL != driver)? driver->m_pDrv: NULL);
    IDirectDrawSurface* overlay = (IDirectDrawSurface*)srf;

    DBG_SET("+");
    if (NULL == drv)
    {
        ERR_SET(VM_NULL_PTR, "null ptr");
    }
    else
    {
        if (FAILED(overlay->Unlock(drv->dd_srf_desc.lpSurface)))
        {
            ERR_SET(VM_OPERATION_FAILED, "IDirectDrawSurface::Unlock");
        }
    }
    DBG_SET("-");
    return result;
}

/* -------------------------------------------------------------------------- */

/* vm_status */
VIDEO_DRV_RENDER_FRAME_FUNC (umc_dx_RenderFrame, driver, frame, rect)
{
#undef  FUNCTION
#define FUNCTION "umc_dx_RenderFrame"
    vm_status           result      = VM_OK;
    DXDrv*              drv         = (DXDrv*)((NULL != driver)? driver->m_pDrv: NULL);
    IDirectDrawSurface* overlay     = (IDirectDrawSurface*) frame;
    Ipp32u              show_cmd;
    HRESULT             hRes;
    ::RECT              src, dst_rec, dst_win, *dst = &dst_rec;

    DBG_SET("+");
    if (NULL == drv)
    {
        ERR_SET(VM_NULL_PTR, "null ptr");
    }
    if (VM_OK == result)
    {
        show_cmd = (drv->dd_support_overlay)? DDOVER_SHOW : DDOVER_HIDE;
        if (DDOVER_SHOW == show_cmd && drv->dd_support_colorkey)
            show_cmd |= DDOVER_KEYDEST;

        src.left    = 0;
        src.top     = 0;
        src.right   = driver->img_width;
        src.bottom  = driver->img_height;

        /* Getting window rectangle. */
        ::POINT pt = {0,0};
        ::ClientToScreen(drv->win, &pt);
        ::GetClientRect(drv->win, &dst_win);
        dst_win.left   += pt.x;
        dst_win.right  += pt.x;
        dst_win.top    += pt.y;
        dst_win.bottom += pt.y;
        if (NULL != rect)
        {
            dst->left    = rect->x;
            dst->top     = rect->y;
            dst->right   = rect->x + rect->w;
            dst->bottom  = rect->y + rect->h;
        }
        else
        {
            dst = &dst_win;
        }

        hRes = overlay->UpdateOverlay(&src, drv->dd_srf_primary,
                                       dst, show_cmd, 0);
        if (DDERR_INVALIDRECT == hRes)
        {
            dst = &dst_win;
            /* Too big rectangle for rendering (dst) specified,
             * trying to render in whole window.
             * Note: see bug #4012 for details.
             */
            DBG_SET("Update surface: invalid rectangle");
            hRes = overlay->UpdateOverlay(&src, drv->dd_srf_primary,
                                          dst, show_cmd, 0);
        }
        if (DDERR_INVALIDRECT == hRes)
        {
            dst = NULL;
            /* Too big rectangle for rendering (dst) specified,
             * trying to use default parameter (dst = NULL).
             * Note: this shouldn't ocuured.
             */
            DBG_SET("Update surface: invalid rectangle");
            hRes = overlay->UpdateOverlay(&src, drv->dd_srf_primary,
                                          NULL, show_cmd, 0);
        }
        if (DDERR_SURFACELOST == hRes)
        {
            HRESULT hR = DD_OK;
            if (SUCCEEDED(hR) && FAILED(overlay->IsLost()))
                hR = overlay->Restore();
            if (SUCCEEDED(hR) && FAILED(drv->dd_srf_primary->IsLost()))
                hR = drv->dd_srf_primary->Restore();
            if (SUCCEEDED(hR))
            {
                hRes = overlay->UpdateOverlay(&src, drv->dd_srf_primary,
                                               dst, show_cmd, 0);
                if (DDERR_INVALIDRECT == hRes)
                {
                    dst = &dst_win;
                    DBG_SET("Update surface: invalid rectangle");
                    hRes = overlay->UpdateOverlay(&src, drv->dd_srf_primary,
                                                dst, show_cmd, 0);
                }
                if (DDERR_INVALIDRECT == hRes)
                {
                    dst = NULL;
                    DBG_SET("Update surface: invalid rectangle");
                    hRes = overlay->UpdateOverlay(&src, drv->dd_srf_primary,
                                                NULL, show_cmd, 0);
                }
            }
            else hRes = hR;
        }
        if (FAILED(hRes))
        {
            ERR_SET(VM_OPERATION_FAILED, "update surface");
        }
    }
    DBG_SET("-");
    return result;
}

/* -------------------------------------------------------------------------- */

/* void* */
VIDEO_DRV_GET_WINDOW_FUNC(umc_dx_GetWindow, driver)
{
#undef  FUNCTION
#define FUNCTION "umc_dx_GetWindow"
    void*   win;
    DXDrv*  drv = (DXDrv*)((NULL != driver)? driver->m_pDrv: NULL);

    DBG_SET("+");
    if (NULL == drv)
    {
        win = NULL;
        DBG_SET("null ptr");
    }
    else
    {
        win = drv->win;
    }
    DBG_SET("-");
    return win;
}

/* -------------------------------------------------------------------------- */

#ifdef UMC_ENABLE_BLT_VIDEO_RENDER

#undef  MODULE
#define MODULE "BLT(DX driver extension)"

/* -------------------------------------------------------------------------- */

const VideoDrvSpec BLTVideoDrvSpec =
{
    VM_STRING(MODULE),
    VideoDrvFalse,
    VideoDrvVideoMemLibrary,
    umc_blt_Init,
    umc_blt_Close,
    umc_vdrv_CreateBuffers,
    umc_vdrv_FreeBuffers,
    umc_blt_CreateSurface,
    umc_blt_FreeSurface,
    umc_dx_LockSurface,
    umc_dx_UnlockSurface,
    umc_blt_RenderFrame,
    umc_blt_SetVideoMode,
    umc_dx_GetWindow,
    NULL
};

typedef DXDrv               BLTDrv;
typedef DXVideoDrvParams    BLTVideoDrvParams;

⌨️ 快捷键说明

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