start implement of gdientry2, for moment it return incorrect info. and does not fill...
[reactos.git] / reactos / dll / win32 / gdi32 / misc / gdientry.c
1 /*
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17 /*
18 * $Id:
19 * COPYRIGHT: See COPYING in the top level directory
20 * PROJECT: ReactOS GDI32
21 * PURPOSE: Gdi DirectX inteface
22 * FILE: lib/gdi32/misc/gdientry.c
23 * PROGRAMER: Magnus Olsen (magnus@greatlord.com)
24 * REVISION HISTORY:
25 * NOTES:
26 */
27
28
29 #include "precomp.h"
30 #include <ddraw.h>
31 #include <ddrawi.h>
32 #include <ddrawint.h>
33 #include <ddrawgdi.h>
34 static LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobalInternal;
35 static ULONG RemberDdQueryDisplaySettingsUniquenessID = 0;
36
37 BOOL
38 intDDCreateSurface ( LPDDRAWI_DDRAWSURFACE_LCL pSurface,
39 BOOL bComplete);
40
41 /*
42 * @implemented
43 *
44 * GDIEntry 1
45 */
46 BOOL
47 STDCALL
48 DdCreateDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
49 HDC hdc)
50 {
51 HDC newHdc;
52 /* check see if HDC is NULL or not
53 if it null we need create the DC */
54
55 if (hdc != NULL)
56 {
57 pDirectDrawGlobal->hDD = (ULONG_PTR)NtGdiDdCreateDirectDrawObject(hdc);
58
59 /* if hDD ==NULL */
60 if (!pDirectDrawGlobal->hDD)
61 {
62 return FALSE;
63 }
64 return TRUE;
65 }
66
67 /* The hdc was not null we need check see if we alread
68 have create a directdraw handler */
69
70 /* if hDD !=NULL */
71 if (pDirectDrawGlobalInternal->hDD)
72 {
73 /* we have create a directdraw handler already */
74
75 pDirectDrawGlobal->hDD = pDirectDrawGlobalInternal->hDD;
76 return TRUE;
77 }
78
79 /* Now we create the DC */
80 newHdc = CreateDC(L"DISPLAY\0", NULL, NULL, NULL);
81
82 /* we are checking if we got a hdc or not */
83 if ((ULONG_PTR)newHdc != pDirectDrawGlobalInternal->hDD)
84 {
85 pDirectDrawGlobalInternal->hDD = (ULONG_PTR) NtGdiDdCreateDirectDrawObject(newHdc);
86 NtGdiDeleteObjectApp(newHdc);
87 }
88
89 /* pDirectDrawGlobal->hDD = pDirectDrawGlobalInternal->hDD; ? */
90 pDirectDrawGlobal->hDD = 0; /* ? */
91
92 /* test see if we got a handler */
93 if (!pDirectDrawGlobalInternal->hDD)
94 {
95 return FALSE;
96 }
97
98 return TRUE;
99 }
100
101 /*
102 * @unimplemented
103 */
104 BOOL
105 STDCALL
106 DdQueryDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
107 LPDDHALINFO pHalInfo,
108 LPDDHAL_DDCALLBACKS pDDCallbacks,
109 LPDDHAL_DDSURFACECALLBACKS pDDSurfaceCallbacks,
110 LPDDHAL_DDPALETTECALLBACKS pDDPaletteCallbacks,
111 LPD3DHAL_CALLBACKS pD3dCallbacks,
112 LPD3DHAL_GLOBALDRIVERDATA pD3dDriverData,
113 LPDDHAL_DDEXEBUFCALLBACKS pD3dBufferCallbacks,
114 LPDDSURFACEDESC pD3dTextureFormats,
115 LPDWORD pdwFourCC,
116 LPVIDMEM pvmList)
117 {
118 BOOL bStatus = FALSE;
119 DD_HALINFO DDHalInfo;
120 LPVOID pCallBackFlags[3];
121 DWORD NumHeaps;
122 DWORD NumFourCC;
123
124 DDHalInfo.dwSize = sizeof(DD_HALINFO);
125
126 pCallBackFlags[0] = pDDCallbacks;
127 pCallBackFlags[1] = pDDSurfaceCallbacks;
128 pCallBackFlags[2] = pDDPaletteCallbacks;
129
130 bStatus = NtGdiDdQueryDirectDrawObject(
131 (HANDLE)pDirectDrawGlobal->hDD,
132 (DD_HALINFO *)&DDHalInfo,
133 (DWORD *)pCallBackFlags,
134 (LPD3DNTHAL_CALLBACKS)pD3dCallbacks,
135 (LPD3DNTHAL_GLOBALDRIVERDATA)pD3dDriverData,
136 (PDD_D3DBUFCALLBACKS)pD3dBufferCallbacks,
137 (LPDDSURFACEDESC)pD3dTextureFormats,
138 (DWORD *)&NumHeaps,
139 (VIDEOMEMORY *)pvmList,
140 (DWORD *)&NumFourCC,
141 (DWORD *)pdwFourCC);
142
143
144 //SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
145 return bStatus;
146 }
147
148 /*
149 * @unimplemented
150 */
151 HBITMAP
152 STDCALL
153 DdCreateDIBSection(HDC hdc,
154 CONST BITMAPINFO *pbmi,
155 UINT iUsage,
156 VOID **ppvBits,
157 HANDLE hSectionApp,
158 DWORD dwOffset)
159 {
160 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
161 return 0;
162 }
163
164 /*
165 * @implemented
166 *
167 * GDIEntry 3
168 */
169 BOOL
170 STDCALL
171 DdDeleteDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal)
172 {
173 BOOL status;
174 /* if pDirectDrawGlobal->hDD == NULL and pDirectDrawGlobalInternal->hDD == NULL
175 return false */
176
177 if (!pDirectDrawGlobal->hDD)
178 {
179 if (!pDirectDrawGlobalInternal->hDD)
180 {
181 return FALSE;
182 }
183 return NtGdiDdDeleteDirectDrawObject((HANDLE)pDirectDrawGlobalInternal->hDD);
184 }
185
186 status = NtGdiDdDeleteDirectDrawObject((HANDLE)pDirectDrawGlobal->hDD);
187 if ((status == TRUE) && (pDirectDrawGlobalInternal->hDD != 0))
188 {
189 pDirectDrawGlobalInternal->hDD = 0;
190 }
191
192 return status;
193 }
194
195 /*
196 * @implemented
197 *
198 * GDIEntry 4
199 */
200 BOOL
201 STDCALL
202 DdCreateSurfaceObject( LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
203 BOOL bPrimarySurface)
204 {
205 return intDDCreateSurface(pSurfaceLocal,1);
206 }
207
208 /*
209 * @implemented
210 *
211 * GDIEntry 5
212 */
213 BOOL
214 STDCALL
215 DdDeleteSurfaceObject(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal)
216 {
217 if (!pSurfaceLocal->hDDSurface)
218 {
219 return FALSE;
220 }
221
222 return NtGdiDdDeleteSurfaceObject((HANDLE)pSurfaceLocal->hDDSurface);
223 }
224
225 /*
226 * @implemented
227 *
228 * GDIEntry 6
229 */
230 BOOL
231 STDCALL
232 DdResetVisrgn(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
233 HWND hWnd)
234 {
235 return NtGdiDdResetVisrgn((HANDLE) pSurfaceLocal->hDDSurface, hWnd);
236 }
237
238 /*
239 * @implemented
240 *
241 * GDIEntry 7
242 */
243 HDC STDCALL DdGetDC(
244 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
245 LPPALETTEENTRY pColorTable
246 )
247 {
248 return NtGdiDdGetDC(pColorTable, (HANDLE) pSurfaceLocal->hDDSurface);
249 }
250
251 /*
252 * @implemented
253 *
254 * GDIEntry 8
255 */
256 BOOL STDCALL DdReleaseDC(
257 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal
258 )
259 {
260 return NtGdiDdReleaseDC((HANDLE) pSurfaceLocal->hDDSurface);
261 }
262
263
264
265 /*
266 * @implemented
267 *
268 * GDIEntry 10
269 */
270 BOOL
271 STDCALL
272 DdReenableDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
273 BOOL *pbNewMode)
274 {
275 if (!pDirectDrawGlobal->hDD)
276 {
277 if (!pDirectDrawGlobalInternal->hDD)
278 {
279 return FALSE;
280 }
281 return NtGdiDdReenableDirectDrawObject((HANDLE)pDirectDrawGlobalInternal->hDD, pbNewMode);
282 }
283
284 return NtGdiDdReenableDirectDrawObject((HANDLE)pDirectDrawGlobal->hDD, pbNewMode);
285 }
286
287 /*
288 * @implemented
289 *
290 * GDIEntry 11
291 */
292 BOOL
293 STDCALL
294 DdAttachSurface( LPDDRAWI_DDRAWSURFACE_LCL pSurfaceFrom,
295 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceTo)
296 {
297
298 /* Create Surface if it does not exits one */
299 if (pSurfaceFrom->hDDSurface)
300 {
301 if (!intDDCreateSurface(pSurfaceFrom,FALSE))
302 {
303 return FALSE;
304 }
305 }
306
307 /* Create Surface if it does not exits one */
308 if (pSurfaceTo->hDDSurface)
309 {
310 if (!intDDCreateSurface(pSurfaceTo,FALSE))
311 {
312 return FALSE;
313 }
314 }
315
316 return NtGdiDdAttachSurface( (HANDLE) pSurfaceFrom->hDDSurface, (HANDLE) pSurfaceTo->hDDSurface);
317 }
318
319 /*
320 * @implemented
321 *
322 * GDIEntry 12
323 */
324 VOID
325 STDCALL
326 DdUnattachSurface(LPDDRAWI_DDRAWSURFACE_LCL pSurface,
327 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceAttached)
328 {
329 NtGdiDdUnattachSurface((HANDLE) pSurface->hDDSurface, (HANDLE) pSurfaceAttached->hDDSurface);
330 }
331
332 /*
333 * @implemented
334 *
335 * GDIEntry 13
336 */
337 ULONG
338 STDCALL
339 DdQueryDisplaySettingsUniqueness()
340 {
341 return RemberDdQueryDisplaySettingsUniquenessID;
342 }
343
344 /*
345 * @implemented
346 *
347 * GDIEntry 14
348 */
349 HANDLE
350 STDCALL
351 DdGetDxHandle(LPDDRAWI_DIRECTDRAW_LCL pDDraw,
352 LPDDRAWI_DDRAWSURFACE_LCL pSurface,
353 BOOL bRelease)
354 {
355 if (pSurface)
356 {
357 return ((HANDLE) NtGdiDdGetDxHandle(NULL, (HANDLE)pSurface->hDDSurface, bRelease));
358 }
359
360
361 if (!pDDraw->lpGbl->hDD)
362 {
363 if (!pDirectDrawGlobalInternal->hDD)
364 {
365 return FALSE;
366 }
367 return ((HANDLE) NtGdiDdGetDxHandle( (HANDLE) pDirectDrawGlobalInternal->hDD, (HANDLE) pSurface->hDDSurface, bRelease));
368 }
369
370 return ((HANDLE) NtGdiDdGetDxHandle((HANDLE)pDDraw->lpGbl->hDD, (HANDLE) pSurface->hDDSurface, bRelease));
371 }
372
373 /*
374 * @implemented
375 *
376 * GDIEntry 15
377 */
378 BOOL STDCALL DdSetGammaRamp(
379 LPDDRAWI_DIRECTDRAW_LCL pDDraw,
380 HDC hdc,
381 LPVOID lpGammaRamp
382 )
383 {
384 if (!pDDraw->lpGbl->hDD)
385 {
386 if (!pDirectDrawGlobalInternal->hDD)
387 {
388 return FALSE;
389 }
390 return NtGdiDdSetGammaRamp((HANDLE)pDirectDrawGlobalInternal->hDD,hdc,lpGammaRamp);
391 }
392
393 return NtGdiDdSetGammaRamp((HANDLE)pDDraw->lpGbl->hDD,hdc,lpGammaRamp);
394 }
395
396 /*
397 * @implemented
398 *
399 * GDIEntry 16
400 */
401 DWORD STDCALL DdSwapTextureHandles(
402 LPDDRAWI_DIRECTDRAW_LCL pDDraw,
403 LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl1,
404 LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl2
405 )
406 {
407 return TRUE;
408 }
409
410
411 /* interal create surface */
412 BOOL
413 intDDCreateSurface ( LPDDRAWI_DDRAWSURFACE_LCL pSurface,
414 BOOL bComplete)
415 {
416 DD_SURFACE_LOCAL SurfaceLocal;
417 DD_SURFACE_GLOBAL SurfaceGlobal;
418 DD_SURFACE_MORE SurfaceMore;
419
420 /* Zero struct */
421 RtlZeroMemory(&SurfaceLocal, sizeof(DD_SURFACE_LOCAL));
422 RtlZeroMemory(&SurfaceGlobal, sizeof(DD_SURFACE_GLOBAL));
423 RtlZeroMemory(&SurfaceMore, sizeof(DD_SURFACE_MORE));
424
425 /* Set up SurfaceLocal struct */
426 SurfaceLocal.ddsCaps.dwCaps = pSurface->ddsCaps.dwCaps;
427 SurfaceLocal.dwFlags = pSurface->dwFlags;
428
429 /* Set up SurfaceMore struct */
430 /* copy pSurface->ddckCKDestBlt and pSurface->ddckCKSrcBlt to SurfaceMore.ddsCapsEx */
431 memcpy(&SurfaceMore.ddsCapsEx, &pSurface->ddckCKDestBlt, sizeof(DDSCAPSEX));
432 SurfaceMore.dwSurfaceHandle = (DWORD) pSurface->dbnOverlayNode.object_int->lpVtbl;
433
434
435 /* Set up SurfaceGlobal struct */
436 SurfaceGlobal.fpVidMem = pSurface->lpGbl->fpVidMem;
437 SurfaceGlobal.dwLinearSize = pSurface->lpGbl->dwLinearSize;
438 SurfaceGlobal.wHeight = pSurface->lpGbl->wHeight;
439 SurfaceGlobal.wWidth = pSurface->lpGbl->wWidth;
440
441 /* check which memory type should be use */
442 if ((pSurface->dwFlags & DDRAWISURFGBL_LOCKVRAMSTYLE) == DDRAWISURFGBL_LOCKVRAMSTYLE)
443 {
444 memcpy(&SurfaceGlobal.ddpfSurface,&pSurface->lpGbl->lpDD->vmiData.ddpfDisplay, sizeof(DDPIXELFORMAT));
445 }
446 else
447 {
448 memcpy(&SurfaceGlobal.ddpfSurface,&pSurface->lpGbl->ddpfSurface, sizeof(DDPIXELFORMAT));
449 }
450
451 /* Determer if Gdi32 chace of directdraw handler or not */
452 if (pSurface->lpGbl->lpDD->hDD)
453 {
454 pSurface->hDDSurface = ((DWORD) NtGdiDdCreateSurfaceObject( (HANDLE) pSurface->lpGbl->lpDD->hDD,
455 (HANDLE) pSurface->hDDSurface, &SurfaceLocal,
456 &SurfaceMore, &SurfaceGlobal, bComplete));
457 }
458 else
459 {
460 pSurface->hDDSurface = ((DWORD) NtGdiDdCreateSurfaceObject( (HANDLE) pDirectDrawGlobalInternal->hDD,
461 (HANDLE) pSurface->hDDSurface, &SurfaceLocal,
462 &SurfaceMore,
463 &SurfaceGlobal,
464 bComplete));
465 }
466
467 /* return status */
468 if (pSurface->hDDSurface)
469 {
470 return TRUE;
471 }
472
473 return FALSE;
474 }