1 | /******************************Module*Header*******************************\
|
---|
2 | *
|
---|
3 | * *******************
|
---|
4 | * * GDI SAMPLE CODE *
|
---|
5 | * *******************
|
---|
6 | *
|
---|
7 | * Module Name: driver.h
|
---|
8 | *
|
---|
9 | * contains prototypes for the frame buffer driver.
|
---|
10 | *
|
---|
11 | * Copyright (c) 1992-1998 Microsoft Corporation
|
---|
12 | \**************************************************************************/
|
---|
13 |
|
---|
14 | #include "stddef.h"
|
---|
15 | #include <stdarg.h>
|
---|
16 | #include "windef.h"
|
---|
17 | #include "wingdi.h"
|
---|
18 | #include "winddi.h"
|
---|
19 | #include "devioctl.h"
|
---|
20 | #include "ntddvdeo.h"
|
---|
21 | #include "debug.h"
|
---|
22 |
|
---|
23 | #include "../Miniport/vboxioctl.h"
|
---|
24 |
|
---|
25 | #include <VBox/VBoxVideo.h>
|
---|
26 |
|
---|
27 | /* Forward declaration. */
|
---|
28 | struct _PDEV;
|
---|
29 | typedef struct _PDEV PDEV;
|
---|
30 | typedef PDEV *PPDEV;
|
---|
31 |
|
---|
32 | typedef struct _VBOXDISPLAYINFO
|
---|
33 | {
|
---|
34 | VBOXVIDEOINFOHDR hdrLink;
|
---|
35 | VBOXVIDEOINFOLINK link;
|
---|
36 | VBOXVIDEOINFOHDR hdrScreen;
|
---|
37 | VBOXVIDEOINFOSCREEN screen;
|
---|
38 | VBOXVIDEOINFOHDR hdrHostEvents;
|
---|
39 | VBOXVIDEOINFOHOSTEVENTS hostEvents;
|
---|
40 | VBOXVIDEOINFOHDR hdrEnd;
|
---|
41 | } VBOXDISPLAYINFO;
|
---|
42 |
|
---|
43 | #include "vbvavrdp.h"
|
---|
44 | #include "vrdpbmp.h"
|
---|
45 |
|
---|
46 | /* Saved screen bits information. */
|
---|
47 | typedef struct _SSB
|
---|
48 | {
|
---|
49 | ULONG ident; /* 1 based index in the stack = the handle returned by DrvSaveScreenBits (SS_SAVE) */
|
---|
50 | BYTE *pBuffer; /* Buffer where screen bits are saved. */
|
---|
51 | } SSB;
|
---|
52 |
|
---|
53 | struct _PDEV
|
---|
54 | {
|
---|
55 | HANDLE hDriver; // Handle to \Device\Screen
|
---|
56 | HDEV hdevEng; // Engine's handle to PDEV
|
---|
57 | HSURF hsurfScreenBitmap; // Engine's handle to VRAM screen bitmap surface
|
---|
58 | SURFOBJ *psoScreenBitmap; // VRAM screen bitmap surface
|
---|
59 | HSURF hsurfScreen; // Engine's handle to VRAM screen device surface
|
---|
60 | ULONG ulBitmapType;
|
---|
61 | HPALETTE hpalDefault; // Handle to the default palette for device.
|
---|
62 | PBYTE pjScreen; // This is pointer to base screen address
|
---|
63 | ULONG cxScreen; // Visible screen width
|
---|
64 | ULONG cyScreen; // Visible screen height
|
---|
65 | POINTL ptlOrg; // Where this display is anchored in
|
---|
66 | // the virtual desktop.
|
---|
67 | POINTL ptlDevOrg; // Device origin for DualView (0,0 for primary view).
|
---|
68 | ULONG ulMode; // Mode the mini-port driver is in.
|
---|
69 | LONG lDeltaScreen; // Distance from one scan to the next.
|
---|
70 | ULONG cScreenSize; // size of video memory, including
|
---|
71 | // offscreen memory.
|
---|
72 | PVOID pOffscreenList; // linked list of DCI offscreen surfaces.
|
---|
73 | FLONG flRed; // For bitfields device, Red Mask
|
---|
74 | FLONG flGreen; // For bitfields device, Green Mask
|
---|
75 | FLONG flBlue; // For bitfields device, Blue Mask
|
---|
76 | ULONG cPaletteShift; // number of bits the 8-8-8 palette must
|
---|
77 | // be shifted by to fit in the hardware
|
---|
78 | // palette.
|
---|
79 | ULONG ulBitCount; // # of bits per pel 8,16,24,32 are only supported.
|
---|
80 | POINTL ptlHotSpot; // adjustment for pointer hot spot
|
---|
81 | VIDEO_POINTER_CAPABILITIES PointerCapabilities; // HW pointer abilities
|
---|
82 | PVIDEO_POINTER_ATTRIBUTES pPointerAttributes; // hardware pointer attributes
|
---|
83 | DWORD cjPointerAttributes; // Size of buffer allocated
|
---|
84 | BOOL fHwCursorActive; // Are we currently using the hw cursor
|
---|
85 | PALETTEENTRY *pPal; // If this is pal managed, this is the pal
|
---|
86 | BOOL bSupportDCI; // Does the miniport support DCI?
|
---|
87 | FLONG flHooks;
|
---|
88 |
|
---|
89 | VBVAENABLERESULT vbva;
|
---|
90 | uint32_t u32VRDPResetFlag;
|
---|
91 | BOOL fHwBufferOverflow;
|
---|
92 | VBVARECORD *pRecord;
|
---|
93 | VRDPBC cache;
|
---|
94 |
|
---|
95 | ULONG cSSB; // Number of active saved screen bits records in the following array.
|
---|
96 | SSB aSSB[4]; // LIFO type stack for saved screen areas.
|
---|
97 |
|
---|
98 | VBOXDISPLAYINFO *pInfo;
|
---|
99 | ULONG iDevice;
|
---|
100 | #ifdef VBOX_WITH_DDRAW
|
---|
101 | BOOL bDdExclusiveMode;
|
---|
102 | DWORD dwNewDDSurfaceOffset;
|
---|
103 | #endif
|
---|
104 | };
|
---|
105 |
|
---|
106 | /* The global semaphore handle for all driver instances. */
|
---|
107 | extern HSEMAPHORE ghsemHwBuffer;
|
---|
108 |
|
---|
109 |
|
---|
110 | DWORD getAvailableModes(HANDLE, PVIDEO_MODE_INFORMATION *, DWORD *);
|
---|
111 | BOOL bInitPDEV(PPDEV, PDEVMODEW, GDIINFO *, DEVINFO *);
|
---|
112 | BOOL bInitSURF(PPDEV, BOOL);
|
---|
113 | BOOL bInitPaletteInfo(PPDEV, DEVINFO *);
|
---|
114 | BOOL bInitPointer(PPDEV, DEVINFO *);
|
---|
115 | BOOL bInit256ColorPalette(PPDEV);
|
---|
116 | BOOL bInitNotificationThread(PPDEV);
|
---|
117 | VOID vStopNotificationThread (PPDEV);
|
---|
118 | VOID vDisablePalette(PPDEV);
|
---|
119 | VOID vDisableSURF(PPDEV);
|
---|
120 |
|
---|
121 | #define MAX_CLUT_SIZE (sizeof(VIDEO_CLUT) + (sizeof(ULONG) * 256))
|
---|
122 |
|
---|
123 | //
|
---|
124 | // Determines the size of the DriverExtra information in the DEVMODE
|
---|
125 | // structure passed to and from the display driver.
|
---|
126 | //
|
---|
127 |
|
---|
128 | #define DRIVER_EXTRA_SIZE 0
|
---|
129 |
|
---|
130 | #define DLL_NAME L"VBoxDisp" // Name of the DLL in UNICODE
|
---|
131 | #define STANDARD_DEBUG_PREFIX "VBOXDISP: " // All debug output is prefixed
|
---|
132 | #define ALLOC_TAG 'bvDD' // Four byte tag (characters in
|
---|
133 | // reverse order) used for memory
|
---|
134 | // allocations
|
---|
135 |
|
---|
136 | // VBOX
|
---|
137 | typedef struct _CLIPRECTS {
|
---|
138 | ULONG c;
|
---|
139 | RECTL arcl[64];
|
---|
140 | } CLIPRECTS;
|
---|
141 |
|
---|
142 |
|
---|
143 | BOOL vboxVbvaEnable (PPDEV ppdev);
|
---|
144 | void vboxVbvaDisable (PPDEV ppdev);
|
---|
145 |
|
---|
146 | BOOL vboxHwBufferBeginUpdate (PPDEV ppdev);
|
---|
147 | void vboxHwBufferEndUpdate (PPDEV ppdev);
|
---|
148 |
|
---|
149 | BOOL vboxWrite (PPDEV ppdev, const void *pv, uint32_t cb);
|
---|
150 |
|
---|
151 | BOOL vboxOrderSupported (PPDEV ppdev, unsigned code);
|
---|
152 |
|
---|
153 | void VBoxProcessDisplayInfo(PPDEV ppdev);
|
---|
154 | void VBoxUpdateDisplayInfo (PPDEV ppdev);
|
---|
155 |
|
---|
156 | void drvLoadEng (void);
|
---|
157 |
|
---|
158 | BOOL bIsScreenSurface (SURFOBJ *pso);
|
---|
159 |
|
---|
160 | __inline SURFOBJ *getSurfObj (SURFOBJ *pso)
|
---|
161 | {
|
---|
162 | if (pso)
|
---|
163 | {
|
---|
164 | PPDEV ppdev = (PPDEV)pso->dhpdev;
|
---|
165 |
|
---|
166 | if (ppdev)
|
---|
167 | {
|
---|
168 | if (bIsScreenSurface(pso))
|
---|
169 | {
|
---|
170 | pso = ppdev->psoScreenBitmap;
|
---|
171 | }
|
---|
172 | }
|
---|
173 | }
|
---|
174 |
|
---|
175 | return pso;
|
---|
176 | }
|
---|
177 |
|
---|
178 | #define CONV_SURF(_pso) getSurfObj (_pso)
|
---|
179 |
|
---|
180 | __inline int format2BytesPerPixel(const SURFOBJ *pso)
|
---|
181 | {
|
---|
182 | switch (pso->iBitmapFormat)
|
---|
183 | {
|
---|
184 | case BMF_16BPP: return 2;
|
---|
185 | case BMF_24BPP: return 3;
|
---|
186 | case BMF_32BPP: return 4;
|
---|
187 | }
|
---|
188 |
|
---|
189 | return 0;
|
---|
190 | }
|
---|
191 |
|
---|
192 | #include <iprt/assert.h>
|
---|
193 |
|
---|
194 | #define VBVA_ASSERT(expr) \
|
---|
195 | do { \
|
---|
196 | if (!(expr)) \
|
---|
197 | { \
|
---|
198 | AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
|
---|
199 | AssertMsg2("!!!\n"); \
|
---|
200 | } \
|
---|
201 | } while (0)
|
---|
202 |
|
---|
203 | #ifdef STAT_sunlover
|
---|
204 | extern ULONG gStatCopyBitsOffscreenToScreen;
|
---|
205 | extern ULONG gStatCopyBitsScreenToScreen;
|
---|
206 | extern ULONG gStatBitBltOffscreenToScreen;
|
---|
207 | extern ULONG gStatBitBltScreenToScreen;
|
---|
208 | extern ULONG gStatUnchangedOffscreenToScreen;
|
---|
209 | extern ULONG gStatUnchangedOffscreenToScreenCRC;
|
---|
210 | extern ULONG gStatNonTransientEngineBitmaps;
|
---|
211 | extern ULONG gStatTransientEngineBitmaps;
|
---|
212 | extern ULONG gStatUnchangedBitmapsCRC;
|
---|
213 | extern ULONG gStatUnchangedBitmapsDeviceCRC;
|
---|
214 | extern ULONG gStatBitmapsCRC;
|
---|
215 | extern ULONG gStatBitBltScreenPattern;
|
---|
216 | extern ULONG gStatBitBltScreenSquare;
|
---|
217 | extern ULONG gStatBitBltScreenPatternReported;
|
---|
218 | extern ULONG gStatBitBltScreenSquareReported;
|
---|
219 | extern ULONG gStatCopyBitsScreenSquare;
|
---|
220 |
|
---|
221 | extern ULONG gStatEnablePDEV;
|
---|
222 | extern ULONG gStatCompletePDEV;
|
---|
223 | extern ULONG gStatDisablePDEV;
|
---|
224 | extern ULONG gStatEnableSurface;
|
---|
225 | extern ULONG gStatDisableSurface;
|
---|
226 | extern ULONG gStatAssertMode;
|
---|
227 | extern ULONG gStatDisableDriver;
|
---|
228 | extern ULONG gStatCreateDeviceBitmap;
|
---|
229 | extern ULONG gStatDeleteDeviceBitmap;
|
---|
230 | extern ULONG gStatDitherColor;
|
---|
231 | extern ULONG gStatStrokePath;
|
---|
232 | extern ULONG gStatFillPath;
|
---|
233 | extern ULONG gStatStrokeAndFillPath;
|
---|
234 | extern ULONG gStatPaint;
|
---|
235 | extern ULONG gStatBitBlt;
|
---|
236 | extern ULONG gStatCopyBits;
|
---|
237 | extern ULONG gStatStretchBlt;
|
---|
238 | extern ULONG gStatSetPalette;
|
---|
239 | extern ULONG gStatTextOut;
|
---|
240 | extern ULONG gStatSetPointerShape;
|
---|
241 | extern ULONG gStatMovePointer;
|
---|
242 | extern ULONG gStatLineTo;
|
---|
243 | extern ULONG gStatSynchronize;
|
---|
244 | extern ULONG gStatGetModes;
|
---|
245 | extern ULONG gStatGradientFill;
|
---|
246 | extern ULONG gStatStretchBltROP;
|
---|
247 | extern ULONG gStatPlgBlt;
|
---|
248 | extern ULONG gStatAlphaBlend;
|
---|
249 | extern ULONG gStatTransparentBlt;
|
---|
250 |
|
---|
251 | void statPrint (void);
|
---|
252 |
|
---|
253 | #define STATDRVENTRY(a, b) do { if (bIsScreenSurface (b)) gStat##a++; } while (0)
|
---|
254 | #define STATPRINT do { statPrint (); } while (0)
|
---|
255 | #else
|
---|
256 | #define STATDRVENTRY(a, b)
|
---|
257 | #define STATPRINT
|
---|
258 | #endif /* STAT_sunlover */
|
---|