wined3d: Don't free D3D cube textures until the wined3d cube texture is destroyed.
[wine/multimedia.git] / dlls / d3d9 / cubetexture.c
blob4bab9dfd021ce30dc9521fa24e0c8e1663520712
1 /*
2 * IDirect3DCubeTexture9 implementation
4 * Copyright 2002-2005 Jason Edmeades
5 * Copyright 2002-2005 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
24 #include "d3d9_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
29 /* IDirect3DCubeTexture9 IUnknown parts follow: */
30 static HRESULT WINAPI IDirect3DCubeTexture9Impl_QueryInterface(LPDIRECT3DCUBETEXTURE9 iface, REFIID riid, LPVOID* ppobj) {
31 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
32 if (IsEqualGUID(riid, &IID_IUnknown)
33 || IsEqualGUID(riid, &IID_IDirect3DResource9)
34 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
35 || IsEqualGUID(riid, &IID_IDirect3DCubeTexture9)) {
36 IDirect3DCubeTexture9_AddRef(iface);
37 *ppobj = This;
38 return S_OK;
41 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
42 *ppobj = NULL;
43 return E_NOINTERFACE;
46 static ULONG WINAPI IDirect3DCubeTexture9Impl_AddRef(LPDIRECT3DCUBETEXTURE9 iface) {
47 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
48 ULONG ref = InterlockedIncrement(&This->ref);
50 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
52 if (ref == 1)
54 IDirect3DDevice9Ex_AddRef(This->parentDevice);
55 wined3d_mutex_lock();
56 IWineD3DCubeTexture_AddRef(This->wineD3DCubeTexture);
57 wined3d_mutex_unlock();
60 return ref;
63 static ULONG WINAPI IDirect3DCubeTexture9Impl_Release(LPDIRECT3DCUBETEXTURE9 iface) {
64 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
65 ULONG ref = InterlockedDecrement(&This->ref);
67 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
69 if (ref == 0) {
70 TRACE("Releasing child %p\n", This->wineD3DCubeTexture);
72 IDirect3DDevice9Ex_Release(This->parentDevice);
73 wined3d_mutex_lock();
74 IWineD3DCubeTexture_Release(This->wineD3DCubeTexture);
75 wined3d_mutex_unlock();
77 return ref;
80 /* IDirect3DCubeTexture9 IDirect3DResource9 Interface follow: */
81 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetDevice(LPDIRECT3DCUBETEXTURE9 iface, IDirect3DDevice9** ppDevice) {
82 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
83 IWineD3DDevice *wined3d_device;
84 HRESULT hr;
85 TRACE("(%p) Relay\n" , This);
87 wined3d_mutex_lock();
88 hr = IWineD3DCubeTexture_GetDevice(This->wineD3DCubeTexture, &wined3d_device);
89 if (SUCCEEDED(hr))
91 IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
92 IWineD3DDevice_Release(wined3d_device);
94 wined3d_mutex_unlock();
96 return hr;
99 static HRESULT WINAPI IDirect3DCubeTexture9Impl_SetPrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
100 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
101 HRESULT hr;
102 TRACE("(%p) Relay\n", This);
104 wined3d_mutex_lock();
105 hr = IWineD3DCubeTexture_SetPrivateData(This->wineD3DCubeTexture,refguid,pData,SizeOfData,Flags);
106 wined3d_mutex_unlock();
108 return hr;
111 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetPrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
112 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
113 HRESULT hr;
114 TRACE("(%p) Relay\n", This);
116 wined3d_mutex_lock();
117 hr = IWineD3DCubeTexture_GetPrivateData(This->wineD3DCubeTexture,refguid,pData,pSizeOfData);
118 wined3d_mutex_unlock();
120 return hr;
123 static HRESULT WINAPI IDirect3DCubeTexture9Impl_FreePrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid) {
124 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
125 HRESULT hr;
126 TRACE("(%p) Relay\n", This);
128 wined3d_mutex_lock();
129 hr = IWineD3DCubeTexture_FreePrivateData(This->wineD3DCubeTexture,refguid);
130 wined3d_mutex_unlock();
132 return hr;
135 static DWORD WINAPI IDirect3DCubeTexture9Impl_SetPriority(LPDIRECT3DCUBETEXTURE9 iface, DWORD PriorityNew) {
136 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
137 DWORD ret;
138 TRACE("(%p) Relay\n", This);
140 wined3d_mutex_lock();
141 ret = IWineD3DCubeTexture_SetPriority(This->wineD3DCubeTexture, PriorityNew);
142 wined3d_mutex_unlock();
144 return ret;
147 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetPriority(LPDIRECT3DCUBETEXTURE9 iface) {
148 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
149 DWORD ret;
150 TRACE("(%p) Relay\n", This);
152 wined3d_mutex_lock();
153 ret = IWineD3DCubeTexture_GetPriority(This->wineD3DCubeTexture);
154 wined3d_mutex_unlock();
156 return ret;
159 static void WINAPI IDirect3DCubeTexture9Impl_PreLoad(LPDIRECT3DCUBETEXTURE9 iface) {
160 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
161 TRACE("(%p) Relay\n", This);
163 wined3d_mutex_lock();
164 IWineD3DCubeTexture_PreLoad(This->wineD3DCubeTexture);
165 wined3d_mutex_unlock();
168 static D3DRESOURCETYPE WINAPI IDirect3DCubeTexture9Impl_GetType(LPDIRECT3DCUBETEXTURE9 iface) {
169 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
170 D3DRESOURCETYPE ret;
171 TRACE("(%p) Relay\n", This);
173 wined3d_mutex_lock();
174 ret = IWineD3DCubeTexture_GetType(This->wineD3DCubeTexture);
175 wined3d_mutex_unlock();
177 return ret;
180 /* IDirect3DCubeTexture9 IDirect3DBaseTexture9 Interface follow: */
181 static DWORD WINAPI IDirect3DCubeTexture9Impl_SetLOD(LPDIRECT3DCUBETEXTURE9 iface, DWORD LODNew) {
182 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
183 DWORD ret;
184 TRACE("(%p) Relay\n", This);
186 wined3d_mutex_lock();
187 ret = IWineD3DCubeTexture_SetLOD(This->wineD3DCubeTexture, LODNew);
188 wined3d_mutex_unlock();
190 return ret;
193 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetLOD(LPDIRECT3DCUBETEXTURE9 iface) {
194 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
195 DWORD ret;
196 TRACE("(%p) Relay\n", This);
198 wined3d_mutex_lock();
199 ret = IWineD3DCubeTexture_GetLOD(This->wineD3DCubeTexture);
200 wined3d_mutex_unlock();
202 return ret;
205 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetLevelCount(LPDIRECT3DCUBETEXTURE9 iface) {
206 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
207 DWORD ret;
208 TRACE("(%p) Relay\n", This);
210 wined3d_mutex_lock();
211 ret = IWineD3DCubeTexture_GetLevelCount(This->wineD3DCubeTexture);
212 wined3d_mutex_unlock();
214 return ret;
217 static HRESULT WINAPI IDirect3DCubeTexture9Impl_SetAutoGenFilterType(LPDIRECT3DCUBETEXTURE9 iface, D3DTEXTUREFILTERTYPE FilterType) {
218 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
219 HRESULT hr;
220 TRACE("(%p) Relay\n", This);
222 wined3d_mutex_lock();
223 hr = IWineD3DCubeTexture_SetAutoGenFilterType(This->wineD3DCubeTexture, (WINED3DTEXTUREFILTERTYPE) FilterType);
224 wined3d_mutex_unlock();
226 return hr;
229 static D3DTEXTUREFILTERTYPE WINAPI IDirect3DCubeTexture9Impl_GetAutoGenFilterType(LPDIRECT3DCUBETEXTURE9 iface) {
230 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
231 D3DTEXTUREFILTERTYPE ret;
232 TRACE("(%p) Relay\n", This);
234 wined3d_mutex_lock();
235 ret = (D3DTEXTUREFILTERTYPE) IWineD3DCubeTexture_GetAutoGenFilterType(This->wineD3DCubeTexture);
236 wined3d_mutex_unlock();
238 return ret;
241 static void WINAPI IDirect3DCubeTexture9Impl_GenerateMipSubLevels(LPDIRECT3DCUBETEXTURE9 iface) {
242 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
243 TRACE("(%p) Relay\n", This);
245 wined3d_mutex_lock();
246 IWineD3DCubeTexture_GenerateMipSubLevels(This->wineD3DCubeTexture);
247 wined3d_mutex_unlock();
250 /* IDirect3DCubeTexture9 Interface follow: */
251 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetLevelDesc(LPDIRECT3DCUBETEXTURE9 iface, UINT Level, D3DSURFACE_DESC* pDesc) {
252 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
253 WINED3DSURFACE_DESC wined3ddesc;
254 HRESULT hr;
256 TRACE("(%p) Relay\n", This);
258 wined3d_mutex_lock();
259 hr = IWineD3DCubeTexture_GetLevelDesc(This->wineD3DCubeTexture, Level, &wined3ddesc);
260 wined3d_mutex_unlock();
262 if (SUCCEEDED(hr))
264 pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.format);
265 pDesc->Type = wined3ddesc.resource_type;
266 pDesc->Usage = wined3ddesc.usage;
267 pDesc->Pool = wined3ddesc.pool;
268 pDesc->MultiSampleType = wined3ddesc.multisample_type;
269 pDesc->MultiSampleQuality = wined3ddesc.multisample_quality;
270 pDesc->Width = wined3ddesc.width;
271 pDesc->Height = wined3ddesc.height;
274 return hr;
277 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetCubeMapSurface(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface9** ppCubeMapSurface) {
278 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
279 HRESULT hrc = D3D_OK;
280 IWineD3DSurface *mySurface = NULL;
282 TRACE("(%p) Relay\n", This);
284 wined3d_mutex_lock();
285 hrc = IWineD3DCubeTexture_GetCubeMapSurface(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, &mySurface);
286 if (hrc == D3D_OK && NULL != ppCubeMapSurface) {
287 IWineD3DCubeTexture_GetParent(mySurface, (IUnknown **)ppCubeMapSurface);
288 IWineD3DCubeTexture_Release(mySurface);
290 wined3d_mutex_unlock();
292 return hrc;
295 static HRESULT WINAPI IDirect3DCubeTexture9Impl_LockRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
296 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
297 HRESULT hr;
298 TRACE("(%p) Relay\n", This);
300 wined3d_mutex_lock();
301 hr = IWineD3DCubeTexture_LockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
302 wined3d_mutex_unlock();
304 return hr;
307 static HRESULT WINAPI IDirect3DCubeTexture9Impl_UnlockRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level) {
308 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
309 HRESULT hr;
310 TRACE("(%p) Relay\n", This);
312 wined3d_mutex_lock();
313 hr = IWineD3DCubeTexture_UnlockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level);
314 wined3d_mutex_unlock();
316 return hr;
319 static HRESULT WINAPI IDirect3DCubeTexture9Impl_AddDirtyRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) {
320 IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
321 HRESULT hr;
322 TRACE("(%p) Relay\n", This);
324 wined3d_mutex_lock();
325 hr = IWineD3DCubeTexture_AddDirtyRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, pDirtyRect);
326 wined3d_mutex_unlock();
328 return hr;
332 static const IDirect3DCubeTexture9Vtbl Direct3DCubeTexture9_Vtbl =
334 /* IUnknown */
335 IDirect3DCubeTexture9Impl_QueryInterface,
336 IDirect3DCubeTexture9Impl_AddRef,
337 IDirect3DCubeTexture9Impl_Release,
338 /* IDirect3DResource9 */
339 IDirect3DCubeTexture9Impl_GetDevice,
340 IDirect3DCubeTexture9Impl_SetPrivateData,
341 IDirect3DCubeTexture9Impl_GetPrivateData,
342 IDirect3DCubeTexture9Impl_FreePrivateData,
343 IDirect3DCubeTexture9Impl_SetPriority,
344 IDirect3DCubeTexture9Impl_GetPriority,
345 IDirect3DCubeTexture9Impl_PreLoad,
346 IDirect3DCubeTexture9Impl_GetType,
347 /* IDirect3DBaseTexture9 */
348 IDirect3DCubeTexture9Impl_SetLOD,
349 IDirect3DCubeTexture9Impl_GetLOD,
350 IDirect3DCubeTexture9Impl_GetLevelCount,
351 IDirect3DCubeTexture9Impl_SetAutoGenFilterType,
352 IDirect3DCubeTexture9Impl_GetAutoGenFilterType,
353 IDirect3DCubeTexture9Impl_GenerateMipSubLevels,
354 IDirect3DCubeTexture9Impl_GetLevelDesc,
355 IDirect3DCubeTexture9Impl_GetCubeMapSurface,
356 IDirect3DCubeTexture9Impl_LockRect,
357 IDirect3DCubeTexture9Impl_UnlockRect,
358 IDirect3DCubeTexture9Impl_AddDirtyRect
361 static void STDMETHODCALLTYPE cubetexture_wined3d_object_destroyed(void *parent)
363 HeapFree(GetProcessHeap(), 0, parent);
366 static const struct wined3d_parent_ops d3d9_cubetexture_wined3d_parent_ops =
368 cubetexture_wined3d_object_destroyed,
371 HRESULT cubetexture_init(IDirect3DCubeTexture9Impl *texture, IDirect3DDevice9Impl *device,
372 UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
374 HRESULT hr;
376 texture->lpVtbl = &Direct3DCubeTexture9_Vtbl;
377 texture->ref = 1;
379 wined3d_mutex_lock();
380 hr = IWineD3DDevice_CreateCubeTexture(device->WineD3DDevice, edge_length, levels, usage,
381 wined3dformat_from_d3dformat(format), pool, &texture->wineD3DCubeTexture,
382 (IUnknown *)texture, &d3d9_cubetexture_wined3d_parent_ops);
383 wined3d_mutex_unlock();
384 if (FAILED(hr))
386 WARN("Failed to create wined3d cube texture, hr %#x.\n", hr);
387 return hr;
390 texture->parentDevice = (IDirect3DDevice9Ex *)device;
391 IDirect3DDevice9Ex_AddRef(texture->parentDevice);
393 return D3D_OK;