VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Display/driver.h@ 35327

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

VBoxVideoGuest.h, VMMDev.h, Additions/WINNT/Graphics: refactoring of the display driver to make the VBVA infrastructure and modesetting functions OS-independent

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.2 KB
Line 
1/******************************Module*Header*******************************\
2*
3 * Copyright (C) 2006-2007 Oracle Corporation
4 *
5 * This file is part of VirtualBox Open Source Edition (OSE), as
6 * available from http://www.virtualbox.org. This file is free software;
7 * you can redistribute it and/or modify it under the terms of the GNU
8 * General Public License (GPL) as published by the Free Software
9 * Foundation, in version 2 as it comes in the "COPYING" file of the
10 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
11 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
12*/
13/*
14* Based in part on Microsoft DDK sample code
15*
16* *******************
17* * GDI SAMPLE CODE *
18* *******************
19*
20* Module Name: driver.h
21*
22* contains prototypes for the frame buffer driver.
23*
24* Copyright (c) 1992-1998 Microsoft Corporation
25\**************************************************************************/
26
27#include "stddef.h"
28#include <stdarg.h>
29#include "windef.h"
30#include "wingdi.h"
31#include "winddi.h"
32#include "devioctl.h"
33#include "ntddvdeo.h"
34#include "debug.h"
35
36#include "../Miniport/vboxioctl.h"
37
38#include <VBox/VBoxVideoGuest.h>
39#include <VBox/VBoxVideo.h>
40#ifdef VBOX_WITH_VIDEOHWACCEL
41#include <iprt/asm.h>
42#endif
43
44/* Forward declaration. */
45struct _PDEV;
46typedef struct _PDEV PDEV;
47typedef PDEV *PPDEV;
48
49typedef struct _VBOXDISPLAYINFO
50{
51 VBOXVIDEOINFOHDR hdrLink;
52 VBOXVIDEOINFOLINK link;
53 VBOXVIDEOINFOHDR hdrScreen;
54 VBOXVIDEOINFOSCREEN screen;
55 VBOXVIDEOINFOHDR hdrHostEvents;
56 VBOXVIDEOINFOHOSTEVENTS hostEvents;
57 VBOXVIDEOINFOHDR hdrEnd;
58} VBOXDISPLAYINFO;
59
60#include "vbvavrdp.h"
61#include "vrdpbmp.h"
62
63/* Saved screen bits information. */
64typedef struct _SSB
65{
66 ULONG ident; /* 1 based index in the stack = the handle returned by DrvSaveScreenBits (SS_SAVE) */
67 BYTE *pBuffer; /* Buffer where screen bits are saved. */
68} SSB;
69
70/* VRAM
71 * | | | | |
72 * 0+framebuffer+ddraw heap+VBVA buffer+displayinfo=cScreenSize
73 */
74typedef struct _VRAMLAYOUT
75{
76 ULONG cbVRAM;
77
78 ULONG offFrameBuffer;
79 ULONG cbFrameBuffer;
80
81 ULONG offDDRAWHeap; //@todo
82 ULONG cbDDRAWHeap;
83
84 ULONG offVBVABuffer;
85 ULONG cbVBVABuffer;
86
87 ULONG offDisplayInformation;
88 ULONG cbDisplayInformation;
89} VRAMLAYOUT;
90
91typedef struct
92{
93 PPDEV ppdev;
94} VBOXSURF, *PVBOXSURF;
95
96#ifdef VBOX_WITH_VIDEOHWACCEL
97typedef struct _VBOXVHWAREGION
98{
99 RECTL Rect;
100 bool bValid;
101}VBOXVHWAREGION, *PVBOXVHWAREGION;
102
103typedef struct _VBOXVHWASURFDESC
104{
105 VBOXVHWA_SURFHANDLE hHostHandle;
106 volatile uint32_t cPendingBltsSrc;
107 volatile uint32_t cPendingBltsDst;
108 volatile uint32_t cPendingFlipsCurr;
109 volatile uint32_t cPendingFlipsTarg;
110#ifdef DEBUG
111 volatile uint32_t cFlipsCurr;
112 volatile uint32_t cFlipsTarg;
113#endif
114// uint32_t cBitsPerPixel;
115 bool bVisible;
116 VBOXVHWAREGION UpdatedMemRegion;
117 VBOXVHWAREGION NonupdatedMemRegion;
118}VBOXVHWASURFDESC, *PVBOXVHWASURFDESC;
119
120typedef struct _VBOXVHWAINFO
121{
122 uint32_t caps;
123 uint32_t caps2;
124 uint32_t colorKeyCaps;
125 uint32_t stretchCaps;
126 uint32_t surfaceCaps;
127 uint32_t numOverlays;
128 uint32_t numFourCC;
129 HGSMIOFFSET FourCC;
130 ULONG_PTR offVramBase;
131 BOOLEAN bVHWAEnabled;
132 BOOLEAN bVHWAInited;
133} VBOXVHWAINFO;
134#endif
135
136struct _PDEV
137{
138 HANDLE hDriver; // Handle to \Device\Screen
139 HDEV hdevEng; // Engine's handle to PDEV
140 HSURF hsurfScreenBitmap; // Engine's handle to VRAM screen bitmap surface
141 SURFOBJ *psoScreenBitmap; // VRAM screen bitmap surface
142 HSURF hsurfScreen; // Engine's handle to VRAM screen device surface
143 ULONG ulBitmapType;
144 HPALETTE hpalDefault; // Handle to the default palette for device.
145 PBYTE pjScreen; // This is pointer to base screen address
146 ULONG cxScreen; // Visible screen width
147 ULONG cyScreen; // Visible screen height
148 POINTL ptlOrg; // Where this display is anchored in
149 // the virtual desktop.
150 POINTL ptlDevOrg; // Device origin for DualView (0,0 for primary view).
151 ULONG ulMode; // Mode the mini-port driver is in.
152 LONG lDeltaScreen; // Distance from one scan to the next.
153
154 PVOID pOffscreenList; // linked list of DCI offscreen surfaces.
155 FLONG flRed; // For bitfields device, Red Mask
156 FLONG flGreen; // For bitfields device, Green Mask
157 FLONG flBlue; // For bitfields device, Blue Mask
158 ULONG cPaletteShift; // number of bits the 8-8-8 palette must
159 // be shifted by to fit in the hardware
160 // palette.
161 ULONG ulBitCount; // # of bits per pel 8,16,24,32 are only supported.
162 POINTL ptlHotSpot; // adjustment for pointer hot spot
163 VIDEO_POINTER_CAPABILITIES PointerCapabilities; // HW pointer abilities
164 PVIDEO_POINTER_ATTRIBUTES pPointerAttributes; // hardware pointer attributes
165 DWORD cjPointerAttributes; // Size of buffer allocated
166 BOOL fHwCursorActive; // Are we currently using the hw cursor
167 PALETTEENTRY *pPal; // If this is pal managed, this is the pal
168 BOOL bSupportDCI; // Does the miniport support DCI?
169 FLONG flHooks;
170
171 VRDPBC cache;
172
173 ULONG cSSB; // Number of active saved screen bits records in the following array.
174 SSB aSSB[4]; // LIFO type stack for saved screen areas.
175
176 ULONG iDevice;
177 VRAMLAYOUT layout;
178
179 PVBOXSURF pdsurfScreen;
180
181#ifdef VBOX_WITH_DDRAW
182 BOOL bDdExclusiveMode;
183 DWORD dwNewDDSurfaceOffset;
184 DWORD cHeaps;
185 VIDEOMEMORY* pvmList;
186 struct {
187 DWORD bLocked;
188 RECTL rArea;
189 } ddLock;
190#endif /* VBOX_WITH_DDRAW */
191
192 BOOLEAN bHGSMISupported;
193 HGSMIGUESTCOMMANDCONTEXT guestCtx;
194 VBVABUFFERCONTEXT vbvaCtx;
195
196 HVBOXVIDEOHGSMI hMpHGSMI; /* context handler passed to miniport HGSMI callbacks */
197 PFNVBOXVIDEOHGSMICOMPLETION pfnHGSMICommandComplete; /* called to complete the command we receive from the miniport */
198 PFNVBOXVIDEOHGSMICOMMANDS pfnHGSMIRequestCommands; /* called to requests the commands posted to us from the host */
199
200 PVOID pVideoPortContext;
201 VBOXVIDEOPORTPROCS VideoPortProcs;
202
203#ifdef VBOX_WITH_VIDEOHWACCEL
204 VBOXVHWAINFO vhwaInfo;
205#endif
206};
207
208#ifdef VBOX_WITH_OPENGL
209typedef struct
210{
211 DWORD dwVersion;
212 DWORD dwDriverVersion;
213 WCHAR szDriverName[256];
214} OPENGL_INFO, *POPENGL_INFO;
215#endif
216
217
218
219extern BOOL g_bOnNT40;
220
221DWORD getAvailableModes(HANDLE, PVIDEO_MODE_INFORMATION *, DWORD *);
222BOOL bInitPDEV(PPDEV, PDEVMODEW, GDIINFO *, DEVINFO *);
223BOOL bInitSURF(PPDEV, BOOL);
224BOOL bInitPaletteInfo(PPDEV, DEVINFO *);
225BOOL bInitPointer(PPDEV, DEVINFO *);
226BOOL bInit256ColorPalette(PPDEV);
227BOOL bInitNotificationThread(PPDEV);
228VOID vStopNotificationThread (PPDEV);
229VOID vDisablePalette(PPDEV);
230VOID vDisableSURF(PPDEV);
231
232#define MAX_CLUT_SIZE (sizeof(VIDEO_CLUT) + (sizeof(ULONG) * 256))
233
234//
235// Determines the size of the DriverExtra information in the DEVMODE
236// structure passed to and from the display driver.
237//
238
239#define DRIVER_EXTRA_SIZE 0
240
241#define DLL_NAME L"VBoxDisp" // Name of the DLL in UNICODE
242#define STANDARD_DEBUG_PREFIX "VBOXDISP: " // All debug output is prefixed
243#define ALLOC_TAG 'bvDD' // Four byte tag (characters in
244 // reverse order) used for memory
245 // allocations
246
247// VBOX
248typedef struct _CLIPRECTS {
249 ULONG c;
250 RECTL arcl[64];
251} CLIPRECTS;
252
253typedef struct _VRDPCLIPRECTS
254{
255 RECTL rclDstOrig; /* Original bounding rectangle. */
256 RECTL rclDst; /* Bounding rectangle of all rects. */
257 CLIPRECTS rects; /* Rectangles to update. */
258} VRDPCLIPRECTS;
259
260
261void VBoxProcessDisplayInfo(PPDEV ppdev);
262void VBoxUpdateDisplayInfo (PPDEV ppdev);
263
264void drvLoadEng (void);
265
266void vboxVBVAHostCommandComplete(PPDEV ppdev, VBVAHOSTCMD * pCmd);
267
268#ifdef VBOX_WITH_VIDEOHWACCEL
269
270DECLINLINE(uint64_t) vboxVHWAVramOffsetFromPDEV(PPDEV pDev, ULONG_PTR offPdev)
271{
272 return (uint64_t)(pDev->vhwaInfo.offVramBase + offPdev);
273}
274
275#define VBOXDD_CHECKFLAG(_v, _f) ((_v) & (_f)) == (_f)
276
277typedef DECLCALLBACK(void) FNVBOXVHWACMDCOMPLETION(PPDEV ppdev, VBOXVHWACMD * pCmd, void * pContext);
278typedef FNVBOXVHWACMDCOMPLETION *PFNVBOXVHWACMDCOMPLETION;
279
280void vboxVHWARectUnited(RECTL * pDst, RECTL * pRect1, RECTL * pRect2);
281bool vboxVHWARectIsEmpty(RECTL * pRect);
282bool vboxVHWARectIntersect(RECTL * pRect1, RECTL * pRect2);
283bool vboxVHWARectInclude(RECTL * pRect1, RECTL * pRect2);
284bool vboxVHWARegionIntersects(PVBOXVHWAREGION pReg, RECTL * pRect);
285bool vboxVHWARegionIncludes(PVBOXVHWAREGION pReg, RECTL * pRect);
286bool vboxVHWARegionIncluded(PVBOXVHWAREGION pReg, RECTL * pRect);
287void vboxVHWARegionSet(PVBOXVHWAREGION pReg, RECTL * pRect);
288void vboxVHWARegionAdd(PVBOXVHWAREGION pReg, RECTL * pRect);
289void vboxVHWARegionInit(PVBOXVHWAREGION pReg);
290void vboxVHWARegionClear(PVBOXVHWAREGION pReg);
291bool vboxVHWARegionValid(PVBOXVHWAREGION pReg);
292void vboxVHWARegionTrySubstitute(PVBOXVHWAREGION pReg, const RECTL *pRect);
293
294VBOXVHWACMD* vboxVHWACommandCreate (PPDEV ppdev, VBOXVHWACMD_TYPE enmCmd, VBOXVHWACMD_LENGTH cbCmd);
295void vboxVHWACommandFree (PPDEV ppdev, VBOXVHWACMD* pCmd);
296DECLINLINE(void) vbvaVHWACommandRelease (PPDEV ppdev, VBOXVHWACMD* pCmd)
297{
298 uint32_t cRefs = ASMAtomicDecU32(&pCmd->cRefs);
299 Assert(cRefs < UINT32_MAX / 2);
300 if(!cRefs)
301 {
302 vboxVHWACommandFree(ppdev, pCmd);
303 }
304}
305
306DECLINLINE(void) vbvaVHWACommandRetain (PPDEV ppdev, VBOXVHWACMD* pCmd)
307{
308 ASMAtomicIncU32(&pCmd->cRefs);
309}
310
311BOOL vboxVHWACommandSubmit (PPDEV ppdev, VBOXVHWACMD* pCmd);
312void vboxVHWACommandSubmitAsynch (PPDEV ppdev, VBOXVHWACMD* pCmd, PFNVBOXVHWACMDCOMPLETION pfnCompletion, void * pContext);
313void vboxVHWACommandSubmitAsynchByEvent (PPDEV ppdev, VBOXVHWACMD* pCmd, VBOXPEVENT pEvent);
314void vboxVHWACommandCheckHostCmds(PPDEV ppdev);
315void vboxVHWACommandSubmitAsynchAndComplete (PPDEV ppdev, VBOXVHWACMD* pCmd);
316
317int vboxVHWAInitHostInfo1(PPDEV ppdev);
318int vboxVHWAInitHostInfo2(PPDEV ppdev, DWORD *pFourCC);
319
320VBOXVHWACMD_QUERYINFO1* vboxVHWAQueryHostInfo1(PPDEV ppdev);
321void vboxVHWAFreeHostInfo1(PPDEV ppdev, VBOXVHWACMD_QUERYINFO1* pInfo);
322VBOXVHWACMD_QUERYINFO2* vboxVHWAQueryHostInfo2(PPDEV ppdev, uint32_t numFourCC);
323void vboxVHWAFreeHostInfo2(PPDEV ppdev, VBOXVHWACMD_QUERYINFO2* pInfo);
324
325void vboxVHWAInit();
326void vboxVHWATerm();
327uint32_t vboxVHWAUnsupportedDDCAPS(uint32_t caps);
328uint32_t vboxVHWAUnsupportedDDSCAPS(uint32_t caps);
329uint32_t vboxVHWAUnsupportedDDPFS(uint32_t caps);
330uint32_t vboxVHWASupportedDDCAPS(uint32_t caps);
331uint32_t vboxVHWASupportedDDSCAPS(uint32_t caps);
332uint32_t vboxVHWASupportedDDPFS(uint32_t caps);
333
334uint32_t vboxVHWAUnsupportedDDCEYCAPS(uint32_t caps);
335uint32_t vboxVHWASupportedDDCEYCAPS(uint32_t caps);
336
337uint32_t vboxVHWAToDDBLTs(uint32_t caps);
338uint32_t vboxVHWAFromDDBLTs(uint32_t caps);
339
340uint32_t vboxVHWAFromDDCAPS2(uint32_t caps);
341uint32_t vboxVHWAToDDCAPS2(uint32_t caps);
342
343void vboxVHWAFromDDBLTFX(VBOXVHWA_BLTFX *pVHWABlt, DDBLTFX *pDdBlt);
344
345void vboxVHWAFromDDCOLORKEY(VBOXVHWA_COLORKEY *pVHWACKey, DDCOLORKEY *pDdCKey);
346
347uint32_t vboxVHWAFromDDOVERs(uint32_t caps);
348uint32_t vboxVHWAToDDOVERs(uint32_t caps);
349uint32_t vboxVHWAFromDDCKEYs(uint32_t caps);
350uint32_t vboxVHWAToDDCKEYs(uint32_t caps);
351
352void vboxVHWAFromDDOVERLAYFX(VBOXVHWA_OVERLAYFX *pVHWAOverlay, DDOVERLAYFX *pDdOverlay);
353
354uint32_t vboxVHWAFromDDCAPS(uint32_t caps);
355uint32_t vboxVHWAToDDCAPS(uint32_t caps);
356uint32_t vboxVHWAFromDDSCAPS(uint32_t caps);
357uint32_t vboxVHWAToDDSCAPS(uint32_t caps);
358uint32_t vboxVHWAFromDDPFS(uint32_t caps);
359uint32_t vboxVHWAToDDPFS(uint32_t caps);
360uint32_t vboxVHWAFromDDCKEYCAPS(uint32_t caps);
361uint32_t vboxVHWAToDDCKEYCAPS(uint32_t caps);
362int vboxVHWAFromDDPIXELFORMAT(VBOXVHWA_PIXELFORMAT *pVHWAFormat, DDPIXELFORMAT *pDdFormat);
363int vboxVHWAFromDDSURFACEDESC(VBOXVHWA_SURFACEDESC *pVHWADesc, DDSURFACEDESC *pDdDesc);
364void vboxVHWAFromRECTL(VBOXVHWA_RECTL *pDst, RECTL *pSrc);
365PVBOXVHWASURFDESC vboxVHWASurfDescAlloc();
366void vboxVHWASurfDescFree(PVBOXVHWASURFDESC pDesc);
367
368int vboxVHWAEnable(PPDEV ppdev);
369int vboxVHWADisable(PPDEV ppdev);
370
371#endif
372
373BOOL bIsScreenSurface (SURFOBJ *pso);
374
375__inline SURFOBJ *getSurfObj (SURFOBJ *pso)
376{
377 if (pso)
378 {
379 PPDEV ppdev = (PPDEV)pso->dhpdev;
380
381 if (ppdev)
382 {
383 if (ppdev->psoScreenBitmap && pso->hsurf == ppdev->hsurfScreen)
384 {
385 /* Convert the device PSO to the bitmap PSO which can be passed to Eng*. */
386 pso = ppdev->psoScreenBitmap;
387 }
388 }
389 }
390
391 return pso;
392}
393
394#define CONV_SURF(_pso) getSurfObj (_pso)
395
396__inline int format2BytesPerPixel(const SURFOBJ *pso)
397{
398 switch (pso->iBitmapFormat)
399 {
400 case BMF_16BPP: return 2;
401 case BMF_24BPP: return 3;
402 case BMF_32BPP: return 4;
403 }
404
405 return 0;
406}
407
408#ifdef VBOX_VBVA_ADJUST_RECT
409void vrdpAdjustRect (SURFOBJ *pso, RECTL *prcl);
410BOOL vbvaFindChangedRect (SURFOBJ *psoDest, SURFOBJ *psoSrc, RECTL *prclDest, POINTL *pptlSrc);
411#endif /* VBOX_VBVA_ADJUST_RECT */
412
413void vrdpReportDirtyRect (PPDEV ppdev, RECTL *prcl);
414void vbvaReportDirtyRect (PPDEV ppdev, RECTL *prcl);
415
416#define VRDP_TEXT_MAX_GLYPH_SIZE 0x100
417#define VRDP_TEXT_MAX_GLYPHS 0xfe
418
419BOOL vboxReportText (PPDEV ppdev,
420 VRDPCLIPRECTS *pClipRects,
421 STROBJ *pstro,
422 FONTOBJ *pfo,
423 RECTL *prclOpaque,
424 ULONG ulForeRGB,
425 ULONG ulBackRGB
426 );
427
428BOOL vrdpReportOrderGeneric (PPDEV ppdev,
429 const VRDPCLIPRECTS *pClipRects,
430 const void *pvOrder,
431 unsigned cbOrder,
432 unsigned code);
433
434
435#include <iprt/assert.h>
436
437#ifdef DEBUG
438#define VBVA_ASSERT(expr) \
439 do { \
440 if (!(expr)) \
441 { \
442 RTAssertMsg1Weak(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
443 RTAssertMsg2Weak("!!!\n"); \
444 } \
445 } while (0)
446#else
447#define VBVA_ASSERT(expr) do {} while (0)
448#endif
449
450#ifdef STAT_sunlover
451extern ULONG gStatCopyBitsOffscreenToScreen;
452extern ULONG gStatCopyBitsScreenToScreen;
453extern ULONG gStatBitBltOffscreenToScreen;
454extern ULONG gStatBitBltScreenToScreen;
455extern ULONG gStatUnchangedOffscreenToScreen;
456extern ULONG gStatUnchangedOffscreenToScreenCRC;
457extern ULONG gStatNonTransientEngineBitmaps;
458extern ULONG gStatTransientEngineBitmaps;
459extern ULONG gStatUnchangedBitmapsCRC;
460extern ULONG gStatUnchangedBitmapsDeviceCRC;
461extern ULONG gStatBitmapsCRC;
462extern ULONG gStatBitBltScreenPattern;
463extern ULONG gStatBitBltScreenSquare;
464extern ULONG gStatBitBltScreenPatternReported;
465extern ULONG gStatBitBltScreenSquareReported;
466extern ULONG gStatCopyBitsScreenSquare;
467
468extern ULONG gStatEnablePDEV;
469extern ULONG gStatCompletePDEV;
470extern ULONG gStatDisablePDEV;
471extern ULONG gStatEnableSurface;
472extern ULONG gStatDisableSurface;
473extern ULONG gStatAssertMode;
474extern ULONG gStatDisableDriver;
475extern ULONG gStatCreateDeviceBitmap;
476extern ULONG gStatDeleteDeviceBitmap;
477extern ULONG gStatDitherColor;
478extern ULONG gStatStrokePath;
479extern ULONG gStatFillPath;
480extern ULONG gStatStrokeAndFillPath;
481extern ULONG gStatPaint;
482extern ULONG gStatBitBlt;
483extern ULONG gStatCopyBits;
484extern ULONG gStatStretchBlt;
485extern ULONG gStatSetPalette;
486extern ULONG gStatTextOut;
487extern ULONG gStatSetPointerShape;
488extern ULONG gStatMovePointer;
489extern ULONG gStatLineTo;
490extern ULONG gStatSynchronize;
491extern ULONG gStatGetModes;
492extern ULONG gStatGradientFill;
493extern ULONG gStatStretchBltROP;
494extern ULONG gStatPlgBlt;
495extern ULONG gStatAlphaBlend;
496extern ULONG gStatTransparentBlt;
497
498void statPrint (void);
499
500#define STATDRVENTRY(a, b) do { if (bIsScreenSurface (b)) gStat##a++; } while (0)
501#define STATPRINT do { statPrint (); } while (0)
502#else
503#define STATDRVENTRY(a, b)
504#define STATPRINT
505#endif /* STAT_sunlover */
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