sorry forget This->DirectDrawGlobal
[reactos.git] / reactos / lib / ddraw / hal / ddraw.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS
5 * FILE: lib/ddraw/hal/ddraw.c
6 * PURPOSE: DirectDraw HAL Implementation
7 * PROGRAMMER: Magnus Olsen, Maarten Bosma
8 *
9 */
10
11 #include "rosdraw.h"
12
13
14 HRESULT Hal_DirectDraw_Initialize (LPDIRECTDRAW7 iface)
15 {
16 IDirectDrawImpl* This = (IDirectDrawImpl*)iface;
17
18
19 /* point to it self */
20 This->DirectDrawGlobal.lp16DD = &This->DirectDrawGlobal;
21
22 /* get the object */
23 if(!DdCreateDirectDrawObject (&This->DirectDrawGlobal, This->hdc))
24 return DDERR_INVALIDPARAMS;
25
26
27 /* alloc all the space */
28 This->DirectDrawGlobal.lpDDCBtmp = (LPDDHAL_CALLBACKS)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DDHAL_CALLBACKS));
29 This->DirectDrawGlobal.lpD3DHALCallbacks = (ULONG_PTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY, sizeof(D3DHAL_CALLBACKS));
30 This->DirectDrawGlobal.lpD3DGlobalDriverData = (ULONG_PTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(D3DHAL_GLOBALDRIVERDATA));
31
32
33 /* Fill in some info */
34 This->HalInfo.lpD3DGlobalDriverData = This->DirectDrawGlobal.lpD3DGlobalDriverData;
35 This->HalInfo.lpD3DHALCallbacks = This->DirectDrawGlobal.lpD3DHALCallbacks;
36 This->HalInfo.lpDDCallbacks = &This->DirectDrawGlobal.lpDDCBtmp->HALDD;
37 This->HalInfo.lpDDExeBufCallbacks = &This->DirectDrawGlobal.lpDDCBtmp->HALDDExeBuf;
38 This->HalInfo.lpDDPaletteCallbacks = &This->DirectDrawGlobal.lpDDCBtmp->HALDDPalette;
39 This->HalInfo.lpDDSurfaceCallbacks = &This->DirectDrawGlobal.lpDDCBtmp->HALDDSurface;
40
41 /* FIXME The insate is not right we need the info that the three NULL return */
42
43 /* query all kinds of infos from the driver */
44 if(!DdQueryDirectDrawObject (
45 &This->DirectDrawGlobal,
46 &This->HalInfo,
47 This->HalInfo.lpDDCallbacks,
48 This->HalInfo.lpDDSurfaceCallbacks,
49 This->HalInfo.lpDDPaletteCallbacks,
50 (LPD3DHAL_CALLBACKS)This->DirectDrawGlobal.lpD3DHALCallbacks,
51 (LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData,
52 This->HalInfo.lpDDExeBufCallbacks,
53 NULL,
54 NULL,
55 NULL ))
56 {
57 OutputDebugString(L"First DdQueryDirectDrawObject failed");
58 return 1;
59 }
60
61 /* FIXME The insate is not right we need the info that the three NULL return and use it here*/
62
63 /* Fixme shall we selected the pixel type before we call the DdQueryDirectDrawObject second time
64 and fill in more info ?? */
65
66 This->HalInfo.vmiData.pvmList = HeapAlloc(GetProcessHeap(), 0, sizeof(VIDMEM) * This->HalInfo.vmiData.dwNumHeaps);
67 This->DirectDrawGlobal.lpdwFourCC = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD) * This->HalInfo.ddCaps.dwNumFourCCCodes);
68 This->DirectDrawGlobal.lpZPixelFormats = HeapAlloc(GetProcessHeap(), 0, sizeof(DDPIXELFORMAT) * This->DirectDrawGlobal.dwNumZPixelFormats);
69 ((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->lpTextureFormats = HeapAlloc(GetProcessHeap(), 0, sizeof(DDSURFACEDESC) * ((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->dwNumTextureFormats);
70
71 if(!DdQueryDirectDrawObject (
72 &This->DirectDrawGlobal,
73 &This->HalInfo,
74 This->HalInfo.lpDDCallbacks,
75 This->HalInfo.lpDDSurfaceCallbacks,
76 This->HalInfo.lpDDPaletteCallbacks,
77 (LPD3DHAL_CALLBACKS)This->DirectDrawGlobal.lpD3DHALCallbacks,
78 (LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData,
79 This->HalInfo.lpDDExeBufCallbacks,
80 ((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->lpTextureFormats,
81 This->DirectDrawGlobal.lpdwFourCC,
82 This->HalInfo.vmiData.pvmList
83 ))
84 {
85 OutputDebugString(L"Second DdQueryDirectDrawObject failed");
86 return 1;
87 }
88
89 /* Copy HalInfo to DirectDrawGlobal (Not complete)*/
90
91 RtlCopyMemory(&This->DirectDrawGlobal.vmiData,&This->HalInfo.vmiData,sizeof(VIDMEMINFO));
92 RtlCopyMemory(&This->DirectDrawGlobal.ddCaps,&This->HalInfo.ddCaps,sizeof(DDCORECAPS));
93 This->DirectDrawGlobal.dwMonitorFrequency = This->HalInfo.dwMonitorFrequency;
94
95 /* have not check where it should go into yet
96 This->HalInfo.GetDriverInfo datatype LPDDHAL_GETDRIVERINFO
97 */
98
99 This->DirectDrawGlobal.dwModeIndex = This->HalInfo.dwModeIndex;
100
101 /* have not check where it should go into yet
102 This->HalInfo.lpdwFourCC datatype LPDWORD
103 */
104
105 This->DirectDrawGlobal.dwNumModes = This->HalInfo.dwNumModes;
106 This->DirectDrawGlobal.lpModeInfo = This->HalInfo.lpModeInfo;
107
108 /* have not check where it should go into yet
109 This->HalInfo.dwFlags data type DWORD
110 */
111
112 /* Unsure which of these two for lpPDevice
113 This->DirectDrawGlobal.dwPDevice = This->HalInfo.lpPDevice;
114 This->lpDriverHandle = This->HalInfo.lpPDevice;
115 */
116
117 This->DirectDrawGlobal.hInstance = This->HalInfo.hInstance;
118
119 /* have not check where it should go into yet
120 This->lpD3DGlobalDriverData datatype ULONG_PTR
121 This->lpD3DHALCallbacks datatype ULONG_PTR
122 */
123 RtlCopyMemory(&This->DirectDrawGlobal.lpDDCBtmp->HALDDExeBuf,&This->HalInfo.lpDDExeBufCallbacks,sizeof(DDHAL_DDEXEBUFCALLBACKS));
124
125
126
127 /************************************************************************/
128 /* Set up the rest of the callbacks all callbacks we get back from */
129 /* gdi32.dll is user mode */
130 /************************************************************************/
131
132 /* Todo add a check see if HalInfo.GetDriverInfo is supported or not */
133
134 /* Do not trust msdn what it say about dwContext it is not in use for
135 windows nt, it is in use for all os, and it always pont to
136 DirectDrawGlobal.hDD */
137
138 DDHAL_GETDRIVERINFODATA DriverInfo;
139 memset(&DriverInfo,0, sizeof(DDHAL_GETDRIVERINFODATA));
140 DriverInfo.dwSize = sizeof(DDHAL_GETDRIVERINFODATA);
141 DriverInfo.dwContext = This->DirectDrawGlobal.hDD;
142
143
144
145
146 /* Get ColorControlCallbacks */
147 DriverInfo.guidInfo = GUID_ColorControlCallbacks;
148 DriverInfo.lpvData = &This->DirectDrawGlobal.lpDDCBtmp->HALDDColorControl;
149 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDCOLORCONTROLCALLBACKS);
150 This->HalInfo.GetDriverInfo( &DriverInfo);
151
152
153 /* Get the GUID_D3DCallbacks callback */
154
155 /* Problem with include files
156 DDHAL_DDMISCELLANEOUSCALLBACKS misc;
157 DriverInfo.guidInfo = GUID_D3DCallbacks;
158 DriverInfo.lpvData = &misc;
159 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
160 This->HalInfo.GetDriverInfo( &DriverInfo);*/
161
162 /* Get the D3DCallbacks2 */
163 /* do we need alloc memmory for This->DirectDrawGlobal.lpD3DHALCallbacks2 */
164 DriverInfo.guidInfo = GUID_D3DCallbacks2;
165 DriverInfo.lpvData = &This->DirectDrawGlobal.lpD3DHALCallbacks2;
166 DriverInfo.dwExpectedSize = sizeof(D3DHAL_CALLBACKS2);
167 This->HalInfo.GetDriverInfo( &DriverInfo);
168
169
170 /* Get the D3DCallbacks3 */
171 /*
172 DriverInfo.guidInfo = GUID_D3DCallbacks3;
173 DriverInfo.lpvData = &misc;
174 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
175 This->HalInfo.GetDriverInfo( &DriverInfo);
176 */
177
178 /* Get the misc callback */
179 /* Problem with include files
180 DriverInfo.guidInfo = GUID_D3DCaps;
181 DriverInfo.lpvData = &misc;
182 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
183 This->HalInfo.GetDriverInfo( &DriverInfo);
184 */
185
186 /* Get the D3DExtendedCaps */
187 /*
188 DriverInfo.guidInfo = GUID_D3DExtendedCaps;
189 DriverInfo.lpvData = &misc;
190 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
191 This->HalInfo.GetDriverInfo( &DriverInfo);
192 */
193
194 /* Get the D3DParseUnknownCommandCallback */
195 /*
196 DriverInfo.guidInfo = GUID_D3DParseUnknownCommandCallback;
197 DriverInfo.lpvData = &misc;
198 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
199 This->HalInfo.GetDriverInfo( &DriverInfo);
200 */
201
202 /* Get the GetHeapAlignment */
203 /*
204 DriverInfo.guidInfo = GUID_GetHeapAlignment;
205 DriverInfo.lpvData = &misc;
206 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
207 This->HalInfo.GetDriverInfo( &DriverInfo);
208 */
209
210 /* Get the KernelCallbacks */
211 DriverInfo.guidInfo = GUID_KernelCallbacks;
212 DriverInfo.lpvData = &This->DirectDrawGlobal.lpDDCBtmp->HALDDKernel;
213 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDKERNELCALLBACKS);
214 This->HalInfo.GetDriverInfo( &DriverInfo);
215
216
217 /* Get the KernelCaps */
218 /* Need Alloc memmory for lpDDKernelCaps ?? */
219 DriverInfo.guidInfo = GUID_KernelCaps;
220 DriverInfo.lpvData = &This->DirectDrawGlobal.lpDDKernelCaps;
221 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDKERNELCALLBACKS);
222 This->HalInfo.GetDriverInfo( &DriverInfo);
223
224
225 /* Get the MiscellaneousCallbacks */
226 DriverInfo.guidInfo = GUID_MiscellaneousCallbacks;
227 DriverInfo.lpvData = &This->DirectDrawGlobal.lpDDCBtmp->HALDDMiscellaneous;
228 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
229 This->HalInfo.GetDriverInfo( &DriverInfo);
230
231
232 /* Get the Miscellaneous2Callbacks */
233 /*
234 DriverInfo.guidInfo = GUID_Miscellaneous2Callbacks;
235 DriverInfo.lpvData = &misc;
236 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
237 This->HalInfo.GetDriverInfo( &DriverInfo);
238 */
239
240 /* Get the MotionCompCallbacks */
241 DriverInfo.guidInfo = GUID_MotionCompCallbacks;
242 DriverInfo.lpvData = &This->DirectDrawGlobal.lpDDCBtmp->HALDDMotionComp;
243 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMOTIONCOMPCALLBACKS);
244 This->HalInfo.GetDriverInfo( &DriverInfo);
245
246
247 /* Get the NonLocalVidMemCaps */
248 /*
249 DriverInfo.guidInfo = GUID_NonLocalVidMemCaps;
250 DriverInfo.lpvData = &misc;
251 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
252 This->HalInfo.GetDriverInfo( &DriverInfo);
253 */
254
255 /* Get the NTCallbacks */
256 /*
257 DriverInfo.guidInfo = GUID_NTCallbacks;
258 DriverInfo.lpvData = &misc;
259 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
260 This->HalInfo.GetDriverInfo( &DriverInfo);
261 */
262
263 /* Get the NTPrivateDriverCaps */
264 /*
265 DriverInfo.guidInfo = GUID_NTPrivateDriverCaps;
266 DriverInfo.lpvData = &misc;
267 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
268 This->HalInfo.GetDriverInfo( &DriverInfo);
269 */
270
271 /* Get the UpdateNonLocalHeap */
272 /*
273 DriverInfo.guidInfo = GUID_UpdateNonLocalHeap;
274 DriverInfo.lpvData = &misc;
275 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
276 This->HalInfo.GetDriverInfo( &DriverInfo);
277 */
278
279 /* Get the VideoPortCallbacks */
280 /* Problem with include files
281 DriverInfo.guidInfo = GUID_VideoPortCallbacks;
282 DriverInfo.lpvData = &This->DirectDrawGlobal.lpDDCBtmp->HALDDVideoPort;
283 DriverInfo.dwExpectedSize = sizeof(HALDDVideoPort);
284 This->HalInfo.GetDriverInfo( &DriverInfo);
285 */
286
287
288 /* Get the VideoPortCaps */
289 /*
290 DriverInfo.guidInfo = GUID_VideoPortCaps;
291 DriverInfo.lpvData = &misc;
292 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
293 This->HalInfo.GetDriverInfo( &DriverInfo);
294 */
295
296 /* Get the ZPixelFormats */
297 /*
298 DriverInfo.guidInfo = GUID_ZPixelFormats;
299 DriverInfo.lpvData = &misc;
300 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
301 This->HalInfo.GetDriverInfo( &DriverInfo);
302 */
303
304
305 /* FIXME add setup for one call ot get memmory */
306
307
308 /* now all insate of HAL is done and we hopply do not have forget anything*/
309
310 return DD_OK;
311 }
312
313 HRESULT Hal_DirectDraw_SetCooperativeLevel (LPDIRECTDRAW7 iface)
314 {
315 return DD_OK;
316 }
317
318
319 VOID Hal_DirectDraw_Release (LPDIRECTDRAW7 iface)
320 {
321 IDirectDrawImpl* This = (IDirectDrawImpl*)iface;
322
323 DdDeleteDirectDrawObject (&This->DirectDrawGlobal);
324
325 if(This->HalInfo.vmiData.pvmList)
326 HeapFree(GetProcessHeap(), 0, This->HalInfo.vmiData.pvmList);
327 if(This->DirectDrawGlobal.lpdwFourCC)
328 HeapFree(GetProcessHeap(), 0, This->DirectDrawGlobal.lpdwFourCC);
329 if(This->DirectDrawGlobal.lpZPixelFormats)
330 HeapFree(GetProcessHeap(), 0, This->DirectDrawGlobal.lpZPixelFormats);
331 if(((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->lpTextureFormats)
332 HeapFree(GetProcessHeap(), 0, ((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->lpTextureFormats);
333
334 if(This->DirectDrawGlobal.lpDDCBtmp)
335 HeapFree(GetProcessHeap(), 0, This->DirectDrawGlobal.lpDDCBtmp);
336 if(This->DirectDrawGlobal.lpD3DHALCallbacks)
337 HeapFree(GetProcessHeap(), 0, (PVOID)This->DirectDrawGlobal.lpD3DHALCallbacks);
338 if(This->DirectDrawGlobal.lpD3DGlobalDriverData)
339 HeapFree(GetProcessHeap(), 0, (PVOID)This->DirectDrawGlobal.lpD3DGlobalDriverData);
340 }