5ee3363add93d06d7b5a696c32548a6b920d7e8a
[reactos.git] / reactos / win32ss / gdi / 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
14 /* DATA **********************************************************************/
15
16 HANDLE ghDirectDraw;
17 ULONG gcDirectDraw;
18
19 #define GetDdHandle(Handle) ((HANDLE)Handle ? (HANDLE)Handle : ghDirectDraw)
20
21
22
23 /* CALLBACKS *****************************************************************/
24
25 /*
26 * @implemented
27 *
28 * DdAddAttachedSurface
29 */
30 DWORD
31 WINAPI
32 DdAddAttachedSurface(LPDDHAL_ADDATTACHEDSURFACEDATA Attach)
33 {
34 /* Call win32k */
35 return NtGdiDdAddAttachedSurface((HANDLE)Attach->lpDDSurface->hDDSurface,
36 (HANDLE)Attach->lpSurfAttached->hDDSurface,
37 (PDD_ADDATTACHEDSURFACEDATA)Attach);
38 }
39
40 /*
41 * @implemented
42 *
43 * DdBlt
44 */
45 DWORD
46 WINAPI
47 DdBlt(LPDDHAL_BLTDATA Blt)
48 {
49 HANDLE Surface = 0;
50
51 /* Use the right surface */
52 if (Blt->lpDDSrcSurface)
53 {
54 Surface = (HANDLE)Blt->lpDDSrcSurface->hDDSurface;
55 }
56
57 /* Call win32k */
58 return NtGdiDdBlt((HANDLE)Blt->lpDDDestSurface->hDDSurface, Surface, (PDD_BLTDATA)Blt);
59 }
60
61 /*
62 * @implemented
63 *
64 * DdDestroySurface
65 */
66 DWORD
67 WINAPI
68 DdDestroySurface(LPDDHAL_DESTROYSURFACEDATA pDestroySurface)
69 {
70 DWORD Return = DDHAL_DRIVER_NOTHANDLED;
71 BOOL RealDestroy;
72
73 if (pDestroySurface->lpDDSurface->hDDSurface)
74 {
75 /* Check if we shoudl really destroy it */
76 RealDestroy = !(pDestroySurface->lpDDSurface->dwFlags & DDRAWISURF_DRIVERMANAGED) ||
77 !(pDestroySurface->lpDDSurface->dwFlags & DDRAWISURF_INVALID);
78
79 /* Call win32k */
80 Return = NtGdiDdDestroySurface((HANDLE)pDestroySurface->lpDDSurface->hDDSurface, RealDestroy);
81 }
82
83 return Return;
84 }
85
86 /*
87 * @implemented
88 *
89 * DdFlip
90 */
91 DWORD
92 WINAPI
93 DdFlip(LPDDHAL_FLIPDATA Flip)
94 {
95 /* Note :
96 * See http://msdn2.microsoft.com/en-us/library/ms794213.aspx and
97 * http://msdn2.microsoft.com/en-us/library/ms792675.aspx
98 */
99
100 HANDLE hSurfaceCurrentLeft = NULL;
101 HANDLE hSurfaceTargetLeft = NULL;
102
103 /* Auto flip off or on */
104 if (Flip->dwFlags & DDFLIP_STEREO )
105 {
106 if ( (Flip->lpSurfTargLeft) &&
107 (Flip->lpSurfCurrLeft))
108 {
109 /* Auto flip on */
110 hSurfaceTargetLeft = (HANDLE) Flip->lpSurfTargLeft->hDDSurface;
111 hSurfaceCurrentLeft = (HANDLE) Flip->lpSurfCurrLeft->hDDSurface;
112 }
113 }
114
115 /* Call win32k */
116 return NtGdiDdFlip( (HANDLE) Flip->lpSurfCurr->hDDSurface,
117 (HANDLE) Flip->lpSurfTarg->hDDSurface,
118 hSurfaceCurrentLeft,
119 hSurfaceTargetLeft,
120 (PDD_FLIPDATA) Flip);
121 }
122
123 /*
124 * @implemented
125 *
126 * DdLock
127 */
128 DWORD
129 WINAPI
130 DdLock(LPDDHAL_LOCKDATA Lock)
131 {
132
133 /* Call win32k */
134 return NtGdiDdLock((HANDLE)Lock->lpDDSurface->hDDSurface,
135 (PDD_LOCKDATA)Lock,
136 (HANDLE)Lock->lpDDSurface->hDC);
137 }
138
139 /*
140 * @implemented
141 *
142 * DdUnlock
143 */
144 DWORD
145 WINAPI
146 DdUnlock(LPDDHAL_UNLOCKDATA Unlock)
147 {
148 /* Call win32k */
149 return NtGdiDdUnlock((HANDLE)Unlock->lpDDSurface->hDDSurface,
150 (PDD_UNLOCKDATA)Unlock);
151 }
152
153 /*
154 * @implemented
155 *
156 * DdGetBltStatus
157 */
158 DWORD
159 WINAPI
160 DdGetBltStatus(LPDDHAL_GETBLTSTATUSDATA GetBltStatus)
161 {
162 /* Call win32k */
163 return NtGdiDdGetBltStatus((HANDLE)GetBltStatus->lpDDSurface->hDDSurface,
164 (PDD_GETBLTSTATUSDATA)GetBltStatus);
165 }
166
167 /*
168 * @implemented
169 *
170 * DdGetBltStatus
171 */
172 DWORD
173 WINAPI
174 DdGetFlipStatus(LPDDHAL_GETFLIPSTATUSDATA GetFlipStatus)
175 {
176 /* Call win32k */
177 return NtGdiDdGetFlipStatus((HANDLE)GetFlipStatus->lpDDSurface->hDDSurface,
178 (PDD_GETFLIPSTATUSDATA)GetFlipStatus);
179 }
180
181 /*
182 * @implemented
183 *
184 * DdUpdateOverlay
185 */
186 DWORD
187 WINAPI
188 DdUpdateOverlay(LPDDHAL_UPDATEOVERLAYDATA UpdateOverlay)
189 {
190
191 /* We have to handle this manually here */
192 if (UpdateOverlay->dwFlags & DDOVER_KEYDEST)
193 {
194 /* Use the override */
195 UpdateOverlay->dwFlags &= ~DDOVER_KEYDEST;
196 UpdateOverlay->dwFlags |= DDOVER_KEYDESTOVERRIDE;
197
198 /* Set the overlay */
199 UpdateOverlay->overlayFX.dckDestColorkey =
200 UpdateOverlay->lpDDDestSurface->ddckCKDestOverlay;
201 }
202 if (UpdateOverlay->dwFlags & DDOVER_KEYSRC)
203 {
204 /* Use the override */
205 UpdateOverlay->dwFlags &= ~DDOVER_KEYSRC;
206 UpdateOverlay->dwFlags |= DDOVER_KEYSRCOVERRIDE;
207
208 /* Set the overlay */
209 UpdateOverlay->overlayFX.dckSrcColorkey =
210 UpdateOverlay->lpDDSrcSurface->ddckCKSrcOverlay;
211 }
212
213 /* Call win32k */
214 return NtGdiDdUpdateOverlay((HANDLE)UpdateOverlay->lpDDDestSurface->hDDSurface,
215 (HANDLE)UpdateOverlay->lpDDSrcSurface->hDDSurface,
216 (PDD_UPDATEOVERLAYDATA)UpdateOverlay);
217 }
218
219 /*
220 * @implemented
221 *
222 * DdSetOverlayPosition
223 */
224 DWORD
225 WINAPI
226 DdSetOverlayPosition(LPDDHAL_SETOVERLAYPOSITIONDATA SetOverlayPosition)
227 {
228 /* Call win32k */
229 return NtGdiDdSetOverlayPosition( (HANDLE)SetOverlayPosition->lpDDSrcSurface->hDDSurface,
230 (HANDLE)SetOverlayPosition->lpDDDestSurface->hDDSurface,
231 (PDD_SETOVERLAYPOSITIONDATA) SetOverlayPosition);
232 }
233
234 /*
235 * @implemented
236 *
237 * DdWaitForVerticalBlank
238 */
239 DWORD
240 WINAPI
241 DdWaitForVerticalBlank(LPDDHAL_WAITFORVERTICALBLANKDATA WaitForVerticalBlank)
242 {
243 /* Call win32k */
244 return NtGdiDdWaitForVerticalBlank(GetDdHandle(
245 WaitForVerticalBlank->lpDD->hDD),
246 (PDD_WAITFORVERTICALBLANKDATA)
247 WaitForVerticalBlank);
248 }
249
250 /*
251 * @implemented
252 *
253 * DdCanCreateSurface
254 */
255 DWORD
256 WINAPI
257 DdCanCreateSurface(LPDDHAL_CANCREATESURFACEDATA CanCreateSurface)
258 {
259 /*
260 * Note : This functions are basic same, in win32k
261 * NtGdiDdCanCreateD3DBuffer and NtGdiDdCanCreateSurface are mergs
262 * toghter in win32k at end and retrurn same data, it is still sepreated
263 * at user mode but in kmode it is not.
264 */
265
266 /* Call win32k */
267 return NtGdiDdCanCreateSurface(GetDdHandle(CanCreateSurface->lpDD->hDD),
268 (PDD_CANCREATESURFACEDATA)CanCreateSurface);
269 }
270
271 /*
272 * @implemented
273 *
274 * DdCreateSurface
275 */
276 DWORD
277 WINAPI
278 DdCreateSurface(LPDDHAL_CREATESURFACEDATA pCreateSurface)
279 {
280 DWORD Return = DDHAL_DRIVER_NOTHANDLED;
281 ULONG SurfaceCount = pCreateSurface->dwSCnt;
282 DD_SURFACE_LOCAL DdSurfaceLocal;
283 DD_SURFACE_MORE DdSurfaceMore;
284 DD_SURFACE_GLOBAL DdSurfaceGlobal;
285
286 HANDLE hPrevSurface, hSurface;
287
288 PDD_SURFACE_LOCAL pDdSurfaceLocal = NULL;
289 PDD_SURFACE_MORE pDdSurfaceMore = NULL;
290 PDD_SURFACE_GLOBAL pDdSurfaceGlobal = NULL;
291
292 PDD_SURFACE_LOCAL ptmpDdSurfaceLocal = NULL;
293 PDD_SURFACE_MORE ptmpDdSurfaceMore = NULL;
294 PDD_SURFACE_GLOBAL ptmpDdSurfaceGlobal = NULL;
295 PHANDLE phSurface = NULL, puhSurface = NULL;
296 ULONG i;
297 LPDDSURFACEDESC pSurfaceDesc = NULL;
298
299 /* TODO: Optimize speed. Most games/dx apps/programs do not want one surface, they want at least two.
300 * So we need increase the stack to contain two surfaces instead of one. This will increase
301 * the speed of the apps when allocating buffers. How to increase the surface stack space:
302 * we need to create a struct for DD_SURFACE_LOCAL DdSurfaceLocal, DD_SURFACE_MORE DdSurfaceMore
303 * DD_SURFACE_GLOBAL DdSurfaceGlobal, HANDLE hPrevSurface, hSurface like
304 * struct { DD_SURFACE_LOCAL DdSurfaceLocal1, DD_SURFACE_LOCAL DdSurfaceLocal2 }
305 * in a way that it may contain two surfaces, maybe even four. We need to watch what is most common before
306 * we create the size. Activate this IF when you start doing the optimze and please also
307 * take reports from users which value they got here.
308 */
309 #if 1
310 {
311 char buffer[1024];
312 \
313 sprintf ( buffer, "Function %s : Optimze max to %d Surface ? (%s:%d)\n", __FUNCTION__, (int)SurfaceCount,__FILE__,__LINE__ );
314 OutputDebugStringA(buffer);
315 }
316 #endif
317
318 /* Check how many surfaces there are */
319 if (SurfaceCount != 1)
320 {
321 /* We got more than one surface, so we need to allocate memory for them */
322 pDdSurfaceLocal = (PDD_SURFACE_LOCAL) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (sizeof(DD_SURFACE_LOCAL) * SurfaceCount ));
323 pDdSurfaceMore = (PDD_SURFACE_MORE) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (sizeof(DD_SURFACE_MORE) * SurfaceCount ));
324 pDdSurfaceGlobal = (PDD_SURFACE_GLOBAL) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (sizeof(DD_SURFACE_GLOBAL) * SurfaceCount ));
325 phSurface = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (sizeof(HANDLE) * SurfaceCount ));
326 puhSurface = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (sizeof(HANDLE) * SurfaceCount ));
327
328 /* Check if we successfully allocated all memory we need */
329 if ((pDdSurfaceLocal == NULL) || (pDdSurfaceMore == NULL) || (pDdSurfaceGlobal == NULL) || (phSurface == NULL) || (puhSurface == NULL))
330 {
331 pCreateSurface->ddRVal = DDERR_OUTOFMEMORY;
332
333 if ( pDdSurfaceLocal != NULL )
334 {
335 HeapFree(GetProcessHeap(), 0, pDdSurfaceLocal);
336 }
337
338 if ( pDdSurfaceMore != NULL )
339 {
340 HeapFree(GetProcessHeap(), 0, pDdSurfaceMore);
341 }
342
343 if ( pDdSurfaceGlobal != NULL )
344 {
345 HeapFree(GetProcessHeap(), 0, pDdSurfaceGlobal);
346 }
347
348 if ( phSurface != NULL )
349 {
350 HeapFree(GetProcessHeap(), 0, phSurface);
351 }
352
353 if ( puhSurface != NULL )
354 {
355 HeapFree(GetProcessHeap(), 0, puhSurface);
356 }
357
358 return DDHAL_DRIVER_HANDLED;
359 }
360 }
361 else
362 {
363 /* We'll use what we have on the stack */
364 pDdSurfaceLocal = &DdSurfaceLocal;
365 pDdSurfaceMore = &DdSurfaceMore;
366 pDdSurfaceGlobal = &DdSurfaceGlobal;
367 phSurface = &hPrevSurface;
368 puhSurface = &hSurface;
369
370 /* Clear the structures */
371 RtlZeroMemory(&DdSurfaceLocal, sizeof(DdSurfaceLocal));
372 RtlZeroMemory(&DdSurfaceGlobal, sizeof(DdSurfaceGlobal));
373 RtlZeroMemory(&DdSurfaceMore, sizeof(DdSurfaceMore));
374 }
375
376 /* check if we got a surface or not */
377 if (SurfaceCount!=0)
378 {
379 /* Loop for each surface */
380 ptmpDdSurfaceGlobal = pDdSurfaceGlobal;
381 ptmpDdSurfaceLocal = pDdSurfaceLocal;
382 ptmpDdSurfaceMore = pDdSurfaceMore;
383 pSurfaceDesc = pCreateSurface->lpDDSurfaceDesc;
384
385 for (i = 0; i < SurfaceCount; i++)
386 {
387 LPDDRAWI_DDRAWSURFACE_LCL lcl = pCreateSurface->lplpSList[i];
388 LPDDRAWI_DDRAWSURFACE_GBL gpl = pCreateSurface->lplpSList[i]->lpGbl;
389
390 phSurface[i] = (HANDLE)lcl->hDDSurface;
391 ptmpDdSurfaceLocal->ddsCaps.dwCaps = lcl->ddsCaps.dwCaps;
392
393 ptmpDdSurfaceLocal->dwFlags = (ptmpDdSurfaceLocal->dwFlags &
394 (0xB0000000 | DDRAWISURF_INMASTERSPRITELIST |
395 DDRAWISURF_HELCB | DDRAWISURF_FRONTBUFFER |
396 DDRAWISURF_BACKBUFFER | DDRAWISURF_INVALID |
397 DDRAWISURF_DCIBUSY | DDRAWISURF_DCILOCK)) |
398 (lcl->dwFlags & DDRAWISURF_DRIVERMANAGED);
399
400 ptmpDdSurfaceGlobal->wWidth = gpl->wWidth;
401 ptmpDdSurfaceGlobal->wHeight = gpl->wHeight;
402 ptmpDdSurfaceGlobal->lPitch = gpl->lPitch;
403 ptmpDdSurfaceGlobal->fpVidMem = gpl->fpVidMem;
404 ptmpDdSurfaceGlobal->dwBlockSizeX = gpl->dwBlockSizeX;
405 ptmpDdSurfaceGlobal->dwBlockSizeY = gpl->dwBlockSizeY;
406
407 if (lcl->dwFlags & DDRAWISURF_HASPIXELFORMAT)
408 {
409 RtlCopyMemory( &ptmpDdSurfaceGlobal->ddpfSurface ,
410 &gpl->ddpfSurface,
411 sizeof(DDPIXELFORMAT));
412
413 ptmpDdSurfaceGlobal->ddpfSurface.dwSize = sizeof(DDPIXELFORMAT);
414 }
415 else
416 {
417 RtlCopyMemory( &ptmpDdSurfaceGlobal->ddpfSurface ,
418 &gpl->lpDD->vmiData.ddpfDisplay,
419 sizeof(DDPIXELFORMAT));
420 }
421
422 /* Note if lcl->lpSurfMore is NULL zero out
423 * ptmpDdSurfaceMore->ddsCapsEx.dwCaps2,
424 * dwCaps3, dwCaps4, ptmpDdSurfaceMore->dwSurfaceHandle
425 */
426 if (lcl->lpSurfMore)
427 {
428 ptmpDdSurfaceMore->ddsCapsEx.dwCaps2 = lcl->lpSurfMore->ddsCapsEx.dwCaps2;
429 ptmpDdSurfaceMore->ddsCapsEx.dwCaps3 = lcl->lpSurfMore->ddsCapsEx.dwCaps3;
430 ptmpDdSurfaceMore->ddsCapsEx.dwCaps4 = lcl->lpSurfMore->ddsCapsEx.dwCaps4;
431 ptmpDdSurfaceMore->dwSurfaceHandle = lcl->lpSurfMore->dwSurfaceHandle;
432 }
433
434
435 /* count to next SurfaceCount */
436 ptmpDdSurfaceGlobal = (PDD_SURFACE_GLOBAL) (((PBYTE) ((ULONG_PTR) ptmpDdSurfaceGlobal)) + sizeof(DD_SURFACE_GLOBAL));
437 ptmpDdSurfaceLocal = (PDD_SURFACE_LOCAL) (((PBYTE) ((ULONG_PTR) ptmpDdSurfaceLocal)) + sizeof(DD_SURFACE_LOCAL));
438 ptmpDdSurfaceMore = (PDD_SURFACE_MORE) (((PBYTE) ((ULONG_PTR) ptmpDdSurfaceMore)) + sizeof(DD_SURFACE_MORE));
439 }
440 }
441
442 /* Call win32k now */
443 pCreateSurface->ddRVal = DDERR_GENERIC;
444
445 Return = NtGdiDdCreateSurface(GetDdHandle(pCreateSurface->lpDD->hDD),
446 (HANDLE *)phSurface,
447 pSurfaceDesc,
448 pDdSurfaceGlobal,
449 pDdSurfaceLocal,
450 pDdSurfaceMore,
451 (PDD_CREATESURFACEDATA)pCreateSurface,
452 puhSurface);
453
454 if (SurfaceCount == 0)
455 {
456 pCreateSurface->ddRVal = DDERR_GENERIC;
457 }
458 else
459 {
460 ptmpDdSurfaceMore = pDdSurfaceMore;
461 ptmpDdSurfaceGlobal = pDdSurfaceGlobal;
462 ptmpDdSurfaceLocal = pDdSurfaceLocal;
463
464 for (i=0; i<SurfaceCount; i++)
465 {
466 LPDDRAWI_DDRAWSURFACE_LCL lcl = pCreateSurface->lplpSList[i];
467 LPDDRAWI_DDRAWSURFACE_GBL gpl = pCreateSurface->lplpSList[i]->lpGbl;
468
469 gpl->lPitch = ptmpDdSurfaceGlobal->lPitch;
470 gpl->fpVidMem = ptmpDdSurfaceGlobal->fpVidMem;
471 gpl->dwBlockSizeX = ptmpDdSurfaceGlobal->dwBlockSizeX;
472 gpl->dwBlockSizeY = ptmpDdSurfaceGlobal->dwBlockSizeY;
473
474 if (lcl->dwFlags & DDRAWISURF_HASPIXELFORMAT)
475 {
476 RtlCopyMemory( &gpl->ddpfSurface, &ptmpDdSurfaceGlobal->ddpfSurface , sizeof(DDPIXELFORMAT));
477 }
478
479 if (pCreateSurface->ddRVal != DD_OK)
480 {
481 gpl->fpVidMem = 0;
482 if (lcl->hDDSurface)
483 {
484 NtGdiDdDeleteSurfaceObject( (HANDLE)lcl->hDDSurface);
485 }
486 lcl->hDDSurface = 0;
487 }
488 else
489 {
490
491 lcl->hDDSurface = (ULONG_PTR) puhSurface[i];
492 }
493
494 lcl->ddsCaps.dwCaps = ptmpDdSurfaceLocal->ddsCaps.dwCaps;
495 if (lcl->lpSurfMore)
496 {
497 lcl->lpSurfMore->ddsCapsEx.dwCaps2 = ptmpDdSurfaceMore->ddsCapsEx.dwCaps2;
498 lcl->lpSurfMore->ddsCapsEx.dwCaps3 = ptmpDdSurfaceMore->ddsCapsEx.dwCaps3;
499 lcl->lpSurfMore->ddsCapsEx.dwCaps4 = ptmpDdSurfaceMore->ddsCapsEx.dwCaps4;
500 }
501
502 /* count to next SurfaceCount */
503 ptmpDdSurfaceGlobal = (PDD_SURFACE_GLOBAL) (((PBYTE) ((ULONG_PTR) ptmpDdSurfaceGlobal)) + sizeof(DD_SURFACE_GLOBAL));
504 ptmpDdSurfaceLocal = (PDD_SURFACE_LOCAL) (((PBYTE) ((ULONG_PTR) ptmpDdSurfaceLocal)) + sizeof(DD_SURFACE_LOCAL));
505 ptmpDdSurfaceMore = (PDD_SURFACE_MORE) (((PBYTE) ((ULONG_PTR) ptmpDdSurfaceMore)) + sizeof(DD_SURFACE_MORE));
506 }
507 }
508
509 /* Check if we have to free all our local allocations */
510 if (SurfaceCount > 1)
511 {
512 if ( pDdSurfaceLocal != NULL )
513 {
514 HeapFree(GetProcessHeap(), 0, pDdSurfaceLocal);
515 }
516
517 if ( pDdSurfaceMore != NULL )
518 {
519 HeapFree(GetProcessHeap(), 0, pDdSurfaceMore);
520 }
521
522 if ( pDdSurfaceGlobal != NULL )
523 {
524 HeapFree(GetProcessHeap(), 0, pDdSurfaceGlobal);
525 }
526
527 if ( phSurface != NULL )
528 {
529 HeapFree(GetProcessHeap(), 0, phSurface);
530 }
531
532 if ( puhSurface != NULL )
533 {
534 HeapFree(GetProcessHeap(), 0, puhSurface);
535 }
536 }
537
538 /* Return */
539 return Return;
540 }
541
542 /*
543 * @implemented
544 *
545 * DdSetColorKey
546 */
547 DWORD
548 WINAPI
549 DdSetColorKey(LPDDHAL_SETCOLORKEYDATA pSetColorKey)
550 {
551 /* Call win32k */
552 return NtGdiDdSetColorKey((HANDLE)pSetColorKey->lpDDSurface->hDDSurface,
553 (PDD_SETCOLORKEYDATA)pSetColorKey);
554 }
555
556 /*
557 * @implemented
558 *
559 * DdGetScanLine
560 */
561 DWORD
562 WINAPI
563 DdGetScanLine(LPDDHAL_GETSCANLINEDATA pGetScanLine)
564 {
565 /* Call win32k */
566 return NtGdiDdGetScanLine(GetDdHandle(pGetScanLine->lpDD->hDD),
567 (PDD_GETSCANLINEDATA)pGetScanLine);
568 }
569
570
571 /*
572 * @implemented
573 *
574 * DvpCreateVideoPort
575 */
576 BOOL
577 WINAPI
578 DvpCreateVideoPort(LPDDHAL_CREATEVPORTDATA pDvdCreatePort)
579 {
580 pDvdCreatePort->lpVideoPort->hDDVideoPort =
581 NtGdiDvpCreateVideoPort(GetDdHandle(pDvdCreatePort->lpDD->lpGbl->hDD),
582 (PDD_CREATEVPORTDATA) pDvdCreatePort);
583
584 return TRUE;
585 }
586
587 /*
588 * @implemented
589 *
590 * DvpCreateVideoPort
591 */
592 DWORD
593 WINAPI
594 DvpDestroyVideoPort(LPDDHAL_DESTROYVPORTDATA pDvdDestoryPort)
595 {
596 return NtGdiDvpDestroyVideoPort(pDvdDestoryPort->lpVideoPort->hDDVideoPort, (PDD_DESTROYVPORTDATA)pDvdDestoryPort);
597 }
598
599 /*
600 * @implemented
601 *
602 * DvpCreateVideoPort
603 */
604 DWORD
605 WINAPI
606 DvpFlipVideoPort(LPDDHAL_FLIPVPORTDATA pDvdPortFlip)
607 {
608 return NtGdiDvpFlipVideoPort(pDvdPortFlip->lpVideoPort->hDDVideoPort,
609 (HANDLE)pDvdPortFlip->lpSurfCurr->hDDSurface,
610 (HANDLE)pDvdPortFlip->lpSurfTarg->hDDSurface,
611 (PDD_FLIPVPORTDATA) pDvdPortFlip);
612 }
613
614 /*
615 * @implemented
616 *
617 * DvpGetVideoPortBandwidth
618 */
619 DWORD
620 WINAPI
621 DvpGetVideoPortBandwidth(LPDDHAL_GETVPORTBANDWIDTHDATA pDvdPortBandWidth)
622 {
623 return NtGdiDvpGetVideoPortBandwidth(pDvdPortBandWidth->lpVideoPort->hDDVideoPort, (PDD_GETVPORTBANDWIDTHDATA)pDvdPortBandWidth);
624 }
625
626 /*
627 * @implemented
628 *
629 * DvpColorControl
630 */
631 DWORD
632 WINAPI
633 DvpColorControl(LPDDHAL_VPORTCOLORDATA pDvdPortColorControl)
634 {
635 return NtGdiDvpColorControl(pDvdPortColorControl->lpVideoPort->hDDVideoPort, (PDD_VPORTCOLORDATA) pDvdPortColorControl);
636 }
637
638 /*
639 * @implemented
640 *
641 * DvpGetVideoSignalStatus
642 */
643 DWORD
644 WINAPI
645 DvpGetVideoSignalStatus(LPDDHAL_GETVPORTSIGNALDATA pDvdPortVideoSignalStatus)
646 {
647 return NtGdiDvpGetVideoSignalStatus(pDvdPortVideoSignalStatus->lpVideoPort->hDDVideoPort, (PDD_GETVPORTSIGNALDATA) pDvdPortVideoSignalStatus);
648 }
649
650 /*
651 * @implemented
652 *
653 * DvpGetVideoPortFlipStatus
654 */
655 DWORD
656 WINAPI
657 DvpGetVideoPortFlipStatus(LPDDHAL_GETVPORTFLIPSTATUSDATA pDvdPortVideoPortFlipStatus)
658 {
659 return NtGdiDvpGetVideoPortFlipStatus(GetDdHandle(pDvdPortVideoPortFlipStatus->lpDD->lpGbl->hDD), (PDD_GETVPORTFLIPSTATUSDATA) pDvdPortVideoPortFlipStatus);
660
661 }
662
663 /*
664 * @implemented
665 *
666 * DvpCanCreateVideoPort
667 */
668 DWORD
669 WINAPI
670 DvpCanCreateVideoPort(LPDDHAL_CANCREATEVPORTDATA pDvdCanCreateVideoPort)
671 {
672 return NtGdiDvpCanCreateVideoPort(GetDdHandle(pDvdCanCreateVideoPort->lpDD->lpGbl->hDD), (PDD_CANCREATEVPORTDATA) pDvdCanCreateVideoPort);
673 }
674 /*
675 * @implemented
676 *
677 * DvpWaitForVideoPortSync
678 */
679 DWORD
680 WINAPI
681 DvpWaitForVideoPortSync(LPDDHAL_WAITFORVPORTSYNCDATA pDvdWaitForVideoPortSync)
682 {
683 return NtGdiDvpWaitForVideoPortSync(pDvdWaitForVideoPortSync->lpVideoPort->hDDVideoPort, (PDD_WAITFORVPORTSYNCDATA) pDvdWaitForVideoPortSync);
684 }
685
686 /*
687 * @implemented
688 *
689 * DvpUpdateVideoPort
690 */
691 DWORD
692 WINAPI
693 DvpUpdateVideoPort(LPDDHAL_UPDATEVPORTDATA pDvdUpdateVideoPort)
694 {
695 /*
696 * Windows XP limit to max 10 handles of videoport surface and Vbi
697 * ReactOS doing same to keep compatible, if it is more that 10
698 * videoport surface or vbi the stack will be curpted in windows xp
699 * ReactOS safe guard againts that
700 *
701 */
702
703 HANDLE phSurfaceVideo[10];
704 HANDLE phSurfaceVbi[10];
705
706 if (pDvdUpdateVideoPort->dwFlags != DDRAWI_VPORTSTOP)
707 {
708 DWORD dwNumAutoflip;
709 DWORD dwNumVBIAutoflip;
710
711 /* Take copy of lplpDDSurface for the handle value will be modify in dxg */
712 dwNumAutoflip = pDvdUpdateVideoPort->dwNumAutoflip;
713 if ((dwNumAutoflip == 0) &&
714 (pDvdUpdateVideoPort->lplpDDSurface == 0))
715 {
716 dwNumAutoflip++;
717 }
718
719 if (dwNumAutoflip != 0)
720 {
721 if (dwNumAutoflip>10)
722 {
723 dwNumAutoflip = 10;
724 }
725 memcpy(phSurfaceVideo,pDvdUpdateVideoPort->lplpDDSurface,dwNumAutoflip*sizeof(HANDLE));
726 }
727
728 /* Take copy of lplpDDVBISurface for the handle value will be modify in dxg */
729 dwNumVBIAutoflip = pDvdUpdateVideoPort->dwNumVBIAutoflip;
730 if ( (dwNumVBIAutoflip == 0) &&
731 (pDvdUpdateVideoPort->lplpDDVBISurface == 0) )
732 {
733 dwNumVBIAutoflip++;
734 }
735
736 if (dwNumVBIAutoflip != 0)
737 {
738 if (dwNumVBIAutoflip>10)
739 {
740 dwNumVBIAutoflip = 10;
741 }
742 memcpy(phSurfaceVbi,pDvdUpdateVideoPort->lplpDDVBISurface,dwNumVBIAutoflip*sizeof(HANDLE));
743 }
744 }
745
746 /* Call Win32k */
747 return NtGdiDvpUpdateVideoPort(pDvdUpdateVideoPort->lpVideoPort->hDDVideoPort,phSurfaceVideo,phSurfaceVbi, (PDD_UPDATEVPORTDATA)pDvdUpdateVideoPort);
748 }
749
750 /*
751 * @implemented
752 *
753 * DvpWaitForVideoPortSync
754 */
755 DWORD
756 WINAPI
757 DvpGetVideoPortField(LPDDHAL_FLIPVPORTDATA pDvdGetVideoPortField)
758 {
759 return NtGdiDvpGetVideoPortField(pDvdGetVideoPortField->lpVideoPort->hDDVideoPort, (PDD_GETVPORTFIELDDATA)pDvdGetVideoPortField);
760 }
761
762 /*
763 * @implemented
764 *
765 * DvpWaitForVideoPortSync
766 */
767 DWORD
768 WINAPI
769 DvpGetVideoPortInputFormats(LPDDHAL_GETVPORTINPUTFORMATDATA pDvdGetVideoPortInputFormat)
770 {
771 return NtGdiDvpGetVideoPortInputFormats(pDvdGetVideoPortInputFormat->lpVideoPort->hDDVideoPort, (PDD_GETVPORTINPUTFORMATDATA) pDvdGetVideoPortInputFormat);
772 }
773
774 /*
775 * @implemented
776 *
777 * DvpGetVideoPortLine
778 */
779 DWORD
780 WINAPI
781 DvpGetVideoPortLine(LPDDHAL_GETVPORTLINEDATA pDvdGetVideoPortLine)
782 {
783 return NtGdiDvpGetVideoPortLine(pDvdGetVideoPortLine->lpVideoPort->hDDVideoPort, (PDD_GETVPORTLINEDATA)pDvdGetVideoPortLine);
784 }
785
786 /*
787 * @implemented
788 *
789 * DvpGetVideoPortOutputFormats
790 */
791 DWORD
792 WINAPI
793 DvpGetVideoPortOutputFormats(LPDDHAL_GETVPORTLINEDATA pDvdGetVideoPortOutputFormat)
794 {
795 return NtGdiDvpGetVideoPortLine(pDvdGetVideoPortOutputFormat->lpVideoPort->hDDVideoPort, (PDD_GETVPORTLINEDATA)pDvdGetVideoPortOutputFormat);
796 }
797
798 /*
799 * @implemented
800 *
801 * DvpGetVideoPortConnectInfo
802 */
803 DWORD
804 WINAPI
805 DvpGetVideoPortConnectInfo(LPDDHAL_GETVPORTCONNECTDATA pDvdGetVideoPortInfo)
806 {
807 return NtGdiDvpGetVideoPortConnectInfo( GetDdHandle( pDvdGetVideoPortInfo->lpDD->lpGbl->hDD) , (PDD_GETVPORTCONNECTDATA) pDvdGetVideoPortInfo);
808 }
809
810 /*
811 * @implemented
812 *
813 * DdGetAvailDriverMemory
814 */
815 DWORD
816 WINAPI
817 DdGetAvailDriverMemory(LPDDHAL_GETAVAILDRIVERMEMORYDATA pDdGetAvailDriverMemory)
818 {
819 return NtGdiDdGetAvailDriverMemory(GetDdHandle( pDdGetAvailDriverMemory->lpDD->hDD), (PDD_GETAVAILDRIVERMEMORYDATA) pDdGetAvailDriverMemory);
820 }
821
822 /*
823 * @implemented
824 *
825 * DdAlphaBlt
826 */
827 DWORD
828 WINAPI
829 DdAlphaBlt(LPDDHAL_BLTDATA pDdAlphaBlt)
830 {
831 HANDLE hDDSrcSurface = 0;
832
833 if (pDdAlphaBlt->lpDDSrcSurface != 0)
834 {
835 hDDSrcSurface = (HANDLE) pDdAlphaBlt->lpDDSrcSurface->hDDSurface;
836 }
837
838 return NtGdiDdAlphaBlt((HANDLE)pDdAlphaBlt->lpDDDestSurface->hDDSurface, hDDSrcSurface, (PDD_BLTDATA)&pDdAlphaBlt);
839 }
840
841 /*
842 * @implemented
843 *
844 * DdCreateSurfaceEx
845 */
846 DWORD
847 WINAPI
848 DdCreateSurfaceEx(LPDDHAL_CREATESURFACEEXDATA pDdCreateSurfaceEx)
849 {
850 pDdCreateSurfaceEx->ddRVal = NtGdiDdCreateSurfaceEx( GetDdHandle(pDdCreateSurfaceEx->lpDDLcl->lpGbl->hDD),
851 (HANDLE)pDdCreateSurfaceEx->lpDDSLcl->hDDSurface,
852 pDdCreateSurfaceEx->lpDDSLcl->lpSurfMore->dwSurfaceHandle);
853 return TRUE;
854 }
855
856 /*
857 * @implemented
858 *
859 * DdColorControl
860 */
861 DWORD
862 WINAPI
863 DdColorControl(LPDDHAL_COLORCONTROLDATA pDdColorControl)
864 {
865 return NtGdiDdColorControl( (HANDLE) pDdColorControl->lpDDSurface->hDDSurface, (PDD_COLORCONTROLDATA) &pDdColorControl);
866 }
867
868 /*
869 * @implemented
870 *
871 * DdSetExclusiveMode
872 */
873 DWORD
874 WINAPI
875 DdSetExclusiveMode(LPDDHAL_SETEXCLUSIVEMODEDATA pDdSetExclusiveMode)
876 {
877 return NtGdiDdSetExclusiveMode( GetDdHandle(pDdSetExclusiveMode->lpDD->hDD), (PDD_SETEXCLUSIVEMODEDATA) &pDdSetExclusiveMode);
878 }
879
880 /*
881 * @implemented
882 *
883 * DdFlipToGDISurface
884 */
885 DWORD
886 WINAPI
887 DdFlipToGDISurface(LPDDHAL_FLIPTOGDISURFACEDATA pDdFlipToGDISurface)
888 {
889 return NtGdiDdFlipToGDISurface( GetDdHandle(pDdFlipToGDISurface->lpDD->hDD), (PDD_FLIPTOGDISURFACEDATA) &pDdFlipToGDISurface);
890 }
891
892 /* TODO */
893 DWORD
894 WINAPI
895 DdGetDriverInfo(LPDDHAL_GETDRIVERINFODATA pData)
896 {
897 DDHAL_GETDRIVERINFODATA pDrvInfoData;
898 DWORD retValue = DDHAL_DRIVER_NOTHANDLED;
899 HANDLE hDD;
900
901 /* FIXME add SEH around this functions */
902
903 RtlZeroMemory(&pDrvInfoData, sizeof (DDHAL_GETDRIVERINFODATA));
904 RtlCopyMemory(&pDrvInfoData.guidInfo, &pData->guidInfo, sizeof(GUID));
905
906 hDD = GetDdHandle(pData->dwContext);
907
908 pDrvInfoData.dwSize = sizeof (DDHAL_GETDRIVERINFODATA);
909 pDrvInfoData.ddRVal = DDERR_GENERIC;
910 pDrvInfoData.dwContext = (ULONG_PTR)hDD;
911
912
913 /* Videoport Callbacks check and setup for DirectX/ ReactX */
914 if (IsEqualGUID(&pData->guidInfo, &GUID_VideoPortCallbacks))
915 {
916 DDHAL_DDVIDEOPORTCALLBACKS pDvdPort;
917 DDHAL_DDVIDEOPORTCALLBACKS* pUserDvdPort = (DDHAL_DDVIDEOPORTCALLBACKS *)pData->lpvData;
918
919 /* Clear internal out buffer and set it up*/
920 RtlZeroMemory(&pDvdPort, DDVIDEOPORTCALLBACKSSIZE);
921 pDvdPort.dwSize = DDVIDEOPORTCALLBACKSSIZE;
922
923 /* set up internal buffer */
924 pDrvInfoData.lpvData = (PVOID)&pDvdPort;
925 pDrvInfoData.dwExpectedSize = DDVIDEOPORTCALLBACKSSIZE ;
926
927 /* Call win32k */
928 retValue = NtGdiDdGetDriverInfo(hDD, (PDD_GETDRIVERINFODATA)&pDrvInfoData);
929
930 /* Setup user out buffer and convert kmode callbacks to user mode */
931 pUserDvdPort->dwSize = DDVIDEOPORTCALLBACKSSIZE;
932 pUserDvdPort->dwFlags = pDrvInfoData.dwFlags = 0;
933
934 pUserDvdPort->dwFlags = (pDrvInfoData.dwFlags & ~(DDHAL_VPORT32_CREATEVIDEOPORT | DDHAL_VPORT32_FLIP |
935 DDHAL_VPORT32_DESTROY | DDHAL_VPORT32_UPDATE | DDHAL_VPORT32_WAITFORSYNC)) |
936 (DDHAL_VPORT32_CREATEVIDEOPORT | DDHAL_VPORT32_FLIP |
937 DDHAL_VPORT32_DESTROY | DDHAL_VPORT32_UPDATE);
938
939 pData->dwActualSize = DDVIDEOPORTCALLBACKSSIZE;
940 pUserDvdPort->CreateVideoPort = (LPDDHALVPORTCB_CREATEVIDEOPORT) DvpCreateVideoPort;
941 pUserDvdPort->FlipVideoPort = (LPDDHALVPORTCB_FLIP) DvpFlipVideoPort;
942 pUserDvdPort->DestroyVideoPort = (LPDDHALVPORTCB_DESTROYVPORT) DvpDestroyVideoPort;
943 pUserDvdPort->UpdateVideoPort = (LPDDHALVPORTCB_UPDATE) DvpUpdateVideoPort;
944
945 if (pDvdPort.CanCreateVideoPort)
946 {
947 pUserDvdPort->CanCreateVideoPort = (LPDDHALVPORTCB_CANCREATEVIDEOPORT) DvpCanCreateVideoPort;
948 }
949
950 if (pDvdPort.GetVideoPortBandwidth)
951 {
952 pUserDvdPort->GetVideoPortBandwidth = (LPDDHALVPORTCB_GETBANDWIDTH) DvpGetVideoPortBandwidth;
953 }
954
955 if (pDvdPort.GetVideoPortInputFormats)
956 {
957 pUserDvdPort->GetVideoPortInputFormats = (LPDDHALVPORTCB_GETINPUTFORMATS) DvpGetVideoPortInputFormats;
958 }
959
960 if (pDvdPort.GetVideoPortOutputFormats)
961 {
962 pUserDvdPort->GetVideoPortOutputFormats = (LPDDHALVPORTCB_GETOUTPUTFORMATS) DvpGetVideoPortOutputFormats;
963 }
964
965 if (pDvdPort.GetVideoPortField)
966 {
967 pUserDvdPort->GetVideoPortField = (LPDDHALVPORTCB_GETFIELD) DvpGetVideoPortField;
968 }
969
970 if (pDvdPort.GetVideoPortLine)
971 {
972 pUserDvdPort->GetVideoPortLine = (LPDDHALVPORTCB_GETLINE) DvpGetVideoPortLine;
973 }
974
975 if (pDvdPort.GetVideoPortConnectInfo)
976 {
977 pUserDvdPort->GetVideoPortConnectInfo = (LPDDHALVPORTCB_GETVPORTCONNECT) DvpGetVideoPortConnectInfo;
978 }
979
980 if (pDvdPort.GetVideoPortFlipStatus)
981 {
982 pUserDvdPort->GetVideoPortFlipStatus = (LPDDHALVPORTCB_GETFLIPSTATUS) DvpGetVideoPortFlipStatus;
983 }
984
985 if (pDvdPort.WaitForVideoPortSync)
986 {
987 pUserDvdPort->WaitForVideoPortSync = (LPDDHALVPORTCB_WAITFORSYNC) DvpWaitForVideoPortSync;
988 }
989
990 if (pDvdPort.GetVideoSignalStatus)
991 {
992 pUserDvdPort->GetVideoSignalStatus = (LPDDHALVPORTCB_GETSIGNALSTATUS) DvpGetVideoSignalStatus;
993 }
994
995 if (pDvdPort.ColorControl)
996 {
997 pUserDvdPort->ColorControl = (LPDDHALVPORTCB_COLORCONTROL) DvpColorControl;
998 }
999
1000 /* Windows XP never repot back the true return value,
1001 * it only report back if we have a driver or not
1002 * ReactOS keep this behoir to be compatible with
1003 * Windows XP
1004 */
1005 pData->ddRVal = retValue;
1006 }
1007
1008 /* Color Control Callbacks check and setup for DirectX/ ReactX */
1009 if (IsEqualGUID(&pData->guidInfo, &GUID_ColorControlCallbacks))
1010 {
1011 DDHAL_DDCOLORCONTROLCALLBACKS pColorControl;
1012 DDHAL_DDCOLORCONTROLCALLBACKS* pUserColorControl = (DDHAL_DDCOLORCONTROLCALLBACKS *)pData->lpvData;
1013
1014 /* Clear internal out buffer and set it up*/
1015 RtlZeroMemory(&pColorControl, DDCOLORCONTROLCALLBACKSSIZE);
1016 pColorControl.dwSize = DDCOLORCONTROLCALLBACKSSIZE;
1017
1018 /* set up internal buffer */
1019 pDrvInfoData.lpvData = (PVOID)&pColorControl;
1020 pDrvInfoData.dwExpectedSize = DDCOLORCONTROLCALLBACKSSIZE ;
1021
1022 /* Call win32k */
1023 retValue = NtGdiDdGetDriverInfo(hDD, (PDD_GETDRIVERINFODATA)&pDrvInfoData);
1024
1025 pData->dwActualSize = DDCOLORCONTROLCALLBACKSSIZE;
1026 pData->dwFlags = pDrvInfoData.dwFlags;
1027
1028 pUserColorControl->dwSize = DDCOLORCONTROLCALLBACKSSIZE;
1029 pUserColorControl->dwFlags = pUserColorControl->dwFlags;
1030
1031 if (pColorControl.ColorControl != NULL)
1032 {
1033 pUserColorControl->ColorControl = (LPDDHALCOLORCB_COLORCONTROL) DdColorControl;
1034 }
1035
1036 /* Windows XP never repot back the true return value,
1037 * it only report back if we have a driver or not
1038 * ReactOS keep this behoir to be compatible with
1039 * Windows XP
1040 */
1041 pData->ddRVal = retValue;
1042 }
1043
1044 /* Misc Callbacks check and setup for DirectX/ ReactX */
1045 else if (IsEqualGUID(&pData->guidInfo, &GUID_MiscellaneousCallbacks))
1046 {
1047 DDHAL_DDMISCELLANEOUSCALLBACKS pMisc;
1048 DDHAL_DDMISCELLANEOUSCALLBACKS* pUserMisc = (DDHAL_DDMISCELLANEOUSCALLBACKS *)pData->lpvData;
1049
1050 /* Clear internal out buffer and set it up*/
1051 RtlZeroMemory(&pMisc, DDMISCELLANEOUSCALLBACKSSIZE);
1052 pMisc.dwSize = DDMISCELLANEOUSCALLBACKSSIZE;
1053
1054 /* set up internal buffer */
1055 pDrvInfoData.lpvData = (PVOID)&pMisc;
1056 pDrvInfoData.dwExpectedSize = DDMISCELLANEOUSCALLBACKSSIZE ;
1057
1058 /* Call win32k */
1059 retValue = NtGdiDdGetDriverInfo(hDD, (PDD_GETDRIVERINFODATA)&pDrvInfoData);
1060
1061 pData->dwActualSize = DDMISCELLANEOUSCALLBACKSSIZE;
1062
1063 /* Only one callbacks are supported */
1064 pUserMisc->dwFlags = pMisc.dwFlags & DDHAL_MISCCB32_GETAVAILDRIVERMEMORY;
1065 pUserMisc->GetAvailDriverMemory = (LPDDHAL_GETAVAILDRIVERMEMORY) DdGetAvailDriverMemory;
1066
1067 /* This callbacks are only for win9x and theirfor it is not longer use in NT or ReactOS
1068 * pUserMisc->UpdateNonLocalHeap;
1069 * pUserMisc->GetHeapAlignment;
1070 * pUserMisc->GetSysmemBltStatus; */
1071
1072 /* Windows XP never repot back the true return value,
1073 * it only report back if we have a driver or not
1074 * ReactOS keep this behoir to be compatible with
1075 * Windows XP
1076 */
1077 pData->ddRVal = retValue;
1078 }
1079
1080 /* Misc 2 Callbacks check and setup for DirectX/ ReactX */
1081 else if (IsEqualGUID(&pData->guidInfo, &GUID_Miscellaneous2Callbacks))
1082 {
1083 DDHAL_DDMISCELLANEOUS2CALLBACKS pMisc;
1084 DDHAL_DDMISCELLANEOUS2CALLBACKS* pUserMisc = (DDHAL_DDMISCELLANEOUS2CALLBACKS *)pData->lpvData;
1085
1086 /* Clear internal out buffer and set it up*/
1087 RtlZeroMemory(&pMisc, DDMISCELLANEOUS2CALLBACKSSIZE);
1088 pMisc.dwSize = DDMISCELLANEOUS2CALLBACKSSIZE;
1089
1090 /* set up internal buffer */
1091 pDrvInfoData.lpvData = (PVOID)&pMisc;
1092 pDrvInfoData.dwExpectedSize = DDMISCELLANEOUS2CALLBACKSSIZE ;
1093
1094 /* Call win32k */
1095 retValue = NtGdiDdGetDriverInfo(hDD, (PDD_GETDRIVERINFODATA)&pDrvInfoData);
1096
1097 pData->dwActualSize = DDMISCELLANEOUS2CALLBACKSSIZE;
1098
1099 pUserMisc->dwFlags = pMisc.dwFlags;
1100
1101 /* This functions are not documneted in MSDN for this struct, here is directx/reactx alpha blend */
1102 if ( pMisc.Reserved )
1103 {
1104 pUserMisc->Reserved = (LPVOID) DdAlphaBlt;
1105 }
1106
1107 if ( pMisc.CreateSurfaceEx )
1108 {
1109 pUserMisc->CreateSurfaceEx = (LPDDHAL_CREATESURFACEEX) DdCreateSurfaceEx;
1110 }
1111
1112 if ( pMisc.GetDriverState )
1113 {
1114 pUserMisc->GetDriverState = (LPDDHAL_GETDRIVERSTATE) NtGdiDdGetDriverState;
1115 }
1116
1117 /* NOTE : pUserMisc->DestroyDDLocal is outdated and are not beign tuch */
1118
1119 /* Windows XP never repot back the true return value,
1120 * it only report back if we have a driver or not
1121 * ReactOS keep this behoir to be compatible with
1122 * Windows XP
1123 */
1124 pData->ddRVal = retValue;
1125 }
1126
1127 /* NT Callbacks check and setup for DirectX/ ReactX */
1128 else if (IsEqualGUID(&pData->guidInfo, &GUID_NTCallbacks))
1129 {
1130 /* MS does not have DHAL_* version of this callbacks
1131 * so we are force using PDD_* callbacks here
1132 */
1133 DD_NTCALLBACKS pNtKernel;
1134 PDD_NTCALLBACKS pUserNtKernel = (PDD_NTCALLBACKS)pData->lpvData;
1135
1136 /* Clear internal out buffer and set it up*/
1137 RtlZeroMemory(&pNtKernel, sizeof(DD_NTCALLBACKS));
1138 pNtKernel.dwSize = sizeof(DD_NTCALLBACKS);
1139
1140 /* set up internal buffer */
1141 pDrvInfoData.lpvData = (PVOID)&pNtKernel;
1142 pDrvInfoData.dwExpectedSize = sizeof(DD_NTCALLBACKS) ;
1143
1144 /* Call win32k */
1145 retValue = NtGdiDdGetDriverInfo(hDD, (PDD_GETDRIVERINFODATA)&pDrvInfoData);
1146
1147 pData->dwActualSize = sizeof(DD_NTCALLBACKS);
1148
1149 pUserNtKernel->dwSize = sizeof(DD_NTCALLBACKS);
1150 pUserNtKernel->dwFlags = pNtKernel.dwFlags;
1151 pUserNtKernel->FreeDriverMemory = 0;
1152
1153 if (pNtKernel.SetExclusiveMode)
1154 {
1155 pUserNtKernel->SetExclusiveMode = (PDD_SETEXCLUSIVEMODE) DdSetExclusiveMode;
1156 }
1157
1158 if (pNtKernel.FlipToGDISurface)
1159 {
1160 pUserNtKernel->FlipToGDISurface = (PDD_FLIPTOGDISURFACE) DdFlipToGDISurface;
1161 }
1162
1163 /* Windows XP never repot back the true return value,
1164 * it only report back if we have a driver or not
1165 * ReactOS keep this behoir to be compatible with
1166 * Windows XP
1167 */
1168 pData->ddRVal = retValue;
1169 }
1170
1171 /* D3D Callbacks version 2 check and setup for DirectX/ ReactX */
1172 else if (IsEqualGUID(&pData->guidInfo, &GUID_D3DCallbacks2))
1173 {
1174 // FIXME GUID_D3DCallbacks2
1175 }
1176
1177 /* D3D Callbacks version 3 check and setup for DirectX/ ReactX */
1178 else if (IsEqualGUID(&pData->guidInfo, &GUID_D3DCallbacks3))
1179 {
1180 // FIXME GUID_D3DCallbacks3
1181 }
1182
1183 /* D3DParseUnknownCommand Callbacks check and setup for DirectX/ ReactX */
1184 else if (IsEqualGUID(&pData->guidInfo, &GUID_D3DParseUnknownCommandCallback))
1185 {
1186 // FIXME GUID_D3DParseUnknownCommandCallback
1187 }
1188
1189 /* MotionComp Callbacks check and setup for DirectX/ ReactX */
1190 else if (IsEqualGUID(&pData->guidInfo, &GUID_MotionCompCallbacks))
1191 {
1192 // FIXME GUID_MotionCompCallbacks
1193 }
1194
1195 /* FIXME VPE2 Callbacks check and setup for DirectX/ ReactX */
1196 //else if (IsEqualGUID(&pData->guidInfo, &GUID_VPE2Callbacks))
1197 //{
1198 // FIXME GUID_VPE2Callbacks
1199 //}
1200 else
1201 {
1202 /* set up internal buffer */
1203 pDrvInfoData.dwExpectedSize = pData->dwExpectedSize;
1204 pDrvInfoData.lpvData = pData->lpvData;
1205
1206 /* We do not cover all callbacks for user mode, they are only cover by kmode */
1207 retValue = NtGdiDdGetDriverInfo(hDD, (PDD_GETDRIVERINFODATA)&pDrvInfoData);
1208
1209 /* Setup return data */
1210 pData->dwActualSize = pDrvInfoData.dwActualSize;
1211 pData->lpvData = pDrvInfoData.lpvData;
1212 /* Windows XP never repot back the true return value,
1213 * it only report back if we have a driver or not
1214 * ReactOS keep this behoir to be compatible with
1215 * Windows XP
1216 */
1217 pData->ddRVal = retValue;
1218 }
1219
1220 return retValue;
1221 }
1222
1223
1224 /*
1225 * @implemented
1226 *
1227 * D3dContextCreate
1228 */
1229 BOOL
1230 WINAPI
1231 D3dContextCreate(LPD3DHAL_CONTEXTCREATEDATA pdcci)
1232 {
1233 HANDLE hSurfZ = NULL;
1234
1235 if (pdcci->lpDDSZLcl)
1236 {
1237 hSurfZ = (HANDLE)pdcci->lpDDSZLcl->hDDSurface;
1238 }
1239
1240 return NtGdiD3dContextCreate(GetDdHandle(pdcci->lpDDLcl->hDD),
1241 (HANDLE)pdcci->lpDDSLcl->hDDSurface,
1242 hSurfZ,
1243 (D3DNTHAL_CONTEXTCREATEI *)pdcci);
1244 }
1245
1246 /*
1247 * @implemented
1248 *
1249 * DdCanCreateD3DBuffer
1250 */
1251 DWORD
1252 WINAPI
1253 DdCanCreateD3DBuffer(LPDDHAL_CANCREATESURFACEDATA CanCreateD3DBuffer)
1254 {
1255 /*
1256 * Note : This functions are basic same, in win32k
1257 * NtGdiDdCanCreateD3DBuffer and NtGdiDdCanCreateSurface are mergs
1258 * toghter in win32k at end and retrurn same data, it is still sepreated
1259 * at user mode but in kmode it is not.
1260 */
1261
1262 /* Call win32k */
1263 return NtGdiDdCanCreateD3DBuffer(GetDdHandle(CanCreateD3DBuffer->lpDD->hDD),
1264 (PDD_CANCREATESURFACEDATA)CanCreateD3DBuffer);
1265 }
1266
1267
1268 /*
1269 * @implemented
1270 *
1271 * DdCreateD3DBuffer
1272 */
1273 DWORD
1274 WINAPI
1275 DdCreateD3DBuffer(LPDDHAL_CREATESURFACEDATA pCreateSurface)
1276 {
1277 HANDLE puhSurface = 0;
1278 DDRAWI_DDRAWSURFACE_GBL *pSurfGBL;
1279 DDRAWI_DDRAWSURFACE_LCL *pSurfLcl;
1280 DD_SURFACE_GLOBAL puSurfaceGlobalData;
1281 DD_SURFACE_MORE puSurfaceMoreData;
1282 DD_SURFACE_LOCAL puSurfaceLocalData;
1283 DWORD retValue;
1284
1285 /* Zero all local memory pointer */
1286 RtlZeroMemory(&puSurfaceGlobalData, sizeof(DD_SURFACE_GLOBAL) );
1287 RtlZeroMemory(&puSurfaceMoreData, sizeof(DD_SURFACE_MORE) ) ;
1288 RtlZeroMemory(&puSurfaceLocalData, sizeof(DD_SURFACE_LOCAL) );
1289
1290 pCreateSurface->dwSCnt = 1;
1291 pSurfLcl = pCreateSurface->lplpSList[0];
1292 pSurfGBL = pSurfLcl->lpGbl;
1293
1294 /* Convert DDRAWI_DDRAWSURFACE_GBL to DD_SURFACE_GLOBAL */
1295 puSurfaceGlobalData.wWidth = pSurfGBL->wWidth;
1296 puSurfaceGlobalData.wHeight = pSurfGBL->wHeight;
1297 puSurfaceGlobalData.dwLinearSize = pSurfGBL->dwLinearSize;
1298 puSurfaceGlobalData.fpVidMem = pSurfGBL->fpVidMem;
1299 puSurfaceGlobalData.dwBlockSizeX = pSurfGBL->dwBlockSizeX;
1300 puSurfaceGlobalData.dwBlockSizeY = pSurfGBL->dwBlockSizeY;
1301
1302 /* Convert DDRAWI_DDRAWSURFACE_MORE to DD_SURFACE_MORE */
1303 puSurfaceMoreData.dwSurfaceHandle = pSurfLcl->lpSurfMore->dwSurfaceHandle;
1304 puSurfaceMoreData.ddsCapsEx.dwCaps2 = pSurfLcl->lpSurfMore->ddsCapsEx.dwCaps2;
1305 puSurfaceMoreData.ddsCapsEx.dwCaps3 = pSurfLcl->lpSurfMore->ddsCapsEx.dwCaps3;
1306 puSurfaceMoreData.ddsCapsEx.dwCaps4 = pSurfLcl->lpSurfMore->ddsCapsEx.dwCaps4;
1307
1308 /* Convert DDRAWI_DDRAWSURFACE_LCL to DD_SURFACE_LOCAL */
1309 puSurfaceLocalData.dwFlags = pSurfLcl->dwFlags;
1310 puSurfaceLocalData.ddsCaps.dwCaps = pSurfLcl->ddsCaps.dwCaps;
1311
1312 /* Call win32k */
1313 retValue = NtGdiDdCreateD3DBuffer( GetDdHandle(pCreateSurface->lpDD->hDD),
1314 (HANDLE*)&pSurfLcl->hDDSurface,
1315 pCreateSurface->lpDDSurfaceDesc,
1316 &puSurfaceGlobalData,
1317 &puSurfaceLocalData,
1318 &puSurfaceMoreData,
1319 (DD_CREATESURFACEDATA *) pCreateSurface,
1320 &puhSurface);
1321
1322 /* Setup surface handle if we got one back */
1323 if ( puhSurface != NULL )
1324 {
1325 pCreateSurface->lplpSList[0]->hDDSurface = (ULONG_PTR)puhSurface;
1326 }
1327
1328 /* Convert DD_SURFACE_GLOBAL to DDRAWI_DDRAWSURFACE_GBL */
1329 pSurfGBL->dwLinearSize = puSurfaceGlobalData.dwLinearSize;
1330 pSurfGBL->fpVidMem = puSurfaceGlobalData.fpVidMem;
1331 pSurfGBL->dwBlockSizeX = puSurfaceGlobalData.dwBlockSizeX;
1332 pSurfGBL->dwBlockSizeY = puSurfaceGlobalData.dwBlockSizeY;
1333
1334 return retValue;
1335 }
1336
1337 /*
1338 * @implemented
1339 *
1340 * DdDestroyD3DBuffer
1341 */
1342 DWORD
1343 WINAPI
1344 DdDestroyD3DBuffer(LPDDHAL_DESTROYSURFACEDATA pDestroySurface)
1345 {
1346 DWORD retValue = 0;
1347 if ( pDestroySurface->lpDDSurface->hDDSurface)
1348 {
1349 /* Call win32k */
1350 retValue = NtGdiDdDestroyD3DBuffer((HANDLE)pDestroySurface->lpDDSurface->hDDSurface);
1351 }
1352
1353 return retValue;
1354 }
1355
1356 /*
1357 * @implemented
1358 *
1359 * DdLockD3D
1360 */
1361 DWORD
1362 WINAPI
1363 DdLockD3D(LPDDHAL_LOCKDATA Lock)
1364 {
1365
1366 /* Call win32k */
1367 return NtGdiDdLockD3D((HANDLE)Lock->lpDDSurface->hDDSurface, (PDD_LOCKDATA)Lock);
1368 }
1369
1370 /*
1371 * @implemented
1372 *
1373 * DdUnlockD3D
1374 */
1375 DWORD
1376 WINAPI
1377 DdUnlockD3D(LPDDHAL_UNLOCKDATA Unlock)
1378 {
1379 /* Call win32k */
1380 return NtGdiDdUnlock((HANDLE)Unlock->lpDDSurface->hDDSurface,
1381 (PDD_UNLOCKDATA)Unlock);
1382 }
1383
1384
1385 /* PRIVATE FUNCTIONS *********************************************************/
1386
1387 BOOL
1388 WINAPI
1389 bDDCreateSurface(LPDDRAWI_DDRAWSURFACE_LCL pSurface,
1390 BOOL bComplete)
1391 {
1392 DD_SURFACE_LOCAL SurfaceLocal;
1393 DD_SURFACE_GLOBAL SurfaceGlobal;
1394 DD_SURFACE_MORE SurfaceMore;
1395
1396 /* Zero struct */
1397 RtlZeroMemory(&SurfaceLocal, sizeof(DD_SURFACE_LOCAL));
1398 RtlZeroMemory(&SurfaceGlobal, sizeof(DD_SURFACE_GLOBAL));
1399 RtlZeroMemory(&SurfaceMore, sizeof(DD_SURFACE_MORE));
1400
1401 /* Set up SurfaceLocal struct */
1402 SurfaceLocal.ddsCaps.dwCaps = pSurface->ddsCaps.dwCaps;
1403 SurfaceLocal.dwFlags = pSurface->dwFlags;
1404
1405 /* Set up SurfaceMore struct */
1406 RtlMoveMemory(&SurfaceMore.ddsCapsEx,
1407 &pSurface->ddckCKDestBlt,
1408 sizeof(DDSCAPSEX));
1409 SurfaceMore.dwSurfaceHandle = (DWORD)pSurface->dbnOverlayNode.object_int->lpVtbl;
1410
1411 /* Set up SurfaceGlobal struct */
1412 SurfaceGlobal.fpVidMem = pSurface->lpGbl->fpVidMem;
1413 SurfaceGlobal.dwLinearSize = pSurface->lpGbl->dwLinearSize;
1414 SurfaceGlobal.wHeight = pSurface->lpGbl->wHeight;
1415 SurfaceGlobal.wWidth = pSurface->lpGbl->wWidth;
1416
1417 /* Check if we have a pixel format */
1418 if (pSurface->dwFlags & DDSD_PIXELFORMAT)
1419 {
1420 /* Use global one */
1421 SurfaceGlobal.ddpfSurface = pSurface->lpGbl->lpDD->vmiData.ddpfDisplay;
1422 SurfaceGlobal.ddpfSurface.dwSize = sizeof(DDPIXELFORMAT);
1423 }
1424 else
1425 {
1426 /* Use local one */
1427 SurfaceGlobal.ddpfSurface = pSurface->lpGbl->lpDD->vmiData.ddpfDisplay;
1428 }
1429
1430 /* Create the object */
1431 pSurface->hDDSurface = (DWORD)NtGdiDdCreateSurfaceObject(GetDdHandle(pSurface->lpGbl->lpDD->hDD),
1432 (HANDLE)pSurface->hDDSurface,
1433 &SurfaceLocal,
1434 &SurfaceMore,
1435 &SurfaceGlobal,
1436 bComplete);
1437
1438 /* Return status */
1439 if (pSurface->hDDSurface) return TRUE;
1440 return FALSE;
1441 }
1442
1443 /* PUBLIC FUNCTIONS **********************************************************/
1444
1445 /*
1446 * @implemented
1447 *
1448 * GDIEntry 1
1449 */
1450 BOOL
1451 WINAPI
1452 DdCreateDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
1453 HDC hdc)
1454 {
1455 BOOL Return = FALSE;
1456
1457 /* Check if the global hDC (hdc == 0) is being used */
1458 if (!hdc)
1459 {
1460 /* We'll only allow this if the global object doesn't exist yet */
1461 if (!ghDirectDraw)
1462 {
1463 /* Create the DC */
1464 if ((hdc = CreateDCW(L"Display", NULL, NULL, NULL)))
1465 {
1466 /* Create the DDraw Object */
1467 ghDirectDraw = NtGdiDdCreateDirectDrawObject(hdc);
1468
1469 /* Delete our DC */
1470 DeleteDC(hdc);
1471 }
1472 }
1473
1474 /* If we created the object, or had one ...*/
1475 if (ghDirectDraw)
1476 {
1477 /* Increase count and set success */
1478 gcDirectDraw++;
1479 Return = TRUE;
1480 }
1481
1482 /* Zero the handle */
1483 pDirectDrawGlobal->hDD = 0;
1484 }
1485 else
1486 {
1487 /* Using the per-process object, so create it */
1488 pDirectDrawGlobal->hDD = (ULONG_PTR)NtGdiDdCreateDirectDrawObject(hdc);
1489
1490 /* Set the return value */
1491 Return = pDirectDrawGlobal->hDD ? TRUE : FALSE;
1492 }
1493
1494 /* Return to caller */
1495 return Return;
1496 }
1497
1498 /*
1499 * @implemented
1500 *
1501 * GDIEntry 2
1502 */
1503 BOOL
1504 WINAPI
1505 DdQueryDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
1506 LPDDHALINFO pHalInfo,
1507 LPDDHAL_DDCALLBACKS pDDCallbacks,
1508 LPDDHAL_DDSURFACECALLBACKS pDDSurfaceCallbacks,
1509 LPDDHAL_DDPALETTECALLBACKS pDDPaletteCallbacks,
1510 LPD3DHAL_CALLBACKS pD3dCallbacks,
1511 LPD3DHAL_GLOBALDRIVERDATA pD3dDriverData,
1512 LPDDHAL_DDEXEBUFCALLBACKS pD3dBufferCallbacks,
1513 LPDDSURFACEDESC pD3dTextureFormats,
1514 LPDWORD pdwFourCC,
1515 LPVIDMEM pvmList)
1516 {
1517 PVIDEOMEMORY VidMemList = NULL;
1518 DD_HALINFO HalInfo;
1519 D3DNTHAL_CALLBACKS D3dCallbacks;
1520 D3DNTHAL_GLOBALDRIVERDATA D3dDriverData;
1521 DD_D3DBUFCALLBACKS D3dBufferCallbacks;
1522 DWORD CallbackFlags[3];
1523 DWORD dwNumHeaps=0, FourCCs=0;
1524 DWORD Flags;
1525 BOOL retVal = TRUE;
1526
1527 /* Clear the structures */
1528 RtlZeroMemory(&HalInfo, sizeof(DD_HALINFO));
1529 RtlZeroMemory(&D3dCallbacks, sizeof(D3DNTHAL_CALLBACKS));
1530 RtlZeroMemory(&D3dDriverData, sizeof(D3DNTHAL_GLOBALDRIVERDATA));
1531 RtlZeroMemory(&D3dBufferCallbacks, sizeof(DD_D3DBUFCALLBACKS));
1532 RtlZeroMemory(CallbackFlags, sizeof(DWORD)*3);
1533
1534 /* Note : XP always alloc 24*sizeof(VIDEOMEMORY) of pvmlist so we change it to it */
1535 if ( (pvmList != NULL) &&
1536 (pHalInfo->vmiData.dwNumHeaps != 0) )
1537 {
1538 VidMemList = (PVIDEOMEMORY) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (sizeof(VIDEOMEMORY) * 24 ) * pHalInfo->vmiData.dwNumHeaps);
1539 }
1540
1541
1542 /* Do the query */
1543 if (!NtGdiDdQueryDirectDrawObject(GetDdHandle(pDirectDrawGlobal->hDD),
1544 &HalInfo,
1545 CallbackFlags,
1546 &D3dCallbacks,
1547 &D3dDriverData,
1548 &D3dBufferCallbacks,
1549 pD3dTextureFormats,
1550 &dwNumHeaps,
1551 VidMemList,
1552 &FourCCs,
1553 pdwFourCC))
1554 {
1555 /* We failed, free the memory and return */
1556 retVal = FALSE;
1557 goto cleanup;
1558 }
1559
1560 /* Clear the incoming pointer */
1561 RtlZeroMemory(pHalInfo, sizeof(DDHALINFO));
1562
1563 /* Convert all the data */
1564 pHalInfo->dwSize = sizeof(DDHALINFO);
1565 pHalInfo->lpDDCallbacks = pDDCallbacks;
1566 pHalInfo->lpDDSurfaceCallbacks = pDDSurfaceCallbacks;
1567 pHalInfo->lpDDPaletteCallbacks = pDDPaletteCallbacks;
1568
1569 /* Check for NT5+ D3D Data */
1570 if ( (D3dCallbacks.dwSize != 0) &&
1571 (D3dDriverData.dwSize != 0) )
1572 {
1573 /* Write these down */
1574 pHalInfo->lpD3DGlobalDriverData = (ULONG_PTR)pD3dDriverData;
1575 pHalInfo->lpD3DHALCallbacks = (ULONG_PTR)pD3dCallbacks;
1576
1577 /* Check for Buffer Callbacks */
1578 if (D3dBufferCallbacks.dwSize)
1579 {
1580 /* Write this one too */
1581 pHalInfo->lpDDExeBufCallbacks = pD3dBufferCallbacks;
1582 }
1583 }
1584
1585 /* Continue converting the rest */
1586 pHalInfo->vmiData.dwFlags = HalInfo.vmiData.dwFlags;
1587 pHalInfo->vmiData.dwDisplayWidth = HalInfo.vmiData.dwDisplayWidth;
1588 pHalInfo->vmiData.dwDisplayHeight = HalInfo.vmiData.dwDisplayHeight;
1589 pHalInfo->vmiData.lDisplayPitch = HalInfo.vmiData.lDisplayPitch;
1590 pHalInfo->vmiData.fpPrimary = 0;
1591
1592 RtlCopyMemory( &pHalInfo->vmiData.ddpfDisplay,
1593 &HalInfo.vmiData.ddpfDisplay,
1594 sizeof(DDPIXELFORMAT));
1595
1596 pHalInfo->vmiData.dwOffscreenAlign = HalInfo.vmiData.dwOffscreenAlign;
1597 pHalInfo->vmiData.dwOverlayAlign = HalInfo.vmiData.dwOverlayAlign;
1598 pHalInfo->vmiData.dwTextureAlign = HalInfo.vmiData.dwTextureAlign;
1599 pHalInfo->vmiData.dwZBufferAlign = HalInfo.vmiData.dwZBufferAlign;
1600 pHalInfo->vmiData.dwAlphaAlign = HalInfo.vmiData.dwAlphaAlign;
1601
1602 pHalInfo->vmiData.dwNumHeaps = dwNumHeaps;
1603 pHalInfo->vmiData.pvmList = pvmList;
1604
1605 RtlCopyMemory( &pHalInfo->ddCaps,
1606 &HalInfo.ddCaps,
1607 sizeof(DDCORECAPS ));
1608
1609 pHalInfo->ddCaps.dwNumFourCCCodes = FourCCs;
1610 pHalInfo->lpdwFourCC = pdwFourCC;
1611
1612 /* always force rope 0x1000 for hal it mean only source copy is supported */
1613 pHalInfo->ddCaps.dwRops[6] = 0x1000;
1614
1615 /* Set the HAL flags what ReactX got from the driver
1616 * Windows XP force setting DDHALINFO_GETDRIVERINFOSET if the driver does not set it
1617 * and ReactX doing same to keep compatible with drivers, but the driver are
1618 * force support DdGetDriverInfo acoriding MSDN but it seam some driver do not set
1619 * this flag even it is being supported. that is mean. It is small hack to keep
1620 * bad driver working, that trust this is always being setting by it self at end
1621 */
1622 pHalInfo->dwFlags = (HalInfo.dwFlags & ~DDHALINFO_GETDRIVERINFOSET) | DDHALINFO_GETDRIVERINFOSET;
1623 pHalInfo->GetDriverInfo = (LPDDHAL_GETDRIVERINFO) DdGetDriverInfo;
1624
1625 /* Now check if we got any DD callbacks */
1626 if (pDDCallbacks)
1627 {
1628 /* Zero the structure */
1629 RtlZeroMemory(pDDCallbacks, sizeof(DDHAL_DDCALLBACKS));
1630 pDDCallbacks->dwSize = sizeof(DDHAL_DDCALLBACKS);
1631
1632 /* Set the flags for this structure
1633 * Windows XP force setting DDHAL_CB32_CREATESURFACE if the driver does not set it
1634 * and ReactX doing same to keep compatible with drivers, but the driver are
1635 * force support pDDCallbacks acoriding MSDN but it seam some driver do not set
1636 * this flag even it is being supported. that is mean. It is small hack to keep
1637 * bad driver working, that trust this is always being setting by it self at end
1638 */
1639 Flags = (CallbackFlags[0] & ~DDHAL_CB32_CREATESURFACE) | DDHAL_CB32_CREATESURFACE;
1640 pDDCallbacks->dwFlags = Flags;
1641
1642 /* Write the always-on functions */
1643 pDDCallbacks->CreateSurface = DdCreateSurface;
1644
1645 /* Now write the pointers, if applicable */
1646 if (Flags & DDHAL_CB32_WAITFORVERTICALBLANK)
1647 {
1648 pDDCallbacks->WaitForVerticalBlank = DdWaitForVerticalBlank;
1649 }
1650 if (Flags & DDHAL_CB32_CANCREATESURFACE)
1651 {
1652 pDDCallbacks->CanCreateSurface = DdCanCreateSurface;
1653 }
1654 if (Flags & DDHAL_CB32_GETSCANLINE)
1655 {
1656 pDDCallbacks->GetScanLine = DdGetScanLine;
1657 }
1658 }
1659
1660 /* Check for DD Surface Callbacks */
1661 if (pDDSurfaceCallbacks)
1662 {
1663 /* Zero the structures */
1664 RtlZeroMemory(pDDSurfaceCallbacks, sizeof(DDHAL_DDSURFACECALLBACKS));
1665 pDDSurfaceCallbacks->dwSize = sizeof(DDHAL_DDSURFACECALLBACKS);
1666
1667 /* Set the flags for this structure
1668 * Windows XP force setting DDHAL_SURFCB32_LOCK, DDHAL_SURFCB32_UNLOCK,
1669 * DDHAL_SURFCB32_SETCOLORKEY, DDHAL_SURFCB32_DESTROYSURFACE if the driver
1670 * does not set it and ReactX doing same to keep compatible with drivers,
1671 * but the driver are force support pDDSurfaceCallbacks acoriding MSDN but it seam
1672 * some driver do not set this flag even it is being supported. that is mean.
1673 * It is small hack to keep bad driver working, that trust this is always being
1674 * setting by it self at end
1675 */
1676
1677 Flags = (CallbackFlags[1] & ~(DDHAL_SURFCB32_LOCK | DDHAL_SURFCB32_UNLOCK |
1678 DDHAL_SURFCB32_SETCOLORKEY | DDHAL_SURFCB32_DESTROYSURFACE)) |
1679 (DDHAL_SURFCB32_LOCK | DDHAL_SURFCB32_UNLOCK |
1680 DDHAL_SURFCB32_SETCOLORKEY | DDHAL_SURFCB32_DESTROYSURFACE);
1681
1682 pDDSurfaceCallbacks->dwFlags = Flags;
1683
1684 /* Write the always-on functions */
1685 pDDSurfaceCallbacks->Lock = DdLock;
1686 pDDSurfaceCallbacks->Unlock = DdUnlock;
1687 pDDSurfaceCallbacks->SetColorKey = DdSetColorKey;
1688 pDDSurfaceCallbacks->DestroySurface = DdDestroySurface;
1689
1690 /* Write the optional ones */
1691 if (Flags & DDHAL_SURFCB32_FLIP)
1692 {
1693 pDDSurfaceCallbacks->Flip = DdFlip;
1694 }
1695 if (Flags & DDHAL_SURFCB32_BLT)
1696 {
1697 pDDSurfaceCallbacks->Blt = DdBlt;
1698 }
1699 if (Flags & DDHAL_SURFCB32_GETBLTSTATUS)
1700 {
1701 pDDSurfaceCallbacks->GetBltStatus = DdGetBltStatus;
1702 }
1703 if (Flags & DDHAL_SURFCB32_GETFLIPSTATUS)
1704 {
1705 pDDSurfaceCallbacks->GetFlipStatus = DdGetFlipStatus;
1706 }
1707 if (Flags & DDHAL_SURFCB32_UPDATEOVERLAY)
1708 {
1709 pDDSurfaceCallbacks->UpdateOverlay = DdUpdateOverlay;
1710 }
1711 if (Flags & DDHAL_SURFCB32_SETOVERLAYPOSITION)
1712 {
1713 pDDSurfaceCallbacks->SetOverlayPosition = DdSetOverlayPosition;
1714 }
1715 if (Flags & DDHAL_SURFCB32_ADDATTACHEDSURFACE)
1716 {
1717 pDDSurfaceCallbacks->AddAttachedSurface = DdAddAttachedSurface;
1718 }
1719 }
1720
1721 /* Check for DD Palette Callbacks, This interface are dead for user mode,
1722 * only what it can support are being report back.
1723 */
1724 if (pDDPaletteCallbacks)
1725 {
1726 /* Zero the struct */
1727 RtlZeroMemory(pDDPaletteCallbacks, sizeof(DDHAL_DDPALETTECALLBACKS));
1728
1729 /* Write the header */
1730 pDDPaletteCallbacks->dwSize = sizeof(DDHAL_DDPALETTECALLBACKS);
1731 pDDPaletteCallbacks->dwFlags = CallbackFlags[2];
1732 }
1733
1734 if (pD3dCallbacks)
1735 {
1736 /* Zero the struct */
1737 RtlZeroMemory(pD3dCallbacks, sizeof(DDHAL_DDEXEBUFCALLBACKS));
1738
1739 /* Check if we have one */
1740 if (D3dCallbacks.dwSize)
1741 {
1742 /* Write the header */
1743 pD3dCallbacks->dwSize = sizeof(DDHAL_DDEXEBUFCALLBACKS);
1744
1745 /* Now check for each callback */
1746 if (D3dCallbacks.ContextCreate)
1747 {
1748 pD3dCallbacks->ContextCreate = (LPD3DHAL_CONTEXTCREATECB) D3dContextCreate;
1749 }
1750 if (D3dCallbacks.ContextDestroy)
1751 {
1752 pD3dCallbacks->ContextDestroy = (LPD3DHAL_CONTEXTDESTROYCB) NtGdiD3dContextDestroy;
1753 }
1754 if (D3dCallbacks.ContextDestroyAll)
1755 {
1756 pD3dCallbacks->ContextDestroyAll = (LPD3DHAL_CONTEXTDESTROYALLCB) NtGdiD3dContextDestroyAll;
1757 }
1758 }
1759 }
1760
1761 /* Check for D3D Driver Data */
1762 if (pD3dDriverData)
1763 {
1764 /* Copy the struct */
1765 RtlMoveMemory(pD3dDriverData, &D3dDriverData, sizeof(D3DHAL_GLOBALDRIVERDATA));
1766
1767 /* Write the pointer to the texture formats */
1768 pD3dDriverData->lpTextureFormats = pD3dTextureFormats;
1769 }
1770
1771 /* Check for D3D Buffer Callbacks */
1772 if (pD3dBufferCallbacks)
1773 {
1774 /* Zero the struct */
1775 RtlZeroMemory(pD3dBufferCallbacks, sizeof(DDHAL_DDEXEBUFCALLBACKS));
1776
1777 if ( D3dBufferCallbacks.dwSize)
1778 {
1779 pD3dBufferCallbacks->dwSize = D3dBufferCallbacks.dwSize;
1780
1781 pD3dBufferCallbacks->dwFlags = D3dBufferCallbacks.dwFlags;
1782 if ( D3dBufferCallbacks.CanCreateD3DBuffer)
1783 {
1784 pD3dBufferCallbacks->CanCreateExecuteBuffer = (LPDDHALEXEBUFCB_CANCREATEEXEBUF)DdCanCreateD3DBuffer;
1785 }
1786
1787 if (D3dBufferCallbacks.CreateD3DBuffer)
1788 {
1789 pD3dBufferCallbacks->CreateExecuteBuffer = (LPDDHALEXEBUFCB_CREATEEXEBUF) DdCreateD3DBuffer;
1790 }
1791
1792 if ( D3dBufferCallbacks.DestroyD3DBuffer )
1793 {
1794 pD3dBufferCallbacks->DestroyExecuteBuffer = (LPDDHALEXEBUFCB_DESTROYEXEBUF) DdDestroyD3DBuffer;
1795 }
1796
1797 if ( D3dBufferCallbacks.LockD3DBuffer )
1798 {
1799 pD3dBufferCallbacks->LockExecuteBuffer = (LPDDHALEXEBUFCB_LOCKEXEBUF) DdLockD3D;
1800 }
1801
1802 if ( D3dBufferCallbacks.UnlockD3DBuffer )
1803 {
1804 pD3dBufferCallbacks->UnlockExecuteBuffer = (LPDDHALEXEBUFCB_UNLOCKEXEBUF) DdUnlockD3D;
1805 }
1806
1807 }
1808 }
1809
1810 /* FIXME VidMemList */
1811
1812 cleanup:
1813 if (VidMemList)
1814 {
1815 HeapFree(GetProcessHeap(), 0, VidMemList);
1816 }
1817
1818 return retVal;
1819 }
1820
1821 /*
1822 * @implemented
1823 *
1824 * GDIEntry 3
1825 */
1826 BOOL
1827 WINAPI
1828 DdDeleteDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal)
1829 {
1830 BOOL Return = FALSE;
1831
1832 /* If this is the global object */
1833 if(pDirectDrawGlobal->hDD)
1834 {
1835 /* Free it */
1836 Return = NtGdiDdDeleteDirectDrawObject((HANDLE)pDirectDrawGlobal->hDD);
1837 if (Return == TRUE)
1838 {
1839 pDirectDrawGlobal->hDD = 0;
1840 }
1841 }
1842 else if (ghDirectDraw)
1843 {
1844 /* Always success here */
1845 Return = TRUE;
1846
1847 /* Make sure this is the last instance */
1848 if (!(--gcDirectDraw))
1849 {
1850 /* Delete the object */
1851 Return = NtGdiDdDeleteDirectDrawObject(ghDirectDraw);
1852 if (Return == TRUE)
1853 {
1854 ghDirectDraw = 0;
1855 }
1856 }
1857 }
1858
1859 /* Return */
1860 return Return;
1861 }
1862
1863 /*
1864 * @implemented
1865 *
1866 * GDIEntry 4
1867 */
1868 BOOL
1869 WINAPI
1870 DdCreateSurfaceObject( LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
1871 BOOL bPrimarySurface)
1872 {
1873 return bDDCreateSurface(pSurfaceLocal, TRUE);
1874 }
1875
1876
1877 /*
1878 * @implemented
1879 *
1880 * GDIEntry 5
1881 */
1882 BOOL
1883 WINAPI
1884 DdDeleteSurfaceObject(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal)
1885 {
1886 BOOL Return = FALSE;
1887
1888 /* Make sure there is one */
1889 if (pSurfaceLocal->hDDSurface)
1890 {
1891 /* Delete it */
1892 Return = NtGdiDdDeleteSurfaceObject((HANDLE)pSurfaceLocal->hDDSurface);
1893 pSurfaceLocal->hDDSurface = 0;
1894 }
1895
1896 return Return;
1897 }
1898
1899 /*
1900 * @implemented
1901 *
1902 * GDIEntry 6
1903 */
1904 BOOL
1905 WINAPI
1906 DdResetVisrgn(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
1907 HWND hWnd)
1908 {
1909 /* Call win32k directly */
1910 return NtGdiDdResetVisrgn((HANDLE) pSurfaceLocal->hDDSurface, hWnd);
1911 }
1912
1913 /*
1914 * @implemented
1915 *
1916 * GDIEntry 7
1917 */
1918 HDC
1919 WINAPI
1920 DdGetDC(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
1921 LPPALETTEENTRY pColorTable)
1922 {
1923 /* Call win32k directly */
1924 return NtGdiDdGetDC(pColorTable, (HANDLE) pSurfaceLocal->hDDSurface);
1925 }
1926
1927 /*
1928 * @implemented
1929 *
1930 * GDIEntry 8
1931 */
1932 BOOL
1933 WINAPI
1934 DdReleaseDC(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal)
1935 {
1936 /* Call win32k directly */
1937 return NtGdiDdReleaseDC((HANDLE) pSurfaceLocal->hDDSurface);
1938 }
1939
1940 /*
1941 * @unimplemented
1942 * GDIEntry 9
1943 */
1944 HBITMAP
1945 WINAPI
1946 DdCreateDIBSection(HDC hdc,
1947 CONST BITMAPINFO *pbmi,
1948 UINT iUsage,
1949 VOID **ppvBits,
1950 HANDLE hSectionApp,
1951 DWORD dwOffset)
1952 {
1953 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1954 return 0;
1955 }
1956
1957 /*
1958 * @implemented
1959 *
1960 * GDIEntry 10
1961 */
1962 BOOL
1963 WINAPI
1964 DdReenableDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
1965 BOOL *pbNewMode)
1966 {
1967 /* Call win32k directly */
1968 return NtGdiDdReenableDirectDrawObject(GetDdHandle(pDirectDrawGlobal->hDD),
1969 pbNewMode);
1970 }
1971
1972
1973 /*
1974 * @implemented
1975 *
1976 * GDIEntry 11
1977 */
1978 BOOL
1979 WINAPI
1980 DdAttachSurface( LPDDRAWI_DDRAWSURFACE_LCL pSurfaceFrom,
1981 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceTo)
1982 {
1983 /* Create Surface if it does not exits one */
1984 if (!pSurfaceFrom->hDDSurface)
1985 {
1986 if (!bDDCreateSurface(pSurfaceFrom, FALSE))
1987 {
1988 return FALSE;
1989 }
1990 }
1991
1992 /* Create Surface if it does not exits one */
1993 if (!pSurfaceTo->hDDSurface)
1994 {
1995 if (!bDDCreateSurface(pSurfaceTo, FALSE))
1996 {
1997 return FALSE;
1998 }
1999 }
2000
2001 /* Call win32k */
2002 return NtGdiDdAttachSurface((HANDLE)pSurfaceFrom->hDDSurface,
2003 (HANDLE)pSurfaceTo->hDDSurface);
2004 }
2005
2006 /*
2007 * @implemented
2008 *
2009 * GDIEntry 12
2010 */
2011 VOID
2012 WINAPI
2013 DdUnattachSurface(LPDDRAWI_DDRAWSURFACE_LCL pSurface,
2014 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceAttached)
2015 {
2016 /* Call win32k */
2017 NtGdiDdUnattachSurface((HANDLE)pSurface->hDDSurface,
2018 (HANDLE)pSurfaceAttached->hDDSurface);
2019 }
2020
2021 /*
2022 * @implemented
2023 *
2024 * GDIEntry 13
2025 */
2026 ULONG
2027 WINAPI
2028 DdQueryDisplaySettingsUniqueness()
2029 {
2030 return GdiSharedHandleTable->flDeviceUniq;
2031 }
2032
2033 /*
2034 * @implemented
2035 *
2036 * GDIEntry 14
2037 */
2038 HANDLE
2039 WINAPI
2040 DdGetDxHandle(LPDDRAWI_DIRECTDRAW_LCL pDDraw,
2041 LPDDRAWI_DDRAWSURFACE_LCL pSurface,
2042 BOOL bRelease)
2043 {
2044 HANDLE hDD = NULL;
2045 HANDLE hSurface = NULL;
2046
2047 /* Check if we already have a surface */
2048 if (!pSurface)
2049 {
2050 /* We don't have one, use the DirectDraw Object handle instead */
2051 hDD = GetDdHandle(pDDraw->lpGbl->hDD);
2052 }
2053 else
2054 {
2055 hSurface = (HANDLE)pSurface->hDDSurface;
2056 }
2057
2058 /* Call the API */
2059 return (HANDLE)NtGdiDdGetDxHandle(hDD, hSurface, bRelease);
2060 }
2061
2062 /*
2063 * @implemented
2064 *
2065 * GDIEntry 15
2066 */
2067 BOOL
2068 WINAPI
2069 DdSetGammaRamp(LPDDRAWI_DIRECTDRAW_LCL pDDraw,
2070 HDC hdc,
2071 LPVOID lpGammaRamp)
2072 {
2073 /* Call win32k directly */
2074 return NtGdiDdSetGammaRamp(GetDdHandle(pDDraw->lpGbl->hDD),
2075 hdc,
2076 lpGammaRamp);
2077 }
2078
2079
2080
2081
2082