Fix some crach in ddraw.dll startup process for surface, we still got crach and surfa...
[reactos.git] / reactos / lib / ddraw / main / surface_main.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS
5 * FILE: lib/ddraw/main/surface.c
6 * PURPOSE: IDirectDrawSurface7 Implementation
7 * PROGRAMMER: Magnus Olsen, Maarten Bosma
8 *
9 */
10
11 #include "rosdraw.h"
12
13
14 HRESULT WINAPI Main_DDrawSurface_Initialize (LPDIRECTDRAWSURFACE7 iface, LPDIRECTDRAW pDD, LPDDSURFACEDESC2 pDDSD)
15 {
16 IDirectDrawSurfaceImpl* This = (IDirectDrawSurfaceImpl*)iface;
17
18 if(sizeof(DDSURFACEDESC2) != pDDSD->dwSize)
19 return DDERR_UNSUPPORTED;
20
21 if(!(pDDSD->dwFlags & DDSD_CAPS))
22 return DDERR_INVALIDPARAMS;
23
24 This->owner = (IDirectDrawImpl*)pDD;
25
26 if (This->owner->DirectDrawGlobal.lpDDCBtmp->HALDD.dwFlags & DDHAL_CB32_CANCREATESURFACE)
27 {
28 /* can the driver create the surface */
29 DDHAL_CANCREATESURFACEDATA CanCreateData;
30 memset(&CanCreateData, 0, sizeof(DDHAL_CANCREATESURFACEDATA));
31 CanCreateData.lpDD = &This->owner->DirectDrawGlobal;
32 CanCreateData.lpDDSurfaceDesc = (DDSURFACEDESC*)pDDSD;
33
34 if (This->owner->DirectDrawGlobal.lpDDCBtmp->HALDD.CanCreateSurface(&CanCreateData) == DDHAL_DRIVER_NOTHANDLED)
35 return DDERR_INVALIDPARAMS;
36
37 if(CanCreateData.ddRVal != DD_OK)
38 return CanCreateData.ddRVal;
39 }
40
41 /* surface global struct */
42 memset(&This->Global, 0, sizeof(DDRAWI_DDRAWSURFACE_GBL));
43 This->Global.lpDD = &This->owner->DirectDrawGlobal;
44 This->Global.wHeight = This->owner->Height;
45 This->Global.wWidth = This->owner->Width;
46 This->Global.dwLinearSize = This->Global.wWidth * This->owner->Bpp/8;
47
48 /* surface more struct */
49 memset(&This->More, 0, sizeof(DDRAWI_DDRAWSURFACE_MORE));
50 This->More.dwSize = sizeof(DDRAWI_DDRAWSURFACE_MORE);
51
52 /* surface local struct */
53 memset(&This->Local, 0, sizeof(DDRAWI_DDRAWSURFACE_LCL));
54 This->Local.lpGbl = &This->Global;
55 This->Local.lpSurfMore = &This->More;
56 This->Local.ddsCaps = *(DDSCAPS*)&pDDSD->ddsCaps;
57
58 /* we need to set some flags if we create the primary surface */
59 if(pDDSD->ddsCaps.dwCaps == DDSCAPS_PRIMARYSURFACE)
60 {
61 This->Local.dwFlags |= DDRAWISURF_FRONTBUFFER;
62 This->Global.dwGlobalFlags |= DDRAWISURFGBL_ISGDISURFACE;
63 }
64
65 /* for the double pointer below */
66 DDRAWI_DDRAWSURFACE_LCL *pLocal[2];
67 pLocal[0] = &This->Local;
68 pLocal[1] = NULL; // we need this one for bad written drivers
69
70 /* the parameter struct */
71 DDHAL_CREATESURFACEDATA CreateData;
72 memset(&CreateData, 0, sizeof(DDHAL_CREATESURFACEDATA));
73 CreateData.lpDD = &This->owner->DirectDrawGlobal;
74 CreateData.lpDDSurfaceDesc = (DDSURFACEDESC*)pDDSD;
75 CreateData.dwSCnt = 1;
76 CreateData.lplpSList = pLocal;
77
78 /* this is the call we were waiting for */
79 if(This->owner->DirectDrawGlobal.lpDDCBtmp->HALDD.CreateSurface(&CreateData) == DDHAL_DRIVER_NOTHANDLED)
80 return DDERR_INVALIDPARAMS;
81
82 if(CreateData.ddRVal != DD_OK)
83 return CreateData.ddRVal;
84
85 OutputDebugString(L"This does not get hit :( ");
86 OutputDebugString(L"Yet ;)");
87
88 return DD_OK;
89 }
90
91 ULONG WINAPI Main_DDrawSurface_AddRef(LPDIRECTDRAWSURFACE7 iface)
92 {
93 IDirectDrawSurfaceImpl* This = (IDirectDrawSurfaceImpl*)iface;
94
95 return InterlockedIncrement((PLONG)&This->owner->DirectDrawGlobal.dsList->dwIntRefCnt);
96 }
97
98 ULONG WINAPI Main_DDrawSurface_Release(LPDIRECTDRAWSURFACE7 iface)
99 {
100 IDirectDrawSurfaceImpl* This = (IDirectDrawSurfaceImpl*)iface;
101 ULONG ref = InterlockedDecrement((PLONG)&This->owner->DirectDrawGlobal.dsList->dwIntRefCnt);
102
103 if (ref == 0)
104 HeapFree(GetProcessHeap(), 0, This);
105
106 return ref;
107 }
108
109 /**** Stubs ****/
110
111 HRESULT WINAPI
112 Main_DDrawSurface_QueryInterface(LPDIRECTDRAWSURFACE7 iface, REFIID riid,
113 LPVOID* ppObj)
114 {
115 return E_NOINTERFACE;
116 }
117
118 HRESULT WINAPI Main_DDrawSurface_Blt(LPDIRECTDRAWSURFACE7 iface, LPRECT rdst,
119 LPDIRECTDRAWSURFACE7 src, LPRECT rsrc, DWORD dwFlags, LPDDBLTFX lpbltfx)
120 {
121 IDirectDrawImpl* This = (IDirectDrawImpl*)iface;
122
123 if (This->DirectDrawGlobal.lpDDCBtmp->HALDD.dwFlags & DDHAL_CB32_FLIPTOGDISURFACE)
124 {
125 return Hal_DDrawSurface_Blt( iface, rdst, src, rsrc, dwFlags, lpbltfx);
126 }
127
128 return Hel_DDrawSurface_Blt( iface, rdst, src, rsrc, dwFlags, lpbltfx);
129 }
130
131
132 HRESULT WINAPI Main_DDrawSurface_Lock (LPDIRECTDRAWSURFACE7 iface, LPRECT prect,
133 LPDDSURFACEDESC2 pDDSD, DWORD flags, HANDLE event)
134 {
135 DX_STUB;
136 }
137
138 HRESULT WINAPI Main_DDrawSurface_Unlock (LPDIRECTDRAWSURFACE7 iface, LPRECT pRect)
139 {
140 DX_STUB;
141 }
142
143 HRESULT WINAPI
144 Main_DDrawSurface_AddAttachedSurface(LPDIRECTDRAWSURFACE7 iface,
145 LPDIRECTDRAWSURFACE7 pAttach)
146 {
147 DX_STUB;
148 }
149
150 /* MSDN: "not currently implemented." */
151 HRESULT WINAPI
152 Main_DDrawSurface_AddOverlayDirtyRect(LPDIRECTDRAWSURFACE7 iface,
153 LPRECT pRect)
154 {
155 DX_STUB;
156 }
157
158 HRESULT WINAPI
159 Main_DDrawSurface_BltFast(LPDIRECTDRAWSURFACE7 iface, DWORD dstx,
160 DWORD dsty, LPDIRECTDRAWSURFACE7 src,
161 LPRECT rsrc, DWORD trans)
162 {
163 DX_STUB;
164 }
165
166 HRESULT WINAPI
167 Main_DDrawSurface_Restore(LPDIRECTDRAWSURFACE7 iface)
168 {
169 DX_STUB;
170 }
171
172 /* MSDN: "not currently implemented." */
173 HRESULT WINAPI
174 Main_DDrawSurface_BltBatch(LPDIRECTDRAWSURFACE7 iface,
175 LPDDBLTBATCH pBatch, DWORD dwCount,
176 DWORD dwFlags)
177 {
178 DX_STUB;
179 }
180
181 HRESULT WINAPI
182 Main_DDrawSurface_ChangeUniquenessValue(LPDIRECTDRAWSURFACE7 iface)
183 {
184 DX_STUB;
185 }
186
187 HRESULT WINAPI
188 Main_DDrawSurface_DeleteAttachedSurface(LPDIRECTDRAWSURFACE7 iface,
189 DWORD dwFlags,
190 LPDIRECTDRAWSURFACE7 pAttach)
191 {
192 DX_STUB;
193 }
194
195 HRESULT WINAPI
196 Main_DDrawSurface_EnumAttachedSurfaces(LPDIRECTDRAWSURFACE7 iface,
197 LPVOID context,
198 LPDDENUMSURFACESCALLBACK7 cb)
199 {
200 DX_STUB;
201 }
202
203 HRESULT WINAPI
204 Main_DDrawSurface_EnumOverlayZOrders(LPDIRECTDRAWSURFACE7 iface,
205 DWORD dwFlags, LPVOID context,
206 LPDDENUMSURFACESCALLBACK7 cb)
207 {
208 DX_STUB;
209 }
210
211 HRESULT WINAPI
212 Main_DDrawSurface_Flip(LPDIRECTDRAWSURFACE7 iface,
213 LPDIRECTDRAWSURFACE7 override, DWORD dwFlags)
214 {
215 DX_STUB;
216 }
217
218 HRESULT WINAPI
219 Main_DDrawSurface_FreePrivateData(LPDIRECTDRAWSURFACE7 iface, REFGUID tag)
220 {
221 DX_STUB;
222 }
223
224 HRESULT WINAPI
225 Main_DDrawSurface_GetAttachedSurface(LPDIRECTDRAWSURFACE7 iface,
226 LPDDSCAPS2 pCaps,
227 LPDIRECTDRAWSURFACE7* ppSurface)
228 {
229 DX_STUB;
230 }
231
232 HRESULT WINAPI
233 Main_DDrawSurface_GetBltStatus(LPDIRECTDRAWSURFACE7 iface, DWORD dwFlags)
234 {
235 DX_STUB;
236 }
237
238 HRESULT WINAPI
239 Main_DDrawSurface_GetCaps(LPDIRECTDRAWSURFACE7 iface, LPDDSCAPS2 pCaps)
240 {
241 DX_STUB;
242 }
243
244 HRESULT WINAPI
245 Main_DDrawSurface_GetClipper(LPDIRECTDRAWSURFACE7 iface,
246 LPDIRECTDRAWCLIPPER* ppClipper)
247 {
248 DX_STUB;
249 }
250
251 HRESULT WINAPI
252 Main_DDrawSurface_GetColorKey(LPDIRECTDRAWSURFACE7 iface, DWORD dwFlags,
253 LPDDCOLORKEY pCKey)
254 {
255 DX_STUB;
256 }
257
258 HRESULT WINAPI
259 Main_DDrawSurface_GetDC(LPDIRECTDRAWSURFACE7 iface, HDC *phDC)
260 {
261 DX_STUB;
262 }
263
264 HRESULT WINAPI
265 Main_DDrawSurface_GetDDInterface(LPDIRECTDRAWSURFACE7 iface, LPVOID* pDD)
266 {
267 DX_STUB;
268 }
269 HRESULT WINAPI
270 Main_DDrawSurface_GetFlipStatus(LPDIRECTDRAWSURFACE7 iface, DWORD dwFlags)
271 {
272 DX_STUB;
273 }
274
275 HRESULT WINAPI
276 Main_DDrawSurface_GetLOD(LPDIRECTDRAWSURFACE7 iface, LPDWORD pdwMaxLOD)
277 {
278 DX_STUB;
279 }
280
281 HRESULT WINAPI
282 Main_DDrawSurface_GetOverlayPosition(LPDIRECTDRAWSURFACE7 iface,
283 LPLONG pX, LPLONG pY)
284 {
285 DX_STUB;
286 }
287 HRESULT WINAPI
288 Main_DDrawSurface_GetPalette(LPDIRECTDRAWSURFACE7 iface,
289 LPDIRECTDRAWPALETTE* ppPalette)
290 {
291 DX_STUB;
292 }
293
294 HRESULT WINAPI
295 Main_DDrawSurface_GetPixelFormat(LPDIRECTDRAWSURFACE7 iface,
296 LPDDPIXELFORMAT pDDPixelFormat)
297 {
298 DX_STUB;
299 }
300
301 HRESULT WINAPI
302 Main_DDrawSurface_GetPriority(LPDIRECTDRAWSURFACE7 iface,
303 LPDWORD pdwPriority)
304 {
305 DX_STUB;
306 }
307
308 HRESULT WINAPI
309 Main_DDrawSurface_GetPrivateData(LPDIRECTDRAWSURFACE7 iface,
310 REFGUID tag, LPVOID pBuffer,
311 LPDWORD pcbBufferSize)
312 {
313 DX_STUB;
314 }
315
316 HRESULT WINAPI
317 Main_DDrawSurface_GetSurfaceDesc(LPDIRECTDRAWSURFACE7 iface,
318 LPDDSURFACEDESC2 pDDSD)
319 {
320 DX_STUB;
321 }
322
323 HRESULT WINAPI
324 Main_DDrawSurface_GetUniquenessValue(LPDIRECTDRAWSURFACE7 iface,
325 LPDWORD pValue)
326 {
327 DX_STUB;
328 }
329
330 HRESULT WINAPI
331 Main_DDrawSurface_IsLost(LPDIRECTDRAWSURFACE7 iface)
332 {
333 DX_STUB;
334 }
335
336 HRESULT WINAPI
337 Main_DDrawSurface_PageLock(LPDIRECTDRAWSURFACE7 iface, DWORD dwFlags)
338 {
339 DX_STUB;
340 }
341
342 HRESULT WINAPI
343 Main_DDrawSurface_PageUnlock(LPDIRECTDRAWSURFACE7 iface, DWORD dwFlags)
344 {
345 DX_STUB;
346 }
347
348 HRESULT WINAPI
349 Main_DDrawSurface_ReleaseDC(LPDIRECTDRAWSURFACE7 iface, HDC hDC)
350 {
351 DX_STUB;
352 }
353
354 HRESULT WINAPI
355 Main_DDrawSurface_SetClipper (LPDIRECTDRAWSURFACE7 iface,
356 LPDIRECTDRAWCLIPPER pDDClipper)
357 {
358 DX_STUB;
359 }
360
361 HRESULT WINAPI
362 Main_DDrawSurface_SetColorKey (LPDIRECTDRAWSURFACE7 iface,
363 DWORD dwFlags, LPDDCOLORKEY pCKey)
364 {
365 DX_STUB;
366 }
367
368 HRESULT WINAPI
369 Main_DDrawSurface_SetLOD (LPDIRECTDRAWSURFACE7 iface, DWORD dwMaxLOD)
370 {
371 DX_STUB;
372 }
373
374 HRESULT WINAPI
375 Main_DDrawSurface_SetOverlayPosition (LPDIRECTDRAWSURFACE7 iface,
376 LONG X, LONG Y)
377 {
378 DX_STUB;
379 }
380
381 HRESULT WINAPI
382 Main_DDrawSurface_SetPalette (LPDIRECTDRAWSURFACE7 iface,
383 LPDIRECTDRAWPALETTE pPalette)
384 {
385 DX_STUB;
386 }
387
388 HRESULT WINAPI
389 Main_DDrawSurface_SetPriority (LPDIRECTDRAWSURFACE7 iface,
390 DWORD dwPriority)
391 {
392 DX_STUB;
393 }
394
395 HRESULT WINAPI
396 Main_DDrawSurface_SetPrivateData (LPDIRECTDRAWSURFACE7 iface,
397 REFGUID tag, LPVOID pData,
398 DWORD cbSize, DWORD dwFlags)
399 {
400 DX_STUB;
401 }
402
403 HRESULT WINAPI
404 Main_DDrawSurface_UpdateOverlay (LPDIRECTDRAWSURFACE7 iface,
405 LPRECT pSrcRect,
406 LPDIRECTDRAWSURFACE7 pDstSurface,
407 LPRECT pDstRect, DWORD dwFlags,
408 LPDDOVERLAYFX pFX)
409 {
410 DX_STUB;
411 }
412
413 /* MSDN: "not currently implemented." */
414 HRESULT WINAPI
415 Main_DDrawSurface_UpdateOverlayDisplay (LPDIRECTDRAWSURFACE7 iface,
416 DWORD dwFlags)
417 {
418 DX_STUB;
419 }
420
421 HRESULT WINAPI Main_DDrawSurface_UpdateOverlayZOrder (LPDIRECTDRAWSURFACE7 iface,
422 DWORD dwFlags, LPDIRECTDRAWSURFACE7 pDDSRef)
423 {
424 DX_STUB;
425 }
426
427 IDirectDrawSurface7Vtbl DirectDrawSurface7_Vtable =
428 {
429 Main_DDrawSurface_QueryInterface,
430 Main_DDrawSurface_AddRef,
431 Main_DDrawSurface_Release,
432 Main_DDrawSurface_AddAttachedSurface,
433 Main_DDrawSurface_AddOverlayDirtyRect,
434 Main_DDrawSurface_Blt,
435 Main_DDrawSurface_BltBatch,
436 Main_DDrawSurface_BltFast,
437 Main_DDrawSurface_DeleteAttachedSurface,
438 Main_DDrawSurface_EnumAttachedSurfaces,
439 Main_DDrawSurface_EnumOverlayZOrders,
440 Main_DDrawSurface_Flip,
441 Main_DDrawSurface_GetAttachedSurface,
442 Main_DDrawSurface_GetBltStatus,
443 Main_DDrawSurface_GetCaps,
444 Main_DDrawSurface_GetClipper,
445 Main_DDrawSurface_GetColorKey,
446 Main_DDrawSurface_GetDC,
447 Main_DDrawSurface_GetFlipStatus,
448 Main_DDrawSurface_GetOverlayPosition,
449 Main_DDrawSurface_GetPalette,
450 Main_DDrawSurface_GetPixelFormat,
451 Main_DDrawSurface_GetSurfaceDesc,
452 Main_DDrawSurface_Initialize,
453 Main_DDrawSurface_IsLost,
454 Main_DDrawSurface_Lock,
455 Main_DDrawSurface_ReleaseDC,
456 Main_DDrawSurface_Restore,
457 Main_DDrawSurface_SetClipper,
458 Main_DDrawSurface_SetColorKey,
459 Main_DDrawSurface_SetOverlayPosition,
460 Main_DDrawSurface_SetPalette,
461 Main_DDrawSurface_Unlock,
462 Main_DDrawSurface_UpdateOverlay,
463 Main_DDrawSurface_UpdateOverlayDisplay,
464 Main_DDrawSurface_UpdateOverlayZOrder
465 };