VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Display/enable.c@ 4280

Last change on this file since 4280 was 4280, checked in by vboxsync, 17 years ago

More logging

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette