Add support for more than 2 audio channels.
[wine] / dlls / ddraw / dsurface / 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #include "config.h"
20 #include <stdarg.h>
21
22 #define CONST_VTABLE
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "ddraw.h"
28 #include "winerror.h"
29
30 #include "dsurface/main.h"
31 #include "dsurface/thunks.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 static HRESULT WINAPI
45 IDirectDrawSurface3Impl_QueryInterface(LPDIRECTDRAWSURFACE3 This, REFIID iid,
46                                        LPVOID *ppObj)
47 {
48     return IDirectDrawSurface7_QueryInterface(CONVERT(This), iid, ppObj);
49 }
50
51 static ULONG WINAPI
52 IDirectDrawSurface3Impl_AddRef(LPDIRECTDRAWSURFACE3 This)
53 {
54     return IDirectDrawSurface7_AddRef(CONVERT(This));
55 }
56
57 static ULONG WINAPI
58 IDirectDrawSurface3Impl_Release(LPDIRECTDRAWSURFACE3 This)
59 {
60     return IDirectDrawSurface7_Release(CONVERT(This));
61 }
62
63 static HRESULT WINAPI
64 IDirectDrawSurface3Impl_AddAttachedSurface(LPDIRECTDRAWSURFACE3 This,
65                                            LPDIRECTDRAWSURFACE3 pAttach)
66 {
67     return IDirectDrawSurface7_AddAttachedSurface(CONVERT(This),
68                                                   CONVERT(pAttach));
69 }
70
71 static HRESULT WINAPI
72 IDirectDrawSurface3Impl_AddOverlayDirtyRect(LPDIRECTDRAWSURFACE3 This,
73                                             LPRECT pRect)
74 {
75     return IDirectDrawSurface7_AddOverlayDirtyRect(CONVERT(This), pRect);
76 }
77
78 static HRESULT WINAPI
79 IDirectDrawSurface3Impl_Blt(LPDIRECTDRAWSURFACE3 This, LPRECT prcDst,
80                             LPDIRECTDRAWSURFACE3 pSrcSurf, LPRECT prcSrc,
81                             DWORD dwFlags, LPDDBLTFX pFX)
82 {
83     return IDirectDrawSurface7_Blt(CONVERT(This), prcDst, CONVERT(pSrcSurf),
84                                    prcSrc, dwFlags, pFX);
85 }
86
87 static HRESULT WINAPI
88 IDirectDrawSurface3Impl_BltBatch(LPDIRECTDRAWSURFACE3 This,
89                                  LPDDBLTBATCH pBatch, DWORD dwCount,
90                                  DWORD dwFlags)
91 {
92     return IDirectDrawSurface7_BltBatch(CONVERT(This), pBatch, dwCount,
93                                         dwFlags);
94 }
95
96 static HRESULT WINAPI
97 IDirectDrawSurface3Impl_BltFast(LPDIRECTDRAWSURFACE3 This, DWORD x, DWORD y,
98                                 LPDIRECTDRAWSURFACE3 pSrcSurf, LPRECT prcSrc,
99                                 DWORD dwTrans)
100 {
101     return IDirectDrawSurface7_BltFast(CONVERT(This), x, y, CONVERT(pSrcSurf),
102                                        prcSrc, dwTrans);
103 }
104
105 static HRESULT WINAPI
106 IDirectDrawSurface3Impl_DeleteAttachedSurface(LPDIRECTDRAWSURFACE3 This,
107                                               DWORD dwFlags,
108                                               LPDIRECTDRAWSURFACE3 pAttached)
109 {
110     return IDirectDrawSurface7_DeleteAttachedSurface(CONVERT(This), dwFlags,
111                                                      CONVERT(pAttached));
112 }
113
114 struct callback_info
115 {
116     LPDDENUMSURFACESCALLBACK callback;
117     LPVOID context;
118 };
119
120 static HRESULT CALLBACK
121 EnumCallback(LPDIRECTDRAWSURFACE7 iface, LPDDSURFACEDESC2 pDDSD,
122              LPVOID context)
123 {
124     const struct callback_info* info = context;
125
126 #if 0
127     /* This is an outgoing conversion so we have to do it. */
128     DDSURFACEDESC ddsd;
129     memset(&ddsd, 0, sizeof(ddsd));
130     ddsd.dwSize = sizeof(ddsd);
131     DDRAW_Convert_DDSURFACEDESC_2_To_1(pDDSD, &ddsd);
132 #endif
133
134     /* the LPDDSURFACEDESC2 -> LPDDSURFACEDESC coercion is safe, since
135      * the data format is compatible with older enum procs */
136     return info->callback((LPDIRECTDRAWSURFACE)CONVERT_REV(iface), (LPDDSURFACEDESC)pDDSD,
137                           info->context);
138 }
139
140 static HRESULT WINAPI
141 IDirectDrawSurface3Impl_EnumAttachedSurfaces(LPDIRECTDRAWSURFACE3 This,
142                                              LPVOID context,
143                                              LPDDENUMSURFACESCALLBACK callback)
144 {
145     struct callback_info info;
146
147     info.callback = callback;
148     info.context  = context;
149
150     return IDirectDrawSurface7_EnumAttachedSurfaces(CONVERT(This), &info,
151                                                     EnumCallback);
152 }
153
154 static HRESULT WINAPI
155 IDirectDrawSurface3Impl_EnumOverlayZOrders(LPDIRECTDRAWSURFACE3 This,
156                                            DWORD dwFlags, LPVOID context,
157                                            LPDDENUMSURFACESCALLBACK callback)
158 {
159     struct callback_info info;
160
161     info.callback = callback;
162     info.context  = context;
163
164     return IDirectDrawSurface7_EnumOverlayZOrders(CONVERT(This), dwFlags,
165                                                   &info, EnumCallback);
166 }
167
168 static HRESULT WINAPI
169 IDirectDrawSurface3Impl_Flip(LPDIRECTDRAWSURFACE3 This,
170                              LPDIRECTDRAWSURFACE3 pOverride, DWORD dwFlags)
171 {
172     return IDirectDrawSurface7_Flip(CONVERT(This), CONVERT(pOverride),
173                                     dwFlags);
174 }
175
176 static HRESULT WINAPI
177 IDirectDrawSurface3Impl_GetAttachedSurface(LPDIRECTDRAWSURFACE3 This,
178                                            LPDDSCAPS pCaps,
179                                            LPDIRECTDRAWSURFACE3* ppAttached)
180 {
181     DDSCAPS2 caps;
182     LPDIRECTDRAWSURFACE7 pAttached7;
183     HRESULT hr;
184
185     caps.dwCaps  = pCaps->dwCaps;
186     caps.dwCaps2 = 0;
187     caps.dwCaps3 = 0;
188     caps.dwCaps4 = 0;
189
190     hr = IDirectDrawSurface7_GetAttachedSurface(CONVERT(This), &caps,
191                                                 &pAttached7);
192     if (FAILED(hr)) return hr;
193
194     *ppAttached = CONVERT_REV(pAttached7);
195     return hr;
196 }
197
198 static HRESULT WINAPI
199 IDirectDrawSurface3Impl_GetBltStatus(LPDIRECTDRAWSURFACE3 This, DWORD dwFlags)
200 {
201     return IDirectDrawSurface7_GetBltStatus(CONVERT(This), dwFlags);
202 }
203
204 static HRESULT WINAPI
205 IDirectDrawSurface3Impl_GetCaps(LPDIRECTDRAWSURFACE3 This, LPDDSCAPS pCaps)
206 {
207     DDSCAPS2 caps;
208     HRESULT hr;
209
210     hr = IDirectDrawSurface7_GetCaps(CONVERT(This), &caps);
211     if (FAILED(hr)) return hr;
212
213     pCaps->dwCaps = caps.dwCaps;
214     return hr;
215 }
216
217 static HRESULT WINAPI
218 IDirectDrawSurface3Impl_GetClipper(LPDIRECTDRAWSURFACE3 This,
219                                    LPDIRECTDRAWCLIPPER* ppClipper)
220 {
221     return IDirectDrawSurface7_GetClipper(CONVERT(This), ppClipper);
222 }
223
224 static HRESULT WINAPI
225 IDirectDrawSurface3Impl_GetColorKey(LPDIRECTDRAWSURFACE3 This, DWORD dwFlags,
226                                     LPDDCOLORKEY pCKey)
227 {
228     return IDirectDrawSurface7_GetColorKey(CONVERT(This), dwFlags, pCKey);
229 }
230
231 static HRESULT WINAPI
232 IDirectDrawSurface3Impl_GetDC(LPDIRECTDRAWSURFACE3 This, HDC* phDC)
233 {
234     return IDirectDrawSurface7_GetDC(CONVERT(This), phDC);
235 }
236
237 static HRESULT WINAPI
238 IDirectDrawSurface3Impl_GetFlipStatus(LPDIRECTDRAWSURFACE3 This, DWORD dwFlags)
239 {
240     return IDirectDrawSurface7_GetFlipStatus(CONVERT(This), dwFlags);
241 }
242
243 static HRESULT WINAPI
244 IDirectDrawSurface3Impl_GetOverlayPosition(LPDIRECTDRAWSURFACE3 This, LPLONG pX,
245                                        LPLONG pY)
246 {
247     return IDirectDrawSurface7_GetOverlayPosition(CONVERT(This), pX, pY);
248 }
249
250 static HRESULT WINAPI
251 IDirectDrawSurface3Impl_GetPalette(LPDIRECTDRAWSURFACE3 This,
252                                    LPDIRECTDRAWPALETTE* ppPalette)
253 {
254     return IDirectDrawSurface7_GetPalette(CONVERT(This), ppPalette);
255 }
256
257 static HRESULT WINAPI
258 IDirectDrawSurface3Impl_GetPixelFormat(LPDIRECTDRAWSURFACE3 This,
259                                        LPDDPIXELFORMAT pPixelFormat)
260 {
261     return IDirectDrawSurface7_GetPixelFormat(CONVERT(This), pPixelFormat);
262 }
263
264 static HRESULT WINAPI
265 IDirectDrawSurface3Impl_GetSurfaceDesc(LPDIRECTDRAWSURFACE3 This,
266                                        LPDDSURFACEDESC pDDSD)
267 {
268     return IDirectDrawSurface7_GetSurfaceDesc(CONVERT(This),
269                                               (LPDDSURFACEDESC2)pDDSD);
270 }
271
272 static HRESULT WINAPI
273 IDirectDrawSurface3Impl_Initialize(LPDIRECTDRAWSURFACE3 This, LPDIRECTDRAW pDD,
274                                    LPDDSURFACEDESC pDDSD)
275 {
276     return IDirectDrawSurface7_Initialize(CONVERT(This), pDD,
277                                           (LPDDSURFACEDESC2)pDDSD);
278 }
279
280 static HRESULT WINAPI
281 IDirectDrawSurface3Impl_IsLost(LPDIRECTDRAWSURFACE3 This)
282 {
283     return IDirectDrawSurface7_IsLost(CONVERT(This));
284 }
285
286 static HRESULT WINAPI
287 IDirectDrawSurface3Impl_Lock(LPDIRECTDRAWSURFACE3 This, LPRECT pRect,
288                              LPDDSURFACEDESC pDDSD, DWORD dwFlags, HANDLE h)
289 {
290     return IDirectDrawSurface7_Lock(CONVERT(This), pRect,
291                                     (LPDDSURFACEDESC2)pDDSD, dwFlags, h);
292 }
293
294 static HRESULT WINAPI
295 IDirectDrawSurface3Impl_ReleaseDC(LPDIRECTDRAWSURFACE3 This, HDC hDC)
296 {
297     return IDirectDrawSurface7_ReleaseDC(CONVERT(This), hDC);
298 }
299
300 static HRESULT WINAPI
301 IDirectDrawSurface3Impl_Restore(LPDIRECTDRAWSURFACE3 This)
302 {
303     return IDirectDrawSurface7_Restore(CONVERT(This));
304 }
305
306 static HRESULT WINAPI
307 IDirectDrawSurface3Impl_SetClipper(LPDIRECTDRAWSURFACE3 This,
308                                    LPDIRECTDRAWCLIPPER pClipper)
309 {
310     return IDirectDrawSurface7_SetClipper(CONVERT(This), pClipper);
311 }
312
313 static HRESULT WINAPI
314 IDirectDrawSurface3Impl_SetColorKey(LPDIRECTDRAWSURFACE3 This, DWORD dwFlags,
315                                     LPDDCOLORKEY pCKey)
316 {
317     return IDirectDrawSurface7_SetColorKey(CONVERT(This), dwFlags, pCKey);
318 }
319
320 static HRESULT WINAPI
321 IDirectDrawSurface3Impl_SetOverlayPosition(LPDIRECTDRAWSURFACE3 This, LONG x,
322                                        LONG y)
323 {
324     return IDirectDrawSurface7_SetOverlayPosition(CONVERT(This), x, y);
325 }
326
327 static HRESULT WINAPI
328 IDirectDrawSurface3Impl_SetPalette(LPDIRECTDRAWSURFACE3 This,
329                                    LPDIRECTDRAWPALETTE pPalette)
330 {
331     return IDirectDrawSurface7_SetPalette(CONVERT(This), pPalette);
332 }
333
334 static HRESULT WINAPI
335 IDirectDrawSurface3Impl_Unlock(LPDIRECTDRAWSURFACE3 This, LPVOID data)
336 {
337     /* data might not be the LPRECT of later versions, so drop it. */
338     return IDirectDrawSurface7_Unlock(CONVERT(This), NULL);
339 }
340
341 static HRESULT WINAPI
342 IDirectDrawSurface3Impl_UpdateOverlay(LPDIRECTDRAWSURFACE3 This, LPRECT prcSrc,
343                                       LPDIRECTDRAWSURFACE3 pDstSurf,
344                                       LPRECT prcDst, DWORD dwFlags,
345                                       LPDDOVERLAYFX pFX)
346 {
347     return IDirectDrawSurface7_UpdateOverlay(CONVERT(This), prcSrc,
348                                              CONVERT(pDstSurf), prcDst,
349                                              dwFlags, pFX);
350 }
351
352 static HRESULT WINAPI
353 IDirectDrawSurface3Impl_UpdateOverlayDisplay(LPDIRECTDRAWSURFACE3 This,
354                                              DWORD dwFlags)
355 {
356     return IDirectDrawSurface7_UpdateOverlayDisplay(CONVERT(This), dwFlags);
357 }
358
359 static HRESULT WINAPI
360 IDirectDrawSurface3Impl_UpdateOverlayZOrder(LPDIRECTDRAWSURFACE3 This,
361                                             DWORD dwFlags,
362                                             LPDIRECTDRAWSURFACE3 pSurfReference)
363 {
364     return IDirectDrawSurface7_UpdateOverlayZOrder(CONVERT(This), dwFlags,
365                                                    CONVERT(pSurfReference));
366 }
367
368 static HRESULT WINAPI
369 IDirectDrawSurface3Impl_GetDDInterface(LPDIRECTDRAWSURFACE3 This, LPVOID* ppDD)
370 {
371     return IDirectDrawSurface7_GetDDInterface(CONVERT(This), ppDD);
372 }
373
374 static HRESULT WINAPI
375 IDirectDrawSurface3Impl_PageLock(LPDIRECTDRAWSURFACE3 This, DWORD dwFlags)
376 {
377     return IDirectDrawSurface7_PageLock(CONVERT(This), dwFlags);
378 }
379
380 static HRESULT WINAPI
381 IDirectDrawSurface3Impl_PageUnlock(LPDIRECTDRAWSURFACE3 This, DWORD dwFlags)
382 {
383     return IDirectDrawSurface7_PageUnlock(CONVERT(This), dwFlags);
384 }
385
386 static HRESULT WINAPI
387 IDirectDrawSurface3Impl_SetSurfaceDesc(LPDIRECTDRAWSURFACE3 This,
388                                        LPDDSURFACEDESC pDDSD, DWORD dwFlags)
389 {
390     return IDirectDrawSurface7_SetSurfaceDesc(CONVERT(This),
391                                               (LPDDSURFACEDESC2)pDDSD,
392                                               dwFlags);
393 }
394
395 const IDirectDrawSurface3Vtbl DDRAW_IDDS3_Thunk_VTable =
396 {
397     IDirectDrawSurface3Impl_QueryInterface,
398     IDirectDrawSurface3Impl_AddRef,
399     IDirectDrawSurface3Impl_Release,
400     IDirectDrawSurface3Impl_AddAttachedSurface,
401     IDirectDrawSurface3Impl_AddOverlayDirtyRect,
402     IDirectDrawSurface3Impl_Blt,
403     IDirectDrawSurface3Impl_BltBatch,
404     IDirectDrawSurface3Impl_BltFast,
405     IDirectDrawSurface3Impl_DeleteAttachedSurface,
406     IDirectDrawSurface3Impl_EnumAttachedSurfaces,
407     IDirectDrawSurface3Impl_EnumOverlayZOrders,
408     IDirectDrawSurface3Impl_Flip,
409     IDirectDrawSurface3Impl_GetAttachedSurface,
410     IDirectDrawSurface3Impl_GetBltStatus,
411     IDirectDrawSurface3Impl_GetCaps,
412     IDirectDrawSurface3Impl_GetClipper,
413     IDirectDrawSurface3Impl_GetColorKey,
414     IDirectDrawSurface3Impl_GetDC,
415     IDirectDrawSurface3Impl_GetFlipStatus,
416     IDirectDrawSurface3Impl_GetOverlayPosition,
417     IDirectDrawSurface3Impl_GetPalette,
418     IDirectDrawSurface3Impl_GetPixelFormat,
419     IDirectDrawSurface3Impl_GetSurfaceDesc,
420     IDirectDrawSurface3Impl_Initialize,
421     IDirectDrawSurface3Impl_IsLost,
422     IDirectDrawSurface3Impl_Lock,
423     IDirectDrawSurface3Impl_ReleaseDC,
424     IDirectDrawSurface3Impl_Restore,
425     IDirectDrawSurface3Impl_SetClipper,
426     IDirectDrawSurface3Impl_SetColorKey,
427     IDirectDrawSurface3Impl_SetOverlayPosition,
428     IDirectDrawSurface3Impl_SetPalette,
429     IDirectDrawSurface3Impl_Unlock,
430     IDirectDrawSurface3Impl_UpdateOverlay,
431     IDirectDrawSurface3Impl_UpdateOverlayDisplay,
432     IDirectDrawSurface3Impl_UpdateOverlayZOrder,
433     IDirectDrawSurface3Impl_GetDDInterface,
434     IDirectDrawSurface3Impl_PageLock,
435     IDirectDrawSurface3Impl_PageUnlock,
436     IDirectDrawSurface3Impl_SetSurfaceDesc
437 };