VirtualBox

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

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

ddraw updates

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