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 WORD
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 BOOL
331 WINAPI
332 bDDCreateSurface(LPDDRAWI_DDRAWSURFACE_LCL pSurface,
333 BOOL bComplete)
334 {
335 DD_SURFACE_LOCAL SurfaceLocal;
336 DD_SURFACE_GLOBAL SurfaceGlobal;
337 DD_SURFACE_MORE SurfaceMore;
338
339 /* Zero struct */
340 RtlZeroMemory(&SurfaceLocal, sizeof(DD_SURFACE_LOCAL));
341 RtlZeroMemory(&SurfaceGlobal, sizeof(DD_SURFACE_GLOBAL));
342 RtlZeroMemory(&SurfaceMore, sizeof(DD_SURFACE_MORE));
343
344 /* Set up SurfaceLocal struct */
345 SurfaceLocal.ddsCaps.dwCaps = pSurface->ddsCaps.dwCaps;
346 SurfaceLocal.dwFlags = pSurface->dwFlags;
347
348 /* Set up SurfaceMore struct */
349 RtlMoveMemory(&SurfaceMore.ddsCapsEx,
350 &pSurface->ddckCKDestBlt,
351 sizeof(DDSCAPSEX));
352 SurfaceMore.dwSurfaceHandle = (DWORD)pSurface->dbnOverlayNode.object_int->lpVtbl;
353
354 /* Set up SurfaceGlobal struct */
355 SurfaceGlobal.fpVidMem = pSurface->lpGbl->fpVidMem;
356 SurfaceGlobal.dwLinearSize = pSurface->lpGbl->dwLinearSize;
357 SurfaceGlobal.wHeight = pSurface->lpGbl->wHeight;
358 SurfaceGlobal.wWidth = pSurface->lpGbl->wWidth;
359
360 /* Check if we have a pixel format */
361 if (pSurface->dwFlags & DDSD_PIXELFORMAT)
362 {
363 /* Use global one */
364 SurfaceGlobal.ddpfSurface = pSurface->lpGbl->lpDD->vmiData.ddpfDisplay;
365 SurfaceGlobal.ddpfSurface.dwSize = sizeof(DDPIXELFORMAT);
366 }
367 else
368 {
369 /* Use local one */
370 SurfaceGlobal.ddpfSurface = pSurface->lpGbl->lpDD->vmiData.ddpfDisplay;
371 }
372
373 /* Create the object */
374 pSurface->hDDSurface = (DWORD)NtGdiDdCreateSurfaceObject(GetDdHandle(pSurface->lpGbl->lpDD->hDD),
375 (HANDLE)pSurface->hDDSurface,
376 &SurfaceLocal,
377 &SurfaceMore,
378 &SurfaceGlobal,
379 bComplete);
380
381 /* Return status */
382 if (pSurface->hDDSurface) return TRUE;
383 return FALSE;
384 }
385
386 /* PUBLIC FUNCTIONS **********************************************************/
387
388 /*
389 * @implemented
390 *
391 * GDIEntry 1
392 */
393 BOOL
394 WINAPI
395 DdCreateDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
396 HDC hdc)
397 {
398 BOOL Return = FALSE;
399
400 /* Check if the global hDC (hdc == 0) is being used */
401 if (!hdc)
402 {
403 /* We'll only allow this if the global object doesn't exist yet */
404 if (!ghDirectDraw)
405 {
406 /* Create the DC */
407 if ((hdc = CreateDC(L"Display", NULL, NULL, NULL)))
408 {
409 /* Create the DDraw Object */
410 ghDirectDraw = NtGdiDdCreateDirectDrawObject(hdc);
411
412 /* Delete our DC */
413 NtGdiDeleteObjectApp(hdc);
414 }
415 }
416
417 /* If we created the object, or had one ...*/
418 if (ghDirectDraw)
419 {
420 /* Increase count and set success */
421 gcDirectDraw++;
422 Return = TRUE;
423 }
424
425 /* Zero the handle */
426 pDirectDrawGlobal->hDD = 0;
427 }
428 else
429 {
430 /* Using the per-process object, so create it */
431 pDirectDrawGlobal->hDD = (ULONG_PTR)NtGdiDdCreateDirectDrawObject(hdc);
432
433 /* Set the return value */
434 Return = pDirectDrawGlobal->hDD ? TRUE : FALSE;
435 }
436
437 /* Return to caller */
438 return Return;
439 }
440
441
442
443
444 static LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobalInternal;
445 static ULONG RemberDdQueryDisplaySettingsUniquenessID = 0;
446
447 BOOL
448 intDDCreateSurface ( LPDDRAWI_DDRAWSURFACE_LCL pSurface,
449 BOOL bComplete);
450
451
452
453
454 /*
455 * @unimplemented
456 */
457 BOOL
458 STDCALL
459 DdQueryDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
460 LPDDHALINFO pHalInfo,
461 LPDDHAL_DDCALLBACKS pDDCallbacks,
462 LPDDHAL_DDSURFACECALLBACKS pDDSurfaceCallbacks,
463 LPDDHAL_DDPALETTECALLBACKS pDDPaletteCallbacks,
464 LPD3DHAL_CALLBACKS pD3dCallbacks,
465 LPD3DHAL_GLOBALDRIVERDATA pD3dDriverData,
466 LPDDHAL_DDEXEBUFCALLBACKS pD3dBufferCallbacks,
467 LPDDSURFACEDESC pD3dTextureFormats,
468 LPDWORD pdwFourCC,
469 LPVIDMEM pvmList)
470 {
471 BOOL bStatus = FALSE;
472 DD_HALINFO DDHalInfo;
473 LPVOID pCallBackFlags[3];
474 DWORD NumHeaps;
475 DWORD NumFourCC;
476
477 DDHalInfo.dwSize = sizeof(DD_HALINFO);
478
479 pCallBackFlags[0] = pDDCallbacks;
480 pCallBackFlags[1] = pDDSurfaceCallbacks;
481 pCallBackFlags[2] = pDDPaletteCallbacks;
482
483 bStatus = NtGdiDdQueryDirectDrawObject(
484 (HANDLE)pDirectDrawGlobal->hDD,
485 (DD_HALINFO *)&DDHalInfo,
486 (DWORD *)pCallBackFlags,
487 (LPD3DNTHAL_CALLBACKS)pD3dCallbacks,
488 (LPD3DNTHAL_GLOBALDRIVERDATA)pD3dDriverData,
489 (PDD_D3DBUFCALLBACKS)pD3dBufferCallbacks,
490 (LPDDSURFACEDESC)pD3dTextureFormats,
491 (DWORD *)&NumHeaps,
492 (VIDEOMEMORY *)pvmList,
493 (DWORD *)&NumFourCC,
494 (DWORD *)pdwFourCC);
495
496
497 //SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
498 return bStatus;
499 }
500
501 /*
502 * @unimplemented
503 */
504 HBITMAP
505 STDCALL
506 DdCreateDIBSection(HDC hdc,
507 CONST BITMAPINFO *pbmi,
508 UINT iUsage,
509 VOID **ppvBits,
510 HANDLE hSectionApp,
511 DWORD dwOffset)
512 {
513 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
514 return 0;
515 }
516
517 /*
518 * @implemented
519 *
520 * GDIEntry 3
521 */
522 BOOL
523 STDCALL
524 DdDeleteDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal)
525 {
526 BOOL status;
527 /* if pDirectDrawGlobal->hDD == NULL and pDirectDrawGlobalInternal->hDD == NULL
528 return false */
529
530 if (!pDirectDrawGlobal->hDD)
531 {
532 if (!pDirectDrawGlobalInternal->hDD)
533 {
534 return FALSE;
535 }
536 return NtGdiDdDeleteDirectDrawObject((HANDLE)pDirectDrawGlobalInternal->hDD);
537 }
538
539 status = NtGdiDdDeleteDirectDrawObject((HANDLE)pDirectDrawGlobal->hDD);
540 if ((status == TRUE) && (pDirectDrawGlobalInternal->hDD != 0))
541 {
542 pDirectDrawGlobalInternal->hDD = 0;
543 }
544
545 return status;
546 }
547
548 /*
549 * @implemented
550 *
551 * GDIEntry 4
552 */
553 BOOL
554 STDCALL
555 DdCreateSurfaceObject( LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
556 BOOL bPrimarySurface)
557 {
558 return intDDCreateSurface(pSurfaceLocal,1);
559 }
560
561 /*
562 * @implemented
563 *
564 * GDIEntry 5
565 */
566 BOOL
567 STDCALL
568 DdDeleteSurfaceObject(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal)
569 {
570 if (!pSurfaceLocal->hDDSurface)
571 {
572 return FALSE;
573 }
574
575 return NtGdiDdDeleteSurfaceObject((HANDLE)pSurfaceLocal->hDDSurface);
576 }
577
578 /*
579 * @implemented
580 *
581 * GDIEntry 6
582 */
583 BOOL
584 STDCALL
585 DdResetVisrgn(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
586 HWND hWnd)
587 {
588 return NtGdiDdResetVisrgn((HANDLE) pSurfaceLocal->hDDSurface, hWnd);
589 }
590
591 /*
592 * @implemented
593 *
594 * GDIEntry 7
595 */
596 HDC STDCALL DdGetDC(
597 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
598 LPPALETTEENTRY pColorTable
599 )
600 {
601 return NtGdiDdGetDC(pColorTable, (HANDLE) pSurfaceLocal->hDDSurface);
602 }
603
604 /*
605 * @implemented
606 *
607 * GDIEntry 8
608 */
609 BOOL STDCALL DdReleaseDC(
610 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal
611 )
612 {
613 return NtGdiDdReleaseDC((HANDLE) pSurfaceLocal->hDDSurface);
614 }
615
616
617
618 /*
619 * @implemented
620 *
621 * GDIEntry 10
622 */
623 BOOL
624 STDCALL
625 DdReenableDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
626 BOOL *pbNewMode)
627 {
628 if (!pDirectDrawGlobal->hDD)
629 {
630 if (!pDirectDrawGlobalInternal->hDD)
631 {
632 return FALSE;
633 }
634 return NtGdiDdReenableDirectDrawObject((HANDLE)pDirectDrawGlobalInternal->hDD, pbNewMode);
635 }
636
637 return NtGdiDdReenableDirectDrawObject((HANDLE)pDirectDrawGlobal->hDD, pbNewMode);
638 }
639
640 /*
641 * @implemented
642 *
643 * GDIEntry 11
644 */
645 BOOL
646 STDCALL
647 DdAttachSurface( LPDDRAWI_DDRAWSURFACE_LCL pSurfaceFrom,
648 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceTo)
649 {
650
651 /* Create Surface if it does not exits one */
652 if (pSurfaceFrom->hDDSurface)
653 {
654 if (!intDDCreateSurface(pSurfaceFrom,FALSE))
655 {
656 return FALSE;
657 }
658 }
659
660 /* Create Surface if it does not exits one */
661 if (pSurfaceTo->hDDSurface)
662 {
663 if (!intDDCreateSurface(pSurfaceTo,FALSE))
664 {
665 return FALSE;
666 }
667 }
668
669 return NtGdiDdAttachSurface( (HANDLE) pSurfaceFrom->hDDSurface, (HANDLE) pSurfaceTo->hDDSurface);
670 }
671
672 /*
673 * @implemented
674 *
675 * GDIEntry 12
676 */
677 VOID
678 STDCALL
679 DdUnattachSurface(LPDDRAWI_DDRAWSURFACE_LCL pSurface,
680 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceAttached)
681 {
682 NtGdiDdUnattachSurface((HANDLE) pSurface->hDDSurface, (HANDLE) pSurfaceAttached->hDDSurface);
683 }
684
685 /*
686 * @implemented
687 *
688 * GDIEntry 13
689 */
690 ULONG
691 STDCALL
692 DdQueryDisplaySettingsUniqueness()
693 {
694 return RemberDdQueryDisplaySettingsUniquenessID;
695 }
696
697 /*
698 * @implemented
699 *
700 * GDIEntry 14
701 */
702 HANDLE
703 STDCALL
704 DdGetDxHandle(LPDDRAWI_DIRECTDRAW_LCL pDDraw,
705 LPDDRAWI_DDRAWSURFACE_LCL pSurface,
706 BOOL bRelease)
707 {
708 if (pSurface)
709 {
710 return ((HANDLE) NtGdiDdGetDxHandle(NULL, (HANDLE)pSurface->hDDSurface, bRelease));
711 }
712
713
714 if (!pDDraw->lpGbl->hDD)
715 {
716 if (!pDirectDrawGlobalInternal->hDD)
717 {
718 return FALSE;
719 }
720 return ((HANDLE) NtGdiDdGetDxHandle( (HANDLE) pDirectDrawGlobalInternal->hDD, (HANDLE) pSurface->hDDSurface, bRelease));
721 }
722
723 return ((HANDLE) NtGdiDdGetDxHandle((HANDLE)pDDraw->lpGbl->hDD, (HANDLE) pSurface->hDDSurface, bRelease));
724 }
725
726 /*
727 * @implemented
728 *
729 * GDIEntry 15
730 */
731 BOOL STDCALL DdSetGammaRamp(
732 LPDDRAWI_DIRECTDRAW_LCL pDDraw,
733 HDC hdc,
734 LPVOID lpGammaRamp
735 )
736 {
737 if (!pDDraw->lpGbl->hDD)
738 {
739 if (!pDirectDrawGlobalInternal->hDD)
740 {
741 return FALSE;
742 }
743 return NtGdiDdSetGammaRamp((HANDLE)pDirectDrawGlobalInternal->hDD,hdc,lpGammaRamp);
744 }
745
746 return NtGdiDdSetGammaRamp((HANDLE)pDDraw->lpGbl->hDD,hdc,lpGammaRamp);
747 }
748
749 /*
750 * @implemented
751 *
752 * GDIEntry 16
753 */
754 DWORD STDCALL DdSwapTextureHandles(
755 LPDDRAWI_DIRECTDRAW_LCL pDDraw,
756 LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl1,
757 LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl2
758 )
759 {
760 return TRUE;
761 }
762
763
764 /* interal create surface */
765 BOOL
766 intDDCreateSurface ( LPDDRAWI_DDRAWSURFACE_LCL pSurface,
767 BOOL bComplete)
768 {
769 DD_SURFACE_LOCAL SurfaceLocal;
770 DD_SURFACE_GLOBAL SurfaceGlobal;
771 DD_SURFACE_MORE SurfaceMore;
772
773 /* Zero struct */
774 RtlZeroMemory(&SurfaceLocal, sizeof(DD_SURFACE_LOCAL));
775 RtlZeroMemory(&SurfaceGlobal, sizeof(DD_SURFACE_GLOBAL));
776 RtlZeroMemory(&SurfaceMore, sizeof(DD_SURFACE_MORE));
777
778 /* Set up SurfaceLocal struct */
779 SurfaceLocal.ddsCaps.dwCaps = pSurface->ddsCaps.dwCaps;
780 SurfaceLocal.dwFlags = pSurface->dwFlags;
781
782 /* Set up SurfaceMore struct */
783 /* copy pSurface->ddckCKDestBlt and pSurface->ddckCKSrcBlt to SurfaceMore.ddsCapsEx */
784 memcpy(&SurfaceMore.ddsCapsEx, &pSurface->ddckCKDestBlt, sizeof(DDSCAPSEX));
785 SurfaceMore.dwSurfaceHandle = (DWORD) pSurface->dbnOverlayNode.object_int->lpVtbl;
786
787
788 /* Set up SurfaceGlobal struct */
789 SurfaceGlobal.fpVidMem = pSurface->lpGbl->fpVidMem;
790 SurfaceGlobal.dwLinearSize = pSurface->lpGbl->dwLinearSize;
791 SurfaceGlobal.wHeight = pSurface->lpGbl->wHeight;
792 SurfaceGlobal.wWidth = pSurface->lpGbl->wWidth;
793
794 /* check which memory type should be use */
795 if ((pSurface->dwFlags & DDRAWISURFGBL_LOCKVRAMSTYLE) == DDRAWISURFGBL_LOCKVRAMSTYLE)
796 {
797 memcpy(&SurfaceGlobal.ddpfSurface,&pSurface->lpGbl->lpDD->vmiData.ddpfDisplay, sizeof(DDPIXELFORMAT));
798 }
799 else
800 {
801 memcpy(&SurfaceGlobal.ddpfSurface,&pSurface->lpGbl->ddpfSurface, sizeof(DDPIXELFORMAT));
802 }
803
804 /* Determer if Gdi32 chace of directdraw handler or not */
805 if (pSurface->lpGbl->lpDD->hDD)
806 {
807 pSurface->hDDSurface = ((DWORD) NtGdiDdCreateSurfaceObject( (HANDLE) pSurface->lpGbl->lpDD->hDD,
808 (HANDLE) pSurface->hDDSurface, &SurfaceLocal,
809 &SurfaceMore, &SurfaceGlobal, bComplete));
810 }
811 else
812 {
813 pSurface->hDDSurface = ((DWORD) NtGdiDdCreateSurfaceObject( (HANDLE) pDirectDrawGlobalInternal->hDD,
814 (HANDLE) pSurface->hDDSurface, &SurfaceLocal,
815 &SurfaceMore,
816 &SurfaceGlobal,
817 bComplete));
818 }
819
820 /* return status */
821 if (pSurface->hDDSurface)
822 {
823 return TRUE;
824 }
825
826 return FALSE;
827 }