xref: /reactos/dll/directx/wine/d3d9/texture.c (revision 81cffd76)
1c2c66affSColin Finck /*
2c2c66affSColin Finck  * Copyright 2002-2005 Jason Edmeades
3c2c66affSColin Finck  * Copyright 2002-2005 Raphael Junqueira
4c2c66affSColin Finck  * Copyright 2005 Oliver Stieber
5c2c66affSColin Finck  *
6c2c66affSColin Finck  * This library is free software; you can redistribute it and/or
7c2c66affSColin Finck  * modify it under the terms of the GNU Lesser General Public
8c2c66affSColin Finck  * License as published by the Free Software Foundation; either
9c2c66affSColin Finck  * version 2.1 of the License, or (at your option) any later version.
10c2c66affSColin Finck  *
11c2c66affSColin Finck  * This library is distributed in the hope that it will be useful,
12c2c66affSColin Finck  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14c2c66affSColin Finck  * Lesser General Public License for more details.
15c2c66affSColin Finck  *
16c2c66affSColin Finck  * You should have received a copy of the GNU Lesser General Public
17c2c66affSColin Finck  * License along with this library; if not, write to the Free Software
18c2c66affSColin Finck  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19c2c66affSColin Finck  */
20c2c66affSColin Finck 
219987f029SAmine Khaldi #include "config.h"
22c2c66affSColin Finck #include "d3d9_private.h"
23c2c66affSColin Finck 
249987f029SAmine Khaldi WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
259987f029SAmine Khaldi 
impl_from_IDirect3DTexture9(IDirect3DTexture9 * iface)26c2c66affSColin Finck static inline struct d3d9_texture *impl_from_IDirect3DTexture9(IDirect3DTexture9 *iface)
27c2c66affSColin Finck {
289987f029SAmine Khaldi     return CONTAINING_RECORD((IDirect3DBaseTexture9 *)iface, struct d3d9_texture, IDirect3DBaseTexture9_iface);
29c2c66affSColin Finck }
30c2c66affSColin Finck 
impl_from_IDirect3DCubeTexture9(IDirect3DCubeTexture9 * iface)31c2c66affSColin Finck static inline struct d3d9_texture *impl_from_IDirect3DCubeTexture9(IDirect3DCubeTexture9 *iface)
32c2c66affSColin Finck {
339987f029SAmine Khaldi     return CONTAINING_RECORD((IDirect3DBaseTexture9 *)iface, struct d3d9_texture, IDirect3DBaseTexture9_iface);
34c2c66affSColin Finck }
35c2c66affSColin Finck 
impl_from_IDirect3DVolumeTexture9(IDirect3DVolumeTexture9 * iface)36c2c66affSColin Finck static inline struct d3d9_texture *impl_from_IDirect3DVolumeTexture9(IDirect3DVolumeTexture9 *iface)
37c2c66affSColin Finck {
389987f029SAmine Khaldi     return CONTAINING_RECORD((IDirect3DBaseTexture9 *)iface, struct d3d9_texture, IDirect3DBaseTexture9_iface);
399987f029SAmine Khaldi }
409987f029SAmine Khaldi 
srv_wined3d_object_destroyed(void * parent)419987f029SAmine Khaldi static void STDMETHODCALLTYPE srv_wined3d_object_destroyed(void *parent)
429987f029SAmine Khaldi {
439987f029SAmine Khaldi     struct d3d9_texture *texture = parent;
449987f029SAmine Khaldi 
459987f029SAmine Khaldi     texture->wined3d_srv = NULL;
469987f029SAmine Khaldi }
479987f029SAmine Khaldi 
489987f029SAmine Khaldi static const struct wined3d_parent_ops d3d9_srv_wined3d_parent_ops =
499987f029SAmine Khaldi {
509987f029SAmine Khaldi     srv_wined3d_object_destroyed,
519987f029SAmine Khaldi };
529987f029SAmine Khaldi 
539987f029SAmine Khaldi /* wined3d critical section must be taken by the caller. */
d3d9_texture_acquire_shader_resource_view(struct d3d9_texture * texture)549987f029SAmine Khaldi static struct wined3d_shader_resource_view *d3d9_texture_acquire_shader_resource_view(struct d3d9_texture *texture)
559987f029SAmine Khaldi {
569987f029SAmine Khaldi     struct wined3d_sub_resource_desc sr_desc;
579987f029SAmine Khaldi     struct wined3d_view_desc desc;
589987f029SAmine Khaldi     HRESULT hr;
599987f029SAmine Khaldi 
609987f029SAmine Khaldi     if (texture->wined3d_srv)
619987f029SAmine Khaldi         return texture->wined3d_srv;
629987f029SAmine Khaldi 
639987f029SAmine Khaldi     wined3d_texture_get_sub_resource_desc(texture->wined3d_texture, 0, &sr_desc);
649987f029SAmine Khaldi     desc.format_id = sr_desc.format;
659987f029SAmine Khaldi     desc.flags = 0;
669987f029SAmine Khaldi     desc.u.texture.level_idx = 0;
679987f029SAmine Khaldi     desc.u.texture.level_count = wined3d_texture_get_level_count(texture->wined3d_texture);
689987f029SAmine Khaldi     desc.u.texture.layer_idx = 0;
699987f029SAmine Khaldi     desc.u.texture.layer_count = sr_desc.usage & WINED3DUSAGE_LEGACY_CUBEMAP ? 6 : 1;
709987f029SAmine Khaldi     if (FAILED(hr = wined3d_shader_resource_view_create(&desc,
719987f029SAmine Khaldi             wined3d_texture_get_resource(texture->wined3d_texture), texture,
729987f029SAmine Khaldi             &d3d9_srv_wined3d_parent_ops, &texture->wined3d_srv)))
739987f029SAmine Khaldi     {
749987f029SAmine Khaldi         ERR("Failed to create shader resource view, hr %#x.\n", hr);
759987f029SAmine Khaldi         return NULL;
769987f029SAmine Khaldi     }
779987f029SAmine Khaldi 
789987f029SAmine Khaldi     return texture->wined3d_srv;
799987f029SAmine Khaldi }
809987f029SAmine Khaldi 
d3d9_texture_cleanup(struct d3d9_texture * texture)819987f029SAmine Khaldi static void d3d9_texture_cleanup(struct d3d9_texture *texture)
829987f029SAmine Khaldi {
839987f029SAmine Khaldi     IDirect3DDevice9Ex *parent_device = texture->parent_device;
849987f029SAmine Khaldi     struct d3d9_surface *surface;
859987f029SAmine Khaldi 
869987f029SAmine Khaldi     wined3d_mutex_lock();
879987f029SAmine Khaldi     if (texture->wined3d_srv)
889987f029SAmine Khaldi         wined3d_shader_resource_view_decref(texture->wined3d_srv);
899987f029SAmine Khaldi     LIST_FOR_EACH_ENTRY(surface, &texture->rtv_list, struct d3d9_surface, rtv_entry)
909987f029SAmine Khaldi         wined3d_rendertarget_view_decref(surface->wined3d_rtv);
919987f029SAmine Khaldi     wined3d_texture_decref(texture->wined3d_texture);
929987f029SAmine Khaldi     wined3d_mutex_unlock();
939987f029SAmine Khaldi 
949987f029SAmine Khaldi     /* Release the device last, as it may cause the device to be destroyed. */
959987f029SAmine Khaldi     IDirect3DDevice9Ex_Release(parent_device);
969987f029SAmine Khaldi }
979987f029SAmine Khaldi 
989987f029SAmine Khaldi /* wined3d critical section must be taken by the caller. */
d3d9_texture_gen_auto_mipmap(struct d3d9_texture * texture)999987f029SAmine Khaldi void d3d9_texture_gen_auto_mipmap(struct d3d9_texture *texture)
1009987f029SAmine Khaldi {
1019987f029SAmine Khaldi     if (!(texture->flags & D3D9_TEXTURE_MIPMAP_DIRTY))
1029987f029SAmine Khaldi         return;
1039987f029SAmine Khaldi     d3d9_texture_acquire_shader_resource_view(texture);
1049987f029SAmine Khaldi     wined3d_shader_resource_view_generate_mipmaps(texture->wined3d_srv);
1059987f029SAmine Khaldi     texture->flags &= ~D3D9_TEXTURE_MIPMAP_DIRTY;
1069987f029SAmine Khaldi }
1079987f029SAmine Khaldi 
d3d9_texture_flag_auto_gen_mipmap(struct d3d9_texture * texture)1089987f029SAmine Khaldi void d3d9_texture_flag_auto_gen_mipmap(struct d3d9_texture *texture)
1099987f029SAmine Khaldi {
1109987f029SAmine Khaldi     if (texture->usage & D3DUSAGE_AUTOGENMIPMAP)
1119987f029SAmine Khaldi         texture->flags |= D3D9_TEXTURE_MIPMAP_DIRTY;
112c2c66affSColin Finck }
113c2c66affSColin Finck 
d3d9_texture_2d_QueryInterface(IDirect3DTexture9 * iface,REFIID riid,void ** out)114c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_2d_QueryInterface(IDirect3DTexture9 *iface, REFIID riid, void **out)
115c2c66affSColin Finck {
116c2c66affSColin Finck     TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
117c2c66affSColin Finck 
118c2c66affSColin Finck     if (IsEqualGUID(riid, &IID_IDirect3DTexture9)
119c2c66affSColin Finck             || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
120c2c66affSColin Finck             || IsEqualGUID(riid, &IID_IDirect3DResource9)
121c2c66affSColin Finck             || IsEqualGUID(riid, &IID_IUnknown))
122c2c66affSColin Finck     {
123c2c66affSColin Finck         IDirect3DTexture9_AddRef(iface);
124c2c66affSColin Finck         *out = iface;
125c2c66affSColin Finck         return S_OK;
126c2c66affSColin Finck     }
127c2c66affSColin Finck 
128c2c66affSColin Finck     WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
129c2c66affSColin Finck 
130c2c66affSColin Finck     *out = NULL;
131c2c66affSColin Finck     return E_NOINTERFACE;
132c2c66affSColin Finck }
133c2c66affSColin Finck 
d3d9_texture_2d_AddRef(IDirect3DTexture9 * iface)134c2c66affSColin Finck static ULONG WINAPI d3d9_texture_2d_AddRef(IDirect3DTexture9 *iface)
135c2c66affSColin Finck {
136c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
137c2c66affSColin Finck     ULONG ref = InterlockedIncrement(&texture->resource.refcount);
138c2c66affSColin Finck 
139c2c66affSColin Finck     TRACE("%p increasing refcount to %u.\n", iface, ref);
140c2c66affSColin Finck 
141c2c66affSColin Finck     if (ref == 1)
142c2c66affSColin Finck     {
143c2c66affSColin Finck         struct d3d9_surface *surface;
144c2c66affSColin Finck 
145c2c66affSColin Finck         IDirect3DDevice9Ex_AddRef(texture->parent_device);
146c2c66affSColin Finck         wined3d_mutex_lock();
147c2c66affSColin Finck         LIST_FOR_EACH_ENTRY(surface, &texture->rtv_list, struct d3d9_surface, rtv_entry)
148c2c66affSColin Finck         {
149c2c66affSColin Finck             wined3d_rendertarget_view_incref(surface->wined3d_rtv);
150c2c66affSColin Finck         }
151c2c66affSColin Finck         wined3d_texture_incref(texture->wined3d_texture);
152c2c66affSColin Finck         wined3d_mutex_unlock();
153c2c66affSColin Finck     }
154c2c66affSColin Finck 
155c2c66affSColin Finck     return ref;
156c2c66affSColin Finck }
157c2c66affSColin Finck 
d3d9_texture_2d_Release(IDirect3DTexture9 * iface)158c2c66affSColin Finck static ULONG WINAPI d3d9_texture_2d_Release(IDirect3DTexture9 *iface)
159c2c66affSColin Finck {
160c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
161c2c66affSColin Finck     ULONG ref = InterlockedDecrement(&texture->resource.refcount);
162c2c66affSColin Finck 
163c2c66affSColin Finck     TRACE("%p decreasing refcount to %u.\n", iface, ref);
164c2c66affSColin Finck 
165c2c66affSColin Finck     if (!ref)
1669987f029SAmine Khaldi         d3d9_texture_cleanup(texture);
167c2c66affSColin Finck     return ref;
168c2c66affSColin Finck }
169c2c66affSColin Finck 
d3d9_texture_2d_GetDevice(IDirect3DTexture9 * iface,IDirect3DDevice9 ** device)170c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_2d_GetDevice(IDirect3DTexture9 *iface, IDirect3DDevice9 **device)
171c2c66affSColin Finck {
172c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
173c2c66affSColin Finck 
174c2c66affSColin Finck     TRACE("iface %p, device %p.\n", iface, device);
175c2c66affSColin Finck 
176c2c66affSColin Finck     *device = (IDirect3DDevice9 *)texture->parent_device;
177c2c66affSColin Finck     IDirect3DDevice9_AddRef(*device);
178c2c66affSColin Finck 
179c2c66affSColin Finck     TRACE("Returning device %p.\n", *device);
180c2c66affSColin Finck 
181c2c66affSColin Finck     return D3D_OK;
182c2c66affSColin Finck }
183c2c66affSColin Finck 
d3d9_texture_2d_SetPrivateData(IDirect3DTexture9 * iface,REFGUID guid,const void * data,DWORD data_size,DWORD flags)184c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_2d_SetPrivateData(IDirect3DTexture9 *iface,
185c2c66affSColin Finck         REFGUID guid, const void *data, DWORD data_size, DWORD flags)
186c2c66affSColin Finck {
187c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
188c2c66affSColin Finck     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
189c2c66affSColin Finck             iface, debugstr_guid(guid), data, data_size, flags);
190c2c66affSColin Finck 
191c2c66affSColin Finck     return d3d9_resource_set_private_data(&texture->resource, guid, data, data_size, flags);
192c2c66affSColin Finck }
193c2c66affSColin Finck 
d3d9_texture_2d_GetPrivateData(IDirect3DTexture9 * iface,REFGUID guid,void * data,DWORD * data_size)194c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_2d_GetPrivateData(IDirect3DTexture9 *iface,
195c2c66affSColin Finck         REFGUID guid, void *data, DWORD *data_size)
196c2c66affSColin Finck {
197c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
198c2c66affSColin Finck     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
199c2c66affSColin Finck             iface, debugstr_guid(guid), data, data_size);
200c2c66affSColin Finck 
201c2c66affSColin Finck     return d3d9_resource_get_private_data(&texture->resource, guid, data, data_size);
202c2c66affSColin Finck }
203c2c66affSColin Finck 
d3d9_texture_2d_FreePrivateData(IDirect3DTexture9 * iface,REFGUID guid)204c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_2d_FreePrivateData(IDirect3DTexture9 *iface, REFGUID guid)
205c2c66affSColin Finck {
206c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
207c2c66affSColin Finck     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
208c2c66affSColin Finck 
209c2c66affSColin Finck     return d3d9_resource_free_private_data(&texture->resource, guid);
210c2c66affSColin Finck }
211c2c66affSColin Finck 
d3d9_texture_2d_SetPriority(IDirect3DTexture9 * iface,DWORD priority)212c2c66affSColin Finck static DWORD WINAPI d3d9_texture_2d_SetPriority(IDirect3DTexture9 *iface, DWORD priority)
213c2c66affSColin Finck {
214c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
215c2c66affSColin Finck     struct wined3d_resource *resource;
216c2c66affSColin Finck     DWORD ret;
217c2c66affSColin Finck 
218c2c66affSColin Finck     TRACE("iface %p, priority %u.\n", iface, priority);
219c2c66affSColin Finck 
220c2c66affSColin Finck     wined3d_mutex_lock();
221c2c66affSColin Finck     resource = wined3d_texture_get_resource(texture->wined3d_texture);
222c2c66affSColin Finck     ret = wined3d_resource_set_priority(resource, priority);
223c2c66affSColin Finck     wined3d_mutex_unlock();
224c2c66affSColin Finck 
225c2c66affSColin Finck     return ret;
226c2c66affSColin Finck }
227c2c66affSColin Finck 
d3d9_texture_2d_GetPriority(IDirect3DTexture9 * iface)228c2c66affSColin Finck static DWORD WINAPI d3d9_texture_2d_GetPriority(IDirect3DTexture9 *iface)
229c2c66affSColin Finck {
230c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
231c2c66affSColin Finck     const struct wined3d_resource *resource;
232c2c66affSColin Finck     DWORD ret;
233c2c66affSColin Finck 
234c2c66affSColin Finck     TRACE("iface %p.\n", iface);
235c2c66affSColin Finck 
236c2c66affSColin Finck     wined3d_mutex_lock();
237c2c66affSColin Finck     resource = wined3d_texture_get_resource(texture->wined3d_texture);
238c2c66affSColin Finck     ret = wined3d_resource_get_priority(resource);
239c2c66affSColin Finck     wined3d_mutex_unlock();
240c2c66affSColin Finck 
241c2c66affSColin Finck     return ret;
242c2c66affSColin Finck }
243c2c66affSColin Finck 
d3d9_texture_2d_PreLoad(IDirect3DTexture9 * iface)244c2c66affSColin Finck static void WINAPI d3d9_texture_2d_PreLoad(IDirect3DTexture9 *iface)
245c2c66affSColin Finck {
246c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
247c2c66affSColin Finck 
248c2c66affSColin Finck     TRACE("iface %p.\n", iface);
249c2c66affSColin Finck 
250c2c66affSColin Finck     wined3d_mutex_lock();
251c2c66affSColin Finck     wined3d_resource_preload(wined3d_texture_get_resource(texture->wined3d_texture));
252c2c66affSColin Finck     wined3d_mutex_unlock();
253c2c66affSColin Finck }
254c2c66affSColin Finck 
d3d9_texture_2d_GetType(IDirect3DTexture9 * iface)255c2c66affSColin Finck static D3DRESOURCETYPE WINAPI d3d9_texture_2d_GetType(IDirect3DTexture9 *iface)
256c2c66affSColin Finck {
257c2c66affSColin Finck     TRACE("iface %p.\n", iface);
258c2c66affSColin Finck 
259c2c66affSColin Finck     return D3DRTYPE_TEXTURE;
260c2c66affSColin Finck }
261c2c66affSColin Finck 
d3d9_texture_2d_SetLOD(IDirect3DTexture9 * iface,DWORD lod)262c2c66affSColin Finck static DWORD WINAPI d3d9_texture_2d_SetLOD(IDirect3DTexture9 *iface, DWORD lod)
263c2c66affSColin Finck {
264c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
265c2c66affSColin Finck     DWORD ret;
266c2c66affSColin Finck 
267c2c66affSColin Finck     TRACE("iface %p, lod %u.\n", iface, lod);
268c2c66affSColin Finck 
269c2c66affSColin Finck     wined3d_mutex_lock();
270c2c66affSColin Finck     ret = wined3d_texture_set_lod(texture->wined3d_texture, lod);
271c2c66affSColin Finck     wined3d_mutex_unlock();
272c2c66affSColin Finck 
273c2c66affSColin Finck     return ret;
274c2c66affSColin Finck }
275c2c66affSColin Finck 
d3d9_texture_2d_GetLOD(IDirect3DTexture9 * iface)276c2c66affSColin Finck static DWORD WINAPI d3d9_texture_2d_GetLOD(IDirect3DTexture9 *iface)
277c2c66affSColin Finck {
278c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
279c2c66affSColin Finck     DWORD ret;
280c2c66affSColin Finck 
281c2c66affSColin Finck     TRACE("iface %p.\n", iface);
282c2c66affSColin Finck 
283c2c66affSColin Finck     wined3d_mutex_lock();
284c2c66affSColin Finck     ret = wined3d_texture_get_lod(texture->wined3d_texture);
285c2c66affSColin Finck     wined3d_mutex_unlock();
286c2c66affSColin Finck 
287c2c66affSColin Finck     return ret;
288c2c66affSColin Finck }
289c2c66affSColin Finck 
d3d9_texture_2d_GetLevelCount(IDirect3DTexture9 * iface)290c2c66affSColin Finck static DWORD WINAPI d3d9_texture_2d_GetLevelCount(IDirect3DTexture9 *iface)
291c2c66affSColin Finck {
292c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
293c2c66affSColin Finck     DWORD ret;
294c2c66affSColin Finck 
295c2c66affSColin Finck     TRACE("iface %p.\n", iface);
296c2c66affSColin Finck 
2979987f029SAmine Khaldi     if (texture->usage & D3DUSAGE_AUTOGENMIPMAP)
2989987f029SAmine Khaldi         return 1;
2999987f029SAmine Khaldi 
300c2c66affSColin Finck     wined3d_mutex_lock();
301c2c66affSColin Finck     ret = wined3d_texture_get_level_count(texture->wined3d_texture);
302c2c66affSColin Finck     wined3d_mutex_unlock();
303c2c66affSColin Finck 
304c2c66affSColin Finck     return ret;
305c2c66affSColin Finck }
306c2c66affSColin Finck 
d3d9_texture_2d_SetAutoGenFilterType(IDirect3DTexture9 * iface,D3DTEXTUREFILTERTYPE filter_type)307c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_2d_SetAutoGenFilterType(IDirect3DTexture9 *iface, D3DTEXTUREFILTERTYPE filter_type)
308c2c66affSColin Finck {
309c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
310c2c66affSColin Finck 
311c2c66affSColin Finck     TRACE("iface %p, filter_type %#x.\n", iface, filter_type);
312c2c66affSColin Finck 
3139987f029SAmine Khaldi     if (filter_type == D3DTEXF_NONE)
3149987f029SAmine Khaldi     {
3159987f029SAmine Khaldi         WARN("Invalid filter type D3DTEXF_NONE specified.\n");
3169987f029SAmine Khaldi         return D3DERR_INVALIDCALL;
3179987f029SAmine Khaldi     }
3189987f029SAmine Khaldi     if (!(texture->usage & D3DUSAGE_AUTOGENMIPMAP))
3199987f029SAmine Khaldi         WARN("Called on a texture without the D3DUSAGE_AUTOGENMIPMAP flag.\n");
3209987f029SAmine Khaldi     else if (filter_type != D3DTEXF_LINEAR)
3219987f029SAmine Khaldi         FIXME("Unsupported filter type %u.\n", filter_type);
322c2c66affSColin Finck 
3239987f029SAmine Khaldi     texture->autogen_filter_type = filter_type;
3249987f029SAmine Khaldi     return D3D_OK;
325c2c66affSColin Finck }
326c2c66affSColin Finck 
d3d9_texture_2d_GetAutoGenFilterType(IDirect3DTexture9 * iface)327c2c66affSColin Finck static D3DTEXTUREFILTERTYPE WINAPI d3d9_texture_2d_GetAutoGenFilterType(IDirect3DTexture9 *iface)
328c2c66affSColin Finck {
329c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
330c2c66affSColin Finck 
331c2c66affSColin Finck     TRACE("iface %p.\n", iface);
332c2c66affSColin Finck 
3339987f029SAmine Khaldi     if (!(texture->usage & D3DUSAGE_AUTOGENMIPMAP))
3349987f029SAmine Khaldi         WARN("Called on a texture without the D3DUSAGE_AUTOGENMIPMAP flag.\n");
335c2c66affSColin Finck 
3369987f029SAmine Khaldi     return texture->autogen_filter_type;
337c2c66affSColin Finck }
338c2c66affSColin Finck 
d3d9_texture_2d_GenerateMipSubLevels(IDirect3DTexture9 * iface)339c2c66affSColin Finck static void WINAPI d3d9_texture_2d_GenerateMipSubLevels(IDirect3DTexture9 *iface)
340c2c66affSColin Finck {
3419987f029SAmine Khaldi     struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
3429987f029SAmine Khaldi 
343c2c66affSColin Finck     TRACE("iface %p.\n", iface);
3449987f029SAmine Khaldi 
3459987f029SAmine Khaldi     wined3d_mutex_lock();
3469987f029SAmine Khaldi     d3d9_texture_gen_auto_mipmap(texture);
3479987f029SAmine Khaldi     wined3d_mutex_unlock();
348c2c66affSColin Finck }
349c2c66affSColin Finck 
d3d9_texture_2d_GetLevelDesc(IDirect3DTexture9 * iface,UINT level,D3DSURFACE_DESC * desc)350c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_2d_GetLevelDesc(IDirect3DTexture9 *iface, UINT level, D3DSURFACE_DESC *desc)
351c2c66affSColin Finck {
352c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
353c2c66affSColin Finck     struct wined3d_sub_resource_desc wined3d_desc;
354c2c66affSColin Finck     HRESULT hr;
355c2c66affSColin Finck 
356c2c66affSColin Finck     TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
357c2c66affSColin Finck 
3589987f029SAmine Khaldi     if (texture->usage & D3DUSAGE_AUTOGENMIPMAP && level)
3599987f029SAmine Khaldi     {
3609987f029SAmine Khaldi         WARN("D3DUSAGE_AUTOGENMIPMAP textures have only one accessible level.\n");
3619987f029SAmine Khaldi         return D3DERR_INVALIDCALL;
3629987f029SAmine Khaldi     }
3639987f029SAmine Khaldi 
364c2c66affSColin Finck     wined3d_mutex_lock();
365c2c66affSColin Finck     if (SUCCEEDED(hr = wined3d_texture_get_sub_resource_desc(texture->wined3d_texture, level, &wined3d_desc)))
366c2c66affSColin Finck     {
367c2c66affSColin Finck         desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
368c2c66affSColin Finck         desc->Type = D3DRTYPE_SURFACE;
3699987f029SAmine Khaldi         desc->Usage = texture->usage;
3709987f029SAmine Khaldi         desc->Pool = d3dpool_from_wined3daccess(wined3d_desc.access, wined3d_desc.usage);
371c2c66affSColin Finck         desc->MultiSampleType = wined3d_desc.multisample_type;
372c2c66affSColin Finck         desc->MultiSampleQuality = wined3d_desc.multisample_quality;
373c2c66affSColin Finck         desc->Width = wined3d_desc.width;
374c2c66affSColin Finck         desc->Height = wined3d_desc.height;
375c2c66affSColin Finck     }
376c2c66affSColin Finck     wined3d_mutex_unlock();
377c2c66affSColin Finck 
378c2c66affSColin Finck     return hr;
379c2c66affSColin Finck }
380c2c66affSColin Finck 
d3d9_texture_2d_GetSurfaceLevel(IDirect3DTexture9 * iface,UINT level,IDirect3DSurface9 ** surface)381c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_2d_GetSurfaceLevel(IDirect3DTexture9 *iface,
382c2c66affSColin Finck         UINT level, IDirect3DSurface9 **surface)
383c2c66affSColin Finck {
384c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
385c2c66affSColin Finck     struct d3d9_surface *surface_impl;
386c2c66affSColin Finck 
387c2c66affSColin Finck     TRACE("iface %p, level %u, surface %p.\n", iface, level, surface);
388c2c66affSColin Finck 
3899987f029SAmine Khaldi     if (texture->usage & D3DUSAGE_AUTOGENMIPMAP && level)
3909987f029SAmine Khaldi     {
3919987f029SAmine Khaldi         WARN("D3DUSAGE_AUTOGENMIPMAP textures have only one accessible level.\n");
3929987f029SAmine Khaldi         return D3DERR_INVALIDCALL;
3939987f029SAmine Khaldi     }
3949987f029SAmine Khaldi 
395c2c66affSColin Finck     wined3d_mutex_lock();
396c2c66affSColin Finck     if (!(surface_impl = wined3d_texture_get_sub_resource_parent(texture->wined3d_texture, level)))
397c2c66affSColin Finck     {
398c2c66affSColin Finck         wined3d_mutex_unlock();
399c2c66affSColin Finck         return D3DERR_INVALIDCALL;
400c2c66affSColin Finck     }
401c2c66affSColin Finck 
402c2c66affSColin Finck     *surface = &surface_impl->IDirect3DSurface9_iface;
403c2c66affSColin Finck     IDirect3DSurface9_AddRef(*surface);
404c2c66affSColin Finck     wined3d_mutex_unlock();
405c2c66affSColin Finck 
406c2c66affSColin Finck     return D3D_OK;
407c2c66affSColin Finck }
408c2c66affSColin Finck 
d3d9_texture_2d_LockRect(IDirect3DTexture9 * iface,UINT level,D3DLOCKED_RECT * locked_rect,const RECT * rect,DWORD flags)409c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_2d_LockRect(IDirect3DTexture9 *iface,
410c2c66affSColin Finck         UINT level, D3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags)
411c2c66affSColin Finck {
412c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
413c2c66affSColin Finck     struct d3d9_surface *surface_impl;
414c2c66affSColin Finck     HRESULT hr;
415c2c66affSColin Finck 
416c2c66affSColin Finck     TRACE("iface %p, level %u, locked_rect %p, rect %p, flags %#x.\n",
417c2c66affSColin Finck             iface, level, locked_rect, rect, flags);
418c2c66affSColin Finck 
4199987f029SAmine Khaldi     if (texture->usage & D3DUSAGE_AUTOGENMIPMAP && level)
4209987f029SAmine Khaldi     {
4219987f029SAmine Khaldi         WARN("D3DUSAGE_AUTOGENMIPMAP textures have only one accessible level.\n");
4229987f029SAmine Khaldi         return D3DERR_INVALIDCALL;
4239987f029SAmine Khaldi     }
4249987f029SAmine Khaldi 
425c2c66affSColin Finck     wined3d_mutex_lock();
426c2c66affSColin Finck     if (!(surface_impl = wined3d_texture_get_sub_resource_parent(texture->wined3d_texture, level)))
427c2c66affSColin Finck         hr = D3DERR_INVALIDCALL;
428c2c66affSColin Finck     else
429c2c66affSColin Finck         hr = IDirect3DSurface9_LockRect(&surface_impl->IDirect3DSurface9_iface, locked_rect, rect, flags);
430c2c66affSColin Finck     wined3d_mutex_unlock();
431c2c66affSColin Finck 
432c2c66affSColin Finck     return hr;
433c2c66affSColin Finck }
434c2c66affSColin Finck 
d3d9_texture_2d_UnlockRect(IDirect3DTexture9 * iface,UINT level)435c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_2d_UnlockRect(IDirect3DTexture9 *iface, UINT level)
436c2c66affSColin Finck {
437c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
438c2c66affSColin Finck     struct d3d9_surface *surface_impl;
439c2c66affSColin Finck     HRESULT hr;
440c2c66affSColin Finck 
441c2c66affSColin Finck     TRACE("iface %p, level %u.\n", iface, level);
442c2c66affSColin Finck 
4439987f029SAmine Khaldi     if (texture->usage & D3DUSAGE_AUTOGENMIPMAP && level)
4449987f029SAmine Khaldi     {
4459987f029SAmine Khaldi         WARN("D3DUSAGE_AUTOGENMIPMAP textures have only one accessible level.\n");
4469987f029SAmine Khaldi         return D3DERR_INVALIDCALL;
4479987f029SAmine Khaldi     }
4489987f029SAmine Khaldi 
449c2c66affSColin Finck     wined3d_mutex_lock();
450c2c66affSColin Finck     if (!(surface_impl = wined3d_texture_get_sub_resource_parent(texture->wined3d_texture, level)))
451c2c66affSColin Finck         hr = D3DERR_INVALIDCALL;
452c2c66affSColin Finck     else
453c2c66affSColin Finck         hr = IDirect3DSurface9_UnlockRect(&surface_impl->IDirect3DSurface9_iface);
454c2c66affSColin Finck     wined3d_mutex_unlock();
455c2c66affSColin Finck 
456c2c66affSColin Finck     return hr;
457c2c66affSColin Finck }
458c2c66affSColin Finck 
d3d9_texture_2d_AddDirtyRect(IDirect3DTexture9 * iface,const RECT * dirty_rect)459c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_2d_AddDirtyRect(IDirect3DTexture9 *iface, const RECT *dirty_rect)
460c2c66affSColin Finck {
461c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
462c2c66affSColin Finck     HRESULT hr;
463c2c66affSColin Finck 
464c2c66affSColin Finck     TRACE("iface %p, dirty_rect %s.\n",
465c2c66affSColin Finck             iface, wine_dbgstr_rect(dirty_rect));
466c2c66affSColin Finck 
467c2c66affSColin Finck     wined3d_mutex_lock();
468c2c66affSColin Finck     if (!dirty_rect)
469c2c66affSColin Finck         hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, NULL);
470c2c66affSColin Finck     else
471c2c66affSColin Finck     {
472c2c66affSColin Finck         struct wined3d_box dirty_region;
473c2c66affSColin Finck 
474c2c66affSColin Finck         wined3d_box_set(&dirty_region, dirty_rect->left, dirty_rect->top, dirty_rect->right, dirty_rect->bottom, 0, 1);
475c2c66affSColin Finck         hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, &dirty_region);
476c2c66affSColin Finck     }
477c2c66affSColin Finck     wined3d_mutex_unlock();
478c2c66affSColin Finck 
479c2c66affSColin Finck     return hr;
480c2c66affSColin Finck }
481c2c66affSColin Finck 
482c2c66affSColin Finck static const IDirect3DTexture9Vtbl d3d9_texture_2d_vtbl =
483c2c66affSColin Finck {
484c2c66affSColin Finck     /* IUnknown */
485c2c66affSColin Finck     d3d9_texture_2d_QueryInterface,
486c2c66affSColin Finck     d3d9_texture_2d_AddRef,
487c2c66affSColin Finck     d3d9_texture_2d_Release,
488c2c66affSColin Finck      /* IDirect3DResource9 */
489c2c66affSColin Finck     d3d9_texture_2d_GetDevice,
490c2c66affSColin Finck     d3d9_texture_2d_SetPrivateData,
491c2c66affSColin Finck     d3d9_texture_2d_GetPrivateData,
492c2c66affSColin Finck     d3d9_texture_2d_FreePrivateData,
493c2c66affSColin Finck     d3d9_texture_2d_SetPriority,
494c2c66affSColin Finck     d3d9_texture_2d_GetPriority,
495c2c66affSColin Finck     d3d9_texture_2d_PreLoad,
496c2c66affSColin Finck     d3d9_texture_2d_GetType,
497c2c66affSColin Finck     /* IDirect3dBaseTexture9 */
498c2c66affSColin Finck     d3d9_texture_2d_SetLOD,
499c2c66affSColin Finck     d3d9_texture_2d_GetLOD,
500c2c66affSColin Finck     d3d9_texture_2d_GetLevelCount,
501c2c66affSColin Finck     d3d9_texture_2d_SetAutoGenFilterType,
502c2c66affSColin Finck     d3d9_texture_2d_GetAutoGenFilterType,
503c2c66affSColin Finck     d3d9_texture_2d_GenerateMipSubLevels,
504c2c66affSColin Finck     /* IDirect3DTexture9 */
505c2c66affSColin Finck     d3d9_texture_2d_GetLevelDesc,
506c2c66affSColin Finck     d3d9_texture_2d_GetSurfaceLevel,
507c2c66affSColin Finck     d3d9_texture_2d_LockRect,
508c2c66affSColin Finck     d3d9_texture_2d_UnlockRect,
509c2c66affSColin Finck     d3d9_texture_2d_AddDirtyRect,
510c2c66affSColin Finck };
511c2c66affSColin Finck 
d3d9_texture_cube_QueryInterface(IDirect3DCubeTexture9 * iface,REFIID riid,void ** out)512c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_cube_QueryInterface(IDirect3DCubeTexture9 *iface, REFIID riid, void **out)
513c2c66affSColin Finck {
514c2c66affSColin Finck     TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
515c2c66affSColin Finck 
516c2c66affSColin Finck     if (IsEqualGUID(riid, &IID_IDirect3DCubeTexture9)
517c2c66affSColin Finck             || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
518c2c66affSColin Finck             || IsEqualGUID(riid, &IID_IDirect3DResource9)
519c2c66affSColin Finck             || IsEqualGUID(riid, &IID_IUnknown))
520c2c66affSColin Finck     {
521c2c66affSColin Finck         IDirect3DCubeTexture9_AddRef(iface);
522c2c66affSColin Finck         *out = iface;
523c2c66affSColin Finck         return S_OK;
524c2c66affSColin Finck     }
525c2c66affSColin Finck 
526c2c66affSColin Finck     WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
527c2c66affSColin Finck 
528c2c66affSColin Finck     *out = NULL;
529c2c66affSColin Finck     return E_NOINTERFACE;
530c2c66affSColin Finck }
531c2c66affSColin Finck 
d3d9_texture_cube_AddRef(IDirect3DCubeTexture9 * iface)532c2c66affSColin Finck static ULONG WINAPI d3d9_texture_cube_AddRef(IDirect3DCubeTexture9 *iface)
533c2c66affSColin Finck {
534c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
535c2c66affSColin Finck     ULONG ref = InterlockedIncrement(&texture->resource.refcount);
536c2c66affSColin Finck 
537c2c66affSColin Finck     TRACE("%p increasing refcount to %u.\n", iface, ref);
538c2c66affSColin Finck 
539c2c66affSColin Finck     if (ref == 1)
540c2c66affSColin Finck     {
541c2c66affSColin Finck         struct d3d9_surface *surface;
542c2c66affSColin Finck 
543c2c66affSColin Finck         IDirect3DDevice9Ex_AddRef(texture->parent_device);
544c2c66affSColin Finck         wined3d_mutex_lock();
545c2c66affSColin Finck         LIST_FOR_EACH_ENTRY(surface, &texture->rtv_list, struct d3d9_surface, rtv_entry)
546c2c66affSColin Finck         {
547c2c66affSColin Finck             wined3d_rendertarget_view_decref(surface->wined3d_rtv);
548c2c66affSColin Finck         }
549c2c66affSColin Finck         wined3d_texture_incref(texture->wined3d_texture);
550c2c66affSColin Finck         wined3d_mutex_unlock();
551c2c66affSColin Finck     }
552c2c66affSColin Finck 
553c2c66affSColin Finck     return ref;
554c2c66affSColin Finck }
555c2c66affSColin Finck 
d3d9_texture_cube_Release(IDirect3DCubeTexture9 * iface)556c2c66affSColin Finck static ULONG WINAPI d3d9_texture_cube_Release(IDirect3DCubeTexture9 *iface)
557c2c66affSColin Finck {
558c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
559c2c66affSColin Finck     ULONG ref = InterlockedDecrement(&texture->resource.refcount);
560c2c66affSColin Finck 
561c2c66affSColin Finck     TRACE("%p decreasing refcount to %u.\n", iface, ref);
562c2c66affSColin Finck 
563c2c66affSColin Finck     if (!ref)
5649987f029SAmine Khaldi         d3d9_texture_cleanup(texture);
565c2c66affSColin Finck     return ref;
566c2c66affSColin Finck }
567c2c66affSColin Finck 
d3d9_texture_cube_GetDevice(IDirect3DCubeTexture9 * iface,IDirect3DDevice9 ** device)568c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_cube_GetDevice(IDirect3DCubeTexture9 *iface, IDirect3DDevice9 **device)
569c2c66affSColin Finck {
570c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
571c2c66affSColin Finck 
572c2c66affSColin Finck     TRACE("iface %p, device %p.\n", iface, device);
573c2c66affSColin Finck 
574c2c66affSColin Finck     *device = (IDirect3DDevice9 *)texture->parent_device;
575c2c66affSColin Finck     IDirect3DDevice9_AddRef(*device);
576c2c66affSColin Finck 
577c2c66affSColin Finck     TRACE("Returning device %p.\n", *device);
578c2c66affSColin Finck 
579c2c66affSColin Finck     return D3D_OK;
580c2c66affSColin Finck }
581c2c66affSColin Finck 
d3d9_texture_cube_SetPrivateData(IDirect3DCubeTexture9 * iface,REFGUID guid,const void * data,DWORD data_size,DWORD flags)582c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_cube_SetPrivateData(IDirect3DCubeTexture9 *iface,
583c2c66affSColin Finck         REFGUID guid, const void *data, DWORD data_size, DWORD flags)
584c2c66affSColin Finck {
585c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
586c2c66affSColin Finck     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
587c2c66affSColin Finck             iface, debugstr_guid(guid), data, data_size, flags);
588c2c66affSColin Finck 
589c2c66affSColin Finck     return d3d9_resource_set_private_data(&texture->resource, guid, data, data_size, flags);
590c2c66affSColin Finck }
591c2c66affSColin Finck 
d3d9_texture_cube_GetPrivateData(IDirect3DCubeTexture9 * iface,REFGUID guid,void * data,DWORD * data_size)592c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_cube_GetPrivateData(IDirect3DCubeTexture9 *iface,
593c2c66affSColin Finck         REFGUID guid, void *data, DWORD *data_size)
594c2c66affSColin Finck {
595c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
596c2c66affSColin Finck     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
597c2c66affSColin Finck             iface, debugstr_guid(guid), data, data_size);
598c2c66affSColin Finck 
599c2c66affSColin Finck     return d3d9_resource_get_private_data(&texture->resource, guid, data, data_size);
600c2c66affSColin Finck }
601c2c66affSColin Finck 
d3d9_texture_cube_FreePrivateData(IDirect3DCubeTexture9 * iface,REFGUID guid)602c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_cube_FreePrivateData(IDirect3DCubeTexture9 *iface, REFGUID guid)
603c2c66affSColin Finck {
604c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
605c2c66affSColin Finck     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
606c2c66affSColin Finck 
607c2c66affSColin Finck     return d3d9_resource_free_private_data(&texture->resource, guid);
608c2c66affSColin Finck }
609c2c66affSColin Finck 
d3d9_texture_cube_SetPriority(IDirect3DCubeTexture9 * iface,DWORD priority)610c2c66affSColin Finck static DWORD WINAPI d3d9_texture_cube_SetPriority(IDirect3DCubeTexture9 *iface, DWORD priority)
611c2c66affSColin Finck {
612c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
613c2c66affSColin Finck     struct wined3d_resource *resource;
614c2c66affSColin Finck     DWORD ret;
615c2c66affSColin Finck 
616c2c66affSColin Finck     TRACE("iface %p, priority %u.\n", iface, priority);
617c2c66affSColin Finck 
618c2c66affSColin Finck     wined3d_mutex_lock();
619c2c66affSColin Finck     resource = wined3d_texture_get_resource(texture->wined3d_texture);
620c2c66affSColin Finck     ret = wined3d_resource_set_priority(resource, priority);
621c2c66affSColin Finck     wined3d_mutex_unlock();
622c2c66affSColin Finck 
623c2c66affSColin Finck     return ret;
624c2c66affSColin Finck }
625c2c66affSColin Finck 
d3d9_texture_cube_GetPriority(IDirect3DCubeTexture9 * iface)626c2c66affSColin Finck static DWORD WINAPI d3d9_texture_cube_GetPriority(IDirect3DCubeTexture9 *iface)
627c2c66affSColin Finck {
628c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
629c2c66affSColin Finck     const struct wined3d_resource *resource;
630c2c66affSColin Finck     DWORD ret;
631c2c66affSColin Finck 
632c2c66affSColin Finck     TRACE("iface %p.\n", iface);
633c2c66affSColin Finck 
634c2c66affSColin Finck     wined3d_mutex_lock();
635c2c66affSColin Finck     resource = wined3d_texture_get_resource(texture->wined3d_texture);
636c2c66affSColin Finck     ret = wined3d_resource_get_priority(resource);
637c2c66affSColin Finck     wined3d_mutex_unlock();
638c2c66affSColin Finck 
639c2c66affSColin Finck     return ret;
640c2c66affSColin Finck }
641c2c66affSColin Finck 
d3d9_texture_cube_PreLoad(IDirect3DCubeTexture9 * iface)642c2c66affSColin Finck static void WINAPI d3d9_texture_cube_PreLoad(IDirect3DCubeTexture9 *iface)
643c2c66affSColin Finck {
644c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
645c2c66affSColin Finck 
646c2c66affSColin Finck     TRACE("iface %p.\n", iface);
647c2c66affSColin Finck 
648c2c66affSColin Finck     wined3d_mutex_lock();
649c2c66affSColin Finck     wined3d_resource_preload(wined3d_texture_get_resource(texture->wined3d_texture));
650c2c66affSColin Finck     wined3d_mutex_unlock();
651c2c66affSColin Finck }
652c2c66affSColin Finck 
d3d9_texture_cube_GetType(IDirect3DCubeTexture9 * iface)653c2c66affSColin Finck static D3DRESOURCETYPE WINAPI d3d9_texture_cube_GetType(IDirect3DCubeTexture9 *iface)
654c2c66affSColin Finck {
655c2c66affSColin Finck     TRACE("iface %p.\n", iface);
656c2c66affSColin Finck 
657c2c66affSColin Finck     return D3DRTYPE_CUBETEXTURE;
658c2c66affSColin Finck }
659c2c66affSColin Finck 
d3d9_texture_cube_SetLOD(IDirect3DCubeTexture9 * iface,DWORD lod)660c2c66affSColin Finck static DWORD WINAPI d3d9_texture_cube_SetLOD(IDirect3DCubeTexture9 *iface, DWORD lod)
661c2c66affSColin Finck {
662c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
663c2c66affSColin Finck     DWORD ret;
664c2c66affSColin Finck 
665c2c66affSColin Finck     TRACE("iface %p, lod %u.\n", iface, lod);
666c2c66affSColin Finck 
667c2c66affSColin Finck     wined3d_mutex_lock();
668c2c66affSColin Finck     ret = wined3d_texture_set_lod(texture->wined3d_texture, lod);
669c2c66affSColin Finck     wined3d_mutex_unlock();
670c2c66affSColin Finck 
671c2c66affSColin Finck     return ret;
672c2c66affSColin Finck }
673c2c66affSColin Finck 
d3d9_texture_cube_GetLOD(IDirect3DCubeTexture9 * iface)674c2c66affSColin Finck static DWORD WINAPI d3d9_texture_cube_GetLOD(IDirect3DCubeTexture9 *iface)
675c2c66affSColin Finck {
676c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
677c2c66affSColin Finck     DWORD ret;
678c2c66affSColin Finck 
679c2c66affSColin Finck     TRACE("iface %p.\n", iface);
680c2c66affSColin Finck 
681c2c66affSColin Finck     wined3d_mutex_lock();
682c2c66affSColin Finck     ret = wined3d_texture_get_lod(texture->wined3d_texture);
683c2c66affSColin Finck     wined3d_mutex_unlock();
684c2c66affSColin Finck 
685c2c66affSColin Finck     return ret;
686c2c66affSColin Finck }
687c2c66affSColin Finck 
d3d9_texture_cube_GetLevelCount(IDirect3DCubeTexture9 * iface)688c2c66affSColin Finck static DWORD WINAPI d3d9_texture_cube_GetLevelCount(IDirect3DCubeTexture9 *iface)
689c2c66affSColin Finck {
690c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
691c2c66affSColin Finck     DWORD ret;
692c2c66affSColin Finck 
693c2c66affSColin Finck     TRACE("iface %p.\n", iface);
694c2c66affSColin Finck 
6959987f029SAmine Khaldi     if (texture->usage & D3DUSAGE_AUTOGENMIPMAP)
6969987f029SAmine Khaldi         return 1;
6979987f029SAmine Khaldi 
698c2c66affSColin Finck     wined3d_mutex_lock();
699c2c66affSColin Finck     ret = wined3d_texture_get_level_count(texture->wined3d_texture);
700c2c66affSColin Finck     wined3d_mutex_unlock();
701c2c66affSColin Finck 
702c2c66affSColin Finck     return ret;
703c2c66affSColin Finck }
704c2c66affSColin Finck 
d3d9_texture_cube_SetAutoGenFilterType(IDirect3DCubeTexture9 * iface,D3DTEXTUREFILTERTYPE filter_type)705c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_cube_SetAutoGenFilterType(IDirect3DCubeTexture9 *iface,
706c2c66affSColin Finck         D3DTEXTUREFILTERTYPE filter_type)
707c2c66affSColin Finck {
708c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
709c2c66affSColin Finck 
710c2c66affSColin Finck     TRACE("iface %p, filter_type %#x.\n", iface, filter_type);
711c2c66affSColin Finck 
7129987f029SAmine Khaldi     if (filter_type == D3DTEXF_NONE)
7139987f029SAmine Khaldi     {
7149987f029SAmine Khaldi         WARN("Invalid filter type D3DTEXF_NONE specified.\n");
7159987f029SAmine Khaldi         return D3DERR_INVALIDCALL;
7169987f029SAmine Khaldi     }
7179987f029SAmine Khaldi     if (!(texture->usage & D3DUSAGE_AUTOGENMIPMAP))
7189987f029SAmine Khaldi         WARN("Called on a texture without the D3DUSAGE_AUTOGENMIPMAP flag.\n");
7199987f029SAmine Khaldi     else if (filter_type != D3DTEXF_LINEAR)
7209987f029SAmine Khaldi         FIXME("Unsupported filter type %u.\n", filter_type);
721c2c66affSColin Finck 
7229987f029SAmine Khaldi     texture->autogen_filter_type = filter_type;
7239987f029SAmine Khaldi     return D3D_OK;
724c2c66affSColin Finck }
725c2c66affSColin Finck 
d3d9_texture_cube_GetAutoGenFilterType(IDirect3DCubeTexture9 * iface)726c2c66affSColin Finck static D3DTEXTUREFILTERTYPE WINAPI d3d9_texture_cube_GetAutoGenFilterType(IDirect3DCubeTexture9 *iface)
727c2c66affSColin Finck {
728c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
729c2c66affSColin Finck 
730c2c66affSColin Finck     TRACE("iface %p.\n", iface);
731c2c66affSColin Finck 
7329987f029SAmine Khaldi     if (!(texture->usage & D3DUSAGE_AUTOGENMIPMAP))
7339987f029SAmine Khaldi         WARN("Called on a texture without the D3DUSAGE_AUTOGENMIPMAP flag.\n");
734c2c66affSColin Finck 
7359987f029SAmine Khaldi     return texture->autogen_filter_type;
736c2c66affSColin Finck }
737c2c66affSColin Finck 
d3d9_texture_cube_GenerateMipSubLevels(IDirect3DCubeTexture9 * iface)738c2c66affSColin Finck static void WINAPI d3d9_texture_cube_GenerateMipSubLevels(IDirect3DCubeTexture9 *iface)
739c2c66affSColin Finck {
7409987f029SAmine Khaldi     struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
7419987f029SAmine Khaldi 
742c2c66affSColin Finck     TRACE("iface %p.\n", iface);
7439987f029SAmine Khaldi 
7449987f029SAmine Khaldi     wined3d_mutex_lock();
7459987f029SAmine Khaldi     d3d9_texture_gen_auto_mipmap(texture);
7469987f029SAmine Khaldi     wined3d_mutex_unlock();
747c2c66affSColin Finck }
748c2c66affSColin Finck 
d3d9_texture_cube_GetLevelDesc(IDirect3DCubeTexture9 * iface,UINT level,D3DSURFACE_DESC * desc)749c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_cube_GetLevelDesc(IDirect3DCubeTexture9 *iface, UINT level, D3DSURFACE_DESC *desc)
750c2c66affSColin Finck {
751c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
752c2c66affSColin Finck     struct wined3d_sub_resource_desc wined3d_desc;
753c2c66affSColin Finck     DWORD level_count;
754c2c66affSColin Finck     HRESULT hr;
755c2c66affSColin Finck 
756c2c66affSColin Finck     TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
757c2c66affSColin Finck 
7589987f029SAmine Khaldi     if (texture->usage & D3DUSAGE_AUTOGENMIPMAP && level)
7599987f029SAmine Khaldi     {
7609987f029SAmine Khaldi         WARN("D3DUSAGE_AUTOGENMIPMAP textures have only one accessible level.\n");
7619987f029SAmine Khaldi         return D3DERR_INVALIDCALL;
7629987f029SAmine Khaldi     }
7639987f029SAmine Khaldi 
764c2c66affSColin Finck     wined3d_mutex_lock();
765c2c66affSColin Finck     level_count = wined3d_texture_get_level_count(texture->wined3d_texture);
766c2c66affSColin Finck     if (level >= level_count)
767c2c66affSColin Finck     {
768c2c66affSColin Finck         wined3d_mutex_unlock();
769c2c66affSColin Finck         return D3DERR_INVALIDCALL;
770c2c66affSColin Finck     }
771c2c66affSColin Finck 
772c2c66affSColin Finck     if (SUCCEEDED(hr = wined3d_texture_get_sub_resource_desc(texture->wined3d_texture, level, &wined3d_desc)))
773c2c66affSColin Finck     {
774c2c66affSColin Finck         desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
775c2c66affSColin Finck         desc->Type = D3DRTYPE_SURFACE;
7769987f029SAmine Khaldi         desc->Usage = texture->usage;
7779987f029SAmine Khaldi         desc->Pool = d3dpool_from_wined3daccess(wined3d_desc.access, wined3d_desc.usage);
778c2c66affSColin Finck         desc->MultiSampleType = wined3d_desc.multisample_type;
779c2c66affSColin Finck         desc->MultiSampleQuality = wined3d_desc.multisample_quality;
780c2c66affSColin Finck         desc->Width = wined3d_desc.width;
781c2c66affSColin Finck         desc->Height = wined3d_desc.height;
782c2c66affSColin Finck     }
783c2c66affSColin Finck     wined3d_mutex_unlock();
784c2c66affSColin Finck 
785c2c66affSColin Finck     return hr;
786c2c66affSColin Finck }
787c2c66affSColin Finck 
d3d9_texture_cube_GetCubeMapSurface(IDirect3DCubeTexture9 * iface,D3DCUBEMAP_FACES face,UINT level,IDirect3DSurface9 ** surface)788c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_cube_GetCubeMapSurface(IDirect3DCubeTexture9 *iface,
789c2c66affSColin Finck         D3DCUBEMAP_FACES face, UINT level, IDirect3DSurface9 **surface)
790c2c66affSColin Finck {
791c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
792c2c66affSColin Finck     struct d3d9_surface *surface_impl;
793c2c66affSColin Finck     UINT sub_resource_idx;
794c2c66affSColin Finck     DWORD level_count;
795c2c66affSColin Finck 
796c2c66affSColin Finck     TRACE("iface %p, face %#x, level %u, surface %p.\n", iface, face, level, surface);
797c2c66affSColin Finck 
7989987f029SAmine Khaldi     if (texture->usage & D3DUSAGE_AUTOGENMIPMAP && level)
7999987f029SAmine Khaldi     {
8009987f029SAmine Khaldi         WARN("D3DUSAGE_AUTOGENMIPMAP textures have only one accessible level.\n");
8019987f029SAmine Khaldi         return D3DERR_INVALIDCALL;
8029987f029SAmine Khaldi     }
8039987f029SAmine Khaldi 
804c2c66affSColin Finck     wined3d_mutex_lock();
805c2c66affSColin Finck     level_count = wined3d_texture_get_level_count(texture->wined3d_texture);
806c2c66affSColin Finck     if (level >= level_count)
807c2c66affSColin Finck     {
808c2c66affSColin Finck         wined3d_mutex_unlock();
809c2c66affSColin Finck         return D3DERR_INVALIDCALL;
810c2c66affSColin Finck     }
811c2c66affSColin Finck 
812c2c66affSColin Finck     sub_resource_idx = level_count * face + level;
813c2c66affSColin Finck     if (!(surface_impl = wined3d_texture_get_sub_resource_parent(texture->wined3d_texture, sub_resource_idx)))
814c2c66affSColin Finck     {
815c2c66affSColin Finck         wined3d_mutex_unlock();
816c2c66affSColin Finck         return D3DERR_INVALIDCALL;
817c2c66affSColin Finck     }
818c2c66affSColin Finck 
819c2c66affSColin Finck     *surface = &surface_impl->IDirect3DSurface9_iface;
820c2c66affSColin Finck     IDirect3DSurface9_AddRef(*surface);
821c2c66affSColin Finck     wined3d_mutex_unlock();
822c2c66affSColin Finck 
823c2c66affSColin Finck     return D3D_OK;
824c2c66affSColin Finck }
825c2c66affSColin Finck 
d3d9_texture_cube_LockRect(IDirect3DCubeTexture9 * iface,D3DCUBEMAP_FACES face,UINT level,D3DLOCKED_RECT * locked_rect,const RECT * rect,DWORD flags)826c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_cube_LockRect(IDirect3DCubeTexture9 *iface,
827c2c66affSColin Finck         D3DCUBEMAP_FACES face, UINT level, D3DLOCKED_RECT *locked_rect, const RECT *rect,
828c2c66affSColin Finck         DWORD flags)
829c2c66affSColin Finck {
830c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
831c2c66affSColin Finck     struct d3d9_surface *surface_impl;
832c2c66affSColin Finck     UINT sub_resource_idx;
833c2c66affSColin Finck     HRESULT hr;
834c2c66affSColin Finck 
835c2c66affSColin Finck     TRACE("iface %p, face %#x, level %u, locked_rect %p, rect %p, flags %#x.\n",
836c2c66affSColin Finck             iface, face, level, locked_rect, rect, flags);
837c2c66affSColin Finck 
8389987f029SAmine Khaldi     if (texture->usage & D3DUSAGE_AUTOGENMIPMAP && level)
8399987f029SAmine Khaldi     {
8409987f029SAmine Khaldi         WARN("D3DUSAGE_AUTOGENMIPMAP textures have only one accessible level.\n");
8419987f029SAmine Khaldi         return D3DERR_INVALIDCALL;
8429987f029SAmine Khaldi     }
8439987f029SAmine Khaldi 
844c2c66affSColin Finck     wined3d_mutex_lock();
845c2c66affSColin Finck     sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
846c2c66affSColin Finck     if (!(surface_impl = wined3d_texture_get_sub_resource_parent(texture->wined3d_texture, sub_resource_idx)))
847c2c66affSColin Finck         hr = D3DERR_INVALIDCALL;
848c2c66affSColin Finck     else
849c2c66affSColin Finck         hr = IDirect3DSurface9_LockRect(&surface_impl->IDirect3DSurface9_iface, locked_rect, rect, flags);
850c2c66affSColin Finck     wined3d_mutex_unlock();
851c2c66affSColin Finck 
852c2c66affSColin Finck     return hr;
853c2c66affSColin Finck }
854c2c66affSColin Finck 
d3d9_texture_cube_UnlockRect(IDirect3DCubeTexture9 * iface,D3DCUBEMAP_FACES face,UINT level)855c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_cube_UnlockRect(IDirect3DCubeTexture9 *iface,
856c2c66affSColin Finck         D3DCUBEMAP_FACES face, UINT level)
857c2c66affSColin Finck {
858c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
859c2c66affSColin Finck     struct d3d9_surface *surface_impl;
860c2c66affSColin Finck     UINT sub_resource_idx;
861c2c66affSColin Finck     HRESULT hr;
862c2c66affSColin Finck 
863c2c66affSColin Finck     TRACE("iface %p, face %#x, level %u.\n", iface, face, level);
864c2c66affSColin Finck 
8659987f029SAmine Khaldi     if (texture->usage & D3DUSAGE_AUTOGENMIPMAP && level)
8669987f029SAmine Khaldi     {
8679987f029SAmine Khaldi         WARN("D3DUSAGE_AUTOGENMIPMAP textures have only one accessible level.\n");
8689987f029SAmine Khaldi         return D3DERR_INVALIDCALL;
8699987f029SAmine Khaldi     }
8709987f029SAmine Khaldi 
871c2c66affSColin Finck     wined3d_mutex_lock();
872c2c66affSColin Finck     sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
873c2c66affSColin Finck     if (!(surface_impl = wined3d_texture_get_sub_resource_parent(texture->wined3d_texture, sub_resource_idx)))
874c2c66affSColin Finck         hr = D3DERR_INVALIDCALL;
875c2c66affSColin Finck     else
876c2c66affSColin Finck         hr = IDirect3DSurface9_UnlockRect(&surface_impl->IDirect3DSurface9_iface);
877c2c66affSColin Finck     wined3d_mutex_unlock();
878c2c66affSColin Finck 
879c2c66affSColin Finck     return hr;
880c2c66affSColin Finck }
881c2c66affSColin Finck 
d3d9_texture_cube_AddDirtyRect(IDirect3DCubeTexture9 * iface,D3DCUBEMAP_FACES face,const RECT * dirty_rect)882c2c66affSColin Finck static HRESULT  WINAPI d3d9_texture_cube_AddDirtyRect(IDirect3DCubeTexture9 *iface,
883c2c66affSColin Finck         D3DCUBEMAP_FACES face, const RECT *dirty_rect)
884c2c66affSColin Finck {
885c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
886c2c66affSColin Finck     HRESULT hr;
887c2c66affSColin Finck 
888c2c66affSColin Finck     TRACE("iface %p, face %#x, dirty_rect %s.\n",
889c2c66affSColin Finck             iface, face, wine_dbgstr_rect(dirty_rect));
890c2c66affSColin Finck 
891c2c66affSColin Finck     wined3d_mutex_lock();
892c2c66affSColin Finck     if (!dirty_rect)
893c2c66affSColin Finck         hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, NULL);
894c2c66affSColin Finck     else
895c2c66affSColin Finck     {
896c2c66affSColin Finck         struct wined3d_box dirty_region;
897c2c66affSColin Finck 
898c2c66affSColin Finck         wined3d_box_set(&dirty_region, dirty_rect->left, dirty_rect->top, dirty_rect->right, dirty_rect->bottom, 0, 1);
899c2c66affSColin Finck         hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, &dirty_region);
900c2c66affSColin Finck     }
901c2c66affSColin Finck     wined3d_mutex_unlock();
902c2c66affSColin Finck 
903c2c66affSColin Finck     return hr;
904c2c66affSColin Finck }
905c2c66affSColin Finck 
906c2c66affSColin Finck static const IDirect3DCubeTexture9Vtbl d3d9_texture_cube_vtbl =
907c2c66affSColin Finck {
908c2c66affSColin Finck     /* IUnknown */
909c2c66affSColin Finck     d3d9_texture_cube_QueryInterface,
910c2c66affSColin Finck     d3d9_texture_cube_AddRef,
911c2c66affSColin Finck     d3d9_texture_cube_Release,
912c2c66affSColin Finck     /* IDirect3DResource9 */
913c2c66affSColin Finck     d3d9_texture_cube_GetDevice,
914c2c66affSColin Finck     d3d9_texture_cube_SetPrivateData,
915c2c66affSColin Finck     d3d9_texture_cube_GetPrivateData,
916c2c66affSColin Finck     d3d9_texture_cube_FreePrivateData,
917c2c66affSColin Finck     d3d9_texture_cube_SetPriority,
918c2c66affSColin Finck     d3d9_texture_cube_GetPriority,
919c2c66affSColin Finck     d3d9_texture_cube_PreLoad,
920c2c66affSColin Finck     d3d9_texture_cube_GetType,
921c2c66affSColin Finck     /* IDirect3DBaseTexture9 */
922c2c66affSColin Finck     d3d9_texture_cube_SetLOD,
923c2c66affSColin Finck     d3d9_texture_cube_GetLOD,
924c2c66affSColin Finck     d3d9_texture_cube_GetLevelCount,
925c2c66affSColin Finck     d3d9_texture_cube_SetAutoGenFilterType,
926c2c66affSColin Finck     d3d9_texture_cube_GetAutoGenFilterType,
927c2c66affSColin Finck     d3d9_texture_cube_GenerateMipSubLevels,
928c2c66affSColin Finck     /* IDirect3DCubeTexture9 */
929c2c66affSColin Finck     d3d9_texture_cube_GetLevelDesc,
930c2c66affSColin Finck     d3d9_texture_cube_GetCubeMapSurface,
931c2c66affSColin Finck     d3d9_texture_cube_LockRect,
932c2c66affSColin Finck     d3d9_texture_cube_UnlockRect,
933c2c66affSColin Finck     d3d9_texture_cube_AddDirtyRect,
934c2c66affSColin Finck };
935c2c66affSColin Finck 
d3d9_texture_3d_QueryInterface(IDirect3DVolumeTexture9 * iface,REFIID riid,void ** out)936c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_3d_QueryInterface(IDirect3DVolumeTexture9 *iface, REFIID riid, void **out)
937c2c66affSColin Finck {
938c2c66affSColin Finck     TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
939c2c66affSColin Finck 
940c2c66affSColin Finck     if (IsEqualGUID(riid, &IID_IDirect3DVolumeTexture9)
941c2c66affSColin Finck             || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
942c2c66affSColin Finck             || IsEqualGUID(riid, &IID_IDirect3DResource9)
943c2c66affSColin Finck             || IsEqualGUID(riid, &IID_IUnknown))
944c2c66affSColin Finck     {
945c2c66affSColin Finck         IDirect3DVolumeTexture9_AddRef(iface);
946c2c66affSColin Finck         *out = iface;
947c2c66affSColin Finck         return S_OK;
948c2c66affSColin Finck     }
949c2c66affSColin Finck 
950c2c66affSColin Finck     WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
951c2c66affSColin Finck 
952c2c66affSColin Finck     *out = NULL;
953c2c66affSColin Finck     return E_NOINTERFACE;
954c2c66affSColin Finck }
955c2c66affSColin Finck 
d3d9_texture_3d_AddRef(IDirect3DVolumeTexture9 * iface)956c2c66affSColin Finck static ULONG WINAPI d3d9_texture_3d_AddRef(IDirect3DVolumeTexture9 *iface)
957c2c66affSColin Finck {
958c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
959c2c66affSColin Finck     ULONG ref = InterlockedIncrement(&texture->resource.refcount);
960c2c66affSColin Finck 
961c2c66affSColin Finck     TRACE("%p increasing refcount to %u.\n", iface, ref);
962c2c66affSColin Finck 
963c2c66affSColin Finck     if (ref == 1)
964c2c66affSColin Finck     {
965c2c66affSColin Finck         IDirect3DDevice9Ex_AddRef(texture->parent_device);
966c2c66affSColin Finck         wined3d_mutex_lock();
967c2c66affSColin Finck         wined3d_texture_incref(texture->wined3d_texture);
968c2c66affSColin Finck         wined3d_mutex_unlock();
969c2c66affSColin Finck     }
970c2c66affSColin Finck 
971c2c66affSColin Finck     return ref;
972c2c66affSColin Finck }
973c2c66affSColin Finck 
d3d9_texture_3d_Release(IDirect3DVolumeTexture9 * iface)974c2c66affSColin Finck static ULONG WINAPI d3d9_texture_3d_Release(IDirect3DVolumeTexture9 *iface)
975c2c66affSColin Finck {
976c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
977c2c66affSColin Finck     ULONG ref = InterlockedDecrement(&texture->resource.refcount);
978c2c66affSColin Finck 
979c2c66affSColin Finck     TRACE("%p decreasing refcount to %u.\n", iface, ref);
980c2c66affSColin Finck 
981c2c66affSColin Finck     if (!ref)
9829987f029SAmine Khaldi         d3d9_texture_cleanup(texture);
983c2c66affSColin Finck     return ref;
984c2c66affSColin Finck }
985c2c66affSColin Finck 
d3d9_texture_3d_GetDevice(IDirect3DVolumeTexture9 * iface,IDirect3DDevice9 ** device)986c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_3d_GetDevice(IDirect3DVolumeTexture9 *iface, IDirect3DDevice9 **device)
987c2c66affSColin Finck {
988c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
989c2c66affSColin Finck 
990c2c66affSColin Finck     TRACE("iface %p, device %p.\n", iface, device);
991c2c66affSColin Finck 
992c2c66affSColin Finck     *device = (IDirect3DDevice9 *)texture->parent_device;
993c2c66affSColin Finck     IDirect3DDevice9_AddRef(*device);
994c2c66affSColin Finck 
995c2c66affSColin Finck     TRACE("Returning device %p.\n", *device);
996c2c66affSColin Finck 
997c2c66affSColin Finck     return D3D_OK;
998c2c66affSColin Finck }
999c2c66affSColin Finck 
d3d9_texture_3d_SetPrivateData(IDirect3DVolumeTexture9 * iface,REFGUID guid,const void * data,DWORD data_size,DWORD flags)1000c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_3d_SetPrivateData(IDirect3DVolumeTexture9 *iface,
1001c2c66affSColin Finck         REFGUID guid, const void *data, DWORD data_size, DWORD flags)
1002c2c66affSColin Finck {
1003c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1004c2c66affSColin Finck     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
1005c2c66affSColin Finck             iface, debugstr_guid(guid), data, data_size, flags);
1006c2c66affSColin Finck 
1007c2c66affSColin Finck     return d3d9_resource_set_private_data(&texture->resource, guid, data, data_size, flags);
1008c2c66affSColin Finck }
1009c2c66affSColin Finck 
d3d9_texture_3d_GetPrivateData(IDirect3DVolumeTexture9 * iface,REFGUID guid,void * data,DWORD * data_size)1010c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_3d_GetPrivateData(IDirect3DVolumeTexture9 *iface,
1011c2c66affSColin Finck         REFGUID guid, void *data, DWORD *data_size)
1012c2c66affSColin Finck {
1013c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1014c2c66affSColin Finck     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
1015c2c66affSColin Finck             iface, debugstr_guid(guid), data, data_size);
1016c2c66affSColin Finck 
1017c2c66affSColin Finck     return d3d9_resource_get_private_data(&texture->resource, guid, data, data_size);
1018c2c66affSColin Finck }
1019c2c66affSColin Finck 
d3d9_texture_3d_FreePrivateData(IDirect3DVolumeTexture9 * iface,REFGUID guid)1020c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_3d_FreePrivateData(IDirect3DVolumeTexture9 *iface, REFGUID guid)
1021c2c66affSColin Finck {
1022c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1023c2c66affSColin Finck     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
1024c2c66affSColin Finck 
1025c2c66affSColin Finck     return d3d9_resource_free_private_data(&texture->resource, guid);
1026c2c66affSColin Finck }
1027c2c66affSColin Finck 
d3d9_texture_3d_SetPriority(IDirect3DVolumeTexture9 * iface,DWORD priority)1028c2c66affSColin Finck static DWORD WINAPI d3d9_texture_3d_SetPriority(IDirect3DVolumeTexture9 *iface, DWORD priority)
1029c2c66affSColin Finck {
1030c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1031c2c66affSColin Finck     struct wined3d_resource *resource;
1032c2c66affSColin Finck     DWORD ret;
1033c2c66affSColin Finck 
1034c2c66affSColin Finck     TRACE("iface %p, priority %u.\n", iface, priority);
1035c2c66affSColin Finck 
1036c2c66affSColin Finck     wined3d_mutex_lock();
1037c2c66affSColin Finck     resource = wined3d_texture_get_resource(texture->wined3d_texture);
1038c2c66affSColin Finck     ret = wined3d_resource_set_priority(resource, priority);
1039c2c66affSColin Finck     wined3d_mutex_unlock();
1040c2c66affSColin Finck 
1041c2c66affSColin Finck     return ret;
1042c2c66affSColin Finck }
1043c2c66affSColin Finck 
d3d9_texture_3d_GetPriority(IDirect3DVolumeTexture9 * iface)1044c2c66affSColin Finck static DWORD WINAPI d3d9_texture_3d_GetPriority(IDirect3DVolumeTexture9 *iface)
1045c2c66affSColin Finck {
1046c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1047c2c66affSColin Finck     const struct wined3d_resource *resource;
1048c2c66affSColin Finck     DWORD ret;
1049c2c66affSColin Finck 
1050c2c66affSColin Finck     TRACE("iface %p.\n", iface);
1051c2c66affSColin Finck 
1052c2c66affSColin Finck     wined3d_mutex_lock();
1053c2c66affSColin Finck     resource = wined3d_texture_get_resource(texture->wined3d_texture);
1054c2c66affSColin Finck     ret = wined3d_resource_get_priority(resource);
1055c2c66affSColin Finck     wined3d_mutex_unlock();
1056c2c66affSColin Finck 
1057c2c66affSColin Finck     return ret;
1058c2c66affSColin Finck }
1059c2c66affSColin Finck 
d3d9_texture_3d_PreLoad(IDirect3DVolumeTexture9 * iface)1060c2c66affSColin Finck static void WINAPI d3d9_texture_3d_PreLoad(IDirect3DVolumeTexture9 *iface)
1061c2c66affSColin Finck {
1062c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1063c2c66affSColin Finck 
1064c2c66affSColin Finck     TRACE("iface %p.\n", iface);
1065c2c66affSColin Finck 
1066c2c66affSColin Finck     wined3d_mutex_lock();
1067c2c66affSColin Finck     wined3d_resource_preload(wined3d_texture_get_resource(texture->wined3d_texture));
1068c2c66affSColin Finck     wined3d_mutex_unlock();
1069c2c66affSColin Finck }
1070c2c66affSColin Finck 
d3d9_texture_3d_GetType(IDirect3DVolumeTexture9 * iface)1071c2c66affSColin Finck static D3DRESOURCETYPE WINAPI d3d9_texture_3d_GetType(IDirect3DVolumeTexture9 *iface)
1072c2c66affSColin Finck {
1073c2c66affSColin Finck     TRACE("iface %p.\n", iface);
1074c2c66affSColin Finck 
1075c2c66affSColin Finck     return D3DRTYPE_VOLUMETEXTURE;
1076c2c66affSColin Finck }
1077c2c66affSColin Finck 
d3d9_texture_3d_SetLOD(IDirect3DVolumeTexture9 * iface,DWORD lod)1078c2c66affSColin Finck static DWORD WINAPI d3d9_texture_3d_SetLOD(IDirect3DVolumeTexture9 *iface, DWORD lod)
1079c2c66affSColin Finck {
1080c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1081c2c66affSColin Finck     DWORD ret;
1082c2c66affSColin Finck 
1083c2c66affSColin Finck     TRACE("iface %p, lod %u.\n", iface, lod);
1084c2c66affSColin Finck 
1085c2c66affSColin Finck     wined3d_mutex_lock();
1086c2c66affSColin Finck     ret = wined3d_texture_set_lod(texture->wined3d_texture, lod);
1087c2c66affSColin Finck     wined3d_mutex_unlock();
1088c2c66affSColin Finck 
1089c2c66affSColin Finck     return ret;
1090c2c66affSColin Finck }
1091c2c66affSColin Finck 
d3d9_texture_3d_GetLOD(IDirect3DVolumeTexture9 * iface)1092c2c66affSColin Finck static DWORD WINAPI d3d9_texture_3d_GetLOD(IDirect3DVolumeTexture9 *iface)
1093c2c66affSColin Finck {
1094c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1095c2c66affSColin Finck     DWORD ret;
1096c2c66affSColin Finck 
1097c2c66affSColin Finck     TRACE("iface %p.\n", iface);
1098c2c66affSColin Finck 
1099c2c66affSColin Finck     wined3d_mutex_lock();
1100c2c66affSColin Finck     ret = wined3d_texture_get_lod(texture->wined3d_texture);
1101c2c66affSColin Finck     wined3d_mutex_unlock();
1102c2c66affSColin Finck 
1103c2c66affSColin Finck     return ret;
1104c2c66affSColin Finck }
1105c2c66affSColin Finck 
d3d9_texture_3d_GetLevelCount(IDirect3DVolumeTexture9 * iface)1106c2c66affSColin Finck static DWORD WINAPI d3d9_texture_3d_GetLevelCount(IDirect3DVolumeTexture9 *iface)
1107c2c66affSColin Finck {
1108c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1109c2c66affSColin Finck     DWORD ret;
1110c2c66affSColin Finck 
1111c2c66affSColin Finck     TRACE("iface %p.\n", iface);
1112c2c66affSColin Finck 
1113c2c66affSColin Finck     wined3d_mutex_lock();
1114c2c66affSColin Finck     ret = wined3d_texture_get_level_count(texture->wined3d_texture);
1115c2c66affSColin Finck     wined3d_mutex_unlock();
1116c2c66affSColin Finck 
1117c2c66affSColin Finck     return ret;
1118c2c66affSColin Finck }
1119c2c66affSColin Finck 
d3d9_texture_3d_SetAutoGenFilterType(IDirect3DVolumeTexture9 * iface,D3DTEXTUREFILTERTYPE filter_type)1120c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_3d_SetAutoGenFilterType(IDirect3DVolumeTexture9 *iface,
1121c2c66affSColin Finck         D3DTEXTUREFILTERTYPE filter_type)
1122c2c66affSColin Finck {
1123c2c66affSColin Finck     TRACE("iface %p, filter_type %#x.\n", iface, filter_type);
1124c2c66affSColin Finck 
11259987f029SAmine Khaldi     return D3DERR_INVALIDCALL;
1126c2c66affSColin Finck }
1127c2c66affSColin Finck 
d3d9_texture_3d_GetAutoGenFilterType(IDirect3DVolumeTexture9 * iface)1128c2c66affSColin Finck static D3DTEXTUREFILTERTYPE WINAPI d3d9_texture_3d_GetAutoGenFilterType(IDirect3DVolumeTexture9 *iface)
1129c2c66affSColin Finck {
1130c2c66affSColin Finck     TRACE("iface %p.\n", iface);
1131c2c66affSColin Finck 
11329987f029SAmine Khaldi     return D3DTEXF_NONE;
1133c2c66affSColin Finck }
1134c2c66affSColin Finck 
d3d9_texture_3d_GenerateMipSubLevels(IDirect3DVolumeTexture9 * iface)1135c2c66affSColin Finck static void WINAPI d3d9_texture_3d_GenerateMipSubLevels(IDirect3DVolumeTexture9 *iface)
1136c2c66affSColin Finck {
1137c2c66affSColin Finck     TRACE("iface %p.\n", iface);
1138c2c66affSColin Finck }
1139c2c66affSColin Finck 
d3d9_texture_3d_GetLevelDesc(IDirect3DVolumeTexture9 * iface,UINT level,D3DVOLUME_DESC * desc)1140c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_3d_GetLevelDesc(IDirect3DVolumeTexture9 *iface, UINT level, D3DVOLUME_DESC *desc)
1141c2c66affSColin Finck {
1142c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1143c2c66affSColin Finck     struct wined3d_sub_resource_desc wined3d_desc;
1144c2c66affSColin Finck     HRESULT hr;
1145c2c66affSColin Finck 
1146c2c66affSColin Finck     TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
1147c2c66affSColin Finck 
1148c2c66affSColin Finck     wined3d_mutex_lock();
1149c2c66affSColin Finck     if (SUCCEEDED(hr = wined3d_texture_get_sub_resource_desc(texture->wined3d_texture, level, &wined3d_desc)))
1150c2c66affSColin Finck     {
1151c2c66affSColin Finck         desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
1152c2c66affSColin Finck         desc->Type = D3DRTYPE_VOLUME;
11539987f029SAmine Khaldi         desc->Usage = texture->usage;
11549987f029SAmine Khaldi         desc->Pool = d3dpool_from_wined3daccess(wined3d_desc.access, wined3d_desc.usage);
1155c2c66affSColin Finck         desc->Width = wined3d_desc.width;
1156c2c66affSColin Finck         desc->Height = wined3d_desc.height;
1157c2c66affSColin Finck         desc->Depth = wined3d_desc.depth;
1158c2c66affSColin Finck     }
1159c2c66affSColin Finck     wined3d_mutex_unlock();
1160c2c66affSColin Finck 
1161c2c66affSColin Finck     return hr;
1162c2c66affSColin Finck }
1163c2c66affSColin Finck 
d3d9_texture_3d_GetVolumeLevel(IDirect3DVolumeTexture9 * iface,UINT level,IDirect3DVolume9 ** volume)1164c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_3d_GetVolumeLevel(IDirect3DVolumeTexture9 *iface,
1165c2c66affSColin Finck         UINT level, IDirect3DVolume9 **volume)
1166c2c66affSColin Finck {
1167c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1168c2c66affSColin Finck     struct d3d9_volume *volume_impl;
1169c2c66affSColin Finck 
1170c2c66affSColin Finck     TRACE("iface %p, level %u, volume %p.\n", iface, level, volume);
1171c2c66affSColin Finck 
1172c2c66affSColin Finck     wined3d_mutex_lock();
1173c2c66affSColin Finck     if (!(volume_impl = wined3d_texture_get_sub_resource_parent(texture->wined3d_texture, level)))
1174c2c66affSColin Finck     {
1175c2c66affSColin Finck         wined3d_mutex_unlock();
1176c2c66affSColin Finck         return D3DERR_INVALIDCALL;
1177c2c66affSColin Finck     }
1178c2c66affSColin Finck 
1179c2c66affSColin Finck     *volume = &volume_impl->IDirect3DVolume9_iface;
1180c2c66affSColin Finck     IDirect3DVolume9_AddRef(*volume);
1181c2c66affSColin Finck     wined3d_mutex_unlock();
1182c2c66affSColin Finck 
1183c2c66affSColin Finck     return D3D_OK;
1184c2c66affSColin Finck }
1185c2c66affSColin Finck 
d3d9_texture_3d_LockBox(IDirect3DVolumeTexture9 * iface,UINT level,D3DLOCKED_BOX * locked_box,const D3DBOX * box,DWORD flags)1186c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_3d_LockBox(IDirect3DVolumeTexture9 *iface,
1187c2c66affSColin Finck         UINT level, D3DLOCKED_BOX *locked_box, const D3DBOX *box, DWORD flags)
1188c2c66affSColin Finck {
1189c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1190c2c66affSColin Finck     struct d3d9_volume *volume_impl;
1191c2c66affSColin Finck     HRESULT hr;
1192c2c66affSColin Finck 
1193c2c66affSColin Finck     TRACE("iface %p, level %u, locked_box %p, box %p, flags %#x.\n",
1194c2c66affSColin Finck             iface, level, locked_box, box, flags);
1195c2c66affSColin Finck 
1196c2c66affSColin Finck     wined3d_mutex_lock();
1197c2c66affSColin Finck     if (!(volume_impl = wined3d_texture_get_sub_resource_parent(texture->wined3d_texture, level)))
1198c2c66affSColin Finck         hr = D3DERR_INVALIDCALL;
1199c2c66affSColin Finck     else
1200c2c66affSColin Finck         hr = IDirect3DVolume9_LockBox(&volume_impl->IDirect3DVolume9_iface, locked_box, box, flags);
1201c2c66affSColin Finck     wined3d_mutex_unlock();
1202c2c66affSColin Finck 
1203c2c66affSColin Finck     return hr;
1204c2c66affSColin Finck }
1205c2c66affSColin Finck 
d3d9_texture_3d_UnlockBox(IDirect3DVolumeTexture9 * iface,UINT level)1206c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_3d_UnlockBox(IDirect3DVolumeTexture9 *iface, UINT level)
1207c2c66affSColin Finck {
1208c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1209c2c66affSColin Finck     struct d3d9_volume *volume_impl;
1210c2c66affSColin Finck     HRESULT hr;
1211c2c66affSColin Finck 
1212c2c66affSColin Finck     TRACE("iface %p, level %u.\n", iface, level);
1213c2c66affSColin Finck 
1214c2c66affSColin Finck     wined3d_mutex_lock();
1215c2c66affSColin Finck     if (!(volume_impl = wined3d_texture_get_sub_resource_parent(texture->wined3d_texture, level)))
1216c2c66affSColin Finck         hr = D3DERR_INVALIDCALL;
1217c2c66affSColin Finck     else
1218c2c66affSColin Finck         hr = IDirect3DVolume9_UnlockBox(&volume_impl->IDirect3DVolume9_iface);
1219c2c66affSColin Finck     wined3d_mutex_unlock();
1220c2c66affSColin Finck 
1221c2c66affSColin Finck     return hr;
1222c2c66affSColin Finck }
1223c2c66affSColin Finck 
d3d9_texture_3d_AddDirtyBox(IDirect3DVolumeTexture9 * iface,const D3DBOX * dirty_box)1224c2c66affSColin Finck static HRESULT WINAPI d3d9_texture_3d_AddDirtyBox(IDirect3DVolumeTexture9 *iface, const D3DBOX *dirty_box)
1225c2c66affSColin Finck {
1226c2c66affSColin Finck     struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1227c2c66affSColin Finck     HRESULT hr;
1228c2c66affSColin Finck 
1229c2c66affSColin Finck     TRACE("iface %p, dirty_box %p.\n", iface, dirty_box);
1230c2c66affSColin Finck 
1231c2c66affSColin Finck     wined3d_mutex_lock();
1232c2c66affSColin Finck     hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, (const struct wined3d_box *)dirty_box);
1233c2c66affSColin Finck     wined3d_mutex_unlock();
1234c2c66affSColin Finck 
1235c2c66affSColin Finck     return hr;
1236c2c66affSColin Finck }
1237c2c66affSColin Finck 
1238c2c66affSColin Finck 
1239c2c66affSColin Finck static const IDirect3DVolumeTexture9Vtbl d3d9_texture_3d_vtbl =
1240c2c66affSColin Finck {
1241c2c66affSColin Finck     /* IUnknown */
1242c2c66affSColin Finck     d3d9_texture_3d_QueryInterface,
1243c2c66affSColin Finck     d3d9_texture_3d_AddRef,
1244c2c66affSColin Finck     d3d9_texture_3d_Release,
1245c2c66affSColin Finck     /* IDirect3DResource9 */
1246c2c66affSColin Finck     d3d9_texture_3d_GetDevice,
1247c2c66affSColin Finck     d3d9_texture_3d_SetPrivateData,
1248c2c66affSColin Finck     d3d9_texture_3d_GetPrivateData,
1249c2c66affSColin Finck     d3d9_texture_3d_FreePrivateData,
1250c2c66affSColin Finck     d3d9_texture_3d_SetPriority,
1251c2c66affSColin Finck     d3d9_texture_3d_GetPriority,
1252c2c66affSColin Finck     d3d9_texture_3d_PreLoad,
1253c2c66affSColin Finck     d3d9_texture_3d_GetType,
1254c2c66affSColin Finck     /* IDirect3DBaseTexture9 */
1255c2c66affSColin Finck     d3d9_texture_3d_SetLOD,
1256c2c66affSColin Finck     d3d9_texture_3d_GetLOD,
1257c2c66affSColin Finck     d3d9_texture_3d_GetLevelCount,
1258c2c66affSColin Finck     d3d9_texture_3d_SetAutoGenFilterType,
1259c2c66affSColin Finck     d3d9_texture_3d_GetAutoGenFilterType,
1260c2c66affSColin Finck     d3d9_texture_3d_GenerateMipSubLevels,
1261c2c66affSColin Finck     /* IDirect3DVolumeTexture9 */
1262c2c66affSColin Finck     d3d9_texture_3d_GetLevelDesc,
1263c2c66affSColin Finck     d3d9_texture_3d_GetVolumeLevel,
1264c2c66affSColin Finck     d3d9_texture_3d_LockBox,
1265c2c66affSColin Finck     d3d9_texture_3d_UnlockBox,
1266c2c66affSColin Finck     d3d9_texture_3d_AddDirtyBox,
1267c2c66affSColin Finck };
1268c2c66affSColin Finck 
unsafe_impl_from_IDirect3DBaseTexture9(IDirect3DBaseTexture9 * iface)1269c2c66affSColin Finck struct d3d9_texture *unsafe_impl_from_IDirect3DBaseTexture9(IDirect3DBaseTexture9 *iface)
1270c2c66affSColin Finck {
1271c2c66affSColin Finck     if (!iface)
1272c2c66affSColin Finck         return NULL;
1273c2c66affSColin Finck 
1274c2c66affSColin Finck     if (iface->lpVtbl != (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_2d_vtbl
1275c2c66affSColin Finck             && iface->lpVtbl != (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_cube_vtbl
1276c2c66affSColin Finck             && iface->lpVtbl != (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_3d_vtbl)
1277c2c66affSColin Finck     {
1278c2c66affSColin Finck         WARN("%p is not a valid IDirect3DBaseTexture9 interface.\n", iface);
1279c2c66affSColin Finck         return NULL;
1280c2c66affSColin Finck     }
1281c2c66affSColin Finck 
1282c2c66affSColin Finck     return CONTAINING_RECORD(iface, struct d3d9_texture, IDirect3DBaseTexture9_iface);
1283c2c66affSColin Finck }
1284c2c66affSColin Finck 
d3d9_texture_wined3d_object_destroyed(void * parent)1285c2c66affSColin Finck static void STDMETHODCALLTYPE d3d9_texture_wined3d_object_destroyed(void *parent)
1286c2c66affSColin Finck {
1287c2c66affSColin Finck     struct d3d9_texture *texture = parent;
1288c2c66affSColin Finck     d3d9_resource_cleanup(&texture->resource);
12899987f029SAmine Khaldi     heap_free(texture);
1290c2c66affSColin Finck }
1291c2c66affSColin Finck 
1292c2c66affSColin Finck static const struct wined3d_parent_ops d3d9_texture_wined3d_parent_ops =
1293c2c66affSColin Finck {
1294c2c66affSColin Finck     d3d9_texture_wined3d_object_destroyed,
1295c2c66affSColin Finck };
1296c2c66affSColin Finck 
texture_init(struct d3d9_texture * texture,struct d3d9_device * device,UINT width,UINT height,UINT levels,DWORD usage,D3DFORMAT format,D3DPOOL pool)1297c2c66affSColin Finck HRESULT texture_init(struct d3d9_texture *texture, struct d3d9_device *device,
1298c2c66affSColin Finck         UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
1299c2c66affSColin Finck {
1300c2c66affSColin Finck     struct wined3d_resource_desc desc;
1301c2c66affSColin Finck     DWORD flags = 0;
1302c2c66affSColin Finck     HRESULT hr;
1303c2c66affSColin Finck 
1304c2c66affSColin Finck     texture->IDirect3DBaseTexture9_iface.lpVtbl = (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_2d_vtbl;
1305c2c66affSColin Finck     d3d9_resource_init(&texture->resource);
1306c2c66affSColin Finck     list_init(&texture->rtv_list);
13079987f029SAmine Khaldi     texture->usage = usage;
1308c2c66affSColin Finck 
1309c2c66affSColin Finck     desc.resource_type = WINED3D_RTYPE_TEXTURE_2D;
1310c2c66affSColin Finck     desc.format = wined3dformat_from_d3dformat(format);
1311c2c66affSColin Finck     desc.multisample_type = WINED3D_MULTISAMPLE_NONE;
1312c2c66affSColin Finck     desc.multisample_quality = 0;
13139987f029SAmine Khaldi     desc.usage = wined3dusage_from_d3dusage(usage);
1314c2c66affSColin Finck     desc.usage |= WINED3DUSAGE_TEXTURE;
13159987f029SAmine Khaldi     if (pool == D3DPOOL_SCRATCH)
13169987f029SAmine Khaldi         desc.usage |= WINED3DUSAGE_SCRATCH;
13179987f029SAmine Khaldi     desc.access = wined3daccess_from_d3dpool(pool, usage)
13189987f029SAmine Khaldi             | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
1319c2c66affSColin Finck     desc.width = width;
1320c2c66affSColin Finck     desc.height = height;
1321c2c66affSColin Finck     desc.depth = 1;
1322c2c66affSColin Finck     desc.size = 0;
1323c2c66affSColin Finck 
1324c2c66affSColin Finck     if (pool != D3DPOOL_DEFAULT || (usage & D3DUSAGE_DYNAMIC))
1325c2c66affSColin Finck         flags |= WINED3D_TEXTURE_CREATE_MAPPABLE;
1326c2c66affSColin Finck 
1327c2c66affSColin Finck     if (is_gdi_compat_wined3dformat(desc.format))
1328c2c66affSColin Finck         flags |= WINED3D_TEXTURE_CREATE_GET_DC;
1329c2c66affSColin Finck 
1330c2c66affSColin Finck     if (usage & D3DUSAGE_AUTOGENMIPMAP)
13319987f029SAmine Khaldi     {
13329987f029SAmine Khaldi         if (pool == D3DPOOL_SYSTEMMEM)
13339987f029SAmine Khaldi         {
13349987f029SAmine Khaldi             WARN("D3DUSAGE_AUTOGENMIPMAP texture can't be in D3DPOOL_SYSTEMMEM, returning D3DERR_INVALIDCALL.\n");
13359987f029SAmine Khaldi             return D3DERR_INVALIDCALL;
1336c2c66affSColin Finck         }
13379987f029SAmine Khaldi         if (levels && levels != 1)
13389987f029SAmine Khaldi         {
13399987f029SAmine Khaldi             WARN("D3DUSAGE_AUTOGENMIPMAP texture with %u levels, returning D3DERR_INVALIDCALL.\n", levels);
13409987f029SAmine Khaldi             return D3DERR_INVALIDCALL;
13419987f029SAmine Khaldi         }
13429987f029SAmine Khaldi         flags |= WINED3D_TEXTURE_CREATE_GENERATE_MIPMAPS;
13437af3969eSAmine Khaldi         texture->autogen_filter_type = D3DTEXF_LINEAR;
1344*81cffd76SJoachim Henze         levels = 0;
13457af3969eSAmine Khaldi     }
13467af3969eSAmine Khaldi     else
13477af3969eSAmine Khaldi     {
13489987f029SAmine Khaldi         texture->autogen_filter_type = D3DTEXF_NONE;
13499987f029SAmine Khaldi     }
13509987f029SAmine Khaldi     if (!levels)
13519987f029SAmine Khaldi         levels = wined3d_log2i(max(width, height)) + 1;
1352c2c66affSColin Finck 
1353c2c66affSColin Finck     wined3d_mutex_lock();
1354c2c66affSColin Finck     hr = wined3d_texture_create(device->wined3d_device, &desc, 1, levels, flags,
1355c2c66affSColin Finck             NULL, texture, &d3d9_texture_wined3d_parent_ops, &texture->wined3d_texture);
1356c2c66affSColin Finck     wined3d_mutex_unlock();
1357c2c66affSColin Finck     if (FAILED(hr))
1358c2c66affSColin Finck     {
1359c2c66affSColin Finck         WARN("Failed to create wined3d texture, hr %#x.\n", hr);
1360c2c66affSColin Finck         return hr;
1361c2c66affSColin Finck     }
1362c2c66affSColin Finck 
1363c2c66affSColin Finck     texture->parent_device = &device->IDirect3DDevice9Ex_iface;
1364c2c66affSColin Finck     IDirect3DDevice9Ex_AddRef(texture->parent_device);
1365c2c66affSColin Finck 
1366c2c66affSColin Finck     return D3D_OK;
1367c2c66affSColin Finck }
1368c2c66affSColin Finck 
cubetexture_init(struct d3d9_texture * texture,struct d3d9_device * device,UINT edge_length,UINT levels,DWORD usage,D3DFORMAT format,D3DPOOL pool)1369c2c66affSColin Finck HRESULT cubetexture_init(struct d3d9_texture *texture, struct d3d9_device *device,
1370c2c66affSColin Finck         UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
1371c2c66affSColin Finck {
1372c2c66affSColin Finck     struct wined3d_resource_desc desc;
1373c2c66affSColin Finck     DWORD flags = 0;
1374c2c66affSColin Finck     HRESULT hr;
1375c2c66affSColin Finck 
1376c2c66affSColin Finck     texture->IDirect3DBaseTexture9_iface.lpVtbl = (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_cube_vtbl;
1377c2c66affSColin Finck     d3d9_resource_init(&texture->resource);
1378c2c66affSColin Finck     list_init(&texture->rtv_list);
13799987f029SAmine Khaldi     texture->usage = usage;
1380c2c66affSColin Finck 
1381c2c66affSColin Finck     desc.resource_type = WINED3D_RTYPE_TEXTURE_2D;
1382c2c66affSColin Finck     desc.format = wined3dformat_from_d3dformat(format);
1383c2c66affSColin Finck     desc.multisample_type = WINED3D_MULTISAMPLE_NONE;
1384c2c66affSColin Finck     desc.multisample_quality = 0;
13859987f029SAmine Khaldi     desc.usage = wined3dusage_from_d3dusage(usage);
1386c2c66affSColin Finck     desc.usage |= WINED3DUSAGE_LEGACY_CUBEMAP | WINED3DUSAGE_TEXTURE;
13879987f029SAmine Khaldi     if (pool == D3DPOOL_SCRATCH)
13889987f029SAmine Khaldi         desc.usage |= WINED3DUSAGE_SCRATCH;
13899987f029SAmine Khaldi     desc.access = wined3daccess_from_d3dpool(pool, usage)
13909987f029SAmine Khaldi             | WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
1391c2c66affSColin Finck     desc.width = edge_length;
1392c2c66affSColin Finck     desc.height = edge_length;
1393c2c66affSColin Finck     desc.depth = 1;
1394c2c66affSColin Finck     desc.size = 0;
1395c2c66affSColin Finck 
1396c2c66affSColin Finck     if (pool != D3DPOOL_DEFAULT || (usage & D3DUSAGE_DYNAMIC))
1397c2c66affSColin Finck         flags |= WINED3D_TEXTURE_CREATE_MAPPABLE;
1398c2c66affSColin Finck 
1399c2c66affSColin Finck     if (is_gdi_compat_wined3dformat(desc.format))
1400c2c66affSColin Finck         flags |= WINED3D_TEXTURE_CREATE_GET_DC;
1401c2c66affSColin Finck 
1402c2c66affSColin Finck     if (usage & D3DUSAGE_AUTOGENMIPMAP)
14039987f029SAmine Khaldi     {
14049987f029SAmine Khaldi         if (pool == D3DPOOL_SYSTEMMEM)
14059987f029SAmine Khaldi         {
14069987f029SAmine Khaldi             WARN("D3DUSAGE_AUTOGENMIPMAP texture can't be in D3DPOOL_SYSTEMMEM, returning D3DERR_INVALIDCALL.\n");
14079987f029SAmine Khaldi             return D3DERR_INVALIDCALL;
1408c2c66affSColin Finck         }
14099987f029SAmine Khaldi         if (levels && levels != 1)
14109987f029SAmine Khaldi         {
14119987f029SAmine Khaldi             WARN("D3DUSAGE_AUTOGENMIPMAP texture with %u levels, returning D3DERR_INVALIDCALL.\n", levels);
14129987f029SAmine Khaldi             return D3DERR_INVALIDCALL;
14139987f029SAmine Khaldi         }
14149987f029SAmine Khaldi         flags |= WINED3D_TEXTURE_CREATE_GENERATE_MIPMAPS;
14159987f029SAmine Khaldi         texture->autogen_filter_type = D3DTEXF_LINEAR;
14169987f029SAmine Khaldi         levels = 0;
14179987f029SAmine Khaldi     }
14189987f029SAmine Khaldi     else
14199987f029SAmine Khaldi     {
14209987f029SAmine Khaldi         texture->autogen_filter_type = D3DTEXF_NONE;
14219987f029SAmine Khaldi     }
14229987f029SAmine Khaldi     if (!levels)
14239987f029SAmine Khaldi         levels = wined3d_log2i(edge_length) + 1;
1424c2c66affSColin Finck 
1425c2c66affSColin Finck     wined3d_mutex_lock();
1426c2c66affSColin Finck     hr = wined3d_texture_create(device->wined3d_device, &desc, 6, levels, flags,
1427c2c66affSColin Finck             NULL, texture, &d3d9_texture_wined3d_parent_ops, &texture->wined3d_texture);
1428c2c66affSColin Finck     wined3d_mutex_unlock();
1429c2c66affSColin Finck     if (FAILED(hr))
1430c2c66affSColin Finck     {
1431c2c66affSColin Finck         WARN("Failed to create wined3d cube texture, hr %#x.\n", hr);
1432c2c66affSColin Finck         return hr;
1433c2c66affSColin Finck     }
1434c2c66affSColin Finck 
1435c2c66affSColin Finck     texture->parent_device = &device->IDirect3DDevice9Ex_iface;
1436c2c66affSColin Finck     IDirect3DDevice9Ex_AddRef(texture->parent_device);
1437c2c66affSColin Finck 
1438c2c66affSColin Finck     return D3D_OK;
1439c2c66affSColin Finck }
1440c2c66affSColin Finck 
volumetexture_init(struct d3d9_texture * texture,struct d3d9_device * device,UINT width,UINT height,UINT depth,UINT levels,DWORD usage,D3DFORMAT format,D3DPOOL pool)1441c2c66affSColin Finck HRESULT volumetexture_init(struct d3d9_texture *texture, struct d3d9_device *device,
1442c2c66affSColin Finck         UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
1443c2c66affSColin Finck {
1444c2c66affSColin Finck     struct wined3d_resource_desc desc;
1445c2c66affSColin Finck     HRESULT hr;
1446c2c66affSColin Finck 
1447c2c66affSColin Finck     texture->IDirect3DBaseTexture9_iface.lpVtbl = (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_3d_vtbl;
1448c2c66affSColin Finck     d3d9_resource_init(&texture->resource);
1449c2c66affSColin Finck     list_init(&texture->rtv_list);
14509987f029SAmine Khaldi     texture->usage = usage;
1451c2c66affSColin Finck 
1452c2c66affSColin Finck     desc.resource_type = WINED3D_RTYPE_TEXTURE_3D;
1453c2c66affSColin Finck     desc.format = wined3dformat_from_d3dformat(format);
1454c2c66affSColin Finck     desc.multisample_type = WINED3D_MULTISAMPLE_NONE;
1455c2c66affSColin Finck     desc.multisample_quality = 0;
14569987f029SAmine Khaldi     desc.usage = wined3dusage_from_d3dusage(usage);
1457c2c66affSColin Finck     desc.usage |= WINED3DUSAGE_TEXTURE;
14589987f029SAmine Khaldi     if (pool == D3DPOOL_SCRATCH)
14599987f029SAmine Khaldi         desc.usage |= WINED3DUSAGE_SCRATCH;
14609987f029SAmine Khaldi     desc.access = wined3daccess_from_d3dpool(pool, usage);
1461c2c66affSColin Finck     desc.width = width;
1462c2c66affSColin Finck     desc.height = height;
1463c2c66affSColin Finck     desc.depth = depth;
1464c2c66affSColin Finck     desc.size = 0;
1465c2c66affSColin Finck 
1466c2c66affSColin Finck     if (usage & D3DUSAGE_AUTOGENMIPMAP)
14679987f029SAmine Khaldi     {
14689987f029SAmine Khaldi         WARN("D3DUSAGE_AUTOGENMIPMAP volume texture is not supported, returning D3DERR_INVALIDCALL.\n");
14699987f029SAmine Khaldi         return D3DERR_INVALIDCALL;
1470c2c66affSColin Finck     }
14719987f029SAmine Khaldi     if (!levels)
14729987f029SAmine Khaldi         levels = wined3d_log2i(max(max(width, height), depth)) + 1;
1473c2c66affSColin Finck 
1474c2c66affSColin Finck     wined3d_mutex_lock();
1475c2c66affSColin Finck     hr = wined3d_texture_create(device->wined3d_device, &desc, 1, levels, 0,
1476c2c66affSColin Finck             NULL, texture, &d3d9_texture_wined3d_parent_ops, &texture->wined3d_texture);
1477c2c66affSColin Finck     wined3d_mutex_unlock();
1478c2c66affSColin Finck     if (FAILED(hr))
1479c2c66affSColin Finck     {
1480c2c66affSColin Finck         WARN("Failed to create wined3d volume texture, hr %#x.\n", hr);
1481c2c66affSColin Finck         return hr;
1482c2c66affSColin Finck     }
1483c2c66affSColin Finck 
1484c2c66affSColin Finck     texture->parent_device = &device->IDirect3DDevice9Ex_iface;
1485c2c66affSColin Finck     IDirect3DDevice9Ex_AddRef(texture->parent_device);
1486c2c66affSColin Finck 
1487c2c66affSColin Finck     return D3D_OK;
1488c2c66affSColin Finck }
1489