1 | /******************************Module*Header*******************************\
|
---|
2 | *
|
---|
3 | * *******************
|
---|
4 | * * GDI SAMPLE CODE *
|
---|
5 | * *******************
|
---|
6 | *
|
---|
7 | * Module Name: enable.c
|
---|
8 | *
|
---|
9 | * This module contains the functions that enable and disable the
|
---|
10 | * driver, the pdev, and the surface.
|
---|
11 | *
|
---|
12 | * Copyright (c) 1992-1998 Microsoft Corporation
|
---|
13 | \**************************************************************************/
|
---|
14 |
|
---|
15 | #include "driver.h"
|
---|
16 |
|
---|
17 | // The driver function table with all function index/address pairs
|
---|
18 |
|
---|
19 | // Hook functions to track dirty rectangles and generate RDP orders.
|
---|
20 | // NT4 functions
|
---|
21 | DRVFN gadrvfn_nt4[] = {
|
---|
22 | { INDEX_DrvEnablePDEV, (PFN) DrvEnablePDEV }, // 0
|
---|
23 | { INDEX_DrvCompletePDEV, (PFN) DrvCompletePDEV }, // 1
|
---|
24 | { INDEX_DrvDisablePDEV, (PFN) DrvDisablePDEV }, // 2
|
---|
25 | { INDEX_DrvEnableSurface, (PFN) DrvEnableSurface }, // 3
|
---|
26 | { INDEX_DrvDisableSurface, (PFN) DrvDisableSurface }, // 4
|
---|
27 | { INDEX_DrvAssertMode, (PFN) DrvAssertMode }, // 5
|
---|
28 | { INDEX_DrvOffset, (PFN) DrvOffset }, // 6
|
---|
29 | { INDEX_DrvDisableDriver, (PFN) DrvDisableDriver }, // 8
|
---|
30 | { INDEX_DrvRealizeBrush, (PFN) DrvRealizeBrush }, // 12
|
---|
31 | { INDEX_DrvDitherColor, (PFN) DrvDitherColor }, // 13
|
---|
32 | { INDEX_DrvStrokePath, (PFN) DrvStrokePath }, // 14
|
---|
33 | { INDEX_DrvFillPath, (PFN) DrvFillPath }, // 15
|
---|
34 | { INDEX_DrvPaint, (PFN) DrvPaint }, // 17
|
---|
35 | { INDEX_DrvBitBlt, (PFN) DrvBitBlt }, // 18
|
---|
36 | { INDEX_DrvCopyBits, (PFN) DrvCopyBits }, // 19
|
---|
37 | { INDEX_DrvStretchBlt, (PFN) DrvStretchBlt, }, // 20
|
---|
38 | { INDEX_DrvSetPalette, (PFN) DrvSetPalette }, // 22
|
---|
39 | { INDEX_DrvTextOut, (PFN) DrvTextOut }, // 23
|
---|
40 | { INDEX_DrvSetPointerShape, (PFN) DrvSetPointerShape }, // 29
|
---|
41 | { INDEX_DrvMovePointer, (PFN) DrvMovePointer }, // 30
|
---|
42 | { INDEX_DrvLineTo, (PFN) DrvLineTo }, // 31
|
---|
43 | { INDEX_DrvSynchronize, (PFN) DrvSynchronize }, // 38
|
---|
44 | { INDEX_DrvSaveScreenBits, (PFN) DrvSaveScreenBits }, // 40
|
---|
45 | { INDEX_DrvGetModes, (PFN) DrvGetModes }, // 41
|
---|
46 | #ifdef VBOX_WITH_DDRAW
|
---|
47 | { INDEX_DrvGetDirectDrawInfo, (PFN) DrvGetDirectDrawInfo }, // 59 0x3b
|
---|
48 | { INDEX_DrvEnableDirectDraw, (PFN) DrvEnableDirectDraw }, // 60 0x3c
|
---|
49 | { INDEX_DrvDisableDirectDraw, (PFN) DrvDisableDirectDraw }, // 61 0x3d
|
---|
50 | #endif
|
---|
51 | };
|
---|
52 | /* Experimental begin */
|
---|
53 | BOOL APIENTRY DrvResetPDEV(
|
---|
54 | DHPDEV dhpdevOld,
|
---|
55 | DHPDEV dhpdevNew
|
---|
56 | )
|
---|
57 | {
|
---|
58 | DISPDBG((0, "Experimental %s: %p, %p\n", __FUNCTION__, dhpdevOld, dhpdevNew));
|
---|
59 | return TRUE;
|
---|
60 | }
|
---|
61 |
|
---|
62 | BOOL DrvNineGrid (PVOID x1, PVOID x2, PVOID x3, PVOID x4, PVOID x5, PVOID x6, PVOID x7, PVOID x8, PVOID x9)
|
---|
63 | {
|
---|
64 | DISPDBG((0, "Experimental %s: %p, %p, %p, %p, %p, %p, %p, %p, %p\n", __FUNCTION__, x1, x2, x3, x4, x5, x6, x7, x8, x9));
|
---|
65 | return FALSE;
|
---|
66 | }
|
---|
67 |
|
---|
68 | VOID APIENTRY DrvDestroyFont(
|
---|
69 | FONTOBJ *pfo)
|
---|
70 | {
|
---|
71 | DISPDBG((0, "Experimental %s: %p\n", __FUNCTION__, pfo));
|
---|
72 | }
|
---|
73 |
|
---|
74 | ULONG APIENTRY DrvEscape(
|
---|
75 | SURFOBJ *pso,
|
---|
76 | ULONG iEsc,
|
---|
77 | ULONG cjIn,
|
---|
78 | PVOID pvIn,
|
---|
79 | ULONG cjOut,
|
---|
80 | PVOID pvOut
|
---|
81 | )
|
---|
82 | {
|
---|
83 | DISPDBG((0, "Experimental %s: %p, %p, %p, %p, %p, %p\n", __FUNCTION__, pso, iEsc, cjIn, pvIn, cjOut, pvOut));
|
---|
84 | return 0;
|
---|
85 | }
|
---|
86 |
|
---|
87 | BOOL DrvConnect (PVOID x1, PVOID x2, PVOID x3, PVOID x4)
|
---|
88 | {
|
---|
89 | DISPDBG((0, "Experimental %s: %p, %p, %p, %p\n", __FUNCTION__, x1, x2, x3, x4));
|
---|
90 | return TRUE;
|
---|
91 | }
|
---|
92 |
|
---|
93 | BOOL DrvDisconnect (PVOID x1, PVOID x2)
|
---|
94 | {
|
---|
95 | DISPDBG((0, "Experimental %s: %p, %p\n", __FUNCTION__, x1, x2));
|
---|
96 | return FALSE;
|
---|
97 | }
|
---|
98 |
|
---|
99 | BOOL DrvReconnect (PVOID x1, PVOID x2)
|
---|
100 | {
|
---|
101 | DISPDBG((0, "Experimental %s: %p, %p\n", __FUNCTION__, x1, x2));
|
---|
102 | return FALSE;
|
---|
103 | }
|
---|
104 |
|
---|
105 | BOOL DrvShadowConnect (PVOID x1, PVOID x2)
|
---|
106 | {
|
---|
107 | DISPDBG((0, "Experimental %s: %p, %p\n", __FUNCTION__, x1, x2));
|
---|
108 | return FALSE;
|
---|
109 | }
|
---|
110 |
|
---|
111 | BOOL DrvShadowDisconnect (PVOID x1, PVOID x2)
|
---|
112 | {
|
---|
113 | DISPDBG((0, "Experimental %s: %p, %p\n", __FUNCTION__, x1, x2));
|
---|
114 | return FALSE;
|
---|
115 | }
|
---|
116 |
|
---|
117 |
|
---|
118 | /* Experimental end */
|
---|
119 |
|
---|
120 | // W2K,XP functions
|
---|
121 | DRVFN gadrvfn_nt5[] = {
|
---|
122 | { INDEX_DrvEnablePDEV, (PFN) DrvEnablePDEV }, // 0 0x0
|
---|
123 | { INDEX_DrvCompletePDEV, (PFN) DrvCompletePDEV }, // 1 0x1
|
---|
124 | { INDEX_DrvDisablePDEV, (PFN) DrvDisablePDEV }, // 2 0x2
|
---|
125 | { INDEX_DrvEnableSurface, (PFN) DrvEnableSurface }, // 3 0x3
|
---|
126 | { INDEX_DrvDisableSurface, (PFN) DrvDisableSurface }, // 4 0x4
|
---|
127 | { INDEX_DrvAssertMode, (PFN) DrvAssertMode }, // 5 0x5
|
---|
128 | { INDEX_DrvDisableDriver, (PFN) DrvDisableDriver }, // 8 0x8
|
---|
129 | { INDEX_DrvRealizeBrush, (PFN) DrvRealizeBrush }, // 12 0xc
|
---|
130 | { INDEX_DrvDitherColor, (PFN) DrvDitherColor }, // 13 0xd
|
---|
131 | { INDEX_DrvStrokePath, (PFN) DrvStrokePath }, // 14 0xe
|
---|
132 | { INDEX_DrvFillPath, (PFN) DrvFillPath }, // 15 0xf
|
---|
133 | { INDEX_DrvPaint, (PFN) DrvPaint }, // 17 0x11
|
---|
134 | { INDEX_DrvBitBlt, (PFN) DrvBitBlt }, // 18 0x12
|
---|
135 | { INDEX_DrvCopyBits, (PFN) DrvCopyBits }, // 19 0x13
|
---|
136 | { INDEX_DrvStretchBlt, (PFN) DrvStretchBlt, }, // 20 0x14
|
---|
137 | { INDEX_DrvSetPalette, (PFN) DrvSetPalette }, // 22 0x16
|
---|
138 | { INDEX_DrvTextOut, (PFN) DrvTextOut }, // 23 0x17
|
---|
139 | { INDEX_DrvSetPointerShape, (PFN) DrvSetPointerShape }, // 29 0x1d
|
---|
140 | { INDEX_DrvMovePointer, (PFN) DrvMovePointer }, // 30 0x1e
|
---|
141 | { INDEX_DrvLineTo, (PFN) DrvLineTo }, // 31 0x1f
|
---|
142 | { INDEX_DrvSynchronize, (PFN) DrvSynchronize }, // 38 0x26
|
---|
143 | { INDEX_DrvSaveScreenBits, (PFN) DrvSaveScreenBits }, // 40 0x28
|
---|
144 | { INDEX_DrvGetModes, (PFN) DrvGetModes }, // 41 0x29
|
---|
145 | #ifdef VBOX_WITH_DDRAW
|
---|
146 | { INDEX_DrvGetDirectDrawInfo, (PFN) DrvGetDirectDrawInfo }, // 59 0x3b
|
---|
147 | { INDEX_DrvEnableDirectDraw, (PFN) DrvEnableDirectDraw }, // 60 0x3c
|
---|
148 | { INDEX_DrvDisableDirectDraw, (PFN) DrvDisableDirectDraw }, // 61 0x3d
|
---|
149 | #endif
|
---|
150 | { INDEX_DrvNotify, (PFN) DrvNotify }, // 87 0x57
|
---|
151 | // /* Experimental. */
|
---|
152 | // { 0x7, (PFN) DrvResetPDEV }, // 0x7
|
---|
153 | // { 0x5b, (PFN) DrvNineGrid }, // 0x5b
|
---|
154 | // { 0x2b, (PFN) DrvDestroyFont }, // 0x2b
|
---|
155 | // { 0x18, (PFN) DrvEscape }, // 0x18
|
---|
156 | // { 0x4d, (PFN) DrvConnect }, // 0x4d
|
---|
157 | // { 0x4e, (PFN) DrvDisconnect }, // 0x4e
|
---|
158 | // { 0x4f, (PFN) DrvReconnect }, // 0x4f
|
---|
159 | // { 0x50, (PFN) DrvShadowConnect }, // 0x50
|
---|
160 | // { 0x51, (PFN) DrvShadowDisconnect }, // 0x51
|
---|
161 |
|
---|
162 | };
|
---|
163 |
|
---|
164 | // Required hook bits will be set up according to DDI version
|
---|
165 | static ULONG gflHooks = 0;
|
---|
166 |
|
---|
167 | #define HOOKS_BMF8BPP gflHooks
|
---|
168 | #define HOOKS_BMF16BPP gflHooks
|
---|
169 | #define HOOKS_BMF24BPP gflHooks
|
---|
170 | #define HOOKS_BMF32BPP gflHooks
|
---|
171 |
|
---|
172 | HSEMAPHORE ghsemHwBuffer = 0;
|
---|
173 |
|
---|
174 | /******************************Public*Routine******************************\
|
---|
175 | * DrvEnableDriver
|
---|
176 | *
|
---|
177 | * Enables the driver by retrieving the drivers function table and version.
|
---|
178 | *
|
---|
179 | \**************************************************************************/
|
---|
180 |
|
---|
181 | BOOL DrvEnableDriver(
|
---|
182 | ULONG iEngineVersion,
|
---|
183 | ULONG cj,
|
---|
184 | PDRVENABLEDATA pded)
|
---|
185 | {
|
---|
186 | // Engine Version is passed down so future drivers can support previous
|
---|
187 | // engine versions. A next generation driver can support both the old
|
---|
188 | // and new engine conventions if told what version of engine it is
|
---|
189 | // working with. For the first version the driver does nothing with it.
|
---|
190 |
|
---|
191 | iEngineVersion;
|
---|
192 |
|
---|
193 | DISPDBG((0, "VBoxDisp::DrvEnableDriver called. iEngine version = %08X\n", iEngineVersion));
|
---|
194 |
|
---|
195 | // Set up hook flags to intercept all functions which can generate VRDP orders
|
---|
196 | gflHooks = HOOK_BITBLT | HOOK_TEXTOUT | HOOK_FILLPATH |
|
---|
197 | HOOK_COPYBITS | HOOK_STROKEPATH | HOOK_LINETO |
|
---|
198 | HOOK_PAINT | HOOK_STRETCHBLT | HOOK_SYNCHRONIZEACCESS;
|
---|
199 |
|
---|
200 | // Fill in as much as we can.
|
---|
201 |
|
---|
202 | if (cj >= sizeof(DRVENABLEDATA))
|
---|
203 | pded->pdrvfn = (iEngineVersion >= DDI_DRIVER_VERSION_NT5)?
|
---|
204 | gadrvfn_nt5:
|
---|
205 | gadrvfn_nt4;
|
---|
206 |
|
---|
207 |
|
---|
208 | if (cj >= (sizeof(ULONG) * 2))
|
---|
209 | pded->c = (iEngineVersion >= DDI_DRIVER_VERSION_NT5)?
|
---|
210 | sizeof(gadrvfn_nt5) / sizeof(DRVFN):
|
---|
211 | sizeof(gadrvfn_nt4) / sizeof(DRVFN);
|
---|
212 |
|
---|
213 | // DDI version this driver was targeted for is passed back to engine.
|
---|
214 | // Future graphic's engine may break calls down to old driver format.
|
---|
215 |
|
---|
216 | if (cj >= sizeof(ULONG))
|
---|
217 | pded->iDriverVersion = (iEngineVersion >= DDI_DRIVER_VERSION_NT5)?
|
---|
218 | DDI_DRIVER_VERSION_NT5:
|
---|
219 | DDI_DRIVER_VERSION_NT4;
|
---|
220 |
|
---|
221 | if (!ghsemHwBuffer)
|
---|
222 | {
|
---|
223 | ghsemHwBuffer = EngCreateSemaphore ();
|
---|
224 | }
|
---|
225 |
|
---|
226 | return(TRUE);
|
---|
227 | }
|
---|
228 |
|
---|
229 | /******************************Public*Routine******************************\
|
---|
230 | * DrvDisableDriver
|
---|
231 | *
|
---|
232 | * Tells the driver it is being disabled. Release any resources allocated in
|
---|
233 | * DrvEnableDriver.
|
---|
234 | *
|
---|
235 | \**************************************************************************/
|
---|
236 |
|
---|
237 | VOID DrvDisableDriver(VOID)
|
---|
238 | {
|
---|
239 | DISPDBG((0, "VBoxDisp::DrvDisableDriver called.\n"));
|
---|
240 |
|
---|
241 | if (ghsemHwBuffer)
|
---|
242 | {
|
---|
243 | EngDeleteSemaphore (ghsemHwBuffer);
|
---|
244 | ghsemHwBuffer = NULL;
|
---|
245 | }
|
---|
246 |
|
---|
247 | return;
|
---|
248 | }
|
---|
249 |
|
---|
250 | /******************************Public*Routine******************************\
|
---|
251 | * DrvEnablePDEV
|
---|
252 | *
|
---|
253 | * DDI function, Enables the Physical Device.
|
---|
254 | *
|
---|
255 | * Return Value: device handle to pdev.
|
---|
256 | *
|
---|
257 | \**************************************************************************/
|
---|
258 |
|
---|
259 | DHPDEV DrvEnablePDEV(
|
---|
260 | DEVMODEW *pDevmode, // Pointer to DEVMODE
|
---|
261 | PWSTR pwszLogAddress, // Logical address
|
---|
262 | ULONG cPatterns, // number of patterns
|
---|
263 | HSURF *ahsurfPatterns, // return standard patterns
|
---|
264 | ULONG cjGdiInfo, // Length of memory pointed to by pGdiInfo
|
---|
265 | ULONG *pGdiInfo, // Pointer to GdiInfo structure
|
---|
266 | ULONG cjDevInfo, // Length of following PDEVINFO structure
|
---|
267 | DEVINFO *pDevInfo, // physical device information structure
|
---|
268 | HDEV hdev, // HDEV, used for callbacks
|
---|
269 | PWSTR pwszDeviceName, // DeviceName - not used
|
---|
270 | HANDLE hDriver) // Handle to base driver
|
---|
271 | {
|
---|
272 | GDIINFO GdiInfo;
|
---|
273 | DEVINFO DevInfo;
|
---|
274 | PPDEV ppdev = (PPDEV) NULL;
|
---|
275 |
|
---|
276 | DISPDBG((0, "VBoxDisp::DrvEnablePDEV called\n"));
|
---|
277 |
|
---|
278 | UNREFERENCED_PARAMETER(pwszLogAddress);
|
---|
279 | UNREFERENCED_PARAMETER(pwszDeviceName);
|
---|
280 |
|
---|
281 | RtlZeroMemory(&DevInfo, sizeof (DEVINFO));
|
---|
282 | RtlZeroMemory(&GdiInfo, sizeof (GDIINFO));
|
---|
283 |
|
---|
284 | // Allocate a physical device structure.
|
---|
285 |
|
---|
286 | ppdev = (PPDEV) EngAllocMem(0, sizeof(PDEV), ALLOC_TAG);
|
---|
287 |
|
---|
288 | if (ppdev == (PPDEV) NULL)
|
---|
289 | {
|
---|
290 | DISPDBG((0, "DISP DrvEnablePDEV failed EngAllocMem\n"));
|
---|
291 | return((DHPDEV) 0);
|
---|
292 | }
|
---|
293 |
|
---|
294 | memset(ppdev, 0, sizeof(PDEV));
|
---|
295 |
|
---|
296 | // Save the screen handle in the PDEV.
|
---|
297 |
|
---|
298 | ppdev->hDriver = hDriver;
|
---|
299 |
|
---|
300 | // Get the current screen mode information. Set up device caps and devinfo.
|
---|
301 |
|
---|
302 | if (!bInitPDEV(ppdev, pDevmode, &GdiInfo, &DevInfo))
|
---|
303 | {
|
---|
304 | DISPDBG((0,"DISP DrvEnablePDEV failed\n"));
|
---|
305 | goto error_free;
|
---|
306 | }
|
---|
307 |
|
---|
308 | // Initialize the cursor information.
|
---|
309 |
|
---|
310 | if (!bInitPointer(ppdev, &DevInfo))
|
---|
311 | {
|
---|
312 | // Not a fatal error...
|
---|
313 | DISPDBG((0, "DrvEnablePDEV failed bInitPointer\n"));
|
---|
314 | }
|
---|
315 |
|
---|
316 | // Initialize palette information.
|
---|
317 |
|
---|
318 | if (!bInitPaletteInfo(ppdev, &DevInfo))
|
---|
319 | {
|
---|
320 | DISPDBG((0, "DrvEnablePDEV failed bInitPalette\n"));
|
---|
321 | goto error_free;
|
---|
322 | }
|
---|
323 |
|
---|
324 | // // Start a thread that will process notifications from VMMDev
|
---|
325 | // if (!bInitNotificationThread(ppdev))
|
---|
326 | // {
|
---|
327 | // DISPDBG((0, "DrvEnablePDEV failed bInitNotificationThread\n"));
|
---|
328 | // goto error_free;
|
---|
329 | // }
|
---|
330 |
|
---|
331 | // Copy the devinfo into the engine buffer.
|
---|
332 |
|
---|
333 | DISPDBG((0, "VBoxDisp::DrvEnablePDEV: sizeof(DEVINFO) = %d, cjDevInfo = %d, alpha = %d\n", sizeof(DEVINFO), cjDevInfo, DevInfo.flGraphicsCaps2 & GCAPS2_ALPHACURSOR));
|
---|
334 |
|
---|
335 | // @todo seems to be not necessary. these bits are initialized in screen.c DevInfo.flGraphicsCaps |= GCAPS_OPAQUERECT |
|
---|
336 | // GCAPS_DITHERONREALIZE |
|
---|
337 | // GCAPS_PALMANAGED |
|
---|
338 | // GCAPS_ALTERNATEFILL |
|
---|
339 | // GCAPS_WINDINGFILL |
|
---|
340 | // GCAPS_MONO_DITHER |
|
---|
341 | // GCAPS_COLOR_DITHER |
|
---|
342 | // GCAPS_ASYNCMOVE;
|
---|
343 | //
|
---|
344 | // DevInfo.flGraphicsCaps |= GCAPS_DITHERONREALIZE;
|
---|
345 |
|
---|
346 | DevInfo.flGraphicsCaps2 |= GCAPS2_RESERVED1; /* @todo figure out what is this. */
|
---|
347 |
|
---|
348 | memcpy(pDevInfo, &DevInfo, min(sizeof(DEVINFO), cjDevInfo));
|
---|
349 |
|
---|
350 | // Set the pdevCaps with GdiInfo we have prepared to the list of caps for this
|
---|
351 | // pdev.
|
---|
352 |
|
---|
353 | memcpy(pGdiInfo, &GdiInfo, min(cjGdiInfo, sizeof(GDIINFO)));
|
---|
354 |
|
---|
355 | DISPDBG((0, "VBoxDisp::DrvEnablePDEV completed\n"));
|
---|
356 |
|
---|
357 | return((DHPDEV) ppdev);
|
---|
358 |
|
---|
359 | // Error case for failure.
|
---|
360 | error_free:
|
---|
361 | EngFreeMem(ppdev);
|
---|
362 | return((DHPDEV) 0);
|
---|
363 | }
|
---|
364 |
|
---|
365 | /******************************Public*Routine******************************\
|
---|
366 | * DrvCompletePDEV
|
---|
367 | *
|
---|
368 | * Store the HPDEV, the engines handle for this PDEV, in the DHPDEV.
|
---|
369 | *
|
---|
370 | \**************************************************************************/
|
---|
371 |
|
---|
372 | VOID DrvCompletePDEV(
|
---|
373 | DHPDEV dhpdev,
|
---|
374 | HDEV hdev)
|
---|
375 | {
|
---|
376 | DISPDBG((0, "VBoxDisp::DrvCompletePDEV called\n"));
|
---|
377 | ((PPDEV) dhpdev)->hdevEng = hdev;
|
---|
378 | }
|
---|
379 |
|
---|
380 | /******************************Public*Routine******************************\
|
---|
381 | * DrvDisablePDEV
|
---|
382 | *
|
---|
383 | * Release the resources allocated in DrvEnablePDEV. If a surface has been
|
---|
384 | * enabled DrvDisableSurface will have already been called.
|
---|
385 | *
|
---|
386 | \**************************************************************************/
|
---|
387 |
|
---|
388 | VOID DrvDisablePDEV(
|
---|
389 | DHPDEV dhpdev)
|
---|
390 | {
|
---|
391 | DISPDBG((0, "VBoxDisp::DrvDisablePDEV called\n"));
|
---|
392 | // vStopNotificationThread ((PPDEV) dhpdev);
|
---|
393 | vDisablePalette((PPDEV) dhpdev);
|
---|
394 |
|
---|
395 | /* Free the driver's VBVA resources. */
|
---|
396 | vboxVbvaDisable ((PPDEV) dhpdev);
|
---|
397 |
|
---|
398 | EngFreeMem(dhpdev);
|
---|
399 | }
|
---|
400 |
|
---|
401 | /******************************Public*Routine******************************\
|
---|
402 | * VOID DrvOffset
|
---|
403 | *
|
---|
404 | * DescriptionText
|
---|
405 | *
|
---|
406 | \**************************************************************************/
|
---|
407 |
|
---|
408 | BOOL DrvOffset(
|
---|
409 | SURFOBJ* pso,
|
---|
410 | LONG x,
|
---|
411 | LONG y,
|
---|
412 | FLONG flReserved)
|
---|
413 | {
|
---|
414 | PDEV* ppdev = (PDEV*) pso->dhpdev;
|
---|
415 |
|
---|
416 | // Add back last offset that we subtracted. I could combine the next
|
---|
417 | // two statements, but I thought this was more clear. It's not
|
---|
418 | // performance critical anyway.
|
---|
419 |
|
---|
420 | ppdev->pjScreen += ((ppdev->ptlOrg.y * ppdev->lDeltaScreen) +
|
---|
421 | (ppdev->ptlOrg.x * ((ppdev->ulBitCount+1) >> 3)));
|
---|
422 |
|
---|
423 | // Subtract out new offset
|
---|
424 |
|
---|
425 | ppdev->pjScreen -= ((y * ppdev->lDeltaScreen) +
|
---|
426 | (x * ((ppdev->ulBitCount+1) >> 3)));
|
---|
427 |
|
---|
428 | ppdev->ptlOrg.x = x;
|
---|
429 | ppdev->ptlOrg.y = y;
|
---|
430 |
|
---|
431 | return(TRUE);
|
---|
432 | }
|
---|
433 |
|
---|
434 | /******************************Public*Routine******************************\
|
---|
435 | * DrvEnableSurface
|
---|
436 | *
|
---|
437 | * Enable the surface for the device. Hook the calls this driver supports.
|
---|
438 | *
|
---|
439 | * Return: Handle to the surface if successful, 0 for failure.
|
---|
440 | *
|
---|
441 | \**************************************************************************/
|
---|
442 |
|
---|
443 | HSURF DrvEnableSurface(
|
---|
444 | DHPDEV dhpdev)
|
---|
445 | {
|
---|
446 | PPDEV ppdev;
|
---|
447 | HSURF hsurf;
|
---|
448 | SIZEL sizl;
|
---|
449 | ULONG ulBitmapType;
|
---|
450 | FLONG flHooks;
|
---|
451 |
|
---|
452 | DISPDBG((0, "DISP DrvEnableSurface called\n"));
|
---|
453 |
|
---|
454 | // Create engine bitmap around frame buffer.
|
---|
455 |
|
---|
456 | ppdev = (PPDEV) dhpdev;
|
---|
457 |
|
---|
458 | ppdev->ptlOrg.x = 0;
|
---|
459 | ppdev->ptlOrg.y = 0;
|
---|
460 |
|
---|
461 | if (!bInitSURF(ppdev, TRUE))
|
---|
462 | {
|
---|
463 | DISPDBG((0, "DISP DrvEnableSurface failed bInitSURF\n"));
|
---|
464 | return(FALSE);
|
---|
465 | }
|
---|
466 |
|
---|
467 | DISPDBG((0, "DISP DrvEnableSurface bInitSURF success\n"));
|
---|
468 |
|
---|
469 | sizl.cx = ppdev->cxScreen;
|
---|
470 | sizl.cy = ppdev->cyScreen;
|
---|
471 |
|
---|
472 | if (ppdev->ulBitCount == 8)
|
---|
473 | {
|
---|
474 | if (!bInit256ColorPalette(ppdev)) {
|
---|
475 | DISPDBG((0, "DISP DrvEnableSurface failed to init the 8bpp palette\n"));
|
---|
476 | return(FALSE);
|
---|
477 | }
|
---|
478 | ulBitmapType = BMF_8BPP;
|
---|
479 | flHooks = HOOKS_BMF8BPP;
|
---|
480 | }
|
---|
481 | else if (ppdev->ulBitCount == 16)
|
---|
482 | {
|
---|
483 | ulBitmapType = BMF_16BPP;
|
---|
484 | flHooks = HOOKS_BMF16BPP;
|
---|
485 | }
|
---|
486 | else if (ppdev->ulBitCount == 24)
|
---|
487 | {
|
---|
488 | ulBitmapType = BMF_24BPP;
|
---|
489 | flHooks = HOOKS_BMF24BPP;
|
---|
490 | }
|
---|
491 | else
|
---|
492 | {
|
---|
493 | ulBitmapType = BMF_32BPP;
|
---|
494 | flHooks = HOOKS_BMF32BPP;
|
---|
495 | }
|
---|
496 |
|
---|
497 | hsurf = (HSURF) EngCreateBitmap(sizl,
|
---|
498 | ppdev->lDeltaScreen,
|
---|
499 | ulBitmapType,
|
---|
500 | (ppdev->lDeltaScreen > 0) ? BMF_TOPDOWN : 0,
|
---|
501 | (PVOID) (ppdev->pjScreen));
|
---|
502 |
|
---|
503 | if (hsurf == (HSURF) 0)
|
---|
504 | {
|
---|
505 | DISPDBG((0, "DISP DrvEnableSurface failed EngCreateBitmap\n"));
|
---|
506 | goto l_Failure;
|
---|
507 | }
|
---|
508 | else
|
---|
509 | {
|
---|
510 | ppdev->hsurfScreenBitmap = hsurf;
|
---|
511 |
|
---|
512 | if (!EngAssociateSurface(hsurf, ppdev->hdevEng, 0))
|
---|
513 | {
|
---|
514 | DISPDBG((0, "DISP DrvEnableSurface failed EngAssociateSurface for ScreenBitmap.\n"));
|
---|
515 | goto l_Failure;
|
---|
516 | }
|
---|
517 | else
|
---|
518 | {
|
---|
519 | SURFOBJ *pso = EngLockSurface(hsurf);
|
---|
520 |
|
---|
521 | ppdev->psoScreenBitmap = pso;
|
---|
522 |
|
---|
523 | hsurf = (HSURF) EngCreateDeviceSurface((DHSURF)pso,
|
---|
524 | sizl,
|
---|
525 | ulBitmapType);
|
---|
526 |
|
---|
527 | if (hsurf == (HSURF) 0)
|
---|
528 | {
|
---|
529 | DISPDBG((0, "DISP DrvEnableSurface failed EngCreateDeviceSurface\n"));
|
---|
530 | goto l_Failure;
|
---|
531 | }
|
---|
532 | else
|
---|
533 | {
|
---|
534 | ppdev->hsurfScreen = hsurf;
|
---|
535 |
|
---|
536 | if (!EngAssociateSurface(hsurf, ppdev->hdevEng, flHooks))
|
---|
537 | {
|
---|
538 | DISPDBG((0, "DISP DrvEnableSurface failed EngAssociateSurface for Screen.\n"));
|
---|
539 | goto l_Failure;
|
---|
540 | }
|
---|
541 | else
|
---|
542 | {
|
---|
543 | ppdev->flHooks = flHooks;
|
---|
544 | ppdev->ulBitmapType = ulBitmapType;
|
---|
545 | }
|
---|
546 | }
|
---|
547 | }
|
---|
548 | }
|
---|
549 |
|
---|
550 | return ppdev->hsurfScreen;
|
---|
551 |
|
---|
552 | l_Failure:
|
---|
553 |
|
---|
554 | DrvDisableSurface(dhpdev);
|
---|
555 |
|
---|
556 | return((HSURF)0);
|
---|
557 | }
|
---|
558 |
|
---|
559 | /******************************Public*Routine******************************\
|
---|
560 | * DrvDisableSurface
|
---|
561 | *
|
---|
562 | * Free resources allocated by DrvEnableSurface. Release the surface.
|
---|
563 | *
|
---|
564 | \**************************************************************************/
|
---|
565 |
|
---|
566 | VOID DrvDisableSurface(
|
---|
567 | DHPDEV dhpdev)
|
---|
568 | {
|
---|
569 | PPDEV ppdev = (PPDEV)dhpdev;
|
---|
570 |
|
---|
571 | DISPDBG((0, "VBoxDisp::DrvDisableSurface called\n"));
|
---|
572 | if (ppdev->psoScreenBitmap)
|
---|
573 | {
|
---|
574 | EngUnlockSurface (ppdev->psoScreenBitmap);
|
---|
575 | ppdev->psoScreenBitmap = NULL;
|
---|
576 | }
|
---|
577 |
|
---|
578 | if (ppdev->hsurfScreen)
|
---|
579 | {
|
---|
580 | EngDeleteSurface(ppdev->hsurfScreen);
|
---|
581 | ppdev->hsurfScreen = (HSURF)0;
|
---|
582 | }
|
---|
583 |
|
---|
584 | if (ppdev->hsurfScreenBitmap)
|
---|
585 | {
|
---|
586 | EngDeleteSurface(ppdev->hsurfScreenBitmap);
|
---|
587 | ppdev->hsurfScreenBitmap = (HSURF)0;
|
---|
588 | }
|
---|
589 |
|
---|
590 | vDisableSURF(ppdev);
|
---|
591 | }
|
---|
592 |
|
---|
593 | /******************************Public*Routine******************************\
|
---|
594 | * DrvAssertMode
|
---|
595 | *
|
---|
596 | * This asks the device to reset itself to the mode of the pdev passed in.
|
---|
597 | *
|
---|
598 | \**************************************************************************/
|
---|
599 |
|
---|
600 | BOOL DrvAssertMode(
|
---|
601 | DHPDEV dhpdev,
|
---|
602 | BOOL bEnable)
|
---|
603 | {
|
---|
604 | PPDEV ppdev = (PPDEV) dhpdev;
|
---|
605 | ULONG ulReturn;
|
---|
606 | PBYTE pjScreen;
|
---|
607 |
|
---|
608 | DISPDBG((0, "DISP DrvAssertMode called bEnable = %d\n", bEnable));
|
---|
609 |
|
---|
610 | if (bEnable)
|
---|
611 | {
|
---|
612 | pjScreen = ppdev->pjScreen;
|
---|
613 |
|
---|
614 | if (!bInitSURF(ppdev, FALSE))
|
---|
615 | {
|
---|
616 | DISPDBG((0, "DISP DrvAssertMode failed bInitSURF\n"));
|
---|
617 | return (FALSE);
|
---|
618 | }
|
---|
619 |
|
---|
620 | if (pjScreen != ppdev->pjScreen)
|
---|
621 | {
|
---|
622 | HSURF hsurf;
|
---|
623 | SIZEL sizl;
|
---|
624 | SURFOBJ *pso;
|
---|
625 |
|
---|
626 | DISPDBG((0, "DISP DrvAssertMode Screen pointer has changed!!!\n"));
|
---|
627 |
|
---|
628 | sizl.cx = ppdev->cxScreen;
|
---|
629 | sizl.cy = ppdev->cyScreen;
|
---|
630 |
|
---|
631 | hsurf = (HSURF) EngCreateBitmap(sizl,
|
---|
632 | ppdev->lDeltaScreen,
|
---|
633 | ppdev->ulBitmapType,
|
---|
634 | (ppdev->lDeltaScreen > 0) ? BMF_TOPDOWN : 0,
|
---|
635 | (PVOID) (ppdev->pjScreen));
|
---|
636 |
|
---|
637 | if (hsurf == (HSURF) 0)
|
---|
638 | {
|
---|
639 | DISPDBG((0, "DISP DrvAssertMode failed EngCreateBitmap\n"));
|
---|
640 | return FALSE;
|
---|
641 | }
|
---|
642 |
|
---|
643 | pso = EngLockSurface(hsurf);
|
---|
644 |
|
---|
645 | if (ppdev->psoScreenBitmap)
|
---|
646 | {
|
---|
647 | EngUnlockSurface (ppdev->psoScreenBitmap);
|
---|
648 | ppdev->psoScreenBitmap = NULL;
|
---|
649 | }
|
---|
650 |
|
---|
651 | if (ppdev->hsurfScreenBitmap)
|
---|
652 | {
|
---|
653 | EngDeleteSurface(ppdev->hsurfScreenBitmap);
|
---|
654 | ppdev->hsurfScreenBitmap = (HSURF)0;
|
---|
655 | }
|
---|
656 |
|
---|
657 | ppdev->hsurfScreenBitmap = hsurf;
|
---|
658 | ppdev->psoScreenBitmap = pso;
|
---|
659 | }
|
---|
660 |
|
---|
661 | if (!EngAssociateSurface(ppdev->hsurfScreenBitmap, ppdev->hdevEng, 0))
|
---|
662 | {
|
---|
663 | DISPDBG((0, "DISP DrvAssertMode failed EngAssociateSurface for ScreenBitmap.\n"));
|
---|
664 | return FALSE;
|
---|
665 | }
|
---|
666 |
|
---|
667 | if (!EngAssociateSurface(ppdev->hsurfScreen, ppdev->hdevEng, ppdev->flHooks))
|
---|
668 | {
|
---|
669 | DISPDBG((0, "DISP DrvAssertMode failed EngAssociateSurface for Screen.\n"));
|
---|
670 | return FALSE;
|
---|
671 | }
|
---|
672 |
|
---|
673 | return TRUE;
|
---|
674 | }
|
---|
675 | else
|
---|
676 | {
|
---|
677 | //
|
---|
678 | // We must give up the display.
|
---|
679 | // Call the kernel driver to reset the device to a known state.
|
---|
680 | //
|
---|
681 |
|
---|
682 | if (EngDeviceIoControl(ppdev->hDriver,
|
---|
683 | IOCTL_VIDEO_RESET_DEVICE,
|
---|
684 | NULL,
|
---|
685 | 0,
|
---|
686 | NULL,
|
---|
687 | 0,
|
---|
688 | &ulReturn))
|
---|
689 | {
|
---|
690 | DISPDBG((0, "DISP DrvAssertMode failed IOCTL\n"));
|
---|
691 | return FALSE;
|
---|
692 | }
|
---|
693 | else
|
---|
694 | {
|
---|
695 | return TRUE;
|
---|
696 | }
|
---|
697 | }
|
---|
698 | }
|
---|
699 |
|
---|
700 | /******************************Public*Routine******************************\
|
---|
701 | * DrvGetModes
|
---|
702 | *
|
---|
703 | * Returns the list of available modes for the device.
|
---|
704 | *
|
---|
705 | \**************************************************************************/
|
---|
706 |
|
---|
707 | ULONG DrvGetModes(
|
---|
708 | HANDLE hDriver,
|
---|
709 | ULONG cjSize,
|
---|
710 | DEVMODEW *pdm)
|
---|
711 |
|
---|
712 | {
|
---|
713 |
|
---|
714 | DWORD cModes;
|
---|
715 | DWORD cbOutputSize;
|
---|
716 | PVIDEO_MODE_INFORMATION pVideoModeInformation, pVideoTemp;
|
---|
717 | DWORD cOutputModes = cjSize / (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
|
---|
718 | DWORD cbModeSize;
|
---|
719 |
|
---|
720 | DISPDBG((3, "DrvGetModes\n"));
|
---|
721 |
|
---|
722 | cModes = getAvailableModes(hDriver,
|
---|
723 | (PVIDEO_MODE_INFORMATION *) &pVideoModeInformation,
|
---|
724 | &cbModeSize);
|
---|
725 |
|
---|
726 | if (cModes == 0)
|
---|
727 | {
|
---|
728 | DISPDBG((0, "DrvGetModes failed to get mode information"));
|
---|
729 | return 0;
|
---|
730 | }
|
---|
731 |
|
---|
732 | if (pdm == NULL)
|
---|
733 | {
|
---|
734 | cbOutputSize = cModes * (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
|
---|
735 | }
|
---|
736 | else
|
---|
737 | {
|
---|
738 | //
|
---|
739 | // Now copy the information for the supported modes back into the output
|
---|
740 | // buffer
|
---|
741 | //
|
---|
742 |
|
---|
743 | cbOutputSize = 0;
|
---|
744 |
|
---|
745 | pVideoTemp = pVideoModeInformation;
|
---|
746 |
|
---|
747 | do
|
---|
748 | {
|
---|
749 | if (pVideoTemp->Length != 0)
|
---|
750 | {
|
---|
751 | if (cOutputModes == 0)
|
---|
752 | {
|
---|
753 | break;
|
---|
754 | }
|
---|
755 |
|
---|
756 | //
|
---|
757 | // Zero the entire structure to start off with.
|
---|
758 | //
|
---|
759 |
|
---|
760 | memset(pdm, 0, sizeof(DEVMODEW));
|
---|
761 |
|
---|
762 | //
|
---|
763 | // Set the name of the device to the name of the DLL.
|
---|
764 | //
|
---|
765 |
|
---|
766 | memcpy(pdm->dmDeviceName, DLL_NAME, sizeof(DLL_NAME));
|
---|
767 |
|
---|
768 | pdm->dmSpecVersion = DM_SPECVERSION;
|
---|
769 | pdm->dmDriverVersion = DM_SPECVERSION;
|
---|
770 | pdm->dmSize = sizeof(DEVMODEW);
|
---|
771 | pdm->dmDriverExtra = DRIVER_EXTRA_SIZE;
|
---|
772 |
|
---|
773 | pdm->dmBitsPerPel = pVideoTemp->NumberOfPlanes *
|
---|
774 | pVideoTemp->BitsPerPlane;
|
---|
775 | pdm->dmPelsWidth = pVideoTemp->VisScreenWidth;
|
---|
776 | pdm->dmPelsHeight = pVideoTemp->VisScreenHeight;
|
---|
777 | pdm->dmDisplayFrequency = pVideoTemp->Frequency;
|
---|
778 | pdm->dmDisplayFlags = 0;
|
---|
779 |
|
---|
780 | pdm->dmFields = DM_BITSPERPEL |
|
---|
781 | DM_PELSWIDTH |
|
---|
782 | DM_PELSHEIGHT |
|
---|
783 | DM_DISPLAYFREQUENCY |
|
---|
784 | DM_DISPLAYFLAGS ;
|
---|
785 |
|
---|
786 | //
|
---|
787 | // Go to the next DEVMODE entry in the buffer.
|
---|
788 | //
|
---|
789 |
|
---|
790 | cOutputModes--;
|
---|
791 |
|
---|
792 | pdm = (LPDEVMODEW) ( ((ULONG_PTR)pdm) + sizeof(DEVMODEW)
|
---|
793 | + DRIVER_EXTRA_SIZE);
|
---|
794 |
|
---|
795 | cbOutputSize += (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
|
---|
796 |
|
---|
797 | }
|
---|
798 |
|
---|
799 | pVideoTemp = (PVIDEO_MODE_INFORMATION)
|
---|
800 | (((PUCHAR)pVideoTemp) + cbModeSize);
|
---|
801 |
|
---|
802 | } while (--cModes);
|
---|
803 | }
|
---|
804 |
|
---|
805 | EngFreeMem(pVideoModeInformation);
|
---|
806 |
|
---|
807 | return cbOutputSize;
|
---|
808 |
|
---|
809 | }
|
---|
810 |
|
---|
811 | VOID DrvSynchronize(
|
---|
812 | IN DHPDEV dhpdev,
|
---|
813 | IN RECTL *prcl)
|
---|
814 | {
|
---|
815 | }
|
---|
816 |
|
---|
817 | /******************************Public*Routine******************************\
|
---|
818 | * DrvNotify
|
---|
819 | *
|
---|
820 | * Called by GDI to notify us of certain "interesting" events
|
---|
821 | *
|
---|
822 | * DN_DEVICE_ORIGIN is used to communicate the X/Y offsets of individual monitors
|
---|
823 | * when DualView is in effect.
|
---|
824 | *
|
---|
825 | \**************************************************************************/
|
---|
826 |
|
---|
827 | VOID DrvNotify(
|
---|
828 | SURFOBJ *pso,
|
---|
829 | ULONG iType,
|
---|
830 | PVOID pvData)
|
---|
831 | {
|
---|
832 | PDEV* ppdev = (PDEV*) pso->dhpdev;
|
---|
833 |
|
---|
834 | DISPDBG((0, "VBoxDisp::DrvNotify called.\n"));
|
---|
835 |
|
---|
836 | switch(iType)
|
---|
837 | {
|
---|
838 | case DN_DEVICE_ORIGIN:
|
---|
839 | ppdev->ptlDevOrg = *(PPOINTL)pvData;
|
---|
840 | DISPDBG((3, "DN_DEVICE_ORIGIN: %d, %d (PSO = %p, pInfo = %p)\n", ppdev->ptlDevOrg.x,
|
---|
841 | ppdev->ptlDevOrg.y, pso, ppdev->pInfo));
|
---|
842 | if (ppdev->pInfo)
|
---|
843 | {
|
---|
844 | ppdev->pInfo->screen.xOrigin = ppdev->ptlDevOrg.x;
|
---|
845 | ppdev->pInfo->screen.yOrigin = ppdev->ptlDevOrg.y;
|
---|
846 | VBoxProcessDisplayInfo(ppdev);
|
---|
847 | }
|
---|
848 | break;
|
---|
849 | case DN_DRAWING_BEGIN:
|
---|
850 | DISPDBG((3, "DN_DRAWING_BEGIN (PSO = %p)\n", pso));
|
---|
851 | break;
|
---|
852 | }
|
---|
853 | }
|
---|