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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "ddraw_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
39 /******************************************************************************
40 * DirectDrawCreateClipper (DDRAW.@)
43 static const IDirectDrawClipperVtbl DDRAW_Clipper_VTable
;
45 HRESULT WINAPI
DirectDrawCreateClipper(
46 DWORD dwFlags
, LPDIRECTDRAWCLIPPER
*lplpDDClipper
, LPUNKNOWN pUnkOuter
48 IDirectDrawClipperImpl
* This
;
49 TRACE("(%08lx,%p,%p)\n", dwFlags
, lplpDDClipper
, pUnkOuter
);
51 if (pUnkOuter
!= NULL
) return CLASS_E_NOAGGREGATION
;
53 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
54 sizeof(IDirectDrawClipperImpl
));
55 if (This
== NULL
) return E_OUTOFMEMORY
;
57 ICOM_INIT_INTERFACE(This
, IDirectDrawClipper
, DDRAW_Clipper_VTable
);
60 This
->ddraw_owner
= NULL
;
62 *lplpDDClipper
= ICOM_INTERFACE(This
, IDirectDrawClipper
);
66 /* This is the classfactory implementation. */
67 HRESULT
DDRAW_CreateDirectDrawClipper(IUnknown
* pUnkOuter
, REFIID riid
,
71 LPDIRECTDRAWCLIPPER pClip
;
73 hr
= DirectDrawCreateClipper(0, &pClip
, pUnkOuter
);
74 if (FAILED(hr
)) return hr
;
76 hr
= IDirectDrawClipper_QueryInterface(pClip
, riid
, ppObj
);
77 IDirectDrawClipper_Release(pClip
);
81 /******************************************************************************
84 HRESULT WINAPI
Main_DirectDrawClipper_SetHwnd(
85 LPDIRECTDRAWCLIPPER iface
, DWORD dwFlags
, HWND hWnd
87 IDirectDrawClipperImpl
*This
= (IDirectDrawClipperImpl
*)iface
;
89 TRACE("(%p)->(0x%08lx,0x%08lx)\n", This
, dwFlags
, (DWORD
)hWnd
);
91 FIXME("dwFlags = 0x%08lx, not supported.\n",dwFlags
);
92 return DDERR_INVALIDPARAMS
;
99 static void Main_DirectDrawClipper_Destroy(IDirectDrawClipperImpl
* This
)
101 if (This
->ddraw_owner
!= NULL
)
102 Main_DirectDraw_RemoveClipper(This
->ddraw_owner
, This
);
104 HeapFree(GetProcessHeap(), 0 ,This
);
107 void Main_DirectDrawClipper_ForceDestroy(IDirectDrawClipperImpl
* This
)
109 WARN("deleting clipper %p with refcnt %lu\n", This
, This
->ref
);
110 Main_DirectDrawClipper_Destroy(This
);
113 ULONG WINAPI
Main_DirectDrawClipper_Release(LPDIRECTDRAWCLIPPER iface
) {
114 IDirectDrawClipperImpl
*This
= (IDirectDrawClipperImpl
*)iface
;
115 ULONG ref
= InterlockedDecrement(&This
->ref
);
117 TRACE("(%p)->() decrementing from %lu.\n", This
, ref
+ 1);
121 Main_DirectDrawClipper_Destroy(This
);
127 /***********************************************************************
128 * IDirectDrawClipper::GetClipList
130 * Retrieve a copy of the clip list
133 * lpRect Rectangle to be used to clip the clip list or NULL for the
135 * lpClipList structure for the resulting copy of the clip list.
136 If NULL, fills lpdwSize up to the number of bytes necessary to hold
138 * lpdwSize Size of resulting clip list; size of the buffer at lpClipList
139 or, if lpClipList is NULL, receives the required size of the buffer
142 * Either DD_OK or DDERR_*
144 HRESULT WINAPI
Main_DirectDrawClipper_GetClipList(
145 LPDIRECTDRAWCLIPPER iface
, LPRECT lpRect
, LPRGNDATA lpClipList
,
148 IDirectDrawClipperImpl
*This
= (IDirectDrawClipperImpl
*)iface
;
150 TRACE("(%p,%p,%p,%p)\n", This
, lpRect
, lpClipList
, lpdwSize
);
154 HDC hDC
= GetDCEx(This
->hWnd
, NULL
, DCX_WINDOW
);
157 HRGN hRgn
= CreateRectRgn(0,0,0,0);
158 if (GetRandomRgn(hDC
, hRgn
, SYSRGN
))
160 if (GetVersion() & 0x80000000)
162 /* map region to screen coordinates */
164 GetDCOrgEx( hDC
, &org
);
165 OffsetRgn( hRgn
, org
.x
, org
.y
);
169 HRGN hRgnClip
= CreateRectRgn(lpRect
->left
, lpRect
->top
,
170 lpRect
->right
, lpRect
->bottom
);
171 CombineRgn(hRgn
, hRgn
, hRgnClip
, RGN_AND
);
172 DeleteObject(hRgnClip
);
174 *lpdwSize
= GetRegionData(hRgn
, *lpdwSize
, lpClipList
);
177 ReleaseDC(This
->hWnd
, hDC
);
183 static int warned
= 0;
185 FIXME("(%p,%p,%p,%p),stub!\n",This
,lpRect
,lpClipList
,lpdwSize
);
186 if (lpdwSize
) *lpdwSize
=0;
187 return DDERR_NOCLIPLIST
;
191 /***********************************************************************
192 * IDirectDrawClipper::SetClipList
194 * Sets or deletes (if lprgn is NULL) the clip list
197 * lprgn Pointer to a LRGNDATA structure or NULL
198 * dwFlags not used, must be 0
200 * Either DD_OK or DDERR_*
202 HRESULT WINAPI
Main_DirectDrawClipper_SetClipList(
203 LPDIRECTDRAWCLIPPER iface
,LPRGNDATA lprgn
,DWORD dwFlag
205 IDirectDrawClipperImpl
*This
= (IDirectDrawClipperImpl
*)iface
;
206 static int warned
= 0;
207 if (warned
++ < 10 || lprgn
== NULL
)
208 FIXME("(%p,%p,%ld),stub!\n",This
,lprgn
,dwFlag
);
212 HRESULT WINAPI
Main_DirectDrawClipper_QueryInterface(
213 LPDIRECTDRAWCLIPPER iface
, REFIID riid
, LPVOID
* ppvObj
215 IDirectDrawClipperImpl
*This
= (IDirectDrawClipperImpl
*)iface
;
217 if (IsEqualGUID(&IID_IUnknown
, riid
)
218 || IsEqualGUID(&IID_IDirectDrawClipper
, riid
))
220 *ppvObj
= ICOM_INTERFACE(This
, IDirectDrawClipper
);
221 InterlockedIncrement(&This
->ref
);
226 return E_NOINTERFACE
;
230 ULONG WINAPI
Main_DirectDrawClipper_AddRef( LPDIRECTDRAWCLIPPER iface
)
232 IDirectDrawClipperImpl
*This
= (IDirectDrawClipperImpl
*)iface
;
233 ULONG ref
= InterlockedIncrement(&This
->ref
);
235 TRACE("(%p)->() incrementing from %lu.\n", This
, ref
- 1);
240 HRESULT WINAPI
Main_DirectDrawClipper_GetHWnd(
241 LPDIRECTDRAWCLIPPER iface
, HWND
* hWndPtr
243 IDirectDrawClipperImpl
*This
= (IDirectDrawClipperImpl
*)iface
;
244 TRACE("(%p)->(%p)\n", This
, hWndPtr
);
246 *hWndPtr
= This
->hWnd
;
251 HRESULT WINAPI
Main_DirectDrawClipper_Initialize(
252 LPDIRECTDRAWCLIPPER iface
, LPDIRECTDRAW lpDD
, DWORD dwFlags
254 IDirectDrawImpl
* pOwner
;
255 IDirectDrawClipperImpl
*This
= (IDirectDrawClipperImpl
*)iface
;
256 TRACE("(%p)->(%p,0x%08lx)\n", This
, lpDD
, dwFlags
);
258 if (This
->ddraw_owner
!= NULL
) return DDERR_ALREADYINITIALIZED
;
260 pOwner
= ICOM_OBJECT(IDirectDrawImpl
, IDirectDraw
, lpDD
);
261 This
->ddraw_owner
= pOwner
;
262 Main_DirectDraw_AddClipper(pOwner
, This
);
267 HRESULT WINAPI
Main_DirectDrawClipper_IsClipListChanged(
268 LPDIRECTDRAWCLIPPER iface
, BOOL
* lpbChanged
270 IDirectDrawClipperImpl
*This
= (IDirectDrawClipperImpl
*)iface
;
271 FIXME("(%p)->(%p),stub!\n",This
,lpbChanged
);
273 /* XXX What is safest? */
279 static const IDirectDrawClipperVtbl DDRAW_Clipper_VTable
=
281 Main_DirectDrawClipper_QueryInterface
,
282 Main_DirectDrawClipper_AddRef
,
283 Main_DirectDrawClipper_Release
,
284 Main_DirectDrawClipper_GetClipList
,
285 Main_DirectDrawClipper_GetHWnd
,
286 Main_DirectDrawClipper_Initialize
,
287 Main_DirectDrawClipper_IsClipListChanged
,
288 Main_DirectDrawClipper_SetClipList
,
289 Main_DirectDrawClipper_SetHwnd