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