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