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 | /* VRAM
|
---|
54 | * | | | | |
|
---|
55 | * 0+framebuffer+ddraw heap+VBVA buffer+displayinfo=cScreenSize
|
---|
56 | */
|
---|
57 | typedef struct _VRAMLAYOUT
|
---|
58 | {
|
---|
59 | ULONG cbVRAM;
|
---|
60 |
|
---|
61 | ULONG offFrameBuffer;
|
---|
62 | ULONG cbFrameBuffer;
|
---|
63 |
|
---|
64 | ULONG offDDRAWHeap; //@todo
|
---|
65 | ULONG cbDDRAWHeap;
|
---|
66 |
|
---|
67 | ULONG offVBVABuffer;
|
---|
68 | ULONG cbVBVABuffer;
|
---|
69 |
|
---|
70 | ULONG offDisplayInformation;
|
---|
71 | ULONG cbDisplayInformation;
|
---|
72 | } VRAMLAYOUT;
|
---|
73 |
|
---|
74 | typedef struct
|
---|
75 | {
|
---|
76 | PPDEV ppdev;
|
---|
77 | } VBOXSURF, *PVBOXSURF;
|
---|
78 |
|
---|
79 | struct _PDEV
|
---|
80 | {
|
---|
81 | HANDLE hDriver; // Handle to \Device\Screen
|
---|
82 | HDEV hdevEng; // Engine's handle to PDEV
|
---|
83 | HSURF hsurfScreenBitmap; // Engine's handle to VRAM screen bitmap surface
|
---|
84 | SURFOBJ *psoScreenBitmap; // VRAM screen bitmap surface
|
---|
85 | HSURF hsurfScreen; // Engine's handle to VRAM screen device surface
|
---|
86 | ULONG ulBitmapType;
|
---|
87 | HPALETTE hpalDefault; // Handle to the default palette for device.
|
---|
88 | PBYTE pjScreen; // This is pointer to base screen address
|
---|
89 | ULONG cxScreen; // Visible screen width
|
---|
90 | ULONG cyScreen; // Visible screen height
|
---|
91 | POINTL ptlOrg; // Where this display is anchored in
|
---|
92 | // the virtual desktop.
|
---|
93 | POINTL ptlDevOrg; // Device origin for DualView (0,0 for primary view).
|
---|
94 | ULONG ulMode; // Mode the mini-port driver is in.
|
---|
95 | LONG lDeltaScreen; // Distance from one scan to the next.
|
---|
96 |
|
---|
97 | PVOID pOffscreenList; // linked list of DCI offscreen surfaces.
|
---|
98 | FLONG flRed; // For bitfields device, Red Mask
|
---|
99 | FLONG flGreen; // For bitfields device, Green Mask
|
---|
100 | FLONG flBlue; // For bitfields device, Blue Mask
|
---|
101 | ULONG cPaletteShift; // number of bits the 8-8-8 palette must
|
---|
102 | // be shifted by to fit in the hardware
|
---|
103 | // palette.
|
---|
104 | ULONG ulBitCount; // # of bits per pel 8,16,24,32 are only supported.
|
---|
105 | POINTL ptlHotSpot; // adjustment for pointer hot spot
|
---|
106 | VIDEO_POINTER_CAPABILITIES PointerCapabilities; // HW pointer abilities
|
---|
107 | PVIDEO_POINTER_ATTRIBUTES pPointerAttributes; // hardware pointer attributes
|
---|
108 | DWORD cjPointerAttributes; // Size of buffer allocated
|
---|
109 | BOOL fHwCursorActive; // Are we currently using the hw cursor
|
---|
110 | PALETTEENTRY *pPal; // If this is pal managed, this is the pal
|
---|
111 | BOOL bSupportDCI; // Does the miniport support DCI?
|
---|
112 | FLONG flHooks;
|
---|
113 |
|
---|
114 | VBVAENABLERESULT vbva;
|
---|
115 | uint32_t u32VRDPResetFlag;
|
---|
116 | BOOL fHwBufferOverflow;
|
---|
117 | VBVARECORD *pRecord;
|
---|
118 | VRDPBC cache;
|
---|
119 |
|
---|
120 | ULONG cSSB; // Number of active saved screen bits records in the following array.
|
---|
121 | SSB aSSB[4]; // LIFO type stack for saved screen areas.
|
---|
122 |
|
---|
123 | VBOXDISPLAYINFO *pInfo;
|
---|
124 | BOOLEAN bVBoxVideoSupported;
|
---|
125 | ULONG iDevice;
|
---|
126 | VRAMLAYOUT layout;
|
---|
127 |
|
---|
128 | PVBOXSURF pdsurfScreen;
|
---|
129 |
|
---|
130 | #ifdef VBOX_WITH_DDRAW
|
---|
131 | BOOL bDdExclusiveMode;
|
---|
132 | DWORD dwNewDDSurfaceOffset;
|
---|
133 | DWORD cHeaps;
|
---|
134 | VIDEOMEMORY* pvmList;
|
---|
135 | struct {
|
---|
136 | DWORD bLocked;
|
---|
137 | RECTL rArea;
|
---|
138 | } ddLock;
|
---|
139 | #endif /* VBOX_WITH_DDRAW */
|
---|
140 | };
|
---|
141 |
|
---|
142 | #ifdef VBOX_WITH_OPENGL
|
---|
143 | typedef struct
|
---|
144 | {
|
---|
145 | DWORD dwVersion;
|
---|
146 | DWORD dwDriverVersion;
|
---|
147 | WCHAR szDriverName[256];
|
---|
148 | } OPENGL_INFO, *POPENGL_INFO;
|
---|
149 | #endif
|
---|
150 |
|
---|
151 | /* The global semaphore handle for all driver instances. */
|
---|
152 | extern HSEMAPHORE ghsemHwBuffer;
|
---|
153 |
|
---|
154 | extern BOOL g_bOnNT40;
|
---|
155 |
|
---|
156 | DWORD getAvailableModes(HANDLE, PVIDEO_MODE_INFORMATION *, DWORD *);
|
---|
157 | BOOL bInitPDEV(PPDEV, PDEVMODEW, GDIINFO *, DEVINFO *);
|
---|
158 | BOOL bInitSURF(PPDEV, BOOL);
|
---|
159 | BOOL bInitPaletteInfo(PPDEV, DEVINFO *);
|
---|
160 | BOOL bInitPointer(PPDEV, DEVINFO *);
|
---|
161 | BOOL bInit256ColorPalette(PPDEV);
|
---|
162 | BOOL bInitNotificationThread(PPDEV);
|
---|
163 | VOID vStopNotificationThread (PPDEV);
|
---|
164 | VOID vDisablePalette(PPDEV);
|
---|
165 | VOID vDisableSURF(PPDEV);
|
---|
166 |
|
---|
167 | #define MAX_CLUT_SIZE (sizeof(VIDEO_CLUT) + (sizeof(ULONG) * 256))
|
---|
168 |
|
---|
169 | //
|
---|
170 | // Determines the size of the DriverExtra information in the DEVMODE
|
---|
171 | // structure passed to and from the display driver.
|
---|
172 | //
|
---|
173 |
|
---|
174 | #define DRIVER_EXTRA_SIZE 0
|
---|
175 |
|
---|
176 | #define DLL_NAME L"VBoxDisp" // Name of the DLL in UNICODE
|
---|
177 | #define STANDARD_DEBUG_PREFIX "VBOXDISP: " // All debug output is prefixed
|
---|
178 | #define ALLOC_TAG 'bvDD' // Four byte tag (characters in
|
---|
179 | // reverse order) used for memory
|
---|
180 | // allocations
|
---|
181 |
|
---|
182 | // VBOX
|
---|
183 | typedef struct _CLIPRECTS {
|
---|
184 | ULONG c;
|
---|
185 | RECTL arcl[64];
|
---|
186 | } CLIPRECTS;
|
---|
187 |
|
---|
188 | typedef struct _VRDPCLIPRECTS
|
---|
189 | {
|
---|
190 | RECTL rclDstOrig; /* Original bounding rectancle. */
|
---|
191 | RECTL rclDst; /* Bounding rectangle of all rects. */
|
---|
192 | CLIPRECTS rects; /* Rectangles to update. */
|
---|
193 | } VRDPCLIPRECTS;
|
---|
194 |
|
---|
195 |
|
---|
196 | BOOL vboxVbvaEnable (PPDEV ppdev);
|
---|
197 | void vboxVbvaDisable (PPDEV ppdev);
|
---|
198 |
|
---|
199 | BOOL vboxHwBufferBeginUpdate (PPDEV ppdev);
|
---|
200 | void vboxHwBufferEndUpdate (PPDEV ppdev);
|
---|
201 |
|
---|
202 | BOOL vboxWrite (PPDEV ppdev, const void *pv, uint32_t cb);
|
---|
203 |
|
---|
204 | BOOL vboxOrderSupported (PPDEV ppdev, unsigned code);
|
---|
205 |
|
---|
206 | void VBoxProcessDisplayInfo(PPDEV ppdev);
|
---|
207 | void VBoxUpdateDisplayInfo (PPDEV ppdev);
|
---|
208 |
|
---|
209 | void drvLoadEng (void);
|
---|
210 |
|
---|
211 | BOOL bIsScreenSurface (SURFOBJ *pso);
|
---|
212 |
|
---|
213 | __inline SURFOBJ *getSurfObj (SURFOBJ *pso)
|
---|
214 | {
|
---|
215 | if (pso)
|
---|
216 | {
|
---|
217 | PPDEV ppdev = (PPDEV)pso->dhpdev;
|
---|
218 |
|
---|
219 | if (ppdev)
|
---|
220 | {
|
---|
221 | if (ppdev->psoScreenBitmap && pso->hsurf == ppdev->hsurfScreen)
|
---|
222 | {
|
---|
223 | /* Convert the device PSO to the bitmap PSO which can be passed to Eng*. */
|
---|
224 | pso = ppdev->psoScreenBitmap;
|
---|
225 | }
|
---|
226 | }
|
---|
227 | }
|
---|
228 |
|
---|
229 | return pso;
|
---|
230 | }
|
---|
231 |
|
---|
232 | #define CONV_SURF(_pso) getSurfObj (_pso)
|
---|
233 |
|
---|
234 | __inline int format2BytesPerPixel(const SURFOBJ *pso)
|
---|
235 | {
|
---|
236 | switch (pso->iBitmapFormat)
|
---|
237 | {
|
---|
238 | case BMF_16BPP: return 2;
|
---|
239 | case BMF_24BPP: return 3;
|
---|
240 | case BMF_32BPP: return 4;
|
---|
241 | }
|
---|
242 |
|
---|
243 | return 0;
|
---|
244 | }
|
---|
245 |
|
---|
246 | #ifdef VBOX_VBVA_ADJUST_RECT
|
---|
247 | void vrdpAdjustRect (SURFOBJ *pso, RECTL *prcl);
|
---|
248 | BOOL vbvaFindChangedRect (SURFOBJ *psoDest, SURFOBJ *psoSrc, RECTL *prclDest, POINTL *pptlSrc);
|
---|
249 | #endif /* VBOX_VBVA_ADJUST_RECT */
|
---|
250 |
|
---|
251 | void vrdpReportDirtyRect (PPDEV ppdev, RECTL *prcl);
|
---|
252 | void vbvaReportDirtyRect (PPDEV ppdev, RECTL *prcl);
|
---|
253 |
|
---|
254 | #define VRDP_TEXT_MAX_GLYPH_SIZE 0x100
|
---|
255 | #define VRDP_TEXT_MAX_GLYPHS 0xfe
|
---|
256 |
|
---|
257 | BOOL vboxReportText (PPDEV ppdev,
|
---|
258 | VRDPCLIPRECTS *pClipRects,
|
---|
259 | STROBJ *pstro,
|
---|
260 | FONTOBJ *pfo,
|
---|
261 | RECTL *prclOpaque,
|
---|
262 | ULONG ulForeRGB,
|
---|
263 | ULONG ulBackRGB
|
---|
264 | );
|
---|
265 |
|
---|
266 | BOOL vrdpReportOrderGeneric (PPDEV ppdev,
|
---|
267 | const VRDPCLIPRECTS *pClipRects,
|
---|
268 | const void *pvOrder,
|
---|
269 | unsigned cbOrder,
|
---|
270 | unsigned code);
|
---|
271 |
|
---|
272 |
|
---|
273 | #include <iprt/assert.h>
|
---|
274 |
|
---|
275 | #define VBVA_ASSERT(expr) \
|
---|
276 | do { \
|
---|
277 | if (!(expr)) \
|
---|
278 | { \
|
---|
279 | AssertMsg1(#expr, __LINE__, __FILE__, __PRETTY_FUNCTION__); \
|
---|
280 | AssertMsg2("!!!\n"); \
|
---|
281 | } \
|
---|
282 | } while (0)
|
---|
283 |
|
---|
284 | #ifdef STAT_sunlover
|
---|
285 | extern ULONG gStatCopyBitsOffscreenToScreen;
|
---|
286 | extern ULONG gStatCopyBitsScreenToScreen;
|
---|
287 | extern ULONG gStatBitBltOffscreenToScreen;
|
---|
288 | extern ULONG gStatBitBltScreenToScreen;
|
---|
289 | extern ULONG gStatUnchangedOffscreenToScreen;
|
---|
290 | extern ULONG gStatUnchangedOffscreenToScreenCRC;
|
---|
291 | extern ULONG gStatNonTransientEngineBitmaps;
|
---|
292 | extern ULONG gStatTransientEngineBitmaps;
|
---|
293 | extern ULONG gStatUnchangedBitmapsCRC;
|
---|
294 | extern ULONG gStatUnchangedBitmapsDeviceCRC;
|
---|
295 | extern ULONG gStatBitmapsCRC;
|
---|
296 | extern ULONG gStatBitBltScreenPattern;
|
---|
297 | extern ULONG gStatBitBltScreenSquare;
|
---|
298 | extern ULONG gStatBitBltScreenPatternReported;
|
---|
299 | extern ULONG gStatBitBltScreenSquareReported;
|
---|
300 | extern ULONG gStatCopyBitsScreenSquare;
|
---|
301 |
|
---|
302 | extern ULONG gStatEnablePDEV;
|
---|
303 | extern ULONG gStatCompletePDEV;
|
---|
304 | extern ULONG gStatDisablePDEV;
|
---|
305 | extern ULONG gStatEnableSurface;
|
---|
306 | extern ULONG gStatDisableSurface;
|
---|
307 | extern ULONG gStatAssertMode;
|
---|
308 | extern ULONG gStatDisableDriver;
|
---|
309 | extern ULONG gStatCreateDeviceBitmap;
|
---|
310 | extern ULONG gStatDeleteDeviceBitmap;
|
---|
311 | extern ULONG gStatDitherColor;
|
---|
312 | extern ULONG gStatStrokePath;
|
---|
313 | extern ULONG gStatFillPath;
|
---|
314 | extern ULONG gStatStrokeAndFillPath;
|
---|
315 | extern ULONG gStatPaint;
|
---|
316 | extern ULONG gStatBitBlt;
|
---|
317 | extern ULONG gStatCopyBits;
|
---|
318 | extern ULONG gStatStretchBlt;
|
---|
319 | extern ULONG gStatSetPalette;
|
---|
320 | extern ULONG gStatTextOut;
|
---|
321 | extern ULONG gStatSetPointerShape;
|
---|
322 | extern ULONG gStatMovePointer;
|
---|
323 | extern ULONG gStatLineTo;
|
---|
324 | extern ULONG gStatSynchronize;
|
---|
325 | extern ULONG gStatGetModes;
|
---|
326 | extern ULONG gStatGradientFill;
|
---|
327 | extern ULONG gStatStretchBltROP;
|
---|
328 | extern ULONG gStatPlgBlt;
|
---|
329 | extern ULONG gStatAlphaBlend;
|
---|
330 | extern ULONG gStatTransparentBlt;
|
---|
331 |
|
---|
332 | void statPrint (void);
|
---|
333 |
|
---|
334 | #define STATDRVENTRY(a, b) do { if (bIsScreenSurface (b)) gStat##a++; } while (0)
|
---|
335 | #define STATPRINT do { statPrint (); } while (0)
|
---|
336 | #else
|
---|
337 | #define STATDRVENTRY(a, b)
|
---|
338 | #define STATPRINT
|
---|
339 | #endif /* STAT_sunlover */
|
---|