forget clear a value in gdientry2
[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 HANDLE hPrevSurface, hSurface;
213 DD_SURFACE_LOCAL* pDdSurfaceLocal;
214 DD_SURFACE_MORE* pDdSurfaceMore;
215 DD_SURFACE_GLOBAL* pDdSurfaceGlobal;
216 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal;
217 //LPDDRAWI_DDRAWSURFACE_MORE pSurfaceMore;
218 LPDDRAWI_DDRAWSURFACE_GBL pSurfaceGlobal;
219 PHANDLE phSurface = NULL, puhSurface = NULL;
220 ULONG i;
221 LPDDSURFACEDESC pSurfaceDesc;
222
223 /* Check how many surfaces there are */
224 if (SurfaceCount != 1)
225 {
226 /* We'll have to allocate more data, our stack isn't big enough */
227
228 }
229 else
230 {
231 /* We'll use what we have on the stack */
232 pDdSurfaceLocal = &DdSurfaceLocal;
233 pDdSurfaceMore = &DdSurfaceMore;
234 pDdSurfaceGlobal = &DdSurfaceGlobal;
235 phSurface = &hPrevSurface;
236 puhSurface = &hSurface;
237
238 /* Clear the structures */
239 RtlZeroMemory(&DdSurfaceLocal, sizeof(DdSurfaceLocal));
240 RtlZeroMemory(&DdSurfaceGlobal, sizeof(DdSurfaceGlobal));
241 RtlZeroMemory(&DdSurfaceMore, sizeof(DdSurfaceMore));
242 }
243
244 /* Loop for each surface */
245 for (i = 0; i < pCreateSurface->dwSCnt; i++)
246 {
247 /* Get data */
248 pSurfaceLocal = pCreateSurface->lplpSList[i];
249 pSurfaceGlobal = pSurfaceLocal->lpGbl;
250 pSurfaceDesc = pCreateSurface->lpDDSurfaceDesc;
251
252 /* Check if it has pixel data */
253 if (pSurfaceDesc->dwFlags & DDRAWISURF_HASPIXELFORMAT)
254 {
255 /* Use its pixel data */
256 DdSurfaceGlobal.ddpfSurface = pSurfaceDesc->ddpfPixelFormat;
257 DdSurfaceGlobal.ddpfSurface.dwSize = sizeof(DDPIXELFORMAT);
258 }
259 else
260 {
261 /* Use the one from the global surface */
262 DdSurfaceGlobal.ddpfSurface = pSurfaceGlobal->lpDD->vmiData.ddpfDisplay;
263 }
264
265 /* Convert data */
266 DdSurfaceGlobal.wWidth = pSurfaceGlobal->wWidth;
267 DdSurfaceGlobal.wHeight = pSurfaceGlobal->wHeight;
268 DdSurfaceGlobal.lPitch = pSurfaceGlobal->lPitch;
269 DdSurfaceGlobal.fpVidMem = pSurfaceGlobal->fpVidMem;
270 DdSurfaceGlobal.dwBlockSizeX = pSurfaceGlobal->dwBlockSizeX;
271 DdSurfaceGlobal.dwBlockSizeY = pSurfaceGlobal->dwBlockSizeY;
272 // DdSurfaceGlobal.ddsCaps = pSurfaceLocal->ddsCaps | 0xBF0000;
273
274 /* FIXME: Ddscapsex stuff missing */
275
276 /* Call win32k now */
277 pCreateSurface->ddRVal = E_FAIL;
278
279 Return = NtGdiDdCreateSurface(GetDdHandle(pCreateSurface->lpDD->hDD),
280 (HANDLE *)phSurface,
281 pSurfaceDesc,
282 &DdSurfaceGlobal,
283 &DdSurfaceLocal,
284 &DdSurfaceMore,
285 (PDD_CREATESURFACEDATA)pCreateSurface,
286 puhSurface);
287
288
289 /* FIXME: Ddscapsex stuff missing */
290
291 /* Convert the data back */
292 pSurfaceGlobal->lPitch = DdSurfaceGlobal.lPitch;
293 pSurfaceGlobal->fpVidMem = DdSurfaceGlobal.fpVidMem;
294 pSurfaceGlobal->dwBlockSizeX = DdSurfaceGlobal.dwBlockSizeX;
295 pSurfaceGlobal->dwBlockSizeY = DdSurfaceGlobal.dwBlockSizeY;
296 pCreateSurface->lplpSList[i]->hDDSurface = (DWORD) hSurface;
297
298 /* FIXME: Ddscapsex stuff missing */
299 }
300
301 /* Check if we have to free all our local allocations */
302 if (SurfaceCount > 1)
303 {
304 /* FIXME: */
305 }
306
307 /* Return */
308 return Return;
309 }
310
311 DWORD
312 APIENTRY
313 DdSetColorKey(LPDDHAL_SETCOLORKEYDATA pSetColorKey)
314 {
315 /* Call win32k */
316 return NtGdiDdSetColorKey((HANDLE)pSetColorKey->lpDDSurface->hDDSurface,
317 (PDD_SETCOLORKEYDATA)pSetColorKey);
318 }
319
320 DWORD
321 APIENTRY
322 DdGetScanLine(LPDDHAL_GETSCANLINEDATA pGetScanLine)
323 {
324 /* Call win32k */
325 return NtGdiDdGetScanLine(GetDdHandle(pGetScanLine->lpDD->hDD),
326 (PDD_GETSCANLINEDATA)pGetScanLine);
327 }
328
329 /* PRIVATE FUNCTIONS *********************************************************/
330 static ULONG RemberDdQueryDisplaySettingsUniquenessID = 0;
331
332 BOOL
333 WINAPI
334 bDDCreateSurface(LPDDRAWI_DDRAWSURFACE_LCL pSurface,
335 BOOL bComplete)
336 {
337 DD_SURFACE_LOCAL SurfaceLocal;
338 DD_SURFACE_GLOBAL SurfaceGlobal;
339 DD_SURFACE_MORE SurfaceMore;
340
341 /* Zero struct */
342 RtlZeroMemory(&SurfaceLocal, sizeof(DD_SURFACE_LOCAL));
343 RtlZeroMemory(&SurfaceGlobal, sizeof(DD_SURFACE_GLOBAL));
344 RtlZeroMemory(&SurfaceMore, sizeof(DD_SURFACE_MORE));
345
346 /* Set up SurfaceLocal struct */
347 SurfaceLocal.ddsCaps.dwCaps = pSurface->ddsCaps.dwCaps;
348 SurfaceLocal.dwFlags = pSurface->dwFlags;
349
350 /* Set up SurfaceMore struct */
351 RtlMoveMemory(&SurfaceMore.ddsCapsEx,
352 &pSurface->ddckCKDestBlt,
353 sizeof(DDSCAPSEX));
354 SurfaceMore.dwSurfaceHandle = (DWORD)pSurface->dbnOverlayNode.object_int->lpVtbl;
355
356 /* Set up SurfaceGlobal struct */
357 SurfaceGlobal.fpVidMem = pSurface->lpGbl->fpVidMem;
358 SurfaceGlobal.dwLinearSize = pSurface->lpGbl->dwLinearSize;
359 SurfaceGlobal.wHeight = pSurface->lpGbl->wHeight;
360 SurfaceGlobal.wWidth = pSurface->lpGbl->wWidth;
361
362 /* Check if we have a pixel format */
363 if (pSurface->dwFlags & DDSD_PIXELFORMAT)
364 {
365 /* Use global one */
366 SurfaceGlobal.ddpfSurface = pSurface->lpGbl->lpDD->vmiData.ddpfDisplay;
367 SurfaceGlobal.ddpfSurface.dwSize = sizeof(DDPIXELFORMAT);
368 }
369 else
370 {
371 /* Use local one */
372 SurfaceGlobal.ddpfSurface = pSurface->lpGbl->lpDD->vmiData.ddpfDisplay;
373 }
374
375 /* Create the object */
376 pSurface->hDDSurface = (DWORD)NtGdiDdCreateSurfaceObject(GetDdHandle(pSurface->lpGbl->lpDD->hDD),
377 (HANDLE)pSurface->hDDSurface,
378 &SurfaceLocal,
379 &SurfaceMore,
380 &SurfaceGlobal,
381 bComplete);
382
383 /* Return status */
384 if (pSurface->hDDSurface) return TRUE;
385 return FALSE;
386 }
387
388 /* PUBLIC FUNCTIONS **********************************************************/
389
390 /*
391 * @implemented
392 *
393 * GDIEntry 1
394 */
395 BOOL
396 WINAPI
397 DdCreateDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
398 HDC hdc)
399 {
400 BOOL Return = FALSE;
401
402 /* Check if the global hDC (hdc == 0) is being used */
403 if (!hdc)
404 {
405 /* We'll only allow this if the global object doesn't exist yet */
406 if (!ghDirectDraw)
407 {
408 /* Create the DC */
409 if ((hdc = CreateDC(L"Display", NULL, NULL, NULL)))
410 {
411 /* Create the DDraw Object */
412 ghDirectDraw = NtGdiDdCreateDirectDrawObject(hdc);
413
414 /* Delete our DC */
415 NtGdiDeleteObjectApp(hdc);
416 }
417 }
418
419 /* If we created the object, or had one ...*/
420 if (ghDirectDraw)
421 {
422 /* Increase count and set success */
423 gcDirectDraw++;
424 Return = TRUE;
425 }
426
427 /* Zero the handle */
428 pDirectDrawGlobal->hDD = 0;
429 }
430 else
431 {
432 /* Using the per-process object, so create it */
433 pDirectDrawGlobal->hDD = (ULONG_PTR)NtGdiDdCreateDirectDrawObject(hdc);
434
435 /* Set the return value */
436 Return = pDirectDrawGlobal->hDD ? TRUE : FALSE;
437 }
438
439 /* Return to caller */
440 return Return;
441 }
442
443 /*
444 * @implemented
445 *
446 * GDIEntry 2
447 */
448 BOOL
449 WINAPI
450 DdQueryDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
451 LPDDHALINFO pHalInfo,
452 LPDDHAL_DDCALLBACKS pDDCallbacks,
453 LPDDHAL_DDSURFACECALLBACKS pDDSurfaceCallbacks,
454 LPDDHAL_DDPALETTECALLBACKS pDDPaletteCallbacks,
455 LPD3DHAL_CALLBACKS pD3dCallbacks,
456 LPD3DHAL_GLOBALDRIVERDATA pD3dDriverData,
457 LPDDHAL_DDEXEBUFCALLBACKS pD3dBufferCallbacks,
458 LPDDSURFACEDESC pD3dTextureFormats,
459 LPDWORD pdwFourCC,
460 LPVIDMEM pvmList)
461 {
462 PVIDEOMEMORY VidMemList = NULL;
463 DD_HALINFO HalInfo;
464 D3DNTHAL_CALLBACKS D3dCallbacks;
465 D3DNTHAL_GLOBALDRIVERDATA D3dDriverData;
466 DD_D3DBUFCALLBACKS D3dBufferCallbacks;
467 DWORD CallbackFlags[3];
468 DWORD dwNumHeaps=0, FourCCs=0;
469 DWORD Flags;
470
471 /* Clear the structures */
472 RtlZeroMemory(&HalInfo, sizeof(DD_HALINFO));
473 RtlZeroMemory(&D3dCallbacks, sizeof(D3DNTHAL_CALLBACKS));
474 RtlZeroMemory(&D3dDriverData, sizeof(D3DNTHAL_GLOBALDRIVERDATA));
475 RtlZeroMemory(&D3dBufferCallbacks, sizeof(DD_D3DBUFCALLBACKS));
476 RtlZeroMemory(CallbackFlags, sizeof(DWORD)*3);
477
478 /* Check if we got a list pointer */
479 if (pvmList)
480 {
481 /* Allocate memory for it */
482 VidMemList = LocalAlloc(LMEM_ZEROINIT,
483 sizeof(VIDEOMEMORY) *
484 pHalInfo->vmiData.dwNumHeaps);
485 }
486
487 /* Do the query */
488 if (!NtGdiDdQueryDirectDrawObject(GetDdHandle(pDirectDrawGlobal->hDD),
489 &HalInfo,
490 CallbackFlags,
491 &D3dCallbacks,
492 &D3dDriverData,
493 &D3dBufferCallbacks,
494 pD3dTextureFormats,
495 &dwNumHeaps,
496 VidMemList,
497 &FourCCs,
498 pdwFourCC))
499 {
500 /* We failed, free the memory and return */
501 if (VidMemList) LocalFree(VidMemList);
502 return FALSE;
503 }
504
505 /* Clear the incoming pointer */
506 RtlZeroMemory(pHalInfo, sizeof(DDHALINFO));
507
508 /* Convert all the data */
509 pHalInfo->dwSize = sizeof(DDHALINFO);
510 pHalInfo->lpDDCallbacks = pDDCallbacks;
511 pHalInfo->lpDDSurfaceCallbacks = pDDSurfaceCallbacks;
512 pHalInfo->lpDDPaletteCallbacks = pDDPaletteCallbacks;
513
514 /* Check for NT5+ D3D Data */
515 if (D3dCallbacks.dwSize && D3dDriverData.dwSize)
516 {
517 /* Write these down */
518 pHalInfo->lpD3DGlobalDriverData = (ULONG_PTR)pD3dDriverData;
519 pHalInfo->lpD3DHALCallbacks = (ULONG_PTR)pD3dCallbacks;
520
521 /* Check for Buffer Callbacks */
522 if (D3dBufferCallbacks.dwSize)
523 {
524 /* Write this one too */
525 pHalInfo->lpDDExeBufCallbacks = pD3dBufferCallbacks;
526 }
527 }
528
529 /* Continue converting the rest */
530 pHalInfo->vmiData.dwFlags = HalInfo.vmiData.dwFlags;
531 pHalInfo->vmiData.dwDisplayWidth = HalInfo.vmiData.dwDisplayWidth;
532 pHalInfo->vmiData.dwDisplayHeight = HalInfo.vmiData.dwDisplayHeight;
533 pHalInfo->vmiData.lDisplayPitch = HalInfo.vmiData.lDisplayPitch;
534 pHalInfo->vmiData.fpPrimary = 0;
535
536 RtlCopyMemory( &pHalInfo->vmiData.ddpfDisplay,
537 &HalInfo.vmiData.ddpfDisplay,
538 sizeof(DDPIXELFORMAT));
539
540 pHalInfo->vmiData.dwOffscreenAlign = HalInfo.vmiData.dwOffscreenAlign;
541 pHalInfo->vmiData.dwOverlayAlign = HalInfo.vmiData.dwOverlayAlign;
542 pHalInfo->vmiData.dwTextureAlign = HalInfo.vmiData.dwTextureAlign;
543 pHalInfo->vmiData.dwZBufferAlign = HalInfo.vmiData.dwZBufferAlign;
544 pHalInfo->vmiData.dwAlphaAlign = HalInfo.vmiData.dwAlphaAlign;
545 pHalInfo->vmiData.dwNumHeaps = dwNumHeaps;
546 pHalInfo->vmiData.pvmList = pvmList;
547
548 RtlCopyMemory( &pHalInfo->ddCaps, &HalInfo.ddCaps,sizeof(DDCORECAPS ));
549
550 pHalInfo->ddCaps.dwNumFourCCCodes = FourCCs;
551 pHalInfo->lpdwFourCC = pdwFourCC;
552 pHalInfo->ddCaps.dwRops[6] = 0x1000;
553
554 /* FIXME implement DdGetDriverInfo */
555 // pHalInfo->dwFlags = HalInfo.dwFlags | DDHALINFO_GETDRIVERINFOSET;
556 // pHalInfo->GetDriverInfo = DdGetDriverInfo;
557
558 /* Now check if we got any DD callbacks */
559 if (pDDCallbacks)
560 {
561 /* Zero the structure */
562 RtlZeroMemory(pDDCallbacks, sizeof(DDHAL_DDCALLBACKS));
563
564 /* Set the flags for this structure */
565 Flags = CallbackFlags[0];
566
567 /* Write the header */
568 pDDCallbacks->dwSize = sizeof(DDHAL_DDCALLBACKS);
569 pDDCallbacks->dwFlags = Flags;
570
571 /* Now write the pointers, if applicable */
572 if (Flags & DDHAL_CB32_CREATESURFACE)
573 {
574 pDDCallbacks->CreateSurface = DdCreateSurface;
575 }
576 if (Flags & DDHAL_CB32_WAITFORVERTICALBLANK)
577 {
578 pDDCallbacks->WaitForVerticalBlank = DdWaitForVerticalBlank;
579 }
580 if (Flags & DDHAL_CB32_CANCREATESURFACE)
581 {
582 pDDCallbacks->CanCreateSurface = DdCanCreateSurface;
583 }
584 if (Flags & DDHAL_CB32_GETSCANLINE)
585 {
586 pDDCallbacks->GetScanLine = DdGetScanLine;
587 }
588 }
589
590 /* Check for DD Surface Callbacks */
591 if (pDDSurfaceCallbacks)
592 {
593 /* Zero the structures */
594 RtlZeroMemory(pDDSurfaceCallbacks, sizeof(DDHAL_DDSURFACECALLBACKS));
595
596 /* Set the flags for this one */
597 Flags = CallbackFlags[1];
598
599 /* Write the header, note that some functions are always exposed */
600 pDDSurfaceCallbacks->dwSize = sizeof(DDHAL_DDSURFACECALLBACKS);
601
602 pDDSurfaceCallbacks->dwFlags = Flags;
603 /*
604 pDDSurfaceCallBacks->dwFlags = (DDHAL_SURFCB32_LOCK |
605 DDHAL_SURFCB32_UNLOCK |
606 DDHAL_SURFCB32_SETCOLORKEY |
607 DDHAL_SURFCB32_DESTROYSURFACE) | Flags;
608 */
609
610 /* Write the always-on functions */
611 pDDSurfaceCallbacks->Lock = DdLock;
612 pDDSurfaceCallbacks->Unlock = DdUnlock;
613 pDDSurfaceCallbacks->SetColorKey = DdSetColorKey;
614 pDDSurfaceCallbacks->DestroySurface = DdDestroySurface;
615
616 /* Write the optional ones */
617 if (Flags & DDHAL_SURFCB32_FLIP)
618 {
619 pDDSurfaceCallbacks->Flip = DdFlip;
620 }
621 if (Flags & DDHAL_SURFCB32_BLT)
622 {
623 pDDSurfaceCallbacks->Blt = DdBlt;
624 }
625 if (Flags & DDHAL_SURFCB32_GETBLTSTATUS)
626 {
627 pDDSurfaceCallbacks->GetBltStatus = DdGetBltStatus;
628 }
629 if (Flags & DDHAL_SURFCB32_GETFLIPSTATUS)
630 {
631 pDDSurfaceCallbacks->GetFlipStatus = DdGetFlipStatus;
632 }
633 if (Flags & DDHAL_SURFCB32_UPDATEOVERLAY)
634 {
635 pDDSurfaceCallbacks->UpdateOverlay = DdUpdateOverlay;
636 }
637 if (Flags & DDHAL_SURFCB32_SETOVERLAYPOSITION)
638 {
639 pDDSurfaceCallbacks->SetOverlayPosition = DdSetOverlayPosition;
640 }
641 if (Flags & DDHAL_SURFCB32_ADDATTACHEDSURFACE)
642 {
643 pDDSurfaceCallbacks->AddAttachedSurface = DdAddAttachedSurface;
644 }
645 }
646
647 /* Check for DD Palette Callbacks */
648 if (pDDPaletteCallbacks)
649 {
650 /* Zero the struct */
651 RtlZeroMemory(pDDPaletteCallbacks, sizeof(DDHAL_DDPALETTECALLBACKS));
652
653 /* Get the flags for this one */
654 Flags = CallbackFlags[2];
655
656 /* Write the header */
657 pDDPaletteCallbacks->dwSize = sizeof(DDHAL_DDPALETTECALLBACKS);
658 pDDPaletteCallbacks->dwFlags = Flags;
659 }
660
661 /* Check for D3D Callbacks */
662 if (pD3dCallbacks)
663 {
664 /* Zero the struct */
665 RtlZeroMemory(pD3dCallbacks, sizeof(D3DHAL_CALLBACKS));
666
667 /* Check if we have one */
668 if (D3dCallbacks.dwSize)
669 {
670 /* Write the header */
671 pD3dCallbacks->dwSize = sizeof(D3DHAL_CALLBACKS);
672
673 /* Now check for each callback */
674 if (D3dCallbacks.ContextCreate)
675 {
676 /* FIXME
677 pD3dCallbacks->ContextCreate = D3dContextCreate;
678 */
679 }
680 if (D3dCallbacks.ContextDestroy)
681 {
682 pD3dCallbacks->ContextDestroy = (LPD3DHAL_CONTEXTDESTROYCB) NtGdiD3dContextDestroy;
683 }
684 if (D3dCallbacks.ContextDestroyAll)
685 {
686 /* FIXME
687 pD3dCallbacks->ContextDestroyAll = (LPD3DHAL_CONTEXTDESTROYALLCB) NtGdiD3dContextDestroyAll;
688 */
689 }
690 }
691 }
692
693 /* Check for D3D Driver Data */
694 if (pD3dDriverData)
695 {
696 /* Copy the struct */
697 RtlMoveMemory(pD3dDriverData,
698 &D3dDriverData,
699 sizeof(D3DHAL_GLOBALDRIVERDATA));
700
701 /* Write the pointer to the texture formats */
702 pD3dDriverData->lpTextureFormats = pD3dTextureFormats;
703 }
704
705 /* FIXME: Check for D3D Buffer Callbacks */
706
707 /* Check if we have a video memory list */
708 if (VidMemList)
709 {
710 /* Start a loop here */
711 PVIDEOMEMORY VidMem = VidMemList;
712
713 /* Loop all the heaps we have */
714 while (dwNumHeaps--)
715 {
716 /* Copy from one format to the other */
717 pvmList->dwFlags = VidMem->dwFlags;
718 pvmList->fpStart = VidMem->fpStart;
719 pvmList->fpEnd = VidMem->fpEnd;
720 pvmList->ddsCaps = VidMem->ddsCaps;
721 pvmList->ddsCapsAlt = VidMem->ddsCapsAlt;
722 pvmList->dwHeight = VidMem->dwHeight;
723
724 /* Advance in both structures */
725 pvmList++;
726 VidMem++;
727 }
728
729 /* Free our structure */
730 LocalFree(VidMemList);
731 }
732
733
734 return TRUE;
735 }
736
737 /*
738 * @implemented
739 *
740 * GDIEntry 3
741 */
742 BOOL
743 WINAPI
744 DdDeleteDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal)
745 {
746 BOOL Return = FALSE;
747
748 /* If this is the global object */
749 if(pDirectDrawGlobal->hDD)
750 {
751 /* Free it */
752 Return = NtGdiDdDeleteDirectDrawObject((HANDLE)pDirectDrawGlobal->hDD);
753 if (Return == TRUE)
754 {
755 pDirectDrawGlobal->hDD = 0;
756 }
757 }
758 else if (ghDirectDraw)
759 {
760 /* Always success here */
761 Return = TRUE;
762
763 /* Make sure this is the last instance */
764 if (!(--gcDirectDraw))
765 {
766 /* Delete the object */
767 Return = NtGdiDdDeleteDirectDrawObject(ghDirectDraw);
768 if (Return == TRUE)
769 {
770 ghDirectDraw = 0;
771 }
772 }
773 }
774
775 /* Return */
776 return Return;
777 }
778
779 /*
780 * @implemented
781 *
782 * GDIEntry 4
783 */
784 BOOL
785 WINAPI
786 DdCreateSurfaceObject( LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
787 BOOL bPrimarySurface)
788 {
789 return bDDCreateSurface(pSurfaceLocal, TRUE);
790 //return bDdCreateSurfaceObject(pSurfaceLocal, TRUE);
791 }
792
793
794 /*
795 * @implemented
796 *
797 * GDIEntry 5
798 */
799 BOOL
800 WINAPI
801 DdDeleteSurfaceObject(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal)
802 {
803 BOOL Return = FALSE;
804
805 /* Make sure there is one */
806 if (pSurfaceLocal->hDDSurface)
807 {
808 /* Delete it */
809 Return = NtGdiDdDeleteSurfaceObject((HANDLE)pSurfaceLocal->hDDSurface);
810 pSurfaceLocal->hDDSurface = 0;
811 }
812
813 return Return;
814 }
815
816 /*
817 * @implemented
818 *
819 * GDIEntry 6
820 */
821 BOOL
822 WINAPI
823 DdResetVisrgn(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
824 HWND hWnd)
825 {
826 /* Call win32k directly */
827 return NtGdiDdResetVisrgn((HANDLE) pSurfaceLocal->hDDSurface, hWnd);
828 }
829
830 /*
831 * @implemented
832 *
833 * GDIEntry 7
834 */
835 HDC
836 WINAPI
837 DdGetDC(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
838 LPPALETTEENTRY pColorTable)
839 {
840 /* Call win32k directly */
841 return NtGdiDdGetDC(pColorTable, (HANDLE) pSurfaceLocal->hDDSurface);
842 }
843
844 /*
845 * @implemented
846 *
847 * GDIEntry 8
848 */
849 BOOL
850 WINAPI
851 DdReleaseDC(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal)
852 {
853 /* Call win32k directly */
854 return NtGdiDdReleaseDC((HANDLE) pSurfaceLocal->hDDSurface);
855 }
856
857 /*
858 * @unimplemented
859 * GDIEntry 9
860 */
861 HBITMAP
862 STDCALL
863 DdCreateDIBSection(HDC hdc,
864 CONST BITMAPINFO *pbmi,
865 UINT iUsage,
866 VOID **ppvBits,
867 HANDLE hSectionApp,
868 DWORD dwOffset)
869 {
870 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
871 return 0;
872 }
873
874 /*
875 * @implemented
876 *
877 * GDIEntry 10
878 */
879 BOOL
880 WINAPI
881 DdReenableDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
882 BOOL *pbNewMode)
883 {
884 /* Call win32k directly */
885 return NtGdiDdReenableDirectDrawObject(GetDdHandle(pDirectDrawGlobal->hDD),
886 pbNewMode);
887 }
888
889
890 /*
891 * @implemented
892 *
893 * GDIEntry 11
894 */
895 BOOL
896 STDCALL
897 DdAttachSurface( LPDDRAWI_DDRAWSURFACE_LCL pSurfaceFrom,
898 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceTo)
899 {
900 /* Create Surface if it does not exits one */
901 if (pSurfaceFrom->hDDSurface)
902 {
903 if (!bDDCreateSurface(pSurfaceFrom, FALSE))
904 {
905 return FALSE;
906 }
907 }
908
909 /* Create Surface if it does not exits one */
910 if (pSurfaceTo->hDDSurface)
911 {
912 if (!bDDCreateSurface(pSurfaceTo, FALSE))
913 {
914 return FALSE;
915 }
916 }
917
918 /* Call win32k */
919 return NtGdiDdAttachSurface((HANDLE)pSurfaceFrom->hDDSurface,
920 (HANDLE)pSurfaceTo->hDDSurface);
921 }
922
923 /*
924 * @implemented
925 *
926 * GDIEntry 12
927 */
928 VOID
929 STDCALL
930 DdUnattachSurface(LPDDRAWI_DDRAWSURFACE_LCL pSurface,
931 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceAttached)
932 {
933 /* Call win32k */
934 NtGdiDdUnattachSurface((HANDLE)pSurface->hDDSurface,
935 (HANDLE)pSurfaceAttached->hDDSurface);
936 }
937
938 /*
939 * @implemented
940 *
941 * GDIEntry 13
942 */
943 ULONG
944 STDCALL
945 DdQueryDisplaySettingsUniqueness()
946 {
947 return RemberDdQueryDisplaySettingsUniquenessID;
948 }
949
950 /*
951 * @implemented
952 *
953 * GDIEntry 14
954 */
955 HANDLE
956 WINAPI
957 DdGetDxHandle(LPDDRAWI_DIRECTDRAW_LCL pDDraw,
958 LPDDRAWI_DDRAWSURFACE_LCL pSurface,
959 BOOL bRelease)
960 {
961 HANDLE hDD = NULL;
962 HANDLE hSurface = (HANDLE)pSurface->hDDSurface;
963
964 /* Check if we already have a surface */
965 if (!pSurface)
966 {
967 /* We don't have one, use the DirectDraw Object handle instead */
968 hSurface = NULL;
969 hDD = GetDdHandle(pDDraw->lpGbl->hDD);
970 }
971
972 /* Call the API */
973 return (HANDLE)NtGdiDdGetDxHandle(hDD, hSurface, bRelease);
974 }
975
976 /*
977 * @implemented
978 *
979 * GDIEntry 15
980 */
981 BOOL
982 WINAPI
983 DdSetGammaRamp(LPDDRAWI_DIRECTDRAW_LCL pDDraw,
984 HDC hdc,
985 LPVOID lpGammaRamp)
986 {
987 /* Call win32k directly */
988 return NtGdiDdSetGammaRamp(GetDdHandle(pDDraw->lpGbl->hDD),
989 hdc,
990 lpGammaRamp);
991 }
992 /*
993 * @implemented
994 *
995 * GDIEntry 16
996 */
997 DWORD
998 WINAPI
999 DdSwapTextureHandles(LPDDRAWI_DIRECTDRAW_LCL pDDraw,
1000 LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl1,
1001 LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl2)
1002 {
1003 /* Always returns success */
1004 return TRUE;
1005 }
1006
1007
1008
1009