ddraw: Some caps fixes.
[wine] / dlls / ddraw / clipper.c
1 /* DirectDrawClipper implementation
2  *
3  * Copyright 2000 (c) Marcus Meissner
4  * Copyright 2000 (c) TransGaming Technologies Inc.
5  * Copyright 2006 (c) Stefan Dösinger
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include "config.h"
23
24 #include <stdarg.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "ddraw.h"
32 #include "winerror.h"
33
34 #include "ddraw_private.h"
35
36 #include "wine/debug.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
39
40 /*****************************************************************************
41  * IUnknown methods
42  *****************************************************************************/
43
44 /*****************************************************************************
45  * IDirectDrawClipper::QueryInterface
46  *
47  * Can query the IUnknown and IDirectDrawClipper interface from a
48  * Clipper object. The IUnknown Interface is equal to the IDirectDrawClipper
49  * interface. Can't create other interfaces.
50  *
51  * Arguments:
52  *  riid: Interface id asked for
53  *  ppvObj: Returns the pointer to the interface
54  *
55  * Return values:
56  *  DD_OK on success
57  *  E_NOINTERFACE if the requested interface wasn't found.
58  *
59  *****************************************************************************/
60 static HRESULT WINAPI IDirectDrawClipperImpl_QueryInterface(
61     LPDIRECTDRAWCLIPPER iface, REFIID riid, LPVOID* ppvObj
62 ) {
63     IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
64
65     if (IsEqualGUID(&IID_IUnknown, riid)
66         || IsEqualGUID(&IID_IDirectDrawClipper, riid))
67     {
68         *ppvObj = ICOM_INTERFACE(This, IDirectDrawClipper);
69         InterlockedIncrement(&This->ref);
70         return S_OK;
71     }
72     else
73     {
74         return E_NOINTERFACE;
75     }
76 }
77
78 /*****************************************************************************
79  * IDirectDrawClipper::AddRef
80  *
81  * Increases the reference count of the interface, returns the new count
82  *
83  *****************************************************************************/
84 static ULONG WINAPI IDirectDrawClipperImpl_AddRef( LPDIRECTDRAWCLIPPER iface )
85 {
86     IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
87     ULONG ref = InterlockedIncrement(&This->ref);
88
89     TRACE("(%p)->() incrementing from %u.\n", This, ref - 1);
90
91     return ref;
92 }
93
94 /*****************************************************************************
95  * IDirectDrawClipper::Release
96  *
97  * Decreases the reference count of the interface, returns the new count
98  * If the refcount is decreased to 0, the interface is destroyed.
99  *
100  *****************************************************************************/
101 static ULONG WINAPI IDirectDrawClipperImpl_Release(IDirectDrawClipper *iface) {
102     IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
103     ULONG ref = InterlockedDecrement(&This->ref);
104
105     TRACE("(%p)->() decrementing from %u.\n", This, ref + 1);
106
107     if (ref == 0)
108     {
109         IWineD3DClipper_Release(This->wineD3DClipper);
110         HeapFree(GetProcessHeap(), 0, This);
111         return 0;
112     }
113     else return ref;
114 }
115
116 /*****************************************************************************
117  * IDirectDrawClipper::SetHwnd
118  *
119  * Assigns a hWnd to the clipper interface.
120  *
121  * Arguments:
122  *  Flags: Unsupported so far
123  *  hWnd: The hWnd to set
124  *
125  * Return values:
126  *  DD_OK on success
127  *  DDERR_INVALIDPARAMS if Flags was != 0
128  *
129  *****************************************************************************/
130
131 static HRESULT WINAPI IDirectDrawClipperImpl_SetHwnd(
132     LPDIRECTDRAWCLIPPER iface, DWORD dwFlags, HWND hWnd
133 ) {
134     IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
135     HRESULT hr;
136     TRACE("(%p)->(%08x,%p)\n", This, dwFlags, hWnd);
137
138     hr = IWineD3DClipper_SetHWnd(This->wineD3DClipper,
139                                  dwFlags,
140                                  hWnd);
141     switch(hr)
142     {
143         case WINED3DERR_INVALIDCALL:        return DDERR_INVALIDPARAMS;
144         default:                            return hr;
145     }
146 }
147
148 /*****************************************************************************
149  * IDirectDrawClipper::GetClipList
150  *
151  * Retrieve a copy of the clip list
152  *
153  * Arguments:
154  *  Rect: Rectangle to be used to clip the clip list or NULL for the
155  *        entire clip list
156  *  ClipList: structure for the resulting copy of the clip list.
157  *            If NULL, fills Size up to the number of bytes necessary to hold
158  *            the entire clip.
159  *  Size: Size of resulting clip list; size of the buffer at ClipList
160  *        or, if ClipList is NULL, receives the required size of the buffer
161  *        in bytes
162  *
163  * RETURNS
164  *  Either DD_OK or DDERR_*
165  ************************************************************************/
166 static HRESULT WINAPI IDirectDrawClipperImpl_GetClipList(
167     LPDIRECTDRAWCLIPPER iface, LPRECT lpRect, LPRGNDATA lpClipList,
168     LPDWORD lpdwSize)
169 {
170     IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
171     TRACE("(%p,%p,%p,%p)\n", This, lpRect, lpClipList, lpdwSize);
172
173     return IWineD3DClipper_GetClipList(This->wineD3DClipper,
174                                        lpRect,
175                                        lpClipList,
176                                        lpdwSize);
177 }
178
179 /*****************************************************************************
180  * IDirectDrawClipper::SetClipList
181  *
182  * Sets or deletes (if lprgn is NULL) the clip list
183  *
184  * This implementation is a stub and returns DD_OK always to make the app
185  * happy.
186  *
187  * PARAMS
188  *  lprgn   Pointer to a LRGNDATA structure or NULL
189  *  dwFlags not used, must be 0
190  * RETURNS
191  *  Either DD_OK or DDERR_*
192  *****************************************************************************/
193 static HRESULT WINAPI IDirectDrawClipperImpl_SetClipList(
194     LPDIRECTDRAWCLIPPER iface,LPRGNDATA lprgn,DWORD dwFlag
195 ) {
196     IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
197
198     return IWineD3DClipper_SetClipList(This->wineD3DClipper,
199                                        lprgn,
200                                        dwFlag);
201 }
202
203 /*****************************************************************************
204  * IDirectDrawClipper::GetHwnd
205  *
206  * Returns the hwnd assigned with SetHwnd
207  *
208  * Arguments:
209  *  hWndPtr: Address to store the HWND at
210  *
211  * Return values:
212  *  Always returns DD_OK;
213  *****************************************************************************/
214 static HRESULT WINAPI IDirectDrawClipperImpl_GetHWnd(
215     LPDIRECTDRAWCLIPPER iface, HWND* hWndPtr
216 ) {
217     IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
218     TRACE("(%p)->(%p)\n", This, hWndPtr);
219
220     return IWineD3DClipper_GetHWnd(This->wineD3DClipper,
221                                    hWndPtr);
222 }
223
224 /*****************************************************************************
225  * IDirectDrawClipper::Initialize
226  *
227  * Initializes the interface. Well, there isn't much to do for this
228  * implementation, but it stores the DirectDraw Interface.
229  *
230  * Arguments:
231  *  DD: Pointer to a IDirectDraw interface
232  *  Flags: Unsupported by now
233  *
234  * Return values:
235  *  DD_OK on success
236  *  DDERR_ALREADYINITIALIZED if this interface isn't initialized already
237  *****************************************************************************/
238 static HRESULT WINAPI IDirectDrawClipperImpl_Initialize(
239      LPDIRECTDRAWCLIPPER iface, LPDIRECTDRAW lpDD, DWORD dwFlags
240 ) {
241     IDirectDrawImpl* pOwner;
242     IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
243     TRACE("(%p)->(%p,0x%08x)\n", This, lpDD, dwFlags);
244
245     if (This->ddraw_owner != NULL) return DDERR_ALREADYINITIALIZED;
246
247     pOwner = ICOM_OBJECT(IDirectDrawImpl, IDirectDraw, lpDD);
248     This->ddraw_owner = pOwner;
249
250     return DD_OK;
251 }
252
253 /*****************************************************************************
254  * IDirectDrawClipper::IsClipListChanged
255  *
256  * This function is a stub
257  *
258  * Arguments:
259  *  Changed:
260  *
261  * Return values:
262  *  DD_OK, because it's a stub
263  *****************************************************************************/
264 static HRESULT WINAPI IDirectDrawClipperImpl_IsClipListChanged(
265     LPDIRECTDRAWCLIPPER iface, BOOL* lpbChanged
266 ) {
267     IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
268     FIXME("(%p)->(%p),stub!\n",This,lpbChanged);
269
270     /* XXX What is safest? */
271     *lpbChanged = FALSE;
272
273     return DD_OK;
274 }
275
276 /*****************************************************************************
277  * The VTable
278  *****************************************************************************/
279 const IDirectDrawClipperVtbl IDirectDrawClipper_Vtbl =
280 {
281     IDirectDrawClipperImpl_QueryInterface,
282     IDirectDrawClipperImpl_AddRef,
283     IDirectDrawClipperImpl_Release,
284     IDirectDrawClipperImpl_GetClipList,
285     IDirectDrawClipperImpl_GetHWnd,
286     IDirectDrawClipperImpl_Initialize,
287     IDirectDrawClipperImpl_IsClipListChanged,
288     IDirectDrawClipperImpl_SetClipList,
289     IDirectDrawClipperImpl_SetHwnd
290 };