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