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