VirtualBox

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

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

Disabled all ddraw features that are not mandatory. Enabled DirectDraw.

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