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