VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Miniport/wddm/VBoxVideoIf.h@ 32580

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

wddm/3d: Aero working cleanly on win7

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.5 KB
Line 
1/** @file
2 * Contains base definitions of constants & structures used
3 * to control & perform rendering,
4 * such as DMA commands types, allocation types, escape codes, etc.
5 * used by both miniport & display drivers.
6 *
7 * The latter uses these and only these defs to communicate with the former
8 * by posting appropriate requests via D3D RT Krnl Svc accessing callbacks.
9 */
10/*
11 * Copyright (C) 2010 Oracle Corporation
12 *
13 * This file is part of VirtualBox Open Source Edition (OSE), as
14 * available from http://www.virtualbox.org. This file is free software;
15 * you can redistribute it and/or modify it under the terms of the GNU
16 * General Public License (GPL) as published by the Free Software
17 * Foundation, in version 2 as it comes in the "COPYING" file of the
18 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
19 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
20 */
21#ifndef ___VBoxVideoIf_h___
22#define ___VBoxVideoIf_h___
23
24#include <VBox/VBoxVideo.h>
25#include "../../../include/VBoxDisplay.h"
26
27#include <iprt/assert.h>
28
29
30/* One would increase this whenever definitions in this file are changed */
31#define VBOXVIDEOIF_VERSION 5
32
33/* create allocation func */
34typedef enum
35{
36 VBOXWDDM_ALLOC_TYPE_UNEFINED = 0,
37 VBOXWDDM_ALLOC_TYPE_STD_SHAREDPRIMARYSURFACE,
38 VBOXWDDM_ALLOC_TYPE_STD_SHADOWSURFACE,
39 VBOXWDDM_ALLOC_TYPE_STD_STAGINGSURFACE,
40 /* this one is win 7-specific and hence unused for now */
41 VBOXWDDM_ALLOC_TYPE_STD_GDISURFACE
42 /* custom allocation types requested from user-mode d3d module will go here */
43 , VBOXWDDM_ALLOC_TYPE_UMD_RC_GENERIC
44} VBOXWDDM_ALLOC_TYPE;
45
46/* usage */
47typedef enum
48{
49 VBOXWDDM_ALLOCUSAGE_TYPE_UNEFINED = 0,
50 /* set for the allocation being primary */
51 VBOXWDDM_ALLOCUSAGE_TYPE_PRIMARY,
52} VBOXWDDM_ALLOCUSAGE_TYPE;
53
54typedef struct VBOXWDDM_SURFACE_DESC
55{
56 UINT width;
57 UINT height;
58 D3DDDIFORMAT format;
59 UINT bpp;
60 UINT pitch;
61 UINT depth;
62 UINT slicePitch;
63 UINT cbSize;
64 D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId;
65 D3DDDI_RATIONAL RefreshRate;
66} VBOXWDDM_SURFACE_DESC, *PVBOXWDDM_SURFACE_DESC;
67
68typedef struct VBOXWDDM_ALLOCINFO
69{
70 VBOXWDDM_ALLOC_TYPE enmType;
71 D3DDDI_RESOURCEFLAGS fFlags;
72 HANDLE hSharedHandle;
73 VBOXWDDM_SURFACE_DESC SurfDesc;
74} VBOXWDDM_ALLOCINFO, *PVBOXWDDM_ALLOCINFO;
75
76/* this resource is OpenResource'd rather than CreateResource'd */
77#define VBOXWDDM_RESOURCE_F_OPENNED 0x00000001
78/* identifies this is a resource created with CreateResource, the VBOXWDDMDISP_RESOURCE::fRcFlags is valid */
79#define VBOXWDDM_RESOURCE_F_TYPE_GENERIC 0x00000002
80
81typedef struct VBOXWDDM_RC_DESC
82{
83 D3DDDI_RESOURCEFLAGS fFlags;
84 D3DDDIFORMAT enmFormat;
85 D3DDDI_POOL enmPool;
86 D3DDDIMULTISAMPLE_TYPE enmMultisampleType;
87 UINT MultisampleQuality;
88 UINT MipLevels;
89 UINT Fvf;
90 D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId;
91 D3DDDI_RATIONAL RefreshRate;
92 D3DDDI_ROTATION enmRotation;
93} VBOXWDDM_RC_DESC, *PVBOXWDDM_RC_DESC;
94
95typedef struct VBOXWDDM_RCINFO
96{
97 uint32_t fFlags;
98 VBOXWDDM_RC_DESC RcDesc;
99 uint32_t cAllocInfos;
100// VBOXWDDM_ALLOCINFO aAllocInfos[1];
101} VBOXWDDM_RCINFO, *PVBOXWDDM_RCINFO;
102
103#define VBOXVHWA_F_ENABLED 0x00000001
104#define VBOXVHWA_F_CKEY_DST 0x00000002
105#define VBOXVHWA_F_CKEY_SRC 0x00000004
106
107#define VBOXVHWA_MAX_FORMATS 8
108
109typedef struct VBOXVHWA_INFO
110{
111 uint32_t fFlags;
112 uint32_t cOverlaysSupported;
113 uint32_t cFormats;
114 D3DDDIFORMAT aFormats[VBOXVHWA_MAX_FORMATS];
115} VBOXVHWA_INFO;
116
117#define VBOXWDDM_OVERLAY_F_CKEY_DST 0x00000001
118#define VBOXWDDM_OVERLAY_F_CKEY_DSTRANGE 0x00000002
119#define VBOXWDDM_OVERLAY_F_CKEY_SRC 0x00000004
120#define VBOXWDDM_OVERLAY_F_CKEY_SRCRANGE 0x00000008
121#define VBOXWDDM_OVERLAY_F_BOB 0x00000010
122#define VBOXWDDM_OVERLAY_F_INTERLEAVED 0x00000020
123#define VBOXWDDM_OVERLAY_F_MIRROR_LR 0x00000040
124#define VBOXWDDM_OVERLAY_F_MIRROR_UD 0x00000080
125#define VBOXWDDM_OVERLAY_F_DEINTERLACED 0x00000100
126
127typedef struct VBOXWDDM_OVERLAY_DESC
128{
129 uint32_t fFlags;
130 UINT DstColorKeyLow;
131 UINT DstColorKeyHigh;
132 UINT SrcColorKeyLow;
133 UINT SrcColorKeyHigh;
134} VBOXWDDM_OVERLAY_DESC, *PVBOXWDDM_OVERLAY_DESC;
135
136/* the dirty rect info is valid */
137#define VBOXWDDM_DIRTYREGION_F_VALID 0x00000001
138#define VBOXWDDM_DIRTYREGION_F_RECT_VALID 0x00000002
139
140typedef struct VBOXWDDM_DIRTYREGION
141{
142 uint32_t fFlags; /* <-- see VBOXWDDM_DIRTYREGION_F_xxx flags above */
143 RECT Rect;
144} VBOXWDDM_DIRTYREGION, *PVBOXWDDM_DIRTYREGION;
145
146typedef struct VBOXWDDM_OVERLAY_INFO
147{
148 VBOXWDDM_OVERLAY_DESC OverlayDesc;
149 VBOXWDDM_DIRTYREGION DirtyRegion; /* <- the dirty region of the overlay surface */
150} VBOXWDDM_OVERLAY_INFO, *PVBOXWDDM_OVERLAY_INFO;
151
152typedef struct VBOXWDDM_OVERLAYFLIP_INFO
153{
154 VBOXWDDM_DIRTYREGION DirtyRegion; /* <- the dirty region of the overlay surface */
155} VBOXWDDM_OVERLAYFLIP_INFO, *PVBOXWDDM_OVERLAYFLIP_INFO;
156
157typedef struct VBOXWDDM_CREATECONTEXT_INFO
158{
159 /* interface version, i.e. 9 for d3d9, 8 for d3d8, etc. */
160 uint32_t u32IfVersion;
161 /* true if d3d false if ddraw */
162 uint32_t u32IsD3D;
163 /* we use uint64_t instead of HANDLE to ensure structure def is the same for both 32-bit and 64-bit
164 * since x64 kernel driver can be called by 32-bit UMD */
165 uint64_t hUmEvent;
166 /* info to be passed to UMD notification to identify the context */
167 uint64_t u64UmInfo;
168} VBOXWDDM_CREATECONTEXT_INFO, *PVBOXWDDM_CREATECONTEXT_INFO;
169
170typedef void *VBOXDISP_UMHANDLE;
171typedef uint32_t VBOXDISP_KMHANDLE;
172
173typedef struct VBOXWDDM_RECTS_FLAFS
174{
175 union
176 {
177 struct
178 {
179 /* used only in conjunction with bSetVisibleRects.
180 * if set - VBOXWDDM_RECTS_INFO::aRects[0] contains view rectangle */
181 UINT bSetViewRect : 1;
182 /* sets visible regions */
183 UINT bSetVisibleRects : 1;
184 /* adds hidden regions */
185 UINT bAddHiddenRects : 1;
186 UINT Reserved : 29;
187 };
188 uint32_t Value;
189 };
190} VBOXWDDM_RECTS_FLAFS, *PVBOXWDDM_RECTS_FLAFS;
191
192typedef struct VBOXWDDM_RECTS_INFO
193{
194 uint32_t cRects;
195 RECT aRects[1];
196} VBOXWDDM_RECTS_INFO, *PVBOXWDDM_RECTS_INFO;
197
198#define VBOXWDDM_RECTS_INFO_SIZE4CRECTS(_cRects) (RT_OFFSETOF(VBOXWDDM_RECTS_INFO, aRects[(_cRects)]))
199#define VBOXWDDM_RECTS_INFO_SIZE(_pRects) (VBOXVIDEOCM_CMD_RECTS_SIZE4CRECTS((_pRects)->cRects))
200
201typedef struct VBOXVIDEOCM_CMD_HDR
202{
203 uint64_t u64UmData;
204 uint32_t cbCmd;
205 uint32_t u32CmdSpecific;
206}VBOXVIDEOCM_CMD_HDR, *PVBOXVIDEOCM_CMD_HDR;
207
208AssertCompile((sizeof (VBOXVIDEOCM_CMD_HDR) & 7) == 0);
209
210typedef struct VBOXVIDEOCM_CMD_RECTS
211{
212 VBOXWDDM_RECTS_FLAFS fFlags;
213 VBOXWDDM_RECTS_INFO RectsInfo;
214} VBOXVIDEOCM_CMD_RECTS, *PVBOXVIDEOCM_CMD_RECTS;
215
216typedef struct VBOXVIDEOCM_CMD_RECTS_INTERNAL
217{
218 union
219 {
220 VBOXDISP_UMHANDLE hSwapchainUm;
221 uint64_t u64Alignment;
222 };
223 VBOXVIDEOCM_CMD_RECTS Cmd;
224} VBOXVIDEOCM_CMD_RECTS_INTERNAL, *PVBOXVIDEOCM_CMD_RECTS_INTERNAL;
225
226#define VBOXVIDEOCM_CMD_RECTS_INTERNAL_SIZE4CRECTS(_cRects) (RT_OFFSETOF(VBOXVIDEOCM_CMD_RECTS_INTERNAL, Cmd.RectsInfo.aRects[(_cRects)]))
227#define VBOXVIDEOCM_CMD_RECTS_INTERNAL_SIZE(_pCmd) (VBOXVIDEOCM_CMD_RECTS_INTERNAL_SIZE4CRECTS((_pCmd)->cRects))
228
229typedef struct VBOXWDDM_GETVBOXVIDEOCMCMD_HDR
230{
231 uint32_t cbCmdsReturned;
232 uint32_t cbRemainingCmds;
233 uint32_t cbRemainingFirstCmd;
234 uint32_t u32Reserved;
235} VBOXWDDM_GETVBOXVIDEOCMCMD_HDR, *PVBOXWDDM_GETVBOXVIDEOCMCMD_HDR;
236
237typedef struct VBOXDISPIFESCAPE_GETVBOXVIDEOCMCMD
238{
239 VBOXDISPIFESCAPE EscapeHdr;
240 VBOXWDDM_GETVBOXVIDEOCMCMD_HDR Hdr;
241} VBOXDISPIFESCAPE_GETVBOXVIDEOCMCMD, *PVBOXDISPIFESCAPE_GETVBOXVIDEOCMCMD;
242
243AssertCompile((sizeof (VBOXDISPIFESCAPE_GETVBOXVIDEOCMCMD) & 7) == 0);
244AssertCompile(RT_OFFSETOF(VBOXDISPIFESCAPE_GETVBOXVIDEOCMCMD, EscapeHdr) == 0);
245
246typedef struct VBOXDISPIFESCAPE_DBGPRINT
247{
248 VBOXDISPIFESCAPE EscapeHdr;
249 /* null-terminated string to DbgPrint including \0 */
250 char aStringBuf[1];
251} VBOXDISPIFESCAPE_DBGPRINT, *PVBOXDISPIFESCAPE_DBGPRINT;
252AssertCompile(RT_OFFSETOF(VBOXDISPIFESCAPE_DBGPRINT, EscapeHdr) == 0);
253
254typedef struct VBOXSCREENLAYOUT_ELEMENT
255{
256 D3DDDI_VIDEO_PRESENT_SOURCE_ID VidPnSourceId;
257 POINT pos;
258} VBOXSCREENLAYOUT_ELEMENT, *PVBOXSCREENLAYOUT_ELEMENT;
259
260typedef struct VBOXSCREENLAYOUT
261{
262 uint32_t cScreens;
263 VBOXSCREENLAYOUT_ELEMENT aScreens[1];
264} VBOXSCREENLAYOUT, *PVBOXSCREENLAYOUT;
265
266typedef struct VBOXDISPIFESCAPE_SCREENLAYOUT
267{
268 VBOXDISPIFESCAPE EscapeHdr;
269 VBOXSCREENLAYOUT ScreenLayout;
270} VBOXDISPIFESCAPE_SCREENLAYOUT, *PVBOXDISPIFESCAPE_SCREENLAYOUT;
271
272typedef struct VBOXSWAPCHAININFO
273{
274 VBOXDISP_KMHANDLE hSwapchainKm; /* in, NULL if new is being created */
275 VBOXDISP_UMHANDLE hSwapchainUm; /* in, UMD private data */
276 RECT Rect;
277 UINT u32Reserved;
278 UINT cAllocs;
279 D3DKMT_HANDLE ahAllocs[1];
280}VBOXSWAPCHAININFO, *PVBOXSWAPCHAININFO;
281typedef struct VBOXDISPIFESCAPE_SWAPCHAININFO
282{
283 VBOXDISPIFESCAPE EscapeHdr;
284 VBOXSWAPCHAININFO SwapchainInfo;
285} VBOXDISPIFESCAPE_SWAPCHAININFO, *PVBOXDISPIFESCAPE_SWAPCHAININFO;
286
287/* query info func */
288typedef struct VBOXWDDM_QI
289{
290 uint32_t u32Version;
291 uint32_t cInfos;
292 VBOXVHWA_INFO aInfos[VBOX_VIDEO_MAX_SCREENS];
293} VBOXWDDM_QI;
294
295/* submit cmd func */
296
297/* tooling */
298DECLINLINE(UINT) vboxWddmCalcBitsPerPixel(D3DDDIFORMAT format)
299{
300 switch (format)
301 {
302 case D3DDDIFMT_R8G8B8:
303 return 24;
304 case D3DDDIFMT_A8R8G8B8:
305 case D3DDDIFMT_X8R8G8B8:
306 return 32;
307 case D3DDDIFMT_R5G6B5:
308 case D3DDDIFMT_X1R5G5B5:
309 case D3DDDIFMT_A1R5G5B5:
310 case D3DDDIFMT_A4R4G4B4:
311 return 16;
312 case D3DDDIFMT_R3G3B2:
313 case D3DDDIFMT_A8:
314 return 8;
315 case D3DDDIFMT_A8R3G3B2:
316 case D3DDDIFMT_X4R4G4B4:
317 return 16;
318 case D3DDDIFMT_A2B10G10R10:
319 case D3DDDIFMT_A8B8G8R8:
320 case D3DDDIFMT_X8B8G8R8:
321 case D3DDDIFMT_G16R16:
322 case D3DDDIFMT_A2R10G10B10:
323 return 32;
324 case D3DDDIFMT_A16B16G16R16:
325 return 64;
326 case D3DDDIFMT_A8P8:
327 return 16;
328 case D3DDDIFMT_P8:
329 case D3DDDIFMT_L8:
330 return 8;
331 case D3DDDIFMT_A8L8:
332 return 16;
333 case D3DDDIFMT_A4L4:
334 return 8;
335 case D3DDDIFMT_V8U8:
336 case D3DDDIFMT_L6V5U5:
337 return 16;
338 case D3DDDIFMT_X8L8V8U8:
339 case D3DDDIFMT_Q8W8V8U8:
340 case D3DDDIFMT_V16U16:
341 case D3DDDIFMT_W11V11U10:
342 case D3DDDIFMT_A2W10V10U10:
343 return 32;
344 case D3DDDIFMT_D16_LOCKABLE:
345 case D3DDDIFMT_D16:
346 case D3DDDIFMT_D15S1:
347 return 16;
348 case D3DDDIFMT_D32:
349 case D3DDDIFMT_D24S8:
350 case D3DDDIFMT_D24X8:
351 case D3DDDIFMT_D24X4S4:
352 case D3DDDIFMT_D24FS8:
353 case D3DDDIFMT_D32_LOCKABLE:
354 case D3DDDIFMT_D32F_LOCKABLE:
355 return 32;
356 case D3DDDIFMT_S8_LOCKABLE:
357 return 8;
358 default:
359 AssertBreakpoint();
360 return 0;
361 }
362}
363
364DECLINLINE(uint32_t) vboxWddmFormatToFourcc(D3DDDIFORMAT format)
365{
366 uint32_t uFormat = (uint32_t)format;
367 /* assume that in case both four bytes are non-zero, this is a fourcc */
368 if ((format & 0xff000000)
369 && (format & 0x00ff0000)
370 && (format & 0x0000ff00)
371 && (format & 0x000000ff)
372 )
373 return uFormat;
374 return 0;
375}
376
377#define VBOXWDDM_ROUNDBOUND(_v, _b) (((_v) + ((_b) - 1)) & ~((_b) - 1))
378
379DECLINLINE(UINT) vboxWddmCalcPitch(UINT w, UINT bitsPerPixel)
380{
381 UINT Pitch = bitsPerPixel * w;
382 /* pitch is now in bits, translate in bytes */
383 return VBOXWDDM_ROUNDBOUND(Pitch, 8) >> 3;
384}
385
386DECLINLINE(void) vboxWddmRectUnite(RECT *pR, const RECT *pR2Unite)
387{
388 pR->left = RT_MIN(pR->left, pR2Unite->left);
389 pR->top = RT_MIN(pR->top, pR2Unite->top);
390 pR->right = RT_MAX(pR->right, pR2Unite->right);
391 pR->bottom = RT_MAX(pR->bottom, pR2Unite->bottom);
392}
393
394DECLINLINE(bool) vboxWddmRectIntersection(const RECT *a, const RECT *b, RECT *rect)
395{
396 Assert(a);
397 Assert(b);
398 Assert(rect);
399 rect->left = RT_MAX(a->left, b->left);
400 rect->right = RT_MIN(a->right, b->right);
401 rect->top = RT_MAX(a->top, b->top);
402 rect->bottom = RT_MIN(a->bottom, b->bottom);
403 return (rect->right>rect->left) && (rect->bottom>rect->top);
404}
405
406DECLINLINE(bool) vboxWddmRectIsEqual(const RECT *pRect1, const RECT *pRect2)
407{
408 Assert(pRect1);
409 Assert(pRect2);
410 if (pRect1->left != pRect2->left)
411 return false;
412 if (pRect1->top != pRect2->top)
413 return false;
414 if (pRect1->right != pRect2->right)
415 return false;
416 if (pRect1->bottom != pRect2->bottom)
417 return false;
418 return true;
419}
420
421DECLINLINE(bool) vboxWddmRectIsCoveres(const RECT *pRect, const RECT *pCovered)
422{
423 Assert(pRect);
424 Assert(pCovered);
425 if (pRect->left > pCovered->left)
426 return false;
427 if (pRect->top > pCovered->top)
428 return false;
429 if (pRect->right < pCovered->right)
430 return false;
431 if (pRect->bottom < pCovered->bottom)
432 return false;
433 return true;
434}
435
436DECLINLINE(bool) vboxWddmRectIsEmpty(const RECT * pRect)
437{
438 return pRect->left == pRect->right-1 && pRect->top == pRect->bottom-1;
439}
440
441DECLINLINE(bool) vboxWddmRectIsIntersect(const RECT * pRect1, const RECT * pRect2)
442{
443 return !((pRect1->left < pRect2->left && pRect1->right < pRect2->left)
444 || (pRect2->left < pRect1->left && pRect2->right < pRect1->left)
445 || (pRect1->top < pRect2->top && pRect1->bottom < pRect2->top)
446 || (pRect2->top < pRect1->top && pRect2->bottom < pRect1->top));
447}
448
449DECLINLINE(void) vboxWddmRectUnited(RECT * pDst, const RECT * pRect1, const RECT * pRect2)
450{
451 pDst->left = RT_MIN(pRect1->left, pRect2->left);
452 pDst->top = RT_MIN(pRect1->top, pRect2->top);
453 pDst->right = RT_MAX(pRect1->right, pRect2->right);
454 pDst->bottom = RT_MAX(pRect1->bottom, pRect2->bottom);
455}
456
457DECLINLINE(void) vboxWddmRectTranslate(RECT * pRect, int x, int y)
458{
459 pRect->left += x;
460 pRect->top += y;
461 pRect->right += x;
462 pRect->bottom += y;
463}
464
465DECLINLINE(void) vboxWddmRectMove(RECT * pRect, int x, int y)
466{
467 LONG w = pRect->right - pRect->left;
468 LONG h = pRect->bottom - pRect->top;
469 pRect->left = x;
470 pRect->top = y;
471 pRect->right = w + x;
472 pRect->bottom = h + y;
473}
474
475DECLINLINE(void) vboxWddmRectTranslated(RECT *pDst, const RECT * pRect, int x, int y)
476{
477 *pDst = *pRect;
478 vboxWddmRectTranslate(pDst, x, y);
479}
480
481DECLINLINE(void) vboxWddmRectMoved(RECT *pDst, const RECT * pRect, int x, int y)
482{
483 *pDst = *pRect;
484 vboxWddmRectMove(pDst, x, y);
485}
486
487DECLINLINE(void) vboxWddmDirtyRegionAddRect(PVBOXWDDM_DIRTYREGION pInfo, const RECT *pRect)
488{
489 if (!(pInfo->fFlags & VBOXWDDM_DIRTYREGION_F_VALID))
490 {
491 pInfo->fFlags = VBOXWDDM_DIRTYREGION_F_VALID;
492 if (pRect)
493 {
494 pInfo->fFlags |= VBOXWDDM_DIRTYREGION_F_RECT_VALID;
495 pInfo->Rect = *pRect;
496 }
497 }
498 else if (!!(pInfo->fFlags & VBOXWDDM_DIRTYREGION_F_RECT_VALID))
499 {
500 if (pRect)
501 vboxWddmRectUnite(&pInfo->Rect, pRect);
502 else
503 pInfo->fFlags &= ~VBOXWDDM_DIRTYREGION_F_RECT_VALID;
504 }
505}
506
507DECLINLINE(void) vboxWddmDirtyRegionUnite(PVBOXWDDM_DIRTYREGION pInfo, const PVBOXWDDM_DIRTYREGION pInfo2)
508{
509 if (pInfo2->fFlags & VBOXWDDM_DIRTYREGION_F_VALID)
510 {
511 if (pInfo2->fFlags & VBOXWDDM_DIRTYREGION_F_RECT_VALID)
512 vboxWddmDirtyRegionAddRect(pInfo, &pInfo2->Rect);
513 else
514 vboxWddmDirtyRegionAddRect(pInfo, NULL);
515 }
516}
517
518DECLINLINE(void) vboxWddmDirtyRegionClear(PVBOXWDDM_DIRTYREGION pInfo)
519{
520 pInfo->fFlags = 0;
521}
522
523#endif /* #ifndef ___VBoxVideoIf_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