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