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