da62043437a3a44165eb66072ae0255a508b48f9
[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 return InterlockedIncrement(&This->ref);
98 }
99
100 ULONG WINAPI Main_DDrawSurface_Release(LPDIRECTDRAWSURFACE7 iface)
101 {
102 IDirectDrawSurfaceImpl* This = (IDirectDrawSurfaceImpl*)iface;
103 ULONG ref = InterlockedDecrement(&This->ref);
104
105 if (ref == 0)
106 HeapFree(GetProcessHeap(), 0, This);
107
108 return ref;
109 }
110
111 /**** Stubs ****/
112
113 HRESULT WINAPI
114 Main_DDrawSurface_QueryInterface(LPDIRECTDRAWSURFACE7 iface, REFIID riid,
115 LPVOID* ppObj)
116 {
117 return E_NOINTERFACE;
118 }
119
120 HRESULT WINAPI Main_DDrawSurface_Blt(LPDIRECTDRAWSURFACE7 iface, LPRECT rdst,
121 LPDIRECTDRAWSURFACE7 src, LPRECT rsrc, DWORD dwFlags, LPDDBLTFX lpbltfx)
122 {
123 IDirectDrawImpl* This = (IDirectDrawImpl*)iface;
124
125 if (This->DirectDrawGlobal.lpDDCBtmp->HALDD.dwFlags & DDHAL_CB32_FLIPTOGDISURFACE)
126 {
127 return Hal_DDrawSurface_Blt( iface, rdst, src, rsrc, dwFlags, lpbltfx);
128 }
129
130 return Hel_DDrawSurface_Blt( iface, rdst, src, rsrc, dwFlags, lpbltfx);
131 }
132
133
134 HRESULT WINAPI Main_DDrawSurface_Lock (LPDIRECTDRAWSURFACE7 iface, LPRECT prect,
135 LPDDSURFACEDESC2 pDDSD, DWORD flags, HANDLE event)
136 {
137 DX_STUB;
138 }
139
140 HRESULT WINAPI Main_DDrawSurface_Unlock (LPDIRECTDRAWSURFACE7 iface, LPRECT pRect)
141 {
142 DX_STUB;
143 }
144
145 HRESULT WINAPI
146 Main_DDrawSurface_AddAttachedSurface(LPDIRECTDRAWSURFACE7 iface,
147 LPDIRECTDRAWSURFACE7 pAttach)
148 {
149 DX_STUB;
150 }
151
152 /* MSDN: "not currently implemented." */
153 HRESULT WINAPI
154 Main_DDrawSurface_AddOverlayDirtyRect(LPDIRECTDRAWSURFACE7 iface,
155 LPRECT pRect)
156 {
157 DX_STUB;
158 }
159
160 HRESULT WINAPI
161 Main_DDrawSurface_BltFast(LPDIRECTDRAWSURFACE7 iface, DWORD dstx,
162 DWORD dsty, LPDIRECTDRAWSURFACE7 src,
163 LPRECT rsrc, DWORD trans)
164 {
165 DX_STUB;
166 }
167
168 HRESULT WINAPI
169 Main_DDrawSurface_Restore(LPDIRECTDRAWSURFACE7 iface)
170 {
171 DX_STUB;
172 }
173
174 /* MSDN: "not currently implemented." */
175 HRESULT WINAPI
176 Main_DDrawSurface_BltBatch(LPDIRECTDRAWSURFACE7 iface,
177 LPDDBLTBATCH pBatch, DWORD dwCount,
178 DWORD dwFlags)
179 {
180 DX_STUB;
181 }
182
183 HRESULT WINAPI
184 Main_DDrawSurface_ChangeUniquenessValue(LPDIRECTDRAWSURFACE7 iface)
185 {
186 DX_STUB;
187 }
188
189 HRESULT WINAPI
190 Main_DDrawSurface_DeleteAttachedSurface(LPDIRECTDRAWSURFACE7 iface,
191 DWORD dwFlags,
192 LPDIRECTDRAWSURFACE7 pAttach)
193 {
194 DX_STUB;
195 }
196
197 HRESULT WINAPI
198 Main_DDrawSurface_EnumAttachedSurfaces(LPDIRECTDRAWSURFACE7 iface,
199 LPVOID context,
200 LPDDENUMSURFACESCALLBACK7 cb)
201 {
202 DX_STUB;
203 }
204
205 HRESULT WINAPI
206 Main_DDrawSurface_EnumOverlayZOrders(LPDIRECTDRAWSURFACE7 iface,
207 DWORD dwFlags, LPVOID context,
208 LPDDENUMSURFACESCALLBACK7 cb)
209 {
210 DX_STUB;
211 }
212
213 HRESULT WINAPI
214 Main_DDrawSurface_Flip(LPDIRECTDRAWSURFACE7 iface,
215 LPDIRECTDRAWSURFACE7 override, DWORD dwFlags)
216 {
217 DX_STUB;
218 }
219
220 HRESULT WINAPI
221 Main_DDrawSurface_FreePrivateData(LPDIRECTDRAWSURFACE7 iface, REFGUID tag)
222 {
223 DX_STUB;
224 }
225
226 HRESULT WINAPI
227 Main_DDrawSurface_GetAttachedSurface(LPDIRECTDRAWSURFACE7 iface,
228 LPDDSCAPS2 pCaps,
229 LPDIRECTDRAWSURFACE7* ppSurface)
230 {
231 DX_STUB;
232 }
233
234 HRESULT WINAPI
235 Main_DDrawSurface_GetBltStatus(LPDIRECTDRAWSURFACE7 iface, DWORD dwFlags)
236 {
237 DX_STUB;
238 }
239
240 HRESULT WINAPI
241 Main_DDrawSurface_GetCaps(LPDIRECTDRAWSURFACE7 iface, LPDDSCAPS2 pCaps)
242 {
243 DX_STUB;
244 }
245
246 HRESULT WINAPI
247 Main_DDrawSurface_GetClipper(LPDIRECTDRAWSURFACE7 iface,
248 LPDIRECTDRAWCLIPPER* ppClipper)
249 {
250 DX_STUB;
251 }
252
253 HRESULT WINAPI
254 Main_DDrawSurface_GetColorKey(LPDIRECTDRAWSURFACE7 iface, DWORD dwFlags,
255 LPDDCOLORKEY pCKey)
256 {
257 DX_STUB;
258 }
259
260 HRESULT WINAPI
261 Main_DDrawSurface_GetDC(LPDIRECTDRAWSURFACE7 iface, HDC *phDC)
262 {
263 DX_STUB;
264 }
265
266 HRESULT WINAPI
267 Main_DDrawSurface_GetDDInterface(LPDIRECTDRAWSURFACE7 iface, LPVOID* pDD)
268 {
269 DX_STUB;
270 }
271 HRESULT WINAPI
272 Main_DDrawSurface_GetFlipStatus(LPDIRECTDRAWSURFACE7 iface, DWORD dwFlags)
273 {
274 DX_STUB;
275 }
276
277 HRESULT WINAPI
278 Main_DDrawSurface_GetLOD(LPDIRECTDRAWSURFACE7 iface, LPDWORD pdwMaxLOD)
279 {
280 DX_STUB;
281 }
282
283 HRESULT WINAPI
284 Main_DDrawSurface_GetOverlayPosition(LPDIRECTDRAWSURFACE7 iface,
285 LPLONG pX, LPLONG pY)
286 {
287 DX_STUB;
288 }
289 HRESULT WINAPI
290 Main_DDrawSurface_GetPalette(LPDIRECTDRAWSURFACE7 iface,
291 LPDIRECTDRAWPALETTE* ppPalette)
292 {
293 DX_STUB;
294 }
295
296 HRESULT WINAPI
297 Main_DDrawSurface_GetPixelFormat(LPDIRECTDRAWSURFACE7 iface,
298 LPDDPIXELFORMAT pDDPixelFormat)
299 {
300 DX_STUB;
301 }
302
303 HRESULT WINAPI
304 Main_DDrawSurface_GetPriority(LPDIRECTDRAWSURFACE7 iface,
305 LPDWORD pdwPriority)
306 {
307 DX_STUB;
308 }
309
310 HRESULT WINAPI
311 Main_DDrawSurface_GetPrivateData(LPDIRECTDRAWSURFACE7 iface,
312 REFGUID tag, LPVOID pBuffer,
313 LPDWORD pcbBufferSize)
314 {
315 DX_STUB;
316 }
317
318 HRESULT WINAPI
319 Main_DDrawSurface_GetSurfaceDesc(LPDIRECTDRAWSURFACE7 iface,
320 LPDDSURFACEDESC2 pDDSD)
321 {
322 DX_STUB;
323 }
324
325 HRESULT WINAPI
326 Main_DDrawSurface_GetUniquenessValue(LPDIRECTDRAWSURFACE7 iface,
327 LPDWORD pValue)
328 {
329 DX_STUB;
330 }
331
332 HRESULT WINAPI
333 Main_DDrawSurface_IsLost(LPDIRECTDRAWSURFACE7 iface)
334 {
335 DX_STUB;
336 }
337
338 HRESULT WINAPI
339 Main_DDrawSurface_PageLock(LPDIRECTDRAWSURFACE7 iface, DWORD dwFlags)
340 {
341 DX_STUB;
342 }
343
344 HRESULT WINAPI
345 Main_DDrawSurface_PageUnlock(LPDIRECTDRAWSURFACE7 iface, DWORD dwFlags)
346 {
347 DX_STUB;
348 }
349
350 HRESULT WINAPI
351 Main_DDrawSurface_ReleaseDC(LPDIRECTDRAWSURFACE7 iface, HDC hDC)
352 {
353 DX_STUB;
354 }
355
356 HRESULT WINAPI
357 Main_DDrawSurface_SetClipper (LPDIRECTDRAWSURFACE7 iface,
358 LPDIRECTDRAWCLIPPER pDDClipper)
359 {
360 DX_STUB;
361 }
362
363 HRESULT WINAPI
364 Main_DDrawSurface_SetColorKey (LPDIRECTDRAWSURFACE7 iface,
365 DWORD dwFlags, LPDDCOLORKEY pCKey)
366 {
367 DX_STUB;
368 }
369
370 HRESULT WINAPI
371 Main_DDrawSurface_SetLOD (LPDIRECTDRAWSURFACE7 iface, DWORD dwMaxLOD)
372 {
373 DX_STUB;
374 }
375
376 HRESULT WINAPI
377 Main_DDrawSurface_SetOverlayPosition (LPDIRECTDRAWSURFACE7 iface,
378 LONG X, LONG Y)
379 {
380 DX_STUB;
381 }
382
383 HRESULT WINAPI
384 Main_DDrawSurface_SetPalette (LPDIRECTDRAWSURFACE7 iface,
385 LPDIRECTDRAWPALETTE pPalette)
386 {
387 DX_STUB;
388 }
389
390 HRESULT WINAPI
391 Main_DDrawSurface_SetPriority (LPDIRECTDRAWSURFACE7 iface,
392 DWORD dwPriority)
393 {
394 DX_STUB;
395 }
396
397 HRESULT WINAPI
398 Main_DDrawSurface_SetPrivateData (LPDIRECTDRAWSURFACE7 iface,
399 REFGUID tag, LPVOID pData,
400 DWORD cbSize, DWORD dwFlags)
401 {
402 DX_STUB;
403 }
404
405 HRESULT WINAPI
406 Main_DDrawSurface_UpdateOverlay (LPDIRECTDRAWSURFACE7 iface,
407 LPRECT pSrcRect,
408 LPDIRECTDRAWSURFACE7 pDstSurface,
409 LPRECT pDstRect, DWORD dwFlags,
410 LPDDOVERLAYFX pFX)
411 {
412 DX_STUB;
413 }
414
415 /* MSDN: "not currently implemented." */
416 HRESULT WINAPI
417 Main_DDrawSurface_UpdateOverlayDisplay (LPDIRECTDRAWSURFACE7 iface,
418 DWORD dwFlags)
419 {
420 DX_STUB;
421 }
422
423 HRESULT WINAPI Main_DDrawSurface_UpdateOverlayZOrder (LPDIRECTDRAWSURFACE7 iface,
424 DWORD dwFlags, LPDIRECTDRAWSURFACE7 pDDSRef)
425 {
426 DX_STUB;
427 }
428
429 IDirectDrawSurface7Vtbl DirectDrawSurface7_Vtable =
430 {
431 Main_DDrawSurface_QueryInterface,
432 Main_DDrawSurface_AddRef,
433 Main_DDrawSurface_Release,
434 Main_DDrawSurface_AddAttachedSurface,
435 Main_DDrawSurface_AddOverlayDirtyRect,
436 Main_DDrawSurface_Blt,
437 Main_DDrawSurface_BltBatch,
438 Main_DDrawSurface_BltFast,
439 Main_DDrawSurface_DeleteAttachedSurface,
440 Main_DDrawSurface_EnumAttachedSurfaces,
441 Main_DDrawSurface_EnumOverlayZOrders,
442 Main_DDrawSurface_Flip,
443 Main_DDrawSurface_GetAttachedSurface,
444 Main_DDrawSurface_GetBltStatus,
445 Main_DDrawSurface_GetCaps,
446 Main_DDrawSurface_GetClipper,
447 Main_DDrawSurface_GetColorKey,
448 Main_DDrawSurface_GetDC,
449 Main_DDrawSurface_GetFlipStatus,
450 Main_DDrawSurface_GetOverlayPosition,
451 Main_DDrawSurface_GetPalette,
452 Main_DDrawSurface_GetPixelFormat,
453 Main_DDrawSurface_GetSurfaceDesc,
454 Main_DDrawSurface_Initialize,
455 Main_DDrawSurface_IsLost,
456 Main_DDrawSurface_Lock,
457 Main_DDrawSurface_ReleaseDC,
458 Main_DDrawSurface_Restore,
459 Main_DDrawSurface_SetClipper,
460 Main_DDrawSurface_SetColorKey,
461 Main_DDrawSurface_SetOverlayPosition,
462 Main_DDrawSurface_SetPalette,
463 Main_DDrawSurface_Unlock,
464 Main_DDrawSurface_UpdateOverlay,
465 Main_DDrawSurface_UpdateOverlayDisplay,
466 Main_DDrawSurface_UpdateOverlayZOrder
467 };