VirtualBox

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

Last change on this file since 34796 was 34665, checked in by vboxsync, 14 years ago

Additions/common/VBoxVideo and Additions/WINNT/Graphics: some adjustments to the common VBoxVideo code

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