VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVhwa.cpp@ 44528

Last change on this file since 44528 was 44528, checked in by vboxsync, 12 years ago

header (C) fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 40.8 KB
Line 
1/* $Id: VBoxMPVhwa.cpp 44528 2013-02-04 14:27:54Z vboxsync $ */
2
3/** @file
4 * VBox WDDM Miniport driver
5 */
6
7/*
8 * Copyright (C) 2012 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#include "VBoxMPWddm.h"
20#include "VBoxMPVhwa.h"
21
22#ifndef VBOXVHWA_WITH_SHGSMI
23# include <iprt/semaphore.h>
24# include <iprt/asm.h>
25#endif
26
27#define VBOXVHWA_PRIMARY_ALLOCATION(_pSrc) ((_pSrc)->pPrimaryAllocation)
28
29
30DECLINLINE(void) vboxVhwaHdrInit(VBOXVHWACMD* pHdr, D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId, VBOXVHWACMD_TYPE enmCmd)
31{
32 memset(pHdr, 0, sizeof(VBOXVHWACMD));
33 pHdr->iDisplay = srcId;
34 pHdr->rc = VERR_GENERAL_FAILURE;
35 pHdr->enmCmd = enmCmd;
36#ifndef VBOXVHWA_WITH_SHGSMI
37 pHdr->cRefs = 1;
38#endif
39}
40
41#ifdef VBOXVHWA_WITH_SHGSMI
42static int vboxVhwaCommandSubmitHgsmi(struct _DEVICE_EXTENSION* pDevExt, HGSMIOFFSET offDr)
43{
44 VBoxHGSMIGuestWrite(pDevExt, offDr);
45 return VINF_SUCCESS;
46}
47#else
48DECLINLINE(void) vbvaVhwaCommandRelease(PVBOXMP_DEVEXT pDevExt, VBOXVHWACMD* pCmd)
49{
50 uint32_t cRefs = ASMAtomicDecU32(&pCmd->cRefs);
51 Assert(cRefs < UINT32_MAX / 2);
52 if(!cRefs)
53 {
54 VBoxHGSMIBufferFree(&VBoxCommonFromDeviceExt(pDevExt)->guestCtx, pCmd);
55 }
56}
57
58DECLINLINE(void) vbvaVhwaCommandRetain(PVBOXMP_DEVEXT pDevExt, VBOXVHWACMD* pCmd)
59{
60 ASMAtomicIncU32(&pCmd->cRefs);
61}
62
63/* do not wait for completion */
64void vboxVhwaCommandSubmitAsynch(PVBOXMP_DEVEXT pDevExt, VBOXVHWACMD* pCmd, PFNVBOXVHWACMDCOMPLETION pfnCompletion, void * pContext)
65{
66 pCmd->GuestVBVAReserved1 = (uintptr_t)pfnCompletion;
67 pCmd->GuestVBVAReserved2 = (uintptr_t)pContext;
68 vbvaVhwaCommandRetain(pDevExt, pCmd);
69
70 VBoxHGSMIBufferSubmit(&VBoxCommonFromDeviceExt(pDevExt)->guestCtx, pCmd);
71
72 if(!(pCmd->Flags & VBOXVHWACMD_FLAG_HG_ASYNCH)
73 || ((pCmd->Flags & VBOXVHWACMD_FLAG_GH_ASYNCH_NOCOMPLETION)
74 && (pCmd->Flags & VBOXVHWACMD_FLAG_HG_ASYNCH_RETURNED)))
75 {
76 /* the command is completed */
77 pfnCompletion(pDevExt, pCmd, pContext);
78 }
79
80 vbvaVhwaCommandRelease(pDevExt, pCmd);
81}
82
83static DECLCALLBACK(void) vboxVhwaCompletionSetEvent(PVBOXMP_DEVEXT pDevExt, VBOXVHWACMD * pCmd, void * pvContext)
84{
85 RTSemEventSignal((RTSEMEVENT)pvContext);
86}
87
88void vboxVhwaCommandSubmitAsynchByEvent(PVBOXMP_DEVEXT pDevExt, VBOXVHWACMD* pCmd, RTSEMEVENT hEvent)
89{
90 vboxVhwaCommandSubmitAsynch(pDevExt, pCmd, vboxVhwaCompletionSetEvent, hEvent);
91}
92#endif
93
94void vboxVhwaCommandCheckCompletion(PVBOXMP_DEVEXT pDevExt)
95{
96 NTSTATUS Status = vboxWddmCallIsr(pDevExt);
97 Assert(Status == STATUS_SUCCESS);
98}
99
100VBOXVHWACMD* vboxVhwaCommandCreate(PVBOXMP_DEVEXT pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId, VBOXVHWACMD_TYPE enmCmd, VBOXVHWACMD_LENGTH cbCmd)
101{
102 vboxVhwaCommandCheckCompletion(pDevExt);
103#ifdef VBOXVHWA_WITH_SHGSMI
104 VBOXVHWACMD* pHdr = (VBOXVHWACMD*)VBoxSHGSMICommandAlloc(&pDevExt->u.primary.hgsmiAdapterHeap,
105 cbCmd + VBOXVHWACMD_HEADSIZE(),
106 HGSMI_CH_VBVA,
107 VBVA_VHWA_CMD);
108#else
109 VBOXVHWACMD* pHdr = (VBOXVHWACMD*)VBoxHGSMIBufferAlloc(&VBoxCommonFromDeviceExt(pDevExt)->guestCtx,
110 cbCmd + VBOXVHWACMD_HEADSIZE(),
111 HGSMI_CH_VBVA,
112 VBVA_VHWA_CMD);
113#endif
114 Assert(pHdr);
115 if (!pHdr)
116 {
117 LOGREL(("VBoxHGSMIBufferAlloc failed"));
118 }
119 else
120 {
121 vboxVhwaHdrInit(pHdr, srcId, enmCmd);
122 }
123
124 return pHdr;
125}
126
127void vboxVhwaCommandFree(PVBOXMP_DEVEXT pDevExt, VBOXVHWACMD* pCmd)
128{
129#ifdef VBOXVHWA_WITH_SHGSMI
130 VBoxSHGSMICommandFree(&pDevExt->u.primary.hgsmiAdapterHeap, pCmd);
131#else
132 vbvaVhwaCommandRelease(pDevExt, pCmd);
133#endif
134}
135
136int vboxVhwaCommandSubmit(PVBOXMP_DEVEXT pDevExt, VBOXVHWACMD* pCmd)
137{
138#ifdef VBOXVHWA_WITH_SHGSMI
139 const VBOXSHGSMIHEADER* pHdr = VBoxSHGSMICommandPrepSynch(&pDevExt->u.primary.hgsmiAdapterHeap, pCmd);
140 Assert(pHdr);
141 int rc = VERR_GENERAL_FAILURE;
142 if (pHdr)
143 {
144 do
145 {
146 HGSMIOFFSET offCmd = VBoxSHGSMICommandOffset(&pDevExt->u.primary.hgsmiAdapterHeap, pHdr);
147 Assert(offCmd != HGSMIOFFSET_VOID);
148 if (offCmd != HGSMIOFFSET_VOID)
149 {
150 rc = vboxVhwaCommandSubmitHgsmi(pDevExt, offCmd);
151 AssertRC(rc);
152 if (RT_SUCCESS(rc))
153 {
154 VBoxSHGSMICommandDoneSynch(&pDevExt->u.primary.hgsmiAdapterHeap, pHdr);
155 AssertRC(rc);
156 break;
157 }
158 }
159 else
160 rc = VERR_INVALID_PARAMETER;
161 /* fail to submit, cancel it */
162 VBoxSHGSMICommandCancelSynch(&pDevExt->u.primary.hgsmiAdapterHeap, pHdr);
163 } while (0);
164 }
165 else
166 rc = VERR_INVALID_PARAMETER;
167 return rc;
168#else
169 RTSEMEVENT hEvent;
170 int rc = RTSemEventCreate(&hEvent);
171 AssertRC(rc);
172 if (RT_SUCCESS(rc))
173 {
174 pCmd->Flags |= VBOXVHWACMD_FLAG_GH_ASYNCH_IRQ;
175 vboxVhwaCommandSubmitAsynchByEvent(pDevExt, pCmd, hEvent);
176 rc = RTSemEventWait(hEvent, RT_INDEFINITE_WAIT);
177 AssertRC(rc);
178 if (RT_SUCCESS(rc))
179 RTSemEventDestroy(hEvent);
180 }
181 return rc;
182#endif
183}
184
185#ifndef VBOXVHWA_WITH_SHGSMI
186static DECLCALLBACK(void) vboxVhwaCompletionFreeCmd(PVBOXMP_DEVEXT pDevExt, VBOXVHWACMD * pCmd, void * pContext)
187{
188 vboxVhwaCommandFree(pDevExt, pCmd);
189}
190
191void vboxVhwaCompletionListProcess(PVBOXMP_DEVEXT pDevExt, VBOXVTLIST *pList)
192{
193 PVBOXVTLIST_ENTRY pNext, pCur;
194 for (pCur = pList->pFirst; pCur; pCur = pNext)
195 {
196 /* need to save next since the command may be released in a pfnCallback and thus its data might be invalid */
197 pNext = pCur->pNext;
198 VBOXVHWACMD *pCmd = VBOXVHWA_LISTENTRY2CMD(pCur);
199 PFNVBOXVHWACMDCOMPLETION pfnCallback = (PFNVBOXVHWACMDCOMPLETION)pCmd->GuestVBVAReserved1;
200 void *pvCallback = (void*)pCmd->GuestVBVAReserved2;
201 pfnCallback(pDevExt, pCmd, pvCallback);
202 }
203}
204
205#endif
206
207void vboxVhwaCommandSubmitAsynchAndComplete(PVBOXMP_DEVEXT pDevExt, VBOXVHWACMD* pCmd)
208{
209#ifdef VBOXVHWA_WITH_SHGSMI
210# error "port me"
211#else
212 pCmd->Flags |= VBOXVHWACMD_FLAG_GH_ASYNCH_NOCOMPLETION;
213
214 vboxVhwaCommandSubmitAsynch(pDevExt, pCmd, vboxVhwaCompletionFreeCmd, NULL);
215#endif
216}
217
218void vboxVhwaFreeHostInfo1(PVBOXMP_DEVEXT pDevExt, VBOXVHWACMD_QUERYINFO1* pInfo)
219{
220 VBOXVHWACMD* pCmd = VBOXVHWACMD_HEAD(pInfo);
221 vboxVhwaCommandFree(pDevExt, pCmd);
222}
223
224void vboxVhwaFreeHostInfo2(PVBOXMP_DEVEXT pDevExt, VBOXVHWACMD_QUERYINFO2* pInfo)
225{
226 VBOXVHWACMD* pCmd = VBOXVHWACMD_HEAD(pInfo);
227 vboxVhwaCommandFree(pDevExt, pCmd);
228}
229
230VBOXVHWACMD_QUERYINFO1* vboxVhwaQueryHostInfo1(PVBOXMP_DEVEXT pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId)
231{
232 VBOXVHWACMD* pCmd = vboxVhwaCommandCreate(pDevExt, srcId, VBOXVHWACMD_TYPE_QUERY_INFO1, sizeof(VBOXVHWACMD_QUERYINFO1));
233 VBOXVHWACMD_QUERYINFO1 *pInfo1;
234
235 Assert(pCmd);
236 if (!pCmd)
237 {
238 LOGREL(("vboxVhwaCommandCreate failed"));
239 return NULL;
240 }
241
242 pInfo1 = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_QUERYINFO1);
243 pInfo1->u.in.guestVersion.maj = VBOXVHWA_VERSION_MAJ;
244 pInfo1->u.in.guestVersion.min = VBOXVHWA_VERSION_MIN;
245 pInfo1->u.in.guestVersion.bld = VBOXVHWA_VERSION_BLD;
246 pInfo1->u.in.guestVersion.reserved = VBOXVHWA_VERSION_RSV;
247
248 int rc = vboxVhwaCommandSubmit(pDevExt, pCmd);
249 AssertRC(rc);
250 if(RT_SUCCESS(rc))
251 {
252 if(RT_SUCCESS(pCmd->rc))
253 {
254 return VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_QUERYINFO1);
255 }
256 }
257
258 vboxVhwaCommandFree(pDevExt, pCmd);
259 return NULL;
260}
261
262VBOXVHWACMD_QUERYINFO2* vboxVhwaQueryHostInfo2(PVBOXMP_DEVEXT pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId, uint32_t numFourCC)
263{
264 VBOXVHWACMD* pCmd = vboxVhwaCommandCreate(pDevExt, srcId, VBOXVHWACMD_TYPE_QUERY_INFO2, VBOXVHWAINFO2_SIZE(numFourCC));
265 VBOXVHWACMD_QUERYINFO2 *pInfo2;
266 Assert(pCmd);
267 if (!pCmd)
268 {
269 LOGREL(("vboxVhwaCommandCreate failed"));
270 return NULL;
271 }
272
273 pInfo2 = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_QUERYINFO2);
274 pInfo2->numFourCC = numFourCC;
275
276 int rc = vboxVhwaCommandSubmit(pDevExt, pCmd);
277 AssertRC(rc);
278 if(RT_SUCCESS(rc))
279 {
280 AssertRC(pCmd->rc);
281 if(RT_SUCCESS(pCmd->rc))
282 {
283 if(pInfo2->numFourCC == numFourCC)
284 {
285 return pInfo2;
286 }
287 }
288 }
289
290 vboxVhwaCommandFree(pDevExt, pCmd);
291 return NULL;
292}
293
294int vboxVhwaEnable(PVBOXMP_DEVEXT pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId)
295{
296 int rc = VERR_GENERAL_FAILURE;
297 VBOXVHWACMD* pCmd;
298
299 pCmd = vboxVhwaCommandCreate(pDevExt, srcId, VBOXVHWACMD_TYPE_ENABLE, 0);
300 Assert(pCmd);
301 if (!pCmd)
302 {
303 LOGREL(("vboxVhwaCommandCreate failed"));
304 return rc;
305 }
306
307 rc = vboxVhwaCommandSubmit(pDevExt, pCmd);
308 AssertRC(rc);
309 if(RT_SUCCESS(rc))
310 {
311 AssertRC(pCmd->rc);
312 if(RT_SUCCESS(pCmd->rc))
313 rc = VINF_SUCCESS;
314 else
315 rc = pCmd->rc;
316 }
317
318 vboxVhwaCommandFree(pDevExt, pCmd);
319 return rc;
320}
321
322int vboxVhwaDisable(PVBOXMP_DEVEXT pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId)
323{
324 vboxVhwaCommandCheckCompletion(pDevExt);
325
326 int rc = VERR_GENERAL_FAILURE;
327 VBOXVHWACMD* pCmd;
328
329 pCmd = vboxVhwaCommandCreate(pDevExt, srcId, VBOXVHWACMD_TYPE_DISABLE, 0);
330 Assert(pCmd);
331 if (!pCmd)
332 {
333 LOGREL(("vboxVhwaCommandCreate failed"));
334 return rc;
335 }
336
337 rc = vboxVhwaCommandSubmit(pDevExt, pCmd);
338 AssertRC(rc);
339 if(RT_SUCCESS(rc))
340 {
341 if(RT_SUCCESS(pCmd->rc))
342 rc = VINF_SUCCESS;
343 else
344 rc = pCmd->rc;
345 }
346
347 vboxVhwaCommandFree(pDevExt, pCmd);
348 return rc;
349}
350
351DECLINLINE(VOID) vboxVhwaHlpOverlayListInit(PVBOXMP_DEVEXT pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
352{
353 PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[VidPnSourceId];
354 pSource->cOverlays = 0;
355 InitializeListHead(&pSource->OverlayList);
356 KeInitializeSpinLock(&pSource->OverlayListLock);
357}
358
359static void vboxVhwaInitSrc(PVBOXMP_DEVEXT pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID srcId)
360{
361 Assert(srcId < (D3DDDI_VIDEO_PRESENT_SOURCE_ID)VBoxCommonFromDeviceExt(pDevExt)->cDisplays);
362 VBOXVHWA_INFO *pSettings = &pDevExt->aSources[srcId].Vhwa.Settings;
363 memset (pSettings, 0, sizeof (VBOXVHWA_INFO));
364
365 vboxVhwaHlpOverlayListInit(pDevExt, srcId);
366
367 VBOXVHWACMD_QUERYINFO1* pInfo1 = vboxVhwaQueryHostInfo1(pDevExt, srcId);
368 if (pInfo1)
369 {
370 if ((pInfo1->u.out.cfgFlags & VBOXVHWA_CFG_ENABLED)
371 && pInfo1->u.out.numOverlays)
372 {
373 if ((pInfo1->u.out.caps & VBOXVHWA_CAPS_OVERLAY)
374 && (pInfo1->u.out.caps & VBOXVHWA_CAPS_OVERLAYSTRETCH)
375 && (pInfo1->u.out.surfaceCaps & VBOXVHWA_SCAPS_OVERLAY)
376 && (pInfo1->u.out.surfaceCaps & VBOXVHWA_SCAPS_FLIP)
377 && (pInfo1->u.out.surfaceCaps & VBOXVHWA_SCAPS_LOCALVIDMEM)
378 && pInfo1->u.out.numOverlays)
379 {
380 pSettings->fFlags |= VBOXVHWA_F_ENABLED;
381
382 if (pInfo1->u.out.caps & VBOXVHWA_CAPS_COLORKEY)
383 {
384 if (pInfo1->u.out.colorKeyCaps & VBOXVHWA_CKEYCAPS_SRCOVERLAY)
385 {
386 pSettings->fFlags |= VBOXVHWA_F_CKEY_SRC;
387 /* todo: VBOXVHWA_CKEYCAPS_SRCOVERLAYONEACTIVE ? */
388 }
389
390 if (pInfo1->u.out.colorKeyCaps & VBOXVHWA_CKEYCAPS_DESTOVERLAY)
391 {
392 pSettings->fFlags |= VBOXVHWA_F_CKEY_DST;
393 /* todo: VBOXVHWA_CKEYCAPS_DESTOVERLAYONEACTIVE ? */
394 }
395 }
396
397 pSettings->cOverlaysSupported = pInfo1->u.out.numOverlays;
398
399 pSettings->cFormats = 0;
400
401 pSettings->aFormats[pSettings->cFormats] = D3DDDIFMT_X8R8G8B8;
402 ++pSettings->cFormats;
403
404 if (pInfo1->u.out.numFourCC
405 && (pInfo1->u.out.caps & VBOXVHWA_CAPS_OVERLAYFOURCC))
406 {
407 VBOXVHWACMD_QUERYINFO2* pInfo2 = vboxVhwaQueryHostInfo2(pDevExt, srcId, pInfo1->u.out.numFourCC);
408 if (pInfo2)
409 {
410 for (uint32_t i = 0; i < pInfo2->numFourCC; ++i)
411 {
412 pSettings->aFormats[pSettings->cFormats] = (D3DDDIFORMAT)pInfo2->FourCC[i];
413 ++pSettings->cFormats;
414 }
415 vboxVhwaFreeHostInfo2(pDevExt, pInfo2);
416 }
417 }
418 }
419 }
420 vboxVhwaFreeHostInfo1(pDevExt, pInfo1);
421 }
422}
423
424void vboxVhwaInit(PVBOXMP_DEVEXT pDevExt)
425{
426 for (int i = 0; i < VBoxCommonFromDeviceExt(pDevExt)->cDisplays; ++i)
427 {
428 vboxVhwaInitSrc(pDevExt, (D3DDDI_VIDEO_PRESENT_SOURCE_ID)i);
429 }
430}
431
432void vboxVhwaFree(PVBOXMP_DEVEXT pDevExt)
433{
434 /* we do not allocate/map anything, just issue a Disable command
435 * to ensure all pending commands are flushed */
436 for (int i = 0; i < VBoxCommonFromDeviceExt(pDevExt)->cDisplays; ++i)
437 {
438 vboxVhwaDisable(pDevExt, i);
439 }
440}
441
442int vboxVhwaHlpTranslateFormat(VBOXVHWA_PIXELFORMAT *pFormat, D3DDDIFORMAT enmFormat)
443{
444 pFormat->Reserved = 0;
445 switch (enmFormat)
446 {
447 case D3DDDIFMT_A8R8G8B8:
448 case D3DDDIFMT_X8R8G8B8:
449 pFormat->flags = VBOXVHWA_PF_RGB;
450 pFormat->c.rgbBitCount = 32;
451 pFormat->m1.rgbRBitMask = 0xff0000;
452 pFormat->m2.rgbGBitMask = 0xff00;
453 pFormat->m3.rgbBBitMask = 0xff;
454 /* always zero for now */
455 pFormat->m4.rgbABitMask = 0;
456 return VINF_SUCCESS;
457 case D3DDDIFMT_R8G8B8:
458 pFormat->flags = VBOXVHWA_PF_RGB;
459 pFormat->c.rgbBitCount = 24;
460 pFormat->m1.rgbRBitMask = 0xff0000;
461 pFormat->m2.rgbGBitMask = 0xff00;
462 pFormat->m3.rgbBBitMask = 0xff;
463 /* always zero for now */
464 pFormat->m4.rgbABitMask = 0;
465 return VINF_SUCCESS;
466 case D3DDDIFMT_R5G6B5:
467 pFormat->flags = VBOXVHWA_PF_RGB;
468 pFormat->c.rgbBitCount = 16;
469 pFormat->m1.rgbRBitMask = 0xf800;
470 pFormat->m2.rgbGBitMask = 0x7e0;
471 pFormat->m3.rgbBBitMask = 0x1f;
472 /* always zero for now */
473 pFormat->m4.rgbABitMask = 0;
474 return VINF_SUCCESS;
475 case D3DDDIFMT_P8:
476 case D3DDDIFMT_A8:
477 case D3DDDIFMT_X1R5G5B5:
478 case D3DDDIFMT_A1R5G5B5:
479 case D3DDDIFMT_A4R4G4B4:
480 case D3DDDIFMT_R3G3B2:
481 case D3DDDIFMT_A8R3G3B2:
482 case D3DDDIFMT_X4R4G4B4:
483 case D3DDDIFMT_A2B10G10R10:
484 case D3DDDIFMT_A8B8G8R8:
485 case D3DDDIFMT_X8B8G8R8:
486 case D3DDDIFMT_G16R16:
487 case D3DDDIFMT_A2R10G10B10:
488 case D3DDDIFMT_A16B16G16R16:
489 case D3DDDIFMT_A8P8:
490 default:
491 {
492 uint32_t fourcc = vboxWddmFormatToFourcc(enmFormat);
493 Assert(fourcc);
494 if (fourcc)
495 {
496 pFormat->flags = VBOXVHWA_PF_FOURCC;
497 pFormat->fourCC = fourcc;
498 return VINF_SUCCESS;
499 }
500 return VERR_NOT_SUPPORTED;
501 }
502 }
503}
504
505int vboxVhwaHlpDestroySurface(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_ALLOCATION pSurf,
506 D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
507{
508 Assert(pSurf->hHostHandle);
509 if (!pSurf->hHostHandle)
510 return VERR_INVALID_STATE;
511
512 VBOXVHWACMD* pCmd = vboxVhwaCommandCreate(pDevExt, VidPnSourceId,
513 VBOXVHWACMD_TYPE_SURF_DESTROY, sizeof(VBOXVHWACMD_SURF_DESTROY));
514 Assert(pCmd);
515 if(pCmd)
516 {
517 VBOXVHWACMD_SURF_DESTROY * pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_DESTROY);
518
519 memset(pBody, 0, sizeof(VBOXVHWACMD_SURF_DESTROY));
520
521 pBody->u.in.hSurf = pSurf->hHostHandle;
522
523 /* we're not interested in completion, just send the command */
524 vboxVhwaCommandSubmitAsynchAndComplete(pDevExt, pCmd);
525
526 pSurf->hHostHandle = VBOXVHWA_SURFHANDLE_INVALID;
527
528 return VINF_SUCCESS;
529 }
530
531 return VERR_OUT_OF_RESOURCES;
532}
533
534int vboxVhwaHlpPopulateSurInfo(VBOXVHWA_SURFACEDESC *pInfo, PVBOXWDDM_ALLOCATION pSurf,
535 uint32_t fFlags, uint32_t cBackBuffers, uint32_t fSCaps,
536 D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
537{
538 memset(pInfo, 0, sizeof(VBOXVHWA_SURFACEDESC));
539
540 pInfo->height = pSurf->AllocData.SurfDesc.height;
541 pInfo->width = pSurf->AllocData.SurfDesc.width;
542 pInfo->flags |= VBOXVHWA_SD_HEIGHT | VBOXVHWA_SD_WIDTH;
543 if (fFlags & VBOXVHWA_SD_PITCH)
544 {
545 pInfo->pitch = pSurf->AllocData.SurfDesc.pitch;
546 pInfo->flags |= VBOXVHWA_SD_PITCH;
547 pInfo->sizeX = pSurf->AllocData.SurfDesc.cbSize;
548 pInfo->sizeY = 1;
549 }
550
551 if (cBackBuffers)
552 {
553 pInfo->cBackBuffers = cBackBuffers;
554 pInfo->flags |= VBOXVHWA_SD_BACKBUFFERCOUNT;
555 }
556 else
557 pInfo->cBackBuffers = 0;
558 pInfo->Reserved = 0;
559 /* @todo: color keys */
560// pInfo->DstOverlayCK;
561// pInfo->DstBltCK;
562// pInfo->SrcOverlayCK;
563// pInfo->SrcBltCK;
564 int rc = vboxVhwaHlpTranslateFormat(&pInfo->PixelFormat, pSurf->AllocData.SurfDesc.format);
565 AssertRC(rc);
566 if (RT_SUCCESS(rc))
567 {
568 pInfo->flags |= VBOXVHWA_SD_PIXELFORMAT;
569 pInfo->surfCaps = fSCaps;
570 pInfo->flags |= VBOXVHWA_SD_CAPS;
571 pInfo->offSurface = pSurf->AllocData.Addr.offVram;
572 }
573
574 return rc;
575}
576
577int vboxVhwaHlpCheckApplySurfInfo(PVBOXWDDM_ALLOCATION pSurf, VBOXVHWA_SURFACEDESC *pInfo,
578 uint32_t fFlags, bool bApplyHostHandle)
579{
580 int rc = VINF_SUCCESS;
581 if (!(fFlags & VBOXVHWA_SD_PITCH))
582 {
583 /* should be set by host */
584// Assert(pInfo->flags & VBOXVHWA_SD_PITCH);
585 pSurf->AllocData.SurfDesc.cbSize = pInfo->sizeX * pInfo->sizeY;
586 Assert(pSurf->AllocData.SurfDesc.cbSize);
587 pSurf->AllocData.SurfDesc.pitch = pInfo->pitch;
588 Assert(pSurf->AllocData.SurfDesc.pitch);
589 /* @todo: make this properly */
590 pSurf->AllocData.SurfDesc.bpp = pSurf->AllocData.SurfDesc.pitch * 8 / pSurf->AllocData.SurfDesc.width;
591 Assert(pSurf->AllocData.SurfDesc.bpp);
592 }
593 else
594 {
595 Assert(pSurf->AllocData.SurfDesc.cbSize == pInfo->sizeX);
596 Assert(pInfo->sizeY == 1);
597 Assert(pInfo->pitch == pSurf->AllocData.SurfDesc.pitch);
598 if (pSurf->AllocData.SurfDesc.cbSize != pInfo->sizeX
599 || pInfo->sizeY != 1
600 || pInfo->pitch != pSurf->AllocData.SurfDesc.pitch)
601 {
602 rc = VERR_INVALID_PARAMETER;
603 }
604 }
605
606 if (bApplyHostHandle && RT_SUCCESS(rc))
607 {
608 pSurf->hHostHandle = pInfo->hSurf;
609 }
610
611 return rc;
612}
613
614int vboxVhwaHlpCreateSurface(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_ALLOCATION pSurf,
615 uint32_t fFlags, uint32_t cBackBuffers, uint32_t fSCaps,
616 D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
617{
618 /* the first thing we need is to post create primary */
619 VBOXVHWACMD* pCmd = vboxVhwaCommandCreate(pDevExt, VidPnSourceId,
620 VBOXVHWACMD_TYPE_SURF_CREATE, sizeof(VBOXVHWACMD_SURF_CREATE));
621 Assert(pCmd);
622 if (pCmd)
623 {
624 VBOXVHWACMD_SURF_CREATE * pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_CREATE);
625 int rc = VINF_SUCCESS;
626
627 memset(pBody, 0, sizeof(VBOXVHWACMD_SURF_CREATE));
628
629 rc = vboxVhwaHlpPopulateSurInfo(&pBody->SurfInfo, pSurf,
630 fFlags, cBackBuffers, fSCaps,
631 VidPnSourceId);
632 AssertRC(rc);
633 if (RT_SUCCESS(rc))
634 {
635 vboxVhwaCommandSubmit(pDevExt, pCmd);
636 Assert(pCmd->rc == VINF_SUCCESS);
637 if(pCmd->rc == VINF_SUCCESS)
638 {
639 rc = vboxVhwaHlpCheckApplySurfInfo(pSurf, &pBody->SurfInfo, fFlags, true);
640 }
641 else
642 rc = pCmd->rc;
643 }
644 vboxVhwaCommandFree(pDevExt, pCmd);
645 return rc;
646 }
647
648 return VERR_OUT_OF_RESOURCES;
649}
650
651int vboxVhwaHlpGetSurfInfoForSource(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_ALLOCATION pSurf, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
652{
653 /* the first thing we need is to post create primary */
654 VBOXVHWACMD* pCmd = vboxVhwaCommandCreate(pDevExt, VidPnSourceId,
655 VBOXVHWACMD_TYPE_SURF_GETINFO, sizeof(VBOXVHWACMD_SURF_GETINFO));
656 Assert(pCmd);
657 if (pCmd)
658 {
659 VBOXVHWACMD_SURF_GETINFO * pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_GETINFO);
660 int rc = VINF_SUCCESS;
661
662 memset(pBody, 0, sizeof(VBOXVHWACMD_SURF_GETINFO));
663
664 rc = vboxVhwaHlpPopulateSurInfo(&pBody->SurfInfo, pSurf,
665 0, 0, VBOXVHWA_SCAPS_OVERLAY | VBOXVHWA_SCAPS_VIDEOMEMORY | VBOXVHWA_SCAPS_LOCALVIDMEM | VBOXVHWA_SCAPS_COMPLEX,
666 VidPnSourceId);
667 AssertRC(rc);
668 if (RT_SUCCESS(rc))
669 {
670 vboxVhwaCommandSubmit(pDevExt, pCmd);
671 Assert(pCmd->rc == VINF_SUCCESS);
672 if(pCmd->rc == VINF_SUCCESS)
673 {
674 rc = vboxVhwaHlpCheckApplySurfInfo(pSurf, &pBody->SurfInfo, 0, true);
675 }
676 else
677 rc = pCmd->rc;
678 }
679 vboxVhwaCommandFree(pDevExt, pCmd);
680 return rc;
681 }
682
683 return VERR_OUT_OF_RESOURCES;
684}
685
686int vboxVhwaHlpGetSurfInfo(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_ALLOCATION pSurf)
687{
688 for (int i = 0; i < VBoxCommonFromDeviceExt(pDevExt)->cDisplays; ++i)
689 {
690 PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[i];
691 if (pSource->Vhwa.Settings.fFlags & VBOXVHWA_F_ENABLED)
692 {
693 int rc = vboxVhwaHlpGetSurfInfoForSource(pDevExt, pSurf, i);
694 AssertRC(rc);
695 return rc;
696 }
697 }
698 AssertBreakpoint();
699 return VERR_NOT_SUPPORTED;
700}
701
702int vboxVhwaHlpDestroyPrimary(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_SOURCE pSource, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
703{
704 PVBOXWDDM_ALLOCATION pFbSurf = VBOXVHWA_PRIMARY_ALLOCATION(pSource);
705
706 int rc = vboxVhwaHlpDestroySurface(pDevExt, pFbSurf, VidPnSourceId);
707 AssertRC(rc);
708 return rc;
709}
710
711int vboxVhwaHlpCreatePrimary(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_SOURCE pSource, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
712{
713 PVBOXWDDM_ALLOCATION pFbSurf = VBOXVHWA_PRIMARY_ALLOCATION(pSource);
714 Assert(pSource->Vhwa.cOverlaysCreated == 1);
715 Assert(pFbSurf->hHostHandle == VBOXVHWA_SURFHANDLE_INVALID);
716 if (pFbSurf->hHostHandle != VBOXVHWA_SURFHANDLE_INVALID)
717 return VERR_INVALID_STATE;
718
719 int rc = vboxVhwaHlpCreateSurface(pDevExt, pFbSurf,
720 VBOXVHWA_SD_PITCH, 0, VBOXVHWA_SCAPS_PRIMARYSURFACE | VBOXVHWA_SCAPS_VIDEOMEMORY | VBOXVHWA_SCAPS_LOCALVIDMEM,
721 VidPnSourceId);
722 AssertRC(rc);
723 return rc;
724}
725
726int vboxVhwaHlpCheckInit(PVBOXMP_DEVEXT pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
727{
728 Assert(VidPnSourceId < (D3DDDI_VIDEO_PRESENT_SOURCE_ID)VBoxCommonFromDeviceExt(pDevExt)->cDisplays);
729 if (VidPnSourceId >= (D3DDDI_VIDEO_PRESENT_SOURCE_ID)VBoxCommonFromDeviceExt(pDevExt)->cDisplays)
730 return VERR_INVALID_PARAMETER;
731
732 PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[VidPnSourceId];
733
734 Assert(!!(pSource->Vhwa.Settings.fFlags & VBOXVHWA_F_ENABLED));
735 if (!(pSource->Vhwa.Settings.fFlags & VBOXVHWA_F_ENABLED))
736 return VERR_NOT_SUPPORTED;
737
738 int rc = VINF_SUCCESS;
739 /* @todo: need a better sync */
740 uint32_t cNew = ASMAtomicIncU32(&pSource->Vhwa.cOverlaysCreated);
741 if (cNew == 1)
742 {
743 rc = vboxVhwaEnable(pDevExt, VidPnSourceId);
744 AssertRC(rc);
745 if (RT_SUCCESS(rc))
746 {
747 rc = vboxVhwaHlpCreatePrimary(pDevExt, pSource, VidPnSourceId);
748 AssertRC(rc);
749 if (RT_FAILURE(rc))
750 {
751 int tmpRc = vboxVhwaDisable(pDevExt, VidPnSourceId);
752 AssertRC(tmpRc);
753 }
754 }
755 }
756 else
757 {
758 PVBOXWDDM_ALLOCATION pFbSurf = VBOXVHWA_PRIMARY_ALLOCATION(pSource);
759 Assert(pFbSurf->hHostHandle);
760 if (pFbSurf->hHostHandle)
761 rc = VINF_ALREADY_INITIALIZED;
762 else
763 rc = VERR_INVALID_STATE;
764 }
765
766 if (RT_FAILURE(rc))
767 ASMAtomicDecU32(&pSource->Vhwa.cOverlaysCreated);
768
769 return rc;
770}
771
772int vboxVhwaHlpCheckTerm(PVBOXMP_DEVEXT pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
773{
774 Assert(VidPnSourceId < (D3DDDI_VIDEO_PRESENT_SOURCE_ID)VBoxCommonFromDeviceExt(pDevExt)->cDisplays);
775 if (VidPnSourceId >= (D3DDDI_VIDEO_PRESENT_SOURCE_ID)VBoxCommonFromDeviceExt(pDevExt)->cDisplays)
776 return VERR_INVALID_PARAMETER;
777
778 PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[VidPnSourceId];
779
780 Assert(!!(pSource->Vhwa.Settings.fFlags & VBOXVHWA_F_ENABLED));
781
782 /* @todo: need a better sync */
783 uint32_t cNew = ASMAtomicDecU32(&pSource->Vhwa.cOverlaysCreated);
784 int rc = VINF_SUCCESS;
785 if (!cNew)
786 {
787 rc = vboxVhwaHlpDestroyPrimary(pDevExt, pSource, VidPnSourceId);
788 AssertRC(rc);
789 }
790 else
791 {
792 Assert(cNew < UINT32_MAX / 2);
793 }
794
795 return rc;
796}
797
798int vboxVhwaHlpOverlayFlip(PVBOXWDDM_OVERLAY pOverlay, const DXGKARG_FLIPOVERLAY *pFlipInfo)
799{
800 PVBOXWDDM_ALLOCATION pAlloc = (PVBOXWDDM_ALLOCATION)pFlipInfo->hSource;
801 Assert(pAlloc->hHostHandle);
802 Assert(pAlloc->pResource);
803 Assert(pAlloc->pResource == pOverlay->pResource);
804 Assert(pFlipInfo->PrivateDriverDataSize == sizeof (VBOXWDDM_OVERLAYFLIP_INFO));
805 Assert(pFlipInfo->pPrivateDriverData);
806 PVBOXWDDM_SOURCE pSource = &pOverlay->pDevExt->aSources[pOverlay->VidPnSourceId];
807 Assert(!!(pSource->Vhwa.Settings.fFlags & VBOXVHWA_F_ENABLED));
808 PVBOXWDDM_ALLOCATION pFbSurf = VBOXVHWA_PRIMARY_ALLOCATION(pSource);
809 Assert(pFbSurf);
810 Assert(pFbSurf->hHostHandle);
811 Assert(pFbSurf->AllocData.Addr.offVram != VBOXVIDEOOFFSET_VOID);
812 Assert(pOverlay->pCurentAlloc);
813 Assert(pOverlay->pCurentAlloc->pResource == pOverlay->pResource);
814 Assert(pOverlay->pCurentAlloc != pAlloc);
815 int rc = VINF_SUCCESS;
816 if (pFlipInfo->PrivateDriverDataSize == sizeof (VBOXWDDM_OVERLAYFLIP_INFO))
817 {
818 PVBOXWDDM_OVERLAYFLIP_INFO pOurInfo = (PVBOXWDDM_OVERLAYFLIP_INFO)pFlipInfo->pPrivateDriverData;
819
820 VBOXVHWACMD* pCmd = vboxVhwaCommandCreate(pOverlay->pDevExt, pOverlay->VidPnSourceId,
821 VBOXVHWACMD_TYPE_SURF_FLIP, sizeof(VBOXVHWACMD_SURF_FLIP));
822 Assert(pCmd);
823 if(pCmd)
824 {
825 VBOXVHWACMD_SURF_FLIP * pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_FLIP);
826
827 memset(pBody, 0, sizeof(VBOXVHWACMD_SURF_FLIP));
828
829// pBody->TargGuestSurfInfo;
830// pBody->CurrGuestSurfInfo;
831 pBody->u.in.hTargSurf = pAlloc->hHostHandle;
832 pBody->u.in.offTargSurface = pFlipInfo->SrcPhysicalAddress.QuadPart;
833 pAlloc->AllocData.Addr.offVram = pFlipInfo->SrcPhysicalAddress.QuadPart;
834 pBody->u.in.hCurrSurf = pOverlay->pCurentAlloc->hHostHandle;
835 pBody->u.in.offCurrSurface = pOverlay->pCurentAlloc->AllocData.Addr.offVram;
836 if (pOurInfo->DirtyRegion.fFlags & VBOXWDDM_DIRTYREGION_F_VALID)
837 {
838 pBody->u.in.xUpdatedTargMemValid = 1;
839 if (pOurInfo->DirtyRegion.fFlags & VBOXWDDM_DIRTYREGION_F_RECT_VALID)
840 pBody->u.in.xUpdatedTargMemRect = *(VBOXVHWA_RECTL*)((void*)&pOurInfo->DirtyRegion.Rect);
841 else
842 {
843 pBody->u.in.xUpdatedTargMemRect.right = pAlloc->AllocData.SurfDesc.width;
844 pBody->u.in.xUpdatedTargMemRect.bottom = pAlloc->AllocData.SurfDesc.height;
845 /* top & left are zero-inited with the above memset */
846 }
847 }
848
849 /* we're not interested in completion, just send the command */
850 vboxVhwaCommandSubmitAsynchAndComplete(pOverlay->pDevExt, pCmd);
851
852 pOverlay->pCurentAlloc = pAlloc;
853
854 rc = VINF_SUCCESS;
855 }
856 else
857 rc = VERR_OUT_OF_RESOURCES;
858 }
859 else
860 rc = VERR_INVALID_PARAMETER;
861
862 return rc;
863}
864
865AssertCompile(sizeof (RECT) == sizeof (VBOXVHWA_RECTL));
866AssertCompile(RT_SIZEOFMEMB(RECT, left) == RT_SIZEOFMEMB(VBOXVHWA_RECTL, left));
867AssertCompile(RT_SIZEOFMEMB(RECT, right) == RT_SIZEOFMEMB(VBOXVHWA_RECTL, right));
868AssertCompile(RT_SIZEOFMEMB(RECT, top) == RT_SIZEOFMEMB(VBOXVHWA_RECTL, top));
869AssertCompile(RT_SIZEOFMEMB(RECT, bottom) == RT_SIZEOFMEMB(VBOXVHWA_RECTL, bottom));
870AssertCompile(RT_OFFSETOF(RECT, left) == RT_OFFSETOF(VBOXVHWA_RECTL, left));
871AssertCompile(RT_OFFSETOF(RECT, right) == RT_OFFSETOF(VBOXVHWA_RECTL, right));
872AssertCompile(RT_OFFSETOF(RECT, top) == RT_OFFSETOF(VBOXVHWA_RECTL, top));
873AssertCompile(RT_OFFSETOF(RECT, bottom) == RT_OFFSETOF(VBOXVHWA_RECTL, bottom));
874
875int vboxVhwaHlpColorFill(PVBOXWDDM_OVERLAY pOverlay, PVBOXWDDM_DMA_PRIVATEDATA_CLRFILL pCF)
876{
877 PVBOXWDDM_ALLOCATION pAlloc = pCF->ClrFill.Alloc.pAlloc;
878 Assert(pAlloc->pResource == pOverlay->pResource);
879#ifdef VBOXWDDM_RENDER_FROM_SHADOW
880 if (pAlloc->bAssigned)
881 {
882 /* check if this is a primary surf */
883 PVBOXWDDM_SOURCE pSource = &pOverlay->pDevExt->aSources[pOverlay->VidPnSourceId];
884 if (pSource->pPrimaryAllocation == pAlloc)
885 {
886 pAlloc = pSource->pShadowAllocation;
887 Assert(pAlloc->pResource == pOverlay->pResource);
888 }
889 }
890#endif
891 Assert(pAlloc->hHostHandle);
892 Assert(pAlloc->pResource);
893 Assert(pAlloc->AllocData.Addr.offVram != VBOXVIDEOOFFSET_VOID);
894
895 int rc;
896 VBOXVHWACMD* pCmd = vboxVhwaCommandCreate(pOverlay->pDevExt, pOverlay->VidPnSourceId,
897 VBOXVHWACMD_TYPE_SURF_FLIP, RT_OFFSETOF(VBOXVHWACMD_SURF_COLORFILL, u.in.aRects[pCF->ClrFill.Rects.cRects]));
898 Assert(pCmd);
899 if(pCmd)
900 {
901 VBOXVHWACMD_SURF_COLORFILL * pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_COLORFILL);
902
903 memset(pBody, 0, sizeof(VBOXVHWACMD_SURF_COLORFILL));
904
905 pBody->u.in.hSurf = pAlloc->hHostHandle;
906 pBody->u.in.offSurface = pAlloc->AllocData.Addr.offVram;
907 pBody->u.in.cRects = pCF->ClrFill.Rects.cRects;
908 memcpy (pBody->u.in.aRects, pCF->ClrFill.Rects.aRects, pCF->ClrFill.Rects.cRects * sizeof (pCF->ClrFill.Rects.aRects[0]));
909 vboxVhwaCommandSubmitAsynchAndComplete(pOverlay->pDevExt, pCmd);
910
911 rc = VINF_SUCCESS;
912 }
913 else
914 rc = VERR_OUT_OF_RESOURCES;
915
916 return rc;
917}
918
919static void vboxVhwaHlpOverlayDstRectSet(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_OVERLAY pOverlay, const RECT *pRect)
920{
921 PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[pOverlay->VidPnSourceId];
922 KIRQL OldIrql;
923 KeAcquireSpinLock(&pSource->OverlayListLock, &OldIrql);
924 pOverlay->DstRect = *pRect;
925 KeReleaseSpinLock(&pSource->OverlayListLock, OldIrql);
926}
927
928static void vboxVhwaHlpOverlayListAdd(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_OVERLAY pOverlay)
929{
930 PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[pOverlay->VidPnSourceId];
931 KIRQL OldIrql;
932 KeAcquireSpinLock(&pSource->OverlayListLock, &OldIrql);
933 ASMAtomicIncU32(&pSource->cOverlays);
934 InsertHeadList(&pSource->OverlayList, &pOverlay->ListEntry);
935 KeReleaseSpinLock(&pSource->OverlayListLock, OldIrql);
936}
937
938static void vboxVhwaHlpOverlayListRemove(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_OVERLAY pOverlay)
939{
940 PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[pOverlay->VidPnSourceId];
941 KIRQL OldIrql;
942 KeAcquireSpinLock(&pSource->OverlayListLock, &OldIrql);
943 ASMAtomicDecU32(&pSource->cOverlays);
944 RemoveEntryList(&pOverlay->ListEntry);
945 KeReleaseSpinLock(&pSource->OverlayListLock, OldIrql);
946}
947
948AssertCompile(sizeof (RECT) == sizeof (VBOXVHWA_RECTL));
949AssertCompile(RT_SIZEOFMEMB(RECT, left) == RT_SIZEOFMEMB(VBOXVHWA_RECTL, left));
950AssertCompile(RT_SIZEOFMEMB(RECT, right) == RT_SIZEOFMEMB(VBOXVHWA_RECTL, right));
951AssertCompile(RT_SIZEOFMEMB(RECT, top) == RT_SIZEOFMEMB(VBOXVHWA_RECTL, top));
952AssertCompile(RT_SIZEOFMEMB(RECT, bottom) == RT_SIZEOFMEMB(VBOXVHWA_RECTL, bottom));
953AssertCompile(RT_OFFSETOF(RECT, left) == RT_OFFSETOF(VBOXVHWA_RECTL, left));
954AssertCompile(RT_OFFSETOF(RECT, right) == RT_OFFSETOF(VBOXVHWA_RECTL, right));
955AssertCompile(RT_OFFSETOF(RECT, top) == RT_OFFSETOF(VBOXVHWA_RECTL, top));
956AssertCompile(RT_OFFSETOF(RECT, bottom) == RT_OFFSETOF(VBOXVHWA_RECTL, bottom));
957
958int vboxVhwaHlpOverlayUpdate(PVBOXWDDM_OVERLAY pOverlay, const DXGK_OVERLAYINFO *pOverlayInfo, RECT * pDstUpdateRect)
959{
960 PVBOXWDDM_ALLOCATION pAlloc = (PVBOXWDDM_ALLOCATION)pOverlayInfo->hAllocation;
961 Assert(pAlloc->hHostHandle);
962 Assert(pAlloc->pResource);
963 Assert(pAlloc->pResource == pOverlay->pResource);
964 Assert(pOverlayInfo->PrivateDriverDataSize == sizeof (VBOXWDDM_OVERLAY_INFO));
965 Assert(pOverlayInfo->pPrivateDriverData);
966 PVBOXWDDM_SOURCE pSource = &pOverlay->pDevExt->aSources[pOverlay->VidPnSourceId];
967 Assert(!!(pSource->Vhwa.Settings.fFlags & VBOXVHWA_F_ENABLED));
968 PVBOXWDDM_ALLOCATION pFbSurf = VBOXVHWA_PRIMARY_ALLOCATION(pSource);
969 Assert(pFbSurf);
970 Assert(pFbSurf->hHostHandle);
971 Assert(pFbSurf->AllocData.Addr.offVram != VBOXVIDEOOFFSET_VOID);
972 int rc = VINF_SUCCESS;
973 if (pOverlayInfo->PrivateDriverDataSize == sizeof (VBOXWDDM_OVERLAY_INFO))
974 {
975 PVBOXWDDM_OVERLAY_INFO pOurInfo = (PVBOXWDDM_OVERLAY_INFO)pOverlayInfo->pPrivateDriverData;
976
977 VBOXVHWACMD* pCmd = vboxVhwaCommandCreate(pOverlay->pDevExt, pOverlay->VidPnSourceId,
978 VBOXVHWACMD_TYPE_SURF_OVERLAY_UPDATE, sizeof(VBOXVHWACMD_SURF_OVERLAY_UPDATE));
979 Assert(pCmd);
980 if(pCmd)
981 {
982 VBOXVHWACMD_SURF_OVERLAY_UPDATE * pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_OVERLAY_UPDATE);
983
984 memset(pBody, 0, sizeof(VBOXVHWACMD_SURF_OVERLAY_UPDATE));
985
986 pBody->u.in.hDstSurf = pFbSurf->hHostHandle;
987 pBody->u.in.offDstSurface = pFbSurf->AllocData.Addr.offVram;
988 pBody->u.in.dstRect = *(VBOXVHWA_RECTL*)((void*)&pOverlayInfo->DstRect);
989 pBody->u.in.hSrcSurf = pAlloc->hHostHandle;
990 pBody->u.in.offSrcSurface = pOverlayInfo->PhysicalAddress.QuadPart;
991 pAlloc->AllocData.Addr.offVram = pOverlayInfo->PhysicalAddress.QuadPart;
992 pBody->u.in.srcRect = *(VBOXVHWA_RECTL*)((void*)&pOverlayInfo->SrcRect);
993 pBody->u.in.flags |= VBOXVHWA_OVER_SHOW;
994 if (pOurInfo->OverlayDesc.fFlags & VBOXWDDM_OVERLAY_F_CKEY_DST)
995 {
996 pBody->u.in.flags |= VBOXVHWA_OVER_KEYDESTOVERRIDE /* ?? VBOXVHWA_OVER_KEYDEST */;
997 pBody->u.in.desc.DstCK.high = pOurInfo->OverlayDesc.DstColorKeyHigh;
998 pBody->u.in.desc.DstCK.low = pOurInfo->OverlayDesc.DstColorKeyLow;
999 }
1000
1001 if (pOurInfo->OverlayDesc.fFlags & VBOXWDDM_OVERLAY_F_CKEY_SRC)
1002 {
1003 pBody->u.in.flags |= VBOXVHWA_OVER_KEYSRCOVERRIDE /* ?? VBOXVHWA_OVER_KEYSRC */;
1004 pBody->u.in.desc.SrcCK.high = pOurInfo->OverlayDesc.SrcColorKeyHigh;
1005 pBody->u.in.desc.SrcCK.low = pOurInfo->OverlayDesc.SrcColorKeyLow;
1006 }
1007
1008 if (pOurInfo->DirtyRegion.fFlags & VBOXWDDM_DIRTYREGION_F_VALID)
1009 {
1010 pBody->u.in.xFlags |= VBOXVHWACMD_SURF_OVERLAY_UPDATE_F_SRCMEMRECT;
1011 if (pOurInfo->DirtyRegion.fFlags & VBOXWDDM_DIRTYREGION_F_RECT_VALID)
1012 pBody->u.in.xUpdatedSrcMemRect = *(VBOXVHWA_RECTL*)((void*)&pOurInfo->DirtyRegion.Rect);
1013 else
1014 {
1015 pBody->u.in.xUpdatedSrcMemRect.right = pAlloc->AllocData.SurfDesc.width;
1016 pBody->u.in.xUpdatedSrcMemRect.bottom = pAlloc->AllocData.SurfDesc.height;
1017 /* top & left are zero-inited with the above memset */
1018 }
1019 }
1020
1021 if (pDstUpdateRect)
1022 {
1023 pBody->u.in.xFlags |= VBOXVHWACMD_SURF_OVERLAY_UPDATE_F_DSTMEMRECT;
1024 pBody->u.in.xUpdatedDstMemRect = *(VBOXVHWA_RECTL*)((void*)pDstUpdateRect);
1025 }
1026
1027 /* we're not interested in completion, just send the command */
1028 vboxVhwaCommandSubmitAsynchAndComplete(pOverlay->pDevExt, pCmd);
1029
1030 pOverlay->pCurentAlloc = pAlloc;
1031
1032 vboxVhwaHlpOverlayDstRectSet(pOverlay->pDevExt, pOverlay, &pOverlayInfo->DstRect);
1033
1034 rc = VINF_SUCCESS;
1035 }
1036 else
1037 rc = VERR_OUT_OF_RESOURCES;
1038 }
1039 else
1040 rc = VERR_INVALID_PARAMETER;
1041
1042 return rc;
1043}
1044
1045int vboxVhwaHlpOverlayUpdate(PVBOXWDDM_OVERLAY pOverlay, const DXGK_OVERLAYINFO *pOverlayInfo)
1046{
1047 return vboxVhwaHlpOverlayUpdate(pOverlay, pOverlayInfo, NULL);
1048}
1049
1050int vboxVhwaHlpOverlayDestroy(PVBOXWDDM_OVERLAY pOverlay)
1051{
1052 int rc = VINF_SUCCESS;
1053
1054 vboxVhwaHlpOverlayListRemove(pOverlay->pDevExt, pOverlay);
1055
1056 for (uint32_t i = 0; i < pOverlay->pResource->cAllocations; ++i)
1057 {
1058 PVBOXWDDM_ALLOCATION pCurAlloc = &pOverlay->pResource->aAllocations[i];
1059 rc = vboxVhwaHlpDestroySurface(pOverlay->pDevExt, pCurAlloc, pOverlay->VidPnSourceId);
1060 AssertRC(rc);
1061 }
1062
1063 if (RT_SUCCESS(rc))
1064 {
1065 int tmpRc = vboxVhwaHlpCheckTerm(pOverlay->pDevExt, pOverlay->VidPnSourceId);
1066 AssertRC(tmpRc);
1067 }
1068
1069 return rc;
1070}
1071
1072
1073int vboxVhwaHlpOverlayCreate(PVBOXMP_DEVEXT pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId, DXGK_OVERLAYINFO *pOverlayInfo,
1074 /* OUT */ PVBOXWDDM_OVERLAY pOverlay)
1075{
1076 int rc = vboxVhwaHlpCheckInit(pDevExt, VidPnSourceId);
1077 AssertRC(rc);
1078 if (RT_SUCCESS(rc))
1079 {
1080 PVBOXWDDM_ALLOCATION pAlloc = (PVBOXWDDM_ALLOCATION)pOverlayInfo->hAllocation;
1081 PVBOXWDDM_RESOURCE pRc = pAlloc->pResource;
1082 Assert(pRc);
1083 for (uint32_t i = 0; i < pRc->cAllocations; ++i)
1084 {
1085 PVBOXWDDM_ALLOCATION pCurAlloc = &pRc->aAllocations[i];
1086 rc = vboxVhwaHlpCreateSurface(pDevExt, pCurAlloc,
1087 0, pRc->cAllocations - 1, VBOXVHWA_SCAPS_OVERLAY | VBOXVHWA_SCAPS_VIDEOMEMORY | VBOXVHWA_SCAPS_LOCALVIDMEM | VBOXVHWA_SCAPS_COMPLEX,
1088 VidPnSourceId);
1089 AssertRC(rc);
1090 if (!RT_SUCCESS(rc))
1091 {
1092 int tmpRc;
1093 for (uint32_t j = 0; j < i; ++j)
1094 {
1095 PVBOXWDDM_ALLOCATION pDestroyAlloc = &pRc->aAllocations[j];
1096 tmpRc = vboxVhwaHlpDestroySurface(pDevExt, pDestroyAlloc, VidPnSourceId);
1097 AssertRC(tmpRc);
1098 }
1099 break;
1100 }
1101 }
1102
1103 if (RT_SUCCESS(rc))
1104 {
1105 pOverlay->pDevExt = pDevExt;
1106 pOverlay->pResource = pRc;
1107 pOverlay->VidPnSourceId = VidPnSourceId;
1108
1109 vboxVhwaHlpOverlayListAdd(pDevExt, pOverlay);
1110#ifdef VBOXWDDM_RENDER_FROM_SHADOW
1111 RECT DstRect;
1112 vboxVhwaHlpOverlayDstRectGet(pDevExt, pOverlay, &DstRect);
1113 NTSTATUS Status = vboxVdmaHlpUpdatePrimary(pDevExt, VidPnSourceId, &DstRect);
1114 Assert(Status == STATUS_SUCCESS);
1115 /* ignore primary update failure */
1116 Status = STATUS_SUCCESS;
1117#endif
1118 rc = vboxVhwaHlpOverlayUpdate(pOverlay, pOverlayInfo, DstRect.right ? &DstRect : NULL);
1119 if (!RT_SUCCESS(rc))
1120 {
1121 int tmpRc = vboxVhwaHlpOverlayDestroy(pOverlay);
1122 AssertRC(tmpRc);
1123 }
1124 }
1125
1126 if (RT_FAILURE(rc))
1127 {
1128 int tmpRc = vboxVhwaHlpCheckTerm(pDevExt, VidPnSourceId);
1129 AssertRC(tmpRc);
1130 AssertRC(rc);
1131 }
1132 }
1133
1134 return rc;
1135}
1136
1137BOOLEAN vboxVhwaHlpOverlayListIsEmpty(PVBOXMP_DEVEXT pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
1138{
1139 PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[VidPnSourceId];
1140 return !ASMAtomicReadU32(&pSource->cOverlays);
1141}
1142
1143#define VBOXWDDM_OVERLAY_FROM_ENTRY(_pEntry) ((PVBOXWDDM_OVERLAY)(((uint8_t*)(_pEntry)) - RT_OFFSETOF(VBOXWDDM_OVERLAY, ListEntry)))
1144
1145void vboxVhwaHlpOverlayDstRectUnion(PVBOXMP_DEVEXT pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId, RECT *pRect)
1146{
1147 if (vboxVhwaHlpOverlayListIsEmpty(pDevExt, VidPnSourceId))
1148 {
1149 memset(pRect, 0, sizeof (*pRect));
1150 return;
1151 }
1152
1153 PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[VidPnSourceId];
1154 KIRQL OldIrql;
1155 KeAcquireSpinLock(&pSource->OverlayListLock, &OldIrql);
1156 if (pSource->cOverlays)
1157 {
1158 PVBOXWDDM_OVERLAY pOverlay = VBOXWDDM_OVERLAY_FROM_ENTRY(pSource->OverlayList.Flink);
1159 *pRect = pOverlay->DstRect;
1160 while (pOverlay->ListEntry.Flink != &pSource->OverlayList)
1161 {
1162 pOverlay = VBOXWDDM_OVERLAY_FROM_ENTRY(pOverlay->ListEntry.Flink);
1163 vboxWddmRectUnite(pRect, &pOverlay->DstRect);
1164 }
1165 }
1166 KeReleaseSpinLock(&pSource->OverlayListLock, OldIrql);
1167}
1168
1169void vboxVhwaHlpOverlayDstRectGet(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_OVERLAY pOverlay, RECT *pRect)
1170{
1171 PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[pOverlay->VidPnSourceId];
1172 KIRQL OldIrql;
1173 KeAcquireSpinLock(&pSource->OverlayListLock, &OldIrql);
1174 *pRect = pOverlay->DstRect;
1175 KeReleaseSpinLock(&pSource->OverlayListLock, OldIrql);
1176}
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