user32: Dont create 16 bits heap in 64-bits mode
[wine/wine64.git] / dlls / ddraw / clipper.c
blobb43ca0eeea8cdcbf85118d41bf12f871f69dcb88
1 /* DirectDrawClipper implementation
3 * Copyright 2000 (c) Marcus Meissner
4 * Copyright 2000 (c) TransGaming Technologies Inc.
5 * Copyright 2006 (c) Stefan Dösinger
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.
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.
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
22 #include "config.h"
24 #include <stdarg.h>
25 #include <stdlib.h>
26 #include <string.h>
28 #define COBJMACROS
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "ddraw.h"
34 #include "winerror.h"
36 #include "ddraw_private.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
42 /*****************************************************************************
43 * IUnknown methods
44 *****************************************************************************/
46 /*****************************************************************************
47 * IDirectDrawClipper::QueryInterface
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.
53 * Arguments:
54 * riid: Interface id asked for
55 * ppvObj: Returns the pointer to the interface
57 * Return values:
58 * DD_OK on success
59 * E_NOINTERFACE if the requested interface wasn't found.
61 *****************************************************************************/
62 static HRESULT WINAPI IDirectDrawClipperImpl_QueryInterface(
63 LPDIRECTDRAWCLIPPER iface, REFIID riid, LPVOID* ppvObj
64 ) {
65 IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
67 if (IsEqualGUID(&IID_IUnknown, riid)
68 || IsEqualGUID(&IID_IDirectDrawClipper, riid))
70 *ppvObj = ICOM_INTERFACE(This, IDirectDrawClipper);
71 InterlockedIncrement(&This->ref);
72 return S_OK;
74 else
76 return E_NOINTERFACE;
80 /*****************************************************************************
81 * IDirectDrawClipper::AddRef
83 * Increases the reference count of the interface, returns the new count
85 *****************************************************************************/
86 static ULONG WINAPI IDirectDrawClipperImpl_AddRef( LPDIRECTDRAWCLIPPER iface )
88 IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
89 ULONG ref = InterlockedIncrement(&This->ref);
91 TRACE("(%p)->() incrementing from %u.\n", This, ref - 1);
93 return ref;
96 /*****************************************************************************
97 * IDirectDrawClipper::Release
99 * Decreases the reference count of the interface, returns the new count
100 * If the refcount is decreased to 0, the interface is destroyed.
102 *****************************************************************************/
103 static ULONG WINAPI IDirectDrawClipperImpl_Release(IDirectDrawClipper *iface) {
104 IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
105 ULONG ref = InterlockedDecrement(&This->ref);
107 TRACE("(%p)->() decrementing from %u.\n", This, ref + 1);
109 if (ref == 0)
111 EnterCriticalSection(&ddraw_cs);
112 IWineD3DClipper_Release(This->wineD3DClipper);
113 HeapFree(GetProcessHeap(), 0, This);
114 LeaveCriticalSection(&ddraw_cs);
115 return 0;
117 else return ref;
120 /*****************************************************************************
121 * IDirectDrawClipper::SetHwnd
123 * Assigns a hWnd to the clipper interface.
125 * Arguments:
126 * Flags: Unsupported so far
127 * hWnd: The hWnd to set
129 * Return values:
130 * DD_OK on success
131 * DDERR_INVALIDPARAMS if Flags was != 0
133 *****************************************************************************/
135 static HRESULT WINAPI IDirectDrawClipperImpl_SetHwnd(
136 LPDIRECTDRAWCLIPPER iface, DWORD dwFlags, HWND hWnd
138 IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
139 HRESULT hr;
140 TRACE("(%p)->(%08x,%p)\n", This, dwFlags, hWnd);
142 EnterCriticalSection(&ddraw_cs);
143 hr = IWineD3DClipper_SetHWnd(This->wineD3DClipper,
144 dwFlags,
145 hWnd);
146 LeaveCriticalSection(&ddraw_cs);
147 switch(hr)
149 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
150 default: return hr;
154 /*****************************************************************************
155 * IDirectDrawClipper::GetClipList
157 * Retrieve a copy of the clip list
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
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)
176 IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
177 HRESULT hr;
178 TRACE("(%p,%p,%p,%p)\n", This, lpRect, lpClipList, lpdwSize);
180 EnterCriticalSection(&ddraw_cs);
181 hr = IWineD3DClipper_GetClipList(This->wineD3DClipper,
182 lpRect,
183 lpClipList,
184 lpdwSize);
185 LeaveCriticalSection(&ddraw_cs);
186 return hr;
189 /*****************************************************************************
190 * IDirectDrawClipper::SetClipList
192 * Sets or deletes (if lprgn is NULL) the clip list
194 * This implementation is a stub and returns DD_OK always to make the app
195 * happy.
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
206 IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
207 HRESULT hr;
209 EnterCriticalSection(&ddraw_cs);
210 hr = IWineD3DClipper_SetClipList(This->wineD3DClipper,
211 lprgn,
212 dwFlag);
213 LeaveCriticalSection(&ddraw_cs);
214 return hr;
217 /*****************************************************************************
218 * IDirectDrawClipper::GetHwnd
220 * Returns the hwnd assigned with SetHwnd
222 * Arguments:
223 * hWndPtr: Address to store the HWND at
225 * Return values:
226 * Always returns DD_OK;
227 *****************************************************************************/
228 static HRESULT WINAPI IDirectDrawClipperImpl_GetHWnd(
229 LPDIRECTDRAWCLIPPER iface, HWND* hWndPtr
231 IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
232 HRESULT hr;
233 TRACE("(%p)->(%p)\n", This, hWndPtr);
235 EnterCriticalSection(&ddraw_cs);
236 hr = IWineD3DClipper_GetHWnd(This->wineD3DClipper,
237 hWndPtr);
238 LeaveCriticalSection(&ddraw_cs);
239 return hr;
242 /*****************************************************************************
243 * IDirectDrawClipper::Initialize
245 * Initializes the interface. Well, there isn't much to do for this
246 * implementation, but it stores the DirectDraw Interface.
248 * Arguments:
249 * DD: Pointer to a IDirectDraw interface
250 * Flags: Unsupported by now
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
259 IDirectDrawImpl* pOwner;
260 IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
261 TRACE("(%p)->(%p,0x%08x)\n", This, lpDD, dwFlags);
263 EnterCriticalSection(&ddraw_cs);
264 if (This->ddraw_owner != NULL)
266 LeaveCriticalSection(&ddraw_cs);
267 return DDERR_ALREADYINITIALIZED;
270 pOwner = ICOM_OBJECT(IDirectDrawImpl, IDirectDraw, lpDD);
271 This->ddraw_owner = pOwner;
273 LeaveCriticalSection(&ddraw_cs);
274 return DD_OK;
277 /*****************************************************************************
278 * IDirectDrawClipper::IsClipListChanged
280 * This function is a stub
282 * Arguments:
283 * Changed:
285 * Return values:
286 * DD_OK, because it's a stub
287 *****************************************************************************/
288 static HRESULT WINAPI IDirectDrawClipperImpl_IsClipListChanged(
289 LPDIRECTDRAWCLIPPER iface, BOOL* lpbChanged
291 IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
292 FIXME("(%p)->(%p),stub!\n",This,lpbChanged);
294 /* XXX What is safest? */
295 *lpbChanged = FALSE;
297 return DD_OK;
300 /*****************************************************************************
301 * The VTable
302 *****************************************************************************/
303 const IDirectDrawClipperVtbl IDirectDrawClipper_Vtbl =
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