VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Display/dd.c@ 4346

Last change on this file since 4346 was 4346, checked in by vboxsync, 18 years ago

logging updates

File size: 28.7 KB
Line 
1#define LOG_ENABLED
2
3#ifdef VBOX_WITH_DDRAW
4
5/******************************Module*Header**********************************\
6*
7* **************************
8* * DirectDraw SAMPLE CODE *
9* **************************
10*
11* Module Name: ddenable.c
12*
13* Content:
14*
15* Copyright (c) 1994-1998 3Dlabs Inc. Ltd. All rights reserved.
16* Copyright (c) 1995-1999 Microsoft Corporation. All rights reserved.
17\*****************************************************************************/
18
19#include "driver.h"
20#include "dd.h"
21#undef CO_E_NOTINITIALIZED
22#include <winerror.h>
23
24
25#if 0
26static DWORD APIENTRY DdCreateSurface(PDD_CREATESURFACEDATA lpCreateSurface);
27#endif
28
29
30/**
31 * DrvGetDirectDrawInfo
32 *
33 * The DrvGetDirectDrawInfo function returns the capabilities of the graphics hardware.
34 *
35 * Parameters:
36 *
37 * dhpdev
38 * Handle to the PDEV returned by the driver’s DrvEnablePDEV routine.
39 * pHalInfo
40 * Points to a DD_HALINFO structure in which the driver should return the hardware capabilities that it supports.
41 * pdwNumHeaps
42 * Points to the location in which the driver should return the number of VIDEOMEMORY structures pointed to by pvmList.
43 * pvmList
44 * Points to an array of VIDEOMEMORY structures in which the driver should return information about each display memory chunk that it controls. The driver should ignore this parameter when it is NULL.
45 * pdwNumFourCCCodes
46 * Points to the location in which the driver should return the number of DWORDs pointed to by pdwFourCC.
47 * pdwFourCC
48 * Points to an array of DWORDs in which the driver should return information about each FOURCC that it supports. The driver should ignore this parameter when it is NULL.
49 *
50 * Return Value:
51 *
52 * DrvGetDirectDrawInfo returns TRUE if it succeeds; otherwise, it returns FALSE.
53 *
54 */
55BOOL APIENTRY DrvGetDirectDrawInfo(
56 DHPDEV dhpdev,
57 DD_HALINFO *pHalInfo,
58 DWORD *pdwNumHeaps,
59 VIDEOMEMORY *pvmList,
60 DWORD *pdwNumFourCCCodes,
61 DWORD *pdwFourCC
62 )
63{
64 PPDEV pDev = (PPDEV)dhpdev;
65 BOOL bDefineDDrawHeap = FALSE;
66 DWORD cHeaps = 0;
67 VIDEOMEMORY *pVm = NULL;
68
69 DISPDBG((0, "%s: %p, %p, %p, %p, %p. %p\n", __FUNCTION__, dhpdev, pHalInfo, pdwNumHeaps, pvmList, pdwNumFourCCCodes, pdwFourCC));
70
71 *pdwNumFourCCCodes = 0;
72 *pdwNumHeaps = 0;
73
74 /* Setup the HAL driver caps. */
75 pHalInfo->dwSize = sizeof(DD_HALINFO);
76 pHalInfo->dwFlags = 0;
77
78 if (!(pvmList && pdwFourCC))
79 {
80 memset(&pHalInfo->ddCaps, 0, sizeof(DDNTCORECAPS));
81 pHalInfo->ddCaps.dwSize = sizeof(DDNTCORECAPS);
82 pHalInfo->ddCaps.dwVidMemTotal = pDev->layout.cbDDRAWHeap;
83 pHalInfo->ddCaps.dwVidMemFree = pHalInfo->ddCaps.dwVidMemTotal;
84
85 pHalInfo->ddCaps.dwCaps = 0;
86 pHalInfo->ddCaps.dwCaps2 = 0;
87
88 /* Declare we can handle textures wider than the primary */
89 pHalInfo->ddCaps.dwCaps2 |= DDCAPS2_WIDESURFACES;
90
91 pHalInfo->ddCaps.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
92
93 /* Create primary surface attributes */
94 pHalInfo->vmiData.pvPrimary = pDev->pjScreen;
95 pHalInfo->vmiData.fpPrimary = 0;
96 pHalInfo->vmiData.dwDisplayWidth = pDev->cxScreen;
97 pHalInfo->vmiData.dwDisplayHeight = pDev->cyScreen;
98 pHalInfo->vmiData.lDisplayPitch = pDev->lDeltaScreen;
99
100 pHalInfo->vmiData.ddpfDisplay.dwSize = sizeof(DDPIXELFORMAT);
101 pHalInfo->vmiData.ddpfDisplay.dwFlags = DDPF_RGB;
102 pHalInfo->vmiData.ddpfDisplay.dwRGBBitCount = pDev->ulBitCount;
103 DISPDBG((0, "pvPrimary %x\n", pHalInfo->vmiData.pvPrimary));
104 DISPDBG((0, "fpPrimary %x\n", pHalInfo->vmiData.fpPrimary));
105 DISPDBG((0, "dwDisplayWidth %d\n", pHalInfo->vmiData.dwDisplayWidth));
106 DISPDBG((0, "dwDisplayHeight %d\n", pHalInfo->vmiData.dwDisplayHeight));
107 DISPDBG((0, "lDisplayPitch %d\n", pHalInfo->vmiData.lDisplayPitch));
108 DISPDBG((0, "dwRGBBitCount %d\n", pHalInfo->vmiData.ddpfDisplay.dwRGBBitCount));
109
110 if (pDev->ulBitmapType == BMF_8BPP)
111 {
112 pHalInfo->vmiData.ddpfDisplay.dwFlags |= DDPF_PALETTEINDEXED8;
113 DISPDBG((0, "DDPF_PALETTEINDEXED8\n"));
114 }
115
116 pHalInfo->vmiData.ddpfDisplay.dwRBitMask = pDev->flRed;
117 pHalInfo->vmiData.ddpfDisplay.dwGBitMask = pDev->flGreen;
118 pHalInfo->vmiData.ddpfDisplay.dwBBitMask = pDev->flBlue;
119
120 pHalInfo->vmiData.dwOffscreenAlign = 4;
121 pHalInfo->vmiData.dwZBufferAlign = 4;
122 pHalInfo->vmiData.dwTextureAlign = 4;
123 }
124
125 cHeaps = 0;
126
127 /* Do we have sufficient videomemory to create an off-screen heap for DDraw? */
128 if (pDev->layout.cbDDRAWHeap > 0)
129 {
130 bDefineDDrawHeap = TRUE;
131 cHeaps++;
132 }
133
134 pDev->cHeaps = cHeaps;
135 *pdwNumHeaps = cHeaps;
136
137 // If pvmList is not NULL then we can go ahead and fill out the VIDEOMEMORY
138 // structures which define our requested heaps.
139
140 if(pvmList) {
141
142 pVm=pvmList;
143
144 //
145 // Snag a pointer to the video-memory list so that we can use it to
146 // call back to DirectDraw to allocate video memory:
147 //
148 pDev->pvmList = pVm;
149
150 //
151 // Define the heap for DirectDraw
152 //
153 if ( bDefineDDrawHeap )
154 {
155 pVm->dwFlags = VIDMEM_ISLINEAR ;
156 pVm->fpStart = pDev->layout.offDDRAWHeap;
157 pVm->fpEnd = pDev->layout.offDDRAWHeap + pDev->layout.cbDDRAWHeap - 1; /* inclusive */
158
159 pVm->ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
160 DISPDBG((0, "fpStart %x fpEnd %x\n", pVm->fpStart, pVm->fpEnd));
161
162 pVm++;
163 }
164 }
165
166#if 0 /* not mandatory */
167 /* DX5 and up */
168 pHalInfo->GetDriverInfo = DdGetDriverInfo;
169 pHalInfo->dwFlags |= DDHALINFO_GETDRIVERINFOSET;
170#endif
171
172#if 0
173 /* No 3D capabilities */
174 if (pHalInfo->lpD3DGlobalDriverData)
175 {
176 LPD3DHAL_GLOBALDRIVERDATA lpD3DGlobalDriverData = (LPD3DHAL_GLOBALDRIVERDATA)pHalInfo->lpD3DGlobalDriverData;
177 lpD3DGlobalDriverData->dwSize = sizeof(D3DHAL_GLOBALDRIVERDATA);
178 }
179#endif
180 return TRUE;
181}
182
183/**
184 * DrvEnableDirectDraw
185 *
186 * The DrvEnableDirectDraw function enables hardware for DirectDraw use.
187 *
188 * Parameters
189 *
190 * dhpdev
191 * Handle to the PDEV returned by the driver’s DrvEnablePDEV routine.
192 * pCallBacks
193 * Points to the DD_CALLBACKS structure to be initialized by the driver.
194 * pSurfaceCallBacks
195 * Points to the DD_SURFACECALLBACKS structure to be initialized by the driver.
196 * pPaletteCallBacks
197 * Points to the DD_PALETTECALLBACKS structure to be initialized by the driver.
198 *
199 * Return Value
200 *
201 * DrvEnableDirectDraw returns TRUE if it succeeds; otherwise, it returns FALSE.
202 *
203 */
204BOOL APIENTRY DrvEnableDirectDraw(
205 DHPDEV dhpdev,
206 DD_CALLBACKS *pCallBacks,
207 DD_SURFACECALLBACKS *pSurfaceCallBacks,
208 DD_PALETTECALLBACKS *pPaletteCallBacks
209 )
210{
211 DISPDBG((0, "%s: %p, %p, %p, %p\n", __FUNCTION__, dhpdev, pCallBacks, pSurfaceCallBacks, pPaletteCallBacks));
212
213 /* Fill in the HAL Callback pointers */
214 pCallBacks->dwSize = sizeof(DD_CALLBACKS);
215 pCallBacks->dwFlags = 0;
216
217 pCallBacks->dwFlags = DDHAL_CB32_CREATESURFACE | DDHAL_CB32_CANCREATESURFACE | DDHAL_CB32_MAPMEMORY;
218 pCallBacks->CreateSurface = DdCreateSurface;
219 pCallBacks->CanCreateSurface = DdCanCreateSurface;
220 pCallBacks->MapMemory = DdMapMemory;
221 // pCallBacks->WaitForVerticalBlank = DdWaitForVerticalBlank;
222 // pCallBacks->GetScanLine = DdGetScanLine;
223 // DDHAL_CB32_WAITFORVERTICALBLANK | DDHAL_CB32_GETSCANLINE
224 /* Note: pCallBacks->SetMode & pCallBacks->DestroyDriver are unused in Windows 2000 and up */
225
226 /* Fill in the Surface Callback pointers */
227 pSurfaceCallBacks->dwSize = sizeof(DD_SURFACECALLBACKS);
228 pSurfaceCallBacks->dwFlags = DDHAL_SURFCB32_LOCK | DDHAL_SURFCB32_UNLOCK;
229 pSurfaceCallBacks->Lock = DdLock;
230 pSurfaceCallBacks->Unlock = DdUnlock;
231
232 /*
233 pSurfaceCallBacks->dwFlags = DDHAL_SURFCB32_DESTROYSURFACE | DDHAL_SURFCB32_LOCK; // DDHAL_SURFCB32_UNLOCK;
234 pSurfaceCallBacks->DestroySurface = DdDestroySurface;
235 pSurfaceCallBacks->Flip = DdFlip;
236 pSurfaceCallBacks->GetBltStatus = DdGetBltStatus;
237 pSurfaceCallBacks->GetFlipStatus = DdGetFlipStatus;
238 pSurfaceCallBacks->Blt = DdBlt;
239 DDHAL_SURFCB32_FLIP | DDHAL_SURFCB32_BLT | DDHAL_SURFCB32_GETBLTSTATUS | DDHAL_SURFCB32_GETFLIPSTATUS;
240 */
241
242// pSurfaceCallBacks.SetColorKey = DdSetColorKey;
243// pSurfaceCallBacks.dwFlags |= DDHAL_SURFCB32_SETCOLORKEY;
244
245 /* Fill in the Palette Callback pointers */
246 pPaletteCallBacks->dwSize = sizeof(DD_PALETTECALLBACKS);
247 pPaletteCallBacks->dwFlags = 0;
248
249 return TRUE;
250}
251
252/**
253 * DrvDisableDirectDraw
254 *
255 * The DrvDisableDirectDraw function disables hardware for DirectDraw use.
256 *
257 * Parameters
258 *
259 * dhpdev
260 * Handle to the PDEV returned by the driver’s DrvEnablePDEV routine.
261 *
262 */
263VOID APIENTRY DrvDisableDirectDraw( DHPDEV dhpdev)
264{
265 DISPDBG((0, "%s: %p\n", __FUNCTION__, dhpdev));
266}
267
268/**
269 * DdGetDriverInfo
270 *
271 * The DdGetDriverInfo function queries the driver for additional DirectDraw and Direct3D functionality that the driver supports.
272 *
273 * Parameters
274 * lpGetDriverInfo
275 * Points to a DD_GETDRIVERINFODATA structure that contains the information required to perform the query.
276 *
277 * Return Value
278 *
279 * DdGetDriverInfo must return DDHAL_DRIVER_HANDLED.
280 *
281 */
282DWORD CALLBACK DdGetDriverInfo(DD_GETDRIVERINFODATA *lpData)
283{
284 PPDEV pDev = (PPDEV)lpData->dhpdev;
285 DWORD dwSize;
286
287 DISPDBG((0, "%s: %p\n", __FUNCTION__, lpData->dhpdev));
288
289 /* Default to 'not supported' */
290 lpData->ddRVal = DDERR_CURRENTLYNOTAVAIL;
291
292 /* Fill in supported stuff */
293 if (IsEqualIID(&lpData->guidInfo, &GUID_D3DCallbacks3))
294 {
295 DISPDBG((0, " -> GUID_D3DCallbacks3\n"));
296 }
297 else
298 if (IsEqualIID(&lpData->guidInfo, &GUID_D3DExtendedCaps))
299 {
300 DISPDBG((0, " -> GUID_D3DExtendedCaps\n"));
301 }
302 else
303 if (IsEqualIID(&lpData->guidInfo, &GUID_ZPixelFormats))
304 {
305 DISPDBG((0, " -> GUID_ZPixelFormats\n"));
306 }
307 else
308 if (IsEqualIID(&(lpData->guidInfo), &GUID_D3DParseUnknownCommandCallback))
309 {
310 DISPDBG((0, " -> GUID_D3DParseUnknownCommandCallback\n"));
311 }
312 else
313 if (IsEqualIID(&(lpData->guidInfo), &GUID_Miscellaneous2Callbacks))
314 {
315 DISPDBG((0, " -> GUID_Miscellaneous2Callbacks\n"));
316 }
317 else
318 if (IsEqualIID(&(lpData->guidInfo), &GUID_UpdateNonLocalHeap))
319 {
320 DISPDBG((0, " -> GUID_UpdateNonLocalHeap\n"));
321 }
322 else
323 if (IsEqualIID(&(lpData->guidInfo), &GUID_GetHeapAlignment))
324 {
325 DISPDBG((0, " -> GUID_GetHeapAlignment\n"));
326 }
327 else
328 if (IsEqualIID(&(lpData->guidInfo), &GUID_NTPrivateDriverCaps))
329 {
330 DD_NTPRIVATEDRIVERCAPS DDPrivateDriverCaps;
331
332 DISPDBG((0, " -> GUID_NTPrivateDriverCaps\n"));
333
334 memset(&DDPrivateDriverCaps, 0, sizeof(DDPrivateDriverCaps));
335 DDPrivateDriverCaps.dwSize=sizeof(DDPrivateDriverCaps);
336
337 DDPrivateDriverCaps.dwPrivateCaps = 0; /* DDHAL_PRIVATECAP_NOTIFYPRIMARYCREATION -> call CreateSurface for the primary surface */
338
339 lpData->dwActualSize =sizeof(DDPrivateDriverCaps);
340
341 dwSize = min(sizeof(DDPrivateDriverCaps),lpData->dwExpectedSize);
342 memcpy(lpData->lpvData, &DDPrivateDriverCaps, dwSize);
343 lpData->ddRVal = DD_OK;
344 }
345 else
346 if (IsEqualIID(&(lpData->guidInfo), &GUID_DDMoreSurfaceCaps))
347 {
348 DD_MORESURFACECAPS DDMoreSurfaceCaps;
349 DDSCAPSEX ddsCapsEx, ddsCapsExAlt;
350
351 DISPDBG((0, " -> GUID_DDMoreSurfaceCaps\n"));
352
353 // fill in everything until expectedsize...
354 memset(&DDMoreSurfaceCaps, 0, sizeof(DDMoreSurfaceCaps));
355
356 // Caps for heaps 2..n
357 memset(&ddsCapsEx, 0, sizeof(ddsCapsEx));
358 memset(&ddsCapsExAlt, 0, sizeof(ddsCapsEx));
359
360 DDMoreSurfaceCaps.dwSize=lpData->dwExpectedSize;
361
362 lpData->dwActualSize = lpData->dwExpectedSize;
363
364 dwSize = min(sizeof(DDMoreSurfaceCaps),lpData->dwExpectedSize);
365 memcpy(lpData->lpvData, &DDMoreSurfaceCaps, dwSize);
366
367 // now fill in other heaps...
368 while (dwSize < lpData->dwExpectedSize)
369 {
370 memcpy( (PBYTE)lpData->lpvData+dwSize,
371 &ddsCapsEx,
372 sizeof(DDSCAPSEX));
373 dwSize += sizeof(DDSCAPSEX);
374 memcpy( (PBYTE)lpData->lpvData+dwSize,
375 &ddsCapsExAlt,
376 sizeof(DDSCAPSEX));
377 dwSize += sizeof(DDSCAPSEX);
378 }
379
380 lpData->ddRVal = DD_OK;
381 }
382 else
383 if (IsEqualIID(&(lpData->guidInfo), &GUID_DDStereoMode))
384 {
385 DISPDBG((0, " -> GUID_DDStereoMode\n"));
386 }
387 else
388 if (IsEqualIID(&(lpData->guidInfo), &GUID_NonLocalVidMemCaps))
389 {
390 DISPDBG((0, " -> GUID_NonLocalVidMemCaps\n"));
391 }
392 else
393 if (IsEqualIID(&lpData->guidInfo, &GUID_NTCallbacks))
394 {
395 DD_NTCALLBACKS NtCallbacks;
396
397 DISPDBG((0, " -> GUID_NTCallbacks\n"));
398 memset(&NtCallbacks, 0, sizeof(NtCallbacks));
399
400 dwSize = min(lpData->dwExpectedSize, sizeof(DD_NTCALLBACKS));
401
402 NtCallbacks.dwSize = dwSize;
403 NtCallbacks.dwFlags = DDHAL_NTCB32_FREEDRIVERMEMORY
404 | DDHAL_NTCB32_SETEXCLUSIVEMODE
405 | DDHAL_NTCB32_FLIPTOGDISURFACE
406 ;
407 NtCallbacks.FreeDriverMemory = DdFreeDriverMemory;
408 NtCallbacks.SetExclusiveMode = DdSetExclusiveMode;
409 NtCallbacks.FlipToGDISurface = DdFlipToGDISurface;
410
411 memcpy(lpData->lpvData, &NtCallbacks, dwSize);
412
413 lpData->ddRVal = DD_OK;
414 }
415 else
416 if (IsEqualIID(&lpData->guidInfo, &GUID_KernelCaps))
417 {
418 DISPDBG((0, " -> GUID_KernelCaps\n"));
419 }
420 else
421 if (IsEqualIID(&lpData->guidInfo, &GUID_KernelCallbacks))
422 {
423 DISPDBG((0, " -> GUID_KernelCallbacks\n"));
424 }
425 else
426 if (IsEqualIID(&lpData->guidInfo, &GUID_MotionCompCallbacks))
427 {
428 DISPDBG((0, " -> GUID_MotionCompCallbacks\n"));
429 }
430 else
431 if (IsEqualIID(&lpData->guidInfo, &GUID_VideoPortCallbacks))
432 {
433 DISPDBG((0, " -> GUID_VideoPortCallbacks\n"));
434 }
435 else
436 if (IsEqualIID(&lpData->guidInfo, &GUID_ColorControlCallbacks))
437 {
438 DISPDBG((0, " -> GUID_ColorControlCallbacks\n"));
439 }
440 else
441 if (IsEqualIID(&lpData->guidInfo, &GUID_VideoPortCaps))
442 {
443 DISPDBG((0, " -> GUID_VideoPortCaps\n"));
444 }
445 else
446 if (IsEqualIID(&lpData->guidInfo, &GUID_D3DCallbacks2))
447 {
448 DISPDBG((0, " -> GUID_D3DCallbacks2\n"));
449 }
450 else
451 if (IsEqualIID(&lpData->guidInfo, &GUID_D3DCallbacks3))
452 {
453 DISPDBG((0, " -> GUID_D3DCallbacks3\n"));
454 }
455
456 /* Always return this */
457 return DDHAL_DRIVER_HANDLED;
458}
459
460/**
461 * DdCreateSurface
462 *
463 * The DdCreateSurface callback function creates a DirectDraw surface.
464 *
465 * lpCreateSurface
466 * Points to a DD_CREATESURFACEDATA structure that contains the information required to create a surface.
467 *
468 * Return Value
469 *
470 * DdCreateSurface returns one of the following callback codes:
471 * DDHAL_DRIVER_HANDLED
472 * DDHAL_DRIVER_NOTHANDLED
473 *
474 */
475DWORD APIENTRY DdCreateSurface(PDD_CREATESURFACEDATA lpCreateSurface)
476{
477 PPDEV pDev = (PPDEV)lpCreateSurface->lpDD->dhpdev;
478 DD_SURFACE_LOCAL* lpSurfaceLocal;
479 DD_SURFACE_GLOBAL* lpSurfaceGlobal;
480 LPDDSURFACEDESC lpSurfaceDesc;
481 LONG lPitch, lBpp;
482
483 DISPDBG((0, "%s: %p\n", __FUNCTION__, pDev));
484
485 lpSurfaceLocal = lpCreateSurface->lplpSList[0];
486 lpSurfaceGlobal = lpSurfaceLocal->lpGbl;
487 lpSurfaceDesc = lpCreateSurface->lpDDSurfaceDesc;
488
489 lpSurfaceGlobal->dwReserved1 = 0;
490
491 if (lpSurfaceDesc->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED4)
492 {
493 lBpp = 4;
494 lPitch = lpSurfaceGlobal->wWidth/2;
495 lPitch = (lPitch + 31) & ~31;
496 }
497 else
498 if (lpSurfaceDesc->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8)
499 {
500 lBpp = 8;
501 lPitch = lpSurfaceGlobal->wWidth;
502 lPitch = (lPitch + 31) & ~31;
503 }
504 else
505 {
506 lBpp = lpSurfaceDesc->ddpfPixelFormat.dwRGBBitCount;
507 lPitch = lpSurfaceGlobal->wWidth*(lBpp/8);
508 }
509 DISPDBG((0, "New surface (%d,%d)\n", lpSurfaceGlobal->wWidth, lpSurfaceGlobal->wHeight));
510 DISPDBG((0, "BPP %d lPitch=%d\n", lBpp, lPitch));
511
512 lpSurfaceGlobal->dwBlockSizeX = lPitch;
513 lpSurfaceGlobal->dwBlockSizeY = lpSurfaceGlobal->wHeight;
514 lpSurfaceGlobal->lPitch = lPitch;
515
516 //
517 // Modify surface descriptions as appropriate and let Direct
518 // Draw perform the allocation if the surface was not the primary
519 //
520 if (lpSurfaceLocal->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
521 {
522 DISPDBG((0, "-> primary surface\n"));
523 lpSurfaceGlobal->fpVidMem = 0;
524 }
525 else
526 {
527 DISPDBG((0, "-> secondary surface\n"));
528 lpSurfaceGlobal->fpVidMem = DDHAL_PLEASEALLOC_BLOCKSIZE;
529 }
530
531 lpSurfaceDesc->lPitch = lpSurfaceGlobal->lPitch;
532 lpSurfaceDesc->dwFlags |= DDSD_PITCH;
533
534
535 return DDHAL_DRIVER_NOTHANDLED;
536}
537
538/**
539 * DdCanCreateSurface
540 *
541 * The DdCanCreateSurface callback function indicates whether the driver can create a surface of the specified surface description.
542 *
543 *
544 * Parameters
545 * lpCanCreateSurface
546 * Points to the DD_CANCREATESURFACEDATA structure containing the information required for the driver to determine whether a surface can be created.
547 *
548 * Return Value
549 *
550 * DdCanCreateSurface returns one of the following callback codes:
551 *
552 * DDHAL_DRIVER_HANDLED
553 * DDHAL_DRIVER_NOTHANDLED
554 *
555 */
556DWORD APIENTRY DdCanCreateSurface(PDD_CANCREATESURFACEDATA lpCanCreateSurface)
557{
558 PPDEV pDev = (PPDEV)lpCanCreateSurface->lpDD->dhpdev;
559
560 PDD_SURFACEDESC lpDDS = lpCanCreateSurface->lpDDSurfaceDesc;
561
562 DISPDBG((0, "%s: %p\n", __FUNCTION__, pDev));
563
564 if (lpDDS->ddsCaps.dwCaps & DDSCAPS_ZBUFFER)
565 {
566 DISPDBG((0, "No Z-Bufer support\n"));
567 lpCanCreateSurface->ddRVal = DDERR_INVALIDPIXELFORMAT;
568 return DDHAL_DRIVER_HANDLED;
569 }
570 if (lpDDS->ddsCaps.dwCaps & DDSCAPS_TEXTURE)
571 {
572 DISPDBG((0, "No texture support\n"));
573 lpCanCreateSurface->ddRVal = DDERR_INVALIDPIXELFORMAT;
574 return DDHAL_DRIVER_HANDLED;
575 }
576
577 if (lpCanCreateSurface->bIsDifferentPixelFormat && (lpDDS->ddpfPixelFormat.dwFlags & DDPF_FOURCC))
578 {
579 DISPDBG((0, "FOURCC not supported\n"));
580 lpCanCreateSurface->ddRVal = DDERR_INVALIDPIXELFORMAT;
581 return DDHAL_DRIVER_HANDLED;
582 }
583
584 lpCanCreateSurface->ddRVal = DD_OK;
585 return DDHAL_DRIVER_HANDLED;
586}
587
588// ***************************WIN NT ONLY**********************************
589//
590// DdMapMemory
591//
592// Maps application-modifiable portions of the frame buffer into the
593// user-mode address space of the specified process, or unmaps memory.
594//
595// DdMapMemory is called to perform memory mapping before the first call to
596// DdLock. The handle returned by the driver in fpProcess will be passed to
597// every DdLock call made on the driver.
598//
599// DdMapMemory is also called to unmap memory after the last DdUnLock call is
600// made.
601//
602// To prevent driver crashes, the driver must not map any portion of the frame
603// buffer that must not be modified by an application.
604//
605// Parameters
606// lpMapMemory
607// Points to a DD_MAPMEMORYDATA structure that contains details for
608// the memory mapping or unmapping operation.
609//
610// .lpDD
611// Points to a DD_DIRECTDRAW_GLOBAL structure that represents
612// the driver.
613// .bMap
614// Specifies the memory operation that the driver should perform.
615// A value of TRUE indicates that the driver should map memory;
616// FALSE means that the driver should unmap memory.
617// .hProcess
618// Specifies a handle to the process whose address space is
619// affected.
620// .fpProcess
621// Specifies the location in which the driver should return the
622// base address of the process's memory mapped space when bMap
623// is TRUE. When bMap is FALSE, fpProcess contains the base
624// address of the memory to be unmapped by the driver.
625// .ddRVal
626// Specifies the location in which the driver writes the return
627// value of the DdMapMemory callback. A return code of DD_OK
628// indicates success.
629//
630//-----------------------------------------------------------------------------
631
632DWORD CALLBACK DdMapMemory(PDD_MAPMEMORYDATA lpMapMemory)
633{
634 PPDEV pDev = (PPDEV)lpMapMemory->lpDD->dhpdev;
635
636 VIDEO_SHARE_MEMORY ShareMemory;
637 VIDEO_SHARE_MEMORY_INFORMATION ShareMemoryInformation;
638 DWORD ReturnedDataLength;
639
640 DISPDBG((0, "%s: %p\n", __FUNCTION__, pDev));
641
642 if (lpMapMemory->bMap)
643 {
644 ShareMemory.ProcessHandle = lpMapMemory->hProcess;
645
646 // 'RequestedVirtualAddress' isn't actually used for the SHARE IOCTL:
647
648 ShareMemory.RequestedVirtualAddress = 0;
649
650 // We map in starting at the top of the frame buffer:
651
652 ShareMemory.ViewOffset = 0;
653 ShareMemory.ViewSize = pDev->cyScreen * pDev->lDeltaScreen;
654
655 DISPDBG((0, "ViewSize = %x\n", ShareMemory.ViewSize));
656
657 if (EngDeviceIoControl(pDev->hDriver,
658 IOCTL_VIDEO_SHARE_VIDEO_MEMORY,
659 &ShareMemory,
660 sizeof(VIDEO_SHARE_MEMORY),
661 &ShareMemoryInformation,
662 sizeof(VIDEO_SHARE_MEMORY_INFORMATION),
663 &ReturnedDataLength))
664 {
665 DISPDBG((0, "Failed IOCTL_VIDEO_SHARE_MEMORY"));
666
667 lpMapMemory->ddRVal = DDERR_GENERIC;
668
669 DISPDBG((0, "DdMapMemory: Exit GEN, DDHAL_DRIVER_HANDLED\n"));
670
671 return(DDHAL_DRIVER_HANDLED);
672 }
673
674 lpMapMemory->fpProcess =
675 (FLATPTR) ShareMemoryInformation.VirtualAddress;
676 }
677 else
678 {
679 ShareMemory.ProcessHandle = lpMapMemory->hProcess;
680 ShareMemory.ViewOffset = 0;
681 ShareMemory.ViewSize = 0;
682 ShareMemory.RequestedVirtualAddress = (VOID*) lpMapMemory->fpProcess;
683
684 if (EngDeviceIoControl(pDev->hDriver,
685 IOCTL_VIDEO_UNSHARE_VIDEO_MEMORY,
686 &ShareMemory,
687 sizeof(VIDEO_SHARE_MEMORY),
688 NULL,
689 0,
690 &ReturnedDataLength))
691 {
692 DISPDBG((0, "Failed IOCTL_VIDEO_UNSHARE_MEMORY\n"));
693 }
694 }
695
696 lpMapMemory->ddRVal = DD_OK;
697
698 return(DDHAL_DRIVER_HANDLED);
699}
700
701/**
702 * DdLock
703 *
704 * The DdLock callback function locks a specified area of surface memory and provides a valid pointer to a block of memory associated with a surface.
705 *
706 * Parameters
707 * lpLock
708 * Points to a DD_LOCKDATA structure that contains the information required to perform the lockdown.
709 *
710 * Return Value
711 *
712 * DdLock returns one of the following callback codes:
713 *
714 * DDHAL_DRIVER_HANDLED
715 * DDHAL_DRIVER_NOTHANDLED
716 *
717 */
718DWORD APIENTRY DdLock(PDD_LOCKDATA lpLock)
719{
720 PPDEV pDev = (PPDEV)lpLock->lpDD->dhpdev;
721
722 DISPDBG((0, "%s: %p\n", __FUNCTION__, pDev));
723
724 // Because we correctly set 'fpVidMem' to be the offset into our frame
725 // buffer when we created the surface, DirectDraw will automatically take
726 // care of adding in the user-mode frame buffer address if we return
727 // DDHAL_DRIVER_NOTHANDLED:
728 lpLock->ddRVal = DD_OK;
729 return DDHAL_DRIVER_NOTHANDLED;
730}
731
732/**
733 * DdUnlock
734 *
735 * The DdUnLock callback function releases the lock held on the specified surface.
736 *
737 * Parameters
738 * lpUnlock
739 * Points to a DD_UNLOCKDATA structure that contains the information required to perform the lock release. *
740 *
741 * Return Value
742 *
743 * DdLock returns one of the following callback codes:
744 *
745 * DDHAL_DRIVER_HANDLED
746 * DDHAL_DRIVER_NOTHANDLED
747 *
748 */
749DWORD APIENTRY DdUnlock(PDD_UNLOCKDATA lpUnlock)
750{
751 PPDEV pDev = (PPDEV)lpUnlock->lpDD->dhpdev;
752 DISPDBG((0, "%s: %p\n", __FUNCTION__, pDev));
753
754 lpUnlock->ddRVal = DD_OK;
755 return DDHAL_DRIVER_NOTHANDLED;
756}
757
758/**
759 * DdDestroySurface
760 *
761 * The DdDestroySurface callback function destroys a DirectDraw surface.
762 *
763 * Parameters
764 * lpDestroySurface
765 * Points to a DD_DESTROYSURFACEDATA structure that contains the information needed to destroy a surface.
766 *
767 * Return Value
768 *
769 * DdDestroySurface returns one of the following callback codes:
770 *
771 * DDHAL_DRIVER_HANDLED
772 * DDHAL_DRIVER_NOTHANDLED
773 *
774 */
775DWORD APIENTRY DdDestroySurface(PDD_DESTROYSURFACEDATA lpDestroySurface)
776{
777 PPDEV pDev = (PPDEV)lpDestroySurface->lpDD->dhpdev;
778 DISPDBG((0, "%s: %p\n", __FUNCTION__, pDev));
779
780 lpDestroySurface->ddRVal = DD_OK;
781 return DDHAL_DRIVER_HANDLED;
782}
783
784
785//-----------------------------------------------------------------------------
786//
787// DdSetExclusiveMode
788//
789// This function is called by DirectDraw when we switch from the GDI surface,
790// to DirectDraw exclusive mode, e.g. to run a game in fullcreen mode.
791// You only need to implement this function when you are using the
792// 'HeapVidMemAllocAligned' function and allocate memory for Device Bitmaps
793// and DirectDraw surfaces from the same heap.
794//
795// We use this call to disable GDI DeviceBitMaps when we are running in
796// DirectDraw exclusive mode. Otherwise a DD app gets confused if both GDI and
797// DirectDraw allocate memory from the same heap.
798//
799// See also DdFlipToGDISurface.
800//
801//-----------------------------------------------------------------------------
802
803
804DWORD APIENTRY DdSetExclusiveMode(PDD_SETEXCLUSIVEMODEDATA lpSetExclusiveMode)
805{
806 PPDEV pDev = (PPDEV)lpSetExclusiveMode->lpDD->dhpdev;
807 DISPDBG((0, "%s: %p\n", __FUNCTION__, pDev));
808
809 // remember setting of exclusive mode in pDev,
810 // so GDI can stop to promote DeviceBitmaps into
811 // video memory
812
813 pDev->bDdExclusiveMode = lpSetExclusiveMode->dwEnterExcl;
814
815 lpSetExclusiveMode->ddRVal = DD_OK;
816
817 return DDHAL_DRIVER_HANDLED;
818}
819
820//-----------------------------------------------------------------------------
821//
822// DWORD DdFlipToGDISurface
823//
824// This function is called by DirectDraw when it flips to the surface on which
825// GDI can write to.
826//
827//-----------------------------------------------------------------------------
828
829DWORD APIENTRY DdFlipToGDISurface(PDD_FLIPTOGDISURFACEDATA lpFlipToGDISurface)
830{
831 PPDEV pDev = (PPDEV)lpFlipToGDISurface->lpDD->dhpdev;
832 DISPDBG((0, "%s: %p\n", __FUNCTION__, pDev));
833
834 pDev->dwNewDDSurfaceOffset = 0xffffffff;
835
836 lpFlipToGDISurface->ddRVal = DD_OK;
837
838 //
839 // we return NOTHANDLED, then the ddraw runtime takes
840 // care that we flip back to the primary...
841 //
842 return DDHAL_DRIVER_NOTHANDLED;
843}
844//-----------------------------------------------------------------------------
845//
846// DWORD DdFreeDriverMemory
847//
848// This function called by DirectDraw when it's running low on memory in
849// our heap. You only need to implement this function if you use the
850// DirectDraw 'HeapVidMemAllocAligned' function in your driver, and you
851// can boot those allocations out of memory to make room for DirectDraw.
852//
853//-----------------------------------------------------------------------------
854
855DWORD APIENTRY DdFreeDriverMemory(PDD_FREEDRIVERMEMORYDATA lpFreeDriverMemory)
856{
857 PPDEV pDev = (PPDEV)lpFreeDriverMemory->lpDD->dhpdev;
858 DISPDBG((0, "%s: %p\n", __FUNCTION__, pDev));
859
860 lpFreeDriverMemory->ddRVal = DDERR_OUTOFMEMORY;
861 return DDHAL_DRIVER_HANDLED;
862}
863
864
865#endif /* VBOX_WITH_DDRAW */
Note: See TracBrowser for help on using the repository browser.

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