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