3fb3a6f4566e68430012d5c03e595977eee532e8
[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 /* FIXME add all callback that have been commect out to gpl */
139 /* FIXME free the memmor that being alloc when ddraw.dll exists */
140 /* FIXME add check for DriverInfo if the handle or not */
141
142 DDHAL_GETDRIVERINFODATA DriverInfo;
143 memset(&DriverInfo,0, sizeof(DDHAL_GETDRIVERINFODATA));
144 DriverInfo.dwSize = sizeof(DDHAL_GETDRIVERINFODATA);
145 DriverInfo.dwContext = This->DirectDrawGlobal.hDD;
146
147
148 /* Get ColorControlCallbacks */
149 DriverInfo.guidInfo = GUID_ColorControlCallbacks;
150 DriverInfo.lpvData = &This->DirectDrawGlobal.lpDDCBtmp->HALDDColorControl;
151 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDCOLORCONTROLCALLBACKS);
152 This->HalInfo.GetDriverInfo( &DriverInfo);
153
154
155 /* Get the GUID_D3DCallbacks callback */
156
157 /* Problem with include files
158 DDHAL_DDMISCELLANEOUSCALLBACKS misc;
159 DriverInfo.guidInfo = GUID_D3DCallbacks;
160 DriverInfo.lpvData = &misc;
161 DriverInfo.dwExpectedSize = sizeof();
162 This->HalInfo.GetDriverInfo( &DriverInfo);*/
163
164 /* Get the D3DCallbacks2 */
165 This->DirectDrawGlobal.lpD3DHALCallbacks2 = (ULONG_PTR)HeapAlloc(GetProcessHeap(), 0, sizeof(D3DHAL_CALLBACKS2));
166 DriverInfo.guidInfo = GUID_D3DCallbacks2;
167 DriverInfo.lpvData = (PVOID)This->DirectDrawGlobal.lpD3DHALCallbacks2;
168 DriverInfo.dwExpectedSize = sizeof(D3DHAL_CALLBACKS2);
169 This->HalInfo.GetDriverInfo( &DriverInfo);
170
171
172 /* Get the D3DCallbacks3 */
173 This->DirectDrawGlobal.lpD3DHALCallbacks = (ULONG_PTR)HeapAlloc(GetProcessHeap(), 0, sizeof(D3DHAL_CALLBACKS3));
174 DriverInfo.guidInfo = GUID_D3DCallbacks3;
175 DriverInfo.lpvData = (PVOID)This->DirectDrawGlobal.lpD3DHALCallbacks;
176 DriverInfo.dwExpectedSize = sizeof(D3DHAL_CALLBACKS3);
177 This->HalInfo.GetDriverInfo( &DriverInfo);
178
179
180 /* Get the misc callback */
181 /* Problem with include files
182 DriverInfo.guidInfo = GUID_D3DCaps;
183 DriverInfo.lpvData = &misc;
184 DriverInfo.dwExpectedSize = sizeof();
185 This->HalInfo.GetDriverInfo( &DriverInfo);
186 */
187
188 /* Get the D3DExtendedCaps */
189
190 This->DirectDrawGlobal.lpD3DExtendedCaps = (ULONG_PTR)HeapAlloc(GetProcessHeap(), 0, sizeof(D3DHAL_D3DEXTENDEDCAPS));
191 DriverInfo.guidInfo = GUID_D3DExtendedCaps;
192 DriverInfo.lpvData = (PVOID) This->DirectDrawGlobal.lpD3DExtendedCaps;
193 DriverInfo.dwExpectedSize = sizeof(D3DHAL_D3DEXTENDEDCAPS);
194 This->HalInfo.GetDriverInfo( &DriverInfo);
195
196
197 /* Get the D3DParseUnknownCommandCallback */
198 /* D3dDrawPrimitives2 callback where should it be fill in
199 DriverInfo.guidInfo = GUID_D3DParseUnknownCommandCallback;
200 DriverInfo.lpvData = &misc;
201 DriverInfo.dwExpectedSize = sizeof();
202 This->HalInfo.GetDriverInfo( &DriverInfo);
203 */
204
205 /* Get the GetHeapAlignment */
206 /* where should it be fill in
207 DriverInfo.guidInfo = GUID_GetHeapAlignment;
208 DriverInfo.lpvData = &misc;
209 DriverInfo.dwExpectedSize = sizeof();
210 This->HalInfo.GetDriverInfo( &DriverInfo);
211 */
212
213
214 /* Get the KernelCallbacks */
215 DriverInfo.guidInfo = GUID_KernelCallbacks;
216 DriverInfo.lpvData = &This->DirectDrawGlobal.lpDDCBtmp->HALDDKernel;
217 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDKERNELCALLBACKS);
218 This->HalInfo.GetDriverInfo( &DriverInfo);
219
220
221 /* Get the KernelCaps */
222 This->DirectDrawGlobal.lpDDKernelCaps = (LPDDKERNELCAPS)HeapAlloc(GetProcessHeap(), 0, sizeof(DDHAL_DDKERNELCALLBACKS));
223 DriverInfo.guidInfo = GUID_KernelCaps;
224 DriverInfo.lpvData = (PVOID) This->DirectDrawGlobal.lpDDKernelCaps;
225 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDKERNELCALLBACKS);
226 This->HalInfo.GetDriverInfo( &DriverInfo);
227
228
229 /* Get the MiscellaneousCallbacks */
230 DriverInfo.guidInfo = GUID_MiscellaneousCallbacks;
231 DriverInfo.lpvData = &This->DirectDrawGlobal.lpDDCBtmp->HALDDMiscellaneous;
232 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
233 This->HalInfo.GetDriverInfo( &DriverInfo);
234
235
236 /* Get the Miscellaneous2Callbacks */
237 /* Not in the DDRAWI_DIRECTDRAW_GBL we map it up as private
238 Contain CreatesurfaceEx and other nice callbacks */
239 DriverInfo.guidInfo = GUID_Miscellaneous2Callbacks;
240 DriverInfo.lpvData = &This->Misc2Callback;
241 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMISCELLANEOUSCALLBACKS);
242 This->HalInfo.GetDriverInfo( &DriverInfo);
243
244
245 /* Get the MotionCompCallbacks */
246 DriverInfo.guidInfo = GUID_MotionCompCallbacks;
247 DriverInfo.lpvData = &This->DirectDrawGlobal.lpDDCBtmp->HALDDMotionComp;
248 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDMOTIONCOMPCALLBACKS);
249 This->HalInfo.GetDriverInfo( &DriverInfo);
250
251
252 /* Get the NonLocalVidMemCaps */
253 This->DirectDrawGlobal.lpddNLVCaps = (LPDDNONLOCALVIDMEMCAPS)HeapAlloc(GetProcessHeap(), 0, sizeof(DDNONLOCALVIDMEMCAPS));
254 DriverInfo.guidInfo = GUID_NonLocalVidMemCaps;
255 DriverInfo.lpvData = (PVOID)This->DirectDrawGlobal.lpddNLVCaps;
256 DriverInfo.dwExpectedSize = sizeof(DDNONLOCALVIDMEMCAPS);
257 This->HalInfo.GetDriverInfo( &DriverInfo);
258
259
260 /* Get the NTCallbacks */
261 /* Fill in wher
262 DriverInfo.guidInfo = GUID_NTCallbacks;
263 DriverInfo.lpvData = &misc;
264 DriverInfo.dwExpectedSize = sizeof();
265 This->HalInfo.GetDriverInfo( &DriverInfo);
266 */
267
268 /* Get the NTPrivateDriverCaps */
269 /* Fill in wher
270 DriverInfo.guidInfo = GUID_NTPrivateDriverCaps;
271 DriverInfo.lpvData = &misc;
272 DriverInfo.dwExpectedSize = sizeof();
273 This->HalInfo.GetDriverInfo( &DriverInfo);
274 */
275
276 /* Get the UpdateNonLocalHeap */
277 /* Fill in where
278 DriverInfo.guidInfo = GUID_UpdateNonLocalHeap;
279 DriverInfo.lpvData = &misc;
280 DriverInfo.dwExpectedSize = sizeof();
281 This->HalInfo.GetDriverInfo( &DriverInfo);
282 */
283
284 /* Get the VideoPortCallbacks */
285 DriverInfo.guidInfo = GUID_VideoPortCallbacks;
286 DriverInfo.lpvData = &This->DirectDrawGlobal.lpDDCBtmp->HALDDVideoPort;
287 DriverInfo.dwExpectedSize = sizeof(DDHAL_DDVIDEOPORTCALLBACKS);
288 This->HalInfo.GetDriverInfo( &DriverInfo);
289
290
291 /* Get the VideoPortCaps */
292 This->DirectDrawGlobal.lpDDVideoPortCaps = (LPDDVIDEOPORTCAPS)HeapAlloc(GetProcessHeap(), 0, sizeof(DDVIDEOPORTCAPS));
293 DriverInfo.guidInfo = GUID_VideoPortCaps;
294 DriverInfo.lpvData = (PVOID)This->DirectDrawGlobal.lpDDVideoPortCaps;
295 DriverInfo.dwExpectedSize = sizeof(DDVIDEOPORTCAPS);
296 This->HalInfo.GetDriverInfo( &DriverInfo);
297
298
299 /* Get the ZPixelFormats */
300 This->DirectDrawGlobal.lpZPixelFormats = (LPDDPIXELFORMAT)HeapAlloc(GetProcessHeap(), 0, sizeof(DDPIXELFORMAT));
301 DriverInfo.guidInfo = GUID_ZPixelFormats;
302 DriverInfo.lpvData = (PVOID)This->DirectDrawGlobal.lpZPixelFormats;
303 DriverInfo.dwExpectedSize = sizeof(DDPIXELFORMAT);
304 This->HalInfo.GetDriverInfo( &DriverInfo);
305
306
307
308 /* Setup some info from the callbacks we got */
309
310 /* FIXME do more callbacks and fill the gpl struct */
311
312 DDHAL_GETAVAILDRIVERMEMORYDATA mem;
313 mem.lpDD = &This->DirectDrawGlobal;
314
315 This->DirectDrawGlobal.lpDDCBtmp->HALDDMiscellaneous.GetAvailDriverMemory(&mem);
316
317 This->DirectDrawGlobal.ddCaps.dwVidMemFree = mem.dwFree;
318 This->DirectDrawGlobal.ddCaps.dwVidMemTotal = mem.dwTotal;
319
320
321
322
323
324 /* Now all setup for HAL is done and we hopply do not have forget anything */
325
326 return DD_OK;
327 }
328
329 HRESULT Hal_DirectDraw_SetCooperativeLevel (LPDIRECTDRAW7 iface)
330 {
331 return DD_OK;
332 }
333
334
335 VOID Hal_DirectDraw_Release (LPDIRECTDRAW7 iface)
336 {
337 IDirectDrawImpl* This = (IDirectDrawImpl*)iface;
338
339 DdDeleteDirectDrawObject (&This->DirectDrawGlobal);
340
341 if(This->HalInfo.vmiData.pvmList)
342 HeapFree(GetProcessHeap(), 0, This->HalInfo.vmiData.pvmList);
343 if(This->DirectDrawGlobal.lpdwFourCC)
344 HeapFree(GetProcessHeap(), 0, This->DirectDrawGlobal.lpdwFourCC);
345 if(This->DirectDrawGlobal.lpZPixelFormats)
346 HeapFree(GetProcessHeap(), 0, This->DirectDrawGlobal.lpZPixelFormats);
347 if(((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->lpTextureFormats)
348 HeapFree(GetProcessHeap(), 0, ((LPD3DHAL_GLOBALDRIVERDATA)This->DirectDrawGlobal.lpD3DGlobalDriverData)->lpTextureFormats);
349
350 if(This->DirectDrawGlobal.lpDDCBtmp)
351 HeapFree(GetProcessHeap(), 0, This->DirectDrawGlobal.lpDDCBtmp);
352 if(This->DirectDrawGlobal.lpD3DHALCallbacks)
353 HeapFree(GetProcessHeap(), 0, (PVOID)This->DirectDrawGlobal.lpD3DHALCallbacks);
354 if(This->DirectDrawGlobal.lpD3DGlobalDriverData)
355 HeapFree(GetProcessHeap(), 0, (PVOID)This->DirectDrawGlobal.lpD3DGlobalDriverData);
356 }