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