mshtml: Use proper name for OnRedirectVerifyCallback implementation.
[wine.git] / dlls / d3d9 / texture.c
blob1f8f0f2bd6fc3d4c05d5861acd9389bdf6d16376
1 /*
2 * Copyright 2002-2005 Jason Edmeades
3 * Copyright 2002-2005 Raphael Junqueira
4 * Copyright 2005 Oliver Stieber
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "d3d9_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
26 static inline struct d3d9_texture *impl_from_IDirect3DTexture9(IDirect3DTexture9 *iface)
28 return CONTAINING_RECORD(iface, struct d3d9_texture, IDirect3DBaseTexture9_iface);
31 static inline struct d3d9_texture *impl_from_IDirect3DCubeTexture9(IDirect3DCubeTexture9 *iface)
33 return CONTAINING_RECORD(iface, struct d3d9_texture, IDirect3DBaseTexture9_iface);
36 static inline struct d3d9_texture *impl_from_IDirect3DVolumeTexture9(IDirect3DVolumeTexture9 *iface)
38 return CONTAINING_RECORD(iface, struct d3d9_texture, IDirect3DBaseTexture9_iface);
41 static HRESULT WINAPI d3d9_texture_2d_QueryInterface(IDirect3DTexture9 *iface, REFIID riid, void **out)
43 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
45 if (IsEqualGUID(riid, &IID_IDirect3DTexture9)
46 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
47 || IsEqualGUID(riid, &IID_IDirect3DResource9)
48 || IsEqualGUID(riid, &IID_IUnknown))
50 IDirect3DTexture9_AddRef(iface);
51 *out = iface;
52 return S_OK;
55 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
57 *out = NULL;
58 return E_NOINTERFACE;
61 static ULONG WINAPI d3d9_texture_2d_AddRef(IDirect3DTexture9 *iface)
63 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
64 ULONG ref = InterlockedIncrement(&texture->resource.refcount);
66 TRACE("%p increasing refcount to %u.\n", iface, ref);
68 if (ref == 1)
70 struct d3d9_surface *surface;
72 IDirect3DDevice9Ex_AddRef(texture->parent_device);
73 wined3d_mutex_lock();
74 LIST_FOR_EACH_ENTRY(surface, &texture->rtv_list, struct d3d9_surface, rtv_entry)
76 wined3d_rendertarget_view_incref(surface->wined3d_rtv);
78 wined3d_texture_incref(texture->wined3d_texture);
79 wined3d_mutex_unlock();
82 return ref;
85 static ULONG WINAPI d3d9_texture_2d_Release(IDirect3DTexture9 *iface)
87 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
88 ULONG ref = InterlockedDecrement(&texture->resource.refcount);
90 TRACE("%p decreasing refcount to %u.\n", iface, ref);
92 if (!ref)
94 IDirect3DDevice9Ex *parent_device = texture->parent_device;
95 struct d3d9_surface *surface;
97 wined3d_mutex_lock();
98 LIST_FOR_EACH_ENTRY(surface, &texture->rtv_list, struct d3d9_surface, rtv_entry)
100 wined3d_rendertarget_view_decref(surface->wined3d_rtv);
102 wined3d_texture_decref(texture->wined3d_texture);
103 wined3d_mutex_unlock();
105 /* Release the device last, as it may cause the device to be destroyed. */
106 IDirect3DDevice9Ex_Release(parent_device);
108 return ref;
111 static HRESULT WINAPI d3d9_texture_2d_GetDevice(IDirect3DTexture9 *iface, IDirect3DDevice9 **device)
113 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
115 TRACE("iface %p, device %p.\n", iface, device);
117 *device = (IDirect3DDevice9 *)texture->parent_device;
118 IDirect3DDevice9_AddRef(*device);
120 TRACE("Returning device %p.\n", *device);
122 return D3D_OK;
125 static HRESULT WINAPI d3d9_texture_2d_SetPrivateData(IDirect3DTexture9 *iface,
126 REFGUID guid, const void *data, DWORD data_size, DWORD flags)
128 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
129 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
130 iface, debugstr_guid(guid), data, data_size, flags);
132 return d3d9_resource_set_private_data(&texture->resource, guid, data, data_size, flags);
135 static HRESULT WINAPI d3d9_texture_2d_GetPrivateData(IDirect3DTexture9 *iface,
136 REFGUID guid, void *data, DWORD *data_size)
138 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
139 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
140 iface, debugstr_guid(guid), data, data_size);
142 return d3d9_resource_get_private_data(&texture->resource, guid, data, data_size);
145 static HRESULT WINAPI d3d9_texture_2d_FreePrivateData(IDirect3DTexture9 *iface, REFGUID guid)
147 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
148 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
150 return d3d9_resource_free_private_data(&texture->resource, guid);
153 static DWORD WINAPI d3d9_texture_2d_SetPriority(IDirect3DTexture9 *iface, DWORD priority)
155 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
156 struct wined3d_resource *resource;
157 DWORD ret;
159 TRACE("iface %p, priority %u.\n", iface, priority);
161 wined3d_mutex_lock();
162 resource = wined3d_texture_get_resource(texture->wined3d_texture);
163 ret = wined3d_resource_set_priority(resource, priority);
164 wined3d_mutex_unlock();
166 return ret;
169 static DWORD WINAPI d3d9_texture_2d_GetPriority(IDirect3DTexture9 *iface)
171 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
172 const struct wined3d_resource *resource;
173 DWORD ret;
175 TRACE("iface %p.\n", iface);
177 wined3d_mutex_lock();
178 resource = wined3d_texture_get_resource(texture->wined3d_texture);
179 ret = wined3d_resource_get_priority(resource);
180 wined3d_mutex_unlock();
182 return ret;
185 static void WINAPI d3d9_texture_2d_PreLoad(IDirect3DTexture9 *iface)
187 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
189 TRACE("iface %p.\n", iface);
191 wined3d_mutex_lock();
192 wined3d_texture_preload(texture->wined3d_texture);
193 wined3d_mutex_unlock();
196 static D3DRESOURCETYPE WINAPI d3d9_texture_2d_GetType(IDirect3DTexture9 *iface)
198 TRACE("iface %p.\n", iface);
200 return D3DRTYPE_TEXTURE;
203 static DWORD WINAPI d3d9_texture_2d_SetLOD(IDirect3DTexture9 *iface, DWORD lod)
205 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
206 DWORD ret;
208 TRACE("iface %p, lod %u.\n", iface, lod);
210 wined3d_mutex_lock();
211 ret = wined3d_texture_set_lod(texture->wined3d_texture, lod);
212 wined3d_mutex_unlock();
214 return ret;
217 static DWORD WINAPI d3d9_texture_2d_GetLOD(IDirect3DTexture9 *iface)
219 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
220 DWORD ret;
222 TRACE("iface %p.\n", iface);
224 wined3d_mutex_lock();
225 ret = wined3d_texture_get_lod(texture->wined3d_texture);
226 wined3d_mutex_unlock();
228 return ret;
231 static DWORD WINAPI d3d9_texture_2d_GetLevelCount(IDirect3DTexture9 *iface)
233 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
234 DWORD ret;
236 TRACE("iface %p.\n", iface);
238 wined3d_mutex_lock();
239 ret = wined3d_texture_get_level_count(texture->wined3d_texture);
240 wined3d_mutex_unlock();
242 return ret;
245 static HRESULT WINAPI d3d9_texture_2d_SetAutoGenFilterType(IDirect3DTexture9 *iface, D3DTEXTUREFILTERTYPE filter_type)
247 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
248 HRESULT hr;
250 TRACE("iface %p, filter_type %#x.\n", iface, filter_type);
252 wined3d_mutex_lock();
253 hr = wined3d_texture_set_autogen_filter_type(texture->wined3d_texture,
254 (enum wined3d_texture_filter_type)filter_type);
255 wined3d_mutex_unlock();
257 return hr;
260 static D3DTEXTUREFILTERTYPE WINAPI d3d9_texture_2d_GetAutoGenFilterType(IDirect3DTexture9 *iface)
262 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
263 D3DTEXTUREFILTERTYPE ret;
265 TRACE("iface %p.\n", iface);
267 wined3d_mutex_lock();
268 ret = (D3DTEXTUREFILTERTYPE)wined3d_texture_get_autogen_filter_type(texture->wined3d_texture);
269 wined3d_mutex_unlock();
271 return ret;
274 static void WINAPI d3d9_texture_2d_GenerateMipSubLevels(IDirect3DTexture9 *iface)
276 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
278 TRACE("iface %p.\n", iface);
280 wined3d_mutex_lock();
281 wined3d_texture_generate_mipmaps(texture->wined3d_texture);
282 wined3d_mutex_unlock();
285 static HRESULT WINAPI d3d9_texture_2d_GetLevelDesc(IDirect3DTexture9 *iface, UINT level, D3DSURFACE_DESC *desc)
287 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
288 struct wined3d_resource *sub_resource;
289 HRESULT hr = D3D_OK;
291 TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
293 wined3d_mutex_lock();
294 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
295 hr = D3DERR_INVALIDCALL;
296 else
298 struct wined3d_resource_desc wined3d_desc;
300 wined3d_resource_get_desc(sub_resource, &wined3d_desc);
301 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
302 desc->Type = wined3d_desc.resource_type;
303 desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
304 desc->Pool = wined3d_desc.pool;
305 desc->MultiSampleType = wined3d_desc.multisample_type;
306 desc->MultiSampleQuality = wined3d_desc.multisample_quality;
307 desc->Width = wined3d_desc.width;
308 desc->Height = wined3d_desc.height;
310 wined3d_mutex_unlock();
312 return hr;
315 static HRESULT WINAPI d3d9_texture_2d_GetSurfaceLevel(IDirect3DTexture9 *iface,
316 UINT level, IDirect3DSurface9 **surface)
318 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
319 struct wined3d_resource *sub_resource;
320 struct d3d9_surface *surface_impl;
322 TRACE("iface %p, level %u, surface %p.\n", iface, level, surface);
324 wined3d_mutex_lock();
325 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
327 wined3d_mutex_unlock();
328 return D3DERR_INVALIDCALL;
331 surface_impl = wined3d_resource_get_parent(sub_resource);
332 *surface = &surface_impl->IDirect3DSurface9_iface;
333 IDirect3DSurface9_AddRef(*surface);
334 wined3d_mutex_unlock();
336 return D3D_OK;
339 static HRESULT WINAPI d3d9_texture_2d_LockRect(IDirect3DTexture9 *iface,
340 UINT level, D3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags)
342 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
343 struct wined3d_resource *sub_resource;
344 struct d3d9_surface *surface_impl;
345 HRESULT hr;
347 TRACE("iface %p, level %u, locked_rect %p, rect %p, flags %#x.\n",
348 iface, level, locked_rect, rect, flags);
350 wined3d_mutex_lock();
351 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
352 hr = D3DERR_INVALIDCALL;
353 else
355 surface_impl = wined3d_resource_get_parent(sub_resource);
356 hr = IDirect3DSurface9_LockRect(&surface_impl->IDirect3DSurface9_iface, locked_rect, rect, flags);
358 wined3d_mutex_unlock();
360 return hr;
363 static HRESULT WINAPI d3d9_texture_2d_UnlockRect(IDirect3DTexture9 *iface, UINT level)
365 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
366 struct wined3d_resource *sub_resource;
367 struct d3d9_surface *surface_impl;
368 HRESULT hr;
370 TRACE("iface %p, level %u.\n", iface, level);
372 wined3d_mutex_lock();
373 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
374 hr = D3DERR_INVALIDCALL;
375 else
377 surface_impl = wined3d_resource_get_parent(sub_resource);
378 hr = IDirect3DSurface9_UnlockRect(&surface_impl->IDirect3DSurface9_iface);
380 wined3d_mutex_unlock();
382 return hr;
385 static HRESULT WINAPI d3d9_texture_2d_AddDirtyRect(IDirect3DTexture9 *iface, const RECT *dirty_rect)
387 struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface);
388 HRESULT hr;
390 TRACE("iface %p, dirty_rect %s.\n",
391 iface, wine_dbgstr_rect(dirty_rect));
393 wined3d_mutex_lock();
394 if (!dirty_rect)
395 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, NULL);
396 else
398 struct wined3d_box dirty_region;
400 dirty_region.left = dirty_rect->left;
401 dirty_region.top = dirty_rect->top;
402 dirty_region.right = dirty_rect->right;
403 dirty_region.bottom = dirty_rect->bottom;
404 dirty_region.front = 0;
405 dirty_region.back = 1;
406 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, &dirty_region);
408 wined3d_mutex_unlock();
410 return hr;
413 static const IDirect3DTexture9Vtbl d3d9_texture_2d_vtbl =
415 /* IUnknown */
416 d3d9_texture_2d_QueryInterface,
417 d3d9_texture_2d_AddRef,
418 d3d9_texture_2d_Release,
419 /* IDirect3DResource9 */
420 d3d9_texture_2d_GetDevice,
421 d3d9_texture_2d_SetPrivateData,
422 d3d9_texture_2d_GetPrivateData,
423 d3d9_texture_2d_FreePrivateData,
424 d3d9_texture_2d_SetPriority,
425 d3d9_texture_2d_GetPriority,
426 d3d9_texture_2d_PreLoad,
427 d3d9_texture_2d_GetType,
428 /* IDirect3dBaseTexture9 */
429 d3d9_texture_2d_SetLOD,
430 d3d9_texture_2d_GetLOD,
431 d3d9_texture_2d_GetLevelCount,
432 d3d9_texture_2d_SetAutoGenFilterType,
433 d3d9_texture_2d_GetAutoGenFilterType,
434 d3d9_texture_2d_GenerateMipSubLevels,
435 /* IDirect3DTexture9 */
436 d3d9_texture_2d_GetLevelDesc,
437 d3d9_texture_2d_GetSurfaceLevel,
438 d3d9_texture_2d_LockRect,
439 d3d9_texture_2d_UnlockRect,
440 d3d9_texture_2d_AddDirtyRect,
443 static HRESULT WINAPI d3d9_texture_cube_QueryInterface(IDirect3DCubeTexture9 *iface, REFIID riid, void **out)
445 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
447 if (IsEqualGUID(riid, &IID_IDirect3DCubeTexture9)
448 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
449 || IsEqualGUID(riid, &IID_IDirect3DResource9)
450 || IsEqualGUID(riid, &IID_IUnknown))
452 IDirect3DCubeTexture9_AddRef(iface);
453 *out = iface;
454 return S_OK;
457 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
459 *out = NULL;
460 return E_NOINTERFACE;
463 static ULONG WINAPI d3d9_texture_cube_AddRef(IDirect3DCubeTexture9 *iface)
465 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
466 ULONG ref = InterlockedIncrement(&texture->resource.refcount);
468 TRACE("%p increasing refcount to %u.\n", iface, ref);
470 if (ref == 1)
472 struct d3d9_surface *surface;
474 IDirect3DDevice9Ex_AddRef(texture->parent_device);
475 wined3d_mutex_lock();
476 LIST_FOR_EACH_ENTRY(surface, &texture->rtv_list, struct d3d9_surface, rtv_entry)
478 wined3d_rendertarget_view_decref(surface->wined3d_rtv);
480 wined3d_texture_incref(texture->wined3d_texture);
481 wined3d_mutex_unlock();
484 return ref;
487 static ULONG WINAPI d3d9_texture_cube_Release(IDirect3DCubeTexture9 *iface)
489 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
490 ULONG ref = InterlockedDecrement(&texture->resource.refcount);
492 TRACE("%p decreasing refcount to %u.\n", iface, ref);
494 if (!ref)
496 IDirect3DDevice9Ex *parent_device = texture->parent_device;
497 struct d3d9_surface *surface;
499 TRACE("Releasing child %p.\n", texture->wined3d_texture);
501 wined3d_mutex_lock();
502 LIST_FOR_EACH_ENTRY(surface, &texture->rtv_list, struct d3d9_surface, rtv_entry)
504 wined3d_rendertarget_view_decref(surface->wined3d_rtv);
506 wined3d_texture_decref(texture->wined3d_texture);
507 wined3d_mutex_unlock();
509 /* Release the device last, as it may cause the device to be destroyed. */
510 IDirect3DDevice9Ex_Release(parent_device);
512 return ref;
515 static HRESULT WINAPI d3d9_texture_cube_GetDevice(IDirect3DCubeTexture9 *iface, IDirect3DDevice9 **device)
517 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
519 TRACE("iface %p, device %p.\n", iface, device);
521 *device = (IDirect3DDevice9 *)texture->parent_device;
522 IDirect3DDevice9_AddRef(*device);
524 TRACE("Returning device %p.\n", *device);
526 return D3D_OK;
529 static HRESULT WINAPI d3d9_texture_cube_SetPrivateData(IDirect3DCubeTexture9 *iface,
530 REFGUID guid, const void *data, DWORD data_size, DWORD flags)
532 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
533 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
534 iface, debugstr_guid(guid), data, data_size, flags);
536 return d3d9_resource_set_private_data(&texture->resource, guid, data, data_size, flags);
539 static HRESULT WINAPI d3d9_texture_cube_GetPrivateData(IDirect3DCubeTexture9 *iface,
540 REFGUID guid, void *data, DWORD *data_size)
542 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
543 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
544 iface, debugstr_guid(guid), data, data_size);
546 return d3d9_resource_get_private_data(&texture->resource, guid, data, data_size);
549 static HRESULT WINAPI d3d9_texture_cube_FreePrivateData(IDirect3DCubeTexture9 *iface, REFGUID guid)
551 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
552 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
554 return d3d9_resource_free_private_data(&texture->resource, guid);
557 static DWORD WINAPI d3d9_texture_cube_SetPriority(IDirect3DCubeTexture9 *iface, DWORD priority)
559 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
560 struct wined3d_resource *resource;
561 DWORD ret;
563 TRACE("iface %p, priority %u.\n", iface, priority);
565 wined3d_mutex_lock();
566 resource = wined3d_texture_get_resource(texture->wined3d_texture);
567 ret = wined3d_resource_set_priority(resource, priority);
568 wined3d_mutex_unlock();
570 return ret;
573 static DWORD WINAPI d3d9_texture_cube_GetPriority(IDirect3DCubeTexture9 *iface)
575 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
576 const struct wined3d_resource *resource;
577 DWORD ret;
579 TRACE("iface %p.\n", iface);
581 wined3d_mutex_lock();
582 resource = wined3d_texture_get_resource(texture->wined3d_texture);
583 ret = wined3d_resource_get_priority(resource);
584 wined3d_mutex_unlock();
586 return ret;
589 static void WINAPI d3d9_texture_cube_PreLoad(IDirect3DCubeTexture9 *iface)
591 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
593 TRACE("iface %p.\n", iface);
595 wined3d_mutex_lock();
596 wined3d_texture_preload(texture->wined3d_texture);
597 wined3d_mutex_unlock();
600 static D3DRESOURCETYPE WINAPI d3d9_texture_cube_GetType(IDirect3DCubeTexture9 *iface)
602 TRACE("iface %p.\n", iface);
604 return D3DRTYPE_CUBETEXTURE;
607 static DWORD WINAPI d3d9_texture_cube_SetLOD(IDirect3DCubeTexture9 *iface, DWORD lod)
609 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
610 DWORD ret;
612 TRACE("iface %p, lod %u.\n", iface, lod);
614 wined3d_mutex_lock();
615 ret = wined3d_texture_set_lod(texture->wined3d_texture, lod);
616 wined3d_mutex_unlock();
618 return ret;
621 static DWORD WINAPI d3d9_texture_cube_GetLOD(IDirect3DCubeTexture9 *iface)
623 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
624 DWORD ret;
626 TRACE("iface %p.\n", iface);
628 wined3d_mutex_lock();
629 ret = wined3d_texture_get_lod(texture->wined3d_texture);
630 wined3d_mutex_unlock();
632 return ret;
635 static DWORD WINAPI d3d9_texture_cube_GetLevelCount(IDirect3DCubeTexture9 *iface)
637 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
638 DWORD ret;
640 TRACE("iface %p.\n", iface);
642 wined3d_mutex_lock();
643 ret = wined3d_texture_get_level_count(texture->wined3d_texture);
644 wined3d_mutex_unlock();
646 return ret;
649 static HRESULT WINAPI d3d9_texture_cube_SetAutoGenFilterType(IDirect3DCubeTexture9 *iface,
650 D3DTEXTUREFILTERTYPE filter_type)
652 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
653 HRESULT hr;
655 TRACE("iface %p, filter_type %#x.\n", iface, filter_type);
657 wined3d_mutex_lock();
658 hr = wined3d_texture_set_autogen_filter_type(texture->wined3d_texture,
659 (enum wined3d_texture_filter_type)filter_type);
660 wined3d_mutex_unlock();
662 return hr;
665 static D3DTEXTUREFILTERTYPE WINAPI d3d9_texture_cube_GetAutoGenFilterType(IDirect3DCubeTexture9 *iface)
667 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
668 D3DTEXTUREFILTERTYPE ret;
670 TRACE("iface %p.\n", iface);
672 wined3d_mutex_lock();
673 ret = (D3DTEXTUREFILTERTYPE)wined3d_texture_get_autogen_filter_type(texture->wined3d_texture);
674 wined3d_mutex_unlock();
676 return ret;
679 static void WINAPI d3d9_texture_cube_GenerateMipSubLevels(IDirect3DCubeTexture9 *iface)
681 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
683 TRACE("iface %p.\n", iface);
685 wined3d_mutex_lock();
686 wined3d_texture_generate_mipmaps(texture->wined3d_texture);
687 wined3d_mutex_unlock();
690 static HRESULT WINAPI d3d9_texture_cube_GetLevelDesc(IDirect3DCubeTexture9 *iface, UINT level, D3DSURFACE_DESC *desc)
692 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
693 struct wined3d_resource *sub_resource;
694 HRESULT hr = D3D_OK;
695 DWORD level_count;
697 TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
699 wined3d_mutex_lock();
700 level_count = wined3d_texture_get_level_count(texture->wined3d_texture);
701 if (level >= level_count)
703 wined3d_mutex_unlock();
704 return D3DERR_INVALIDCALL;
707 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
708 hr = D3DERR_INVALIDCALL;
709 else
711 struct wined3d_resource_desc wined3d_desc;
713 wined3d_resource_get_desc(sub_resource, &wined3d_desc);
714 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
715 desc->Type = wined3d_desc.resource_type;
716 desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
717 desc->Pool = wined3d_desc.pool;
718 desc->MultiSampleType = wined3d_desc.multisample_type;
719 desc->MultiSampleQuality = wined3d_desc.multisample_quality;
720 desc->Width = wined3d_desc.width;
721 desc->Height = wined3d_desc.height;
723 wined3d_mutex_unlock();
725 return hr;
728 static HRESULT WINAPI d3d9_texture_cube_GetCubeMapSurface(IDirect3DCubeTexture9 *iface,
729 D3DCUBEMAP_FACES face, UINT level, IDirect3DSurface9 **surface)
731 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
732 struct wined3d_resource *sub_resource;
733 struct d3d9_surface *surface_impl;
734 UINT sub_resource_idx;
735 DWORD level_count;
737 TRACE("iface %p, face %#x, level %u, surface %p.\n", iface, face, level, surface);
739 wined3d_mutex_lock();
740 level_count = wined3d_texture_get_level_count(texture->wined3d_texture);
741 if (level >= level_count)
743 wined3d_mutex_unlock();
744 return D3DERR_INVALIDCALL;
747 sub_resource_idx = level_count * face + level;
748 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
750 wined3d_mutex_unlock();
751 return D3DERR_INVALIDCALL;
754 surface_impl = wined3d_resource_get_parent(sub_resource);
755 *surface = &surface_impl->IDirect3DSurface9_iface;
756 IDirect3DSurface9_AddRef(*surface);
757 wined3d_mutex_unlock();
759 return D3D_OK;
762 static HRESULT WINAPI d3d9_texture_cube_LockRect(IDirect3DCubeTexture9 *iface,
763 D3DCUBEMAP_FACES face, UINT level, D3DLOCKED_RECT *locked_rect, const RECT *rect,
764 DWORD flags)
766 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
767 struct wined3d_resource *sub_resource;
768 struct d3d9_surface *surface_impl;
769 UINT sub_resource_idx;
770 HRESULT hr;
772 TRACE("iface %p, face %#x, level %u, locked_rect %p, rect %p, flags %#x.\n",
773 iface, face, level, locked_rect, rect, flags);
775 wined3d_mutex_lock();
776 sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
777 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
778 hr = D3DERR_INVALIDCALL;
779 else
781 surface_impl = wined3d_resource_get_parent(sub_resource);
782 hr = IDirect3DSurface9_LockRect(&surface_impl->IDirect3DSurface9_iface, locked_rect, rect, flags);
784 wined3d_mutex_unlock();
786 return hr;
789 static HRESULT WINAPI d3d9_texture_cube_UnlockRect(IDirect3DCubeTexture9 *iface,
790 D3DCUBEMAP_FACES face, UINT level)
792 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
793 struct wined3d_resource *sub_resource;
794 struct d3d9_surface *surface_impl;
795 UINT sub_resource_idx;
796 HRESULT hr;
798 TRACE("iface %p, face %#x, level %u.\n", iface, face, level);
800 wined3d_mutex_lock();
801 sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
802 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
803 hr = D3DERR_INVALIDCALL;
804 else
806 surface_impl = wined3d_resource_get_parent(sub_resource);
807 hr = IDirect3DSurface9_UnlockRect(&surface_impl->IDirect3DSurface9_iface);
809 wined3d_mutex_unlock();
811 return hr;
814 static HRESULT WINAPI d3d9_texture_cube_AddDirtyRect(IDirect3DCubeTexture9 *iface,
815 D3DCUBEMAP_FACES face, const RECT *dirty_rect)
817 struct d3d9_texture *texture = impl_from_IDirect3DCubeTexture9(iface);
818 HRESULT hr;
820 TRACE("iface %p, face %#x, dirty_rect %s.\n",
821 iface, face, wine_dbgstr_rect(dirty_rect));
823 wined3d_mutex_lock();
824 if (!dirty_rect)
825 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, NULL);
826 else
828 struct wined3d_box dirty_region;
830 dirty_region.left = dirty_rect->left;
831 dirty_region.top = dirty_rect->top;
832 dirty_region.right = dirty_rect->right;
833 dirty_region.bottom = dirty_rect->bottom;
834 dirty_region.front = 0;
835 dirty_region.back = 1;
836 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, &dirty_region);
838 wined3d_mutex_unlock();
840 return hr;
843 static const IDirect3DCubeTexture9Vtbl d3d9_texture_cube_vtbl =
845 /* IUnknown */
846 d3d9_texture_cube_QueryInterface,
847 d3d9_texture_cube_AddRef,
848 d3d9_texture_cube_Release,
849 /* IDirect3DResource9 */
850 d3d9_texture_cube_GetDevice,
851 d3d9_texture_cube_SetPrivateData,
852 d3d9_texture_cube_GetPrivateData,
853 d3d9_texture_cube_FreePrivateData,
854 d3d9_texture_cube_SetPriority,
855 d3d9_texture_cube_GetPriority,
856 d3d9_texture_cube_PreLoad,
857 d3d9_texture_cube_GetType,
858 /* IDirect3DBaseTexture9 */
859 d3d9_texture_cube_SetLOD,
860 d3d9_texture_cube_GetLOD,
861 d3d9_texture_cube_GetLevelCount,
862 d3d9_texture_cube_SetAutoGenFilterType,
863 d3d9_texture_cube_GetAutoGenFilterType,
864 d3d9_texture_cube_GenerateMipSubLevels,
865 /* IDirect3DCubeTexture9 */
866 d3d9_texture_cube_GetLevelDesc,
867 d3d9_texture_cube_GetCubeMapSurface,
868 d3d9_texture_cube_LockRect,
869 d3d9_texture_cube_UnlockRect,
870 d3d9_texture_cube_AddDirtyRect,
873 static HRESULT WINAPI d3d9_texture_3d_QueryInterface(IDirect3DVolumeTexture9 *iface, REFIID riid, void **out)
875 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
877 if (IsEqualGUID(riid, &IID_IDirect3DVolumeTexture9)
878 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
879 || IsEqualGUID(riid, &IID_IDirect3DResource9)
880 || IsEqualGUID(riid, &IID_IUnknown))
882 IDirect3DVolumeTexture9_AddRef(iface);
883 *out = iface;
884 return S_OK;
887 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
889 *out = NULL;
890 return E_NOINTERFACE;
893 static ULONG WINAPI d3d9_texture_3d_AddRef(IDirect3DVolumeTexture9 *iface)
895 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
896 ULONG ref = InterlockedIncrement(&texture->resource.refcount);
898 TRACE("%p increasing refcount to %u.\n", iface, ref);
900 if (ref == 1)
902 IDirect3DDevice9Ex_AddRef(texture->parent_device);
903 wined3d_mutex_lock();
904 wined3d_texture_incref(texture->wined3d_texture);
905 wined3d_mutex_unlock();
908 return ref;
911 static ULONG WINAPI d3d9_texture_3d_Release(IDirect3DVolumeTexture9 *iface)
913 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
914 ULONG ref = InterlockedDecrement(&texture->resource.refcount);
916 TRACE("%p decreasing refcount to %u.\n", iface, ref);
918 if (!ref)
920 IDirect3DDevice9Ex *parent_device = texture->parent_device;
922 wined3d_mutex_lock();
923 wined3d_texture_decref(texture->wined3d_texture);
924 wined3d_mutex_unlock();
926 /* Release the device last, as it may cause the device to be destroyed. */
927 IDirect3DDevice9Ex_Release(parent_device);
929 return ref;
932 static HRESULT WINAPI d3d9_texture_3d_GetDevice(IDirect3DVolumeTexture9 *iface, IDirect3DDevice9 **device)
934 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
936 TRACE("iface %p, device %p.\n", iface, device);
938 *device = (IDirect3DDevice9 *)texture->parent_device;
939 IDirect3DDevice9_AddRef(*device);
941 TRACE("Returning device %p.\n", *device);
943 return D3D_OK;
946 static HRESULT WINAPI d3d9_texture_3d_SetPrivateData(IDirect3DVolumeTexture9 *iface,
947 REFGUID guid, const void *data, DWORD data_size, DWORD flags)
949 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
950 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
951 iface, debugstr_guid(guid), data, data_size, flags);
953 return d3d9_resource_set_private_data(&texture->resource, guid, data, data_size, flags);
956 static HRESULT WINAPI d3d9_texture_3d_GetPrivateData(IDirect3DVolumeTexture9 *iface,
957 REFGUID guid, void *data, DWORD *data_size)
959 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
960 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
961 iface, debugstr_guid(guid), data, data_size);
963 return d3d9_resource_get_private_data(&texture->resource, guid, data, data_size);
966 static HRESULT WINAPI d3d9_texture_3d_FreePrivateData(IDirect3DVolumeTexture9 *iface, REFGUID guid)
968 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
969 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
971 return d3d9_resource_free_private_data(&texture->resource, guid);
974 static DWORD WINAPI d3d9_texture_3d_SetPriority(IDirect3DVolumeTexture9 *iface, DWORD priority)
976 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
977 struct wined3d_resource *resource;
978 DWORD ret;
980 TRACE("iface %p, priority %u.\n", iface, priority);
982 wined3d_mutex_lock();
983 resource = wined3d_texture_get_resource(texture->wined3d_texture);
984 ret = wined3d_resource_set_priority(resource, priority);
985 wined3d_mutex_unlock();
987 return ret;
990 static DWORD WINAPI d3d9_texture_3d_GetPriority(IDirect3DVolumeTexture9 *iface)
992 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
993 const struct wined3d_resource *resource;
994 DWORD ret;
996 TRACE("iface %p.\n", iface);
998 wined3d_mutex_lock();
999 resource = wined3d_texture_get_resource(texture->wined3d_texture);
1000 ret = wined3d_resource_get_priority(resource);
1001 wined3d_mutex_unlock();
1003 return ret;
1006 static void WINAPI d3d9_texture_3d_PreLoad(IDirect3DVolumeTexture9 *iface)
1008 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1010 TRACE("iface %p.\n", iface);
1012 wined3d_mutex_lock();
1013 wined3d_texture_preload(texture->wined3d_texture);
1014 wined3d_mutex_unlock();
1017 static D3DRESOURCETYPE WINAPI d3d9_texture_3d_GetType(IDirect3DVolumeTexture9 *iface)
1019 TRACE("iface %p.\n", iface);
1021 return D3DRTYPE_VOLUMETEXTURE;
1024 static DWORD WINAPI d3d9_texture_3d_SetLOD(IDirect3DVolumeTexture9 *iface, DWORD lod)
1026 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1027 DWORD ret;
1029 TRACE("iface %p, lod %u.\n", iface, lod);
1031 wined3d_mutex_lock();
1032 ret = wined3d_texture_set_lod(texture->wined3d_texture, lod);
1033 wined3d_mutex_unlock();
1035 return ret;
1038 static DWORD WINAPI d3d9_texture_3d_GetLOD(IDirect3DVolumeTexture9 *iface)
1040 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1041 DWORD ret;
1043 TRACE("iface %p.\n", iface);
1045 wined3d_mutex_lock();
1046 ret = wined3d_texture_get_lod(texture->wined3d_texture);
1047 wined3d_mutex_unlock();
1049 return ret;
1052 static DWORD WINAPI d3d9_texture_3d_GetLevelCount(IDirect3DVolumeTexture9 *iface)
1054 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1055 DWORD ret;
1057 TRACE("iface %p.\n", iface);
1059 wined3d_mutex_lock();
1060 ret = wined3d_texture_get_level_count(texture->wined3d_texture);
1061 wined3d_mutex_unlock();
1063 return ret;
1066 static HRESULT WINAPI d3d9_texture_3d_SetAutoGenFilterType(IDirect3DVolumeTexture9 *iface,
1067 D3DTEXTUREFILTERTYPE filter_type)
1069 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1070 HRESULT hr;
1072 TRACE("iface %p, filter_type %#x.\n", iface, filter_type);
1074 wined3d_mutex_lock();
1075 hr = wined3d_texture_set_autogen_filter_type(texture->wined3d_texture,
1076 (enum wined3d_texture_filter_type)filter_type);
1077 wined3d_mutex_unlock();
1079 return hr;
1082 static D3DTEXTUREFILTERTYPE WINAPI d3d9_texture_3d_GetAutoGenFilterType(IDirect3DVolumeTexture9 *iface)
1084 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1085 D3DTEXTUREFILTERTYPE filter_type;
1087 TRACE("iface %p.\n", iface);
1089 wined3d_mutex_lock();
1090 filter_type = (D3DTEXTUREFILTERTYPE)wined3d_texture_get_autogen_filter_type(texture->wined3d_texture);
1091 wined3d_mutex_unlock();
1093 return filter_type;
1096 static void WINAPI d3d9_texture_3d_GenerateMipSubLevels(IDirect3DVolumeTexture9 *iface)
1098 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1100 TRACE("iface %p.\n", iface);
1102 wined3d_mutex_lock();
1103 wined3d_texture_generate_mipmaps(texture->wined3d_texture);
1104 wined3d_mutex_unlock();
1107 static HRESULT WINAPI d3d9_texture_3d_GetLevelDesc(IDirect3DVolumeTexture9 *iface, UINT level, D3DVOLUME_DESC *desc)
1109 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1110 struct wined3d_resource *sub_resource;
1111 HRESULT hr = D3D_OK;
1113 TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
1115 wined3d_mutex_lock();
1116 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
1117 hr = D3DERR_INVALIDCALL;
1118 else
1120 struct wined3d_resource_desc wined3d_desc;
1122 wined3d_resource_get_desc(sub_resource, &wined3d_desc);
1123 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
1124 desc->Type = wined3d_desc.resource_type;
1125 desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
1126 desc->Pool = wined3d_desc.pool;
1127 desc->Width = wined3d_desc.width;
1128 desc->Height = wined3d_desc.height;
1129 desc->Depth = wined3d_desc.depth;
1131 wined3d_mutex_unlock();
1133 return hr;
1136 static HRESULT WINAPI d3d9_texture_3d_GetVolumeLevel(IDirect3DVolumeTexture9 *iface,
1137 UINT level, IDirect3DVolume9 **volume)
1139 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1140 struct wined3d_resource *sub_resource;
1141 struct d3d9_volume *volume_impl;
1143 TRACE("iface %p, level %u, volume %p.\n", iface, level, volume);
1145 wined3d_mutex_lock();
1146 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
1148 wined3d_mutex_unlock();
1149 return D3DERR_INVALIDCALL;
1152 volume_impl = wined3d_resource_get_parent(sub_resource);
1153 *volume = &volume_impl->IDirect3DVolume9_iface;
1154 IDirect3DVolume9_AddRef(*volume);
1155 wined3d_mutex_unlock();
1157 return D3D_OK;
1160 static HRESULT WINAPI d3d9_texture_3d_LockBox(IDirect3DVolumeTexture9 *iface,
1161 UINT level, D3DLOCKED_BOX *locked_box, const D3DBOX *box, DWORD flags)
1163 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1164 struct wined3d_resource *sub_resource;
1165 struct d3d9_volume *volume_impl;
1166 HRESULT hr;
1168 TRACE("iface %p, level %u, locked_box %p, box %p, flags %#x.\n",
1169 iface, level, locked_box, box, flags);
1171 wined3d_mutex_lock();
1172 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
1173 hr = D3DERR_INVALIDCALL;
1174 else
1176 volume_impl = wined3d_resource_get_parent(sub_resource);
1177 hr = IDirect3DVolume9_LockBox(&volume_impl->IDirect3DVolume9_iface, locked_box, box, flags);
1179 wined3d_mutex_unlock();
1181 return hr;
1184 static HRESULT WINAPI d3d9_texture_3d_UnlockBox(IDirect3DVolumeTexture9 *iface, UINT level)
1186 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1187 struct wined3d_resource *sub_resource;
1188 struct d3d9_volume *volume_impl;
1189 HRESULT hr;
1191 TRACE("iface %p, level %u.\n", iface, level);
1193 wined3d_mutex_lock();
1194 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
1195 hr = D3DERR_INVALIDCALL;
1196 else
1198 volume_impl = wined3d_resource_get_parent(sub_resource);
1199 hr = IDirect3DVolume9_UnlockBox(&volume_impl->IDirect3DVolume9_iface);
1201 wined3d_mutex_unlock();
1203 return hr;
1206 static HRESULT WINAPI d3d9_texture_3d_AddDirtyBox(IDirect3DVolumeTexture9 *iface, const D3DBOX *dirty_box)
1208 struct d3d9_texture *texture = impl_from_IDirect3DVolumeTexture9(iface);
1209 HRESULT hr;
1211 TRACE("iface %p, dirty_box %p.\n", iface, dirty_box);
1213 wined3d_mutex_lock();
1214 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, (const struct wined3d_box *)dirty_box);
1215 wined3d_mutex_unlock();
1217 return hr;
1221 static const IDirect3DVolumeTexture9Vtbl d3d9_texture_3d_vtbl =
1223 /* IUnknown */
1224 d3d9_texture_3d_QueryInterface,
1225 d3d9_texture_3d_AddRef,
1226 d3d9_texture_3d_Release,
1227 /* IDirect3DResource9 */
1228 d3d9_texture_3d_GetDevice,
1229 d3d9_texture_3d_SetPrivateData,
1230 d3d9_texture_3d_GetPrivateData,
1231 d3d9_texture_3d_FreePrivateData,
1232 d3d9_texture_3d_SetPriority,
1233 d3d9_texture_3d_GetPriority,
1234 d3d9_texture_3d_PreLoad,
1235 d3d9_texture_3d_GetType,
1236 /* IDirect3DBaseTexture9 */
1237 d3d9_texture_3d_SetLOD,
1238 d3d9_texture_3d_GetLOD,
1239 d3d9_texture_3d_GetLevelCount,
1240 d3d9_texture_3d_SetAutoGenFilterType,
1241 d3d9_texture_3d_GetAutoGenFilterType,
1242 d3d9_texture_3d_GenerateMipSubLevels,
1243 /* IDirect3DVolumeTexture9 */
1244 d3d9_texture_3d_GetLevelDesc,
1245 d3d9_texture_3d_GetVolumeLevel,
1246 d3d9_texture_3d_LockBox,
1247 d3d9_texture_3d_UnlockBox,
1248 d3d9_texture_3d_AddDirtyBox,
1251 struct d3d9_texture *unsafe_impl_from_IDirect3DBaseTexture9(IDirect3DBaseTexture9 *iface)
1253 if (!iface)
1254 return NULL;
1256 if (iface->lpVtbl != (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_2d_vtbl
1257 && iface->lpVtbl != (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_cube_vtbl
1258 && iface->lpVtbl != (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_3d_vtbl)
1260 WARN("%p is not a valid IDirect3DBaseTexture9 interface.\n", iface);
1261 return NULL;
1264 return CONTAINING_RECORD(iface, struct d3d9_texture, IDirect3DBaseTexture9_iface);
1267 static void STDMETHODCALLTYPE d3d9_texture_wined3d_object_destroyed(void *parent)
1269 struct d3d9_texture *texture = parent;
1270 d3d9_resource_cleanup(&texture->resource);
1271 HeapFree(GetProcessHeap(), 0, texture);
1274 static const struct wined3d_parent_ops d3d9_texture_wined3d_parent_ops =
1276 d3d9_texture_wined3d_object_destroyed,
1279 HRESULT texture_init(struct d3d9_texture *texture, struct d3d9_device *device,
1280 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
1282 struct wined3d_resource_desc desc;
1283 DWORD surface_flags = 0;
1284 HRESULT hr;
1286 texture->IDirect3DBaseTexture9_iface.lpVtbl = (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_2d_vtbl;
1287 d3d9_resource_init(&texture->resource);
1288 list_init(&texture->rtv_list);
1290 desc.resource_type = WINED3D_RTYPE_TEXTURE;
1291 desc.format = wined3dformat_from_d3dformat(format);
1292 desc.multisample_type = WINED3D_MULTISAMPLE_NONE;
1293 desc.multisample_quality = 0;
1294 desc.usage = usage & WINED3DUSAGE_MASK;
1295 desc.usage |= WINED3DUSAGE_TEXTURE;
1296 desc.pool = pool;
1297 desc.width = width;
1298 desc.height = height;
1299 desc.depth = 1;
1300 desc.size = 0;
1302 if (pool != D3DPOOL_DEFAULT || (usage & D3DUSAGE_DYNAMIC))
1303 surface_flags |= WINED3D_SURFACE_MAPPABLE;
1305 if (!levels)
1307 if (usage & D3DUSAGE_AUTOGENMIPMAP)
1308 levels = 1;
1309 else
1310 levels = wined3d_log2i(max(width, height)) + 1;
1313 wined3d_mutex_lock();
1314 hr = wined3d_texture_create(device->wined3d_device, &desc, levels, surface_flags,
1315 NULL, texture, &d3d9_texture_wined3d_parent_ops, &texture->wined3d_texture);
1316 wined3d_mutex_unlock();
1317 if (FAILED(hr))
1319 WARN("Failed to create wined3d texture, hr %#x.\n", hr);
1320 return hr;
1323 texture->parent_device = &device->IDirect3DDevice9Ex_iface;
1324 IDirect3DDevice9Ex_AddRef(texture->parent_device);
1326 return D3D_OK;
1329 HRESULT cubetexture_init(struct d3d9_texture *texture, struct d3d9_device *device,
1330 UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
1332 struct wined3d_resource_desc desc;
1333 DWORD surface_flags = 0;
1334 HRESULT hr;
1336 texture->IDirect3DBaseTexture9_iface.lpVtbl = (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_cube_vtbl;
1337 d3d9_resource_init(&texture->resource);
1338 list_init(&texture->rtv_list);
1340 desc.resource_type = WINED3D_RTYPE_CUBE_TEXTURE;
1341 desc.format = wined3dformat_from_d3dformat(format);
1342 desc.multisample_type = WINED3D_MULTISAMPLE_NONE;
1343 desc.multisample_quality = 0;
1344 desc.usage = usage & WINED3DUSAGE_MASK;
1345 desc.usage |= WINED3DUSAGE_TEXTURE;
1346 desc.pool = pool;
1347 desc.width = edge_length;
1348 desc.height = edge_length;
1349 desc.depth = 1;
1350 desc.size = 0;
1352 if (pool != D3DPOOL_DEFAULT || (usage & D3DUSAGE_DYNAMIC))
1353 surface_flags |= WINED3D_SURFACE_MAPPABLE;
1355 if (!levels)
1357 if (usage & D3DUSAGE_AUTOGENMIPMAP)
1358 levels = 1;
1359 else
1360 levels = wined3d_log2i(edge_length) + 1;
1363 wined3d_mutex_lock();
1364 hr = wined3d_texture_create(device->wined3d_device, &desc, levels, surface_flags,
1365 NULL, texture, &d3d9_texture_wined3d_parent_ops, &texture->wined3d_texture);
1366 wined3d_mutex_unlock();
1367 if (FAILED(hr))
1369 WARN("Failed to create wined3d cube texture, hr %#x.\n", hr);
1370 return hr;
1373 texture->parent_device = &device->IDirect3DDevice9Ex_iface;
1374 IDirect3DDevice9Ex_AddRef(texture->parent_device);
1376 return D3D_OK;
1379 HRESULT volumetexture_init(struct d3d9_texture *texture, struct d3d9_device *device,
1380 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
1382 struct wined3d_resource_desc desc;
1383 HRESULT hr;
1385 texture->IDirect3DBaseTexture9_iface.lpVtbl = (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_3d_vtbl;
1386 d3d9_resource_init(&texture->resource);
1387 list_init(&texture->rtv_list);
1389 desc.resource_type = WINED3D_RTYPE_VOLUME_TEXTURE;
1390 desc.format = wined3dformat_from_d3dformat(format);
1391 desc.multisample_type = WINED3D_MULTISAMPLE_NONE;
1392 desc.multisample_quality = 0;
1393 desc.usage = usage & WINED3DUSAGE_MASK;
1394 desc.usage |= WINED3DUSAGE_TEXTURE;
1395 desc.pool = pool;
1396 desc.width = width;
1397 desc.height = height;
1398 desc.depth = depth;
1399 desc.size = 0;
1401 if (!levels)
1403 if (usage & D3DUSAGE_AUTOGENMIPMAP)
1404 levels = 1;
1405 else
1406 levels = wined3d_log2i(max(max(width, height), depth)) + 1;
1409 wined3d_mutex_lock();
1410 hr = wined3d_texture_create(device->wined3d_device, &desc, levels, 0,
1411 NULL, texture, &d3d9_texture_wined3d_parent_ops, &texture->wined3d_texture);
1412 wined3d_mutex_unlock();
1413 if (FAILED(hr))
1415 WARN("Failed to create wined3d volume texture, hr %#x.\n", hr);
1416 return hr;
1419 texture->parent_device = &device->IDirect3DDevice9Ex_iface;
1420 IDirect3DDevice9Ex_AddRef(texture->parent_device);
1422 return D3D_OK;