VBoxD3DIf.h revision dc4c9f05c58012e8b1f0bfdd12b2e14fc2f228de
587e39a4b516e63e86e5616bb49eb4fd38656327slive/* $Id$ */
587e39a4b516e63e86e5616bb49eb4fd38656327slive
587e39a4b516e63e86e5616bb49eb4fd38656327slive/** @file
587e39a4b516e63e86e5616bb49eb4fd38656327slive * VBoxVideo Display D3D User mode dll
f2e55f27f49e34dcd7a066d1486a623a02a93ec7erikabele */
064ac48394fa2a3d65221c86feb200f2d11f88b0nd
587e39a4b516e63e86e5616bb49eb4fd38656327slive/*
f2e55f27f49e34dcd7a066d1486a623a02a93ec7erikabele * Copyright (C) 2012 Oracle Corporation
587e39a4b516e63e86e5616bb49eb4fd38656327slive *
587e39a4b516e63e86e5616bb49eb4fd38656327slive * This file is part of VirtualBox Open Source Edition (OSE), as
587e39a4b516e63e86e5616bb49eb4fd38656327slive * available from http://www.virtualbox.org. This file is free software;
587e39a4b516e63e86e5616bb49eb4fd38656327slive * you can redistribute it and/or modify it under the terms of the GNU
587e39a4b516e63e86e5616bb49eb4fd38656327slive * General Public License (GPL) as published by the Free Software
587e39a4b516e63e86e5616bb49eb4fd38656327slive * Foundation, in version 2 as it comes in the "COPYING" file of the
587e39a4b516e63e86e5616bb49eb4fd38656327slive * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
587e39a4b516e63e86e5616bb49eb4fd38656327slive * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
587e39a4b516e63e86e5616bb49eb4fd38656327slive */
587e39a4b516e63e86e5616bb49eb4fd38656327slive
587e39a4b516e63e86e5616bb49eb4fd38656327slive#ifndef ___VBoxDispD3DRcIf_h__
587e39a4b516e63e86e5616bb49eb4fd38656327slive#define ___VBoxDispD3DRcIf_h__
587e39a4b516e63e86e5616bb49eb4fd38656327slive
587e39a4b516e63e86e5616bb49eb4fd38656327slive#include "VBoxDispD3DCmn.h"
587e39a4b516e63e86e5616bb49eb4fd38656327slive
587e39a4b516e63e86e5616bb49eb4fd38656327slivestatic D3DFORMAT vboxDDI2D3DFormat(D3DDDIFORMAT format);
6a3d8d134c395506972ae3afc1c00ebddd9d2086sliveD3DMULTISAMPLE_TYPE vboxDDI2D3DMultiSampleType(D3DDDIMULTISAMPLE_TYPE enmType);
6a3d8d134c395506972ae3afc1c00ebddd9d2086sliveD3DPOOL vboxDDI2D3DPool(D3DDDI_POOL enmPool);
6a3d8d134c395506972ae3afc1c00ebddd9d2086sliveD3DRENDERSTATETYPE vboxDDI2D3DRenderStateType(D3DDDIRENDERSTATETYPE enmType);
439945dc3565e433010177ffb4e4841b98065d1dsliveVBOXWDDMDISP_TSS_LOOKUP vboxDDI2D3DTestureStageStateType(D3DDDITEXTURESTAGESTATETYPE enmType);
6a3d8d134c395506972ae3afc1c00ebddd9d2086sliveDWORD vboxDDI2D3DUsage(D3DDDI_RESOURCEFLAGS fFlags);
587e39a4b516e63e86e5616bb49eb4fd38656327sliveDWORD vboxDDI2D3DLockFlags(D3DDDI_LOCKFLAGS fLockFlags);
439945dc3565e433010177ffb4e4841b98065d1dsliveD3DTEXTUREFILTERTYPE vboxDDI2D3DBltFlags(D3DDDI_BLTFLAGS fFlags);
439945dc3565e433010177ffb4e4841b98065d1dsliveD3DQUERYTYPE vboxDDI2D3DQueryType(D3DDDIQUERYTYPE enmType);
439945dc3565e433010177ffb4e4841b98065d1dsliveDWORD vboxDDI2D3DIssueQueryFlags(D3DDDI_ISSUEQUERYFLAGS Flags);
439945dc3565e433010177ffb4e4841b98065d1dslive
439945dc3565e433010177ffb4e4841b98065d1dsliveHRESULT VBoxD3DIfCreateForRc(struct VBOXWDDMDISP_RESOURCE *pRc);
439945dc3565e433010177ffb4e4841b98065d1dsliveHRESULT VBoxD3DIfLockRect(struct VBOXWDDMDISP_RESOURCE *pRc, UINT iAlloc,
587e39a4b516e63e86e5616bb49eb4fd38656327slive D3DLOCKED_RECT * pLockedRect,
587e39a4b516e63e86e5616bb49eb4fd38656327slive CONST RECT *pRect,
587e39a4b516e63e86e5616bb49eb4fd38656327slive DWORD fLockFlags);
587e39a4b516e63e86e5616bb49eb4fd38656327sliveHRESULT VBoxD3DIfUnlockRect(struct VBOXWDDMDISP_RESOURCE *pRc, UINT iAlloc);
587e39a4b516e63e86e5616bb49eb4fd38656327slivevoid VBoxD3DIfLockUnlockMemSynch(struct VBOXWDDMDISP_ALLOCATION *pAlloc, D3DLOCKED_RECT *pLockInfo, RECT *pRect, bool bToLockInfo);
587e39a4b516e63e86e5616bb49eb4fd38656327slive
587e39a4b516e63e86e5616bb49eb4fd38656327slive/* NOTE: does NOT increment a ref counter! NO Release needed!! */
f2e55f27f49e34dcd7a066d1486a623a02a93ec7erikabeleDECLINLINE(IUnknown*) VBoxD3DIfGet(PVBOXWDDMDISP_ALLOCATION pAlloc)
587e39a4b516e63e86e5616bb49eb4fd38656327slive{
587e39a4b516e63e86e5616bb49eb4fd38656327slive if (pAlloc->pD3DIf)
587e39a4b516e63e86e5616bb49eb4fd38656327slive return pAlloc->pD3DIf;
587e39a4b516e63e86e5616bb49eb4fd38656327slive
587e39a4b516e63e86e5616bb49eb4fd38656327slive if (pAlloc->enmType != VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE)
587e39a4b516e63e86e5616bb49eb4fd38656327slive {
587e39a4b516e63e86e5616bb49eb4fd38656327slive WARN(("dynamic creation is supported for VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE only!, current type is %d", pAlloc->enmType));
f2e55f27f49e34dcd7a066d1486a623a02a93ec7erikabele return NULL;
f2e55f27f49e34dcd7a066d1486a623a02a93ec7erikabele }
064ac48394fa2a3d65221c86feb200f2d11f88b0nd
064ac48394fa2a3d65221c86feb200f2d11f88b0nd HRESULT hr = VBoxD3DIfCreateForRc(pAlloc->pRc);
f2e55f27f49e34dcd7a066d1486a623a02a93ec7erikabele if (!SUCCEEDED(hr))
f2e55f27f49e34dcd7a066d1486a623a02a93ec7erikabele {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd WARN(("VBoxD3DIfCreateForRc failed, hr 0x%x", hr));
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd return NULL;
587e39a4b516e63e86e5616bb49eb4fd38656327slive }
587e39a4b516e63e86e5616bb49eb4fd38656327slive
587e39a4b516e63e86e5616bb49eb4fd38656327slive Assert(pAlloc->pD3DIf);
587e39a4b516e63e86e5616bb49eb4fd38656327slive Assert(pAlloc->enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE);
587e39a4b516e63e86e5616bb49eb4fd38656327slive
587e39a4b516e63e86e5616bb49eb4fd38656327slive return pAlloc->pD3DIf;
587e39a4b516e63e86e5616bb49eb4fd38656327slive}
587e39a4b516e63e86e5616bb49eb4fd38656327slive
587e39a4b516e63e86e5616bb49eb4fd38656327slive/* on success increments the surface ref counter,
587e39a4b516e63e86e5616bb49eb4fd38656327slive * i.e. one must call pSurf->Release() once the surface is not needed*/
587e39a4b516e63e86e5616bb49eb4fd38656327sliveDECLINLINE(HRESULT) VBoxD3DIfSurfGet(PVBOXWDDMDISP_RESOURCE pRc, UINT iAlloc, IDirect3DSurface9 **ppSurf)
587e39a4b516e63e86e5616bb49eb4fd38656327slive{
587e39a4b516e63e86e5616bb49eb4fd38656327slive HRESULT hr = S_OK;
587e39a4b516e63e86e5616bb49eb4fd38656327slive Assert(pRc->cAllocations > iAlloc);
587e39a4b516e63e86e5616bb49eb4fd38656327slive *ppSurf = NULL;
587e39a4b516e63e86e5616bb49eb4fd38656327slive IUnknown* pD3DIf = VBoxD3DIfGet(&pRc->aAllocations[iAlloc]);
587e39a4b516e63e86e5616bb49eb4fd38656327slive
587e39a4b516e63e86e5616bb49eb4fd38656327slive switch (pRc->aAllocations[0].enmD3DIfType)
587e39a4b516e63e86e5616bb49eb4fd38656327slive {
65241490e40aa0c831988073eed0633dad10c6f2nd case VBOXDISP_D3DIFTYPE_SURFACE:
65241490e40aa0c831988073eed0633dad10c6f2nd {
587e39a4b516e63e86e5616bb49eb4fd38656327slive IDirect3DSurface9 *pD3DIfSurf = (IDirect3DSurface9*)pD3DIf;
587e39a4b516e63e86e5616bb49eb4fd38656327slive Assert(pD3DIfSurf);
587e39a4b516e63e86e5616bb49eb4fd38656327slive pD3DIfSurf->AddRef();
587e39a4b516e63e86e5616bb49eb4fd38656327slive *ppSurf = pD3DIfSurf;
587e39a4b516e63e86e5616bb49eb4fd38656327slive break;
65241490e40aa0c831988073eed0633dad10c6f2nd }
65241490e40aa0c831988073eed0633dad10c6f2nd case VBOXDISP_D3DIFTYPE_TEXTURE:
65241490e40aa0c831988073eed0633dad10c6f2nd {
587e39a4b516e63e86e5616bb49eb4fd38656327slive Assert(pRc->cAllocations == 1); /* <- VBoxD3DIfSurfGet is typically used in Blt & ColorFill functions
587e39a4b516e63e86e5616bb49eb4fd38656327slive * in this case, if texture is used as a destination,
587e39a4b516e63e86e5616bb49eb4fd38656327slive * we should update sub-layers as well which is not done currently
587e39a4b516e63e86e5616bb49eb4fd38656327slive * so for now check VBoxD3DIfSurfGet is used for one-level textures */
587e39a4b516e63e86e5616bb49eb4fd38656327slive IDirect3DTexture9 *pD3DIfTex = (IDirect3DTexture9*)pD3DIf;
587e39a4b516e63e86e5616bb49eb4fd38656327slive IDirect3DSurface9 *pSurfaceLevel;
587e39a4b516e63e86e5616bb49eb4fd38656327slive Assert(pD3DIfTex);
587e39a4b516e63e86e5616bb49eb4fd38656327slive hr = pD3DIfTex->GetSurfaceLevel(iAlloc, &pSurfaceLevel);
587e39a4b516e63e86e5616bb49eb4fd38656327slive Assert(hr == S_OK);
587e39a4b516e63e86e5616bb49eb4fd38656327slive if (hr == S_OK)
587e39a4b516e63e86e5616bb49eb4fd38656327slive {
587e39a4b516e63e86e5616bb49eb4fd38656327slive *ppSurf = pSurfaceLevel;
587e39a4b516e63e86e5616bb49eb4fd38656327slive }
587e39a4b516e63e86e5616bb49eb4fd38656327slive break;
587e39a4b516e63e86e5616bb49eb4fd38656327slive }
587e39a4b516e63e86e5616bb49eb4fd38656327slive case VBOXDISP_D3DIFTYPE_CUBE_TEXTURE:
587e39a4b516e63e86e5616bb49eb4fd38656327slive {
587e39a4b516e63e86e5616bb49eb4fd38656327slive Assert(0);
587e39a4b516e63e86e5616bb49eb4fd38656327slive IDirect3DCubeTexture9 *pD3DIfCubeTex = (IDirect3DCubeTexture9*)pD3DIf;
587e39a4b516e63e86e5616bb49eb4fd38656327slive IDirect3DSurface9 *pSurfaceLevel;
587e39a4b516e63e86e5616bb49eb4fd38656327slive Assert(pD3DIfCubeTex);
587e39a4b516e63e86e5616bb49eb4fd38656327slive hr = pD3DIfCubeTex->GetCubeMapSurface(VBOXDISP_CUBEMAP_INDEX_TO_FACE(pRc, iAlloc),
587e39a4b516e63e86e5616bb49eb4fd38656327slive VBOXDISP_CUBEMAP_INDEX_TO_LEVEL(pRc, iAlloc), &pSurfaceLevel);
587e39a4b516e63e86e5616bb49eb4fd38656327slive Assert(hr == S_OK);
587e39a4b516e63e86e5616bb49eb4fd38656327slive if (hr == S_OK)
587e39a4b516e63e86e5616bb49eb4fd38656327slive {
587e39a4b516e63e86e5616bb49eb4fd38656327slive *ppSurf = pSurfaceLevel;
587e39a4b516e63e86e5616bb49eb4fd38656327slive }
587e39a4b516e63e86e5616bb49eb4fd38656327slive break;
587e39a4b516e63e86e5616bb49eb4fd38656327slive }
default:
{
WARN(("unexpected enmD3DIfType %d", pRc->aAllocations[0].enmD3DIfType));
hr = E_FAIL;
break;
}
}
return hr;
}
VOID VBoxD3DIfFillPresentParams(D3DPRESENT_PARAMETERS *pParams, PVBOXWDDMDISP_RESOURCE pRc, UINT cRTs);
HRESULT VBoxD3DIfDeviceCreateDummy(PVBOXWDDMDISP_DEVICE pDevice);
DECLINLINE(IDirect3DDevice9*) VBoxD3DIfDeviceGet(PVBOXWDDMDISP_DEVICE pDevice)
{
if (pDevice->pDevice9If)
return pDevice->pDevice9If;
#ifdef VBOXWDDMDISP_DEBUG
g_VBoxVDbgInternalDevice = pDevice;
#endif
HRESULT hr = VBoxD3DIfDeviceCreateDummy(pDevice);
Assert(hr == S_OK);
Assert(pDevice->pDevice9If);
return pDevice->pDevice9If;
}
#define VBOXDISPMODE_IS_3D(_p) (!!((_p)->D3D.pD3D9If))
#ifdef VBOXDISP_EARLYCREATEDEVICE
#define VBOXDISP_D3DEV(_p) (_p)->pDevice9If
#else
#define VBOXDISP_D3DEV(_p) VBoxD3DIfDeviceGet(_p)
#endif
#endif /* ___VBoxDispD3DRcIf_h__ */