Start implement code that alex for one year ago, thanks alex for all help and for...
[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
18 /* DATA **********************************************************************/
19
20 HANDLE ghDirectDraw;
21 ULONG gcDirectDraw;
22
23 #define GetDdHandle(Handle) (Handle ? Handle : ghDirectDraw)
24
25
26 /* CALLBACKS *****************************************************************/
27
28 /*
29 * Dd Surface Callbacks
30 */
31 DWORD
32 WINAPI
33 DdAddAttachedSurface(LPDDHAL_ADDATTACHEDSURFACEDATA Attach)
34 {
35 /* Call win32k */
36 return NtGdiDdAddAttachedSurface((HANDLE)Attach->lpDDSurface->hDDSurface,
37 (HANDLE)Attach->lpSurfAttached->hDDSurface,
38 (PDD_ADDATTACHEDSURFACEDATA)Attach);
39 }
40
41 DWORD
42 WINAPI
43 DdBlt(LPDDHAL_BLTDATA Blt)
44 {
45 HANDLE Surface = 0;
46
47 /* Use the right surface */
48 if (Blt->lpDDSrcSurface) Surface = (HANDLE)Blt->lpDDSrcSurface->hDDSurface;
49
50 /* Call win32k */
51 return NtGdiDdBlt((HANDLE)Blt->lpDDDestSurface->hDDSurface, Surface, (PDD_BLTDATA)Blt);
52 }
53
54 DWORD
55 APIENTRY
56 DdDestroySurface(LPDDHAL_DESTROYSURFACEDATA pDestroySurface)
57 {
58 DWORD Return = DDHAL_DRIVER_NOTHANDLED;
59 BOOL RealDestroy = TRUE;
60 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal;
61
62 /* Get the local surface */
63 pSurfaceLocal = pDestroySurface->lpDDSurface;
64
65 /* Make sure there's a surface */
66 if (pSurfaceLocal->hDDSurface)
67 {
68 /* Check if we shoudl really destroy it */
69 if ((pSurfaceLocal->dwFlags & DDRAWISURF_DRIVERMANAGED) &&
70 (pSurfaceLocal->dwFlags & DDRAWISURF_INVALID))
71 {
72 RealDestroy = FALSE;
73 }
74
75 /* Call win32k */
76 Return = NtGdiDdDestroySurface((HANDLE)pSurfaceLocal->hDDSurface,
77 RealDestroy);
78 }
79
80 return Return;
81 }
82
83 DWORD
84 WINAPI
85 DdFlip(LPDDHAL_FLIPDATA Flip)
86 {
87 /* Call win32k */
88
89 return NtGdiDdFlip( (HANDLE)Flip->lpSurfCurr->hDDSurface,
90 (HANDLE)Flip->lpSurfTarg->hDDSurface,
91 /* FIXME the two last should be current left handler */
92 (HANDLE)Flip->lpSurfCurr->hDDSurface,
93 (HANDLE)Flip->lpSurfTarg->hDDSurface,
94 (PDD_FLIPDATA)Flip);
95 }
96
97 WORD
98 WINAPI
99 DdLock(LPDDHAL_LOCKDATA Lock)
100 {
101 /* Call win32k */
102 return NtGdiDdLock((HANDLE)Lock->lpDDSurface->hDDSurface,
103 (PDD_LOCKDATA)Lock,
104 (HANDLE)Lock->lpDDSurface->hDC);
105 }
106
107
108
109
110 static LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobalInternal;
111 static ULONG RemberDdQueryDisplaySettingsUniquenessID = 0;
112
113 BOOL
114 intDDCreateSurface ( LPDDRAWI_DDRAWSURFACE_LCL pSurface,
115 BOOL bComplete);
116
117 /*
118 * @implemented
119 *
120 * GDIEntry 1
121 */
122 BOOL
123 STDCALL
124 DdCreateDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
125 HDC hdc)
126 {
127 HDC newHdc;
128 /* check see if HDC is NULL or not
129 if it null we need create the DC */
130
131 if (hdc != NULL)
132 {
133 pDirectDrawGlobal->hDD = (ULONG_PTR)NtGdiDdCreateDirectDrawObject(hdc);
134
135 /* if hDD ==NULL */
136 if (!pDirectDrawGlobal->hDD)
137 {
138 return FALSE;
139 }
140 return TRUE;
141 }
142
143 /* The hdc was not null we need check see if we alread
144 have create a directdraw handler */
145
146 /* if hDD !=NULL */
147 if (pDirectDrawGlobalInternal->hDD)
148 {
149 /* we have create a directdraw handler already */
150
151 pDirectDrawGlobal->hDD = pDirectDrawGlobalInternal->hDD;
152 return TRUE;
153 }
154
155 /* Now we create the DC */
156 newHdc = CreateDC(L"DISPLAY\0", NULL, NULL, NULL);
157
158 /* we are checking if we got a hdc or not */
159 if ((ULONG_PTR)newHdc != pDirectDrawGlobalInternal->hDD)
160 {
161 pDirectDrawGlobalInternal->hDD = (ULONG_PTR) NtGdiDdCreateDirectDrawObject(newHdc);
162 NtGdiDeleteObjectApp(newHdc);
163 }
164
165 /* pDirectDrawGlobal->hDD = pDirectDrawGlobalInternal->hDD; ? */
166 pDirectDrawGlobal->hDD = 0; /* ? */
167
168 /* test see if we got a handler */
169 if (!pDirectDrawGlobalInternal->hDD)
170 {
171 return FALSE;
172 }
173
174 return TRUE;
175 }
176
177 /*
178 * @unimplemented
179 */
180 BOOL
181 STDCALL
182 DdQueryDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
183 LPDDHALINFO pHalInfo,
184 LPDDHAL_DDCALLBACKS pDDCallbacks,
185 LPDDHAL_DDSURFACECALLBACKS pDDSurfaceCallbacks,
186 LPDDHAL_DDPALETTECALLBACKS pDDPaletteCallbacks,
187 LPD3DHAL_CALLBACKS pD3dCallbacks,
188 LPD3DHAL_GLOBALDRIVERDATA pD3dDriverData,
189 LPDDHAL_DDEXEBUFCALLBACKS pD3dBufferCallbacks,
190 LPDDSURFACEDESC pD3dTextureFormats,
191 LPDWORD pdwFourCC,
192 LPVIDMEM pvmList)
193 {
194 BOOL bStatus = FALSE;
195 DD_HALINFO DDHalInfo;
196 LPVOID pCallBackFlags[3];
197 DWORD NumHeaps;
198 DWORD NumFourCC;
199
200 DDHalInfo.dwSize = sizeof(DD_HALINFO);
201
202 pCallBackFlags[0] = pDDCallbacks;
203 pCallBackFlags[1] = pDDSurfaceCallbacks;
204 pCallBackFlags[2] = pDDPaletteCallbacks;
205
206 bStatus = NtGdiDdQueryDirectDrawObject(
207 (HANDLE)pDirectDrawGlobal->hDD,
208 (DD_HALINFO *)&DDHalInfo,
209 (DWORD *)pCallBackFlags,
210 (LPD3DNTHAL_CALLBACKS)pD3dCallbacks,
211 (LPD3DNTHAL_GLOBALDRIVERDATA)pD3dDriverData,
212 (PDD_D3DBUFCALLBACKS)pD3dBufferCallbacks,
213 (LPDDSURFACEDESC)pD3dTextureFormats,
214 (DWORD *)&NumHeaps,
215 (VIDEOMEMORY *)pvmList,
216 (DWORD *)&NumFourCC,
217 (DWORD *)pdwFourCC);
218
219
220 //SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
221 return bStatus;
222 }
223
224 /*
225 * @unimplemented
226 */
227 HBITMAP
228 STDCALL
229 DdCreateDIBSection(HDC hdc,
230 CONST BITMAPINFO *pbmi,
231 UINT iUsage,
232 VOID **ppvBits,
233 HANDLE hSectionApp,
234 DWORD dwOffset)
235 {
236 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
237 return 0;
238 }
239
240 /*
241 * @implemented
242 *
243 * GDIEntry 3
244 */
245 BOOL
246 STDCALL
247 DdDeleteDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal)
248 {
249 BOOL status;
250 /* if pDirectDrawGlobal->hDD == NULL and pDirectDrawGlobalInternal->hDD == NULL
251 return false */
252
253 if (!pDirectDrawGlobal->hDD)
254 {
255 if (!pDirectDrawGlobalInternal->hDD)
256 {
257 return FALSE;
258 }
259 return NtGdiDdDeleteDirectDrawObject((HANDLE)pDirectDrawGlobalInternal->hDD);
260 }
261
262 status = NtGdiDdDeleteDirectDrawObject((HANDLE)pDirectDrawGlobal->hDD);
263 if ((status == TRUE) && (pDirectDrawGlobalInternal->hDD != 0))
264 {
265 pDirectDrawGlobalInternal->hDD = 0;
266 }
267
268 return status;
269 }
270
271 /*
272 * @implemented
273 *
274 * GDIEntry 4
275 */
276 BOOL
277 STDCALL
278 DdCreateSurfaceObject( LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
279 BOOL bPrimarySurface)
280 {
281 return intDDCreateSurface(pSurfaceLocal,1);
282 }
283
284 /*
285 * @implemented
286 *
287 * GDIEntry 5
288 */
289 BOOL
290 STDCALL
291 DdDeleteSurfaceObject(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal)
292 {
293 if (!pSurfaceLocal->hDDSurface)
294 {
295 return FALSE;
296 }
297
298 return NtGdiDdDeleteSurfaceObject((HANDLE)pSurfaceLocal->hDDSurface);
299 }
300
301 /*
302 * @implemented
303 *
304 * GDIEntry 6
305 */
306 BOOL
307 STDCALL
308 DdResetVisrgn(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
309 HWND hWnd)
310 {
311 return NtGdiDdResetVisrgn((HANDLE) pSurfaceLocal->hDDSurface, hWnd);
312 }
313
314 /*
315 * @implemented
316 *
317 * GDIEntry 7
318 */
319 HDC STDCALL DdGetDC(
320 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
321 LPPALETTEENTRY pColorTable
322 )
323 {
324 return NtGdiDdGetDC(pColorTable, (HANDLE) pSurfaceLocal->hDDSurface);
325 }
326
327 /*
328 * @implemented
329 *
330 * GDIEntry 8
331 */
332 BOOL STDCALL DdReleaseDC(
333 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal
334 )
335 {
336 return NtGdiDdReleaseDC((HANDLE) pSurfaceLocal->hDDSurface);
337 }
338
339
340
341 /*
342 * @implemented
343 *
344 * GDIEntry 10
345 */
346 BOOL
347 STDCALL
348 DdReenableDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
349 BOOL *pbNewMode)
350 {
351 if (!pDirectDrawGlobal->hDD)
352 {
353 if (!pDirectDrawGlobalInternal->hDD)
354 {
355 return FALSE;
356 }
357 return NtGdiDdReenableDirectDrawObject((HANDLE)pDirectDrawGlobalInternal->hDD, pbNewMode);
358 }
359
360 return NtGdiDdReenableDirectDrawObject((HANDLE)pDirectDrawGlobal->hDD, pbNewMode);
361 }
362
363 /*
364 * @implemented
365 *
366 * GDIEntry 11
367 */
368 BOOL
369 STDCALL
370 DdAttachSurface( LPDDRAWI_DDRAWSURFACE_LCL pSurfaceFrom,
371 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceTo)
372 {
373
374 /* Create Surface if it does not exits one */
375 if (pSurfaceFrom->hDDSurface)
376 {
377 if (!intDDCreateSurface(pSurfaceFrom,FALSE))
378 {
379 return FALSE;
380 }
381 }
382
383 /* Create Surface if it does not exits one */
384 if (pSurfaceTo->hDDSurface)
385 {
386 if (!intDDCreateSurface(pSurfaceTo,FALSE))
387 {
388 return FALSE;
389 }
390 }
391
392 return NtGdiDdAttachSurface( (HANDLE) pSurfaceFrom->hDDSurface, (HANDLE) pSurfaceTo->hDDSurface);
393 }
394
395 /*
396 * @implemented
397 *
398 * GDIEntry 12
399 */
400 VOID
401 STDCALL
402 DdUnattachSurface(LPDDRAWI_DDRAWSURFACE_LCL pSurface,
403 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceAttached)
404 {
405 NtGdiDdUnattachSurface((HANDLE) pSurface->hDDSurface, (HANDLE) pSurfaceAttached->hDDSurface);
406 }
407
408 /*
409 * @implemented
410 *
411 * GDIEntry 13
412 */
413 ULONG
414 STDCALL
415 DdQueryDisplaySettingsUniqueness()
416 {
417 return RemberDdQueryDisplaySettingsUniquenessID;
418 }
419
420 /*
421 * @implemented
422 *
423 * GDIEntry 14
424 */
425 HANDLE
426 STDCALL
427 DdGetDxHandle(LPDDRAWI_DIRECTDRAW_LCL pDDraw,
428 LPDDRAWI_DDRAWSURFACE_LCL pSurface,
429 BOOL bRelease)
430 {
431 if (pSurface)
432 {
433 return ((HANDLE) NtGdiDdGetDxHandle(NULL, (HANDLE)pSurface->hDDSurface, bRelease));
434 }
435
436
437 if (!pDDraw->lpGbl->hDD)
438 {
439 if (!pDirectDrawGlobalInternal->hDD)
440 {
441 return FALSE;
442 }
443 return ((HANDLE) NtGdiDdGetDxHandle( (HANDLE) pDirectDrawGlobalInternal->hDD, (HANDLE) pSurface->hDDSurface, bRelease));
444 }
445
446 return ((HANDLE) NtGdiDdGetDxHandle((HANDLE)pDDraw->lpGbl->hDD, (HANDLE) pSurface->hDDSurface, bRelease));
447 }
448
449 /*
450 * @implemented
451 *
452 * GDIEntry 15
453 */
454 BOOL STDCALL DdSetGammaRamp(
455 LPDDRAWI_DIRECTDRAW_LCL pDDraw,
456 HDC hdc,
457 LPVOID lpGammaRamp
458 )
459 {
460 if (!pDDraw->lpGbl->hDD)
461 {
462 if (!pDirectDrawGlobalInternal->hDD)
463 {
464 return FALSE;
465 }
466 return NtGdiDdSetGammaRamp((HANDLE)pDirectDrawGlobalInternal->hDD,hdc,lpGammaRamp);
467 }
468
469 return NtGdiDdSetGammaRamp((HANDLE)pDDraw->lpGbl->hDD,hdc,lpGammaRamp);
470 }
471
472 /*
473 * @implemented
474 *
475 * GDIEntry 16
476 */
477 DWORD STDCALL DdSwapTextureHandles(
478 LPDDRAWI_DIRECTDRAW_LCL pDDraw,
479 LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl1,
480 LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl2
481 )
482 {
483 return TRUE;
484 }
485
486
487 /* interal create surface */
488 BOOL
489 intDDCreateSurface ( LPDDRAWI_DDRAWSURFACE_LCL pSurface,
490 BOOL bComplete)
491 {
492 DD_SURFACE_LOCAL SurfaceLocal;
493 DD_SURFACE_GLOBAL SurfaceGlobal;
494 DD_SURFACE_MORE SurfaceMore;
495
496 /* Zero struct */
497 RtlZeroMemory(&SurfaceLocal, sizeof(DD_SURFACE_LOCAL));
498 RtlZeroMemory(&SurfaceGlobal, sizeof(DD_SURFACE_GLOBAL));
499 RtlZeroMemory(&SurfaceMore, sizeof(DD_SURFACE_MORE));
500
501 /* Set up SurfaceLocal struct */
502 SurfaceLocal.ddsCaps.dwCaps = pSurface->ddsCaps.dwCaps;
503 SurfaceLocal.dwFlags = pSurface->dwFlags;
504
505 /* Set up SurfaceMore struct */
506 /* copy pSurface->ddckCKDestBlt and pSurface->ddckCKSrcBlt to SurfaceMore.ddsCapsEx */
507 memcpy(&SurfaceMore.ddsCapsEx, &pSurface->ddckCKDestBlt, sizeof(DDSCAPSEX));
508 SurfaceMore.dwSurfaceHandle = (DWORD) pSurface->dbnOverlayNode.object_int->lpVtbl;
509
510
511 /* Set up SurfaceGlobal struct */
512 SurfaceGlobal.fpVidMem = pSurface->lpGbl->fpVidMem;
513 SurfaceGlobal.dwLinearSize = pSurface->lpGbl->dwLinearSize;
514 SurfaceGlobal.wHeight = pSurface->lpGbl->wHeight;
515 SurfaceGlobal.wWidth = pSurface->lpGbl->wWidth;
516
517 /* check which memory type should be use */
518 if ((pSurface->dwFlags & DDRAWISURFGBL_LOCKVRAMSTYLE) == DDRAWISURFGBL_LOCKVRAMSTYLE)
519 {
520 memcpy(&SurfaceGlobal.ddpfSurface,&pSurface->lpGbl->lpDD->vmiData.ddpfDisplay, sizeof(DDPIXELFORMAT));
521 }
522 else
523 {
524 memcpy(&SurfaceGlobal.ddpfSurface,&pSurface->lpGbl->ddpfSurface, sizeof(DDPIXELFORMAT));
525 }
526
527 /* Determer if Gdi32 chace of directdraw handler or not */
528 if (pSurface->lpGbl->lpDD->hDD)
529 {
530 pSurface->hDDSurface = ((DWORD) NtGdiDdCreateSurfaceObject( (HANDLE) pSurface->lpGbl->lpDD->hDD,
531 (HANDLE) pSurface->hDDSurface, &SurfaceLocal,
532 &SurfaceMore, &SurfaceGlobal, bComplete));
533 }
534 else
535 {
536 pSurface->hDDSurface = ((DWORD) NtGdiDdCreateSurfaceObject( (HANDLE) pDirectDrawGlobalInternal->hDD,
537 (HANDLE) pSurface->hDDSurface, &SurfaceLocal,
538 &SurfaceMore,
539 &SurfaceGlobal,
540 bComplete));
541 }
542
543 /* return status */
544 if (pSurface->hDDSurface)
545 {
546 return TRUE;
547 }
548
549 return FALSE;
550 }