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: enable.c
|
---|
21 | *
|
---|
22 | * This module contains the functions that enable and disable the
|
---|
23 | * driver, the pdev, and the surface.
|
---|
24 | *
|
---|
25 | * Copyright (c) 1992-1998 Microsoft Corporation
|
---|
26 | \**************************************************************************/
|
---|
27 |
|
---|
28 | #include "driver.h"
|
---|
29 | #include "dd.h"
|
---|
30 | #include <VBoxDisplay.h>
|
---|
31 |
|
---|
32 | // The driver function table with all function index/address pairs
|
---|
33 |
|
---|
34 | // Hook functions to track dirty rectangles and generate RDP orders.
|
---|
35 | // NT4 functions
|
---|
36 | DRVFN gadrvfn_nt4[] = {
|
---|
37 | { INDEX_DrvEnablePDEV, (PFN) DrvEnablePDEV }, // 0
|
---|
38 | { INDEX_DrvCompletePDEV, (PFN) DrvCompletePDEV }, // 1
|
---|
39 | { INDEX_DrvDisablePDEV, (PFN) DrvDisablePDEV }, // 2
|
---|
40 | { INDEX_DrvEnableSurface, (PFN) DrvEnableSurface }, // 3
|
---|
41 | { INDEX_DrvDisableSurface, (PFN) DrvDisableSurface }, // 4
|
---|
42 | { INDEX_DrvAssertMode, (PFN) DrvAssertMode }, // 5
|
---|
43 | { INDEX_DrvOffset, (PFN) DrvOffset }, // 6
|
---|
44 | { INDEX_DrvDisableDriver, (PFN) DrvDisableDriver }, // 8
|
---|
45 | // { INDEX_DrvCreateDeviceBitmap, (PFN) DrvCreateDeviceBitmap }, // 10
|
---|
46 | // { INDEX_DrvDeleteDeviceBitmap, (PFN) DrvDeleteDeviceBitmap }, // 11
|
---|
47 | { INDEX_DrvRealizeBrush, (PFN) DrvRealizeBrush }, // 12
|
---|
48 | { INDEX_DrvDitherColor, (PFN) DrvDitherColor }, // 13
|
---|
49 | { INDEX_DrvStrokePath, (PFN) DrvStrokePath }, // 14
|
---|
50 | { INDEX_DrvFillPath, (PFN) DrvFillPath }, // 15
|
---|
51 | { INDEX_DrvPaint, (PFN) DrvPaint }, // 17
|
---|
52 | { INDEX_DrvBitBlt, (PFN) DrvBitBlt }, // 18
|
---|
53 | { INDEX_DrvCopyBits, (PFN) DrvCopyBits }, // 19
|
---|
54 | { INDEX_DrvStretchBlt, (PFN) DrvStretchBlt, }, // 20
|
---|
55 | { INDEX_DrvSetPalette, (PFN) DrvSetPalette }, // 22
|
---|
56 | { INDEX_DrvTextOut, (PFN) DrvTextOut }, // 23
|
---|
57 | { INDEX_DrvEscape, (PFN) DrvEscape }, // 24
|
---|
58 | { INDEX_DrvSetPointerShape, (PFN) DrvSetPointerShape }, // 29
|
---|
59 | { INDEX_DrvMovePointer, (PFN) DrvMovePointer }, // 30
|
---|
60 | { INDEX_DrvLineTo, (PFN) DrvLineTo }, // 31
|
---|
61 | { INDEX_DrvSynchronize, (PFN) DrvSynchronize }, // 38
|
---|
62 | { INDEX_DrvSaveScreenBits, (PFN) DrvSaveScreenBits }, // 40
|
---|
63 | { INDEX_DrvGetModes, (PFN) DrvGetModes }, // 41
|
---|
64 | #ifdef VBOX_WITH_DDRAW
|
---|
65 | { INDEX_DrvGetDirectDrawInfo, (PFN) DrvGetDirectDrawInfo }, // 59 0x3b
|
---|
66 | { INDEX_DrvEnableDirectDraw, (PFN) DrvEnableDirectDraw }, // 60 0x3c
|
---|
67 | { INDEX_DrvDisableDirectDraw, (PFN) DrvDisableDirectDraw }, // 61 0x3d
|
---|
68 | #endif
|
---|
69 | };
|
---|
70 | /* Experimental begin */
|
---|
71 | BOOL APIENTRY DrvResetPDEV(DHPDEV dhpdevOld, DHPDEV dhpdevNew)
|
---|
72 | {
|
---|
73 | DISPDBG((0, "Experimental %s: %p, %p\n", __FUNCTION__, dhpdevOld, dhpdevNew));
|
---|
74 | return TRUE;
|
---|
75 | }
|
---|
76 |
|
---|
77 | BOOL DrvNineGrid (PVOID x1, PVOID x2, PVOID x3, PVOID x4, PVOID x5, PVOID x6, PVOID x7, PVOID x8, PVOID x9)
|
---|
78 | {
|
---|
79 | DISPDBG((0, "Experimental %s: %p, %p, %p, %p, %p, %p, %p, %p, %p\n", __FUNCTION__, x1, x2, x3, x4, x5, x6, x7, x8, x9));
|
---|
80 | return FALSE;
|
---|
81 | }
|
---|
82 |
|
---|
83 | VOID APIENTRY DrvDestroyFont(FONTOBJ *pfo)
|
---|
84 | {
|
---|
85 | DISPDBG((0, "Experimental %s: %p\n", __FUNCTION__, pfo));
|
---|
86 | }
|
---|
87 |
|
---|
88 | ULONG APIENTRY DrvEscape(SURFOBJ *pso, ULONG iEsc, ULONG cjIn, PVOID pvIn, ULONG cjOut, PVOID pvOut)
|
---|
89 | {
|
---|
90 | PDEV* ppdev = (PDEV*) pso->dhpdev;
|
---|
91 |
|
---|
92 | DISPDBG((0, "%s: %p, %p, %p, %p, %p, %p\n", __FUNCTION__, pso, iEsc, cjIn, pvIn, cjOut, pvOut));
|
---|
93 |
|
---|
94 | switch(iEsc)
|
---|
95 | {
|
---|
96 | #ifdef VBOX_WITH_OPENGL
|
---|
97 | case OPENGL_GETINFO:
|
---|
98 | {
|
---|
99 | if ( cjOut >= sizeof(OPENGL_INFO)
|
---|
100 | && pvOut)
|
---|
101 | {
|
---|
102 | POPENGL_INFO pInfo = (POPENGL_INFO)pvOut;
|
---|
103 |
|
---|
104 | pInfo->dwVersion = 2;
|
---|
105 | pInfo->dwDriverVersion = 1;
|
---|
106 | pInfo->szDriverName[0] = 'V';
|
---|
107 | pInfo->szDriverName[1] = 'B';
|
---|
108 | pInfo->szDriverName[2] = 'o';
|
---|
109 | pInfo->szDriverName[3] = 'x';
|
---|
110 | pInfo->szDriverName[4] = 'O';
|
---|
111 | pInfo->szDriverName[5] = 'G';
|
---|
112 | pInfo->szDriverName[6] = 'L';
|
---|
113 | pInfo->szDriverName[7] = 0;
|
---|
114 |
|
---|
115 | DISPDBG((0, "OPENGL_GETINFO\n"));
|
---|
116 | return cjOut;
|
---|
117 | }
|
---|
118 | else
|
---|
119 | DISPDBG((0, "OPENGL_GETINFO invalid size %d\n", cjOut)); /* It doesn't matter that we fail here. Opengl32 will fall back to software rendering when this escape is not supported. */
|
---|
120 | break;
|
---|
121 | }
|
---|
122 | #endif
|
---|
123 |
|
---|
124 | case VBOXESC_ISVRDPACTIVE:
|
---|
125 | {
|
---|
126 | ULONG ret = 0;
|
---|
127 |
|
---|
128 | if (ppdev && ppdev->pVBVA)
|
---|
129 | {
|
---|
130 | if (ppdev->pVBVA->hostFlags.u32HostEvents & VBVA_F_MODE_VRDP)
|
---|
131 | {
|
---|
132 | ret = 1;
|
---|
133 | }
|
---|
134 | DISPDBG((0, "VBOXESC_ISVRDPACTIVE -> %d (%x)\n", ret, ppdev->pVBVA->hostFlags.u32HostEvents));
|
---|
135 | }
|
---|
136 | else
|
---|
137 | DISPDBG((0, "VBOXESC_ISVRDPACTIVE -> 0\n"));
|
---|
138 | return ret;
|
---|
139 | }
|
---|
140 |
|
---|
141 | case VBOXESC_SETVISIBLEREGION:
|
---|
142 | {
|
---|
143 | LPRGNDATA lpRgnData = (LPRGNDATA)pvIn;
|
---|
144 |
|
---|
145 | DISPDBG((0, "VBOXESC_SETVISIBLEREGION\n"));
|
---|
146 |
|
---|
147 | if ( cjIn >= sizeof(RGNDATAHEADER)
|
---|
148 | && pvIn
|
---|
149 | && lpRgnData->rdh.dwSize == sizeof(RGNDATAHEADER)
|
---|
150 | && lpRgnData->rdh.iType == RDH_RECTANGLES
|
---|
151 | && cjIn == lpRgnData->rdh.nCount * sizeof(RECT) + sizeof(RGNDATAHEADER))
|
---|
152 | {
|
---|
153 | DWORD ulReturn, i;
|
---|
154 | PRTRECT pRTRect;
|
---|
155 | RECT *pRect = (RECT *)&lpRgnData->Buffer;
|
---|
156 |
|
---|
157 | pRTRect = (PRTRECT) EngAllocMem(0, lpRgnData->rdh.nCount*sizeof(RTRECT), ALLOC_TAG);
|
---|
158 | for (i=0;i<lpRgnData->rdh.nCount;i++)
|
---|
159 | {
|
---|
160 | DISPDBG((0, "New visible rectangle (%d,%d) (%d,%d)\n", pRect[i].left, pRect[i].bottom, pRect[i].right, pRect[i].top));
|
---|
161 | pRTRect[i].xLeft = pRect[i].left;
|
---|
162 | pRTRect[i].yBottom = pRect[i].bottom;
|
---|
163 | pRTRect[i].xRight = pRect[i].right;
|
---|
164 | pRTRect[i].yTop = pRect[i].top;
|
---|
165 | }
|
---|
166 |
|
---|
167 | if (EngDeviceIoControl(ppdev->hDriver,
|
---|
168 | IOCTL_VIDEO_VBOX_SETVISIBLEREGION,
|
---|
169 | pRTRect,
|
---|
170 | lpRgnData->rdh.nCount*sizeof(RTRECT),
|
---|
171 | NULL,
|
---|
172 | 0,
|
---|
173 | &ulReturn))
|
---|
174 | {
|
---|
175 | DISPDBG((0, "DISP DrvAssertMode failed IOCTL_VIDEO_VBOX_SETVISIBLEREGION\n"));
|
---|
176 | return 0;
|
---|
177 | }
|
---|
178 | else
|
---|
179 | {
|
---|
180 | DISPDBG((0, "DISP IOCTL_VIDEO_VBOX_SETVISIBLEREGION successful\n"));
|
---|
181 | return 1;
|
---|
182 | }
|
---|
183 |
|
---|
184 | }
|
---|
185 | else
|
---|
186 | {
|
---|
187 | if (pvIn)
|
---|
188 | DISPDBG((0, "check failed rdh.dwSize=%x iType=%d size=%d expected size=%d\n", lpRgnData->rdh.dwSize, lpRgnData->rdh.iType, cjIn, lpRgnData->rdh.nCount * sizeof(RECT) + sizeof(RGNDATAHEADER)));
|
---|
189 | }
|
---|
190 |
|
---|
191 | break;
|
---|
192 | }
|
---|
193 |
|
---|
194 | case QUERYESCSUPPORT:
|
---|
195 | if ( cjIn == sizeof(DWORD)
|
---|
196 | && pvIn)
|
---|
197 | {
|
---|
198 | DWORD nEscapeQuery = *(DWORD *)pvIn;
|
---|
199 |
|
---|
200 | switch(nEscapeQuery)
|
---|
201 | {
|
---|
202 | #ifdef VBOX_WITH_OPENGL
|
---|
203 | case OPENGL_GETINFO:
|
---|
204 | return 1;
|
---|
205 | #endif
|
---|
206 | default:
|
---|
207 | DISPDBG((0, "QUERYESCSUPPORT %d unsupported\n", nEscapeQuery));
|
---|
208 | break;
|
---|
209 | }
|
---|
210 | }
|
---|
211 | else
|
---|
212 | DISPDBG((0, "QUERYESCSUPPORT invalid size %d\n", cjOut));
|
---|
213 | break;
|
---|
214 |
|
---|
215 | default:
|
---|
216 | DISPDBG((0, "Unsupported Escape %d\n", iEsc));
|
---|
217 | break;
|
---|
218 | }
|
---|
219 | return 0;
|
---|
220 | }
|
---|
221 |
|
---|
222 | BOOL DrvConnect (PVOID x1, PVOID x2, PVOID x3, PVOID x4)
|
---|
223 | {
|
---|
224 | DISPDBG((0, "Experimental %s: %p, %p, %p, %p\n", __FUNCTION__, x1, x2, x3, x4));
|
---|
225 | return TRUE;
|
---|
226 | }
|
---|
227 |
|
---|
228 | BOOL DrvDisconnect (PVOID x1, PVOID x2)
|
---|
229 | {
|
---|
230 | DISPDBG((0, "Experimental %s: %p, %p\n", __FUNCTION__, x1, x2));
|
---|
231 | return FALSE;
|
---|
232 | }
|
---|
233 |
|
---|
234 | BOOL DrvReconnect (PVOID x1, PVOID x2)
|
---|
235 | {
|
---|
236 | DISPDBG((0, "Experimental %s: %p, %p\n", __FUNCTION__, x1, x2));
|
---|
237 | return FALSE;
|
---|
238 | }
|
---|
239 |
|
---|
240 | BOOL DrvShadowConnect (PVOID x1, PVOID x2)
|
---|
241 | {
|
---|
242 | DISPDBG((0, "Experimental %s: %p, %p\n", __FUNCTION__, x1, x2));
|
---|
243 | return FALSE;
|
---|
244 | }
|
---|
245 |
|
---|
246 | BOOL DrvShadowDisconnect (PVOID x1, PVOID x2)
|
---|
247 | {
|
---|
248 | DISPDBG((0, "Experimental %s: %p, %p\n", __FUNCTION__, x1, x2));
|
---|
249 | return FALSE;
|
---|
250 | }
|
---|
251 |
|
---|
252 |
|
---|
253 | /* Experimental end */
|
---|
254 |
|
---|
255 | // W2K,XP functions
|
---|
256 | DRVFN gadrvfn_nt5[] = {
|
---|
257 | { INDEX_DrvEnablePDEV, (PFN) DrvEnablePDEV }, // 0 0x0
|
---|
258 | { INDEX_DrvCompletePDEV, (PFN) DrvCompletePDEV }, // 1 0x1
|
---|
259 | { INDEX_DrvDisablePDEV, (PFN) DrvDisablePDEV }, // 2 0x2
|
---|
260 | { INDEX_DrvEnableSurface, (PFN) DrvEnableSurface }, // 3 0x3
|
---|
261 | { INDEX_DrvDisableSurface, (PFN) DrvDisableSurface }, // 4 0x4
|
---|
262 | { INDEX_DrvAssertMode, (PFN) DrvAssertMode }, // 5 0x5
|
---|
263 | { INDEX_DrvDisableDriver, (PFN) DrvDisableDriver }, // 8 0x8
|
---|
264 | // { INDEX_DrvCreateDeviceBitmap, (PFN) DrvCreateDeviceBitmap }, // 10
|
---|
265 | // { INDEX_DrvDeleteDeviceBitmap, (PFN) DrvDeleteDeviceBitmap }, // 11
|
---|
266 | { INDEX_DrvRealizeBrush, (PFN) DrvRealizeBrush }, // 12 0xc
|
---|
267 | { INDEX_DrvDitherColor, (PFN) DrvDitherColor }, // 13 0xd
|
---|
268 | { INDEX_DrvStrokePath, (PFN) DrvStrokePath }, // 14 0xe
|
---|
269 | { INDEX_DrvFillPath, (PFN) DrvFillPath }, // 15 0xf
|
---|
270 | // { INDEX_DrvStrokeAndFillPath, (PFN) DrvStrokeAndFillPath }, // 16 0x10
|
---|
271 | { INDEX_DrvPaint, (PFN) DrvPaint }, // 17 0x11
|
---|
272 | { INDEX_DrvBitBlt, (PFN) DrvBitBlt }, // 18 0x12
|
---|
273 | { INDEX_DrvCopyBits, (PFN) DrvCopyBits }, // 19 0x13
|
---|
274 | { INDEX_DrvStretchBlt, (PFN) DrvStretchBlt, }, // 20 0x14
|
---|
275 | { INDEX_DrvSetPalette, (PFN) DrvSetPalette }, // 22 0x16
|
---|
276 | { INDEX_DrvTextOut, (PFN) DrvTextOut }, // 23 0x17
|
---|
277 | { INDEX_DrvEscape, (PFN) DrvEscape }, // 24 0x18
|
---|
278 | { INDEX_DrvSetPointerShape, (PFN) DrvSetPointerShape }, // 29 0x1d
|
---|
279 | { INDEX_DrvMovePointer, (PFN) DrvMovePointer }, // 30 0x1e
|
---|
280 | { INDEX_DrvLineTo, (PFN) DrvLineTo }, // 31 0x1f
|
---|
281 | { INDEX_DrvSynchronize, (PFN) DrvSynchronize }, // 38 0x26
|
---|
282 | { INDEX_DrvSaveScreenBits, (PFN) DrvSaveScreenBits }, // 40 0x28
|
---|
283 | { INDEX_DrvGetModes, (PFN) DrvGetModes }, // 41 0x29
|
---|
284 | #ifdef VBOX_WITH_DDRAW
|
---|
285 | { INDEX_DrvGetDirectDrawInfo, (PFN) DrvGetDirectDrawInfo }, // 59 0x3b
|
---|
286 | { INDEX_DrvEnableDirectDraw, (PFN) DrvEnableDirectDraw }, // 60 0x3c
|
---|
287 | { INDEX_DrvDisableDirectDraw, (PFN) DrvDisableDirectDraw }, // 61 0x3d
|
---|
288 | { INDEX_DrvDeriveSurface, (PFN) DrvDeriveSurface }, // 85 0x55
|
---|
289 | #endif
|
---|
290 | { INDEX_DrvNotify, (PFN) DrvNotify }, // 87 0x57
|
---|
291 | // /* Experimental. */
|
---|
292 | // { 0x7, (PFN) DrvResetPDEV }, // 0x7
|
---|
293 | // { 0x5b, (PFN) DrvNineGrid }, // 0x5b
|
---|
294 | // { 0x2b, (PFN) DrvDestroyFont }, // 0x2b
|
---|
295 | // { 0x18, (PFN) DrvEscape }, // 0x18
|
---|
296 | // { 0x4d, (PFN) DrvConnect }, // 0x4d
|
---|
297 | // { 0x4e, (PFN) DrvDisconnect }, // 0x4e
|
---|
298 | // { 0x4f, (PFN) DrvReconnect }, // 0x4f
|
---|
299 | // { 0x50, (PFN) DrvShadowConnect }, // 0x50
|
---|
300 | // { 0x51, (PFN) DrvShadowDisconnect }, // 0x51
|
---|
301 |
|
---|
302 | };
|
---|
303 |
|
---|
304 | // Required hook bits will be set up according to DDI version
|
---|
305 | static ULONG gflHooks = 0;
|
---|
306 | BOOL g_bOnNT40 = TRUE; /* assume NT4 guest by default */
|
---|
307 |
|
---|
308 | #define HOOKS_BMF8BPP gflHooks
|
---|
309 | #define HOOKS_BMF16BPP gflHooks
|
---|
310 | #define HOOKS_BMF24BPP gflHooks
|
---|
311 | #define HOOKS_BMF32BPP gflHooks
|
---|
312 |
|
---|
313 |
|
---|
314 | /******************************Public*Routine******************************\
|
---|
315 | * DrvEnableDriver
|
---|
316 | *
|
---|
317 | * Enables the driver by retrieving the drivers function table and version.
|
---|
318 | *
|
---|
319 | \**************************************************************************/
|
---|
320 |
|
---|
321 | BOOL DrvEnableDriver(ULONG iEngineVersion, ULONG cj, PDRVENABLEDATA pded)
|
---|
322 | {
|
---|
323 | // Engine Version is passed down so future drivers can support previous
|
---|
324 | // engine versions. A next generation driver can support both the old
|
---|
325 | // and new engine conventions if told what version of engine it is
|
---|
326 | // working with. For the first version the driver does nothing with it.
|
---|
327 |
|
---|
328 | DISPDBG((0, "VBoxDisp::DrvEnableDriver called. iEngine version = %08X\n", iEngineVersion));
|
---|
329 |
|
---|
330 | // Set up hook flags to intercept all functions which can generate VRDP orders
|
---|
331 | gflHooks = HOOK_BITBLT | HOOK_TEXTOUT | HOOK_FILLPATH |
|
---|
332 | HOOK_COPYBITS | HOOK_STROKEPATH | HOOK_LINETO | /* HOOK_STROKEANDFILLPATH | */
|
---|
333 | #ifdef VBOX_NEW_SURFACE_CODE
|
---|
334 | HOOK_PAINT | HOOK_STRETCHBLT | HOOK_SYNCHRONIZE;
|
---|
335 | #else
|
---|
336 | HOOK_PAINT | HOOK_STRETCHBLT | HOOK_SYNCHRONIZEACCESS;
|
---|
337 | #endif
|
---|
338 | // Set up g_bOnNT40 based on the value in iEngineVersion
|
---|
339 | if(iEngineVersion >= DDI_DRIVER_VERSION_NT5)
|
---|
340 | g_bOnNT40 = FALSE;
|
---|
341 |
|
---|
342 | // Fill in as much as we can.
|
---|
343 |
|
---|
344 | if (cj >= sizeof(DRVENABLEDATA))
|
---|
345 | pded->pdrvfn = (iEngineVersion >= DDI_DRIVER_VERSION_NT5)?
|
---|
346 | gadrvfn_nt5:
|
---|
347 | gadrvfn_nt4;
|
---|
348 |
|
---|
349 |
|
---|
350 | if (cj >= (sizeof(ULONG) * 2))
|
---|
351 | pded->c = (iEngineVersion >= DDI_DRIVER_VERSION_NT5)?
|
---|
352 | sizeof(gadrvfn_nt5) / sizeof(DRVFN):
|
---|
353 | sizeof(gadrvfn_nt4) / sizeof(DRVFN);
|
---|
354 |
|
---|
355 | // DDI version this driver was targeted for is passed back to engine.
|
---|
356 | // Future graphic's engine may break calls down to old driver format.
|
---|
357 |
|
---|
358 | if (cj >= sizeof(ULONG))
|
---|
359 | pded->iDriverVersion = (iEngineVersion >= DDI_DRIVER_VERSION_NT5)?
|
---|
360 | DDI_DRIVER_VERSION_NT5:
|
---|
361 | DDI_DRIVER_VERSION_NT4;
|
---|
362 |
|
---|
363 |
|
---|
364 | return(TRUE);
|
---|
365 | }
|
---|
366 |
|
---|
367 | /******************************Public*Routine******************************\
|
---|
368 | * DrvDisableDriver
|
---|
369 | *
|
---|
370 | * Tells the driver it is being disabled. Release any resources allocated in
|
---|
371 | * DrvEnableDriver.
|
---|
372 | *
|
---|
373 | \**************************************************************************/
|
---|
374 |
|
---|
375 | VOID DrvDisableDriver(VOID)
|
---|
376 | {
|
---|
377 | DISPDBG((0, "VBoxDisp::DrvDisableDriver called.\n"));
|
---|
378 |
|
---|
379 |
|
---|
380 | return;
|
---|
381 | }
|
---|
382 |
|
---|
383 | /******************************Public*Routine******************************\
|
---|
384 | * DrvEnablePDEV
|
---|
385 | *
|
---|
386 | * DDI function, Enables the Physical Device.
|
---|
387 | *
|
---|
388 | * Return Value: device handle to pdev.
|
---|
389 | *
|
---|
390 | \**************************************************************************/
|
---|
391 |
|
---|
392 | DHPDEV DrvEnablePDEV(
|
---|
393 | DEVMODEW *pDevmode, // Pointer to DEVMODE
|
---|
394 | PWSTR pwszLogAddress, // Logical address
|
---|
395 | ULONG cPatterns, // number of patterns
|
---|
396 | HSURF *ahsurfPatterns, // return standard patterns
|
---|
397 | ULONG cjGdiInfo, // Length of memory pointed to by pGdiInfo
|
---|
398 | ULONG *pGdiInfo, // Pointer to GdiInfo structure
|
---|
399 | ULONG cjDevInfo, // Length of following PDEVINFO structure
|
---|
400 | DEVINFO *pDevInfo, // physical device information structure
|
---|
401 | HDEV hdev, // HDEV, used for callbacks
|
---|
402 | PWSTR pwszDeviceName, // DeviceName - not used
|
---|
403 | HANDLE hDriver) // Handle to base driver
|
---|
404 | {
|
---|
405 | GDIINFO GdiInfo;
|
---|
406 | DEVINFO DevInfo;
|
---|
407 | PPDEV ppdev = (PPDEV) NULL;
|
---|
408 |
|
---|
409 | DISPDBG((0, "VBoxDisp::DrvEnablePDEV called\n"));
|
---|
410 |
|
---|
411 | UNREFERENCED_PARAMETER(pwszLogAddress);
|
---|
412 | UNREFERENCED_PARAMETER(pwszDeviceName);
|
---|
413 |
|
---|
414 | RtlZeroMemory(&DevInfo, sizeof (DEVINFO));
|
---|
415 | RtlZeroMemory(&GdiInfo, sizeof (GDIINFO));
|
---|
416 |
|
---|
417 | // Allocate a physical device structure.
|
---|
418 |
|
---|
419 | ppdev = (PPDEV) EngAllocMem(0, sizeof(PDEV), ALLOC_TAG);
|
---|
420 |
|
---|
421 | if (ppdev == (PPDEV) NULL)
|
---|
422 | {
|
---|
423 | DISPDBG((0, "DISP DrvEnablePDEV failed EngAllocMem\n"));
|
---|
424 | return((DHPDEV) 0);
|
---|
425 | }
|
---|
426 |
|
---|
427 | memset(ppdev, 0, sizeof(PDEV));
|
---|
428 |
|
---|
429 | // Save the screen handle in the PDEV.
|
---|
430 |
|
---|
431 | ppdev->hDriver = hDriver;
|
---|
432 |
|
---|
433 | // Get the current screen mode information. Set up device caps and devinfo.
|
---|
434 |
|
---|
435 | if (!bInitPDEV(ppdev, pDevmode, &GdiInfo, &DevInfo))
|
---|
436 | {
|
---|
437 | DISPDBG((0,"DISP DrvEnablePDEV failed\n"));
|
---|
438 | goto error_free;
|
---|
439 | }
|
---|
440 |
|
---|
441 | // Initialize the cursor information.
|
---|
442 |
|
---|
443 | if (!bInitPointer(ppdev, &DevInfo))
|
---|
444 | {
|
---|
445 | // Not a fatal error...
|
---|
446 | DISPDBG((0, "DrvEnablePDEV failed bInitPointer\n"));
|
---|
447 | }
|
---|
448 |
|
---|
449 | // Initialize palette information.
|
---|
450 |
|
---|
451 | if (!bInitPaletteInfo(ppdev, &DevInfo))
|
---|
452 | {
|
---|
453 | DISPDBG((0, "DrvEnablePDEV failed bInitPalette\n"));
|
---|
454 | goto error_free;
|
---|
455 | }
|
---|
456 |
|
---|
457 | // // Start a thread that will process notifications from VMMDev
|
---|
458 | // if (!bInitNotificationThread(ppdev))
|
---|
459 | // {
|
---|
460 | // DISPDBG((0, "DrvEnablePDEV failed bInitNotificationThread\n"));
|
---|
461 | // goto error_free;
|
---|
462 | // }
|
---|
463 |
|
---|
464 | // Copy the devinfo into the engine buffer.
|
---|
465 |
|
---|
466 | DISPDBG((0, "VBoxDisp::DrvEnablePDEV: sizeof(DEVINFO) = %d, cjDevInfo = %d, alpha = %d\n", sizeof(DEVINFO), cjDevInfo, DevInfo.flGraphicsCaps2 & GCAPS2_ALPHACURSOR));
|
---|
467 |
|
---|
468 | // @todo seems to be not necessary. these bits are initialized in screen.c DevInfo.flGraphicsCaps |= GCAPS_OPAQUERECT |
|
---|
469 | // GCAPS_DITHERONREALIZE |
|
---|
470 | // GCAPS_PALMANAGED |
|
---|
471 | // GCAPS_ALTERNATEFILL |
|
---|
472 | // GCAPS_WINDINGFILL |
|
---|
473 | // GCAPS_MONO_DITHER |
|
---|
474 | // GCAPS_COLOR_DITHER |
|
---|
475 | // GCAPS_ASYNCMOVE;
|
---|
476 | //
|
---|
477 | // DevInfo.flGraphicsCaps |= GCAPS_DITHERONREALIZE;
|
---|
478 |
|
---|
479 | DevInfo.flGraphicsCaps2 |= GCAPS2_RESERVED1; /* @todo figure out what is this. */
|
---|
480 |
|
---|
481 | memcpy(pDevInfo, &DevInfo, min(sizeof(DEVINFO), cjDevInfo));
|
---|
482 |
|
---|
483 | // Set the pdevCaps with GdiInfo we have prepared to the list of caps for this
|
---|
484 | // pdev.
|
---|
485 |
|
---|
486 | memcpy(pGdiInfo, &GdiInfo, min(cjGdiInfo, sizeof(GDIINFO)));
|
---|
487 |
|
---|
488 | DISPDBG((0, "VBoxDisp::DrvEnablePDEV completed %x\n", ppdev));
|
---|
489 |
|
---|
490 | return((DHPDEV) ppdev);
|
---|
491 |
|
---|
492 | // Error case for failure.
|
---|
493 | error_free:
|
---|
494 | EngFreeMem(ppdev);
|
---|
495 | return((DHPDEV) 0);
|
---|
496 | }
|
---|
497 |
|
---|
498 | /******************************Public*Routine******************************\
|
---|
499 | * DrvCompletePDEV
|
---|
500 | *
|
---|
501 | * Store the HPDEV, the engines handle for this PDEV, in the DHPDEV.
|
---|
502 | *
|
---|
503 | \**************************************************************************/
|
---|
504 |
|
---|
505 | VOID DrvCompletePDEV(DHPDEV dhpdev, HDEV hdev)
|
---|
506 | {
|
---|
507 | DISPDBG((0, "VBoxDisp::DrvCompletePDEV called %x\n", dhpdev));
|
---|
508 | ((PPDEV) dhpdev)->hdevEng = hdev;
|
---|
509 | }
|
---|
510 |
|
---|
511 | /******************************Public*Routine******************************\
|
---|
512 | * DrvDisablePDEV
|
---|
513 | *
|
---|
514 | * Release the resources allocated in DrvEnablePDEV. If a surface has been
|
---|
515 | * enabled DrvDisableSurface will have already been called.
|
---|
516 | *
|
---|
517 | \**************************************************************************/
|
---|
518 |
|
---|
519 | VOID DrvDisablePDEV(DHPDEV dhpdev)
|
---|
520 | {
|
---|
521 | DISPDBG((0, "VBoxDisp::DrvDisablePDEV called %x\n", dhpdev));
|
---|
522 | // vStopNotificationThread ((PPDEV) dhpdev);
|
---|
523 | vDisablePalette((PPDEV) dhpdev);
|
---|
524 |
|
---|
525 | EngFreeMem(dhpdev);
|
---|
526 | }
|
---|
527 |
|
---|
528 | /******************************Public*Routine******************************\
|
---|
529 | * VOID DrvOffset
|
---|
530 | *
|
---|
531 | * DescriptionText
|
---|
532 | *
|
---|
533 | \**************************************************************************/
|
---|
534 |
|
---|
535 | BOOL DrvOffset(SURFOBJ *pso, LONG x, LONG y, FLONG flReserved)
|
---|
536 | {
|
---|
537 | PDEV* ppdev = (PDEV*) pso->dhpdev;
|
---|
538 |
|
---|
539 | DISPDBG((0, "VBoxDisp::DrvOffset %x %x %x\n", x, y, flReserved));
|
---|
540 |
|
---|
541 | // Add back last offset that we subtracted. I could combine the next
|
---|
542 | // two statements, but I thought this was more clear. It's not
|
---|
543 | // performance critical anyway.
|
---|
544 |
|
---|
545 | ppdev->pjScreen += ((ppdev->ptlOrg.y * ppdev->lDeltaScreen) +
|
---|
546 | (ppdev->ptlOrg.x * ((ppdev->ulBitCount+1) >> 3)));
|
---|
547 |
|
---|
548 | // Subtract out new offset
|
---|
549 |
|
---|
550 | ppdev->pjScreen -= ((y * ppdev->lDeltaScreen) +
|
---|
551 | (x * ((ppdev->ulBitCount+1) >> 3)));
|
---|
552 |
|
---|
553 | ppdev->ptlOrg.x = x;
|
---|
554 | ppdev->ptlOrg.y = y;
|
---|
555 |
|
---|
556 | return(TRUE);
|
---|
557 | }
|
---|
558 |
|
---|
559 | /******************************Public*Routine******************************\
|
---|
560 | * DrvEnableSurface
|
---|
561 | *
|
---|
562 | * Enable the surface for the device. Hook the calls this driver supports.
|
---|
563 | *
|
---|
564 | * Return: Handle to the surface if successful, 0 for failure.
|
---|
565 | *
|
---|
566 | \**************************************************************************/
|
---|
567 |
|
---|
568 | HSURF DrvEnableSurface(DHPDEV dhpdev)
|
---|
569 | {
|
---|
570 | PPDEV ppdev;
|
---|
571 | HSURF hsurf;
|
---|
572 | SIZEL sizl;
|
---|
573 | ULONG ulBitmapType;
|
---|
574 | FLONG flHooks;
|
---|
575 | #ifdef VBOX_NEW_SURFACE_CODE
|
---|
576 | PVBOXSURF psurf;
|
---|
577 | #endif
|
---|
578 | DISPDBG((0, "DISP DrvEnableSurface called\n"));
|
---|
579 |
|
---|
580 | // Create engine bitmap around frame buffer.
|
---|
581 |
|
---|
582 | ppdev = (PPDEV) dhpdev;
|
---|
583 |
|
---|
584 | ppdev->ptlOrg.x = 0;
|
---|
585 | ppdev->ptlOrg.y = 0;
|
---|
586 |
|
---|
587 | if (!bInitSURF(ppdev, TRUE))
|
---|
588 | {
|
---|
589 | DISPDBG((0, "DISP DrvEnableSurface failed bInitSURF\n"));
|
---|
590 | return(FALSE);
|
---|
591 | }
|
---|
592 |
|
---|
593 | DISPDBG((0, "DISP DrvEnableSurface bInitSURF success\n"));
|
---|
594 |
|
---|
595 | sizl.cx = ppdev->cxScreen;
|
---|
596 | sizl.cy = ppdev->cyScreen;
|
---|
597 |
|
---|
598 | if (ppdev->ulBitCount == 8)
|
---|
599 | {
|
---|
600 | if (!bInit256ColorPalette(ppdev)) {
|
---|
601 | DISPDBG((0, "DISP DrvEnableSurface failed to init the 8bpp palette\n"));
|
---|
602 | return(FALSE);
|
---|
603 | }
|
---|
604 | ulBitmapType = BMF_8BPP;
|
---|
605 | flHooks = HOOKS_BMF8BPP;
|
---|
606 | }
|
---|
607 | else if (ppdev->ulBitCount == 16)
|
---|
608 | {
|
---|
609 | ulBitmapType = BMF_16BPP;
|
---|
610 | flHooks = HOOKS_BMF16BPP;
|
---|
611 | }
|
---|
612 | else if (ppdev->ulBitCount == 24)
|
---|
613 | {
|
---|
614 | ulBitmapType = BMF_24BPP;
|
---|
615 | flHooks = HOOKS_BMF24BPP;
|
---|
616 | }
|
---|
617 | else
|
---|
618 | {
|
---|
619 | ulBitmapType = BMF_32BPP;
|
---|
620 | flHooks = HOOKS_BMF32BPP;
|
---|
621 | }
|
---|
622 |
|
---|
623 | #ifdef VBOX_NEW_SURFACE_CODE
|
---|
624 | psurf = (PVBOXSURF)EngAllocMem(0, sizeof(VBOXSURF), ALLOC_TAG);
|
---|
625 | if (psurf == NULL)
|
---|
626 | {
|
---|
627 | DISPDBG((0, "DrvEnableSurface: failed pdsurf memory allocation\n"));
|
---|
628 | goto l_Failure;
|
---|
629 | }
|
---|
630 | ppdev->pdsurfScreen = psurf;
|
---|
631 | psurf->ppdev = ppdev;
|
---|
632 |
|
---|
633 | //
|
---|
634 | // On NT4.0 we create a GDI managed bitmap as the primay surface. But
|
---|
635 | // on NT5.0 we create a device managed primary.
|
---|
636 | //
|
---|
637 | // On NT4.0 we still use our driver's accleration capabilities by
|
---|
638 | // doing a trick with EngLockSurface on the GDI managed primary.
|
---|
639 | //
|
---|
640 |
|
---|
641 | if(g_bOnNT40)
|
---|
642 | {
|
---|
643 | hsurf = (HSURF) EngCreateBitmap(sizl,
|
---|
644 | ppdev->lDeltaScreen,
|
---|
645 | ulBitmapType,
|
---|
646 | (ppdev->lDeltaScreen > 0) ? BMF_TOPDOWN : 0,
|
---|
647 | (PVOID)(ppdev->pjScreen));
|
---|
648 | }
|
---|
649 | else
|
---|
650 | {
|
---|
651 | hsurf = (HSURF)EngCreateDeviceSurface((DHSURF)psurf, sizl,
|
---|
652 | ulBitmapType);
|
---|
653 | }
|
---|
654 |
|
---|
655 | if ( hsurf == 0 )
|
---|
656 | {
|
---|
657 | DISPDBG((0, "DrvEnableSurface: failed EngCreateDeviceBitmap\n"));
|
---|
658 | goto l_Failure;
|
---|
659 | }
|
---|
660 |
|
---|
661 | //
|
---|
662 | // On NT5.0 we call EngModifSurface to expose our device surface to
|
---|
663 | // GDI. We cant do this on NT4.0 hence we call EngAssociateSurface.
|
---|
664 | //
|
---|
665 |
|
---|
666 | if(g_bOnNT40)
|
---|
667 | {
|
---|
668 | //
|
---|
669 | // We have to associate the surface we just created with our physical
|
---|
670 | // device so that GDI can get information related to the PDEV when
|
---|
671 | // it's drawing to the surface (such as, for example, the length of
|
---|
672 | // styles on the device when simulating styled lines).
|
---|
673 | //
|
---|
674 |
|
---|
675 | //
|
---|
676 | // On NT4.0 we dont want to be called to Synchronize Access
|
---|
677 | //
|
---|
678 | LONG myflHooks = flHooks;
|
---|
679 | myflHooks &= ~HOOK_SYNCHRONIZE;
|
---|
680 |
|
---|
681 | if (!EngAssociateSurface(hsurf, ppdev->hdevEng, myflHooks))
|
---|
682 | {
|
---|
683 | DISPDBG((0, "DrvEnableSurface: failed EngAssociateSurface\n"));
|
---|
684 | goto l_Failure;
|
---|
685 | }
|
---|
686 |
|
---|
687 | //
|
---|
688 | // Jam in the value of dhsurf into screen SURFOBJ. We do this to
|
---|
689 | // make sure the driver acclerates Drv calls we hook and not
|
---|
690 | // punt them back to GDI as the SURFOBJ's dhsurf = 0.
|
---|
691 | //
|
---|
692 | ppdev->psoScreenBitmap = EngLockSurface(hsurf);
|
---|
693 | if(ppdev->psoScreenBitmap == 0)
|
---|
694 | {
|
---|
695 | DISPDBG((0, "DrvEnableSurface: failed EngLockSurface\n"));
|
---|
696 | goto l_Failure;
|
---|
697 | }
|
---|
698 |
|
---|
699 | ppdev->psoScreenBitmap->dhsurf = (DHSURF)hsurf;
|
---|
700 |
|
---|
701 | }
|
---|
702 | else
|
---|
703 | {
|
---|
704 | //
|
---|
705 | // Tell GDI about the screen surface. This will enable GDI to render
|
---|
706 | // directly to the screen.
|
---|
707 | //
|
---|
708 |
|
---|
709 | if ( !EngModifySurface(hsurf,
|
---|
710 | ppdev->hdevEng,
|
---|
711 | flHooks,
|
---|
712 | MS_NOTSYSTEMMEMORY,
|
---|
713 | (DHSURF)psurf,
|
---|
714 | ppdev->pjScreen,
|
---|
715 | ppdev->lDeltaScreen,
|
---|
716 | NULL))
|
---|
717 | {
|
---|
718 | DISPDBG((0, "DrvEnableSurface: failed EngModifySurface"));
|
---|
719 | goto l_Failure;
|
---|
720 | }
|
---|
721 | }
|
---|
722 | ppdev->hsurfScreen = hsurf;
|
---|
723 | ppdev->flHooks = flHooks;
|
---|
724 | ppdev->ulBitmapType = ulBitmapType;
|
---|
725 | #else
|
---|
726 | /* Create a GDI bitmap which will be used to draw with Eng* functions. */
|
---|
727 | ppdev->hsurfScreenBitmap = (HSURF)EngCreateBitmap(sizl,
|
---|
728 | ppdev->lDeltaScreen,
|
---|
729 | ulBitmapType,
|
---|
730 | (ppdev->lDeltaScreen > 0) ? BMF_TOPDOWN : 0,
|
---|
731 | (PVOID) (ppdev->pjScreen));
|
---|
732 |
|
---|
733 | if (ppdev->hsurfScreenBitmap == (HSURF) 0)
|
---|
734 | {
|
---|
735 | DISPDBG((0, "DISP DrvEnableSurface failed EngCreateBitmap ppdev->hsurfScreenBitmap\n"));
|
---|
736 | goto l_Failure;
|
---|
737 | }
|
---|
738 | else
|
---|
739 | {
|
---|
740 | /* Get the GDI bitmap SURFOBJ, which will be passed to Eng*. */
|
---|
741 | ppdev->psoScreenBitmap = EngLockSurface(ppdev->hsurfScreenBitmap);
|
---|
742 |
|
---|
743 | /* Create device managed surface, which will represent screen for GDI. */
|
---|
744 | ppdev->hsurfScreen = (HSURF)EngCreateDeviceSurface((DHSURF)ppdev, /* Handle assigned by the device. */
|
---|
745 | sizl,
|
---|
746 | ulBitmapType);
|
---|
747 |
|
---|
748 | if (ppdev->hsurfScreen == (HSURF) 0)
|
---|
749 | {
|
---|
750 | DISPDBG((0, "DISP DrvEnableSurface failed EngCreateDeviceSurface ppdev->hsurfScreen\n"));
|
---|
751 | goto l_Failure;
|
---|
752 | }
|
---|
753 | else
|
---|
754 | {
|
---|
755 | /* Tell GDI that the driver will handle drawing operations on the screen surface. */
|
---|
756 | if (!EngAssociateSurface(ppdev->hsurfScreen, ppdev->hdevEng, flHooks))
|
---|
757 | {
|
---|
758 | DISPDBG((0, "DISP DrvEnableSurface failed EngAssociateSurface for Screen.\n"));
|
---|
759 | goto l_Failure;
|
---|
760 | }
|
---|
761 | else
|
---|
762 | {
|
---|
763 | ppdev->flHooks = flHooks;
|
---|
764 | ppdev->ulBitmapType = ulBitmapType;
|
---|
765 |
|
---|
766 | DISPDBG((0, "DISP DrvEnableSurface success ppdev %p, ppdev->hsurfScreen %p\n", ppdev, ppdev->hsurfScreen));
|
---|
767 | }
|
---|
768 | }
|
---|
769 | }
|
---|
770 | #endif /* VBOX_NEW_SURFACE_CODE */
|
---|
771 | return ppdev->hsurfScreen;
|
---|
772 |
|
---|
773 | l_Failure:
|
---|
774 |
|
---|
775 | DrvDisableSurface(dhpdev);
|
---|
776 |
|
---|
777 | return((HSURF)0);
|
---|
778 | }
|
---|
779 |
|
---|
780 | /******************************Public*Routine******************************\
|
---|
781 | * DrvDisableSurface
|
---|
782 | *
|
---|
783 | * Free resources allocated by DrvEnableSurface. Release the surface.
|
---|
784 | *
|
---|
785 | \**************************************************************************/
|
---|
786 |
|
---|
787 | VOID DrvDisableSurface(DHPDEV dhpdev)
|
---|
788 | {
|
---|
789 | PPDEV ppdev = (PPDEV)dhpdev;
|
---|
790 |
|
---|
791 | DISPDBG((0, "VBoxDisp::DrvDisableSurface called\n"));
|
---|
792 | if (ppdev->psoScreenBitmap)
|
---|
793 | {
|
---|
794 | EngUnlockSurface (ppdev->psoScreenBitmap);
|
---|
795 | ppdev->psoScreenBitmap = NULL;
|
---|
796 | }
|
---|
797 |
|
---|
798 | if (ppdev->hsurfScreen)
|
---|
799 | {
|
---|
800 | EngDeleteSurface(ppdev->hsurfScreen);
|
---|
801 | ppdev->hsurfScreen = (HSURF)0;
|
---|
802 | }
|
---|
803 | #ifdef VBOX_NEW_SURFACE_CODE
|
---|
804 | if (ppdev->pdsurfScreen)
|
---|
805 | {
|
---|
806 | EngFreeMem(ppdev->pdsurfScreen);
|
---|
807 | ppdev->pdsurfScreen = NULL;
|
---|
808 | }
|
---|
809 | #else
|
---|
810 | if (ppdev->hsurfScreenBitmap)
|
---|
811 | {
|
---|
812 | EngDeleteSurface(ppdev->hsurfScreenBitmap);
|
---|
813 | ppdev->hsurfScreenBitmap = (HSURF)0;
|
---|
814 | }
|
---|
815 | #endif
|
---|
816 |
|
---|
817 | vDisableSURF(ppdev);
|
---|
818 | }
|
---|
819 |
|
---|
820 | /******************************Public*Routine******************************\
|
---|
821 | * DrvAssertMode
|
---|
822 | *
|
---|
823 | * This asks the device to reset itself to the mode of the pdev passed in.
|
---|
824 | *
|
---|
825 | \**************************************************************************/
|
---|
826 |
|
---|
827 | BOOL DrvAssertMode(DHPDEV dhpdev, BOOL bEnable)
|
---|
828 | {
|
---|
829 | PPDEV ppdev = (PPDEV) dhpdev;
|
---|
830 | ULONG ulReturn;
|
---|
831 | PBYTE pjScreen;
|
---|
832 |
|
---|
833 | DISPDBG((0, "DISP DrvAssertMode called bEnable = %d\n", bEnable));
|
---|
834 |
|
---|
835 | if (bEnable)
|
---|
836 | {
|
---|
837 | pjScreen = ppdev->pjScreen;
|
---|
838 |
|
---|
839 | if (!bInitSURF(ppdev, FALSE))
|
---|
840 | {
|
---|
841 | DISPDBG((0, "DISP DrvAssertMode failed bInitSURF\n"));
|
---|
842 | return (FALSE);
|
---|
843 | }
|
---|
844 |
|
---|
845 | #ifdef VBOX_NEW_SURFACE_CODE
|
---|
846 | todo
|
---|
847 | #endif
|
---|
848 | if (pjScreen != ppdev->pjScreen)
|
---|
849 | {
|
---|
850 | HSURF hsurf;
|
---|
851 | SIZEL sizl;
|
---|
852 | SURFOBJ *pso;
|
---|
853 |
|
---|
854 | DISPDBG((0, "DISP DrvAssertMode Screen pointer has changed!!!\n"));
|
---|
855 |
|
---|
856 | sizl.cx = ppdev->cxScreen;
|
---|
857 | sizl.cy = ppdev->cyScreen;
|
---|
858 |
|
---|
859 | hsurf = (HSURF) EngCreateBitmap(sizl,
|
---|
860 | ppdev->lDeltaScreen,
|
---|
861 | ppdev->ulBitmapType,
|
---|
862 | (ppdev->lDeltaScreen > 0) ? BMF_TOPDOWN : 0,
|
---|
863 | (PVOID) (ppdev->pjScreen));
|
---|
864 |
|
---|
865 | if (hsurf == (HSURF) 0)
|
---|
866 | {
|
---|
867 | DISPDBG((0, "DISP DrvAssertMode failed EngCreateBitmap\n"));
|
---|
868 | return FALSE;
|
---|
869 | }
|
---|
870 |
|
---|
871 | pso = EngLockSurface(hsurf);
|
---|
872 |
|
---|
873 | if (ppdev->psoScreenBitmap)
|
---|
874 | {
|
---|
875 | EngUnlockSurface (ppdev->psoScreenBitmap);
|
---|
876 | ppdev->psoScreenBitmap = NULL;
|
---|
877 | }
|
---|
878 |
|
---|
879 | if (ppdev->hsurfScreenBitmap)
|
---|
880 | {
|
---|
881 | EngDeleteSurface(ppdev->hsurfScreenBitmap);
|
---|
882 | ppdev->hsurfScreenBitmap = (HSURF)0;
|
---|
883 | }
|
---|
884 |
|
---|
885 | ppdev->hsurfScreenBitmap = hsurf;
|
---|
886 | ppdev->psoScreenBitmap = pso;
|
---|
887 | }
|
---|
888 |
|
---|
889 | if (!EngAssociateSurface(ppdev->hsurfScreenBitmap, ppdev->hdevEng, 0))
|
---|
890 | {
|
---|
891 | DISPDBG((0, "DISP DrvAssertMode failed EngAssociateSurface for ScreenBitmap.\n"));
|
---|
892 | return FALSE;
|
---|
893 | }
|
---|
894 |
|
---|
895 | if (!EngAssociateSurface(ppdev->hsurfScreen, ppdev->hdevEng, ppdev->flHooks))
|
---|
896 | {
|
---|
897 | DISPDBG((0, "DISP DrvAssertMode failed EngAssociateSurface for Screen.\n"));
|
---|
898 | return FALSE;
|
---|
899 | }
|
---|
900 |
|
---|
901 | return TRUE;
|
---|
902 | }
|
---|
903 | else
|
---|
904 | {
|
---|
905 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
906 | /* tells we can not process host commands any more and ensures we've completed processing of the host VHWA commands */
|
---|
907 | vboxVHWADisable(ppdev);
|
---|
908 | #endif
|
---|
909 |
|
---|
910 | /* Free the driver's VBVA resources. */
|
---|
911 | vboxVbvaDisable ((PPDEV) dhpdev);
|
---|
912 |
|
---|
913 | //
|
---|
914 | // We must give up the display.
|
---|
915 | // Call the kernel driver to reset the device to a known state.
|
---|
916 | //
|
---|
917 |
|
---|
918 | if (EngDeviceIoControl(ppdev->hDriver,
|
---|
919 | IOCTL_VIDEO_RESET_DEVICE,
|
---|
920 | NULL,
|
---|
921 | 0,
|
---|
922 | NULL,
|
---|
923 | 0,
|
---|
924 | &ulReturn))
|
---|
925 | {
|
---|
926 | DISPDBG((0, "DISP DrvAssertMode failed IOCTL\n"));
|
---|
927 | return FALSE;
|
---|
928 | }
|
---|
929 | else
|
---|
930 | {
|
---|
931 | return TRUE;
|
---|
932 | }
|
---|
933 | }
|
---|
934 | }
|
---|
935 |
|
---|
936 | #if 0
|
---|
937 | /******************************Public*Routine**********************************\
|
---|
938 | * HBITMAP DrvCreateDeviceBitmap
|
---|
939 | *
|
---|
940 | * Function called by GDI to create a device-format-bitmap (DFB). We will
|
---|
941 | * always try to allocate the bitmap in off-screen; if we can't, we simply
|
---|
942 | * fail the call and GDI will create and manage the bitmap itself.
|
---|
943 | *
|
---|
944 | * Note: We do not have to zero the bitmap bits. GDI will automatically
|
---|
945 | * call us via DrvBitBlt to zero the bits (which is a security
|
---|
946 | * consideration).
|
---|
947 | *
|
---|
948 | \******************************************************************************/
|
---|
949 |
|
---|
950 | HBITMAP
|
---|
951 | DrvCreateDeviceBitmap(
|
---|
952 | DHPDEV dhpdev,
|
---|
953 | SIZEL sizl,
|
---|
954 | ULONG iFormat)
|
---|
955 | {
|
---|
956 | DISPDBG((0, "DISP DrvCreateDeviceBitmap %x (%d,%d) %x\n", dhpdev, sizl.cx, sizl.cy, iFormat));
|
---|
957 | /* Let GDI manage the bitmap */
|
---|
958 | return (HBITMAP)0;
|
---|
959 | }
|
---|
960 |
|
---|
961 | /******************************Public*Routine**********************************\
|
---|
962 | * VOID DrvDeleteDeviceBitmap
|
---|
963 | *
|
---|
964 | * Deletes a DFB.
|
---|
965 | *
|
---|
966 | \******************************************************************************/
|
---|
967 |
|
---|
968 | VOID
|
---|
969 | DrvDeleteDeviceBitmap(
|
---|
970 | DHSURF dhsurf)
|
---|
971 | {
|
---|
972 | DISPDBG((0, "DISP DrvDeleteDeviceBitmap %x", dhsurf));
|
---|
973 | }
|
---|
974 | #endif /* 0 */
|
---|
975 |
|
---|
976 | /******************************Public*Routine******************************\
|
---|
977 | * DrvGetModes
|
---|
978 | *
|
---|
979 | * Returns the list of available modes for the device.
|
---|
980 | *
|
---|
981 | \**************************************************************************/
|
---|
982 |
|
---|
983 | ULONG DrvGetModes(HANDLE hDriver, ULONG cjSize, DEVMODEW *pdm)
|
---|
984 | {
|
---|
985 |
|
---|
986 | DWORD cModes;
|
---|
987 | DWORD cbOutputSize;
|
---|
988 | PVIDEO_MODE_INFORMATION pVideoModeInformation, pVideoTemp;
|
---|
989 | DWORD cOutputModes = cjSize / (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
|
---|
990 | DWORD cbModeSize;
|
---|
991 |
|
---|
992 | DISPDBG((3, "DrvGetModes\n"));
|
---|
993 |
|
---|
994 | cModes = getAvailableModes(hDriver,
|
---|
995 | (PVIDEO_MODE_INFORMATION *) &pVideoModeInformation,
|
---|
996 | &cbModeSize);
|
---|
997 |
|
---|
998 | if (cModes == 0)
|
---|
999 | {
|
---|
1000 | DISPDBG((0, "DrvGetModes failed to get mode information"));
|
---|
1001 | return 0;
|
---|
1002 | }
|
---|
1003 |
|
---|
1004 | if (pdm == NULL)
|
---|
1005 | {
|
---|
1006 | cbOutputSize = cModes * (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
|
---|
1007 | }
|
---|
1008 | else
|
---|
1009 | {
|
---|
1010 | //
|
---|
1011 | // Now copy the information for the supported modes back into the output
|
---|
1012 | // buffer
|
---|
1013 | //
|
---|
1014 |
|
---|
1015 | cbOutputSize = 0;
|
---|
1016 |
|
---|
1017 | pVideoTemp = pVideoModeInformation;
|
---|
1018 |
|
---|
1019 | do
|
---|
1020 | {
|
---|
1021 | if (pVideoTemp->Length != 0)
|
---|
1022 | {
|
---|
1023 | if (cOutputModes == 0)
|
---|
1024 | {
|
---|
1025 | break;
|
---|
1026 | }
|
---|
1027 |
|
---|
1028 | //
|
---|
1029 | // Zero the entire structure to start off with.
|
---|
1030 | //
|
---|
1031 |
|
---|
1032 | memset(pdm, 0, sizeof(DEVMODEW));
|
---|
1033 |
|
---|
1034 | //
|
---|
1035 | // Set the name of the device to the name of the DLL.
|
---|
1036 | //
|
---|
1037 |
|
---|
1038 | memcpy(pdm->dmDeviceName, DLL_NAME, sizeof(DLL_NAME));
|
---|
1039 |
|
---|
1040 | pdm->dmSpecVersion = DM_SPECVERSION;
|
---|
1041 | pdm->dmDriverVersion = DM_SPECVERSION;
|
---|
1042 | pdm->dmSize = sizeof(DEVMODEW);
|
---|
1043 | pdm->dmDriverExtra = DRIVER_EXTRA_SIZE;
|
---|
1044 |
|
---|
1045 | pdm->dmBitsPerPel = pVideoTemp->NumberOfPlanes *
|
---|
1046 | pVideoTemp->BitsPerPlane;
|
---|
1047 | pdm->dmPelsWidth = pVideoTemp->VisScreenWidth;
|
---|
1048 | pdm->dmPelsHeight = pVideoTemp->VisScreenHeight;
|
---|
1049 | pdm->dmDisplayFrequency = pVideoTemp->Frequency;
|
---|
1050 | pdm->dmDisplayFlags = 0;
|
---|
1051 |
|
---|
1052 | pdm->dmFields = DM_BITSPERPEL |
|
---|
1053 | DM_PELSWIDTH |
|
---|
1054 | DM_PELSHEIGHT |
|
---|
1055 | DM_DISPLAYFREQUENCY |
|
---|
1056 | DM_DISPLAYFLAGS ;
|
---|
1057 |
|
---|
1058 | //
|
---|
1059 | // Go to the next DEVMODE entry in the buffer.
|
---|
1060 | //
|
---|
1061 |
|
---|
1062 | cOutputModes--;
|
---|
1063 |
|
---|
1064 | pdm = (LPDEVMODEW) ( ((ULONG_PTR)pdm) + sizeof(DEVMODEW)
|
---|
1065 | + DRIVER_EXTRA_SIZE);
|
---|
1066 |
|
---|
1067 | cbOutputSize += (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
|
---|
1068 |
|
---|
1069 | }
|
---|
1070 |
|
---|
1071 | pVideoTemp = (PVIDEO_MODE_INFORMATION)
|
---|
1072 | (((PUCHAR)pVideoTemp) + cbModeSize);
|
---|
1073 |
|
---|
1074 | } while (--cModes);
|
---|
1075 | }
|
---|
1076 |
|
---|
1077 | EngFreeMem(pVideoModeInformation);
|
---|
1078 |
|
---|
1079 | return cbOutputSize;
|
---|
1080 |
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 | VOID DrvSynchronize(IN DHPDEV dhpdev,IN RECTL *prcl)
|
---|
1084 | {
|
---|
1085 | DISPDBG((0, "VBoxDisp::DrvSynchronize\n"));
|
---|
1086 | }
|
---|
1087 |
|
---|
1088 | /******************************Public*Routine******************************\
|
---|
1089 | * DrvNotify
|
---|
1090 | *
|
---|
1091 | * Called by GDI to notify us of certain "interesting" events
|
---|
1092 | *
|
---|
1093 | * DN_DEVICE_ORIGIN is used to communicate the X/Y offsets of individual monitors
|
---|
1094 | * when DualView is in effect.
|
---|
1095 | *
|
---|
1096 | \**************************************************************************/
|
---|
1097 |
|
---|
1098 | VOID DrvNotify(
|
---|
1099 | SURFOBJ *pso,
|
---|
1100 | ULONG iType,
|
---|
1101 | PVOID pvData)
|
---|
1102 | {
|
---|
1103 | PDEV* ppdev = (PDEV*) pso->dhpdev;
|
---|
1104 |
|
---|
1105 | DISPDBG((0, "VBoxDisp::DrvNotify called.\n"));
|
---|
1106 |
|
---|
1107 | switch(iType)
|
---|
1108 | {
|
---|
1109 | case DN_DEVICE_ORIGIN:
|
---|
1110 | {
|
---|
1111 | POINTL ptlDevOrg = *(PPOINTL)pvData;
|
---|
1112 | DISPDBG((3, "DN_DEVICE_ORIGIN: current @%d,%d, new @%d,%d, (PSO = %p)\n", ppdev->ptlDevOrg.x,
|
---|
1113 | ppdev->ptlDevOrg.y, ptlDevOrg.x, ptlDevOrg.y, pso));
|
---|
1114 | if (ppdev->ptlDevOrg.x != ptlDevOrg.x || ppdev->ptlDevOrg.y != ptlDevOrg.y)
|
---|
1115 | {
|
---|
1116 | ppdev->ptlDevOrg = ptlDevOrg;
|
---|
1117 | VBoxProcessDisplayInfo(ppdev);
|
---|
1118 | }
|
---|
1119 | } break;
|
---|
1120 | case DN_DRAWING_BEGIN:
|
---|
1121 | DISPDBG((3, "DN_DRAWING_BEGIN (PSO = %p)\n", pso));
|
---|
1122 | break;
|
---|
1123 | }
|
---|
1124 | }
|
---|
1125 |
|
---|
1126 | #ifdef VBOX_WITH_DDRAW
|
---|
1127 | //--------------------------Public Routine-------------------------------------
|
---|
1128 | //
|
---|
1129 | // HBITMAP DrvDeriveSurface
|
---|
1130 | //
|
---|
1131 | // This function derives and creates a GDI surface from the specified
|
---|
1132 | // DirectDraw surface.
|
---|
1133 | //
|
---|
1134 | // Parameters
|
---|
1135 | // pDirectDraw-----Points to a DD_DIRECTDRAW_GLOBAL structure that describes
|
---|
1136 | // the DirectDraw object.
|
---|
1137 | // pSurface--------Points to a DD_SURFACE_LOCAL structure that describes the
|
---|
1138 | // DirectDraw surface around which to wrap a GDI surface.
|
---|
1139 | //
|
---|
1140 | // Return Value
|
---|
1141 | // DrvDeriveSurface returns a handle to the created GDI surface upon success.
|
---|
1142 | // It returns NULL if the call fails or if the driver cannot accelerate GDI
|
---|
1143 | // drawing to the specified DirectDraw surface.
|
---|
1144 | //
|
---|
1145 | // Comments
|
---|
1146 | // DrvDeriveSurface allows the driver to create a GDI surface around a
|
---|
1147 | // DirectDraw video memory or AGP surface object in order to allow accelerated
|
---|
1148 | // GDI drawing to the surface. If the driver does not hook this call, all GDI
|
---|
1149 | // drawing to DirectDraw surfaces is done in software using the DIB engine.
|
---|
1150 | //
|
---|
1151 | // GDI calls DrvDeriveSurface with RGB surfaces only.
|
---|
1152 | //
|
---|
1153 | // The driver should call DrvCreateDeviceBitmap to create a GDI surface of the
|
---|
1154 | // same size and format as that of the DirectDraw surface. Space for the
|
---|
1155 | // actual pixels need not be allocated since it already exists.
|
---|
1156 | //
|
---|
1157 | //-----------------------------------------------------------------------------
|
---|
1158 | HBITMAP DrvDeriveSurface(DD_DIRECTDRAW_GLOBAL* pDirectDraw, DD_SURFACE_LOCAL* pSurface)
|
---|
1159 | {
|
---|
1160 | PPDEV pDev = (PPDEV)pDirectDraw->dhpdev;
|
---|
1161 | HBITMAP hbmDevice;
|
---|
1162 | DD_SURFACE_GLOBAL* pSurfaceGlobal;
|
---|
1163 |
|
---|
1164 | DISPDBG((0, "%s: %p\n", __FUNCTION__, pDev));
|
---|
1165 |
|
---|
1166 | pSurfaceGlobal = pSurface->lpGbl;
|
---|
1167 |
|
---|
1168 | //
|
---|
1169 | // GDI should never call us for a non-RGB surface, but let's assert just
|
---|
1170 | // to make sure they're doing their job properly.
|
---|
1171 | //
|
---|
1172 | AssertMsg(!(pSurfaceGlobal->ddpfSurface.dwFlags & DDPF_FOURCC), ("GDI called us with a non-RGB surface!"));
|
---|
1173 |
|
---|
1174 | // The GDI driver does not accelerate surfaces in AGP memory,
|
---|
1175 | // thus we fail the call
|
---|
1176 |
|
---|
1177 | if (pSurface->ddsCaps.dwCaps & DDSCAPS_NONLOCALVIDMEM)
|
---|
1178 | {
|
---|
1179 | DISPDBG((0, "DrvDeriveSurface return NULL, surface in AGP memory\n"));
|
---|
1180 | return 0;
|
---|
1181 | }
|
---|
1182 |
|
---|
1183 | // The GDI driver does not accelerate managed surface,
|
---|
1184 | // thus we fail the call
|
---|
1185 | if (pSurface->lpSurfMore->ddsCapsEx.dwCaps2 & DDSCAPS2_TEXTUREMANAGE)
|
---|
1186 | {
|
---|
1187 | DISPDBG((0, "DrvDeriveSurface return NULL, surface is managed\n"));
|
---|
1188 | return 0;
|
---|
1189 | }
|
---|
1190 |
|
---|
1191 | //
|
---|
1192 | // The rest of our driver expects GDI calls to come in with the same
|
---|
1193 | // format as the primary surface. So we'd better not wrap a device
|
---|
1194 | // bitmap around an RGB format that the rest of our driver doesn't
|
---|
1195 | // understand. Also, we must check to see that it is not a surface
|
---|
1196 | // whose pitch does not match the primary surface.
|
---|
1197 | //
|
---|
1198 | // NOTE: Most surfaces created by this driver are allocated as 2D surfaces
|
---|
1199 | // whose lPitch's are equal to the screen pitch. However, overlay surfaces
|
---|
1200 | // are allocated such that there lPitch's are usually different then the
|
---|
1201 | // screen pitch. The hardware can not accelerate drawing operations to
|
---|
1202 | // these surfaces and thus we fail to derive these surfaces.
|
---|
1203 | //
|
---|
1204 | if ( (pSurfaceGlobal->ddpfSurface.dwRGBBitCount == pDev->ulBitCount) )
|
---|
1205 | {
|
---|
1206 | SIZEL sizel;
|
---|
1207 | DWORD ulBitmapType, flHooks;
|
---|
1208 |
|
---|
1209 | sizel.cx = pSurfaceGlobal->wWidth;
|
---|
1210 | sizel.cy = pSurfaceGlobal->wHeight;
|
---|
1211 |
|
---|
1212 | if (pDev->ulBitCount == 8)
|
---|
1213 | {
|
---|
1214 | ulBitmapType = BMF_8BPP;
|
---|
1215 | flHooks = HOOKS_BMF8BPP;
|
---|
1216 | }
|
---|
1217 | else if (pDev->ulBitCount == 16)
|
---|
1218 | {
|
---|
1219 | ulBitmapType = BMF_16BPP;
|
---|
1220 | flHooks = HOOKS_BMF16BPP;
|
---|
1221 | }
|
---|
1222 | else if (pDev->ulBitCount == 24)
|
---|
1223 | {
|
---|
1224 | ulBitmapType = BMF_24BPP;
|
---|
1225 | flHooks = HOOKS_BMF24BPP;
|
---|
1226 | }
|
---|
1227 | else
|
---|
1228 | {
|
---|
1229 | ulBitmapType = BMF_32BPP;
|
---|
1230 | flHooks = HOOKS_BMF32BPP;
|
---|
1231 | }
|
---|
1232 |
|
---|
1233 | /* Create a bitmap that represents the DDRAW bits.
|
---|
1234 | * Important is to calculate the address of the bitmap.
|
---|
1235 | */
|
---|
1236 | hbmDevice = EngCreateBitmap(sizel,
|
---|
1237 | pSurfaceGlobal->lPitch,
|
---|
1238 | ulBitmapType,
|
---|
1239 | (pDev->lDeltaScreen > 0) ? BMF_TOPDOWN : 0,
|
---|
1240 | (PVOID) (pDev->pjScreen + pSurfaceGlobal->fpVidMem));
|
---|
1241 | if (hbmDevice)
|
---|
1242 | {
|
---|
1243 | if (pSurfaceGlobal->fpVidMem == 0)
|
---|
1244 | {
|
---|
1245 | /* Screen surface, mark it so it will be recognized by the driver.
|
---|
1246 | * and so the driver will be called on any operations on the surface
|
---|
1247 | * (required for VBVA and VRDP).
|
---|
1248 | */
|
---|
1249 | if (EngAssociateSurface((HSURF)hbmDevice, pDev->hdevEng, flHooks))
|
---|
1250 | {
|
---|
1251 | SURFOBJ *surfobj = EngLockSurface ((HSURF)hbmDevice);
|
---|
1252 | DISPDBG((0, "DrvDeriveSurface surfobj %x, hsurf = %x\n", surfobj, surfobj->hsurf));
|
---|
1253 |
|
---|
1254 | surfobj->dhpdev = (DHPDEV)pDev;
|
---|
1255 |
|
---|
1256 | EngUnlockSurface(surfobj);
|
---|
1257 |
|
---|
1258 | DISPDBG((0, "DrvDeriveSurface return succeed %x at %x\n", hbmDevice, pSurfaceGlobal->fpVidMem));
|
---|
1259 | return(hbmDevice);
|
---|
1260 | }
|
---|
1261 | }
|
---|
1262 | else
|
---|
1263 | {
|
---|
1264 | DISPDBG((0, "DrvDeriveSurface return succeed %x at %x\n", hbmDevice, pSurfaceGlobal->fpVidMem));
|
---|
1265 | return(hbmDevice);
|
---|
1266 | }
|
---|
1267 |
|
---|
1268 | DISPDBG((0, "DrvDeriveSurface: EngAssociateSurface failed\n"));
|
---|
1269 | EngDeleteSurface((HSURF)hbmDevice);
|
---|
1270 | }
|
---|
1271 | }
|
---|
1272 |
|
---|
1273 | DISPDBG((0, "DrvDeriveSurface return NULL\n"));
|
---|
1274 | DISPDBG((0, "pSurfaceGlobal->ddpfSurface.dwRGBBitCount = %d, lPitch =%ld\n", pSurfaceGlobal->ddpfSurface.dwRGBBitCount,pSurfaceGlobal->lPitch));
|
---|
1275 |
|
---|
1276 | return(0);
|
---|
1277 | }
|
---|
1278 | #endif /* VBOX_WITH_DDRAW */
|
---|