* Made it possible to include both d3d9types.h and ddrawgdi.h at the same time
[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 #include <d3dhal.h>
19
20 /* DATA **********************************************************************/
21
22 HANDLE ghDirectDraw;
23 ULONG gcDirectDraw;
24
25 #define GetDdHandle(Handle) ((HANDLE)Handle ? (HANDLE)Handle : ghDirectDraw)
26
27
28 /* CALLBACKS *****************************************************************/
29
30 /*
31 * Dd Surface Callbacks
32 */
33 DWORD
34 WINAPI
35 DdAddAttachedSurface(LPDDHAL_ADDATTACHEDSURFACEDATA Attach)
36 {
37 /* Call win32k */
38 return NtGdiDdAddAttachedSurface((HANDLE)Attach->lpDDSurface->hDDSurface,
39 (HANDLE)Attach->lpSurfAttached->hDDSurface,
40 (PDD_ADDATTACHEDSURFACEDATA)Attach);
41 }
42
43 DWORD
44 WINAPI
45 DdBlt(LPDDHAL_BLTDATA Blt)
46 {
47 HANDLE Surface = 0;
48
49 /* Use the right surface */
50 if (Blt->lpDDSrcSurface) Surface = (HANDLE)Blt->lpDDSrcSurface->hDDSurface;
51
52 /* Call win32k */
53 return NtGdiDdBlt((HANDLE)Blt->lpDDDestSurface->hDDSurface, Surface, (PDD_BLTDATA)Blt);
54 }
55
56 DWORD
57 APIENTRY
58 DdDestroySurface(LPDDHAL_DESTROYSURFACEDATA pDestroySurface)
59 {
60 DWORD Return = DDHAL_DRIVER_NOTHANDLED;
61 BOOL RealDestroy = TRUE;
62 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal;
63
64 /* Get the local surface */
65 pSurfaceLocal = pDestroySurface->lpDDSurface;
66
67 /* Make sure there's a surface */
68 if (pSurfaceLocal->hDDSurface)
69 {
70 /* Check if we shoudl really destroy it */
71 if ((pSurfaceLocal->dwFlags & DDRAWISURF_DRIVERMANAGED) &&
72 (pSurfaceLocal->dwFlags & DDRAWISURF_INVALID))
73 {
74 RealDestroy = FALSE;
75 }
76
77 /* Call win32k */
78 Return = NtGdiDdDestroySurface((HANDLE)pSurfaceLocal->hDDSurface,
79 RealDestroy);
80 }
81
82 return Return;
83 }
84
85 DWORD
86 WINAPI
87 DdFlip(LPDDHAL_FLIPDATA Flip)
88 {
89 /* Call win32k */
90
91 return NtGdiDdFlip( (HANDLE)Flip->lpSurfCurr->hDDSurface,
92 (HANDLE)Flip->lpSurfTarg->hDDSurface,
93 /* FIXME the two last should be current left handler */
94 (HANDLE)Flip->lpSurfCurr->hDDSurface,
95 (HANDLE)Flip->lpSurfTarg->hDDSurface,
96 (PDD_FLIPDATA)Flip);
97 }
98
99 DWORD
100 WINAPI
101 DdLock(LPDDHAL_LOCKDATA Lock)
102 {
103 /* Call win32k */
104 return NtGdiDdLock((HANDLE)Lock->lpDDSurface->hDDSurface,
105 (PDD_LOCKDATA)Lock,
106 (HANDLE)Lock->lpDDSurface->hDC);
107 }
108
109 DWORD
110 WINAPI
111 DdUnlock(LPDDHAL_UNLOCKDATA Unlock)
112 {
113 /* Call win32k */
114 return NtGdiDdUnlock((HANDLE)Unlock->lpDDSurface->hDDSurface,
115 (PDD_UNLOCKDATA)Unlock);
116 }
117
118 DWORD
119 WINAPI
120 DdGetBltStatus(LPDDHAL_GETBLTSTATUSDATA GetBltStatus)
121 {
122 /* Call win32k */
123 return NtGdiDdGetBltStatus((HANDLE)GetBltStatus->lpDDSurface->hDDSurface,
124 (PDD_GETBLTSTATUSDATA)GetBltStatus);
125 }
126
127 DWORD
128 WINAPI
129 DdGetFlipStatus(LPDDHAL_GETFLIPSTATUSDATA GetFlipStatus)
130 {
131 /* Call win32k */
132 return NtGdiDdGetFlipStatus((HANDLE)GetFlipStatus->lpDDSurface->hDDSurface,
133 (PDD_GETFLIPSTATUSDATA)GetFlipStatus);
134 }
135
136 DWORD
137 APIENTRY
138 DdUpdateOverlay(LPDDHAL_UPDATEOVERLAYDATA UpdateOverlay)
139 {
140 /* We have to handle this manually here */
141 if (UpdateOverlay->dwFlags & DDOVER_KEYDEST)
142 {
143 /* Use the override */
144 UpdateOverlay->dwFlags &= ~DDOVER_KEYDEST;
145 UpdateOverlay->dwFlags |= DDOVER_KEYDESTOVERRIDE;
146
147 /* Set the overlay */
148 UpdateOverlay->overlayFX.dckDestColorkey =
149 UpdateOverlay->lpDDDestSurface->ddckCKDestOverlay;
150 }
151 if (UpdateOverlay->dwFlags & DDOVER_KEYSRC)
152 {
153 /* Use the override */
154 UpdateOverlay->dwFlags &= ~DDOVER_KEYSRC;
155 UpdateOverlay->dwFlags |= DDOVER_KEYSRCOVERRIDE;
156
157 /* Set the overlay */
158 UpdateOverlay->overlayFX.dckSrcColorkey =
159 UpdateOverlay->lpDDSrcSurface->ddckCKSrcOverlay;
160 }
161
162 /* Call win32k */
163 return NtGdiDdUpdateOverlay((HANDLE)UpdateOverlay->lpDDDestSurface->hDDSurface,
164 (HANDLE)UpdateOverlay->lpDDSrcSurface->hDDSurface,
165 (PDD_UPDATEOVERLAYDATA)UpdateOverlay);
166 }
167
168 DWORD
169 APIENTRY
170 DdSetOverlayPosition(LPDDHAL_SETOVERLAYPOSITIONDATA SetOverlayPosition)
171 {
172 /* Call win32k */
173 return NtGdiDdSetOverlayPosition((HANDLE)SetOverlayPosition->
174 lpDDSrcSurface->hDDSurface,
175 (HANDLE)SetOverlayPosition->
176 lpDDDestSurface->hDDSurface,
177 (PDD_SETOVERLAYPOSITIONDATA)
178 SetOverlayPosition);
179 }
180
181 /*
182 * Dd Callbacks
183 */
184 DWORD
185 WINAPI
186 DdWaitForVerticalBlank(LPDDHAL_WAITFORVERTICALBLANKDATA WaitForVerticalBlank)
187 {
188 /* Call win32k */
189 return NtGdiDdWaitForVerticalBlank(GetDdHandle(
190 WaitForVerticalBlank->lpDD->hDD),
191 (PDD_WAITFORVERTICALBLANKDATA)
192 WaitForVerticalBlank);
193 }
194
195 DWORD
196 WINAPI
197 DdCanCreateSurface(LPDDHAL_CANCREATESURFACEDATA CanCreateSurface)
198 {
199 /* Call win32k */
200 return NtGdiDdCanCreateSurface(GetDdHandle(CanCreateSurface->lpDD->hDD),
201 (PDD_CANCREATESURFACEDATA)CanCreateSurface);
202 }
203
204 DWORD
205 APIENTRY
206 DdCreateSurface(LPDDHAL_CREATESURFACEDATA pCreateSurface)
207 {
208 DWORD Return = DDHAL_DRIVER_NOTHANDLED;
209 ULONG SurfaceCount = pCreateSurface->dwSCnt;
210 DD_SURFACE_LOCAL DdSurfaceLocal;
211 DD_SURFACE_MORE DdSurfaceMore;
212 DD_SURFACE_GLOBAL DdSurfaceGlobal;
213
214 HANDLE hPrevSurface, hSurface;
215
216
217 PDD_SURFACE_LOCAL pDdSurfaceLocal = NULL;
218 PDD_SURFACE_MORE pDdSurfaceMore = NULL;
219 PDD_SURFACE_GLOBAL pDdSurfaceGlobal = NULL;
220
221 PDD_SURFACE_LOCAL ptmpDdSurfaceLocal = NULL;
222 PDD_SURFACE_MORE ptmpDdSurfaceMore = NULL;
223 PDD_SURFACE_GLOBAL ptmpDdSurfaceGlobal = NULL;
224 PHANDLE phSurface = NULL, puhSurface = NULL;
225 ULONG i;
226 LPDDSURFACEDESC pSurfaceDesc = NULL;
227
228 /* Check how many surfaces there are */
229 if (SurfaceCount != 1)
230 {
231 /* We'll have to allocate more data, our stack isn't big enough */
232
233 }
234 else
235 {
236 /* We'll use what we have on the stack */
237 pDdSurfaceLocal = &DdSurfaceLocal;
238 pDdSurfaceMore = &DdSurfaceMore;
239 pDdSurfaceGlobal = &DdSurfaceGlobal;
240 phSurface = &hPrevSurface;
241 puhSurface = &hSurface;
242
243 /* Clear the structures */
244 RtlZeroMemory(&DdSurfaceLocal, sizeof(DdSurfaceLocal));
245 RtlZeroMemory(&DdSurfaceGlobal, sizeof(DdSurfaceGlobal));
246 RtlZeroMemory(&DdSurfaceMore, sizeof(DdSurfaceMore));
247 }
248
249 /* check if we got a surface or not */
250 if (SurfaceCount!=0)
251 {
252 /* Loop for each surface */
253 ptmpDdSurfaceGlobal = pDdSurfaceGlobal;
254 ptmpDdSurfaceLocal = pDdSurfaceLocal;
255 ptmpDdSurfaceMore = pDdSurfaceMore;
256 pSurfaceDesc = pCreateSurface->lpDDSurfaceDesc;
257
258 for (i = 0; i < SurfaceCount; i++)
259 {
260 LPDDRAWI_DDRAWSURFACE_LCL lcl = pCreateSurface->lplpSList[i];
261 LPDDRAWI_DDRAWSURFACE_GBL gpl = pCreateSurface->lplpSList[i]->lpGbl;
262
263 phSurface[i] = (HANDLE)lcl->hDDSurface;
264 ptmpDdSurfaceLocal->ddsCaps.dwCaps = lcl->ddsCaps.dwCaps;
265
266 ptmpDdSurfaceLocal->dwFlags = (ptmpDdSurfaceLocal->dwFlags &
267 (0xB0000000 | DDRAWISURF_INMASTERSPRITELIST |
268 DDRAWISURF_HELCB | DDRAWISURF_FRONTBUFFER |
269 DDRAWISURF_BACKBUFFER | DDRAWISURF_INVALID |
270 DDRAWISURF_DCIBUSY | DDRAWISURF_DCILOCK)) |
271 (lcl->dwFlags & DDRAWISURF_DRIVERMANAGED);
272
273 ptmpDdSurfaceGlobal->wWidth = gpl->wWidth;
274 ptmpDdSurfaceGlobal->wHeight = gpl->wHeight;
275 ptmpDdSurfaceGlobal->lPitch = gpl->lPitch;
276 ptmpDdSurfaceGlobal->fpVidMem = gpl->fpVidMem;
277 ptmpDdSurfaceGlobal->dwBlockSizeX = gpl->dwBlockSizeX;
278 ptmpDdSurfaceGlobal->dwBlockSizeY = gpl->dwBlockSizeY;
279
280 if (lcl->dwFlags & DDRAWISURF_HASPIXELFORMAT)
281 {
282 RtlCopyMemory( &ptmpDdSurfaceGlobal->ddpfSurface ,
283 &gpl->ddpfSurface,
284 sizeof(DDPIXELFORMAT));
285
286 ptmpDdSurfaceGlobal->ddpfSurface.dwSize = sizeof(DDPIXELFORMAT);
287 }
288 else
289 {
290 RtlCopyMemory( &ptmpDdSurfaceGlobal->ddpfSurface ,
291 &gpl->lpDD->vmiData.ddpfDisplay,
292 sizeof(DDPIXELFORMAT));
293 }
294
295 if (lcl->lpSurfMore)
296 {
297 ptmpDdSurfaceMore->ddsCapsEx.dwCaps2 = lcl->lpSurfMore->ddsCapsEx.dwCaps2;
298 ptmpDdSurfaceMore->ddsCapsEx.dwCaps3 = lcl->lpSurfMore->ddsCapsEx.dwCaps3;
299 ptmpDdSurfaceMore->ddsCapsEx.dwCaps4 = lcl->lpSurfMore->ddsCapsEx.dwCaps4;
300 ptmpDdSurfaceMore->dwSurfaceHandle = (DWORD) pCreateSurface->lplpSList[i]->dbnOverlayNode.object_int;
301 }
302
303 /* FIXME count to next SurfaceCount for
304 ptmpDdSurfaceGlobal = pDdSurfaceGlobal;
305 ptmpDdSurfaceLocal = pDdSurfaceLocal;
306 ptmpDdSurfaceMore = pDdSurfaceMore;
307
308 we only support one surface create at moment
309 */
310 }
311 }
312
313 /* Call win32k now */
314 pCreateSurface->ddRVal = DDERR_GENERIC;
315
316 Return = NtGdiDdCreateSurface(GetDdHandle(pCreateSurface->lpDD->hDD),
317 (HANDLE *)phSurface,
318 pSurfaceDesc,
319 pDdSurfaceGlobal,
320 pDdSurfaceLocal,
321 pDdSurfaceMore,
322 (PDD_CREATESURFACEDATA)pCreateSurface,
323 puhSurface);
324
325 if (SurfaceCount == 0)
326 {
327 pCreateSurface->ddRVal = DDERR_GENERIC;
328 }
329 else
330 {
331 ptmpDdSurfaceMore = pDdSurfaceMore;
332 ptmpDdSurfaceGlobal = pDdSurfaceGlobal;
333 ptmpDdSurfaceLocal = pDdSurfaceLocal;
334
335 for (i=0;i<SurfaceCount;i++)
336 {
337 LPDDRAWI_DDRAWSURFACE_LCL lcl = pCreateSurface->lplpSList[i];
338 LPDDRAWI_DDRAWSURFACE_GBL gpl = pCreateSurface->lplpSList[i]->lpGbl;
339
340 gpl->lPitch = ptmpDdSurfaceGlobal->lPitch;
341 gpl->fpVidMem = ptmpDdSurfaceGlobal->fpVidMem;
342 gpl->dwBlockSizeX = ptmpDdSurfaceGlobal->dwBlockSizeX;
343 gpl->dwBlockSizeY = ptmpDdSurfaceGlobal->dwBlockSizeY;
344
345 if (lcl->dwFlags & DDRAWISURF_HASPIXELFORMAT)
346 {
347 RtlCopyMemory( &gpl->ddpfSurface, &ptmpDdSurfaceGlobal->ddpfSurface , sizeof(DDPIXELFORMAT));
348 }
349
350 if (pCreateSurface->ddRVal != DD_OK)
351 {
352 gpl->fpVidMem = 0;
353 if (lcl->hDDSurface)
354 {
355 NtGdiDdDeleteSurfaceObject( (HANDLE)lcl->hDDSurface);
356 }
357 lcl->hDDSurface = 0;
358 }
359 else
360 {
361
362 lcl->hDDSurface = (ULONG_PTR) puhSurface[i];
363 }
364
365 lcl->ddsCaps.dwCaps = ptmpDdSurfaceLocal->ddsCaps.dwCaps;
366 if (lcl->lpSurfMore)
367 {
368 lcl->lpSurfMore->ddsCapsEx.dwCaps2 = ptmpDdSurfaceMore->ddsCapsEx.dwCaps2;
369 lcl->lpSurfMore->ddsCapsEx.dwCaps3 = ptmpDdSurfaceMore->ddsCapsEx.dwCaps3;
370 lcl->lpSurfMore->ddsCapsEx.dwCaps4 = ptmpDdSurfaceMore->ddsCapsEx.dwCaps4;
371 }
372 /* FIXME count to next SurfaceCount for
373 ptmpDdSurfaceGlobal = pDdSurfaceGlobal;
374 ptmpDdSurfaceLocal = pDdSurfaceLocal;
375 ptmpDdSurfaceMore = pDdSurfaceMore;
376 we only support one surface create at moment
377 */
378 }
379 }
380
381 /* Check if we have to free all our local allocations */
382 if (SurfaceCount > 1)
383 {
384 /* FIXME: */
385 }
386
387 /* Return */
388 return Return;
389 }
390
391 DWORD
392 APIENTRY
393 DdSetColorKey(LPDDHAL_SETCOLORKEYDATA pSetColorKey)
394 {
395 /* Call win32k */
396 return NtGdiDdSetColorKey((HANDLE)pSetColorKey->lpDDSurface->hDDSurface,
397 (PDD_SETCOLORKEYDATA)pSetColorKey);
398 }
399
400 DWORD
401 APIENTRY
402 DdGetScanLine(LPDDHAL_GETSCANLINEDATA pGetScanLine)
403 {
404 /* Call win32k */
405 return NtGdiDdGetScanLine(GetDdHandle(pGetScanLine->lpDD->hDD),
406 (PDD_GETSCANLINEDATA)pGetScanLine);
407 }
408
409 /* PRIVATE FUNCTIONS *********************************************************/
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 = CreateDCW(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 }
835
836
837 /*
838 * @implemented
839 *
840 * GDIEntry 5
841 */
842 BOOL
843 WINAPI
844 DdDeleteSurfaceObject(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal)
845 {
846 BOOL Return = FALSE;
847
848 /* Make sure there is one */
849 if (pSurfaceLocal->hDDSurface)
850 {
851 /* Delete it */
852 Return = NtGdiDdDeleteSurfaceObject((HANDLE)pSurfaceLocal->hDDSurface);
853 pSurfaceLocal->hDDSurface = 0;
854 }
855
856 return Return;
857 }
858
859 /*
860 * @implemented
861 *
862 * GDIEntry 6
863 */
864 BOOL
865 WINAPI
866 DdResetVisrgn(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
867 HWND hWnd)
868 {
869 /* Call win32k directly */
870 return NtGdiDdResetVisrgn((HANDLE) pSurfaceLocal->hDDSurface, hWnd);
871 }
872
873 /*
874 * @implemented
875 *
876 * GDIEntry 7
877 */
878 HDC
879 WINAPI
880 DdGetDC(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
881 LPPALETTEENTRY pColorTable)
882 {
883 /* Call win32k directly */
884 return NtGdiDdGetDC(pColorTable, (HANDLE) pSurfaceLocal->hDDSurface);
885 }
886
887 /*
888 * @implemented
889 *
890 * GDIEntry 8
891 */
892 BOOL
893 WINAPI
894 DdReleaseDC(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal)
895 {
896 /* Call win32k directly */
897 return NtGdiDdReleaseDC((HANDLE) pSurfaceLocal->hDDSurface);
898 }
899
900 /*
901 * @unimplemented
902 * GDIEntry 9
903 */
904 HBITMAP
905 STDCALL
906 DdCreateDIBSection(HDC hdc,
907 CONST BITMAPINFO *pbmi,
908 UINT iUsage,
909 VOID **ppvBits,
910 HANDLE hSectionApp,
911 DWORD dwOffset)
912 {
913 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
914 return 0;
915 }
916
917 /*
918 * @implemented
919 *
920 * GDIEntry 10
921 */
922 BOOL
923 WINAPI
924 DdReenableDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
925 BOOL *pbNewMode)
926 {
927 /* Call win32k directly */
928 return NtGdiDdReenableDirectDrawObject(GetDdHandle(pDirectDrawGlobal->hDD),
929 pbNewMode);
930 }
931
932
933 /*
934 * @implemented
935 *
936 * GDIEntry 11
937 */
938 BOOL
939 STDCALL
940 DdAttachSurface( LPDDRAWI_DDRAWSURFACE_LCL pSurfaceFrom,
941 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceTo)
942 {
943 /* Create Surface if it does not exits one */
944 if (!pSurfaceFrom->hDDSurface)
945 {
946 if (!bDDCreateSurface(pSurfaceFrom, FALSE))
947 {
948 return FALSE;
949 }
950 }
951
952 /* Create Surface if it does not exits one */
953 if (!pSurfaceTo->hDDSurface)
954 {
955 if (!bDDCreateSurface(pSurfaceTo, FALSE))
956 {
957 return FALSE;
958 }
959 }
960
961 /* Call win32k */
962 return NtGdiDdAttachSurface((HANDLE)pSurfaceFrom->hDDSurface,
963 (HANDLE)pSurfaceTo->hDDSurface);
964 }
965
966 /*
967 * @implemented
968 *
969 * GDIEntry 12
970 */
971 VOID
972 STDCALL
973 DdUnattachSurface(LPDDRAWI_DDRAWSURFACE_LCL pSurface,
974 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceAttached)
975 {
976 /* Call win32k */
977 NtGdiDdUnattachSurface((HANDLE)pSurface->hDDSurface,
978 (HANDLE)pSurfaceAttached->hDDSurface);
979 }
980
981 /*
982 * @implemented
983 *
984 * GDIEntry 13
985 */
986 ULONG
987 STDCALL
988 DdQueryDisplaySettingsUniqueness()
989 {
990 return GdiSharedHandleTable->flDeviceUniq;
991 }
992
993 /*
994 * @implemented
995 *
996 * GDIEntry 14
997 */
998 HANDLE
999 WINAPI
1000 DdGetDxHandle(LPDDRAWI_DIRECTDRAW_LCL pDDraw,
1001 LPDDRAWI_DDRAWSURFACE_LCL pSurface,
1002 BOOL bRelease)
1003 {
1004 HANDLE hDD = NULL;
1005 HANDLE hSurface = (HANDLE)pSurface->hDDSurface;
1006
1007 /* Check if we already have a surface */
1008 if (!pSurface)
1009 {
1010 /* We don't have one, use the DirectDraw Object handle instead */
1011 hSurface = NULL;
1012 hDD = GetDdHandle(pDDraw->lpGbl->hDD);
1013 }
1014
1015 /* Call the API */
1016 return (HANDLE)NtGdiDdGetDxHandle(hDD, hSurface, bRelease);
1017 }
1018
1019 /*
1020 * @implemented
1021 *
1022 * GDIEntry 15
1023 */
1024 BOOL
1025 WINAPI
1026 DdSetGammaRamp(LPDDRAWI_DIRECTDRAW_LCL pDDraw,
1027 HDC hdc,
1028 LPVOID lpGammaRamp)
1029 {
1030 /* Call win32k directly */
1031 return NtGdiDdSetGammaRamp(GetDdHandle(pDDraw->lpGbl->hDD),
1032 hdc,
1033 lpGammaRamp);
1034 }
1035
1036
1037
1038
1039