VirtualBox

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

Last change on this file since 16605 was 16605, checked in by vboxsync, 16 years ago

header updates

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