VirtualBox

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

Last change on this file since 36679 was 36670, checked in by vboxsync, 14 years ago

VBoxVideo: fix memory leak in seamless mode

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