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