third_party/virtualbox/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win.cpp
/** Get IDirect3DSurface9 for the given face and mipmap.
 */
Get IDirect3DSurface9 for the given face and mipmap.
Get IDirect3DSurface9 for the given face and mipmap .
int vmsvga3dGetD3DSurface(PVMSVGA3DCONTEXT pContext,
                          PVMSVGA3DSURFACE pSurface,
                          uint32_t face,
                          uint32_t mipmap,
                          bool fLockable,
                          IDirect3DSurface9 **ppD3DSurf)
{
    AssertPtrReturn(pSurface->u.pSurface, VERR_INVALID_PARAMETER);
    IDirect3DBaseTexture9 *pTexture;
    if (fLockable && pSurface->bounce.pTexture)
       pTexture = pSurface->bounce.pTexture;
    else
       pTexture = pSurface->u.pTexture;
#ifndef VBOX_VMSVGA3D_WITH_WINE_OPENGL
    if (pSurface->idAssociatedContext != pContext->id)
    {
        AssertMsgReturn(!fLockable,
                        ("Lockable surface must be from the same context (surface cid = %d, req cid = %d)",
                         pSurface->idAssociatedContext, pContext->id),
                        VERR_INVALID_PARAMETER);
        if (   pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE
            || pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE)
        {
            LogFunc(("using texture sid=%x created for another context (%d vs %d)\n",
                     pSurface->id, pSurface->idAssociatedContext, pContext->id));
            PVMSVGA3DSHAREDSURFACE pSharedSurface = vmsvga3dSurfaceGetSharedCopy(pContext, pSurface);
            AssertReturn(pSharedSurface, VERR_INTERNAL_ERROR);
            pTexture = pSharedSurface->u.pTexture;
        }
        else
        {
            AssertMsgFailed(("surface sid=%x created for another context (%d vs %d)\n",
                            pSurface->id, pSurface->idAssociatedContext, pContext->id));
        }
    }
#else
    RT_NOREF(pContext);
#endif
    if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE)
    {
        Assert(pSurface->cFaces == 6);
        IDirect3DCubeTexture9 *p = (IDirect3DCubeTexture9 *)pTexture;
        D3DCUBEMAP_FACES FaceType = vmsvga3dCubemapFaceFromIndex(face);
        HRESULT hr = p->GetCubeMapSurface(FaceType, mipmap, ppD3DSurf);
        AssertMsgReturn(hr == D3D_OK, ("GetCubeMapSurface failed with %x\n", hr), VERR_INTERNAL_ERROR);
    }
    else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE)
    {
        Assert(pSurface->cFaces == 1);
        Assert(face == 0);
        IDirect3DTexture9 *p = (IDirect3DTexture9 *)pTexture;
        HRESULT hr = p->GetSurfaceLevel(mipmap, ppD3DSurf);
        AssertMsgReturn(hr == D3D_OK, ("GetSurfaceLevel failed with %x\n", hr), VERR_INTERNAL_ERROR);
    }
    else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_SURFACE)
    {
        pSurface->u.pSurface->AddRef();
        *ppD3DSurf = pSurface->u.pSurface;
    }
    else
    {
        AssertMsgFailedReturn(("No surface for type %d\n", pSurface->enmD3DResType), VERR_INTERNAL_ERROR);
    }
    return VINF_SUCCESS;
}
int vmsvga3dGetD3DSurface ( PVMSVGA3DCONTEXT pContext , PVMSVGA3DSURFACE pSurface , uint32_t face , uint32_t mipmap , bool fLockable , IDirect3DSurface9 * * ppD3DSurf ) { AssertPtrReturn ( pSurface -> u . pSurface , VERR_INVALID_PARAMETER ) ; IDirect3DBaseTexture9 * pTexture ; if ( fLockable && pSurface -> bounce . pTexture ) pTexture = pSurface -> bounce . pTexture ; else pTexture = pSurface -> u . pTexture ; #ifndef VBOX_VMSVGA3D_WITH_WINE_OPENGL if ( pSurface -> idAssociatedContext != pContext -> id ) { AssertMsgReturn ( ! fLockable , ( " " , pSurface -> idAssociatedContext , pContext -> id ) , VERR_INVALID_PARAMETER ) ; if ( pSurface -> enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE || pSurface -> enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE ) { LogFunc ( ( " \n " , pSurface -> id , pSurface -> idAssociatedContext , pContext -> id ) ) ; PVMSVGA3DSHAREDSURFACE pSharedSurface = vmsvga3dSurfaceGetSharedCopy ( pContext , pSurface ) ; AssertReturn ( pSharedSurface , VERR_INTERNAL_ERROR ) ; pTexture = pSharedSurface -> u . pTexture ; } else { AssertMsgFailed ( ( " \n " , pSurface -> id , pSurface -> idAssociatedContext , pContext -> id ) ) ; } } #else RT_NOREF ( pContext ) ; #endif if ( pSurface -> enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE ) { Assert ( pSurface -> cFaces == 6 ) ; IDirect3DCubeTexture9 * p = ( IDirect3DCubeTexture9 * ) pTexture ; D3DCUBEMAP_FACES FaceType = vmsvga3dCubemapFaceFromIndex ( face ) ; HRESULT hr = p -> GetCubeMapSurface ( FaceType , mipmap , ppD3DSurf ) ; AssertMsgReturn ( hr == D3D_OK , ( " \n " , hr ) , VERR_INTERNAL_ERROR ) ; } else if ( pSurface -> enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE ) { Assert ( pSurface -> cFaces == 1 ) ; Assert ( face == 0 ) ; IDirect3DTexture9 * p = ( IDirect3DTexture9 * ) pTexture ; HRESULT hr = p -> GetSurfaceLevel ( mipmap , ppD3DSurf ) ; AssertMsgReturn ( hr == D3D_OK , ( " \n " , hr ) , VERR_INTERNAL_ERROR ) ; } else if ( pSurface -> enmD3DResType == VMSVGA3D_D3DRESTYPE_SURFACE ) { pSurface -> u . pSurface -> AddRef ( ) ; * ppD3DSurf = pSurface -> u . pSurface ; } else { AssertMsgFailedReturn ( ( " \n " , pSurface -> enmD3DResType ) , VERR_INTERNAL_ERROR ) ; } return VINF_SUCCESS ; }
Get IDirect3DSurface9 for the given face and mipmap.
Get IDirect3DSurface9 for the given face and mipmap .