texture.c 9.95 KB
Newer Older
1 2 3
/*
 * IDirect3DTexture8 implementation
 *
4
 * Copyright 2005 Oliver Stieber
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * 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
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20
 */

21
#include "config.h"
22 23
#include "d3d8_private.h"

24 25
WINE_DEFAULT_DEBUG_CHANNEL(d3d8);

26
/* IDirect3DTexture8 IUnknown parts follow: */
27
static HRESULT WINAPI IDirect3DTexture8Impl_QueryInterface(LPDIRECT3DTEXTURE8 iface, REFIID riid, LPVOID *ppobj) {
28
    IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
29

30
    if (IsEqualGUID(riid, &IID_IUnknown)
Raphael Junqueira's avatar
Raphael Junqueira committed
31 32 33
        || IsEqualGUID(riid, &IID_IDirect3DResource8)
        || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
        || IsEqualGUID(riid, &IID_IDirect3DTexture8)) {
34
        IUnknown_AddRef(iface);
35
        *ppobj = This;
H. Verbeet's avatar
H. Verbeet committed
36
        return S_OK;
37 38
    }

Raphael Junqueira's avatar
Raphael Junqueira committed
39
    WARN("(%p)->(%s,%p) not found\n", This, debugstr_guid(riid), ppobj);
H. Verbeet's avatar
H. Verbeet committed
40
    *ppobj = NULL;
41 42 43
    return E_NOINTERFACE;
}

44
static ULONG WINAPI IDirect3DTexture8Impl_AddRef(LPDIRECT3DTEXTURE8 iface) {
45
    IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
46 47
    ULONG ref = InterlockedIncrement(&This->ref);

48
    TRACE("(%p) : AddRef from %d\n", This, ref - 1);
49 50

    return ref;
51 52
}

53
static ULONG WINAPI IDirect3DTexture8Impl_Release(LPDIRECT3DTEXTURE8 iface) {
54
    IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
55
    ULONG ref = InterlockedDecrement(&This->ref);
56

57
    TRACE("(%p) : ReleaseRef to %d\n", This, ref);
58

59
    if (ref == 0) {
60
        wined3d_mutex_lock();
61
        IWineD3DTexture_Destroy(This->wineD3DTexture, D3D8CB_DestroySurface);
62 63
        wined3d_mutex_unlock();

64
        IUnknown_Release(This->parentDevice);
65 66 67 68 69 70
        HeapFree(GetProcessHeap(), 0, This);
    }
    return ref;
}

/* IDirect3DTexture8 IDirect3DResource8 Interface follow: */
71
static HRESULT WINAPI IDirect3DTexture8Impl_GetDevice(LPDIRECT3DTEXTURE8 iface, IDirect3DDevice8 **ppDevice) {
72
    IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
73
    IWineD3DDevice *wined3d_device;
74
    HRESULT hr;
75
    TRACE("(%p) Relay\n", This);
76 77

    wined3d_mutex_lock();
78 79 80 81 82 83
    hr = IWineD3DTexture_GetDevice(This->wineD3DTexture, &wined3d_device);
    if (SUCCEEDED(hr))
    {
        IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
        IWineD3DDevice_Release(wined3d_device);
    }
84 85
    wined3d_mutex_unlock();

86
    return hr;
87
}
88

89
static HRESULT WINAPI IDirect3DTexture8Impl_SetPrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
90
    IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
91
    HRESULT hr;
92
    TRACE("(%p) Relay\n", This);
93

94
    wined3d_mutex_lock();
95
    hr = IWineD3DTexture_SetPrivateData(This->wineD3DTexture, refguid, pData, SizeOfData, Flags);
96 97
    wined3d_mutex_unlock();

98
    return hr;
99
}
100

101
static HRESULT WINAPI IDirect3DTexture8Impl_GetPrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid, void *pData, DWORD* pSizeOfData) {
102
    IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
103
    HRESULT hr;
104
    TRACE("(%p) Relay\n", This);
105

106
    wined3d_mutex_lock();
107
    hr = IWineD3DTexture_GetPrivateData(This->wineD3DTexture, refguid, pData, pSizeOfData);
108 109
    wined3d_mutex_unlock();

110
    return hr;
111
}
112

113
static HRESULT WINAPI IDirect3DTexture8Impl_FreePrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid) {
114
    IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
115
    HRESULT hr;
116
    TRACE("(%p) Relay\n", This);
117

118
    wined3d_mutex_lock();
119
    hr = IWineD3DTexture_FreePrivateData(This->wineD3DTexture, refguid);
120 121
    wined3d_mutex_unlock();

122
    return hr;
123
}
124

125
static DWORD WINAPI IDirect3DTexture8Impl_SetPriority(LPDIRECT3DTEXTURE8 iface, DWORD PriorityNew) {
126
    IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
127
    DWORD ret;
128
    TRACE("(%p) Relay\n", This);
129

130
    wined3d_mutex_lock();
131
    ret = IWineD3DTexture_SetPriority(This->wineD3DTexture, PriorityNew);
132 133
    wined3d_mutex_unlock();

134
    return ret;
135
}
136

137
static DWORD WINAPI IDirect3DTexture8Impl_GetPriority(LPDIRECT3DTEXTURE8 iface) {
138
    IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
139
    DWORD ret;
140
    TRACE("(%p) Relay\n", This);
141

142
    wined3d_mutex_lock();
143
    ret = IWineD3DTexture_GetPriority(This->wineD3DTexture);
144 145
    wined3d_mutex_unlock();

146
    return ret;
147
}
148

149
static void WINAPI IDirect3DTexture8Impl_PreLoad(LPDIRECT3DTEXTURE8 iface) {
150
    IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
151
    TRACE("(%p) Relay\n", This);
152

153
    wined3d_mutex_lock();
154
    IWineD3DTexture_PreLoad(This->wineD3DTexture);
155
    wined3d_mutex_unlock();
156
}
157

158
static D3DRESOURCETYPE WINAPI IDirect3DTexture8Impl_GetType(LPDIRECT3DTEXTURE8 iface) {
159
    IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
160
    D3DRESOURCETYPE type;
161
    TRACE("(%p) Relay\n", This);
162

163
    wined3d_mutex_lock();
164
    type = IWineD3DTexture_GetType(This->wineD3DTexture);
165 166
    wined3d_mutex_unlock();

167
    return type;
168 169
}

170
/* IDirect3DTexture8 IDirect3DBaseTexture8 Interface follow: */
171
static DWORD WINAPI IDirect3DTexture8Impl_SetLOD(LPDIRECT3DTEXTURE8 iface, DWORD LODNew) {
172
    IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
173
    DWORD ret;
174
    TRACE("(%p) Relay\n", This);
175

176
    wined3d_mutex_lock();
177
    ret = IWineD3DTexture_SetLOD(This->wineD3DTexture, LODNew);
178 179
    wined3d_mutex_unlock();

180
    return ret;
181
}
182

183
static DWORD WINAPI IDirect3DTexture8Impl_GetLOD(LPDIRECT3DTEXTURE8 iface) {
184
    IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
185
    DWORD ret;
186
    TRACE("(%p) Relay\n", This);
187

188
    wined3d_mutex_lock();
189
    ret = IWineD3DTexture_GetLOD(This->wineD3DTexture);
190 191
    wined3d_mutex_unlock();

192
    return ret;
193
}
194

195
static DWORD WINAPI IDirect3DTexture8Impl_GetLevelCount(LPDIRECT3DTEXTURE8 iface) {
196
    IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
197
    DWORD ret;
198
    TRACE("(%p) Relay\n", This);
199

200
    wined3d_mutex_lock();
201
    ret = IWineD3DTexture_GetLevelCount(This->wineD3DTexture);
202 203
    wined3d_mutex_unlock();

204
    return ret;
205 206
}

207
/* IDirect3DTexture8 Interface follow: */
208
static HRESULT WINAPI IDirect3DTexture8Impl_GetLevelDesc(LPDIRECT3DTEXTURE8 iface, UINT Level, D3DSURFACE_DESC *pDesc) {
209
    IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
210
    HRESULT hr;
211

212 213 214
    WINED3DSURFACE_DESC    wined3ddesc;
    TRACE("(%p) Relay\n", This);

215
    wined3d_mutex_lock();
216
    hr = IWineD3DTexture_GetLevelDesc(This->wineD3DTexture, Level, &wined3ddesc);
217
    wined3d_mutex_unlock();
218

219 220 221 222 223 224 225 226 227 228 229
    if (SUCCEEDED(hr))
    {
        pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.format);
        pDesc->Type = wined3ddesc.resource_type;
        pDesc->Usage = wined3ddesc.usage;
        pDesc->Pool = wined3ddesc.pool;
        pDesc->Size = wined3ddesc.size;
        pDesc->MultiSampleType = wined3ddesc.multisample_type;
        pDesc->Width = wined3ddesc.width;
        pDesc->Height = wined3ddesc.height;
    }
230

231
    return hr;
232
}
233

234
static HRESULT WINAPI IDirect3DTexture8Impl_GetSurfaceLevel(LPDIRECT3DTEXTURE8 iface, UINT Level, IDirect3DSurface8 **ppSurfaceLevel) {
235
    IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
236 237 238 239
    HRESULT hrc = D3D_OK;
    IWineD3DSurface *mySurface = NULL;

    TRACE("(%p) Relay\n", This);
240 241

    wined3d_mutex_lock();
242 243 244 245
    hrc = IWineD3DTexture_GetSurfaceLevel(This->wineD3DTexture, Level, &mySurface);
    if (hrc == D3D_OK && NULL != ppSurfaceLevel) {
       IWineD3DSurface_GetParent(mySurface, (IUnknown **)ppSurfaceLevel);
       IWineD3DSurface_Release(mySurface);
246
    }
247 248
    wined3d_mutex_unlock();

249
    return hrc;
250
}
251

252
static HRESULT WINAPI IDirect3DTexture8Impl_LockRect(LPDIRECT3DTEXTURE8 iface, UINT Level, D3DLOCKED_RECT *pLockedRect, CONST RECT *pRect, DWORD Flags) {
253
    IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
254
    HRESULT hr;
255
    TRACE("(%p) Relay\n", This);
256

257
    wined3d_mutex_lock();
258
    hr = IWineD3DTexture_LockRect(This->wineD3DTexture, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
259 260
    wined3d_mutex_unlock();

261
    return hr;
262
}
263

264
static HRESULT WINAPI IDirect3DTexture8Impl_UnlockRect(LPDIRECT3DTEXTURE8 iface, UINT Level) {
265
    IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
266
    HRESULT hr;
267
    TRACE("(%p) Relay\n", This);
268

269
    wined3d_mutex_lock();
270
    hr = IWineD3DTexture_UnlockRect(This->wineD3DTexture, Level);
271 272
    wined3d_mutex_unlock();

273
    return hr;
274 275
}

276
static HRESULT WINAPI IDirect3DTexture8Impl_AddDirtyRect(LPDIRECT3DTEXTURE8 iface, CONST RECT *pDirtyRect) {
277
    IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
278
    HRESULT hr;
279
    TRACE("(%p) Relay\n", This);
280

281
    wined3d_mutex_lock();
282
    hr = IWineD3DTexture_AddDirtyRect(This->wineD3DTexture, pDirtyRect);
283 284
    wined3d_mutex_unlock();

285
    return hr;
286
}
287

288
const IDirect3DTexture8Vtbl Direct3DTexture8_Vtbl =
289
{
290
    /* IUnknown */
291 292 293
    IDirect3DTexture8Impl_QueryInterface,
    IDirect3DTexture8Impl_AddRef,
    IDirect3DTexture8Impl_Release,
294
     /* IDirect3DResource8 */
295 296 297 298 299 300 301 302
    IDirect3DTexture8Impl_GetDevice,
    IDirect3DTexture8Impl_SetPrivateData,
    IDirect3DTexture8Impl_GetPrivateData,
    IDirect3DTexture8Impl_FreePrivateData,
    IDirect3DTexture8Impl_SetPriority,
    IDirect3DTexture8Impl_GetPriority,
    IDirect3DTexture8Impl_PreLoad,
    IDirect3DTexture8Impl_GetType,
303
    /* IDirect3dBaseTexture8 */
304 305 306
    IDirect3DTexture8Impl_SetLOD,
    IDirect3DTexture8Impl_GetLOD,
    IDirect3DTexture8Impl_GetLevelCount,
307
    /* IDirect3DTexture8 */
308 309 310 311 312 313
    IDirect3DTexture8Impl_GetLevelDesc,
    IDirect3DTexture8Impl_GetSurfaceLevel,
    IDirect3DTexture8Impl_LockRect,
    IDirect3DTexture8Impl_UnlockRect,
    IDirect3DTexture8Impl_AddDirtyRect
};