VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxUhgsmiBase.h@ 39130

Last change on this file since 39130 was 36867, checked in by vboxsync, 14 years ago

Additions/Video: display/miniport drivers

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