VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxUhgsmiBase.h@ 34848

Last change on this file since 34848 was 33714, checked in by vboxsync, 14 years ago

wddm/3d: CrHgsmi cleanup, free resources correctly; 2D fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1/** @file
2 *
3 * VBoxVideo Display D3D User mode dll
4 *
5 * Copyright (C) 2010 Oracle Corporation
6 *
7 * This file is part of VirtualBox Open Source Edition (OSE), as
8 * available from http://www.virtualbox.org. This file is free software;
9 * you can redistribute it and/or modify it under the terms of the GNU
10 * General Public License (GPL) as published by the Free Software
11 * Foundation, in version 2 as it comes in the "COPYING" file of the
12 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
13 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
14 */
15#ifndef ___VBoxUhgsmiBase_h__
16#define ___VBoxUhgsmiBase_h__
17
18#include <VBox/VBoxUhgsmi.h>
19#include <VBox/VBoxCrHgsmi.h>
20
21#include <windows.h>
22#include <D3dkmthk.h>
23//#include <D3dumddi.h>
24#include "../../Miniport/wddm/VBoxVideoIf.h"
25
26
27#ifndef VBOX_WITH_CRHGSMI
28#error "VBOX_WITH_CRHGSMI not defined!"
29#endif
30
31typedef struct VBOXUHGSMI_PRIVATE_BASE
32{
33 VBOXUHGSMI Base;
34#ifdef VBOX_CRHGSMI_WITH_D3DDEV
35 HVBOXCRHGSMI_CLIENT hClient;
36#endif
37} VBOXUHGSMI_PRIVATE_BASE, *PVBOXUHGSMI_PRIVATE_BASE;
38
39typedef struct VBOXUHGSMI_BUFFER_PRIVATE_BASE
40{
41 VBOXUHGSMI_BUFFER Base;
42 D3DKMT_HANDLE hAllocation;
43} VBOXUHGSMI_BUFFER_PRIVATE_BASE, *PVBOXUHGSMI_BUFFER_PRIVATE_BASE;
44
45#define VBOXUHGSMIBASE_GET_PRIVATE(_p, _t) ((_t*)(((uint8_t*)_p) - RT_OFFSETOF(_t, Base)))
46#define VBOXUHGSMIBASE_GET(_p) VBOXUHGSMIBASE_GET_PRIVATE(_p, VBOXUHGSMI_PRIVATE_BASE)
47#define VBOXUHGSMIBASE_GET_BUFFER(_p) VBOXUHGSMIBASE_GET_PRIVATE(_p, VBOXUHGSMI_BUFFER_PRIVATE_BASE)
48
49
50DECLINLINE(int) vboxUhgsmiBaseLockData(PVBOXUHGSMI_BUFFER pBuf, uint32_t offLock, uint32_t cbLock, VBOXUHGSMI_BUFFER_LOCK_FLAGS fFlags,
51 D3DDDICB_LOCKFLAGS *pfFlags, UINT *pNumPages, UINT* pPages)
52{
53 D3DDDICB_LOCKFLAGS fLockFlags;
54 fLockFlags.Value = 0;
55 if (fFlags.bLockEntire)
56 {
57 Assert(!offLock);
58 fLockFlags.LockEntire = 1;
59 }
60 else
61 {
62 if (!cbLock)
63 {
64 Assert(0);
65 return VERR_INVALID_PARAMETER;
66 }
67 if (offLock + cbLock > pBuf->cbBuffer)
68 {
69 Assert(0);
70 return VERR_INVALID_PARAMETER;
71 }
72
73 uint32_t iFirstPage = offLock >> 12;
74 uint32_t iAfterLastPage = (cbLock + 0xfff) >> 12;
75 uint32_t cPages = iAfterLastPage - iFirstPage;
76 uint32_t cBufPages = pBuf->cbBuffer >> 12;
77 Assert(cPages <= (cBufPages));
78
79 if (cPages == cBufPages)
80 {
81 *pNumPages = 0;
82 fLockFlags.LockEntire = 1;
83 }
84 else
85 {
86 *pNumPages = cPages;
87 for (UINT i = 0, j = iFirstPage; i < cPages; ++i, ++j)
88 {
89 pPages[i] = j;
90 }
91 }
92
93 }
94
95 fLockFlags.ReadOnly = fFlags.bReadOnly;
96 fLockFlags.WriteOnly = fFlags.bWriteOnly;
97 fLockFlags.DonotWait = fFlags.bDonotWait;
98// fLockFlags.Discard = fFlags.bDiscard;
99 *pfFlags = fLockFlags;
100 return VINF_SUCCESS;
101}
102
103DECLINLINE(int) vboxUhgsmiBaseEventChkCreate(VBOXUHGSMI_SYNCHOBJECT_TYPE enmSynchType, HVBOXUHGSMI_SYNCHOBJECT *phSynch, bool *pbSynchCreated)
104{
105 bool bSynchCreated = false;
106
107 switch (enmSynchType)
108 {
109 case VBOXUHGSMI_SYNCHOBJECT_TYPE_EVENT:
110 if (!*phSynch)
111 {
112 *phSynch = CreateEvent(
113 NULL, /* LPSECURITY_ATTRIBUTES lpEventAttributes */
114 FALSE, /* BOOL bManualReset */
115 FALSE, /* BOOL bInitialState */
116 NULL /* LPCTSTR lpName */
117 );
118 Assert(*phSynch);
119 if (!*phSynch)
120 {
121 DWORD winEr = GetLastError();
122 /* todo: translate winer */
123 return VERR_GENERAL_FAILURE;
124 }
125 bSynchCreated = true;
126 }
127 break;
128 case VBOXUHGSMI_SYNCHOBJECT_TYPE_SEMAPHORE:
129 if (!*phSynch)
130 {
131 *phSynch = CreateSemaphore(
132 NULL, /* LPSECURITY_ATTRIBUTES lpSemaphoreAttributes */
133 0, /* LONG lInitialCount */
134 (LONG)((~0UL) >> 1), /* LONG lMaximumCount */
135 NULL /* LPCTSTR lpName */
136 );
137 Assert(*phSynch);
138 if (!*phSynch)
139 {
140 DWORD winEr = GetLastError();
141 /* todo: translate winer */
142 return VERR_GENERAL_FAILURE;
143 }
144 bSynchCreated = true;
145 }
146 break;
147 case VBOXUHGSMI_SYNCHOBJECT_TYPE_NONE:
148 Assert(!*phSynch);
149 if (*phSynch)
150 return VERR_INVALID_PARAMETER;
151 break;
152 default:
153 Assert(0);
154 return VERR_INVALID_PARAMETER;
155 }
156 *pbSynchCreated = bSynchCreated;
157 return VINF_SUCCESS;
158}
159
160DECLINLINE(int) vboxUhgsmiBaseDmaFill(PVBOXUHGSMI_BUFFER_SUBMIT aBuffers, uint32_t cBuffers,
161 VOID* pCommandBuffer, UINT *pCommandBufferSize,
162 D3DDDI_ALLOCATIONLIST *pAllocationList, UINT AllocationListSize,
163 D3DDDI_PATCHLOCATIONLIST *pPatchLocationList, UINT PatchLocationListSize)
164{
165 const uint32_t cbDmaCmd = RT_OFFSETOF(VBOXWDDM_DMA_PRIVATEDATA_UM_CHROMIUM_CMD, aBufInfos[cBuffers]);
166 if (*pCommandBufferSize < cbDmaCmd)
167 {
168 Assert(0);
169 return VERR_GENERAL_FAILURE;
170 }
171 if (AllocationListSize < cBuffers)
172 {
173 Assert(0);
174 return VERR_GENERAL_FAILURE;
175 }
176
177 *pCommandBufferSize = cbDmaCmd;
178
179 PVBOXWDDM_DMA_PRIVATEDATA_UM_CHROMIUM_CMD pHdr = (PVBOXWDDM_DMA_PRIVATEDATA_UM_CHROMIUM_CMD)pCommandBuffer;
180 pHdr->Base.enmCmd = VBOXVDMACMD_TYPE_CHROMIUM_CMD;
181 pHdr->Base.u32CmdReserved = cBuffers;
182
183 PVBOXWDDM_UHGSMI_BUFFER_UI_SUBMIT_INFO pBufSubmInfo = pHdr->aBufInfos;
184
185 for (uint32_t i = 0; i < cBuffers; ++i)
186 {
187 PVBOXUHGSMI_BUFFER_SUBMIT pBufInfo = &aBuffers[i];
188 PVBOXUHGSMI_BUFFER_PRIVATE_BASE pBuffer = VBOXUHGSMIBASE_GET_BUFFER(pBufInfo->pBuf);
189
190 memset(pAllocationList, 0, sizeof (D3DDDI_ALLOCATIONLIST));
191 pAllocationList->hAllocation = pBuffer->hAllocation;
192 pAllocationList->Value = 0;
193 pAllocationList->WriteOperation = !pBufInfo->fFlags.bHostReadOnly;
194 pAllocationList->DoNotRetireInstance = pBufInfo->fFlags.bDoNotRetire;
195 pBufSubmInfo->fSubFlags = pBufInfo->fFlags;
196 if (pBufInfo->fFlags.bEntireBuffer)
197 {
198 pBufSubmInfo->offData = 0;
199 pBufSubmInfo->cbData = pBuffer->Base.cbBuffer;
200 }
201 else
202 {
203 pBufSubmInfo->offData = pBufInfo->offData;
204 pBufSubmInfo->cbData = pBufInfo->cbData;
205 }
206
207 ++pAllocationList;
208 ++pBufSubmInfo;
209 }
210
211 return VINF_SUCCESS;
212}
213
214#endif /* #ifndef ___VBoxUhgsmiBase_h__ */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette