Fix a stupied bug in DdAttachSurface when pSurfaceFrom->hDDSurface is NULL or pSurfac...
[reactos.git] / reactos / dll / win32 / gdi32 / misc / gdientry.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS GDI32
4 * PURPOSE: GDI DirectX inteface
5 * FILE: lib/gdi32/misc/gdientry.c
6 * PROGRAMERS: Alex Ionescu (alex@relsoft.net)
7 * Magnus Olsen (magnus@greatlord.com)
8 */
9
10 /* INCLUDES ******************************************************************/
11
12 #include "precomp.h"
13 #include <ddraw.h>
14 #include <ddrawi.h>
15 #include <ddrawint.h>
16 #include <ddrawgdi.h>
17 #include <ntgdi.h>
18
19 /* DATA **********************************************************************/
20
21 HANDLE ghDirectDraw;
22 ULONG gcDirectDraw;
23
24 #define GetDdHandle(Handle) ((HANDLE)Handle ? (HANDLE)Handle : ghDirectDraw)
25
26
27 /* CALLBACKS *****************************************************************/
28
29 /*
30 * Dd Surface Callbacks
31 */
32 DWORD
33 WINAPI
34 DdAddAttachedSurface(LPDDHAL_ADDATTACHEDSURFACEDATA Attach)
35 {
36 /* Call win32k */
37 return NtGdiDdAddAttachedSurface((HANDLE)Attach->lpDDSurface->hDDSurface,
38 (HANDLE)Attach->lpSurfAttached->hDDSurface,
39 (PDD_ADDATTACHEDSURFACEDATA)Attach);
40 }
41
42 DWORD
43 WINAPI
44 DdBlt(LPDDHAL_BLTDATA Blt)
45 {
46 HANDLE Surface = 0;
47
48 /* Use the right surface */
49 if (Blt->lpDDSrcSurface) Surface = (HANDLE)Blt->lpDDSrcSurface->hDDSurface;
50
51 /* Call win32k */
52 return NtGdiDdBlt((HANDLE)Blt->lpDDDestSurface->hDDSurface, Surface, (PDD_BLTDATA)Blt);
53 }
54
55 DWORD
56 APIENTRY
57 DdDestroySurface(LPDDHAL_DESTROYSURFACEDATA pDestroySurface)
58 {
59 DWORD Return = DDHAL_DRIVER_NOTHANDLED;
60 BOOL RealDestroy = TRUE;
61 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal;
62
63 /* Get the local surface */
64 pSurfaceLocal = pDestroySurface->lpDDSurface;
65
66 /* Make sure there's a surface */
67 if (pSurfaceLocal->hDDSurface)
68 {
69 /* Check if we shoudl really destroy it */
70 if ((pSurfaceLocal->dwFlags & DDRAWISURF_DRIVERMANAGED) &&
71 (pSurfaceLocal->dwFlags & DDRAWISURF_INVALID))
72 {
73 RealDestroy = FALSE;
74 }
75
76 /* Call win32k */
77 Return = NtGdiDdDestroySurface((HANDLE)pSurfaceLocal->hDDSurface,
78 RealDestroy);
79 }
80
81 return Return;
82 }
83
84 DWORD
85 WINAPI
86 DdFlip(LPDDHAL_FLIPDATA Flip)
87 {
88 /* Call win32k */
89
90 return NtGdiDdFlip( (HANDLE)Flip->lpSurfCurr->hDDSurface,
91 (HANDLE)Flip->lpSurfTarg->hDDSurface,
92 /* FIXME the two last should be current left handler */
93 (HANDLE)Flip->lpSurfCurr->hDDSurface,
94 (HANDLE)Flip->lpSurfTarg->hDDSurface,
95 (PDD_FLIPDATA)Flip);
96 }
97
98 DWORD
99 WINAPI
100 DdLock(LPDDHAL_LOCKDATA Lock)
101 {
102 /* Call win32k */
103 return NtGdiDdLock((HANDLE)Lock->lpDDSurface->hDDSurface,
104 (PDD_LOCKDATA)Lock,
105 (HANDLE)Lock->lpDDSurface->hDC);
106 }
107
108 DWORD
109 WINAPI
110 DdUnlock(LPDDHAL_UNLOCKDATA Unlock)
111 {
112 /* Call win32k */
113 return NtGdiDdUnlock((HANDLE)Unlock->lpDDSurface->hDDSurface,
114 (PDD_UNLOCKDATA)Unlock);
115 }
116
117 DWORD
118 WINAPI
119 DdGetBltStatus(LPDDHAL_GETBLTSTATUSDATA GetBltStatus)
120 {
121 /* Call win32k */
122 return NtGdiDdGetBltStatus((HANDLE)GetBltStatus->lpDDSurface->hDDSurface,
123 (PDD_GETBLTSTATUSDATA)GetBltStatus);
124 }
125
126 DWORD
127 WINAPI
128 DdGetFlipStatus(LPDDHAL_GETFLIPSTATUSDATA GetFlipStatus)
129 {
130 /* Call win32k */
131 return NtGdiDdGetFlipStatus((HANDLE)GetFlipStatus->lpDDSurface->hDDSurface,
132 (PDD_GETFLIPSTATUSDATA)GetFlipStatus);
133 }
134
135 DWORD
136 APIENTRY
137 DdUpdateOverlay(LPDDHAL_UPDATEOVERLAYDATA UpdateOverlay)
138 {
139 /* We have to handle this manually here */
140 if (UpdateOverlay->dwFlags & DDOVER_KEYDEST)
141 {
142 /* Use the override */
143 UpdateOverlay->dwFlags &= ~DDOVER_KEYDEST;
144 UpdateOverlay->dwFlags |= DDOVER_KEYDESTOVERRIDE;
145
146 /* Set the overlay */
147 UpdateOverlay->overlayFX.dckDestColorkey =
148 UpdateOverlay->lpDDDestSurface->ddckCKDestOverlay;
149 }
150 if (UpdateOverlay->dwFlags & DDOVER_KEYSRC)
151 {
152 /* Use the override */
153 UpdateOverlay->dwFlags &= ~DDOVER_KEYSRC;
154 UpdateOverlay->dwFlags |= DDOVER_KEYSRCOVERRIDE;
155
156 /* Set the overlay */
157 UpdateOverlay->overlayFX.dckSrcColorkey =
158 UpdateOverlay->lpDDSrcSurface->ddckCKSrcOverlay;
159 }
160
161 /* Call win32k */
162 return NtGdiDdUpdateOverlay((HANDLE)UpdateOverlay->lpDDDestSurface->hDDSurface,
163 (HANDLE)UpdateOverlay->lpDDSrcSurface->hDDSurface,
164 (PDD_UPDATEOVERLAYDATA)UpdateOverlay);
165 }
166
167 DWORD
168 APIENTRY
169 DdSetOverlayPosition(LPDDHAL_SETOVERLAYPOSITIONDATA SetOverlayPosition)
170 {
171 /* Call win32k */
172 return NtGdiDdSetOverlayPosition((HANDLE)SetOverlayPosition->
173 lpDDSrcSurface->hDDSurface,
174 (HANDLE)SetOverlayPosition->
175 lpDDDestSurface->hDDSurface,
176 (PDD_SETOVERLAYPOSITIONDATA)
177 SetOverlayPosition);
178 }
179
180 /*
181 * Dd Callbacks
182 */
183 DWORD
184 WINAPI
185 DdWaitForVerticalBlank(LPDDHAL_WAITFORVERTICALBLANKDATA WaitForVerticalBlank)
186 {
187 /* Call win32k */
188 return NtGdiDdWaitForVerticalBlank(GetDdHandle(
189 WaitForVerticalBlank->lpDD->hDD),
190 (PDD_WAITFORVERTICALBLANKDATA)
191 WaitForVerticalBlank);
192 }
193
194 DWORD
195 WINAPI
196 DdCanCreateSurface(LPDDHAL_CANCREATESURFACEDATA CanCreateSurface)
197 {
198 /* Call win32k */
199 return NtGdiDdCanCreateSurface(GetDdHandle(CanCreateSurface->lpDD->hDD),
200 (PDD_CANCREATESURFACEDATA)CanCreateSurface);
201 }
202
203 DWORD
204 APIENTRY
205 DdCreateSurface(LPDDHAL_CREATESURFACEDATA pCreateSurface)
206 {
207 DWORD Return = DDHAL_DRIVER_NOTHANDLED;
208 ULONG SurfaceCount = pCreateSurface->dwSCnt;
209 DD_SURFACE_LOCAL DdSurfaceLocal;
210 DD_SURFACE_MORE DdSurfaceMore;
211 DD_SURFACE_GLOBAL DdSurfaceGlobal;
212
213 HANDLE hPrevSurface, hSurface;
214
215
216 PDD_SURFACE_LOCAL pDdSurfaceLocal = NULL;
217 PDD_SURFACE_MORE pDdSurfaceMore = NULL;
218 PDD_SURFACE_GLOBAL pDdSurfaceGlobal = NULL;
219
220 PDD_SURFACE_LOCAL ptmpDdSurfaceLocal = NULL;
221 PDD_SURFACE_MORE ptmpDdSurfaceMore = NULL;
222 PDD_SURFACE_GLOBAL ptmpDdSurfaceGlobal = NULL;
223 PHANDLE phSurface = NULL, puhSurface = NULL;
224 ULONG i;
225 LPDDSURFACEDESC pSurfaceDesc = NULL;
226
227 /* Check how many surfaces there are */
228 if (SurfaceCount != 1)
229 {
230 /* We'll have to allocate more data, our stack isn't big enough */
231
232 }
233 else
234 {
235 /* We'll use what we have on the stack */
236 pDdSurfaceLocal = &DdSurfaceLocal;
237 pDdSurfaceMore = &DdSurfaceMore;
238 pDdSurfaceGlobal = &DdSurfaceGlobal;
239 phSurface = &hPrevSurface;
240 puhSurface = &hSurface;
241
242 /* Clear the structures */
243 RtlZeroMemory(&DdSurfaceLocal, sizeof(DdSurfaceLocal));
244 RtlZeroMemory(&DdSurfaceGlobal, sizeof(DdSurfaceGlobal));
245 RtlZeroMemory(&DdSurfaceMore, sizeof(DdSurfaceMore));
246 }
247
248 /* check if we got a surface or not */
249 if (SurfaceCount!=0)
250 {
251 /* Loop for each surface */
252 ptmpDdSurfaceGlobal = pDdSurfaceGlobal;
253 ptmpDdSurfaceLocal = pDdSurfaceLocal;
254 ptmpDdSurfaceMore = pDdSurfaceMore;
255 pSurfaceDesc = pCreateSurface->lpDDSurfaceDesc;
256
257 for (i = 0; i < SurfaceCount; i++)
258 {
259 LPDDRAWI_DDRAWSURFACE_LCL lcl = pCreateSurface->lplpSList[i];
260 LPDDRAWI_DDRAWSURFACE_GBL gpl = pCreateSurface->lplpSList[i]->lpGbl;
261
262 phSurface[i] = (HANDLE)lcl->hDDSurface;
263 ptmpDdSurfaceLocal->ddsCaps.dwCaps = lcl->ddsCaps.dwCaps;
264
265 ptmpDdSurfaceLocal->dwFlags = (ptmpDdSurfaceLocal->dwFlags &
266 (0xB0000000 | DDRAWISURF_INMASTERSPRITELIST |
267 DDRAWISURF_HELCB | DDRAWISURF_FRONTBUFFER |
268 DDRAWISURF_BACKBUFFER | DDRAWISURF_INVALID |
269 DDRAWISURF_DCIBUSY | DDRAWISURF_DCILOCK)) |
270 (lcl->dwFlags & DDRAWISURF_DRIVERMANAGED);
271
272 ptmpDdSurfaceGlobal->wWidth = gpl->wWidth;
273 ptmpDdSurfaceGlobal->wHeight = gpl->wHeight;
274 ptmpDdSurfaceGlobal->lPitch = gpl->lPitch;
275 ptmpDdSurfaceGlobal->fpVidMem = gpl->fpVidMem;
276 ptmpDdSurfaceGlobal->dwBlockSizeX = gpl->dwBlockSizeX;
277 ptmpDdSurfaceGlobal->dwBlockSizeY = gpl->dwBlockSizeY;
278
279 if (lcl->dwFlags & DDRAWISURF_HASPIXELFORMAT)
280 {
281 RtlCopyMemory( &ptmpDdSurfaceGlobal->ddpfSurface ,
282 &gpl->ddpfSurface,
283 sizeof(DDPIXELFORMAT));
284
285 ptmpDdSurfaceGlobal->ddpfSurface.dwSize = sizeof(DDPIXELFORMAT);
286 }
287 else
288 {
289 RtlCopyMemory( &ptmpDdSurfaceGlobal->ddpfSurface ,
290 &gpl->lpDD->vmiData.ddpfDisplay,
291 sizeof(DDPIXELFORMAT));
292 }
293
294 if (lcl->lpSurfMore)
295 {
296 ptmpDdSurfaceMore->ddsCapsEx.dwCaps2 = lcl->lpSurfMore->ddsCapsEx.dwCaps2;
297 ptmpDdSurfaceMore->ddsCapsEx.dwCaps3 = lcl->lpSurfMore->ddsCapsEx.dwCaps3;
298 ptmpDdSurfaceMore->ddsCapsEx.dwCaps4 = lcl->lpSurfMore->ddsCapsEx.dwCaps4;
299 ptmpDdSurfaceMore->dwSurfaceHandle = (DWORD) pCreateSurface->lplpSList[i]->dbnOverlayNode.object_int;
300 }
301
302 /* FIXME count to next SurfaceCount for
303 ptmpDdSurfaceGlobal = pDdSurfaceGlobal;
304 ptmpDdSurfaceLocal = pDdSurfaceLocal;
305 ptmpDdSurfaceMore = pDdSurfaceMore;
306
307 we only support one surface create at moment
308 */
309 }
310 }
311
312 /* Call win32k now */
313 pCreateSurface->ddRVal = DDERR_GENERIC;
314
315 Return = NtGdiDdCreateSurface(GetDdHandle(pCreateSurface->lpDD->hDD),
316 (HANDLE *)phSurface,
317 pSurfaceDesc,
318 pDdSurfaceGlobal,
319 pDdSurfaceLocal,
320 pDdSurfaceMore,
321 (PDD_CREATESURFACEDATA)pCreateSurface,
322 puhSurface);
323
324 if (SurfaceCount == 0)
325 {
326 pCreateSurface->ddRVal = DDERR_GENERIC;
327 }
328 else
329 {
330 ptmpDdSurfaceMore = pDdSurfaceMore;
331 ptmpDdSurfaceGlobal = pDdSurfaceGlobal;
332 ptmpDdSurfaceLocal = pDdSurfaceLocal;
333
334 for (i=0;i<SurfaceCount;i++)
335 {
336 LPDDRAWI_DDRAWSURFACE_LCL lcl = pCreateSurface->lplpSList[i];
337 LPDDRAWI_DDRAWSURFACE_GBL gpl = pCreateSurface->lplpSList[i]->lpGbl;
338
339 gpl->lPitch = ptmpDdSurfaceGlobal->lPitch;
340 gpl->fpVidMem = ptmpDdSurfaceGlobal->fpVidMem;
341 gpl->dwBlockSizeX = ptmpDdSurfaceGlobal->dwBlockSizeX;
342 gpl->dwBlockSizeY = ptmpDdSurfaceGlobal->dwBlockSizeY;
343
344 if (lcl->dwFlags & DDRAWISURF_HASPIXELFORMAT)
345 {
346 RtlCopyMemory( &gpl->ddpfSurface, &ptmpDdSurfaceGlobal->ddpfSurface , sizeof(DDPIXELFORMAT));
347 }
348
349 if (pCreateSurface->ddRVal != DD_OK)
350 {
351 gpl->fpVidMem = 0;
352 if (lcl->hDDSurface)
353 {
354 NtGdiDdDeleteSurfaceObject( (HANDLE)lcl->hDDSurface);
355 }
356 lcl->hDDSurface = 0;
357 }
358 else
359 {
360
361 lcl->hDDSurface = (ULONG_PTR) puhSurface[i];
362 }
363
364 lcl->ddsCaps.dwCaps = ptmpDdSurfaceLocal->ddsCaps.dwCaps;
365 if (lcl->lpSurfMore)
366 {
367 lcl->lpSurfMore->ddsCapsEx.dwCaps2 = ptmpDdSurfaceMore->ddsCapsEx.dwCaps2;
368 lcl->lpSurfMore->ddsCapsEx.dwCaps3 = ptmpDdSurfaceMore->ddsCapsEx.dwCaps3;
369 lcl->lpSurfMore->ddsCapsEx.dwCaps4 = ptmpDdSurfaceMore->ddsCapsEx.dwCaps4;
370 }
371 /* FIXME count to next SurfaceCount for
372 ptmpDdSurfaceGlobal = pDdSurfaceGlobal;
373 ptmpDdSurfaceLocal = pDdSurfaceLocal;
374 ptmpDdSurfaceMore = pDdSurfaceMore;
375 we only support one surface create at moment
376 */
377 }
378 }
379
380 /* Check if we have to free all our local allocations */
381 if (SurfaceCount > 1)
382 {
383 /* FIXME: */
384 }
385
386 /* Return */
387 return Return;
388 }
389
390 DWORD
391 APIENTRY
392 DdSetColorKey(LPDDHAL_SETCOLORKEYDATA pSetColorKey)
393 {
394 /* Call win32k */
395 return NtGdiDdSetColorKey((HANDLE)pSetColorKey->lpDDSurface->hDDSurface,
396 (PDD_SETCOLORKEYDATA)pSetColorKey);
397 }
398
399 DWORD
400 APIENTRY
401 DdGetScanLine(LPDDHAL_GETSCANLINEDATA pGetScanLine)
402 {
403 /* Call win32k */
404 return NtGdiDdGetScanLine(GetDdHandle(pGetScanLine->lpDD->hDD),
405 (PDD_GETSCANLINEDATA)pGetScanLine);
406 }
407
408 /* PRIVATE FUNCTIONS *********************************************************/
409 static ULONG RemberDdQueryDisplaySettingsUniquenessID = 0;
410
411 BOOL
412 WINAPI
413 bDDCreateSurface(LPDDRAWI_DDRAWSURFACE_LCL pSurface,
414 BOOL bComplete)
415 {
416 DD_SURFACE_LOCAL SurfaceLocal;
417 DD_SURFACE_GLOBAL SurfaceGlobal;
418 DD_SURFACE_MORE SurfaceMore;
419
420 /* Zero struct */
421 RtlZeroMemory(&SurfaceLocal, sizeof(DD_SURFACE_LOCAL));
422 RtlZeroMemory(&SurfaceGlobal, sizeof(DD_SURFACE_GLOBAL));
423 RtlZeroMemory(&SurfaceMore, sizeof(DD_SURFACE_MORE));
424
425 /* Set up SurfaceLocal struct */
426 SurfaceLocal.ddsCaps.dwCaps = pSurface->ddsCaps.dwCaps;
427 SurfaceLocal.dwFlags = pSurface->dwFlags;
428
429 /* Set up SurfaceMore struct */
430 RtlMoveMemory(&SurfaceMore.ddsCapsEx,
431 &pSurface->ddckCKDestBlt,
432 sizeof(DDSCAPSEX));
433 SurfaceMore.dwSurfaceHandle = (DWORD)pSurface->dbnOverlayNode.object_int->lpVtbl;
434
435 /* Set up SurfaceGlobal struct */
436 SurfaceGlobal.fpVidMem = pSurface->lpGbl->fpVidMem;
437 SurfaceGlobal.dwLinearSize = pSurface->lpGbl->dwLinearSize;
438 SurfaceGlobal.wHeight = pSurface->lpGbl->wHeight;
439 SurfaceGlobal.wWidth = pSurface->lpGbl->wWidth;
440
441 /* Check if we have a pixel format */
442 if (pSurface->dwFlags & DDSD_PIXELFORMAT)
443 {
444 /* Use global one */
445 SurfaceGlobal.ddpfSurface = pSurface->lpGbl->lpDD->vmiData.ddpfDisplay;
446 SurfaceGlobal.ddpfSurface.dwSize = sizeof(DDPIXELFORMAT);
447 }
448 else
449 {
450 /* Use local one */
451 SurfaceGlobal.ddpfSurface = pSurface->lpGbl->lpDD->vmiData.ddpfDisplay;
452 }
453
454 /* Create the object */
455 pSurface->hDDSurface = (DWORD)NtGdiDdCreateSurfaceObject(GetDdHandle(pSurface->lpGbl->lpDD->hDD),
456 (HANDLE)pSurface->hDDSurface,
457 &SurfaceLocal,
458 &SurfaceMore,
459 &SurfaceGlobal,
460 bComplete);
461
462 /* Return status */
463 if (pSurface->hDDSurface) return TRUE;
464 return FALSE;
465 }
466
467 /* PUBLIC FUNCTIONS **********************************************************/
468
469 /*
470 * @implemented
471 *
472 * GDIEntry 1
473 */
474 BOOL
475 WINAPI
476 DdCreateDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
477 HDC hdc)
478 {
479 BOOL Return = FALSE;
480
481 /* Check if the global hDC (hdc == 0) is being used */
482 if (!hdc)
483 {
484 /* We'll only allow this if the global object doesn't exist yet */
485 if (!ghDirectDraw)
486 {
487 /* Create the DC */
488 if ((hdc = CreateDC(L"Display", NULL, NULL, NULL)))
489 {
490 /* Create the DDraw Object */
491 ghDirectDraw = NtGdiDdCreateDirectDrawObject(hdc);
492
493 /* Delete our DC */
494 NtGdiDeleteObjectApp(hdc);
495 }
496 }
497
498 /* If we created the object, or had one ...*/
499 if (ghDirectDraw)
500 {
501 /* Increase count and set success */
502 gcDirectDraw++;
503 Return = TRUE;
504 }
505
506 /* Zero the handle */
507 pDirectDrawGlobal->hDD = 0;
508 }
509 else
510 {
511 /* Using the per-process object, so create it */
512 pDirectDrawGlobal->hDD = (ULONG_PTR)NtGdiDdCreateDirectDrawObject(hdc);
513
514 /* Set the return value */
515 Return = pDirectDrawGlobal->hDD ? TRUE : FALSE;
516 }
517
518 /* Return to caller */
519 return Return;
520 }
521
522 /*
523 * @implemented
524 *
525 * GDIEntry 2
526 */
527 BOOL
528 WINAPI
529 DdQueryDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
530 LPDDHALINFO pHalInfo,
531 LPDDHAL_DDCALLBACKS pDDCallbacks,
532 LPDDHAL_DDSURFACECALLBACKS pDDSurfaceCallbacks,
533 LPDDHAL_DDPALETTECALLBACKS pDDPaletteCallbacks,
534 LPD3DHAL_CALLBACKS pD3dCallbacks,
535 LPD3DHAL_GLOBALDRIVERDATA pD3dDriverData,
536 LPDDHAL_DDEXEBUFCALLBACKS pD3dBufferCallbacks,
537 LPDDSURFACEDESC pD3dTextureFormats,
538 LPDWORD pdwFourCC,
539 LPVIDMEM pvmList)
540 {
541 PVIDEOMEMORY VidMemList = NULL;
542 DD_HALINFO HalInfo;
543 D3DNTHAL_CALLBACKS D3dCallbacks;
544 D3DNTHAL_GLOBALDRIVERDATA D3dDriverData;
545 DD_D3DBUFCALLBACKS D3dBufferCallbacks;
546 DWORD CallbackFlags[3];
547 DWORD dwNumHeaps=0, FourCCs=0;
548 DWORD Flags;
549
550 /* Clear the structures */
551 RtlZeroMemory(&HalInfo, sizeof(DD_HALINFO));
552 RtlZeroMemory(&D3dCallbacks, sizeof(D3DNTHAL_CALLBACKS));
553 RtlZeroMemory(&D3dDriverData, sizeof(D3DNTHAL_GLOBALDRIVERDATA));
554 RtlZeroMemory(&D3dBufferCallbacks, sizeof(DD_D3DBUFCALLBACKS));
555 RtlZeroMemory(CallbackFlags, sizeof(DWORD)*3);
556
557 pvmList = NULL;
558
559 /* Do the query */
560 if (!NtGdiDdQueryDirectDrawObject(GetDdHandle(pDirectDrawGlobal->hDD),
561 &HalInfo,
562 CallbackFlags,
563 &D3dCallbacks,
564 &D3dDriverData,
565 &D3dBufferCallbacks,
566 pD3dTextureFormats,
567 &dwNumHeaps,
568 VidMemList,
569 &FourCCs,
570 pdwFourCC))
571 {
572 /* We failed, free the memory and return */
573 return FALSE;
574 }
575
576 /* Clear the incoming pointer */
577 RtlZeroMemory(pHalInfo, sizeof(DDHALINFO));
578
579 /* Convert all the data */
580 pHalInfo->dwSize = sizeof(DDHALINFO);
581 pHalInfo->lpDDCallbacks = pDDCallbacks;
582 pHalInfo->lpDDSurfaceCallbacks = pDDSurfaceCallbacks;
583 pHalInfo->lpDDPaletteCallbacks = pDDPaletteCallbacks;
584
585 /* Check for NT5+ D3D Data */
586 if (D3dCallbacks.dwSize && D3dDriverData.dwSize)
587 {
588 /* Write these down */
589 pHalInfo->lpD3DGlobalDriverData = (ULONG_PTR)pD3dDriverData;
590 pHalInfo->lpD3DHALCallbacks = (ULONG_PTR)pD3dCallbacks;
591
592 /* Check for Buffer Callbacks */
593 if (D3dBufferCallbacks.dwSize)
594 {
595 /* Write this one too */
596 pHalInfo->lpDDExeBufCallbacks = pD3dBufferCallbacks;
597 }
598 }
599
600 /* Continue converting the rest */
601 pHalInfo->vmiData.dwFlags = HalInfo.vmiData.dwFlags;
602 pHalInfo->vmiData.dwDisplayWidth = HalInfo.vmiData.dwDisplayWidth;
603 pHalInfo->vmiData.dwDisplayHeight = HalInfo.vmiData.dwDisplayHeight;
604 pHalInfo->vmiData.lDisplayPitch = HalInfo.vmiData.lDisplayPitch;
605 pHalInfo->vmiData.fpPrimary = 0;
606
607 RtlCopyMemory( &pHalInfo->vmiData.ddpfDisplay,
608 &HalInfo.vmiData.ddpfDisplay,
609 sizeof(DDPIXELFORMAT));
610
611 pHalInfo->vmiData.dwOffscreenAlign = HalInfo.vmiData.dwOffscreenAlign;
612 pHalInfo->vmiData.dwOverlayAlign = HalInfo.vmiData.dwOverlayAlign;
613 pHalInfo->vmiData.dwTextureAlign = HalInfo.vmiData.dwTextureAlign;
614 pHalInfo->vmiData.dwZBufferAlign = HalInfo.vmiData.dwZBufferAlign;
615 pHalInfo->vmiData.dwAlphaAlign = HalInfo.vmiData.dwAlphaAlign;
616 pHalInfo->vmiData.dwNumHeaps = 0;
617 pHalInfo->vmiData.pvmList = pvmList;
618
619 RtlCopyMemory( &pHalInfo->ddCaps, &HalInfo.ddCaps,sizeof(DDCORECAPS ));
620
621 pHalInfo->ddCaps.dwNumFourCCCodes = FourCCs;
622 pHalInfo->lpdwFourCC = pdwFourCC;
623 pHalInfo->ddCaps.dwRops[6] = 0x1000;
624
625 /* FIXME implement DdGetDriverInfo */
626 // pHalInfo->dwFlags = HalInfo.dwFlags | DDHALINFO_GETDRIVERINFOSET;
627 // pHalInfo->GetDriverInfo = DdGetDriverInfo;
628
629 /* Now check if we got any DD callbacks */
630 if (pDDCallbacks)
631 {
632 /* Zero the structure */
633 RtlZeroMemory(pDDCallbacks, sizeof(DDHAL_DDCALLBACKS));
634
635 /* Set the flags for this structure */
636 Flags = CallbackFlags[0];
637
638 /* Write the header */
639 pDDCallbacks->dwSize = sizeof(DDHAL_DDCALLBACKS);
640 pDDCallbacks->dwFlags = Flags;
641
642 /* Now write the pointers, if applicable */
643 if (Flags & DDHAL_CB32_CREATESURFACE)
644 {
645 pDDCallbacks->CreateSurface = DdCreateSurface;
646 }
647 if (Flags & DDHAL_CB32_WAITFORVERTICALBLANK)
648 {
649 pDDCallbacks->WaitForVerticalBlank = DdWaitForVerticalBlank;
650 }
651 if (Flags & DDHAL_CB32_CANCREATESURFACE)
652 {
653 pDDCallbacks->CanCreateSurface = DdCanCreateSurface;
654 }
655 if (Flags & DDHAL_CB32_GETSCANLINE)
656 {
657 pDDCallbacks->GetScanLine = DdGetScanLine;
658 }
659 }
660
661 /* Check for DD Surface Callbacks */
662 if (pDDSurfaceCallbacks)
663 {
664 /* Zero the structures */
665 RtlZeroMemory(pDDSurfaceCallbacks, sizeof(DDHAL_DDSURFACECALLBACKS));
666
667 /* Set the flags for this one */
668 Flags = CallbackFlags[1];
669
670 /* Write the header, note that some functions are always exposed */
671 pDDSurfaceCallbacks->dwSize = sizeof(DDHAL_DDSURFACECALLBACKS);
672
673 pDDSurfaceCallbacks->dwFlags = Flags;
674 /*
675 pDDSurfaceCallBacks->dwFlags = (DDHAL_SURFCB32_LOCK |
676 DDHAL_SURFCB32_UNLOCK |
677 DDHAL_SURFCB32_SETCOLORKEY |
678 DDHAL_SURFCB32_DESTROYSURFACE) | Flags;
679 */
680
681 /* Write the always-on functions */
682 pDDSurfaceCallbacks->Lock = DdLock;
683 pDDSurfaceCallbacks->Unlock = DdUnlock;
684 pDDSurfaceCallbacks->SetColorKey = DdSetColorKey;
685 pDDSurfaceCallbacks->DestroySurface = DdDestroySurface;
686
687 /* Write the optional ones */
688 if (Flags & DDHAL_SURFCB32_FLIP)
689 {
690 pDDSurfaceCallbacks->Flip = DdFlip;
691 }
692 if (Flags & DDHAL_SURFCB32_BLT)
693 {
694 pDDSurfaceCallbacks->Blt = DdBlt;
695 }
696 if (Flags & DDHAL_SURFCB32_GETBLTSTATUS)
697 {
698 pDDSurfaceCallbacks->GetBltStatus = DdGetBltStatus;
699 }
700 if (Flags & DDHAL_SURFCB32_GETFLIPSTATUS)
701 {
702 pDDSurfaceCallbacks->GetFlipStatus = DdGetFlipStatus;
703 }
704 if (Flags & DDHAL_SURFCB32_UPDATEOVERLAY)
705 {
706 pDDSurfaceCallbacks->UpdateOverlay = DdUpdateOverlay;
707 }
708 if (Flags & DDHAL_SURFCB32_SETOVERLAYPOSITION)
709 {
710 pDDSurfaceCallbacks->SetOverlayPosition = DdSetOverlayPosition;
711 }
712 if (Flags & DDHAL_SURFCB32_ADDATTACHEDSURFACE)
713 {
714 pDDSurfaceCallbacks->AddAttachedSurface = DdAddAttachedSurface;
715 }
716 }
717
718 /* Check for DD Palette Callbacks */
719 if (pDDPaletteCallbacks)
720 {
721 /* Zero the struct */
722 RtlZeroMemory(pDDPaletteCallbacks, sizeof(DDHAL_DDPALETTECALLBACKS));
723
724 /* Get the flags for this one */
725 Flags = CallbackFlags[2];
726
727 /* Write the header */
728 pDDPaletteCallbacks->dwSize = sizeof(DDHAL_DDPALETTECALLBACKS);
729 pDDPaletteCallbacks->dwFlags = Flags;
730 }
731
732 /* Check for D3D Callbacks */
733 if (pD3dCallbacks)
734 {
735 /* Zero the struct */
736 RtlZeroMemory(pD3dCallbacks, sizeof(D3DHAL_CALLBACKS));
737
738 /* Check if we have one */
739 if (D3dCallbacks.dwSize)
740 {
741 /* Write the header */
742 pD3dCallbacks->dwSize = sizeof(D3DHAL_CALLBACKS);
743
744 /* Now check for each callback */
745 if (D3dCallbacks.ContextCreate)
746 {
747 /* FIXME
748 pD3dCallbacks->ContextCreate = D3dContextCreate;
749 */
750 }
751 if (D3dCallbacks.ContextDestroy)
752 {
753 pD3dCallbacks->ContextDestroy = (LPD3DHAL_CONTEXTDESTROYCB) NtGdiD3dContextDestroy;
754 }
755 if (D3dCallbacks.ContextDestroyAll)
756 {
757 /* FIXME
758 pD3dCallbacks->ContextDestroyAll = (LPD3DHAL_CONTEXTDESTROYALLCB) NtGdiD3dContextDestroyAll;
759 */
760 }
761 }
762 }
763
764 /* Check for D3D Driver Data */
765 if (pD3dDriverData)
766 {
767 /* Copy the struct */
768 RtlMoveMemory(pD3dDriverData,
769 &D3dDriverData,
770 sizeof(D3DHAL_GLOBALDRIVERDATA));
771
772 /* Write the pointer to the texture formats */
773 pD3dDriverData->lpTextureFormats = pD3dTextureFormats;
774 }
775
776 /* FIXME: Check for D3D Buffer Callbacks */
777
778 return TRUE;
779 }
780
781 /*
782 * @implemented
783 *
784 * GDIEntry 3
785 */
786 BOOL
787 WINAPI
788 DdDeleteDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal)
789 {
790 BOOL Return = FALSE;
791
792 /* If this is the global object */
793 if(pDirectDrawGlobal->hDD)
794 {
795 /* Free it */
796 Return = NtGdiDdDeleteDirectDrawObject((HANDLE)pDirectDrawGlobal->hDD);
797 if (Return == TRUE)
798 {
799 pDirectDrawGlobal->hDD = 0;
800 }
801 }
802 else if (ghDirectDraw)
803 {
804 /* Always success here */
805 Return = TRUE;
806
807 /* Make sure this is the last instance */
808 if (!(--gcDirectDraw))
809 {
810 /* Delete the object */
811 Return = NtGdiDdDeleteDirectDrawObject(ghDirectDraw);
812 if (Return == TRUE)
813 {
814 ghDirectDraw = 0;
815 }
816 }
817 }
818
819 /* Return */
820 return Return;
821 }
822
823 /*
824 * @implemented
825 *
826 * GDIEntry 4
827 */
828 BOOL
829 WINAPI
830 DdCreateSurfaceObject( LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
831 BOOL bPrimarySurface)
832 {
833 return bDDCreateSurface(pSurfaceLocal, TRUE);
834 //return bDdCreateSurfaceObject(pSurfaceLocal, TRUE);
835 }
836
837
838 /*
839 * @implemented
840 *
841 * GDIEntry 5
842 */
843 BOOL
844 WINAPI
845 DdDeleteSurfaceObject(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal)
846 {
847 BOOL Return = FALSE;
848
849 /* Make sure there is one */
850 if (pSurfaceLocal->hDDSurface)
851 {
852 /* Delete it */
853 Return = NtGdiDdDeleteSurfaceObject((HANDLE)pSurfaceLocal->hDDSurface);
854 pSurfaceLocal->hDDSurface = 0;
855 }
856
857 return Return;
858 }
859
860 /*
861 * @implemented
862 *
863 * GDIEntry 6
864 */
865 BOOL
866 WINAPI
867 DdResetVisrgn(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
868 HWND hWnd)
869 {
870 /* Call win32k directly */
871 return NtGdiDdResetVisrgn((HANDLE) pSurfaceLocal->hDDSurface, hWnd);
872 }
873
874 /*
875 * @implemented
876 *
877 * GDIEntry 7
878 */
879 HDC
880 WINAPI
881 DdGetDC(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
882 LPPALETTEENTRY pColorTable)
883 {
884 /* Call win32k directly */
885 return NtGdiDdGetDC(pColorTable, (HANDLE) pSurfaceLocal->hDDSurface);
886 }
887
888 /*
889 * @implemented
890 *
891 * GDIEntry 8
892 */
893 BOOL
894 WINAPI
895 DdReleaseDC(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal)
896 {
897 /* Call win32k directly */
898 return NtGdiDdReleaseDC((HANDLE) pSurfaceLocal->hDDSurface);
899 }
900
901 /*
902 * @unimplemented
903 * GDIEntry 9
904 */
905 HBITMAP
906 STDCALL
907 DdCreateDIBSection(HDC hdc,
908 CONST BITMAPINFO *pbmi,
909 UINT iUsage,
910 VOID **ppvBits,
911 HANDLE hSectionApp,
912 DWORD dwOffset)
913 {
914 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
915 return 0;
916 }
917
918 /*
919 * @implemented
920 *
921 * GDIEntry 10
922 */
923 BOOL
924 WINAPI
925 DdReenableDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
926 BOOL *pbNewMode)
927 {
928 /* Call win32k directly */
929 return NtGdiDdReenableDirectDrawObject(GetDdHandle(pDirectDrawGlobal->hDD),
930 pbNewMode);
931 }
932
933
934 /*
935 * @implemented
936 *
937 * GDIEntry 11
938 */
939 BOOL
940 STDCALL
941 DdAttachSurface( LPDDRAWI_DDRAWSURFACE_LCL pSurfaceFrom,
942 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceTo)
943 {
944 /* Create Surface if it does not exits one */
945 if (!pSurfaceFrom->hDDSurface)
946 {
947 if (!bDDCreateSurface(pSurfaceFrom, FALSE))
948 {
949 return FALSE;
950 }
951 }
952
953 /* Create Surface if it does not exits one */
954 if (!pSurfaceTo->hDDSurface)
955 {
956 if (!bDDCreateSurface(pSurfaceTo, FALSE))
957 {
958 return FALSE;
959 }
960 }
961
962 /* Call win32k */
963 return NtGdiDdAttachSurface((HANDLE)pSurfaceFrom->hDDSurface,
964 (HANDLE)pSurfaceTo->hDDSurface);
965 }
966
967 /*
968 * @implemented
969 *
970 * GDIEntry 12
971 */
972 VOID
973 STDCALL
974 DdUnattachSurface(LPDDRAWI_DDRAWSURFACE_LCL pSurface,
975 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceAttached)
976 {
977 /* Call win32k */
978 NtGdiDdUnattachSurface((HANDLE)pSurface->hDDSurface,
979 (HANDLE)pSurfaceAttached->hDDSurface);
980 }
981
982 /*
983 * @implemented
984 *
985 * GDIEntry 13
986 */
987 ULONG
988 STDCALL
989 DdQueryDisplaySettingsUniqueness()
990 {
991 return RemberDdQueryDisplaySettingsUniquenessID;
992 }
993
994 /*
995 * @implemented
996 *
997 * GDIEntry 14
998 */
999 HANDLE
1000 WINAPI
1001 DdGetDxHandle(LPDDRAWI_DIRECTDRAW_LCL pDDraw,
1002 LPDDRAWI_DDRAWSURFACE_LCL pSurface,
1003 BOOL bRelease)
1004 {
1005 HANDLE hDD = NULL;
1006 HANDLE hSurface = (HANDLE)pSurface->hDDSurface;
1007
1008 /* Check if we already have a surface */
1009 if (!pSurface)
1010 {
1011 /* We don't have one, use the DirectDraw Object handle instead */
1012 hSurface = NULL;
1013 hDD = GetDdHandle(pDDraw->lpGbl->hDD);
1014 }
1015
1016 /* Call the API */
1017 return (HANDLE)NtGdiDdGetDxHandle(hDD, hSurface, bRelease);
1018 }
1019
1020 /*
1021 * @implemented
1022 *
1023 * GDIEntry 15
1024 */
1025 BOOL
1026 WINAPI
1027 DdSetGammaRamp(LPDDRAWI_DIRECTDRAW_LCL pDDraw,
1028 HDC hdc,
1029 LPVOID lpGammaRamp)
1030 {
1031 /* Call win32k directly */
1032 return NtGdiDdSetGammaRamp(GetDdHandle(pDDraw->lpGbl->hDD),
1033 hdc,
1034 lpGammaRamp);
1035 }
1036
1037
1038
1039
1040