VirtualBox

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

Last change on this file since 33676 was 33241, checked in by vboxsync, 14 years ago

wddm/3d: chromium hgsmi working (still disabled to make some cleaning)

  • 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 HVBOXCRHGSMI_CLIENT hClient;
35} VBOXUHGSMI_PRIVATE_BASE, *PVBOXUHGSMI_PRIVATE_BASE;
36
37typedef struct VBOXUHGSMI_BUFFER_PRIVATE_BASE
38{
39 VBOXUHGSMI_BUFFER Base;
40 D3DKMT_HANDLE hAllocation;
41} VBOXUHGSMI_BUFFER_PRIVATE_BASE, *PVBOXUHGSMI_BUFFER_PRIVATE_BASE;
42
43#define VBOXUHGSMIBASE_GET_PRIVATE(_p, _t) ((_t*)(((uint8_t*)_p) - RT_OFFSETOF(_t, Base)))
44#define VBOXUHGSMIBASE_GET(_p) VBOXUHGSMIBASE_GET_PRIVATE(_p, VBOXUHGSMI_PRIVATE_BASE)
45#define VBOXUHGSMIBASE_GET_BUFFER(_p) VBOXUHGSMIBASE_GET_PRIVATE(_p, VBOXUHGSMI_BUFFER_PRIVATE_BASE)
46
47
48DECLINLINE(int) vboxUhgsmiBaseLockData(PVBOXUHGSMI_BUFFER pBuf, uint32_t offLock, uint32_t cbLock, VBOXUHGSMI_BUFFER_LOCK_FLAGS fFlags,
49 D3DDDICB_LOCKFLAGS *pfFlags, UINT *pNumPages, UINT* pPages)
50{
51 D3DDDICB_LOCKFLAGS fLockFlags;
52 fLockFlags.Value = 0;
53 if (fFlags.bLockEntire)
54 {
55 Assert(!offLock);
56 fLockFlags.LockEntire = 1;
57 }
58 else
59 {
60 if (!cbLock)
61 {
62 Assert(0);
63 return VERR_INVALID_PARAMETER;
64 }
65 if (offLock + cbLock > pBuf->cbBuffer)
66 {
67 Assert(0);
68 return VERR_INVALID_PARAMETER;
69 }
70
71 uint32_t iFirstPage = offLock >> 12;
72 uint32_t iAfterLastPage = (cbLock + 0xfff) >> 12;
73 uint32_t cPages = iAfterLastPage - iFirstPage;
74 uint32_t cBufPages = pBuf->cbBuffer >> 12;
75 Assert(cPages <= (cBufPages));
76
77 if (cPages == cBufPages)
78 {
79 *pNumPages = 0;
80 fLockFlags.LockEntire = 1;
81 }
82 else
83 {
84 *pNumPages = cPages;
85 for (UINT i = 0, j = iFirstPage; i < cPages; ++i, ++j)
86 {
87 pPages[i] = j;
88 }
89 }
90
91 }
92
93 fLockFlags.ReadOnly = fFlags.bReadOnly;
94 fLockFlags.WriteOnly = fFlags.bWriteOnly;
95 fLockFlags.DonotWait = fFlags.bDonotWait;
96// fLockFlags.Discard = fFlags.bDiscard;
97 *pfFlags = fLockFlags;
98 return VINF_SUCCESS;
99}
100
101DECLINLINE(int) vboxUhgsmiBaseEventChkCreate(VBOXUHGSMI_SYNCHOBJECT_TYPE enmSynchType, HVBOXUHGSMI_SYNCHOBJECT *phSynch, bool *pbSynchCreated)
102{
103 bool bSynchCreated = false;
104
105 switch (enmSynchType)
106 {
107 case VBOXUHGSMI_SYNCHOBJECT_TYPE_EVENT:
108 if (!*phSynch)
109 {
110 *phSynch = CreateEvent(
111 NULL, /* LPSECURITY_ATTRIBUTES lpEventAttributes */
112 FALSE, /* BOOL bManualReset */
113 FALSE, /* BOOL bInitialState */
114 NULL /* LPCTSTR lpName */
115 );
116 Assert(*phSynch);
117 if (!*phSynch)
118 {
119 DWORD winEr = GetLastError();
120 /* todo: translate winer */
121 return VERR_GENERAL_FAILURE;
122 }
123 bSynchCreated = true;
124 }
125 break;
126 case VBOXUHGSMI_SYNCHOBJECT_TYPE_SEMAPHORE:
127 if (!*phSynch)
128 {
129 *phSynch = CreateSemaphore(
130 NULL, /* LPSECURITY_ATTRIBUTES lpSemaphoreAttributes */
131 0, /* LONG lInitialCount */
132 (LONG)((~0UL) >> 1), /* LONG lMaximumCount */
133 NULL /* LPCTSTR lpName */
134 );
135 Assert(*phSynch);
136 if (!*phSynch)
137 {
138 DWORD winEr = GetLastError();
139 /* todo: translate winer */
140 return VERR_GENERAL_FAILURE;
141 }
142 bSynchCreated = true;
143 }
144 break;
145 case VBOXUHGSMI_SYNCHOBJECT_TYPE_NONE:
146 Assert(!*phSynch);
147 if (*phSynch)
148 return VERR_INVALID_PARAMETER;
149 break;
150 default:
151 Assert(0);
152 return VERR_INVALID_PARAMETER;
153 }
154 *pbSynchCreated = bSynchCreated;
155 return VINF_SUCCESS;
156}
157
158DECLINLINE(int) vboxUhgsmiBaseDmaFill(PVBOXUHGSMI_BUFFER_SUBMIT aBuffers, uint32_t cBuffers,
159 VOID* pCommandBuffer, UINT *pCommandBufferSize,
160 D3DDDI_ALLOCATIONLIST *pAllocationList, UINT AllocationListSize,
161 D3DDDI_PATCHLOCATIONLIST *pPatchLocationList, UINT PatchLocationListSize)
162{
163 const uint32_t cbDmaCmd = RT_OFFSETOF(VBOXWDDM_DMA_PRIVATEDATA_UM_CHROMIUM_CMD, aBufInfos[cBuffers]);
164 if (*pCommandBufferSize < cbDmaCmd)
165 {
166 Assert(0);
167 return VERR_GENERAL_FAILURE;
168 }
169 if (AllocationListSize < cBuffers)
170 {
171 Assert(0);
172 return VERR_GENERAL_FAILURE;
173 }
174
175 *pCommandBufferSize = cbDmaCmd;
176
177 PVBOXWDDM_DMA_PRIVATEDATA_UM_CHROMIUM_CMD pHdr = (PVBOXWDDM_DMA_PRIVATEDATA_UM_CHROMIUM_CMD)pCommandBuffer;
178 pHdr->Base.enmCmd = VBOXVDMACMD_TYPE_CHROMIUM_CMD;
179 pHdr->Base.u32CmdReserved = cBuffers;
180
181 PVBOXWDDM_UHGSMI_BUFFER_UI_SUBMIT_INFO pBufSubmInfo = pHdr->aBufInfos;
182
183 for (uint32_t i = 0; i < cBuffers; ++i)
184 {
185 PVBOXUHGSMI_BUFFER_SUBMIT pBufInfo = &aBuffers[i];
186 PVBOXUHGSMI_BUFFER_PRIVATE_BASE pBuffer = VBOXUHGSMIBASE_GET_BUFFER(pBufInfo->pBuf);
187
188 memset(pAllocationList, 0, sizeof (D3DDDI_ALLOCATIONLIST));
189 pAllocationList->hAllocation = pBuffer->hAllocation;
190 pAllocationList->Value = 0;
191 pAllocationList->WriteOperation = !pBufInfo->fFlags.bHostReadOnly;
192 pAllocationList->DoNotRetireInstance = pBufInfo->fFlags.bDoNotRetire;
193 pBufSubmInfo->fSubFlags = pBufInfo->fFlags;
194 if (pBufInfo->fFlags.bEntireBuffer)
195 {
196 pBufSubmInfo->offData = 0;
197 pBufSubmInfo->cbData = pBuffer->Base.cbBuffer;
198 }
199 else
200 {
201 pBufSubmInfo->offData = pBufInfo->offData;
202 pBufSubmInfo->cbData = pBufInfo->cbData;
203 }
204
205 ++pAllocationList;
206 ++pBufSubmInfo;
207 }
208
209 return VINF_SUCCESS;
210}
211
212#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