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 | #define DBG 1
|
---|
28 |
|
---|
29 | #include "driver.h"
|
---|
30 |
|
---|
31 | // The driver function table with all function index/address pairs
|
---|
32 |
|
---|
33 | static DRVFN gadrvfn[] =
|
---|
34 | {
|
---|
35 | { INDEX_DrvEnablePDEV, (PFN) DrvEnablePDEV },
|
---|
36 | { INDEX_DrvCompletePDEV, (PFN) DrvCompletePDEV },
|
---|
37 | { INDEX_DrvDisablePDEV, (PFN) DrvDisablePDEV },
|
---|
38 | { INDEX_DrvEnableSurface, (PFN) DrvEnableSurface },
|
---|
39 | { INDEX_DrvDisableSurface, (PFN) DrvDisableSurface },
|
---|
40 | { INDEX_DrvAssertMode, (PFN) DrvAssertMode },
|
---|
41 | { INDEX_DrvTextOut, (PFN) DrvTextOut },
|
---|
42 | { INDEX_DrvBitBlt, (PFN) DrvBitBlt },
|
---|
43 | { INDEX_DrvCopyBits, (PFN) DrvCopyBits },
|
---|
44 | { INDEX_DrvStrokePath, (PFN) DrvStrokePath },
|
---|
45 | };
|
---|
46 |
|
---|
47 | //
|
---|
48 | // always hook these routines to ensure the mirrored driver
|
---|
49 | // is called for our surfaces
|
---|
50 | //
|
---|
51 |
|
---|
52 | #define flGlobalHooks HOOK_BITBLT|HOOK_TEXTOUT|HOOK_COPYBITS|HOOK_STROKEPATH
|
---|
53 |
|
---|
54 | // Define the functions you want to hook for 8/16/24/32 pel formats
|
---|
55 |
|
---|
56 | #define HOOKS_BMF8BPP 0
|
---|
57 |
|
---|
58 | #define HOOKS_BMF16BPP 0
|
---|
59 |
|
---|
60 | #define HOOKS_BMF24BPP 0
|
---|
61 |
|
---|
62 | #define HOOKS_BMF32BPP 0
|
---|
63 |
|
---|
64 | /******************************Public*Routine******************************\
|
---|
65 | * DrvEnableDriver
|
---|
66 | *
|
---|
67 | * Enables the driver by retrieving the drivers function table and version.
|
---|
68 | *
|
---|
69 | \**************************************************************************/
|
---|
70 |
|
---|
71 | BOOL DrvEnableDriver(
|
---|
72 | ULONG iEngineVersion,
|
---|
73 | ULONG cj,
|
---|
74 | PDRVENABLEDATA pded)
|
---|
75 | {
|
---|
76 | // Engine Version is passed down so future drivers can support previous
|
---|
77 | // engine versions. A next generation driver can support both the old
|
---|
78 | // and new engine conventions if told what version of engine it is
|
---|
79 | // working with. For the first version the driver does nothing with it.
|
---|
80 |
|
---|
81 | iEngineVersion;
|
---|
82 |
|
---|
83 | DISPDBG((0,"DrvEnableDriver: mirror\n"));
|
---|
84 |
|
---|
85 | // Fill in as much as we can.
|
---|
86 |
|
---|
87 | if (cj >= sizeof(DRVENABLEDATA))
|
---|
88 | pded->pdrvfn = gadrvfn;
|
---|
89 |
|
---|
90 | if (cj >= (sizeof(ULONG) * 2))
|
---|
91 | pded->c = sizeof(gadrvfn) / sizeof(DRVFN);
|
---|
92 |
|
---|
93 | // DDI version this driver was targeted for is passed back to engine.
|
---|
94 | // Future graphic's engine may break calls down to old driver format.
|
---|
95 |
|
---|
96 | if (cj >= sizeof(ULONG))
|
---|
97 | // DDI_DRIVER_VERSION is now out-dated. See winddi.h
|
---|
98 | // DDI_DRIVER_VERSION_NT4 is equivalent to the old DDI_DRIVER_VERSION
|
---|
99 | pded->iDriverVersion = DDI_DRIVER_VERSION_NT4;
|
---|
100 |
|
---|
101 | return(TRUE);
|
---|
102 | }
|
---|
103 |
|
---|
104 | /******************************Public*Routine******************************\
|
---|
105 | * DrvEnablePDEV
|
---|
106 | *
|
---|
107 | * DDI function, Enables the Physical Device.
|
---|
108 | *
|
---|
109 | * Return Value: device handle to pdev.
|
---|
110 | *
|
---|
111 | \**************************************************************************/
|
---|
112 |
|
---|
113 | DHPDEV DrvEnablePDEV(
|
---|
114 | DEVMODEW *pDevmode, // Pointer to DEVMODE
|
---|
115 | PWSTR pwszLogAddress, // Logical address
|
---|
116 | ULONG cPatterns, // number of patterns
|
---|
117 | HSURF *ahsurfPatterns, // return standard patterns
|
---|
118 | ULONG cjGdiInfo, // Length of memory pointed to by pGdiInfo
|
---|
119 | ULONG *pGdiInfo, // Pointer to GdiInfo structure
|
---|
120 | ULONG cjDevInfo, // Length of following PDEVINFO structure
|
---|
121 | DEVINFO *pDevInfo, // physical device information structure
|
---|
122 | HDEV hdev, // HDEV, used for callbacks
|
---|
123 | PWSTR pwszDeviceName, // DeviceName - not used
|
---|
124 | HANDLE hDriver) // Handle to base driver
|
---|
125 | {
|
---|
126 | GDIINFO GdiInfo;
|
---|
127 | DEVINFO DevInfo;
|
---|
128 | PPDEV ppdev = (PPDEV) NULL;
|
---|
129 |
|
---|
130 | DISPDBG((0,"DrvEnablePDEV\n"));
|
---|
131 |
|
---|
132 | UNREFERENCED_PARAMETER(pwszLogAddress);
|
---|
133 | UNREFERENCED_PARAMETER(pwszDeviceName);
|
---|
134 |
|
---|
135 | // Allocate a physical device structure.
|
---|
136 |
|
---|
137 | ppdev = (PPDEV) EngAllocMem(0, sizeof(PDEV), ALLOC_TAG);
|
---|
138 |
|
---|
139 | if (ppdev == (PPDEV) NULL)
|
---|
140 | {
|
---|
141 | RIP("DISP DrvEnablePDEV failed EngAllocMem\n");
|
---|
142 | return((DHPDEV) 0);
|
---|
143 | }
|
---|
144 |
|
---|
145 | memset(ppdev, 0, sizeof(PDEV));
|
---|
146 |
|
---|
147 | // Save the screen handle in the PDEV.
|
---|
148 |
|
---|
149 | ppdev->hDriver = hDriver;
|
---|
150 |
|
---|
151 | // Get the current screen mode information. Set up device caps and devinfo.
|
---|
152 |
|
---|
153 | if (!bInitPDEV(ppdev, pDevmode, &GdiInfo, &DevInfo))
|
---|
154 | {
|
---|
155 | DISPDBG((0,"DISP DrvEnablePDEV failed\n"));
|
---|
156 | goto error_free;
|
---|
157 | }
|
---|
158 |
|
---|
159 | // Copy the devinfo into the engine buffer.
|
---|
160 |
|
---|
161 | memcpy(pDevInfo, &DevInfo, min(sizeof(DEVINFO), cjDevInfo));
|
---|
162 |
|
---|
163 | // Set the pdevCaps with GdiInfo we have prepared to the list of caps for this
|
---|
164 | // pdev.
|
---|
165 |
|
---|
166 | memcpy(pGdiInfo, &GdiInfo, min(cjGdiInfo, sizeof(GDIINFO)));
|
---|
167 |
|
---|
168 | //
|
---|
169 | DISPDBG((0,"DrvEnablePDEV OK\n"));
|
---|
170 | return((DHPDEV) ppdev);
|
---|
171 |
|
---|
172 | // Error case for failure.
|
---|
173 | error_free:
|
---|
174 | EngFreeMem(ppdev);
|
---|
175 | DISPDBG((0,"DrvEnablePDEV FAIL!!!\n"));
|
---|
176 | return((DHPDEV) 0);
|
---|
177 | }
|
---|
178 |
|
---|
179 | /******************************Public*Routine******************************\
|
---|
180 | * DrvCompletePDEV
|
---|
181 | *
|
---|
182 | * Store the HPDEV, the engines handle for this PDEV, in the DHPDEV.
|
---|
183 | *
|
---|
184 | \**************************************************************************/
|
---|
185 |
|
---|
186 | VOID DrvCompletePDEV(
|
---|
187 | DHPDEV dhpdev,
|
---|
188 | HDEV hdev)
|
---|
189 | {
|
---|
190 | DISPDBG((0,"DrvCompletePDEV\n"));
|
---|
191 | ((PPDEV) dhpdev)->hdevEng = hdev;
|
---|
192 | DISPDBG((0,"DrvCompletePDEV OK\n"));
|
---|
193 | }
|
---|
194 |
|
---|
195 | /******************************Public*Routine******************************\
|
---|
196 | * DrvDisablePDEV
|
---|
197 | *
|
---|
198 | * Release the resources allocated in DrvEnablePDEV. If a surface has been
|
---|
199 | * enabled DrvDisableSurface will have already been called.
|
---|
200 | *
|
---|
201 | \**************************************************************************/
|
---|
202 |
|
---|
203 | VOID DrvDisablePDEV(
|
---|
204 | DHPDEV dhpdev)
|
---|
205 | {
|
---|
206 | PPDEV ppdev = (PPDEV) dhpdev;
|
---|
207 | DISPDBG((0,"DrvDisablePDEV\n"));
|
---|
208 |
|
---|
209 | EngDeletePalette(ppdev->hpalDefault);
|
---|
210 |
|
---|
211 | EngFreeMem(dhpdev);
|
---|
212 | }
|
---|
213 |
|
---|
214 | /******************************Public*Routine******************************\
|
---|
215 | * DrvEnableSurface
|
---|
216 | *
|
---|
217 | * Enable the surface for the device. Hook the calls this driver supports.
|
---|
218 | *
|
---|
219 | * Return: Handle to the surface if successful, 0 for failure.
|
---|
220 | *
|
---|
221 | \**************************************************************************/
|
---|
222 |
|
---|
223 | HSURF DrvEnableSurface(
|
---|
224 | DHPDEV dhpdev)
|
---|
225 | {
|
---|
226 | PPDEV ppdev;
|
---|
227 | HSURF hsurf;
|
---|
228 | SIZEL sizl;
|
---|
229 | ULONG ulBitmapType;
|
---|
230 | FLONG flHooks;
|
---|
231 | ULONG mirrorsize;
|
---|
232 | MIRRSURF *mirrsurf;
|
---|
233 | DHSURF dhsurf;
|
---|
234 |
|
---|
235 | // Create engine bitmap around frame buffer.
|
---|
236 |
|
---|
237 | DISPDBG((0,"DrvEnableSurface:\n"));
|
---|
238 |
|
---|
239 | ppdev = (PPDEV) dhpdev;
|
---|
240 |
|
---|
241 | ppdev->ptlOrg.x = 0;
|
---|
242 | ppdev->ptlOrg.y = 0;
|
---|
243 |
|
---|
244 | sizl.cx = ppdev->cxScreen;
|
---|
245 | sizl.cy = ppdev->cyScreen;
|
---|
246 |
|
---|
247 | if (ppdev->ulBitCount == 16)
|
---|
248 | {
|
---|
249 | ulBitmapType = BMF_16BPP;
|
---|
250 | flHooks = HOOKS_BMF16BPP;
|
---|
251 | }
|
---|
252 | else if (ppdev->ulBitCount == 24)
|
---|
253 | {
|
---|
254 | ulBitmapType = BMF_24BPP;
|
---|
255 | flHooks = HOOKS_BMF24BPP;
|
---|
256 | }
|
---|
257 | else
|
---|
258 | {
|
---|
259 | ulBitmapType = BMF_32BPP;
|
---|
260 | flHooks = HOOKS_BMF32BPP;
|
---|
261 | }
|
---|
262 |
|
---|
263 | flHooks |= flGlobalHooks;
|
---|
264 |
|
---|
265 | mirrorsize = (ULONG)(sizeof(MIRRSURF) +
|
---|
266 | ppdev->lDeltaScreen * sizl.cy);
|
---|
267 |
|
---|
268 | mirrsurf = (MIRRSURF *) EngAllocMem(FL_ZERO_MEMORY,
|
---|
269 | mirrorsize,
|
---|
270 | 0x4D495252);
|
---|
271 | if (!mirrsurf) {
|
---|
272 | RIP("DISP DrvEnableSurface failed EngAllocMem\n");
|
---|
273 | return(FALSE);
|
---|
274 | }
|
---|
275 |
|
---|
276 |
|
---|
277 | dhsurf = (DHSURF) mirrsurf;
|
---|
278 |
|
---|
279 | // dhsurf = (DHSURF) ppdev;
|
---|
280 |
|
---|
281 | hsurf = EngCreateDeviceSurface(dhsurf,
|
---|
282 | sizl,
|
---|
283 | ulBitmapType);
|
---|
284 |
|
---|
285 | if (hsurf == (HSURF) 0)
|
---|
286 | {
|
---|
287 | RIP("DISP DrvEnableSurface failed EngCreateBitmap\n");
|
---|
288 | return(FALSE);
|
---|
289 | }
|
---|
290 |
|
---|
291 | if (!EngAssociateSurface(hsurf, ppdev->hdevEng, flHooks))
|
---|
292 | {
|
---|
293 | RIP("DISP DrvEnableSurface failed EngAssociateSurface\n");
|
---|
294 | EngDeleteSurface(hsurf);
|
---|
295 | return(FALSE);
|
---|
296 | }
|
---|
297 |
|
---|
298 | ppdev->hsurfEng = (HSURF) hsurf;
|
---|
299 | ppdev->pvTmpBuffer = (PVOID) dhsurf;
|
---|
300 |
|
---|
301 | mirrsurf->cx = ppdev->cxScreen;
|
---|
302 | mirrsurf->cy = ppdev->cyScreen;
|
---|
303 | mirrsurf->lDelta = ppdev->lDeltaScreen;
|
---|
304 | mirrsurf->ulBitCount = ppdev->ulBitCount;
|
---|
305 | mirrsurf->bIsScreen = TRUE;
|
---|
306 |
|
---|
307 | DISPDBG((0,"DrvEnableSurface OK\n"));
|
---|
308 |
|
---|
309 | return(hsurf);
|
---|
310 | }
|
---|
311 |
|
---|
312 | /******************************Public*Routine******************************\
|
---|
313 | * DrvDisableSurface
|
---|
314 | *
|
---|
315 | * Free resources allocated by DrvEnableSurface. Release the surface.
|
---|
316 | *
|
---|
317 | \**************************************************************************/
|
---|
318 |
|
---|
319 | VOID DrvDisableSurface(
|
---|
320 | DHPDEV dhpdev)
|
---|
321 | {
|
---|
322 | PPDEV ppdev = (PPDEV) dhpdev;
|
---|
323 |
|
---|
324 | DISPDBG((0,"DrvDisableSurface:\n"));
|
---|
325 |
|
---|
326 | EngDeleteSurface( ppdev->hsurfEng );
|
---|
327 |
|
---|
328 | // deallocate MIRRSURF structure.
|
---|
329 |
|
---|
330 | EngFreeMem( ppdev->pvTmpBuffer );
|
---|
331 | }
|
---|
332 |
|
---|
333 | /******************************Public*Routine******************************\
|
---|
334 | * DrvCopyBits
|
---|
335 | *
|
---|
336 | \**************************************************************************/
|
---|
337 |
|
---|
338 | BOOL DrvCopyBits(
|
---|
339 | OUT SURFOBJ *psoDst,
|
---|
340 | IN SURFOBJ *psoSrc,
|
---|
341 | IN CLIPOBJ *pco,
|
---|
342 | IN XLATEOBJ *pxlo,
|
---|
343 | IN RECTL *prclDst,
|
---|
344 | IN POINTL *pptlSrc
|
---|
345 | )
|
---|
346 | {
|
---|
347 | DISPDBG((0,"DrvCopyBits\n"));
|
---|
348 | return TRUE;
|
---|
349 | }
|
---|
350 |
|
---|
351 | /******************************Public*Routine******************************\
|
---|
352 | * DrvBitBlt
|
---|
353 | *
|
---|
354 | \**************************************************************************/
|
---|
355 |
|
---|
356 | BOOL DrvBitBlt(
|
---|
357 | IN SURFOBJ *psoDst,
|
---|
358 | IN SURFOBJ *psoSrc,
|
---|
359 | IN SURFOBJ *psoMask,
|
---|
360 | IN CLIPOBJ *pco,
|
---|
361 | IN XLATEOBJ *pxlo,
|
---|
362 | IN RECTL *prclDst,
|
---|
363 | IN POINTL *pptlSrc,
|
---|
364 | IN POINTL *pptlMask,
|
---|
365 | IN BRUSHOBJ *pbo,
|
---|
366 | IN POINTL *pptlBrush,
|
---|
367 | IN ROP4 rop4
|
---|
368 | )
|
---|
369 | {
|
---|
370 | DISPDBG((0,"DrvBitBlt\n"));
|
---|
371 | return TRUE;
|
---|
372 | }
|
---|
373 |
|
---|
374 | BOOL DrvTextOut(
|
---|
375 | IN SURFOBJ *psoDst,
|
---|
376 | IN STROBJ *pstro,
|
---|
377 | IN FONTOBJ *pfo,
|
---|
378 | IN CLIPOBJ *pco,
|
---|
379 | IN RECTL *prclExtra,
|
---|
380 | IN RECTL *prclOpaque,
|
---|
381 | IN BRUSHOBJ *pboFore,
|
---|
382 | IN BRUSHOBJ *pboOpaque,
|
---|
383 | IN POINTL *pptlOrg,
|
---|
384 | IN MIX mix
|
---|
385 | )
|
---|
386 | {
|
---|
387 | DISPDBG((0,"DrvTextOut\n"));
|
---|
388 | return TRUE;
|
---|
389 | }
|
---|
390 |
|
---|
391 | BOOL
|
---|
392 | DrvStrokePath(SURFOBJ* pso,
|
---|
393 | PATHOBJ* ppo,
|
---|
394 | CLIPOBJ* pco,
|
---|
395 | XFORMOBJ* pxo,
|
---|
396 | BRUSHOBJ* pbo,
|
---|
397 | POINTL* pptlBrush,
|
---|
398 | LINEATTRS* pLineAttrs,
|
---|
399 | MIX mix)
|
---|
400 | {
|
---|
401 | DISPDBG((0,"DrvStrokePath\n"));
|
---|
402 | return TRUE;
|
---|
403 | }
|
---|
404 |
|
---|
405 | BOOL DrvAssertMode(DHPDEV dhpdev,
|
---|
406 | BOOL bEnable)
|
---|
407 | {
|
---|
408 | DISPDBG((0,"DrvAssertMode\n"));
|
---|
409 | return TRUE;
|
---|
410 | }
|
---|