server: Store debugging output strings as client_ptr_t instead of void pointers.
[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 #define COBJMACROS
29
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "ddraw.h"
34 #include "winerror.h"
35
36 #include "ddraw_private.h"
37
38 #include "wine/debug.h"
39
40 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
41
42 /*****************************************************************************
43  * IUnknown methods
44  *****************************************************************************/
45
46 /*****************************************************************************
47  * IDirectDrawClipper::QueryInterface
48  *
49  * Can query the IUnknown and IDirectDrawClipper interface from a
50  * Clipper object. The IUnknown Interface is equal to the IDirectDrawClipper
51  * interface. Can't create other interfaces.
52  *
53  * Arguments:
54  *  riid: Interface id asked for
55  *  ppvObj: Returns the pointer to the interface
56  *
57  * Return values:
58  *  DD_OK on success
59  *  E_NOINTERFACE if the requested interface wasn't found.
60  *
61  *****************************************************************************/
62 static HRESULT WINAPI IDirectDrawClipperImpl_QueryInterface(
63     LPDIRECTDRAWCLIPPER iface, REFIID riid, LPVOID* ppvObj
64 ) {
65     IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
66
67     if (IsEqualGUID(&IID_IUnknown, riid)
68         || IsEqualGUID(&IID_IDirectDrawClipper, riid))
69     {
70         *ppvObj = ICOM_INTERFACE(This, IDirectDrawClipper);
71         InterlockedIncrement(&This->ref);
72         return S_OK;
73     }
74     else
75     {
76         return E_NOINTERFACE;
77     }
78 }
79
80 /*****************************************************************************
81  * IDirectDrawClipper::AddRef
82  *
83  * Increases the reference count of the interface, returns the new count
84  *
85  *****************************************************************************/
86 static ULONG WINAPI IDirectDrawClipperImpl_AddRef( LPDIRECTDRAWCLIPPER iface )
87 {
88     IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
89     ULONG ref = InterlockedIncrement(&This->ref);
90
91     TRACE("(%p)->() incrementing from %u.\n", This, ref - 1);
92
93     return ref;
94 }
95
96 /*****************************************************************************
97  * IDirectDrawClipper::Release
98  *
99  * Decreases the reference count of the interface, returns the new count
100  * If the refcount is decreased to 0, the interface is destroyed.
101  *
102  *****************************************************************************/
103 static ULONG WINAPI IDirectDrawClipperImpl_Release(IDirectDrawClipper *iface) {
104     IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
105     ULONG ref = InterlockedDecrement(&This->ref);
106
107     TRACE("(%p)->() decrementing from %u.\n", This, ref + 1);
108
109     if (ref == 0)
110     {
111         EnterCriticalSection(&ddraw_cs);
112         IWineD3DClipper_Release(This->wineD3DClipper);
113         HeapFree(GetProcessHeap(), 0, This);
114         LeaveCriticalSection(&ddraw_cs);
115         return 0;
116     }
117     else return ref;
118 }
119
120 /*****************************************************************************
121  * IDirectDrawClipper::SetHwnd
122  *
123  * Assigns a hWnd to the clipper interface.
124  *
125  * Arguments:
126  *  Flags: Unsupported so far
127  *  hWnd: The hWnd to set
128  *
129  * Return values:
130  *  DD_OK on success
131  *  DDERR_INVALIDPARAMS if Flags was != 0
132  *
133  *****************************************************************************/
134
135 static HRESULT WINAPI IDirectDrawClipperImpl_SetHwnd(
136     LPDIRECTDRAWCLIPPER iface, DWORD dwFlags, HWND hWnd
137 ) {
138     IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
139     HRESULT hr;
140     TRACE("(%p)->(%08x,%p)\n", This, dwFlags, hWnd);
141
142     EnterCriticalSection(&ddraw_cs);
143     hr = IWineD3DClipper_SetHWnd(This->wineD3DClipper,
144                                  dwFlags,
145                                  hWnd);
146     LeaveCriticalSection(&ddraw_cs);
147     switch(hr)
148     {
149         case WINED3DERR_INVALIDCALL:        return DDERR_INVALIDPARAMS;
150         default:                            return hr;
151     }
152 }
153
154 /*****************************************************************************
155  * IDirectDrawClipper::GetClipList
156  *
157  * Retrieve a copy of the clip list
158  *
159  * Arguments:
160  *  Rect: Rectangle to be used to clip the clip list or NULL for the
161  *        entire clip list
162  *  ClipList: structure for the resulting copy of the clip list.
163  *            If NULL, fills Size up to the number of bytes necessary to hold
164  *            the entire clip.
165  *  Size: Size of resulting clip list; size of the buffer at ClipList
166  *        or, if ClipList is NULL, receives the required size of the buffer
167  *        in bytes
168  *
169  * RETURNS
170  *  Either DD_OK or DDERR_*
171  ************************************************************************/
172 static HRESULT WINAPI IDirectDrawClipperImpl_GetClipList(
173     LPDIRECTDRAWCLIPPER iface, LPRECT lpRect, LPRGNDATA lpClipList,
174     LPDWORD lpdwSize)
175 {
176     IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
177     HRESULT hr;
178     TRACE("(%p,%p,%p,%p)\n", This, lpRect, lpClipList, lpdwSize);
179
180     EnterCriticalSection(&ddraw_cs);
181     hr = IWineD3DClipper_GetClipList(This->wineD3DClipper,
182                                      lpRect,
183                                      lpClipList,
184                                      lpdwSize);
185     LeaveCriticalSection(&ddraw_cs);
186     return hr;
187 }
188
189 /*****************************************************************************
190  * IDirectDrawClipper::SetClipList
191  *
192  * Sets or deletes (if lprgn is NULL) the clip list
193  *
194  * This implementation is a stub and returns DD_OK always to make the app
195  * happy.
196  *
197  * PARAMS
198  *  lprgn   Pointer to a LRGNDATA structure or NULL
199  *  dwFlags not used, must be 0
200  * RETURNS
201  *  Either DD_OK or DDERR_*
202  *****************************************************************************/
203 static HRESULT WINAPI IDirectDrawClipperImpl_SetClipList(
204     LPDIRECTDRAWCLIPPER iface,LPRGNDATA lprgn,DWORD dwFlag
205 ) {
206     IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
207     HRESULT hr;
208
209     EnterCriticalSection(&ddraw_cs);
210     hr = IWineD3DClipper_SetClipList(This->wineD3DClipper,
211                                      lprgn,
212                                      dwFlag);
213     LeaveCriticalSection(&ddraw_cs);
214     return hr;
215 }
216
217 /*****************************************************************************
218  * IDirectDrawClipper::GetHwnd
219  *
220  * Returns the hwnd assigned with SetHwnd
221  *
222  * Arguments:
223  *  hWndPtr: Address to store the HWND at
224  *
225  * Return values:
226  *  Always returns DD_OK;
227  *****************************************************************************/
228 static HRESULT WINAPI IDirectDrawClipperImpl_GetHWnd(
229     LPDIRECTDRAWCLIPPER iface, HWND* hWndPtr
230 ) {
231     IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
232     HRESULT hr;
233     TRACE("(%p)->(%p)\n", This, hWndPtr);
234
235     EnterCriticalSection(&ddraw_cs);
236     hr =  IWineD3DClipper_GetHWnd(This->wineD3DClipper,
237                                   hWndPtr);
238     LeaveCriticalSection(&ddraw_cs);
239     return hr;
240 }
241
242 /*****************************************************************************
243  * IDirectDrawClipper::Initialize
244  *
245  * Initializes the interface. Well, there isn't much to do for this
246  * implementation, but it stores the DirectDraw Interface.
247  *
248  * Arguments:
249  *  DD: Pointer to a IDirectDraw interface
250  *  Flags: Unsupported by now
251  *
252  * Return values:
253  *  DD_OK on success
254  *  DDERR_ALREADYINITIALIZED if this interface isn't initialized already
255  *****************************************************************************/
256 static HRESULT WINAPI IDirectDrawClipperImpl_Initialize(
257      LPDIRECTDRAWCLIPPER iface, LPDIRECTDRAW lpDD, DWORD dwFlags
258 ) {
259     IDirectDrawImpl* pOwner;
260     IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
261     TRACE("(%p)->(%p,0x%08x)\n", This, lpDD, dwFlags);
262
263     EnterCriticalSection(&ddraw_cs);
264     if (This->ddraw_owner != NULL)
265     {
266         LeaveCriticalSection(&ddraw_cs);
267         return DDERR_ALREADYINITIALIZED;
268     }
269
270     pOwner = ICOM_OBJECT(IDirectDrawImpl, IDirectDraw, lpDD);
271     This->ddraw_owner = pOwner;
272
273     LeaveCriticalSection(&ddraw_cs);
274     return DD_OK;
275 }
276
277 /*****************************************************************************
278  * IDirectDrawClipper::IsClipListChanged
279  *
280  * This function is a stub
281  *
282  * Arguments:
283  *  Changed:
284  *
285  * Return values:
286  *  DD_OK, because it's a stub
287  *****************************************************************************/
288 static HRESULT WINAPI IDirectDrawClipperImpl_IsClipListChanged(
289     LPDIRECTDRAWCLIPPER iface, BOOL* lpbChanged
290 ) {
291     IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
292     FIXME("(%p)->(%p),stub!\n",This,lpbChanged);
293
294     /* XXX What is safest? */
295     *lpbChanged = FALSE;
296
297     return DD_OK;
298 }
299
300 /*****************************************************************************
301  * The VTable
302  *****************************************************************************/
303 const IDirectDrawClipperVtbl IDirectDrawClipper_Vtbl =
304 {
305     IDirectDrawClipperImpl_QueryInterface,
306     IDirectDrawClipperImpl_AddRef,
307     IDirectDrawClipperImpl_Release,
308     IDirectDrawClipperImpl_GetClipList,
309     IDirectDrawClipperImpl_GetHWnd,
310     IDirectDrawClipperImpl_Initialize,
311     IDirectDrawClipperImpl_IsClipListChanged,
312     IDirectDrawClipperImpl_SetClipList,
313     IDirectDrawClipperImpl_SetHwnd
314 };