1 /* DirectDrawClipper implementation
3 * Copyright 2000 Marcus Meissner
4 * Copyright 2000 TransGaming Technologies Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 #include "ddraw_private.h"
36 #include "dclipper/main.h"
37 #include "ddraw/main.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
43 /******************************************************************************
44 * DirectDrawCreateClipper (DDRAW.@)
47 static const IDirectDrawClipperVtbl DDRAW_Clipper_VTable;
49 HRESULT WINAPI DirectDrawCreateClipper(
50 DWORD dwFlags, LPDIRECTDRAWCLIPPER *lplpDDClipper, LPUNKNOWN pUnkOuter
52 IDirectDrawClipperImpl* This;
53 TRACE("(%08lx,%p,%p)\n", dwFlags, lplpDDClipper, pUnkOuter);
55 if (pUnkOuter != NULL) return CLASS_E_NOAGGREGATION;
57 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
58 sizeof(IDirectDrawClipperImpl));
59 if (This == NULL) return E_OUTOFMEMORY;
61 ICOM_INIT_INTERFACE(This, IDirectDrawClipper, DDRAW_Clipper_VTable);
64 This->ddraw_owner = NULL;
66 *lplpDDClipper = ICOM_INTERFACE(This, IDirectDrawClipper);
70 /* This is the classfactory implementation. */
71 HRESULT DDRAW_CreateDirectDrawClipper(IUnknown* pUnkOuter, REFIID riid,
75 LPDIRECTDRAWCLIPPER pClip;
77 hr = DirectDrawCreateClipper(0, &pClip, pUnkOuter);
78 if (FAILED(hr)) return hr;
80 hr = IDirectDrawClipper_QueryInterface(pClip, riid, ppObj);
81 IDirectDrawClipper_Release(pClip);
85 /******************************************************************************
88 HRESULT WINAPI Main_DirectDrawClipper_SetHwnd(
89 LPDIRECTDRAWCLIPPER iface, DWORD dwFlags, HWND hWnd
91 IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
93 TRACE("(%p)->(0x%08lx,0x%08lx)\n", This, dwFlags, (DWORD)hWnd);
95 FIXME("dwFlags = 0x%08lx, not supported.\n",dwFlags);
96 return DDERR_INVALIDPARAMS;
103 static void Main_DirectDrawClipper_Destroy(IDirectDrawClipperImpl* This)
105 if (This->ddraw_owner != NULL)
106 Main_DirectDraw_RemoveClipper(This->ddraw_owner, This);
108 HeapFree(GetProcessHeap(), 0 ,This);
111 void Main_DirectDrawClipper_ForceDestroy(IDirectDrawClipperImpl* This)
113 WARN("deleting clipper %p with refcnt %lu\n", This, This->ref);
114 Main_DirectDrawClipper_Destroy(This);
117 ULONG WINAPI Main_DirectDrawClipper_Release(LPDIRECTDRAWCLIPPER iface) {
118 IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
119 ULONG ref = InterlockedDecrement(&This->ref);
121 TRACE("(%p)->() decrementing from %lu.\n", This, ref + 1);
125 Main_DirectDrawClipper_Destroy(This);
131 /***********************************************************************
132 * IDirectDrawClipper::GetClipList
134 * Retrieve a copy of the clip list
137 * lpRect Rectangle to be used to clip the clip list or NULL for the
139 * lpClipList structure for the resulting copy of the clip list.
140 If NULL, fills lpdwSize up to the number of bytes necessary to hold
142 * lpdwSize Size of resulting clip list; size of the buffer at lpClipList
143 or, if lpClipList is NULL, receives the required size of the buffer
146 * Either DD_OK or DDERR_*
148 HRESULT WINAPI Main_DirectDrawClipper_GetClipList(
149 LPDIRECTDRAWCLIPPER iface, LPRECT lpRect, LPRGNDATA lpClipList,
152 IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
154 TRACE("(%p,%p,%p,%p)\n", This, lpRect, lpClipList, lpdwSize);
158 HDC hDC = GetDCEx(This->hWnd, NULL, DCX_WINDOW);
161 HRGN hRgn = CreateRectRgn(0,0,0,0);
162 if (GetRandomRgn(hDC, hRgn, SYSRGN))
166 HRGN hRgnClip = CreateRectRgn(lpRect->left, lpRect->top,
167 lpRect->right, lpRect->bottom);
168 CombineRgn(hRgn, hRgn, hRgnClip, RGN_AND);
169 DeleteObject(hRgnClip);
171 *lpdwSize = GetRegionData(hRgn, *lpdwSize, lpClipList);
174 ReleaseDC(This->hWnd, hDC);
180 static int warned = 0;
182 FIXME("(%p,%p,%p,%p),stub!\n",This,lpRect,lpClipList,lpdwSize);
183 if (lpdwSize) *lpdwSize=0;
184 return DDERR_NOCLIPLIST;
188 /***********************************************************************
189 * IDirectDrawClipper::SetClipList
191 * Sets or deletes (if lprgn is NULL) the clip list
194 * lprgn Pointer to a LRGNDATA structure or NULL
195 * dwFlags not used, must be 0
197 * Either DD_OK or DDERR_*
199 HRESULT WINAPI Main_DirectDrawClipper_SetClipList(
200 LPDIRECTDRAWCLIPPER iface,LPRGNDATA lprgn,DWORD dwFlag
202 IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
203 static int warned = 0;
204 if (warned++ < 10 || lprgn == NULL)
205 FIXME("(%p,%p,%ld),stub!\n",This,lprgn,dwFlag);
209 HRESULT WINAPI Main_DirectDrawClipper_QueryInterface(
210 LPDIRECTDRAWCLIPPER iface, REFIID riid, LPVOID* ppvObj
212 IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
214 if (IsEqualGUID(&IID_IUnknown, riid)
215 || IsEqualGUID(&IID_IDirectDrawClipper, riid))
217 *ppvObj = ICOM_INTERFACE(This, IDirectDrawClipper);
218 InterlockedIncrement(&This->ref);
223 return E_NOINTERFACE;
227 ULONG WINAPI Main_DirectDrawClipper_AddRef( LPDIRECTDRAWCLIPPER iface )
229 IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
230 ULONG ref = InterlockedIncrement(&This->ref);
232 TRACE("(%p)->() incrementing from %lu.\n", This, ref - 1);
237 HRESULT WINAPI Main_DirectDrawClipper_GetHWnd(
238 LPDIRECTDRAWCLIPPER iface, HWND* hWndPtr
240 IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
241 TRACE("(%p)->(%p)\n", This, hWndPtr);
243 *hWndPtr = This->hWnd;
248 HRESULT WINAPI Main_DirectDrawClipper_Initialize(
249 LPDIRECTDRAWCLIPPER iface, LPDIRECTDRAW lpDD, DWORD dwFlags
251 IDirectDrawImpl* pOwner;
252 IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
253 TRACE("(%p)->(%p,0x%08lx)\n", This, lpDD, dwFlags);
255 if (This->ddraw_owner != NULL) return DDERR_ALREADYINITIALIZED;
257 pOwner = ICOM_OBJECT(IDirectDrawImpl, IDirectDraw, lpDD);
258 This->ddraw_owner = pOwner;
259 Main_DirectDraw_AddClipper(pOwner, This);
264 HRESULT WINAPI Main_DirectDrawClipper_IsClipListChanged(
265 LPDIRECTDRAWCLIPPER iface, BOOL* lpbChanged
267 IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
268 FIXME("(%p)->(%p),stub!\n",This,lpbChanged);
270 /* XXX What is safest? */
276 static const IDirectDrawClipperVtbl DDRAW_Clipper_VTable =
278 Main_DirectDrawClipper_QueryInterface,
279 Main_DirectDrawClipper_AddRef,
280 Main_DirectDrawClipper_Release,
281 Main_DirectDrawClipper_GetClipList,
282 Main_DirectDrawClipper_GetHWnd,
283 Main_DirectDrawClipper_Initialize,
284 Main_DirectDrawClipper_IsClipListChanged,
285 Main_DirectDrawClipper_SetClipList,
286 Main_DirectDrawClipper_SetHwnd