ddraw: Get rid of ICOM_OBJECT.
[wine] / dlls / ddraw / surface_thunks.c
1 /* IDirectDrawSurface3 -> IDirectDrawSurface7 thunks
2  * Copyright 2000 TransGaming Technologies Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include "config.h"
20 #include "wine/port.h"
21 #include "wine/debug.h"
22 #include <stdarg.h>
23 #include <assert.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "ddraw.h"
29 #include "winerror.h"
30
31 #include "ddraw_private.h"
32 #include "ddcomimpl.h"
33
34 #define CONVERT(pdds) COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,        \
35                                          IDirectDrawSurface3,           \
36                                          IDirectDrawSurface7,           \
37                                          (pdds))
38
39 #define CONVERT_REV(pdds) COM_INTERFACE_CAST(IDirectDrawSurfaceImpl,    \
40                                              IDirectDrawSurface7,       \
41                                              IDirectDrawSurface3,       \
42                                              (pdds))
43
44 WINE_DEFAULT_DEBUG_CHANNEL(ddraw_thunk);
45 WINE_DECLARE_DEBUG_CHANNEL(ddraw);
46
47 static inline IDirectDrawSurfaceImpl *surface_from_surface3(IDirectDrawSurface3 *iface)
48 {
49     return (IDirectDrawSurfaceImpl *)((char*)iface - FIELD_OFFSET(IDirectDrawSurfaceImpl, IDirectDrawSurface3_vtbl));
50 }
51
52 static HRESULT WINAPI
53 IDirectDrawSurface3Impl_QueryInterface(LPDIRECTDRAWSURFACE3 This, REFIID iid,
54                                        LPVOID *ppObj)
55 {
56     return IDirectDrawSurface7_QueryInterface(CONVERT(This), iid, ppObj);
57 }
58
59 static ULONG WINAPI
60 IDirectDrawSurface3Impl_AddRef(LPDIRECTDRAWSURFACE3 This)
61 {
62     return IDirectDrawSurface7_AddRef(CONVERT(This));
63 }
64
65 static ULONG WINAPI
66 IDirectDrawSurface3Impl_Release(LPDIRECTDRAWSURFACE3 iface)
67 {
68     IDirectDrawSurfaceImpl *This = surface_from_surface3(iface);
69     TRACE("(%p)\n", This);
70     return IDirectDrawSurface7_Release(CONVERT(iface));
71 }
72
73 static HRESULT WINAPI
74 IDirectDrawSurface3Impl_AddAttachedSurface(LPDIRECTDRAWSURFACE3 iface,
75                                            LPDIRECTDRAWSURFACE3 pAttach)
76 {
77     IDirectDrawSurfaceImpl *This = surface_from_surface3(iface);
78     IDirectDrawSurfaceImpl *Surf = surface_from_surface3(pAttach);
79     TRACE("(%p)->(%p)\n", This, Surf);
80
81     /* Tests suggest that
82      * -> offscreen plain surfaces can be attached to other offscreen plain surfaces
83      * -> offscreen plain surfaces can be attached to primaries
84      * -> primaries can be attached to offscreen plain surfaces
85      * -> z buffers can be attached to primaries
86      *
87      */
88     if(This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE | DDSCAPS_OFFSCREENPLAIN) &&
89        Surf->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE | DDSCAPS_OFFSCREENPLAIN))
90     {
91         /* Sizes have to match */
92         if(Surf->surface_desc.dwWidth != This->surface_desc.dwWidth ||
93         Surf->surface_desc.dwHeight != This->surface_desc.dwHeight)
94         {
95             WARN("Surface sizes do not match\n");
96             return DDERR_CANNOTATTACHSURFACE;
97         }
98         /* OK */
99     }
100     else if(This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE) &&
101             Surf->surface_desc.ddsCaps.dwCaps & (DDSCAPS_ZBUFFER))
102     {
103         /* OK */
104     }
105     else
106     {
107         WARN("Invalid attachment combination\n");
108         return DDERR_CANNOTATTACHSURFACE;
109     }
110
111     return IDirectDrawSurfaceImpl_AddAttachedSurface(This,
112                                                      Surf);
113 }
114
115 static HRESULT WINAPI
116 IDirectDrawSurface3Impl_AddOverlayDirtyRect(LPDIRECTDRAWSURFACE3 This,
117                                             LPRECT pRect)
118 {
119     return IDirectDrawSurface7_AddOverlayDirtyRect(CONVERT(This), pRect);
120 }
121
122 static HRESULT WINAPI
123 IDirectDrawSurface3Impl_Blt(LPDIRECTDRAWSURFACE3 This, LPRECT prcDst,
124                             LPDIRECTDRAWSURFACE3 pSrcSurf, LPRECT prcSrc,
125                             DWORD dwFlags, LPDDBLTFX pFX)
126 {
127     return IDirectDrawSurface7_Blt(CONVERT(This), prcDst, CONVERT(pSrcSurf),
128                                    prcSrc, dwFlags, pFX);
129 }
130
131 static HRESULT WINAPI
132 IDirectDrawSurface3Impl_BltBatch(LPDIRECTDRAWSURFACE3 This,
133                                  LPDDBLTBATCH pBatch, DWORD dwCount,
134                                  DWORD dwFlags)
135 {
136     return IDirectDrawSurface7_BltBatch(CONVERT(This), pBatch, dwCount,
137                                         dwFlags);
138 }
139
140 static HRESULT WINAPI
141 IDirectDrawSurface3Impl_BltFast(LPDIRECTDRAWSURFACE3 This, DWORD x, DWORD y,
142                                 LPDIRECTDRAWSURFACE3 pSrcSurf, LPRECT prcSrc,
143                                 DWORD dwTrans)
144 {
145     return IDirectDrawSurface7_BltFast(CONVERT(This), x, y, CONVERT(pSrcSurf),
146                                        prcSrc, dwTrans);
147 }
148
149 static HRESULT WINAPI
150 IDirectDrawSurface3Impl_DeleteAttachedSurface(LPDIRECTDRAWSURFACE3 This,
151                                               DWORD dwFlags,
152                                               LPDIRECTDRAWSURFACE3 pAttached)
153 {
154     return IDirectDrawSurface7_DeleteAttachedSurface(CONVERT(This), dwFlags,
155                                                      CONVERT(pAttached));
156 }
157
158 struct callback_info
159 {
160     LPDDENUMSURFACESCALLBACK callback;
161     LPVOID context;
162 };
163
164 static HRESULT CALLBACK
165 EnumCallback(LPDIRECTDRAWSURFACE7 iface, LPDDSURFACEDESC2 pDDSD,
166              LPVOID context)
167 {
168     const struct callback_info* info = context;
169
170 #if 0
171     /* This is an outgoing conversion so we have to do it. */
172     DDSURFACEDESC ddsd;
173     memset(&ddsd, 0, sizeof(ddsd));
174     ddsd.dwSize = sizeof(ddsd);
175     DDRAW_Convert_DDSURFACEDESC_2_To_1(pDDSD, &ddsd);
176 #endif
177
178     /* the LPDDSURFACEDESC2 -> LPDDSURFACEDESC coercion is safe, since
179      * the data format is compatible with older enum procs */
180     return info->callback((LPDIRECTDRAWSURFACE)CONVERT_REV(iface), (LPDDSURFACEDESC)pDDSD,
181                           info->context);
182 }
183
184 static HRESULT WINAPI
185 IDirectDrawSurface3Impl_EnumAttachedSurfaces(LPDIRECTDRAWSURFACE3 This,
186                                              LPVOID context,
187                                              LPDDENUMSURFACESCALLBACK callback)
188 {
189     struct callback_info info;
190
191     info.callback = callback;
192     info.context  = context;
193
194     return IDirectDrawSurface7_EnumAttachedSurfaces(CONVERT(This), &info,
195                                                     EnumCallback);
196 }
197
198 static HRESULT WINAPI
199 IDirectDrawSurface3Impl_EnumOverlayZOrders(LPDIRECTDRAWSURFACE3 This,
200                                            DWORD dwFlags, LPVOID context,
201                                            LPDDENUMSURFACESCALLBACK callback)
202 {
203     struct callback_info info;
204
205     info.callback = callback;
206     info.context  = context;
207
208     return IDirectDrawSurface7_EnumOverlayZOrders(CONVERT(This), dwFlags,
209                                                   &info, EnumCallback);
210 }
211
212 static HRESULT WINAPI
213 IDirectDrawSurface3Impl_Flip(LPDIRECTDRAWSURFACE3 This,
214                              LPDIRECTDRAWSURFACE3 pOverride, DWORD dwFlags)
215 {
216     return IDirectDrawSurface7_Flip(CONVERT(This), CONVERT(pOverride),
217                                     dwFlags);
218 }
219
220 static HRESULT WINAPI
221 IDirectDrawSurface3Impl_GetAttachedSurface(LPDIRECTDRAWSURFACE3 This,
222                                            LPDDSCAPS pCaps,
223                                            LPDIRECTDRAWSURFACE3* ppAttached)
224 {
225     DDSCAPS2 caps;
226     LPDIRECTDRAWSURFACE7 pAttached7;
227     HRESULT hr;
228
229     caps.dwCaps  = pCaps->dwCaps;
230     caps.dwCaps2 = 0;
231     caps.dwCaps3 = 0;
232     caps.dwCaps4 = 0;
233
234     hr = IDirectDrawSurface7_GetAttachedSurface(CONVERT(This), &caps,
235                                                 &pAttached7);
236     if (FAILED(hr)) *ppAttached = NULL;
237     else *ppAttached = CONVERT_REV(pAttached7);
238     return hr;
239 }
240
241 static HRESULT WINAPI
242 IDirectDrawSurface3Impl_GetBltStatus(LPDIRECTDRAWSURFACE3 This, DWORD dwFlags)
243 {
244     return IDirectDrawSurface7_GetBltStatus(CONVERT(This), dwFlags);
245 }
246
247 static HRESULT WINAPI
248 IDirectDrawSurface3Impl_GetCaps(LPDIRECTDRAWSURFACE3 This, LPDDSCAPS pCaps)
249 {
250     DDSCAPS2 caps;
251     HRESULT hr;
252
253     hr = IDirectDrawSurface7_GetCaps(CONVERT(This), &caps);
254     if (FAILED(hr)) return hr;
255
256     pCaps->dwCaps = caps.dwCaps;
257     return hr;
258 }
259
260 static HRESULT WINAPI
261 IDirectDrawSurface3Impl_GetClipper(LPDIRECTDRAWSURFACE3 This,
262                                    LPDIRECTDRAWCLIPPER* ppClipper)
263 {
264     return IDirectDrawSurface7_GetClipper(CONVERT(This), ppClipper);
265 }
266
267 static HRESULT WINAPI
268 IDirectDrawSurface3Impl_GetColorKey(LPDIRECTDRAWSURFACE3 This, DWORD dwFlags,
269                                     LPDDCOLORKEY pCKey)
270 {
271     return IDirectDrawSurface7_GetColorKey(CONVERT(This), dwFlags, pCKey);
272 }
273
274 static HRESULT WINAPI
275 IDirectDrawSurface3Impl_GetDC(LPDIRECTDRAWSURFACE3 This, HDC* phDC)
276 {
277     return IDirectDrawSurface7_GetDC(CONVERT(This), phDC);
278 }
279
280 static HRESULT WINAPI
281 IDirectDrawSurface3Impl_GetFlipStatus(LPDIRECTDRAWSURFACE3 This, DWORD dwFlags)
282 {
283     return IDirectDrawSurface7_GetFlipStatus(CONVERT(This), dwFlags);
284 }
285
286 static HRESULT WINAPI
287 IDirectDrawSurface3Impl_GetOverlayPosition(LPDIRECTDRAWSURFACE3 This, LPLONG pX,
288                                        LPLONG pY)
289 {
290     return IDirectDrawSurface7_GetOverlayPosition(CONVERT(This), pX, pY);
291 }
292
293 static HRESULT WINAPI
294 IDirectDrawSurface3Impl_GetPalette(LPDIRECTDRAWSURFACE3 This,
295                                    LPDIRECTDRAWPALETTE* ppPalette)
296 {
297     return IDirectDrawSurface7_GetPalette(CONVERT(This), ppPalette);
298 }
299
300 static HRESULT WINAPI
301 IDirectDrawSurface3Impl_GetPixelFormat(LPDIRECTDRAWSURFACE3 This,
302                                        LPDDPIXELFORMAT pPixelFormat)
303 {
304     return IDirectDrawSurface7_GetPixelFormat(CONVERT(This), pPixelFormat);
305 }
306
307 static HRESULT WINAPI
308 IDirectDrawSurface3Impl_GetSurfaceDesc(LPDIRECTDRAWSURFACE3 iface,
309                                        LPDDSURFACEDESC pDDSD)
310 {
311     IDirectDrawSurfaceImpl *This = surface_from_surface3(iface);
312
313     TRACE_(ddraw)("(%p)->(%p)\n",This,pDDSD);
314
315     if(!pDDSD)
316         return DDERR_INVALIDPARAMS;
317
318     if (pDDSD->dwSize != sizeof(DDSURFACEDESC))
319     {
320         WARN("Incorrect struct size %d, returning DDERR_INVALIDPARAMS\n",pDDSD->dwSize);
321         return DDERR_INVALIDPARAMS;
322     }
323
324     EnterCriticalSection(&ddraw_cs);
325     DD_STRUCT_COPY_BYSIZE(pDDSD,(DDSURFACEDESC *) &This->surface_desc);
326     TRACE("Returning surface desc:\n");
327     if (TRACE_ON(ddraw))
328     {
329         /* DDRAW_dump_surface_desc handles the smaller size */
330         DDRAW_dump_surface_desc((DDSURFACEDESC2 *) pDDSD);
331     }
332
333     LeaveCriticalSection(&ddraw_cs);
334     return DD_OK;
335 }
336
337 static HRESULT WINAPI
338 IDirectDrawSurface3Impl_Initialize(LPDIRECTDRAWSURFACE3 This, LPDIRECTDRAW pDD,
339                                    LPDDSURFACEDESC pDDSD)
340 {
341     return IDirectDrawSurface7_Initialize(CONVERT(This), pDD,
342                                           (LPDDSURFACEDESC2)pDDSD);
343 }
344
345 static HRESULT WINAPI
346 IDirectDrawSurface3Impl_IsLost(LPDIRECTDRAWSURFACE3 This)
347 {
348     return IDirectDrawSurface7_IsLost(CONVERT(This));
349 }
350
351 static HRESULT WINAPI
352 IDirectDrawSurface3Impl_Lock(LPDIRECTDRAWSURFACE3 This, LPRECT pRect,
353                              LPDDSURFACEDESC pDDSD, DWORD dwFlags, HANDLE h)
354 {
355     return IDirectDrawSurface7_Lock(CONVERT(This), pRect,
356                                     (LPDDSURFACEDESC2)pDDSD, dwFlags, h);
357 }
358
359 static HRESULT WINAPI
360 IDirectDrawSurface3Impl_ReleaseDC(LPDIRECTDRAWSURFACE3 This, HDC hDC)
361 {
362     return IDirectDrawSurface7_ReleaseDC(CONVERT(This), hDC);
363 }
364
365 static HRESULT WINAPI
366 IDirectDrawSurface3Impl_Restore(LPDIRECTDRAWSURFACE3 This)
367 {
368     return IDirectDrawSurface7_Restore(CONVERT(This));
369 }
370
371 static HRESULT WINAPI
372 IDirectDrawSurface3Impl_SetClipper(LPDIRECTDRAWSURFACE3 This,
373                                    LPDIRECTDRAWCLIPPER pClipper)
374 {
375     return IDirectDrawSurface7_SetClipper(CONVERT(This), pClipper);
376 }
377
378 static HRESULT WINAPI
379 IDirectDrawSurface3Impl_SetColorKey(LPDIRECTDRAWSURFACE3 This, DWORD dwFlags,
380                                     LPDDCOLORKEY pCKey)
381 {
382     return IDirectDrawSurface7_SetColorKey(CONVERT(This), dwFlags, pCKey);
383 }
384
385 static HRESULT WINAPI
386 IDirectDrawSurface3Impl_SetOverlayPosition(LPDIRECTDRAWSURFACE3 This, LONG x,
387                                        LONG y)
388 {
389     return IDirectDrawSurface7_SetOverlayPosition(CONVERT(This), x, y);
390 }
391
392 static HRESULT WINAPI
393 IDirectDrawSurface3Impl_SetPalette(LPDIRECTDRAWSURFACE3 This,
394                                    LPDIRECTDRAWPALETTE pPalette)
395 {
396     return IDirectDrawSurface7_SetPalette(CONVERT(This), pPalette);
397 }
398
399 static HRESULT WINAPI
400 IDirectDrawSurface3Impl_Unlock(LPDIRECTDRAWSURFACE3 This, LPVOID data)
401 {
402     /* data might not be the LPRECT of later versions, so drop it. */
403     return IDirectDrawSurface7_Unlock(CONVERT(This), NULL);
404 }
405
406 static HRESULT WINAPI
407 IDirectDrawSurface3Impl_UpdateOverlay(LPDIRECTDRAWSURFACE3 This, LPRECT prcSrc,
408                                       LPDIRECTDRAWSURFACE3 pDstSurf,
409                                       LPRECT prcDst, DWORD dwFlags,
410                                       LPDDOVERLAYFX pFX)
411 {
412     return IDirectDrawSurface7_UpdateOverlay(CONVERT(This), prcSrc,
413                                              CONVERT(pDstSurf), prcDst,
414                                              dwFlags, pFX);
415 }
416
417 static HRESULT WINAPI
418 IDirectDrawSurface3Impl_UpdateOverlayDisplay(LPDIRECTDRAWSURFACE3 This,
419                                              DWORD dwFlags)
420 {
421     return IDirectDrawSurface7_UpdateOverlayDisplay(CONVERT(This), dwFlags);
422 }
423
424 static HRESULT WINAPI
425 IDirectDrawSurface3Impl_UpdateOverlayZOrder(LPDIRECTDRAWSURFACE3 This,
426                                             DWORD dwFlags,
427                                             LPDIRECTDRAWSURFACE3 pSurfReference)
428 {
429     return IDirectDrawSurface7_UpdateOverlayZOrder(CONVERT(This), dwFlags,
430                                                    CONVERT(pSurfReference));
431 }
432
433 static HRESULT WINAPI
434 IDirectDrawSurface3Impl_GetDDInterface(LPDIRECTDRAWSURFACE3 This, LPVOID* ppDD)
435 {
436     return IDirectDrawSurface7_GetDDInterface(CONVERT(This), ppDD);
437 }
438
439 static HRESULT WINAPI
440 IDirectDrawSurface3Impl_PageLock(LPDIRECTDRAWSURFACE3 This, DWORD dwFlags)
441 {
442     return IDirectDrawSurface7_PageLock(CONVERT(This), dwFlags);
443 }
444
445 static HRESULT WINAPI
446 IDirectDrawSurface3Impl_PageUnlock(LPDIRECTDRAWSURFACE3 This, DWORD dwFlags)
447 {
448     return IDirectDrawSurface7_PageUnlock(CONVERT(This), dwFlags);
449 }
450
451 static HRESULT WINAPI
452 IDirectDrawSurface3Impl_SetSurfaceDesc(LPDIRECTDRAWSURFACE3 This,
453                                        LPDDSURFACEDESC pDDSD, DWORD dwFlags)
454 {
455     return IDirectDrawSurface7_SetSurfaceDesc(CONVERT(This),
456                                               (LPDDSURFACEDESC2)pDDSD,
457                                               dwFlags);
458 }
459
460 const IDirectDrawSurface3Vtbl IDirectDrawSurface3_Vtbl =
461 {
462     IDirectDrawSurface3Impl_QueryInterface,
463     IDirectDrawSurface3Impl_AddRef,
464     IDirectDrawSurface3Impl_Release,
465     IDirectDrawSurface3Impl_AddAttachedSurface,
466     IDirectDrawSurface3Impl_AddOverlayDirtyRect,
467     IDirectDrawSurface3Impl_Blt,
468     IDirectDrawSurface3Impl_BltBatch,
469     IDirectDrawSurface3Impl_BltFast,
470     IDirectDrawSurface3Impl_DeleteAttachedSurface,
471     IDirectDrawSurface3Impl_EnumAttachedSurfaces,
472     IDirectDrawSurface3Impl_EnumOverlayZOrders,
473     IDirectDrawSurface3Impl_Flip,
474     IDirectDrawSurface3Impl_GetAttachedSurface,
475     IDirectDrawSurface3Impl_GetBltStatus,
476     IDirectDrawSurface3Impl_GetCaps,
477     IDirectDrawSurface3Impl_GetClipper,
478     IDirectDrawSurface3Impl_GetColorKey,
479     IDirectDrawSurface3Impl_GetDC,
480     IDirectDrawSurface3Impl_GetFlipStatus,
481     IDirectDrawSurface3Impl_GetOverlayPosition,
482     IDirectDrawSurface3Impl_GetPalette,
483     IDirectDrawSurface3Impl_GetPixelFormat,
484     IDirectDrawSurface3Impl_GetSurfaceDesc,
485     IDirectDrawSurface3Impl_Initialize,
486     IDirectDrawSurface3Impl_IsLost,
487     IDirectDrawSurface3Impl_Lock,
488     IDirectDrawSurface3Impl_ReleaseDC,
489     IDirectDrawSurface3Impl_Restore,
490     IDirectDrawSurface3Impl_SetClipper,
491     IDirectDrawSurface3Impl_SetColorKey,
492     IDirectDrawSurface3Impl_SetOverlayPosition,
493     IDirectDrawSurface3Impl_SetPalette,
494     IDirectDrawSurface3Impl_Unlock,
495     IDirectDrawSurface3Impl_UpdateOverlay,
496     IDirectDrawSurface3Impl_UpdateOverlayDisplay,
497     IDirectDrawSurface3Impl_UpdateOverlayZOrder,
498     IDirectDrawSurface3Impl_GetDDInterface,
499     IDirectDrawSurface3Impl_PageLock,
500     IDirectDrawSurface3Impl_PageUnlock,
501     IDirectDrawSurface3Impl_SetSurfaceDesc
502 };