third_party/virtualbox/src/VBox/Devices/Graphics/DevVGA-SVGA3d-win.cpp
/* Get the shared surface copy or create a new one. */
Get the shared surface copy or create a new one.
Get the shared surface copy or create a new one .
static PVMSVGA3DSHAREDSURFACE vmsvga3dSurfaceGetSharedCopy(PVMSVGA3DCONTEXT pContext, PVMSVGA3DSURFACE pSurface)
{
    Assert(pSurface->hSharedObject);
    PVMSVGA3DSHAREDSURFACE pSharedSurface = (PVMSVGA3DSHAREDSURFACE)RTAvlU32Get(&pSurface->pSharedObjectTree, pContext->id);
    if (!pSharedSurface)
    {
        const uint32_t cWidth = pSurface->pMipmapLevels[0].mipmapSize.width;
        const uint32_t cHeight = pSurface->pMipmapLevels[0].mipmapSize.height;
        const uint32_t cDepth = pSurface->pMipmapLevels[0].mipmapSize.depth;
        const uint32_t numMipLevels = pSurface->faces[0].numMipLevels;
        LogFunc(("Create shared %stexture copy d3d (%d,%d,%d) cMip=%d usage %x format %x.\n",
                  pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE ? "volume " :
                  pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE ? "cube " :
                  pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE ? "" : "UNKNOWN!!!",
                  cWidth,
                  cHeight,
                  cDepth,
                  numMipLevels,
                  pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET,
                  pSurface->formatD3D));
        pSharedSurface = (PVMSVGA3DSHAREDSURFACE)RTMemAllocZ(sizeof(*pSharedSurface));
        AssertReturn(pSharedSurface, NULL);
        pSharedSurface->Core.Key = pContext->id;
        bool ret = RTAvlU32Insert(&pSurface->pSharedObjectTree, &pSharedSurface->Core);
        AssertReturn(ret, NULL);
        HRESULT hr;
        if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE)
            hr = pContext->pDevice->CreateVolumeTexture(cWidth,
                                                        cHeight,
                                                        cDepth,
                                                        numMipLevels,
                                                        pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET,
                                                        pSurface->formatD3D,
                                                        D3DPOOL_DEFAULT,
                                                        &pSharedSurface->u.pVolumeTexture,
                                                        &pSurface->hSharedObject);
        else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE)
            hr = pContext->pDevice->CreateCubeTexture(cWidth,
                                                      numMipLevels,
                                                      pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET,
                                                      pSurface->formatD3D,
                                                      D3DPOOL_DEFAULT,
                                                      &pSharedSurface->u.pCubeTexture,
                                                      &pSurface->hSharedObject);
        else if (pSurface->enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE)
            hr = pContext->pDevice->CreateTexture(cWidth,
                                                  cHeight,
                                                  numMipLevels,
                                                  pSurface->fUsageD3D | D3DUSAGE_RENDERTARGET,
                                                  pSurface->formatD3D,
                                                  D3DPOOL_DEFAULT,
                                                  &pSharedSurface->u.pTexture,
                                                  &pSurface->hSharedObject);
        else
            hr = E_FAIL;
        if (RT_LIKELY(hr == D3D_OK))
            ;
        else
        {
            AssertMsgFailed(("CreateTexture type %d failed with %x\n", pSurface->enmD3DResType, hr));
            RTAvlU32Remove(&pSurface->pSharedObjectTree, pContext->id);
            RTMemFree(pSharedSurface);
            return NULL;
        }
    }
    return pSharedSurface;
}
static PVMSVGA3DSHAREDSURFACE vmsvga3dSurfaceGetSharedCopy ( PVMSVGA3DCONTEXT pContext , PVMSVGA3DSURFACE pSurface ) { Assert ( pSurface -> hSharedObject ) ; PVMSVGA3DSHAREDSURFACE pSharedSurface = ( PVMSVGA3DSHAREDSURFACE ) RTAvlU32Get ( & pSurface -> pSharedObjectTree , pContext -> id ) ; if ( ! pSharedSurface ) { const uint32_t cWidth = pSurface -> pMipmapLevels [ 0 ] . mipmapSize . width ; const uint32_t cHeight = pSurface -> pMipmapLevels [ 0 ] . mipmapSize . height ; const uint32_t cDepth = pSurface -> pMipmapLevels [ 0 ] . mipmapSize . depth ; const uint32_t numMipLevels = pSurface -> faces [ 0 ] . numMipLevels ; LogFunc ( ( " \n " , pSurface -> enmD3DResType == VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE ? " " : pSurface -> enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE ? " " : pSurface -> enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE ? " " : " " , cWidth , cHeight , cDepth , numMipLevels , pSurface -> fUsageD3D | D3DUSAGE_RENDERTARGET , pSurface -> formatD3D ) ) ; pSharedSurface = ( PVMSVGA3DSHAREDSURFACE ) RTMemAllocZ ( sizeof ( * pSharedSurface ) ) ; AssertReturn ( pSharedSurface , NULL ) ; pSharedSurface -> Core . Key = pContext -> id ; bool ret = RTAvlU32Insert ( & pSurface -> pSharedObjectTree , & pSharedSurface -> Core ) ; AssertReturn ( ret , NULL ) ; HRESULT hr ; if ( pSurface -> enmD3DResType == VMSVGA3D_D3DRESTYPE_VOLUME_TEXTURE ) hr = pContext -> pDevice -> CreateVolumeTexture ( cWidth , cHeight , cDepth , numMipLevels , pSurface -> fUsageD3D | D3DUSAGE_RENDERTARGET , pSurface -> formatD3D , D3DPOOL_DEFAULT , & pSharedSurface -> u . pVolumeTexture , & pSurface -> hSharedObject ) ; else if ( pSurface -> enmD3DResType == VMSVGA3D_D3DRESTYPE_CUBE_TEXTURE ) hr = pContext -> pDevice -> CreateCubeTexture ( cWidth , numMipLevels , pSurface -> fUsageD3D | D3DUSAGE_RENDERTARGET , pSurface -> formatD3D , D3DPOOL_DEFAULT , & pSharedSurface -> u . pCubeTexture , & pSurface -> hSharedObject ) ; else if ( pSurface -> enmD3DResType == VMSVGA3D_D3DRESTYPE_TEXTURE ) hr = pContext -> pDevice -> CreateTexture ( cWidth , cHeight , numMipLevels , pSurface -> fUsageD3D | D3DUSAGE_RENDERTARGET , pSurface -> formatD3D , D3DPOOL_DEFAULT , & pSharedSurface -> u . pTexture , & pSurface -> hSharedObject ) ; else hr = E_FAIL ; if ( RT_LIKELY ( hr == D3D_OK ) ) ; else { AssertMsgFailed ( ( " \n " , pSurface -> enmD3DResType , hr ) ) ; RTAvlU32Remove ( & pSurface -> pSharedObjectTree , pContext -> id ) ; RTMemFree ( pSharedSurface ) ; return NULL ; } } return pSharedSurface ; }
Get the shared surface copy or create a new one.
Get the shared surface copy or create a new one .
/* Create shadow copy of the original shared texture.
         * Shared d3d resources require Vista+ and have some restrictions.
         * D3DUSAGE_RENDERTARGET is required for use as a StretchRect destination.
         */ /* likely */