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