947a4c9fae23a98db41fa2c85a3bebff68d69052
[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 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
119 return 0;
120 }
121
122 /*
123 * @unimplemented
124 */
125 HBITMAP
126 STDCALL
127 DdCreateDIBSection(HDC hdc,
128 CONST BITMAPINFO *pbmi,
129 UINT iUsage,
130 VOID **ppvBits,
131 HANDLE hSectionApp,
132 DWORD dwOffset)
133 {
134 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
135 return 0;
136 }
137
138 /*
139 * @implemented
140 *
141 * GDIEntry 3
142 */
143 BOOL
144 STDCALL
145 DdDeleteDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal)
146 {
147 BOOL status;
148 /* if pDirectDrawGlobal->hDD == NULL and pDirectDrawGlobalInternal->hDD == NULL
149 return false */
150
151 if (!pDirectDrawGlobal->hDD)
152 {
153 if (!pDirectDrawGlobalInternal->hDD)
154 {
155 return FALSE;
156 }
157 return NtGdiDdDeleteDirectDrawObject((HANDLE)pDirectDrawGlobalInternal->hDD);
158 }
159
160 status = NtGdiDdDeleteDirectDrawObject((HANDLE)pDirectDrawGlobal->hDD);
161 if ((status == TRUE) && (pDirectDrawGlobalInternal->hDD != 0))
162 {
163 pDirectDrawGlobalInternal->hDD = 0;
164 }
165
166 return status;
167 }
168
169 /*
170 * @implemented
171 *
172 * GDIEntry 4
173 */
174 BOOL
175 STDCALL
176 DdCreateSurfaceObject( LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
177 BOOL bPrimarySurface)
178 {
179 return intDDCreateSurface(pSurfaceLocal,1);
180 }
181
182 /*
183 * @implemented
184 *
185 * GDIEntry 5
186 */
187 BOOL
188 STDCALL
189 DdDeleteSurfaceObject(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal)
190 {
191 if (!pSurfaceLocal->hDDSurface)
192 {
193 return FALSE;
194 }
195
196 return NtGdiDdDeleteSurfaceObject((HANDLE)pSurfaceLocal->hDDSurface);
197 }
198
199 /*
200 * @implemented
201 *
202 * GDIEntry 6
203 */
204 BOOL
205 STDCALL
206 DdResetVisrgn(LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
207 HWND hWnd)
208 {
209 return NtGdiDdResetVisrgn((HANDLE) pSurfaceLocal->hDDSurface, hWnd);
210 }
211
212 /*
213 * @implemented
214 *
215 * GDIEntry 7
216 */
217 HDC STDCALL DdGetDC(
218 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal,
219 LPPALETTEENTRY pColorTable
220 )
221 {
222 return NtGdiDdGetDC(pColorTable, (HANDLE) pSurfaceLocal->hDDSurface);
223 }
224
225 /*
226 * @implemented
227 *
228 * GDIEntry 8
229 */
230 BOOL STDCALL DdReleaseDC(
231 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceLocal
232 )
233 {
234 return NtGdiDdReleaseDC((HANDLE) pSurfaceLocal->hDDSurface);
235 }
236
237
238
239 /*
240 * @implemented
241 *
242 * GDIEntry 10
243 */
244 BOOL
245 STDCALL
246 DdReenableDirectDrawObject(LPDDRAWI_DIRECTDRAW_GBL pDirectDrawGlobal,
247 BOOL *pbNewMode)
248 {
249 if (!pDirectDrawGlobal->hDD)
250 {
251 if (!pDirectDrawGlobalInternal->hDD)
252 {
253 return FALSE;
254 }
255 return NtGdiDdReenableDirectDrawObject((HANDLE)pDirectDrawGlobalInternal->hDD, pbNewMode);
256 }
257
258 return NtGdiDdReenableDirectDrawObject((HANDLE)pDirectDrawGlobal->hDD, pbNewMode);
259 }
260
261 /*
262 * @implemented
263 *
264 * GDIEntry 11
265 */
266 BOOL
267 STDCALL
268 DdAttachSurface( LPDDRAWI_DDRAWSURFACE_LCL pSurfaceFrom,
269 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceTo)
270 {
271
272 /* Create Surface if it does not exits one */
273 if (pSurfaceFrom->hDDSurface)
274 {
275 if (!intDDCreateSurface(pSurfaceFrom,FALSE))
276 {
277 return FALSE;
278 }
279 }
280
281 /* Create Surface if it does not exits one */
282 if (pSurfaceTo->hDDSurface)
283 {
284 if (!intDDCreateSurface(pSurfaceTo,FALSE))
285 {
286 return FALSE;
287 }
288 }
289
290 return NtGdiDdAttachSurface( (HANDLE) pSurfaceFrom->hDDSurface, (HANDLE) pSurfaceTo->hDDSurface);
291 }
292
293 /*
294 * @implemented
295 *
296 * GDIEntry 12
297 */
298 VOID
299 STDCALL
300 DdUnattachSurface(LPDDRAWI_DDRAWSURFACE_LCL pSurface,
301 LPDDRAWI_DDRAWSURFACE_LCL pSurfaceAttached)
302 {
303 NtGdiDdUnattachSurface((HANDLE) pSurface->hDDSurface, (HANDLE) pSurfaceAttached->hDDSurface);
304 }
305
306 /*
307 * @implemented
308 *
309 * GDIEntry 13
310 */
311 ULONG
312 STDCALL
313 DdQueryDisplaySettingsUniqueness()
314 {
315 return RemberDdQueryDisplaySettingsUniquenessID;
316 }
317
318 /*
319 * @implemented
320 *
321 * GDIEntry 14
322 */
323 HANDLE
324 STDCALL
325 DdGetDxHandle(LPDDRAWI_DIRECTDRAW_LCL pDDraw,
326 LPDDRAWI_DDRAWSURFACE_LCL pSurface,
327 BOOL bRelease)
328 {
329 if (pSurface)
330 {
331 return ((HANDLE) NtGdiDdGetDxHandle(NULL, (HANDLE)pSurface->hDDSurface, bRelease));
332 }
333
334
335 if (!pDDraw->lpGbl->hDD)
336 {
337 if (!pDirectDrawGlobalInternal->hDD)
338 {
339 return FALSE;
340 }
341 return ((HANDLE) NtGdiDdGetDxHandle( (HANDLE) pDirectDrawGlobalInternal->hDD, (HANDLE) pSurface->hDDSurface, bRelease));
342 }
343
344 return ((HANDLE) NtGdiDdGetDxHandle((HANDLE)pDDraw->lpGbl->hDD, (HANDLE) pSurface->hDDSurface, bRelease));
345 }
346
347 /*
348 * @implemented
349 *
350 * GDIEntry 15
351 */
352 BOOL STDCALL DdSetGammaRamp(
353 LPDDRAWI_DIRECTDRAW_LCL pDDraw,
354 HDC hdc,
355 LPVOID lpGammaRamp
356 )
357 {
358 if (!pDDraw->lpGbl->hDD)
359 {
360 if (!pDirectDrawGlobalInternal->hDD)
361 {
362 return FALSE;
363 }
364 return NtGdiDdSetGammaRamp((HANDLE)pDirectDrawGlobalInternal->hDD,hdc,lpGammaRamp);
365 }
366
367 return NtGdiDdSetGammaRamp((HANDLE)pDDraw->lpGbl->hDD,hdc,lpGammaRamp);
368 }
369
370 /*
371 * @implemented
372 *
373 * GDIEntry 16
374 */
375 DWORD STDCALL DdSwapTextureHandles(
376 LPDDRAWI_DIRECTDRAW_LCL pDDraw,
377 LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl1,
378 LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl2
379 )
380 {
381 return TRUE;
382 }
383
384
385 /* interal create surface */
386 BOOL
387 intDDCreateSurface ( LPDDRAWI_DDRAWSURFACE_LCL pSurface,
388 BOOL bComplete)
389 {
390 DD_SURFACE_LOCAL SurfaceLocal;
391 DD_SURFACE_GLOBAL SurfaceGlobal;
392 DD_SURFACE_MORE SurfaceMore;
393
394 /* Zero struct */
395 RtlZeroMemory(&SurfaceLocal, sizeof(DD_SURFACE_LOCAL));
396 RtlZeroMemory(&SurfaceGlobal, sizeof(DD_SURFACE_GLOBAL));
397 RtlZeroMemory(&SurfaceMore, sizeof(DD_SURFACE_MORE));
398
399 /* Set up SurfaceLocal struct */
400 SurfaceLocal.ddsCaps.dwCaps = pSurface->ddsCaps.dwCaps;
401 SurfaceLocal.dwFlags = pSurface->dwFlags;
402
403 /* Set up SurfaceMore struct */
404 /* copy pSurface->ddckCKDestBlt and pSurface->ddckCKSrcBlt to SurfaceMore.ddsCapsEx */
405 memcpy(&SurfaceMore.ddsCapsEx, &pSurface->ddckCKDestBlt, sizeof(DDSCAPSEX));
406 SurfaceMore.dwSurfaceHandle = (DWORD) pSurface->dbnOverlayNode.object_int->lpVtbl;
407
408
409 /* Set up SurfaceGlobal struct */
410 SurfaceGlobal.fpVidMem = pSurface->lpGbl->fpVidMem;
411 SurfaceGlobal.dwLinearSize = pSurface->lpGbl->dwLinearSize;
412 SurfaceGlobal.wHeight = pSurface->lpGbl->wHeight;
413 SurfaceGlobal.wWidth = pSurface->lpGbl->wWidth;
414
415 /* check which memory type should be use */
416 if ((pSurface->dwFlags & DDRAWISURFGBL_LOCKVRAMSTYLE) == DDRAWISURFGBL_LOCKVRAMSTYLE)
417 {
418 memcpy(&SurfaceGlobal.ddpfSurface,&pSurface->lpGbl->lpDD->vmiData.ddpfDisplay, sizeof(DDPIXELFORMAT));
419 }
420 else
421 {
422 memcpy(&SurfaceGlobal.ddpfSurface,&pSurface->lpGbl->ddpfSurface, sizeof(DDPIXELFORMAT));
423 }
424
425 /* Determer if Gdi32 chace of directdraw handler or not */
426 if (pSurface->lpGbl->lpDD->hDD)
427 {
428 pSurface->hDDSurface = ((DWORD) NtGdiDdCreateSurfaceObject( (HANDLE) pSurface->lpGbl->lpDD->hDD,
429 (HANDLE) pSurface->hDDSurface, &SurfaceLocal,
430 &SurfaceMore, &SurfaceGlobal, bComplete));
431 }
432 else
433 {
434 pSurface->hDDSurface = ((DWORD) NtGdiDdCreateSurfaceObject( (HANDLE) pDirectDrawGlobalInternal->hDD,
435 (HANDLE) pSurface->hDDSurface, &SurfaceLocal,
436 &SurfaceMore,
437 &SurfaceGlobal,
438 bComplete));
439 }
440
441 /* return status */
442 if (pSurface->hDDSurface)
443 {
444 return TRUE;
445 }
446
447 return FALSE;
448 }