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