more code, from alex patch I got over one year ago, thanks alex for all help and...
[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;
469 DWORD Flags;
470
471 /* Check if we got a list pointer */
472 if (pvmList)
473 {
474 /* Allocate memory for it */
475 VidMemList = LocalAlloc(LMEM_ZEROINIT,
476 sizeof(VIDEOMEMORY) *
477 pHalInfo->vmiData.dwNumHeaps);
478 }
479
480 /* Clear the structures */
481 RtlZeroMemory(&HalInfo, sizeof(DD_HALINFO));
482 RtlZeroMemory(&D3dCallbacks, sizeof(D3DNTHAL_CALLBACKS));
483 RtlZeroMemory(&D3dDriverData, sizeof(D3DNTHAL_GLOBALDRIVERDATA));
484 RtlZeroMemory(&D3dBufferCallbacks, sizeof(DD_D3DBUFCALLBACKS));
485
486 //* Do the query */
487 if (!NtGdiDdQueryDirectDrawObject(GetDdHandle(pDirectDrawGlobal->hDD),
488 &HalInfo,
489 CallbackFlags,
490 &D3dCallbacks,
491 &D3dDriverData,
492 &D3dBufferCallbacks,
493 pD3dTextureFormats,
494 &dwNumHeaps,
495 VidMemList,
496 &FourCCs,
497 pdwFourCC))
498 {
499 /* We failed, free the memory and return */
500 if (VidMemList) LocalFree(VidMemList);
501 return FALSE;
502 }
503
504 /* Clear the incoming pointer */
505 RtlZeroMemory(pHalInfo, sizeof(DDHALINFO));
506
507 /* Convert all the data */
508 pHalInfo->dwSize = sizeof(DDHALINFO);
509 pHalInfo->lpDDCallbacks = pDDCallbacks;
510 pHalInfo->lpDDSurfaceCallbacks = pDDSurfaceCallbacks;
511 pHalInfo->lpDDPaletteCallbacks = pDDPaletteCallbacks;
512
513 /* Check for NT5+ D3D Data */
514 if (D3dCallbacks.dwSize && D3dDriverData.dwSize)
515 {
516 /* Write these down */
517 pHalInfo->lpD3DGlobalDriverData = (ULONG_PTR)pD3dDriverData;
518 pHalInfo->lpD3DHALCallbacks = (ULONG_PTR)pD3dCallbacks;
519
520 /* Check for Buffer Callbacks */
521 if (D3dBufferCallbacks.dwSize)
522 {
523 /* Write this one too */
524 pHalInfo->lpDDExeBufCallbacks = pD3dBufferCallbacks;
525 }
526 }
527
528 /* Continue converting the rest */
529 pHalInfo->vmiData.dwFlags = HalInfo.vmiData.dwFlags;
530 pHalInfo->vmiData.dwDisplayWidth = HalInfo.vmiData.dwDisplayWidth;
531 pHalInfo->vmiData.dwDisplayHeight = HalInfo.vmiData.dwDisplayHeight;
532 pHalInfo->vmiData.lDisplayPitch = HalInfo.vmiData.lDisplayPitch;
533 pHalInfo->vmiData.fpPrimary = 0;
534 pHalInfo->vmiData.ddpfDisplay = HalInfo.vmiData.ddpfDisplay;
535 pHalInfo->vmiData.dwOffscreenAlign = HalInfo.vmiData.dwOffscreenAlign;
536 pHalInfo->vmiData.dwOverlayAlign = HalInfo.vmiData.dwOverlayAlign;
537 pHalInfo->vmiData.dwTextureAlign = HalInfo.vmiData.dwTextureAlign;
538 pHalInfo->vmiData.dwZBufferAlign = HalInfo.vmiData.dwZBufferAlign;
539 pHalInfo->vmiData.dwAlphaAlign = HalInfo.vmiData.dwAlphaAlign;
540 pHalInfo->vmiData.dwNumHeaps = dwNumHeaps;
541 pHalInfo->vmiData.pvmList = pvmList;
542 // pHalInfo->ddCaps = HalInfo.ddCaps;
543 // pHalInfo->ddCaps.dwNumFourCCCodes = FourCCs;
544 pHalInfo->lpdwFourCC = pdwFourCC;
545 pHalInfo->ddCaps.dwRops[6] = 0x1000;
546 pHalInfo->dwFlags = HalInfo.dwFlags | DDHALINFO_GETDRIVERINFOSET;
547 // pHalInfo->GetDriverInfo = DdGetDriverInfo;
548
549 /* Now check if we got any DD callbacks */
550 if (pDDCallbacks)
551 {
552 /* Zero the structure */
553 RtlZeroMemory(pDDCallbacks, sizeof(DDHAL_DDCALLBACKS));
554
555 /* Set the flags for this structure */
556 Flags = CallbackFlags[0];
557
558 /* Write the header */
559 pDDCallbacks->dwSize = sizeof(DDHAL_DDCALLBACKS);
560 pDDCallbacks->dwFlags = Flags;
561
562 /* Now write the pointers, if applicable */
563 if (Flags & DDHAL_CB32_CREATESURFACE)
564 {
565 pDDCallbacks->CreateSurface = DdCreateSurface;
566 }
567 if (Flags & DDHAL_CB32_WAITFORVERTICALBLANK)
568 {
569 pDDCallbacks->WaitForVerticalBlank = DdWaitForVerticalBlank;
570 }
571 if (Flags & DDHAL_CB32_CANCREATESURFACE)
572 {
573 pDDCallbacks->CanCreateSurface = DdCanCreateSurface;
574 }
575 if (Flags & DDHAL_CB32_GETSCANLINE)
576 {
577 pDDCallbacks->GetScanLine = DdGetScanLine;
578 }
579 }
580
581 /* Check for DD Surface Callbacks */
582 if (pDDSurfaceCallbacks)
583 {
584 /* Zero the structures */
585 RtlZeroMemory(pDDSurfaceCallbacks, sizeof(DDHAL_DDSURFACECALLBACKS));
586
587 /* Set the flags for this one */
588 Flags = CallbackFlags[1];
589
590
591 /* Write the header, note that some functions are always exposed */
592 pDDSurfaceCallbacks->dwSize = sizeof(DDHAL_DDSURFACECALLBACKS);
593
594 pDDSurfaceCallbacks->dwFlags = Flags;
595 /*
596 pDDSurfaceCallBacks->dwFlags = (DDHAL_SURFCB32_LOCK |
597 DDHAL_SURFCB32_UNLOCK |
598 DDHAL_SURFCB32_SETCOLORKEY |
599 DDHAL_SURFCB32_DESTROYSURFACE) | Flags;
600 */
601
602 /* Write the always-on functions */
603 pDDSurfaceCallbacks->Lock = DdLock;
604 pDDSurfaceCallbacks->Unlock = DdUnlock;
605 pDDSurfaceCallbacks->SetColorKey = DdSetColorKey;
606 pDDSurfaceCallbacks->DestroySurface = DdDestroySurface;
607
608 /* Write the optional ones */
609 if (Flags & DDHAL_SURFCB32_FLIP)
610 {
611 pDDSurfaceCallbacks->Flip = DdFlip;
612 }
613 if (Flags & DDHAL_SURFCB32_BLT)
614 {
615 pDDSurfaceCallbacks->Blt = DdBlt;
616 }
617 if (Flags & DDHAL_SURFCB32_GETBLTSTATUS)
618 {
619 pDDSurfaceCallbacks->GetBltStatus = DdGetBltStatus;
620 }
621 if (Flags & DDHAL_SURFCB32_GETFLIPSTATUS)
622 {
623 pDDSurfaceCallbacks->GetFlipStatus = DdGetFlipStatus;
624 }
625 if (Flags & DDHAL_SURFCB32_UPDATEOVERLAY)
626 {
627 pDDSurfaceCallbacks->UpdateOverlay = DdUpdateOverlay;
628 }
629 if (Flags & DDHAL_SURFCB32_SETOVERLAYPOSITION)
630 {
631 pDDSurfaceCallbacks->SetOverlayPosition = DdSetOverlayPosition;
632 }
633 if (Flags & DDHAL_SURFCB32_ADDATTACHEDSURFACE)
634 {
635 pDDSurfaceCallbacks->AddAttachedSurface = DdAddAttachedSurface;
636 }
637 }
638
639 /* Check for DD Palette Callbacks */
640 if (pDDPaletteCallbacks)
641 {
642 /* Zero the struct */
643 RtlZeroMemory(pDDPaletteCallbacks, sizeof(DDHAL_DDPALETTECALLBACKS));
644
645 /* Get the flags for this one */
646 Flags = CallbackFlags[2];
647
648 /* Write the header */
649 pDDPaletteCallbacks->dwSize = sizeof(DDHAL_DDPALETTECALLBACKS);
650 pDDPaletteCallbacks->dwFlags = Flags;
651 }
652
653 /* Check for D3D Callbacks */
654 if (pD3dCallbacks)
655 {
656 /* Zero the struct */
657 RtlZeroMemory(pD3dCallbacks, sizeof(D3DHAL_CALLBACKS));
658
659 /* Check if we have one */
660 if (D3dCallbacks.dwSize)
661 {
662 /* Write the header */
663 pD3dCallbacks->dwSize = sizeof(D3DHAL_CALLBACKS);
664
665 /* Now check for each callback */
666 if (D3dCallbacks.ContextCreate)
667 {
668 /* FIXME
669 pD3dCallbacks->ContextCreate = D3dContextCreate;
670 */
671 }
672 if (D3dCallbacks.ContextDestroy)
673 {
674 pD3dCallbacks->ContextDestroy = (LPD3DHAL_CONTEXTDESTROYCB) NtGdiD3dContextDestroy;
675 }
676 if (D3dCallbacks.ContextDestroyAll)
677 {
678 /* FIXME
679 pD3dCallbacks->ContextDestroyAll = (LPD3DHAL_CONTEXTDESTROYALLCB) NtGdiD3dContextDestroyAll;
680 */
681 }
682 }
683 }
684
685 /* Check for D3D Driver Data */
686 if (pD3dDriverData)
687 {
688 /* Copy the struct */
689 RtlMoveMemory(pD3dDriverData,
690 &D3dDriverData,
691 sizeof(D3DHAL_GLOBALDRIVERDATA));
692
693 /* Write the pointer to the texture formats */
694 pD3dDriverData->lpTextureFormats = pD3dTextureFormats;
695 }
696
697 /* FIXME: Check for D3D Buffer Callbacks */
698
699 /* Check if we have a video memory list */
700 if (VidMemList)
701 {
702 /* Start a loop here */
703 PVIDEOMEMORY VidMem = VidMemList;
704
705 /* Loop all the heaps we have */
706 while (dwNumHeaps--)
707 {
708 /* Copy from one format to the other */
709 pvmList->dwFlags = VidMem->dwFlags;
710 pvmList->fpStart = VidMem->fpStart;
711 pvmList->fpEnd = VidMem->fpEnd;
712 pvmList->ddsCaps = VidMem->ddsCaps;
713 pvmList->ddsCapsAlt = VidMem->ddsCapsAlt;
714 pvmList->dwHeight = VidMem->dwHeight;
715
716 /* Advance in both structures */
717 pvmList++;
718 VidMem++;
719 }
720
721 /* Free our structure */
722 LocalFree(VidMemList);
723 }
724
725
726 return TRUE;
727 }
728
729 /*
730 * @implemented
731 *
732 * GDIEntry 3
733 */
734 BOOL
735 WINAPI
736 DdDeleteDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal)
737 {
738 BOOL Return = FALSE;
739
740 /* If this is the global object */
741 if(pDirectDrawGlobal->hDD)
742 {
743 /* Free it */
744 Return = NtGdiDdDeleteDirectDrawObject((HANDLE)pDirectDrawGlobal->hDD);
745 }
746 else if (ghDirectDraw)
747 {
748 /* Always success here */
749 Return = TRUE;
750
751 /* Make sure this is the last instance */
752 if (!(--gcDirectDraw))
753 {
754 /* Delete the object */
755 Return = NtGdiDdDeleteDirectDrawObject(ghDirectDraw);
756 ghDirectDraw = 0;
757 }
758 }
759
760 /* Return */
761 return Return;
762 }
763
764 /*
765 * @implemented
766 *
767 * GDIEntry 4
768 */
769 BOOL
770 WINAPI
771 DdCreateSurfaceObject( LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
772 BOOL bPrimarySurface)
773 {
774 return bDDCreateSurface(pSurfaceLocal, TRUE);
775 //return bDdCreateSurfaceObject(pSurfaceLocal, TRUE);
776 }
777
778
779 /*
780 * @implemented
781 *
782 * GDIEntry 5
783 */
784 BOOL
785 WINAPI
786 DdDeleteSurfaceObject(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal)
787 {
788 BOOL Return = FALSE;
789
790 /* Make sure there is one */
791 if (pSurfaceLocal->hDDSurface)
792 {
793 /* Delete it */
794 Return = NtGdiDdDeleteSurfaceObject((HANDLE)pSurfaceLocal->hDDSurface);
795 pSurfaceLocal->hDDSurface = 0;
796 }
797
798 return Return;
799 }
800
801 /*
802 * @implemented
803 *
804 * GDIEntry 6
805 */
806 BOOL
807 WINAPI
808 DdResetVisrgn(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
809 HWND hWnd)
810 {
811 /* Call win32k directly */
812 return NtGdiDdResetVisrgn((HANDLE) pSurfaceLocal->hDDSurface, hWnd);
813 }
814
815 /*
816 * @implemented
817 *
818 * GDIEntry 7
819 */
820 HDC
821 WINAPI
822 DdGetDC(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
823 LPPALETTEENTRY pColorTable)
824 {
825 /* Call win32k directly */
826 return NtGdiDdGetDC(pColorTable, (HANDLE) pSurfaceLocal->hDDSurface);
827 }
828
829 /*
830 * @implemented
831 *
832 * GDIEntry 8
833 */
834 BOOL
835 WINAPI
836 DdReleaseDC(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal)
837 {
838 /* Call win32k directly */
839 return NtGdiDdReleaseDC((HANDLE) pSurfaceLocal->hDDSurface);
840 }
841
842 /*
843 * @unimplemented
844 * GDIEntry 9
845 */
846 HBITMAP
847 STDCALL
848 DdCreateDIBSection(HDC hdc,
849 CONST BITMAPINFO *pbmi,
850 UINT iUsage,
851 VOID **ppvBits,
852 HANDLE hSectionApp,
853 DWORD dwOffset)
854 {
855 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
856 return 0;
857 }
858
859 /*
860 * @implemented
861 *
862 * GDIEntry 10
863 */
864 BOOL
865 WINAPI
866 DdReenableDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
867 BOOL *pbNewMode)
868 {
869 /* Call win32k directly */
870 return NtGdiDdReenableDirectDrawObject(GetDdHandle(pDirectDrawGlobal->hDD),
871 pbNewMode);
872 }
873
874
875 /*
876 * @implemented
877 *
878 * GDIEntry 11
879 */
880 BOOL
881 STDCALL
882 DdAttachSurface( LPDDRAWI_DDRAWSURFACE_LCL pSurfaceFrom,
883 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceTo)
884 {
885 /* Create Surface if it does not exits one */
886 if (pSurfaceFrom->hDDSurface)
887 {
888 if (!bDDCreateSurface(pSurfaceFrom, FALSE))
889 {
890 return FALSE;
891 }
892 }
893
894 /* Create Surface if it does not exits one */
895 if (pSurfaceTo->hDDSurface)
896 {
897 if (!bDDCreateSurface(pSurfaceTo, FALSE))
898 {
899 return FALSE;
900 }
901 }
902
903 /* Call win32k */
904 return NtGdiDdAttachSurface((HANDLE)pSurfaceFrom->hDDSurface,
905 (HANDLE)pSurfaceTo->hDDSurface);
906 }
907
908 /*
909 * @implemented
910 *
911 * GDIEntry 12
912 */
913 VOID
914 STDCALL
915 DdUnattachSurface(LPDDRAWI_DDRAWSURFACE_LCL pSurface,
916 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceAttached)
917 {
918 /* Call win32k */
919 NtGdiDdUnattachSurface((HANDLE)pSurface->hDDSurface,
920 (HANDLE)pSurfaceAttached->hDDSurface);
921 }
922
923 /*
924 * @implemented
925 *
926 * GDIEntry 13
927 */
928 ULONG
929 STDCALL
930 DdQueryDisplaySettingsUniqueness()
931 {
932 return RemberDdQueryDisplaySettingsUniquenessID;
933 }
934
935 /*
936 * @implemented
937 *
938 * GDIEntry 14
939 */
940 HANDLE
941 WINAPI
942 DdGetDxHandle(LPDDRAWI_DIRECTDRAW_LCL pDDraw,
943 LPDDRAWI_DDRAWSURFACE_LCL pSurface,
944 BOOL bRelease)
945 {
946 HANDLE hDD = NULL;
947 HANDLE hSurface = (HANDLE)pSurface->hDDSurface;
948
949 /* Check if we already have a surface */
950 if (!pSurface)
951 {
952 /* We don't have one, use the DirectDraw Object handle instead */
953 hSurface = NULL;
954 hDD = GetDdHandle(pDDraw->lpGbl->hDD);
955 }
956
957 /* Call the API */
958 return (HANDLE)NtGdiDdGetDxHandle(hDD, hSurface, bRelease);
959 }
960
961 /*
962 * @implemented
963 *
964 * GDIEntry 15
965 */
966 BOOL
967 WINAPI
968 DdSetGammaRamp(LPDDRAWI_DIRECTDRAW_LCL pDDraw,
969 HDC hdc,
970 LPVOID lpGammaRamp)
971 {
972 /* Call win32k directly */
973 return NtGdiDdSetGammaRamp(GetDdHandle(pDDraw->lpGbl->hDD),
974 hdc,
975 lpGammaRamp);
976 }
977 /*
978 * @implemented
979 *
980 * GDIEntry 16
981 */
982 DWORD
983 WINAPI
984 DdSwapTextureHandles(LPDDRAWI_DIRECTDRAW_LCL pDDraw,
985 LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl1,
986 LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl2)
987 {
988 /* Always returns success */
989 return TRUE;
990 }
991
992
993
994