1 | /* $Id: VBoxD3DIf.h 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxVideo Display D3D User mode dll
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef GA_INCLUDED_SRC_WINNT_Graphics_Video_disp_wddm_VBoxD3DIf_h
|
---|
29 | #define GA_INCLUDED_SRC_WINNT_Graphics_Video_disp_wddm_VBoxD3DIf_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include "VBoxDispD3DCmn.h"
|
---|
35 |
|
---|
36 | D3DFORMAT vboxDDI2D3DFormat(D3DDDIFORMAT format);
|
---|
37 | D3DMULTISAMPLE_TYPE vboxDDI2D3DMultiSampleType(D3DDDIMULTISAMPLE_TYPE enmType);
|
---|
38 | D3DPOOL vboxDDI2D3DPool(D3DDDI_POOL enmPool);
|
---|
39 | D3DRENDERSTATETYPE vboxDDI2D3DRenderStateType(D3DDDIRENDERSTATETYPE enmType);
|
---|
40 | VBOXWDDMDISP_TSS_LOOKUP vboxDDI2D3DTestureStageStateType(D3DDDITEXTURESTAGESTATETYPE enmType);
|
---|
41 | DWORD vboxDDI2D3DUsage(D3DDDI_RESOURCEFLAGS fFlags);
|
---|
42 | DWORD vboxDDI2D3DLockFlags(D3DDDI_LOCKFLAGS fLockFlags);
|
---|
43 | D3DTEXTUREFILTERTYPE vboxDDI2D3DBltFlags(D3DDDI_BLTFLAGS fFlags);
|
---|
44 | D3DQUERYTYPE vboxDDI2D3DQueryType(D3DDDIQUERYTYPE enmType);
|
---|
45 | DWORD vboxDDI2D3DIssueQueryFlags(D3DDDI_ISSUEQUERYFLAGS Flags);
|
---|
46 |
|
---|
47 | HRESULT VBoxD3DIfCreateForRc(struct VBOXWDDMDISP_RESOURCE *pRc);
|
---|
48 | HRESULT VBoxD3DIfLockRect(struct VBOXWDDMDISP_RESOURCE *pRc, UINT iAlloc,
|
---|
49 | D3DLOCKED_RECT * pLockedRect,
|
---|
50 | CONST RECT *pRect,
|
---|
51 | DWORD fLockFlags);
|
---|
52 | HRESULT VBoxD3DIfUnlockRect(struct VBOXWDDMDISP_RESOURCE *pRc, UINT iAlloc);
|
---|
53 | void VBoxD3DIfLockUnlockMemSynch(struct VBOXWDDMDISP_ALLOCATION *pAlloc, D3DLOCKED_RECT *pLockInfo, RECT *pRect, bool bToLockInfo);
|
---|
54 |
|
---|
55 | IUnknown* vboxD3DIfCreateSharedPrimary(PVBOXWDDMDISP_ALLOCATION pAlloc);
|
---|
56 |
|
---|
57 |
|
---|
58 | /* NOTE: does NOT increment a ref counter! NO Release needed!! */
|
---|
59 | DECLINLINE(IUnknown*) vboxD3DIfGet(PVBOXWDDMDISP_ALLOCATION pAlloc)
|
---|
60 | {
|
---|
61 | if (pAlloc->pD3DIf)
|
---|
62 | return pAlloc->pD3DIf;
|
---|
63 |
|
---|
64 | #ifdef VBOX_WITH_VMSVGA3D_DX9
|
---|
65 | if (pAlloc->enmType == VBOXWDDM_ALLOC_TYPE_D3D)
|
---|
66 | return pAlloc->pRc->pDevice->pfnCreateSharedPrimary(pAlloc);
|
---|
67 | #endif
|
---|
68 |
|
---|
69 | if (pAlloc->enmType != VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE)
|
---|
70 | {
|
---|
71 | WARN(("dynamic creation is supported for VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE only!, current type is %d", pAlloc->enmType));
|
---|
72 | return NULL;
|
---|
73 | }
|
---|
74 |
|
---|
75 | Assert(pAlloc->pRc->pDevice->pfnCreateSharedPrimary);
|
---|
76 | return pAlloc->pRc->pDevice->pfnCreateSharedPrimary(pAlloc);
|
---|
77 | }
|
---|
78 |
|
---|
79 | /* on success increments the surface ref counter,
|
---|
80 | * i.e. one must call pSurf->Release() once the surface is not needed*/
|
---|
81 | DECLINLINE(HRESULT) VBoxD3DIfSurfGet(PVBOXWDDMDISP_RESOURCE pRc, UINT iAlloc, IDirect3DSurface9 **ppSurf)
|
---|
82 | {
|
---|
83 | HRESULT hr = S_OK;
|
---|
84 | Assert(pRc->cAllocations > iAlloc);
|
---|
85 | *ppSurf = NULL;
|
---|
86 | IUnknown* pD3DIf = vboxD3DIfGet(&pRc->aAllocations[iAlloc]);
|
---|
87 |
|
---|
88 | switch (pRc->aAllocations[0].enmD3DIfType)
|
---|
89 | {
|
---|
90 | case VBOXDISP_D3DIFTYPE_SURFACE:
|
---|
91 | {
|
---|
92 | IDirect3DSurface9 *pD3DIfSurf = (IDirect3DSurface9*)pD3DIf;
|
---|
93 | Assert(pD3DIfSurf);
|
---|
94 | pD3DIfSurf->AddRef();
|
---|
95 | *ppSurf = pD3DIfSurf;
|
---|
96 | break;
|
---|
97 | }
|
---|
98 | case VBOXDISP_D3DIFTYPE_TEXTURE:
|
---|
99 | {
|
---|
100 | /* @todo VBoxD3DIfSurfGet is typically used in Blt & ColorFill functions
|
---|
101 | * in this case, if texture is used as a destination,
|
---|
102 | * we should update sub-layers as well which is not done currently. */
|
---|
103 | IDirect3DTexture9 *pD3DIfTex = (IDirect3DTexture9*)pD3DIf;
|
---|
104 | IDirect3DSurface9 *pSurfaceLevel;
|
---|
105 | Assert(pD3DIfTex);
|
---|
106 | hr = pD3DIfTex->GetSurfaceLevel(iAlloc, &pSurfaceLevel);
|
---|
107 | Assert(hr == S_OK);
|
---|
108 | if (hr == S_OK)
|
---|
109 | {
|
---|
110 | *ppSurf = pSurfaceLevel;
|
---|
111 | }
|
---|
112 | break;
|
---|
113 | }
|
---|
114 | case VBOXDISP_D3DIFTYPE_CUBE_TEXTURE:
|
---|
115 | {
|
---|
116 | IDirect3DCubeTexture9 *pD3DIfCubeTex = (IDirect3DCubeTexture9*)pD3DIf;
|
---|
117 | IDirect3DSurface9 *pSurfaceLevel;
|
---|
118 | Assert(pD3DIfCubeTex);
|
---|
119 | hr = pD3DIfCubeTex->GetCubeMapSurface(VBOXDISP_CUBEMAP_INDEX_TO_FACE(pRc, iAlloc),
|
---|
120 | VBOXDISP_CUBEMAP_INDEX_TO_LEVEL(pRc, iAlloc), &pSurfaceLevel);
|
---|
121 | Assert(hr == S_OK);
|
---|
122 | if (hr == S_OK)
|
---|
123 | {
|
---|
124 | *ppSurf = pSurfaceLevel;
|
---|
125 | }
|
---|
126 | break;
|
---|
127 | }
|
---|
128 | default:
|
---|
129 | {
|
---|
130 | WARN(("unexpected enmD3DIfType %d", pRc->aAllocations[0].enmD3DIfType));
|
---|
131 | hr = E_FAIL;
|
---|
132 | break;
|
---|
133 | }
|
---|
134 | }
|
---|
135 | return hr;
|
---|
136 | }
|
---|
137 |
|
---|
138 | VOID VBoxD3DIfFillPresentParams(D3DPRESENT_PARAMETERS *pParams, PVBOXWDDMDISP_RESOURCE pRc, UINT cRTs);
|
---|
139 | HRESULT VBoxD3DIfDeviceCreateDummy(PVBOXWDDMDISP_DEVICE pDevice);
|
---|
140 |
|
---|
141 | DECLINLINE(IDirect3DDevice9*) VBoxD3DIfDeviceGet(PVBOXWDDMDISP_DEVICE pDevice)
|
---|
142 | {
|
---|
143 | if (pDevice->pDevice9If)
|
---|
144 | return pDevice->pDevice9If;
|
---|
145 |
|
---|
146 | #ifdef VBOXWDDMDISP_DEBUG
|
---|
147 | g_VBoxVDbgInternalDevice = pDevice;
|
---|
148 | #endif
|
---|
149 |
|
---|
150 | Assert(pDevice->pfnCreateDirect3DDevice);
|
---|
151 | HRESULT hr = pDevice->pfnCreateDirect3DDevice(pDevice);
|
---|
152 | Assert(hr == S_OK); NOREF(hr);
|
---|
153 | Assert(pDevice->pDevice9If);
|
---|
154 | return pDevice->pDevice9If;
|
---|
155 | }
|
---|
156 |
|
---|
157 | #define VBOXDISPMODE_IS_3D(_p) ((_p)->f3D)
|
---|
158 | #define VBOXDISP_D3DEV(_p) VBoxD3DIfDeviceGet(_p)
|
---|
159 |
|
---|
160 | #endif /* !GA_INCLUDED_SRC_WINNT_Graphics_Video_disp_wddm_VBoxD3DIf_h */
|
---|