clipper.c 9.91 KB
Newer Older
1
/* DirectDrawClipper implementation
2
 *
3 4 5
 * Copyright 2000 (c) Marcus Meissner
 * Copyright 2000 (c) TransGaming Technologies Inc.
 * Copyright 2006 (c) Stefan Dsinger
6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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 23
 */

#include "config.h"

24
#include <stdarg.h>
25
#include <stdlib.h>
26
#include <string.h>
27

28 29 30
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
31
#include "ddraw.h"
32
#include "winerror.h"
33

34 35
#include "ddraw_private.h"

36
#include "wine/debug.h"
37

38
WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
39

40 41 42
/*****************************************************************************
 * IUnknown methods
 *****************************************************************************/
43

44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
/*****************************************************************************
 * IDirectDrawClipper::QueryInterface
 *
 * Can query the IUnknown and IDirectDrawClipper interface from a
 * Clipper object. The IUnknown Interface is equal to the IDirectDrawClipper
 * interface. Can't create other interfaces.
 *
 * Arguments:
 *  riid: Interface id asked for
 *  ppvObj: Returns the pointer to the interface
 *
 * Return values:
 *  DD_OK on success
 *  E_NOINTERFACE if the requested interface wasn't found.
 *
 *****************************************************************************/
static HRESULT WINAPI IDirectDrawClipperImpl_QueryInterface(
    LPDIRECTDRAWCLIPPER iface, REFIID riid, LPVOID* ppvObj
62
) {
63
    IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
64

65 66 67 68 69 70 71 72 73 74 75 76
    if (IsEqualGUID(&IID_IUnknown, riid)
	|| IsEqualGUID(&IID_IDirectDrawClipper, riid))
    {
	*ppvObj = ICOM_INTERFACE(This, IDirectDrawClipper);
	InterlockedIncrement(&This->ref);
	return S_OK;
    }
    else
    {
	return E_NOINTERFACE;
    }
}
77

78 79 80 81 82 83 84 85 86 87
/*****************************************************************************
 * IDirectDrawClipper::AddRef
 *
 * Increases the reference count of the interface, returns the new count
 *
 *****************************************************************************/
static ULONG WINAPI IDirectDrawClipperImpl_AddRef( LPDIRECTDRAWCLIPPER iface )
{
    IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
    ULONG ref = InterlockedIncrement(&This->ref);
88

89
    TRACE("(%p)->() incrementing from %u.\n", This, ref - 1);
90

91
    return ref;
92 93
}

94 95 96 97 98 99 100 101 102 103
/*****************************************************************************
 * IDirectDrawClipper::Release
 *
 * Decreases the reference count of the interface, returns the new count
 * If the refcount is decreased to 0, the interface is destroyed.
 *
 *****************************************************************************/
static ULONG WINAPI IDirectDrawClipperImpl_Release(IDirectDrawClipper *iface) {
    IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
    ULONG ref = InterlockedDecrement(&This->ref);
104

105
    TRACE("(%p)->() decrementing from %u.\n", This, ref + 1);
106

107 108
    if (ref == 0)
    {
109
        EnterCriticalSection(&ddraw_cs);
110 111
        IWineD3DClipper_Release(This->wineD3DClipper);
        HeapFree(GetProcessHeap(), 0, This);
112
        LeaveCriticalSection(&ddraw_cs);
113
        return 0;
114 115
    }
    else return ref;
116 117
}

118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
/*****************************************************************************
 * IDirectDrawClipper::SetHwnd
 *
 * Assigns a hWnd to the clipper interface.
 *
 * Arguments:
 *  Flags: Unsupported so far
 *  hWnd: The hWnd to set
 *
 * Return values:
 *  DD_OK on success
 *  DDERR_INVALIDPARAMS if Flags was != 0
 *
 *****************************************************************************/

static HRESULT WINAPI IDirectDrawClipperImpl_SetHwnd(
134 135
    LPDIRECTDRAWCLIPPER iface, DWORD dwFlags, HWND hWnd
) {
136
    IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
137 138
    HRESULT hr;
    TRACE("(%p)->(%08x,%p)\n", This, dwFlags, hWnd);
139

140
    EnterCriticalSection(&ddraw_cs);
141 142 143
    hr = IWineD3DClipper_SetHWnd(This->wineD3DClipper,
                                 dwFlags,
                                 hWnd);
144
    LeaveCriticalSection(&ddraw_cs);
145 146 147 148
    switch(hr)
    {
        case WINED3DERR_INVALIDCALL:        return DDERR_INVALIDPARAMS;
        default:                            return hr;
149 150 151
    }
}

152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
/*****************************************************************************
 * IDirectDrawClipper::GetClipList
 *
 * Retrieve a copy of the clip list
 *
 * Arguments:
 *  Rect: Rectangle to be used to clip the clip list or NULL for the
 *        entire clip list
 *  ClipList: structure for the resulting copy of the clip list.
 *            If NULL, fills Size up to the number of bytes necessary to hold
 *            the entire clip.
 *  Size: Size of resulting clip list; size of the buffer at ClipList
 *        or, if ClipList is NULL, receives the required size of the buffer
 *        in bytes
 *
 * RETURNS
 *  Either DD_OK or DDERR_*
 ************************************************************************/
static HRESULT WINAPI IDirectDrawClipperImpl_GetClipList(
171
    LPDIRECTDRAWCLIPPER iface, LPRECT lpRect, LPRGNDATA lpClipList,
172 173
    LPDWORD lpdwSize)
{
174
    IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
175
    HRESULT hr;
Christian Costa's avatar
Christian Costa committed
176
    TRACE("(%p,%p,%p,%p)\n", This, lpRect, lpClipList, lpdwSize);
177

178 179 180 181 182 183 184
    EnterCriticalSection(&ddraw_cs);
    hr = IWineD3DClipper_GetClipList(This->wineD3DClipper,
                                     lpRect,
                                     lpClipList,
                                     lpdwSize);
    LeaveCriticalSection(&ddraw_cs);
    return hr;
185 186
}

187 188 189 190 191
/*****************************************************************************
 * IDirectDrawClipper::SetClipList
 *
 * Sets or deletes (if lprgn is NULL) the clip list
 *
192
 * This implementation is a stub and returns DD_OK always to make the app
193 194 195 196 197 198 199 200 201
 * happy.
 *
 * PARAMS
 *  lprgn   Pointer to a LRGNDATA structure or NULL
 *  dwFlags not used, must be 0
 * RETURNS
 *  Either DD_OK or DDERR_*
 *****************************************************************************/
static HRESULT WINAPI IDirectDrawClipperImpl_SetClipList(
202
    LPDIRECTDRAWCLIPPER iface,LPRGNDATA lprgn,DWORD dwFlag
203
) {
204
    IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
205
    HRESULT hr;
206

207 208 209 210 211 212
    EnterCriticalSection(&ddraw_cs);
    hr = IWineD3DClipper_SetClipList(This->wineD3DClipper,
                                     lprgn,
                                     dwFlag);
    LeaveCriticalSection(&ddraw_cs);
    return hr;
213 214
}

215 216 217 218 219 220 221 222 223 224 225 226
/*****************************************************************************
 * IDirectDrawClipper::GetHwnd
 *
 * Returns the hwnd assigned with SetHwnd
 *
 * Arguments:
 *  hWndPtr: Address to store the HWND at
 *
 * Return values:
 *  Always returns DD_OK;
 *****************************************************************************/
static HRESULT WINAPI IDirectDrawClipperImpl_GetHWnd(
227 228
    LPDIRECTDRAWCLIPPER iface, HWND* hWndPtr
) {
229
    IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
230
    HRESULT hr;
Christian Costa's avatar
Christian Costa committed
231
    TRACE("(%p)->(%p)\n", This, hWndPtr);
232

233 234 235 236 237
    EnterCriticalSection(&ddraw_cs);
    hr =  IWineD3DClipper_GetHWnd(This->wineD3DClipper,
                                  hWndPtr);
    LeaveCriticalSection(&ddraw_cs);
    return hr;
238 239
}

240 241 242 243 244 245 246 247 248 249 250 251
/*****************************************************************************
 * IDirectDrawClipper::Initialize
 *
 * Initializes the interface. Well, there isn't much to do for this
 * implementation, but it stores the DirectDraw Interface.
 *
 * Arguments:
 *  DD: Pointer to a IDirectDraw interface
 *  Flags: Unsupported by now
 *
 * Return values:
 *  DD_OK on success
252
 *  DDERR_ALREADYINITIALIZED if this interface isn't initialized already
253 254
 *****************************************************************************/
static HRESULT WINAPI IDirectDrawClipperImpl_Initialize(
255 256
     LPDIRECTDRAWCLIPPER iface, LPDIRECTDRAW lpDD, DWORD dwFlags
) {
257
    IDirectDrawImpl* pOwner;
258
    IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
259
    TRACE("(%p)->(%p,0x%08x)\n", This, lpDD, dwFlags);
260

261 262 263 264 265 266
    EnterCriticalSection(&ddraw_cs);
    if (This->ddraw_owner != NULL)
    {
        LeaveCriticalSection(&ddraw_cs);
        return DDERR_ALREADYINITIALIZED;
    }
267 268 269 270

    pOwner = ICOM_OBJECT(IDirectDrawImpl, IDirectDraw, lpDD);
    This->ddraw_owner = pOwner;

271
    LeaveCriticalSection(&ddraw_cs);
272 273 274
    return DD_OK;
}

275 276 277 278 279 280 281 282 283 284 285 286
/*****************************************************************************
 * IDirectDrawClipper::IsClipListChanged
 *
 * This function is a stub
 *
 * Arguments:
 *  Changed:
 *
 * Return values:
 *  DD_OK, because it's a stub
 *****************************************************************************/
static HRESULT WINAPI IDirectDrawClipperImpl_IsClipListChanged(
287 288
    LPDIRECTDRAWCLIPPER iface, BOOL* lpbChanged
) {
289
    IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
290
    FIXME("(%p)->(%p),stub!\n",This,lpbChanged);
291 292 293 294

    /* XXX What is safest? */
    *lpbChanged = FALSE;

295 296 297
    return DD_OK;
}

298 299 300 301
/*****************************************************************************
 * The VTable
 *****************************************************************************/
const IDirectDrawClipperVtbl IDirectDrawClipper_Vtbl =
302
{
303 304 305 306 307 308 309 310 311
    IDirectDrawClipperImpl_QueryInterface,
    IDirectDrawClipperImpl_AddRef,
    IDirectDrawClipperImpl_Release,
    IDirectDrawClipperImpl_GetClipList,
    IDirectDrawClipperImpl_GetHWnd,
    IDirectDrawClipperImpl_Initialize,
    IDirectDrawClipperImpl_IsClipListChanged,
    IDirectDrawClipperImpl_SetClipList,
    IDirectDrawClipperImpl_SetHwnd
312
};