Setup the hal startup process some bit. We still does not insate hal right yet.
[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 /* Get ColorControlCallbacks */
145 DriverInfo.guidInfo = GUID_ColorControlCallbacks;
146 DriverInfo.lpvData = &This->DirectDrawGlobal.lpDDCBtmp->HALDDColorControl;
147 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDCOLORCONTROLCALLBACKS);
148 This->HalInfo.GetDriverInfo( &DriverInfo);
149
150
151 /* Get the GUID_D3DCallbacks callback */
152
153 /* Problem with include files
154 DDHAL_DDMISCELLANEOUSCALLBACKS misc;
155 DriverInfo.guidInfo = GUID_D3DCallbacks;
156 DriverInfo.lpvData = &misc;
157 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
158 This->HalInfo.GetDriverInfo( &DriverInfo);*/
159
160 /* Get the D3DCallbacks2 */
161 This->DirectDrawGlobal.lpD3DHALCallbacks2 = (ULONG_PTR)HeapAlloc(GetProcessHeap(), 0, sizeof(D3DHAL_CALLBACKS2));
162 DriverInfo.guidInfo = GUID_D3DCallbacks2;
163 DriverInfo.lpvData = (PVOID)This->DirectDrawGlobal.lpD3DHALCallbacks2;
164 DriverInfo.dwExpectedSize = sizeof(D3DHAL_CALLBACKS2);
165 This->HalInfo.GetDriverInfo( &DriverInfo);
166
167
168 /* Get the D3DCallbacks3 */
169 This->DirectDrawGlobal.lpD3DHALCallbacks = (ULONG_PTR)HeapAlloc(GetProcessHeap(), 0, sizeof(D3DHAL_CALLBACKS3));
170 DriverInfo.guidInfo = GUID_D3DCallbacks3;
171 DriverInfo.lpvData = (PVOID)This->DirectDrawGlobal.lpD3DHALCallbacks;
172 DriverInfo.dwExpectedSize = sizeof(D3DHAL_CALLBACKS3);
173 This->HalInfo.GetDriverInfo( &DriverInfo);
174
175
176 /* Get the misc callback */
177 /* Problem with include files
178 DriverInfo.guidInfo = GUID_D3DCaps;
179 DriverInfo.lpvData = &misc;
180 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
181 This->HalInfo.GetDriverInfo( &DriverInfo);
182 */
183
184 /* Get the D3DExtendedCaps */
185
186 This->DirectDrawGlobal.lpD3DExtendedCaps = (ULONG_PTR)HeapAlloc(GetProcessHeap(), 0, sizeof(D3DHAL_D3DEXTENDEDCAPS));
187 DriverInfo.guidInfo = GUID_D3DExtendedCaps;
188 DriverInfo.lpvData = (PVOID) This->DirectDrawGlobal.lpD3DExtendedCaps;
189 DriverInfo.dwExpectedSize = sizeof(D3DHAL_D3DEXTENDEDCAPS);
190 This->HalInfo.GetDriverInfo( &DriverInfo);
191
192
193 /* Get the D3DParseUnknownCommandCallback */
194 /*
195 DriverInfo.guidInfo = GUID_D3DParseUnknownCommandCallback;
196 DriverInfo.lpvData = &misc;
197 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
198 This->HalInfo.GetDriverInfo( &DriverInfo);
199 */
200
201 /* Get the GetHeapAlignment */
202 /*
203 DriverInfo.guidInfo = GUID_GetHeapAlignment;
204 DriverInfo.lpvData = &misc;
205 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
206 This->HalInfo.GetDriverInfo( &DriverInfo);
207 */
208
209 /* Get the KernelCallbacks */
210 DriverInfo.guidInfo = GUID_KernelCallbacks;
211 DriverInfo.lpvData = &This->DirectDrawGlobal.lpDDCBtmp->HALDDKernel;
212 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDKERNELCALLBACKS);
213 This->HalInfo.GetDriverInfo( &DriverInfo);
214
215
216 /* Get the KernelCaps */
217 This->DirectDrawGlobal.lpDDKernelCaps = (LPDDKERNELCAPS)HeapAlloc(GetProcessHeap(), 0, sizeof(DDHAL_DDKERNELCALLBACKS));
218 DriverInfo.guidInfo = GUID_KernelCaps;
219 DriverInfo.lpvData = (PVOID) This->DirectDrawGlobal.lpDDKernelCaps;
220 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDKERNELCALLBACKS);
221 This->HalInfo.GetDriverInfo( &DriverInfo);
222
223
224 /* Get the MiscellaneousCallbacks */
225 DriverInfo.guidInfo = GUID_MiscellaneousCallbacks;
226 DriverInfo.lpvData = &This->DirectDrawGlobal.lpDDCBtmp->HALDDMiscellaneous;
227 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
228 This->HalInfo.GetDriverInfo( &DriverInfo);
229
230
231 /* Get the Miscellaneous2Callbacks */
232 /*
233 DriverInfo.guidInfo = GUID_Miscellaneous2Callbacks;
234 DriverInfo.lpvData = &misc;
235 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
236 This->HalInfo.GetDriverInfo( &DriverInfo);
237 */
238
239 /* Get the MotionCompCallbacks */
240 DriverInfo.guidInfo = GUID_MotionCompCallbacks;
241 DriverInfo.lpvData = &This->DirectDrawGlobal.lpDDCBtmp->HALDDMotionComp;
242 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMOTIONCOMPCALLBACKS);
243 This->HalInfo.GetDriverInfo( &DriverInfo);
244
245
246 /* Get the NonLocalVidMemCaps */
247 /*
248 DriverInfo.guidInfo = GUID_NonLocalVidMemCaps;
249 DriverInfo.lpvData = &misc;
250 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
251 This->HalInfo.GetDriverInfo( &DriverInfo);
252 */
253
254 /* Get the NTCallbacks */
255 /*
256 DriverInfo.guidInfo = GUID_NTCallbacks;
257 DriverInfo.lpvData = &misc;
258 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
259 This->HalInfo.GetDriverInfo( &DriverInfo);
260 */
261
262 /* Get the NTPrivateDriverCaps */
263 /*
264 DriverInfo.guidInfo = GUID_NTPrivateDriverCaps;
265 DriverInfo.lpvData = &misc;
266 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
267 This->HalInfo.GetDriverInfo( &DriverInfo);
268 */
269
270 /* Get the UpdateNonLocalHeap */
271 /*
272 DriverInfo.guidInfo = GUID_UpdateNonLocalHeap;
273 DriverInfo.lpvData = &misc;
274 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
275 This->HalInfo.GetDriverInfo( &DriverInfo);
276 */
277
278 /* Get the VideoPortCallbacks */
279 /* Problem with include files
280 DriverInfo.guidInfo = GUID_VideoPortCallbacks;
281 DriverInfo.lpvData = &This->DirectDrawGlobal.lpDDCBtmp->HALDDVideoPort;
282 DriverInfo.dwExpectedSize = sizeof(HALDDVideoPort);
283 This->HalInfo.GetDriverInfo( &DriverInfo);
284 */
285
286
287 /* Get the VideoPortCaps */
288 /*
289 DriverInfo.guidInfo = GUID_VideoPortCaps;
290 DriverInfo.lpvData = &misc;
291 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
292 This->HalInfo.GetDriverInfo( &DriverInfo);
293 */
294
295 /* Get the ZPixelFormats */
296 /*
297 DriverInfo.guidInfo = GUID_ZPixelFormats;
298 DriverInfo.lpvData = &misc;
299 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
300 This->HalInfo.GetDriverInfo( &DriverInfo);
301 */
302
303
304 /* FIXME add setup for one call ot get memmory */
305
306
307 /* now all insate of HAL is done and we hopply do not have forget anything*/
308
309 return DD_OK;
310 }
311
312 HRESULT Hal_DirectDraw_SetCooperativeLevel (LPDIRECTDRAW7 iface)
313 {
314 return DD_OK;
315 }
316
317
318 VOID Hal_DirectDraw_Release (LPDIRECTDRAW7 iface)
319 {
320 IDirectDrawImpl* This = (IDirectDrawImpl*)iface;
321
322 DdDeleteDirectDrawObject (&This->DirectDrawGlobal);
323
324 if(This->HalInfo.vmiData.pvmList)
325 HeapFree(GetProcessHeap(), 0, This->HalInfo.vmiData.pvmList);
326 if(This->DirectDrawGlobal.lpdwFourCC)
327 HeapFree(GetProcessHeap(), 0, This->DirectDrawGlobal.lpdwFourCC);
328 if(This->DirectDrawGlobal.lpZPixelFormats)
329 HeapFree(GetProcessHeap(), 0, This->DirectDrawGlobal.lpZPixelFormats);
330 if(((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->lpTextureFormats)
331 HeapFree(GetProcessHeap(), 0, ((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->lpTextureFormats);
332
333 if(This->DirectDrawGlobal.lpDDCBtmp)
334 HeapFree(GetProcessHeap(), 0, This->DirectDrawGlobal.lpDDCBtmp);
335 if(This->DirectDrawGlobal.lpD3DHALCallbacks)
336 HeapFree(GetProcessHeap(), 0, (PVOID)This->DirectDrawGlobal.lpD3DHALCallbacks);
337 if(This->DirectDrawGlobal.lpD3DGlobalDriverData)
338 HeapFree(GetProcessHeap(), 0, (PVOID)This->DirectDrawGlobal.lpD3DGlobalDriverData);
339 }