VirtualBox

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

Last change on this file since 51325 was 51260, checked in by vboxsync, 11 years ago

wddm: resize enhancements & 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 51260 2014-05-15 15:35:56Z vboxsync $ */
2
3/** @file
4 * VBox WDDM Miniport driver
5 */
6
7/*
8 * Copyright (C) 2011-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 if (pSurf->AllocData.Addr.SegmentId != 1)
541 {
542 WARN(("invalid segment id!"));
543 return VERR_INVALID_PARAMETER;
544 }
545
546 pInfo->height = pSurf->AllocData.SurfDesc.height;
547 pInfo->width = pSurf->AllocData.SurfDesc.width;
548 pInfo->flags |= VBOXVHWA_SD_HEIGHT | VBOXVHWA_SD_WIDTH;
549 if (fFlags & VBOXVHWA_SD_PITCH)
550 {
551 pInfo->pitch = pSurf->AllocData.SurfDesc.pitch;
552 pInfo->flags |= VBOXVHWA_SD_PITCH;
553 pInfo->sizeX = pSurf->AllocData.SurfDesc.cbSize;
554 pInfo->sizeY = 1;
555 }
556
557 if (cBackBuffers)
558 {
559 pInfo->cBackBuffers = cBackBuffers;
560 pInfo->flags |= VBOXVHWA_SD_BACKBUFFERCOUNT;
561 }
562 else
563 pInfo->cBackBuffers = 0;
564 pInfo->Reserved = 0;
565 /* @todo: color keys */
566// pInfo->DstOverlayCK;
567// pInfo->DstBltCK;
568// pInfo->SrcOverlayCK;
569// pInfo->SrcBltCK;
570 int rc = vboxVhwaHlpTranslateFormat(&pInfo->PixelFormat, pSurf->AllocData.SurfDesc.format);
571 AssertRC(rc);
572 if (RT_SUCCESS(rc))
573 {
574 pInfo->flags |= VBOXVHWA_SD_PIXELFORMAT;
575 pInfo->surfCaps = fSCaps;
576 pInfo->flags |= VBOXVHWA_SD_CAPS;
577 pInfo->offSurface = pSurf->AllocData.Addr.offVram;
578 }
579
580 return rc;
581}
582
583int vboxVhwaHlpCheckApplySurfInfo(PVBOXWDDM_ALLOCATION pSurf, VBOXVHWA_SURFACEDESC *pInfo,
584 uint32_t fFlags, bool bApplyHostHandle)
585{
586 int rc = VINF_SUCCESS;
587 if (!(fFlags & VBOXVHWA_SD_PITCH))
588 {
589 /* should be set by host */
590// Assert(pInfo->flags & VBOXVHWA_SD_PITCH);
591 pSurf->AllocData.SurfDesc.cbSize = pInfo->sizeX * pInfo->sizeY;
592 Assert(pSurf->AllocData.SurfDesc.cbSize);
593 pSurf->AllocData.SurfDesc.pitch = pInfo->pitch;
594 Assert(pSurf->AllocData.SurfDesc.pitch);
595 /* @todo: make this properly */
596 pSurf->AllocData.SurfDesc.bpp = pSurf->AllocData.SurfDesc.pitch * 8 / pSurf->AllocData.SurfDesc.width;
597 Assert(pSurf->AllocData.SurfDesc.bpp);
598 }
599 else
600 {
601 Assert(pSurf->AllocData.SurfDesc.cbSize == pInfo->sizeX);
602 Assert(pInfo->sizeY == 1);
603 Assert(pInfo->pitch == pSurf->AllocData.SurfDesc.pitch);
604 if (pSurf->AllocData.SurfDesc.cbSize != pInfo->sizeX
605 || pInfo->sizeY != 1
606 || pInfo->pitch != pSurf->AllocData.SurfDesc.pitch)
607 {
608 rc = VERR_INVALID_PARAMETER;
609 }
610 }
611
612 if (bApplyHostHandle && RT_SUCCESS(rc))
613 {
614 pSurf->hHostHandle = pInfo->hSurf;
615 }
616
617 return rc;
618}
619
620int vboxVhwaHlpCreateSurface(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_ALLOCATION pSurf,
621 uint32_t fFlags, uint32_t cBackBuffers, uint32_t fSCaps,
622 D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
623{
624 /* the first thing we need is to post create primary */
625 VBOXVHWACMD* pCmd = vboxVhwaCommandCreate(pDevExt, VidPnSourceId,
626 VBOXVHWACMD_TYPE_SURF_CREATE, sizeof(VBOXVHWACMD_SURF_CREATE));
627 Assert(pCmd);
628 if (pCmd)
629 {
630 VBOXVHWACMD_SURF_CREATE * pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_CREATE);
631 int rc = VINF_SUCCESS;
632
633 memset(pBody, 0, sizeof(VBOXVHWACMD_SURF_CREATE));
634
635 rc = vboxVhwaHlpPopulateSurInfo(&pBody->SurfInfo, pSurf,
636 fFlags, cBackBuffers, fSCaps,
637 VidPnSourceId);
638 AssertRC(rc);
639 if (RT_SUCCESS(rc))
640 {
641 vboxVhwaCommandSubmit(pDevExt, pCmd);
642 Assert(pCmd->rc == VINF_SUCCESS);
643 if(pCmd->rc == VINF_SUCCESS)
644 {
645 rc = vboxVhwaHlpCheckApplySurfInfo(pSurf, &pBody->SurfInfo, fFlags, true);
646 }
647 else
648 rc = pCmd->rc;
649 }
650 vboxVhwaCommandFree(pDevExt, pCmd);
651 return rc;
652 }
653
654 return VERR_OUT_OF_RESOURCES;
655}
656
657int vboxVhwaHlpGetSurfInfoForSource(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_ALLOCATION pSurf, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
658{
659 /* the first thing we need is to post create primary */
660 VBOXVHWACMD* pCmd = vboxVhwaCommandCreate(pDevExt, VidPnSourceId,
661 VBOXVHWACMD_TYPE_SURF_GETINFO, sizeof(VBOXVHWACMD_SURF_GETINFO));
662 Assert(pCmd);
663 if (pCmd)
664 {
665 VBOXVHWACMD_SURF_GETINFO * pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_GETINFO);
666 int rc = VINF_SUCCESS;
667
668 memset(pBody, 0, sizeof(VBOXVHWACMD_SURF_GETINFO));
669
670 rc = vboxVhwaHlpPopulateSurInfo(&pBody->SurfInfo, pSurf,
671 0, 0, VBOXVHWA_SCAPS_OVERLAY | VBOXVHWA_SCAPS_VIDEOMEMORY | VBOXVHWA_SCAPS_LOCALVIDMEM | VBOXVHWA_SCAPS_COMPLEX,
672 VidPnSourceId);
673 AssertRC(rc);
674 if (RT_SUCCESS(rc))
675 {
676 vboxVhwaCommandSubmit(pDevExt, pCmd);
677 Assert(pCmd->rc == VINF_SUCCESS);
678 if(pCmd->rc == VINF_SUCCESS)
679 {
680 rc = vboxVhwaHlpCheckApplySurfInfo(pSurf, &pBody->SurfInfo, 0, true);
681 }
682 else
683 rc = pCmd->rc;
684 }
685 vboxVhwaCommandFree(pDevExt, pCmd);
686 return rc;
687 }
688
689 return VERR_OUT_OF_RESOURCES;
690}
691
692int vboxVhwaHlpGetSurfInfo(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_ALLOCATION pSurf)
693{
694 for (int i = 0; i < VBoxCommonFromDeviceExt(pDevExt)->cDisplays; ++i)
695 {
696 PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[i];
697 if (pSource->Vhwa.Settings.fFlags & VBOXVHWA_F_ENABLED)
698 {
699 int rc = vboxVhwaHlpGetSurfInfoForSource(pDevExt, pSurf, i);
700 AssertRC(rc);
701 return rc;
702 }
703 }
704 AssertBreakpoint();
705 return VERR_NOT_SUPPORTED;
706}
707
708int vboxVhwaHlpDestroyPrimary(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_SOURCE pSource, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
709{
710 PVBOXWDDM_ALLOCATION pFbSurf = VBOXVHWA_PRIMARY_ALLOCATION(pSource);
711
712 int rc = vboxVhwaHlpDestroySurface(pDevExt, pFbSurf, VidPnSourceId);
713 AssertRC(rc);
714 return rc;
715}
716
717int vboxVhwaHlpCreatePrimary(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_SOURCE pSource, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
718{
719 PVBOXWDDM_ALLOCATION pFbSurf = VBOXVHWA_PRIMARY_ALLOCATION(pSource);
720 Assert(pSource->Vhwa.cOverlaysCreated == 1);
721 Assert(pFbSurf->hHostHandle == VBOXVHWA_SURFHANDLE_INVALID);
722 if (pFbSurf->hHostHandle != VBOXVHWA_SURFHANDLE_INVALID)
723 return VERR_INVALID_STATE;
724
725 int rc = vboxVhwaHlpCreateSurface(pDevExt, pFbSurf,
726 VBOXVHWA_SD_PITCH, 0, VBOXVHWA_SCAPS_PRIMARYSURFACE | VBOXVHWA_SCAPS_VIDEOMEMORY | VBOXVHWA_SCAPS_LOCALVIDMEM,
727 VidPnSourceId);
728 AssertRC(rc);
729 return rc;
730}
731
732int vboxVhwaHlpCheckInit(PVBOXMP_DEVEXT pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
733{
734 Assert(VidPnSourceId < (D3DDDI_VIDEO_PRESENT_SOURCE_ID)VBoxCommonFromDeviceExt(pDevExt)->cDisplays);
735 if (VidPnSourceId >= (D3DDDI_VIDEO_PRESENT_SOURCE_ID)VBoxCommonFromDeviceExt(pDevExt)->cDisplays)
736 return VERR_INVALID_PARAMETER;
737
738 PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[VidPnSourceId];
739
740 Assert(!!(pSource->Vhwa.Settings.fFlags & VBOXVHWA_F_ENABLED));
741 if (!(pSource->Vhwa.Settings.fFlags & VBOXVHWA_F_ENABLED))
742 return VERR_NOT_SUPPORTED;
743
744 int rc = VINF_SUCCESS;
745 /* @todo: need a better sync */
746 uint32_t cNew = ASMAtomicIncU32(&pSource->Vhwa.cOverlaysCreated);
747 if (cNew == 1)
748 {
749 rc = vboxVhwaEnable(pDevExt, VidPnSourceId);
750 AssertRC(rc);
751 if (RT_SUCCESS(rc))
752 {
753 rc = vboxVhwaHlpCreatePrimary(pDevExt, pSource, VidPnSourceId);
754 AssertRC(rc);
755 if (RT_FAILURE(rc))
756 {
757 int tmpRc = vboxVhwaDisable(pDevExt, VidPnSourceId);
758 AssertRC(tmpRc);
759 }
760 }
761 }
762 else
763 {
764 PVBOXWDDM_ALLOCATION pFbSurf = VBOXVHWA_PRIMARY_ALLOCATION(pSource);
765 Assert(pFbSurf->hHostHandle);
766 if (pFbSurf->hHostHandle)
767 rc = VINF_ALREADY_INITIALIZED;
768 else
769 rc = VERR_INVALID_STATE;
770 }
771
772 if (RT_FAILURE(rc))
773 ASMAtomicDecU32(&pSource->Vhwa.cOverlaysCreated);
774
775 return rc;
776}
777
778int vboxVhwaHlpCheckTerm(PVBOXMP_DEVEXT pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
779{
780 Assert(VidPnSourceId < (D3DDDI_VIDEO_PRESENT_SOURCE_ID)VBoxCommonFromDeviceExt(pDevExt)->cDisplays);
781 if (VidPnSourceId >= (D3DDDI_VIDEO_PRESENT_SOURCE_ID)VBoxCommonFromDeviceExt(pDevExt)->cDisplays)
782 return VERR_INVALID_PARAMETER;
783
784 PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[VidPnSourceId];
785
786 Assert(!!(pSource->Vhwa.Settings.fFlags & VBOXVHWA_F_ENABLED));
787
788 /* @todo: need a better sync */
789 uint32_t cNew = ASMAtomicDecU32(&pSource->Vhwa.cOverlaysCreated);
790 int rc = VINF_SUCCESS;
791 if (!cNew)
792 {
793 rc = vboxVhwaHlpDestroyPrimary(pDevExt, pSource, VidPnSourceId);
794 AssertRC(rc);
795 }
796 else
797 {
798 Assert(cNew < UINT32_MAX / 2);
799 }
800
801 return rc;
802}
803
804int vboxVhwaHlpOverlayFlip(PVBOXWDDM_OVERLAY pOverlay, const DXGKARG_FLIPOVERLAY *pFlipInfo)
805{
806 PVBOXWDDM_ALLOCATION pAlloc = (PVBOXWDDM_ALLOCATION)pFlipInfo->hSource;
807 Assert(pAlloc->hHostHandle);
808 Assert(pAlloc->pResource);
809 Assert(pAlloc->pResource == pOverlay->pResource);
810 Assert(pFlipInfo->PrivateDriverDataSize == sizeof (VBOXWDDM_OVERLAYFLIP_INFO));
811 Assert(pFlipInfo->pPrivateDriverData);
812 PVBOXWDDM_SOURCE pSource = &pOverlay->pDevExt->aSources[pOverlay->VidPnSourceId];
813 Assert(!!(pSource->Vhwa.Settings.fFlags & VBOXVHWA_F_ENABLED));
814 PVBOXWDDM_ALLOCATION pFbSurf = VBOXVHWA_PRIMARY_ALLOCATION(pSource);
815 Assert(pFbSurf);
816 Assert(pFbSurf->hHostHandle);
817 Assert(pFbSurf->AllocData.Addr.offVram != VBOXVIDEOOFFSET_VOID);
818 Assert(pOverlay->pCurentAlloc);
819 Assert(pOverlay->pCurentAlloc->pResource == pOverlay->pResource);
820 Assert(pOverlay->pCurentAlloc != pAlloc);
821 int rc = VINF_SUCCESS;
822
823 if (pFbSurf->AllocData.Addr.SegmentId != 1)
824 {
825 WARN(("invalid segment id on flip"));
826 return VERR_INVALID_PARAMETER;
827 }
828
829 if (pFlipInfo->PrivateDriverDataSize == sizeof (VBOXWDDM_OVERLAYFLIP_INFO))
830 {
831 PVBOXWDDM_OVERLAYFLIP_INFO pOurInfo = (PVBOXWDDM_OVERLAYFLIP_INFO)pFlipInfo->pPrivateDriverData;
832
833 VBOXVHWACMD* pCmd = vboxVhwaCommandCreate(pOverlay->pDevExt, pOverlay->VidPnSourceId,
834 VBOXVHWACMD_TYPE_SURF_FLIP, sizeof(VBOXVHWACMD_SURF_FLIP));
835 Assert(pCmd);
836 if(pCmd)
837 {
838 VBOXVHWACMD_SURF_FLIP * pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_FLIP);
839
840 memset(pBody, 0, sizeof(VBOXVHWACMD_SURF_FLIP));
841
842// pBody->TargGuestSurfInfo;
843// pBody->CurrGuestSurfInfo;
844 pBody->u.in.hTargSurf = pAlloc->hHostHandle;
845 pBody->u.in.offTargSurface = pFlipInfo->SrcPhysicalAddress.QuadPart;
846 pAlloc->AllocData.Addr.offVram = pFlipInfo->SrcPhysicalAddress.QuadPart;
847 pBody->u.in.hCurrSurf = pOverlay->pCurentAlloc->hHostHandle;
848 pBody->u.in.offCurrSurface = pOverlay->pCurentAlloc->AllocData.Addr.offVram;
849 if (pOurInfo->DirtyRegion.fFlags & VBOXWDDM_DIRTYREGION_F_VALID)
850 {
851 pBody->u.in.xUpdatedTargMemValid = 1;
852 if (pOurInfo->DirtyRegion.fFlags & VBOXWDDM_DIRTYREGION_F_RECT_VALID)
853 pBody->u.in.xUpdatedTargMemRect = *(VBOXVHWA_RECTL*)((void*)&pOurInfo->DirtyRegion.Rect);
854 else
855 {
856 pBody->u.in.xUpdatedTargMemRect.right = pAlloc->AllocData.SurfDesc.width;
857 pBody->u.in.xUpdatedTargMemRect.bottom = pAlloc->AllocData.SurfDesc.height;
858 /* top & left are zero-inited with the above memset */
859 }
860 }
861
862 /* we're not interested in completion, just send the command */
863 vboxVhwaCommandSubmitAsynchAndComplete(pOverlay->pDevExt, pCmd);
864
865 pOverlay->pCurentAlloc = pAlloc;
866
867 rc = VINF_SUCCESS;
868 }
869 else
870 rc = VERR_OUT_OF_RESOURCES;
871 }
872 else
873 rc = VERR_INVALID_PARAMETER;
874
875 return rc;
876}
877
878AssertCompile(sizeof (RECT) == sizeof (VBOXVHWA_RECTL));
879AssertCompile(RT_SIZEOFMEMB(RECT, left) == RT_SIZEOFMEMB(VBOXVHWA_RECTL, left));
880AssertCompile(RT_SIZEOFMEMB(RECT, right) == RT_SIZEOFMEMB(VBOXVHWA_RECTL, right));
881AssertCompile(RT_SIZEOFMEMB(RECT, top) == RT_SIZEOFMEMB(VBOXVHWA_RECTL, top));
882AssertCompile(RT_SIZEOFMEMB(RECT, bottom) == RT_SIZEOFMEMB(VBOXVHWA_RECTL, bottom));
883AssertCompile(RT_OFFSETOF(RECT, left) == RT_OFFSETOF(VBOXVHWA_RECTL, left));
884AssertCompile(RT_OFFSETOF(RECT, right) == RT_OFFSETOF(VBOXVHWA_RECTL, right));
885AssertCompile(RT_OFFSETOF(RECT, top) == RT_OFFSETOF(VBOXVHWA_RECTL, top));
886AssertCompile(RT_OFFSETOF(RECT, bottom) == RT_OFFSETOF(VBOXVHWA_RECTL, bottom));
887
888int vboxVhwaHlpColorFill(PVBOXWDDM_OVERLAY pOverlay, PVBOXWDDM_DMA_PRIVATEDATA_CLRFILL pCF)
889{
890 PVBOXWDDM_ALLOCATION pAlloc = pCF->ClrFill.Alloc.pAlloc;
891 Assert(pAlloc->pResource == pOverlay->pResource);
892
893 if (pAlloc->AllocData.Addr.SegmentId != 1)
894 {
895 WARN(("invalid segment id on color fill"));
896 return VERR_INVALID_PARAMETER;
897 }
898
899 Assert(pAlloc->hHostHandle);
900 Assert(pAlloc->pResource);
901 Assert(pAlloc->AllocData.Addr.offVram != VBOXVIDEOOFFSET_VOID);
902
903 int rc;
904 VBOXVHWACMD* pCmd = vboxVhwaCommandCreate(pOverlay->pDevExt, pOverlay->VidPnSourceId,
905 VBOXVHWACMD_TYPE_SURF_FLIP, RT_OFFSETOF(VBOXVHWACMD_SURF_COLORFILL, u.in.aRects[pCF->ClrFill.Rects.cRects]));
906 Assert(pCmd);
907 if(pCmd)
908 {
909 VBOXVHWACMD_SURF_COLORFILL * pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_COLORFILL);
910
911 memset(pBody, 0, sizeof(VBOXVHWACMD_SURF_COLORFILL));
912
913 pBody->u.in.hSurf = pAlloc->hHostHandle;
914 pBody->u.in.offSurface = pAlloc->AllocData.Addr.offVram;
915 pBody->u.in.cRects = pCF->ClrFill.Rects.cRects;
916 memcpy (pBody->u.in.aRects, pCF->ClrFill.Rects.aRects, pCF->ClrFill.Rects.cRects * sizeof (pCF->ClrFill.Rects.aRects[0]));
917 vboxVhwaCommandSubmitAsynchAndComplete(pOverlay->pDevExt, pCmd);
918
919 rc = VINF_SUCCESS;
920 }
921 else
922 rc = VERR_OUT_OF_RESOURCES;
923
924 return rc;
925}
926
927static void vboxVhwaHlpOverlayDstRectSet(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_OVERLAY pOverlay, const RECT *pRect)
928{
929 PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[pOverlay->VidPnSourceId];
930 KIRQL OldIrql;
931 KeAcquireSpinLock(&pSource->OverlayListLock, &OldIrql);
932 pOverlay->DstRect = *pRect;
933 KeReleaseSpinLock(&pSource->OverlayListLock, OldIrql);
934}
935
936static void vboxVhwaHlpOverlayListAdd(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_OVERLAY pOverlay)
937{
938 PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[pOverlay->VidPnSourceId];
939 KIRQL OldIrql;
940 KeAcquireSpinLock(&pSource->OverlayListLock, &OldIrql);
941 ASMAtomicIncU32(&pSource->cOverlays);
942 InsertHeadList(&pSource->OverlayList, &pOverlay->ListEntry);
943 KeReleaseSpinLock(&pSource->OverlayListLock, OldIrql);
944}
945
946static void vboxVhwaHlpOverlayListRemove(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_OVERLAY pOverlay)
947{
948 PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[pOverlay->VidPnSourceId];
949 KIRQL OldIrql;
950 KeAcquireSpinLock(&pSource->OverlayListLock, &OldIrql);
951 ASMAtomicDecU32(&pSource->cOverlays);
952 RemoveEntryList(&pOverlay->ListEntry);
953 KeReleaseSpinLock(&pSource->OverlayListLock, OldIrql);
954}
955
956AssertCompile(sizeof (RECT) == sizeof (VBOXVHWA_RECTL));
957AssertCompile(RT_SIZEOFMEMB(RECT, left) == RT_SIZEOFMEMB(VBOXVHWA_RECTL, left));
958AssertCompile(RT_SIZEOFMEMB(RECT, right) == RT_SIZEOFMEMB(VBOXVHWA_RECTL, right));
959AssertCompile(RT_SIZEOFMEMB(RECT, top) == RT_SIZEOFMEMB(VBOXVHWA_RECTL, top));
960AssertCompile(RT_SIZEOFMEMB(RECT, bottom) == RT_SIZEOFMEMB(VBOXVHWA_RECTL, bottom));
961AssertCompile(RT_OFFSETOF(RECT, left) == RT_OFFSETOF(VBOXVHWA_RECTL, left));
962AssertCompile(RT_OFFSETOF(RECT, right) == RT_OFFSETOF(VBOXVHWA_RECTL, right));
963AssertCompile(RT_OFFSETOF(RECT, top) == RT_OFFSETOF(VBOXVHWA_RECTL, top));
964AssertCompile(RT_OFFSETOF(RECT, bottom) == RT_OFFSETOF(VBOXVHWA_RECTL, bottom));
965
966int vboxVhwaHlpOverlayUpdate(PVBOXWDDM_OVERLAY pOverlay, const DXGK_OVERLAYINFO *pOverlayInfo, RECT * pDstUpdateRect)
967{
968 PVBOXWDDM_ALLOCATION pAlloc = (PVBOXWDDM_ALLOCATION)pOverlayInfo->hAllocation;
969 Assert(pAlloc->hHostHandle);
970 Assert(pAlloc->pResource);
971 Assert(pAlloc->pResource == pOverlay->pResource);
972 Assert(pOverlayInfo->PrivateDriverDataSize == sizeof (VBOXWDDM_OVERLAY_INFO));
973 Assert(pOverlayInfo->pPrivateDriverData);
974 PVBOXWDDM_SOURCE pSource = &pOverlay->pDevExt->aSources[pOverlay->VidPnSourceId];
975 Assert(!!(pSource->Vhwa.Settings.fFlags & VBOXVHWA_F_ENABLED));
976 PVBOXWDDM_ALLOCATION pFbSurf = VBOXVHWA_PRIMARY_ALLOCATION(pSource);
977 Assert(pFbSurf);
978 Assert(pFbSurf->hHostHandle);
979 Assert(pFbSurf->AllocData.Addr.offVram != VBOXVIDEOOFFSET_VOID);
980 int rc = VINF_SUCCESS;
981
982 if (pFbSurf->AllocData.Addr.SegmentId != 1)
983 {
984 WARN(("invalid segment id on overlay update"));
985 return VERR_INVALID_PARAMETER;
986 }
987
988 if (pOverlayInfo->PrivateDriverDataSize == sizeof (VBOXWDDM_OVERLAY_INFO))
989 {
990 PVBOXWDDM_OVERLAY_INFO pOurInfo = (PVBOXWDDM_OVERLAY_INFO)pOverlayInfo->pPrivateDriverData;
991
992 VBOXVHWACMD* pCmd = vboxVhwaCommandCreate(pOverlay->pDevExt, pOverlay->VidPnSourceId,
993 VBOXVHWACMD_TYPE_SURF_OVERLAY_UPDATE, sizeof(VBOXVHWACMD_SURF_OVERLAY_UPDATE));
994 Assert(pCmd);
995 if(pCmd)
996 {
997 VBOXVHWACMD_SURF_OVERLAY_UPDATE * pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_OVERLAY_UPDATE);
998
999 memset(pBody, 0, sizeof(VBOXVHWACMD_SURF_OVERLAY_UPDATE));
1000
1001 pBody->u.in.hDstSurf = pFbSurf->hHostHandle;
1002 pBody->u.in.offDstSurface = pFbSurf->AllocData.Addr.offVram;
1003 pBody->u.in.dstRect = *(VBOXVHWA_RECTL*)((void*)&pOverlayInfo->DstRect);
1004 pBody->u.in.hSrcSurf = pAlloc->hHostHandle;
1005 pBody->u.in.offSrcSurface = pOverlayInfo->PhysicalAddress.QuadPart;
1006 pAlloc->AllocData.Addr.offVram = pOverlayInfo->PhysicalAddress.QuadPart;
1007 pBody->u.in.srcRect = *(VBOXVHWA_RECTL*)((void*)&pOverlayInfo->SrcRect);
1008 pBody->u.in.flags |= VBOXVHWA_OVER_SHOW;
1009 if (pOurInfo->OverlayDesc.fFlags & VBOXWDDM_OVERLAY_F_CKEY_DST)
1010 {
1011 pBody->u.in.flags |= VBOXVHWA_OVER_KEYDESTOVERRIDE /* ?? VBOXVHWA_OVER_KEYDEST */;
1012 pBody->u.in.desc.DstCK.high = pOurInfo->OverlayDesc.DstColorKeyHigh;
1013 pBody->u.in.desc.DstCK.low = pOurInfo->OverlayDesc.DstColorKeyLow;
1014 }
1015
1016 if (pOurInfo->OverlayDesc.fFlags & VBOXWDDM_OVERLAY_F_CKEY_SRC)
1017 {
1018 pBody->u.in.flags |= VBOXVHWA_OVER_KEYSRCOVERRIDE /* ?? VBOXVHWA_OVER_KEYSRC */;
1019 pBody->u.in.desc.SrcCK.high = pOurInfo->OverlayDesc.SrcColorKeyHigh;
1020 pBody->u.in.desc.SrcCK.low = pOurInfo->OverlayDesc.SrcColorKeyLow;
1021 }
1022
1023 if (pOurInfo->DirtyRegion.fFlags & VBOXWDDM_DIRTYREGION_F_VALID)
1024 {
1025 pBody->u.in.xFlags |= VBOXVHWACMD_SURF_OVERLAY_UPDATE_F_SRCMEMRECT;
1026 if (pOurInfo->DirtyRegion.fFlags & VBOXWDDM_DIRTYREGION_F_RECT_VALID)
1027 pBody->u.in.xUpdatedSrcMemRect = *(VBOXVHWA_RECTL*)((void*)&pOurInfo->DirtyRegion.Rect);
1028 else
1029 {
1030 pBody->u.in.xUpdatedSrcMemRect.right = pAlloc->AllocData.SurfDesc.width;
1031 pBody->u.in.xUpdatedSrcMemRect.bottom = pAlloc->AllocData.SurfDesc.height;
1032 /* top & left are zero-inited with the above memset */
1033 }
1034 }
1035
1036 if (pDstUpdateRect)
1037 {
1038 pBody->u.in.xFlags |= VBOXVHWACMD_SURF_OVERLAY_UPDATE_F_DSTMEMRECT;
1039 pBody->u.in.xUpdatedDstMemRect = *(VBOXVHWA_RECTL*)((void*)pDstUpdateRect);
1040 }
1041
1042 /* we're not interested in completion, just send the command */
1043 vboxVhwaCommandSubmitAsynchAndComplete(pOverlay->pDevExt, pCmd);
1044
1045 pOverlay->pCurentAlloc = pAlloc;
1046
1047 vboxVhwaHlpOverlayDstRectSet(pOverlay->pDevExt, pOverlay, &pOverlayInfo->DstRect);
1048
1049 rc = VINF_SUCCESS;
1050 }
1051 else
1052 rc = VERR_OUT_OF_RESOURCES;
1053 }
1054 else
1055 rc = VERR_INVALID_PARAMETER;
1056
1057 return rc;
1058}
1059
1060int vboxVhwaHlpOverlayUpdate(PVBOXWDDM_OVERLAY pOverlay, const DXGK_OVERLAYINFO *pOverlayInfo)
1061{
1062 return vboxVhwaHlpOverlayUpdate(pOverlay, pOverlayInfo, NULL);
1063}
1064
1065int vboxVhwaHlpOverlayDestroy(PVBOXWDDM_OVERLAY pOverlay)
1066{
1067 int rc = VINF_SUCCESS;
1068
1069 vboxVhwaHlpOverlayListRemove(pOverlay->pDevExt, pOverlay);
1070
1071 for (uint32_t i = 0; i < pOverlay->pResource->cAllocations; ++i)
1072 {
1073 PVBOXWDDM_ALLOCATION pCurAlloc = &pOverlay->pResource->aAllocations[i];
1074 rc = vboxVhwaHlpDestroySurface(pOverlay->pDevExt, pCurAlloc, pOverlay->VidPnSourceId);
1075 AssertRC(rc);
1076 }
1077
1078 if (RT_SUCCESS(rc))
1079 {
1080 int tmpRc = vboxVhwaHlpCheckTerm(pOverlay->pDevExt, pOverlay->VidPnSourceId);
1081 AssertRC(tmpRc);
1082 }
1083
1084 return rc;
1085}
1086
1087
1088int vboxVhwaHlpOverlayCreate(PVBOXMP_DEVEXT pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId, DXGK_OVERLAYINFO *pOverlayInfo,
1089 /* OUT */ PVBOXWDDM_OVERLAY pOverlay)
1090{
1091 int rc = vboxVhwaHlpCheckInit(pDevExt, VidPnSourceId);
1092 AssertRC(rc);
1093 if (RT_SUCCESS(rc))
1094 {
1095 PVBOXWDDM_ALLOCATION pAlloc = (PVBOXWDDM_ALLOCATION)pOverlayInfo->hAllocation;
1096 PVBOXWDDM_RESOURCE pRc = pAlloc->pResource;
1097 Assert(pRc);
1098 for (uint32_t i = 0; i < pRc->cAllocations; ++i)
1099 {
1100 PVBOXWDDM_ALLOCATION pCurAlloc = &pRc->aAllocations[i];
1101 rc = vboxVhwaHlpCreateSurface(pDevExt, pCurAlloc,
1102 0, pRc->cAllocations - 1, VBOXVHWA_SCAPS_OVERLAY | VBOXVHWA_SCAPS_VIDEOMEMORY | VBOXVHWA_SCAPS_LOCALVIDMEM | VBOXVHWA_SCAPS_COMPLEX,
1103 VidPnSourceId);
1104 AssertRC(rc);
1105 if (!RT_SUCCESS(rc))
1106 {
1107 int tmpRc;
1108 for (uint32_t j = 0; j < i; ++j)
1109 {
1110 PVBOXWDDM_ALLOCATION pDestroyAlloc = &pRc->aAllocations[j];
1111 tmpRc = vboxVhwaHlpDestroySurface(pDevExt, pDestroyAlloc, VidPnSourceId);
1112 AssertRC(tmpRc);
1113 }
1114 break;
1115 }
1116 }
1117
1118 if (RT_SUCCESS(rc))
1119 {
1120 pOverlay->pDevExt = pDevExt;
1121 pOverlay->pResource = pRc;
1122 pOverlay->VidPnSourceId = VidPnSourceId;
1123
1124 vboxVhwaHlpOverlayListAdd(pDevExt, pOverlay);
1125
1126 RECT DstRect;
1127 vboxVhwaHlpOverlayDstRectGet(pDevExt, pOverlay, &DstRect);
1128
1129 rc = vboxVhwaHlpOverlayUpdate(pOverlay, pOverlayInfo, DstRect.right ? &DstRect : NULL);
1130 if (!RT_SUCCESS(rc))
1131 {
1132 int tmpRc = vboxVhwaHlpOverlayDestroy(pOverlay);
1133 AssertRC(tmpRc);
1134 }
1135 }
1136
1137 if (RT_FAILURE(rc))
1138 {
1139 int tmpRc = vboxVhwaHlpCheckTerm(pDevExt, VidPnSourceId);
1140 AssertRC(tmpRc);
1141 AssertRC(rc);
1142 }
1143 }
1144
1145 return rc;
1146}
1147
1148BOOLEAN vboxVhwaHlpOverlayListIsEmpty(PVBOXMP_DEVEXT pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId)
1149{
1150 PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[VidPnSourceId];
1151 return !ASMAtomicReadU32(&pSource->cOverlays);
1152}
1153
1154#define VBOXWDDM_OVERLAY_FROM_ENTRY(_pEntry) ((PVBOXWDDM_OVERLAY)(((uint8_t*)(_pEntry)) - RT_OFFSETOF(VBOXWDDM_OVERLAY, ListEntry)))
1155
1156void vboxVhwaHlpOverlayDstRectUnion(PVBOXMP_DEVEXT pDevExt, D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId, RECT *pRect)
1157{
1158 if (vboxVhwaHlpOverlayListIsEmpty(pDevExt, VidPnSourceId))
1159 {
1160 memset(pRect, 0, sizeof (*pRect));
1161 return;
1162 }
1163
1164 PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[VidPnSourceId];
1165 KIRQL OldIrql;
1166 KeAcquireSpinLock(&pSource->OverlayListLock, &OldIrql);
1167 if (pSource->cOverlays)
1168 {
1169 PVBOXWDDM_OVERLAY pOverlay = VBOXWDDM_OVERLAY_FROM_ENTRY(pSource->OverlayList.Flink);
1170 *pRect = pOverlay->DstRect;
1171 while (pOverlay->ListEntry.Flink != &pSource->OverlayList)
1172 {
1173 pOverlay = VBOXWDDM_OVERLAY_FROM_ENTRY(pOverlay->ListEntry.Flink);
1174 vboxWddmRectUnite(pRect, &pOverlay->DstRect);
1175 }
1176 }
1177 KeReleaseSpinLock(&pSource->OverlayListLock, OldIrql);
1178}
1179
1180void vboxVhwaHlpOverlayDstRectGet(PVBOXMP_DEVEXT pDevExt, PVBOXWDDM_OVERLAY pOverlay, RECT *pRect)
1181{
1182 PVBOXWDDM_SOURCE pSource = &pDevExt->aSources[pOverlay->VidPnSourceId];
1183 KIRQL OldIrql;
1184 KeAcquireSpinLock(&pSource->OverlayListLock, &OldIrql);
1185 *pRect = pOverlay->DstRect;
1186 KeReleaseSpinLock(&pSource->OverlayListLock, OldIrql);
1187}
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