VirtualBox

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

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

*: spelling fixes, thanks Timeless!

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