Bug fix DdCreateSurface, it can now create one surface, the code are tested in window...
[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->fpVidMem;
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 /* Check if we got a list pointer */
558 if (pvmList)
559 {
560 /* Allocate memory for it */
561 VidMemList = LocalAlloc(LMEM_ZEROINIT,
562 sizeof(VIDEOMEMORY) *
563 pHalInfo->vmiData.dwNumHeaps);
564 }
565
566 /* Do the query */
567 if (!NtGdiDdQueryDirectDrawObject(GetDdHandle(pDirectDrawGlobal->hDD),
568 &HalInfo,
569 CallbackFlags,
570 &D3dCallbacks,
571 &D3dDriverData,
572 &D3dBufferCallbacks,
573 pD3dTextureFormats,
574 &dwNumHeaps,
575 VidMemList,
576 &FourCCs,
577 pdwFourCC))
578 {
579 /* We failed, free the memory and return */
580 if (VidMemList) LocalFree(VidMemList);
581 return FALSE;
582 }
583
584 /* Clear the incoming pointer */
585 RtlZeroMemory(pHalInfo, sizeof(DDHALINFO));
586
587 /* Convert all the data */
588 pHalInfo->dwSize = sizeof(DDHALINFO);
589 pHalInfo->lpDDCallbacks = pDDCallbacks;
590 pHalInfo->lpDDSurfaceCallbacks = pDDSurfaceCallbacks;
591 pHalInfo->lpDDPaletteCallbacks = pDDPaletteCallbacks;
592
593 /* Check for NT5+ D3D Data */
594 if (D3dCallbacks.dwSize && D3dDriverData.dwSize)
595 {
596 /* Write these down */
597 pHalInfo->lpD3DGlobalDriverData = (ULONG_PTR)pD3dDriverData;
598 pHalInfo->lpD3DHALCallbacks = (ULONG_PTR)pD3dCallbacks;
599
600 /* Check for Buffer Callbacks */
601 if (D3dBufferCallbacks.dwSize)
602 {
603 /* Write this one too */
604 pHalInfo->lpDDExeBufCallbacks = pD3dBufferCallbacks;
605 }
606 }
607
608 /* Continue converting the rest */
609 pHalInfo->vmiData.dwFlags = HalInfo.vmiData.dwFlags;
610 pHalInfo->vmiData.dwDisplayWidth = HalInfo.vmiData.dwDisplayWidth;
611 pHalInfo->vmiData.dwDisplayHeight = HalInfo.vmiData.dwDisplayHeight;
612 pHalInfo->vmiData.lDisplayPitch = HalInfo.vmiData.lDisplayPitch;
613 pHalInfo->vmiData.fpPrimary = 0;
614
615 RtlCopyMemory( &pHalInfo->vmiData.ddpfDisplay,
616 &HalInfo.vmiData.ddpfDisplay,
617 sizeof(DDPIXELFORMAT));
618
619 pHalInfo->vmiData.dwOffscreenAlign = HalInfo.vmiData.dwOffscreenAlign;
620 pHalInfo->vmiData.dwOverlayAlign = HalInfo.vmiData.dwOverlayAlign;
621 pHalInfo->vmiData.dwTextureAlign = HalInfo.vmiData.dwTextureAlign;
622 pHalInfo->vmiData.dwZBufferAlign = HalInfo.vmiData.dwZBufferAlign;
623 pHalInfo->vmiData.dwAlphaAlign = HalInfo.vmiData.dwAlphaAlign;
624 pHalInfo->vmiData.dwNumHeaps = dwNumHeaps;
625 pHalInfo->vmiData.pvmList = pvmList;
626
627 RtlCopyMemory( &pHalInfo->ddCaps, &HalInfo.ddCaps,sizeof(DDCORECAPS ));
628
629 pHalInfo->ddCaps.dwNumFourCCCodes = FourCCs;
630 pHalInfo->lpdwFourCC = pdwFourCC;
631 pHalInfo->ddCaps.dwRops[6] = 0x1000;
632
633 /* FIXME implement DdGetDriverInfo */
634 // pHalInfo->dwFlags = HalInfo.dwFlags | DDHALINFO_GETDRIVERINFOSET;
635 // pHalInfo->GetDriverInfo = DdGetDriverInfo;
636
637 /* Now check if we got any DD callbacks */
638 if (pDDCallbacks)
639 {
640 /* Zero the structure */
641 RtlZeroMemory(pDDCallbacks, sizeof(DDHAL_DDCALLBACKS));
642
643 /* Set the flags for this structure */
644 Flags = CallbackFlags[0];
645
646 /* Write the header */
647 pDDCallbacks->dwSize = sizeof(DDHAL_DDCALLBACKS);
648 pDDCallbacks->dwFlags = Flags;
649
650 /* Now write the pointers, if applicable */
651 if (Flags & DDHAL_CB32_CREATESURFACE)
652 {
653 pDDCallbacks->CreateSurface = DdCreateSurface;
654 }
655 if (Flags & DDHAL_CB32_WAITFORVERTICALBLANK)
656 {
657 pDDCallbacks->WaitForVerticalBlank = DdWaitForVerticalBlank;
658 }
659 if (Flags & DDHAL_CB32_CANCREATESURFACE)
660 {
661 pDDCallbacks->CanCreateSurface = DdCanCreateSurface;
662 }
663 if (Flags & DDHAL_CB32_GETSCANLINE)
664 {
665 pDDCallbacks->GetScanLine = DdGetScanLine;
666 }
667 }
668
669 /* Check for DD Surface Callbacks */
670 if (pDDSurfaceCallbacks)
671 {
672 /* Zero the structures */
673 RtlZeroMemory(pDDSurfaceCallbacks, sizeof(DDHAL_DDSURFACECALLBACKS));
674
675 /* Set the flags for this one */
676 Flags = CallbackFlags[1];
677
678 /* Write the header, note that some functions are always exposed */
679 pDDSurfaceCallbacks->dwSize = sizeof(DDHAL_DDSURFACECALLBACKS);
680
681 pDDSurfaceCallbacks->dwFlags = Flags;
682 /*
683 pDDSurfaceCallBacks->dwFlags = (DDHAL_SURFCB32_LOCK |
684 DDHAL_SURFCB32_UNLOCK |
685 DDHAL_SURFCB32_SETCOLORKEY |
686 DDHAL_SURFCB32_DESTROYSURFACE) | Flags;
687 */
688
689 /* Write the always-on functions */
690 pDDSurfaceCallbacks->Lock = DdLock;
691 pDDSurfaceCallbacks->Unlock = DdUnlock;
692 pDDSurfaceCallbacks->SetColorKey = DdSetColorKey;
693 pDDSurfaceCallbacks->DestroySurface = DdDestroySurface;
694
695 /* Write the optional ones */
696 if (Flags & DDHAL_SURFCB32_FLIP)
697 {
698 pDDSurfaceCallbacks->Flip = DdFlip;
699 }
700 if (Flags & DDHAL_SURFCB32_BLT)
701 {
702 pDDSurfaceCallbacks->Blt = DdBlt;
703 }
704 if (Flags & DDHAL_SURFCB32_GETBLTSTATUS)
705 {
706 pDDSurfaceCallbacks->GetBltStatus = DdGetBltStatus;
707 }
708 if (Flags & DDHAL_SURFCB32_GETFLIPSTATUS)
709 {
710 pDDSurfaceCallbacks->GetFlipStatus = DdGetFlipStatus;
711 }
712 if (Flags & DDHAL_SURFCB32_UPDATEOVERLAY)
713 {
714 pDDSurfaceCallbacks->UpdateOverlay = DdUpdateOverlay;
715 }
716 if (Flags & DDHAL_SURFCB32_SETOVERLAYPOSITION)
717 {
718 pDDSurfaceCallbacks->SetOverlayPosition = DdSetOverlayPosition;
719 }
720 if (Flags & DDHAL_SURFCB32_ADDATTACHEDSURFACE)
721 {
722 pDDSurfaceCallbacks->AddAttachedSurface = DdAddAttachedSurface;
723 }
724 }
725
726 /* Check for DD Palette Callbacks */
727 if (pDDPaletteCallbacks)
728 {
729 /* Zero the struct */
730 RtlZeroMemory(pDDPaletteCallbacks, sizeof(DDHAL_DDPALETTECALLBACKS));
731
732 /* Get the flags for this one */
733 Flags = CallbackFlags[2];
734
735 /* Write the header */
736 pDDPaletteCallbacks->dwSize = sizeof(DDHAL_DDPALETTECALLBACKS);
737 pDDPaletteCallbacks->dwFlags = Flags;
738 }
739
740 /* Check for D3D Callbacks */
741 if (pD3dCallbacks)
742 {
743 /* Zero the struct */
744 RtlZeroMemory(pD3dCallbacks, sizeof(D3DHAL_CALLBACKS));
745
746 /* Check if we have one */
747 if (D3dCallbacks.dwSize)
748 {
749 /* Write the header */
750 pD3dCallbacks->dwSize = sizeof(D3DHAL_CALLBACKS);
751
752 /* Now check for each callback */
753 if (D3dCallbacks.ContextCreate)
754 {
755 /* FIXME
756 pD3dCallbacks->ContextCreate = D3dContextCreate;
757 */
758 }
759 if (D3dCallbacks.ContextDestroy)
760 {
761 pD3dCallbacks->ContextDestroy = (LPD3DHAL_CONTEXTDESTROYCB) NtGdiD3dContextDestroy;
762 }
763 if (D3dCallbacks.ContextDestroyAll)
764 {
765 /* FIXME
766 pD3dCallbacks->ContextDestroyAll = (LPD3DHAL_CONTEXTDESTROYALLCB) NtGdiD3dContextDestroyAll;
767 */
768 }
769 }
770 }
771
772 /* Check for D3D Driver Data */
773 if (pD3dDriverData)
774 {
775 /* Copy the struct */
776 RtlMoveMemory(pD3dDriverData,
777 &D3dDriverData,
778 sizeof(D3DHAL_GLOBALDRIVERDATA));
779
780 /* Write the pointer to the texture formats */
781 pD3dDriverData->lpTextureFormats = pD3dTextureFormats;
782 }
783
784 /* FIXME: Check for D3D Buffer Callbacks */
785
786 /* Check if we have a video memory list */
787 if (VidMemList)
788 {
789 /* Start a loop here */
790 PVIDEOMEMORY VidMem = VidMemList;
791
792 /* Loop all the heaps we have */
793 while (dwNumHeaps--)
794 {
795 /* Copy from one format to the other */
796 pvmList->dwFlags = VidMem->dwFlags;
797 pvmList->fpStart = VidMem->fpStart;
798 pvmList->fpEnd = VidMem->fpEnd;
799 pvmList->ddsCaps = VidMem->ddsCaps;
800 pvmList->ddsCapsAlt = VidMem->ddsCapsAlt;
801 pvmList->dwHeight = VidMem->dwHeight;
802
803 /* Advance in both structures */
804 pvmList++;
805 VidMem++;
806 }
807
808 /* Free our structure */
809 LocalFree(VidMemList);
810 }
811
812
813 return TRUE;
814 }
815
816 /*
817 * @implemented
818 *
819 * GDIEntry 3
820 */
821 BOOL
822 WINAPI
823 DdDeleteDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal)
824 {
825 BOOL Return = FALSE;
826
827 /* If this is the global object */
828 if(pDirectDrawGlobal->hDD)
829 {
830 /* Free it */
831 Return = NtGdiDdDeleteDirectDrawObject((HANDLE)pDirectDrawGlobal->hDD);
832 if (Return == TRUE)
833 {
834 pDirectDrawGlobal->hDD = 0;
835 }
836 }
837 else if (ghDirectDraw)
838 {
839 /* Always success here */
840 Return = TRUE;
841
842 /* Make sure this is the last instance */
843 if (!(--gcDirectDraw))
844 {
845 /* Delete the object */
846 Return = NtGdiDdDeleteDirectDrawObject(ghDirectDraw);
847 if (Return == TRUE)
848 {
849 ghDirectDraw = 0;
850 }
851 }
852 }
853
854 /* Return */
855 return Return;
856 }
857
858 /*
859 * @implemented
860 *
861 * GDIEntry 4
862 */
863 BOOL
864 WINAPI
865 DdCreateSurfaceObject( LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
866 BOOL bPrimarySurface)
867 {
868 return bDDCreateSurface(pSurfaceLocal, TRUE);
869 //return bDdCreateSurfaceObject(pSurfaceLocal, TRUE);
870 }
871
872
873 /*
874 * @implemented
875 *
876 * GDIEntry 5
877 */
878 BOOL
879 WINAPI
880 DdDeleteSurfaceObject(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal)
881 {
882 BOOL Return = FALSE;
883
884 /* Make sure there is one */
885 if (pSurfaceLocal->hDDSurface)
886 {
887 /* Delete it */
888 Return = NtGdiDdDeleteSurfaceObject((HANDLE)pSurfaceLocal->hDDSurface);
889 pSurfaceLocal->hDDSurface = 0;
890 }
891
892 return Return;
893 }
894
895 /*
896 * @implemented
897 *
898 * GDIEntry 6
899 */
900 BOOL
901 WINAPI
902 DdResetVisrgn(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
903 HWND hWnd)
904 {
905 /* Call win32k directly */
906 return NtGdiDdResetVisrgn((HANDLE) pSurfaceLocal->hDDSurface, hWnd);
907 }
908
909 /*
910 * @implemented
911 *
912 * GDIEntry 7
913 */
914 HDC
915 WINAPI
916 DdGetDC(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
917 LPPALETTEENTRY pColorTable)
918 {
919 /* Call win32k directly */
920 return NtGdiDdGetDC(pColorTable, (HANDLE) pSurfaceLocal->hDDSurface);
921 }
922
923 /*
924 * @implemented
925 *
926 * GDIEntry 8
927 */
928 BOOL
929 WINAPI
930 DdReleaseDC(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal)
931 {
932 /* Call win32k directly */
933 return NtGdiDdReleaseDC((HANDLE) pSurfaceLocal->hDDSurface);
934 }
935
936 /*
937 * @unimplemented
938 * GDIEntry 9
939 */
940 HBITMAP
941 STDCALL
942 DdCreateDIBSection(HDC hdc,
943 CONST BITMAPINFO *pbmi,
944 UINT iUsage,
945 VOID **ppvBits,
946 HANDLE hSectionApp,
947 DWORD dwOffset)
948 {
949 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
950 return 0;
951 }
952
953 /*
954 * @implemented
955 *
956 * GDIEntry 10
957 */
958 BOOL
959 WINAPI
960 DdReenableDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
961 BOOL *pbNewMode)
962 {
963 /* Call win32k directly */
964 return NtGdiDdReenableDirectDrawObject(GetDdHandle(pDirectDrawGlobal->hDD),
965 pbNewMode);
966 }
967
968
969 /*
970 * @implemented
971 *
972 * GDIEntry 11
973 */
974 BOOL
975 STDCALL
976 DdAttachSurface( LPDDRAWI_DDRAWSURFACE_LCL pSurfaceFrom,
977 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceTo)
978 {
979 /* Create Surface if it does not exits one */
980 if (pSurfaceFrom->hDDSurface)
981 {
982 if (!bDDCreateSurface(pSurfaceFrom, FALSE))
983 {
984 return FALSE;
985 }
986 }
987
988 /* Create Surface if it does not exits one */
989 if (pSurfaceTo->hDDSurface)
990 {
991 if (!bDDCreateSurface(pSurfaceTo, FALSE))
992 {
993 return FALSE;
994 }
995 }
996
997 /* Call win32k */
998 return NtGdiDdAttachSurface((HANDLE)pSurfaceFrom->hDDSurface,
999 (HANDLE)pSurfaceTo->hDDSurface);
1000 }
1001
1002 /*
1003 * @implemented
1004 *
1005 * GDIEntry 12
1006 */
1007 VOID
1008 STDCALL
1009 DdUnattachSurface(LPDDRAWI_DDRAWSURFACE_LCL pSurface,
1010 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceAttached)
1011 {
1012 /* Call win32k */
1013 NtGdiDdUnattachSurface((HANDLE)pSurface->hDDSurface,
1014 (HANDLE)pSurfaceAttached->hDDSurface);
1015 }
1016
1017 /*
1018 * @implemented
1019 *
1020 * GDIEntry 13
1021 */
1022 ULONG
1023 STDCALL
1024 DdQueryDisplaySettingsUniqueness()
1025 {
1026 return RemberDdQueryDisplaySettingsUniquenessID;
1027 }
1028
1029 /*
1030 * @implemented
1031 *
1032 * GDIEntry 14
1033 */
1034 HANDLE
1035 WINAPI
1036 DdGetDxHandle(LPDDRAWI_DIRECTDRAW_LCL pDDraw,
1037 LPDDRAWI_DDRAWSURFACE_LCL pSurface,
1038 BOOL bRelease)
1039 {
1040 HANDLE hDD = NULL;
1041 HANDLE hSurface = (HANDLE)pSurface->hDDSurface;
1042
1043 /* Check if we already have a surface */
1044 if (!pSurface)
1045 {
1046 /* We don't have one, use the DirectDraw Object handle instead */
1047 hSurface = NULL;
1048 hDD = GetDdHandle(pDDraw->lpGbl->hDD);
1049 }
1050
1051 /* Call the API */
1052 return (HANDLE)NtGdiDdGetDxHandle(hDD, hSurface, bRelease);
1053 }
1054
1055 /*
1056 * @implemented
1057 *
1058 * GDIEntry 15
1059 */
1060 BOOL
1061 WINAPI
1062 DdSetGammaRamp(LPDDRAWI_DIRECTDRAW_LCL pDDraw,
1063 HDC hdc,
1064 LPVOID lpGammaRamp)
1065 {
1066 /* Call win32k directly */
1067 return NtGdiDdSetGammaRamp(GetDdHandle(pDDraw->lpGbl->hDD),
1068 hdc,
1069 lpGammaRamp);
1070 }
1071 /*
1072 * @implemented
1073 *
1074 * GDIEntry 16
1075 */
1076 DWORD
1077 WINAPI
1078 DdSwapTextureHandles(LPDDRAWI_DIRECTDRAW_LCL pDDraw,
1079 LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl1,
1080 LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl2)
1081 {
1082 /* Always returns success */
1083 return TRUE;
1084 }
1085
1086
1087
1088