VirtualBox

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

Last change on this file since 32577 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

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