コード例 #1
0
ファイル: DXSurfaceDevice.cpp プロジェクト: hongxchen/DXVideo
HRESULT CDXSurfaceDevice9::OpenShareSurface(HANDLE hShare, IUnknown **ppSurface, UINT w, UINT h, D3DFORMAT format)
{

    DXGI_FORMAT DxgiFormat;

    // If the format is not cross api shareable the utility function will return
    // D3DFMT_UNKNOWN
    if ((DxgiFormat = D3D9FormatToCrossAPIDXGI(format)) == D3DFMT_UNKNOWN)
    {
        return E_INVALIDARG;
    }

    HRESULT hr = S_OK;
    IDirect3DTexture9 *pTexture = NULL;

    hr = m_pDevice->CreateTexture(w, h, 1, D3DUSAGE_RENDERTARGET, format, D3DPOOL_DEFAULT, &pTexture, &hShare);
    if (S_OK == hr && pTexture)
    {
        // Store the shared handle
        hr = pTexture->SetPrivateData(SharedHandleGuid, &hShare, sizeof(HANDLE), 0);

        if (S_OK != hr)
            hr = GetSurfaceFromTexture(pTexture, (IDirect3DSurface9 **)ppSurface);

        SAFE_RELEASE(pTexture)
    }