2 * Copyright 2005 Oliver Stieber
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "d3d8_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
24 static inline struct d3d8_texture *impl_from_IDirect3DTexture8(IDirect3DTexture8 *iface)
26 return CONTAINING_RECORD(iface, struct d3d8_texture, IDirect3DBaseTexture8_iface);
29 static inline struct d3d8_texture *impl_from_IDirect3DCubeTexture8(IDirect3DCubeTexture8 *iface)
31 return CONTAINING_RECORD(iface, struct d3d8_texture, IDirect3DBaseTexture8_iface);
34 static inline struct d3d8_texture *impl_from_IDirect3DVolumeTexture8(IDirect3DVolumeTexture8 *iface)
36 return CONTAINING_RECORD(iface, struct d3d8_texture, IDirect3DBaseTexture8_iface);
39 static HRESULT WINAPI d3d8_texture_2d_QueryInterface(IDirect3DTexture8 *iface, REFIID riid, void **out)
41 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
43 if (IsEqualGUID(riid, &IID_IDirect3DTexture8)
44 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
45 || IsEqualGUID(riid, &IID_IDirect3DResource8)
46 || IsEqualGUID(riid, &IID_IUnknown))
48 IUnknown_AddRef(iface);
53 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
59 static ULONG WINAPI d3d8_texture_2d_AddRef(IDirect3DTexture8 *iface)
61 struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
62 ULONG ref = InterlockedIncrement(&texture->refcount);
64 TRACE("%p increasing refcount to %u.\n", iface, ref);
68 IDirect3DDevice8_AddRef(texture->parent_device);
70 wined3d_texture_incref(texture->wined3d_texture);
71 wined3d_mutex_unlock();
77 static ULONG WINAPI d3d8_texture_2d_Release(IDirect3DTexture8 *iface)
79 struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
80 ULONG ref = InterlockedDecrement(&texture->refcount);
82 TRACE("%p decreasing refcount to %u.\n", iface, ref);
86 IDirect3DDevice8 *parent_device = texture->parent_device;
89 wined3d_texture_decref(texture->wined3d_texture);
90 wined3d_mutex_unlock();
92 /* Release the device last, as it may cause the device to be destroyed. */
93 IDirect3DDevice8_Release(parent_device);
98 static HRESULT WINAPI d3d8_texture_2d_GetDevice(IDirect3DTexture8 *iface, IDirect3DDevice8 **device)
100 struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
102 TRACE("iface %p, device %p.\n", iface, device);
104 *device = texture->parent_device;
105 IDirect3DDevice8_AddRef(*device);
107 TRACE("Returning device %p.\n", *device);
112 static HRESULT WINAPI d3d8_texture_2d_SetPrivateData(IDirect3DTexture8 *iface,
113 REFGUID guid, const void *data, DWORD data_size, DWORD flags)
115 struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
116 struct wined3d_resource *resource;
119 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
120 iface, debugstr_guid(guid), data, data_size, flags);
122 wined3d_mutex_lock();
123 resource = wined3d_texture_get_resource(texture->wined3d_texture);
124 hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags);
125 wined3d_mutex_unlock();
130 static HRESULT WINAPI d3d8_texture_2d_GetPrivateData(IDirect3DTexture8 *iface,
131 REFGUID guid, void *data, DWORD *data_size)
133 struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
134 struct wined3d_resource *resource;
137 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
138 iface, debugstr_guid(guid), data, data_size);
140 wined3d_mutex_lock();
141 resource = wined3d_texture_get_resource(texture->wined3d_texture);
142 hr = wined3d_resource_get_private_data(resource, guid, data, data_size);
143 wined3d_mutex_unlock();
148 static HRESULT WINAPI d3d8_texture_2d_FreePrivateData(IDirect3DTexture8 *iface, REFGUID guid)
150 struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
151 struct wined3d_resource *resource;
154 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
156 wined3d_mutex_lock();
157 resource = wined3d_texture_get_resource(texture->wined3d_texture);
158 hr = wined3d_resource_free_private_data(resource, guid);
159 wined3d_mutex_unlock();
164 static DWORD WINAPI d3d8_texture_2d_SetPriority(IDirect3DTexture8 *iface, DWORD priority)
166 struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
169 TRACE("iface %p, priority %u.\n", iface, priority);
171 wined3d_mutex_lock();
172 ret = wined3d_texture_set_priority(texture->wined3d_texture, priority);
173 wined3d_mutex_unlock();
178 static DWORD WINAPI d3d8_texture_2d_GetPriority(IDirect3DTexture8 *iface)
180 struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
183 TRACE("iface %p.\n", iface);
185 wined3d_mutex_lock();
186 ret = wined3d_texture_get_priority(texture->wined3d_texture);
187 wined3d_mutex_unlock();
192 static void WINAPI d3d8_texture_2d_PreLoad(IDirect3DTexture8 *iface)
194 struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
196 TRACE("iface %p.\n", iface);
198 wined3d_mutex_lock();
199 wined3d_texture_preload(texture->wined3d_texture);
200 wined3d_mutex_unlock();
203 static D3DRESOURCETYPE WINAPI d3d8_texture_2d_GetType(IDirect3DTexture8 *iface)
205 TRACE("iface %p.\n", iface);
207 return D3DRTYPE_TEXTURE;
210 static DWORD WINAPI d3d8_texture_2d_SetLOD(IDirect3DTexture8 *iface, DWORD lod)
212 struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
215 TRACE("iface %p, lod %u.\n", iface, lod);
217 wined3d_mutex_lock();
218 ret = wined3d_texture_set_lod(texture->wined3d_texture, lod);
219 wined3d_mutex_unlock();
224 static DWORD WINAPI d3d8_texture_2d_GetLOD(IDirect3DTexture8 *iface)
226 struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
229 TRACE("iface %p.\n", iface);
231 wined3d_mutex_lock();
232 ret = wined3d_texture_get_lod(texture->wined3d_texture);
233 wined3d_mutex_unlock();
238 static DWORD WINAPI d3d8_texture_2d_GetLevelCount(IDirect3DTexture8 *iface)
240 struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
243 TRACE("iface %p.\n", iface);
245 wined3d_mutex_lock();
246 ret = wined3d_texture_get_level_count(texture->wined3d_texture);
247 wined3d_mutex_unlock();
252 static HRESULT WINAPI d3d8_texture_2d_GetLevelDesc(IDirect3DTexture8 *iface, UINT level, D3DSURFACE_DESC *desc)
254 struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
255 struct wined3d_resource *sub_resource;
258 TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
260 wined3d_mutex_lock();
261 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
262 hr = D3DERR_INVALIDCALL;
265 struct wined3d_resource_desc wined3d_desc;
267 wined3d_resource_get_desc(sub_resource, &wined3d_desc);
268 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
269 desc->Type = wined3d_desc.resource_type;
270 desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
271 desc->Pool = wined3d_desc.pool;
272 desc->Size = wined3d_desc.size;
273 desc->MultiSampleType = wined3d_desc.multisample_type;
274 desc->Width = wined3d_desc.width;
275 desc->Height = wined3d_desc.height;
277 wined3d_mutex_unlock();
282 static HRESULT WINAPI d3d8_texture_2d_GetSurfaceLevel(IDirect3DTexture8 *iface,
283 UINT level, IDirect3DSurface8 **surface)
285 struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
286 struct wined3d_resource *sub_resource;
287 IDirect3DSurface8Impl *surface_impl;
289 TRACE("iface %p, level %u, surface %p.\n", iface, level, surface);
291 wined3d_mutex_lock();
292 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
294 wined3d_mutex_unlock();
295 return D3DERR_INVALIDCALL;
298 surface_impl = wined3d_resource_get_parent(sub_resource);
299 *surface = &surface_impl->IDirect3DSurface8_iface;
300 IDirect3DSurface8_AddRef(*surface);
301 wined3d_mutex_unlock();
306 static HRESULT WINAPI d3d8_texture_2d_LockRect(IDirect3DTexture8 *iface, UINT level,
307 D3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags)
309 struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
310 struct wined3d_resource *sub_resource;
311 IDirect3DSurface8Impl *surface_impl;
314 TRACE("iface %p, level %u, locked_rect %p, rect %p, flags %#x.\n",
315 iface, level, locked_rect, rect, flags);
317 wined3d_mutex_lock();
318 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
319 hr = D3DERR_INVALIDCALL;
322 surface_impl = wined3d_resource_get_parent(sub_resource);
323 hr = IDirect3DSurface8_LockRect(&surface_impl->IDirect3DSurface8_iface, locked_rect, rect, flags);
325 wined3d_mutex_unlock();
330 static HRESULT WINAPI d3d8_texture_2d_UnlockRect(IDirect3DTexture8 *iface, UINT level)
332 struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
333 struct wined3d_resource *sub_resource;
334 IDirect3DSurface8Impl *surface_impl;
337 TRACE("iface %p, level %u.\n", iface, level);
339 wined3d_mutex_lock();
340 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
341 hr = D3DERR_INVALIDCALL;
344 surface_impl = wined3d_resource_get_parent(sub_resource);
345 hr = IDirect3DSurface8_UnlockRect(&surface_impl->IDirect3DSurface8_iface);
347 wined3d_mutex_unlock();
352 static HRESULT WINAPI d3d8_texture_2d_AddDirtyRect(IDirect3DTexture8 *iface, const RECT *dirty_rect)
354 struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
357 TRACE("iface %p, dirty_rect %s.\n",
358 iface, wine_dbgstr_rect(dirty_rect));
360 wined3d_mutex_lock();
362 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, NULL);
365 struct wined3d_box dirty_region;
367 dirty_region.left = dirty_rect->left;
368 dirty_region.top = dirty_rect->top;
369 dirty_region.right = dirty_rect->right;
370 dirty_region.bottom = dirty_rect->bottom;
371 dirty_region.front = 0;
372 dirty_region.back = 1;
373 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, &dirty_region);
375 wined3d_mutex_unlock();
380 static const IDirect3DTexture8Vtbl Direct3DTexture8_Vtbl =
383 d3d8_texture_2d_QueryInterface,
384 d3d8_texture_2d_AddRef,
385 d3d8_texture_2d_Release,
386 /* IDirect3DResource8 */
387 d3d8_texture_2d_GetDevice,
388 d3d8_texture_2d_SetPrivateData,
389 d3d8_texture_2d_GetPrivateData,
390 d3d8_texture_2d_FreePrivateData,
391 d3d8_texture_2d_SetPriority,
392 d3d8_texture_2d_GetPriority,
393 d3d8_texture_2d_PreLoad,
394 d3d8_texture_2d_GetType,
395 /* IDirect3dBaseTexture8 */
396 d3d8_texture_2d_SetLOD,
397 d3d8_texture_2d_GetLOD,
398 d3d8_texture_2d_GetLevelCount,
399 /* IDirect3DTexture8 */
400 d3d8_texture_2d_GetLevelDesc,
401 d3d8_texture_2d_GetSurfaceLevel,
402 d3d8_texture_2d_LockRect,
403 d3d8_texture_2d_UnlockRect,
404 d3d8_texture_2d_AddDirtyRect,
407 static HRESULT WINAPI d3d8_texture_cube_QueryInterface(IDirect3DCubeTexture8 *iface, REFIID riid, void **out)
409 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
411 if (IsEqualGUID(riid, &IID_IDirect3DCubeTexture8)
412 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
413 || IsEqualGUID(riid, &IID_IDirect3DResource8)
414 || IsEqualGUID(riid, &IID_IUnknown))
416 IUnknown_AddRef(iface);
421 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
424 return E_NOINTERFACE;
427 static ULONG WINAPI d3d8_texture_cube_AddRef(IDirect3DCubeTexture8 *iface)
429 struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
430 ULONG ref = InterlockedIncrement(&texture->refcount);
432 TRACE("%p increasing refcount to %u.\n", iface, ref);
436 IUnknown_AddRef(texture->parent_device);
437 wined3d_mutex_lock();
438 wined3d_texture_incref(texture->wined3d_texture);
439 wined3d_mutex_unlock();
445 static ULONG WINAPI d3d8_texture_cube_Release(IDirect3DCubeTexture8 *iface)
447 struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
448 ULONG ref = InterlockedDecrement(&texture->refcount);
450 TRACE("%p decreasing refcount to %u.\n", iface, ref);
454 IDirect3DDevice8 *parent_device = texture->parent_device;
456 TRACE("Releasing child %p.\n", texture->wined3d_texture);
458 wined3d_mutex_lock();
459 wined3d_texture_decref(texture->wined3d_texture);
460 wined3d_mutex_unlock();
462 /* Release the device last, as it may cause the device to be destroyed. */
463 IDirect3DDevice8_Release(parent_device);
468 static HRESULT WINAPI d3d8_texture_cube_GetDevice(IDirect3DCubeTexture8 *iface, IDirect3DDevice8 **device)
470 struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
472 TRACE("iface %p, device %p.\n", iface, device);
474 *device = texture->parent_device;
475 IDirect3DDevice8_AddRef(*device);
477 TRACE("Returning device %p.\n", *device);
482 static HRESULT WINAPI d3d8_texture_cube_SetPrivateData(IDirect3DCubeTexture8 *iface,
483 REFGUID guid, const void *data, DWORD data_size, DWORD flags)
485 struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
486 struct wined3d_resource *resource;
489 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
490 iface, debugstr_guid(guid), data, data_size, flags);
492 wined3d_mutex_lock();
493 resource = wined3d_texture_get_resource(texture->wined3d_texture);
494 hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags);
495 wined3d_mutex_unlock();
500 static HRESULT WINAPI d3d8_texture_cube_GetPrivateData(IDirect3DCubeTexture8 *iface,
501 REFGUID guid, void *data, DWORD *data_size)
503 struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
504 struct wined3d_resource *resource;
507 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
508 iface, debugstr_guid(guid), data, data_size);
510 wined3d_mutex_lock();
511 resource = wined3d_texture_get_resource(texture->wined3d_texture);
512 hr = wined3d_resource_get_private_data(resource, guid, data, data_size);
513 wined3d_mutex_unlock();
518 static HRESULT WINAPI d3d8_texture_cube_FreePrivateData(IDirect3DCubeTexture8 *iface, REFGUID guid)
520 struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
521 struct wined3d_resource *resource;
524 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
526 wined3d_mutex_lock();
527 resource = wined3d_texture_get_resource(texture->wined3d_texture);
528 hr = wined3d_resource_free_private_data(resource, guid);
529 wined3d_mutex_unlock();
534 static DWORD WINAPI d3d8_texture_cube_SetPriority(IDirect3DCubeTexture8 *iface, DWORD priority)
536 struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
539 TRACE("iface %p, priority %u.\n", iface, priority);
541 wined3d_mutex_lock();
542 ret = wined3d_texture_set_priority(texture->wined3d_texture, priority);
543 wined3d_mutex_unlock();
548 static DWORD WINAPI d3d8_texture_cube_GetPriority(IDirect3DCubeTexture8 *iface)
550 struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
553 TRACE("iface %p.\n", iface);
555 wined3d_mutex_lock();
556 ret = wined3d_texture_get_priority(texture->wined3d_texture);
557 wined3d_mutex_unlock();
562 static void WINAPI d3d8_texture_cube_PreLoad(IDirect3DCubeTexture8 *iface)
564 struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
566 TRACE("iface %p.\n", iface);
568 wined3d_mutex_lock();
569 wined3d_texture_preload(texture->wined3d_texture);
570 wined3d_mutex_unlock();
573 static D3DRESOURCETYPE WINAPI d3d8_texture_cube_GetType(IDirect3DCubeTexture8 *iface)
575 TRACE("iface %p.\n", iface);
577 return D3DRTYPE_CUBETEXTURE;
580 static DWORD WINAPI d3d8_texture_cube_SetLOD(IDirect3DCubeTexture8 *iface, DWORD lod)
582 struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
585 TRACE("iface %p, lod %u.\n", iface, lod);
587 wined3d_mutex_lock();
588 ret = wined3d_texture_set_lod(texture->wined3d_texture, lod);
589 wined3d_mutex_unlock();
594 static DWORD WINAPI d3d8_texture_cube_GetLOD(IDirect3DCubeTexture8 *iface)
596 struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
599 TRACE("iface %p.\n", iface);
601 wined3d_mutex_lock();
602 ret = wined3d_texture_get_lod(texture->wined3d_texture);
603 wined3d_mutex_unlock();
608 static DWORD WINAPI d3d8_texture_cube_GetLevelCount(IDirect3DCubeTexture8 *iface)
610 struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
613 TRACE("iface %p.\n", iface);
615 wined3d_mutex_lock();
616 ret = wined3d_texture_get_level_count(texture->wined3d_texture);
617 wined3d_mutex_unlock();
622 static HRESULT WINAPI d3d8_texture_cube_GetLevelDesc(IDirect3DCubeTexture8 *iface, UINT level, D3DSURFACE_DESC *desc)
624 struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
625 struct wined3d_resource *sub_resource;
628 TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
630 wined3d_mutex_lock();
631 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
632 hr = D3DERR_INVALIDCALL;
635 struct wined3d_resource_desc wined3d_desc;
637 wined3d_resource_get_desc(sub_resource, &wined3d_desc);
638 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
639 desc->Type = wined3d_desc.resource_type;
640 desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
641 desc->Pool = wined3d_desc.pool;
642 desc->Size = wined3d_desc.size;
643 desc->MultiSampleType = wined3d_desc.multisample_type;
644 desc->Width = wined3d_desc.width;
645 desc->Height = wined3d_desc.height;
647 wined3d_mutex_unlock();
652 static HRESULT WINAPI d3d8_texture_cube_GetCubeMapSurface(IDirect3DCubeTexture8 *iface,
653 D3DCUBEMAP_FACES face, UINT level, IDirect3DSurface8 **surface)
655 struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
656 struct wined3d_resource *sub_resource;
657 IDirect3DSurface8Impl *surface_impl;
658 UINT sub_resource_idx;
660 TRACE("iface %p, face %#x, level %u, surface %p.\n", iface, face, level, surface);
662 wined3d_mutex_lock();
663 sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
664 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
666 wined3d_mutex_unlock();
667 return D3DERR_INVALIDCALL;
670 surface_impl = wined3d_resource_get_parent(sub_resource);
671 *surface = &surface_impl->IDirect3DSurface8_iface;
672 IDirect3DSurface8_AddRef(*surface);
673 wined3d_mutex_unlock();
678 static HRESULT WINAPI d3d8_texture_cube_LockRect(IDirect3DCubeTexture8 *iface,
679 D3DCUBEMAP_FACES face, UINT level, D3DLOCKED_RECT *locked_rect, const RECT *rect,
682 struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
683 struct wined3d_resource *sub_resource;
684 IDirect3DSurface8Impl *surface_impl;
685 UINT sub_resource_idx;
688 TRACE("iface %p, face %#x, level %u, locked_rect %p, rect %p, flags %#x.\n",
689 iface, face, level, locked_rect, rect, flags);
691 wined3d_mutex_lock();
692 sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
693 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
694 hr = D3DERR_INVALIDCALL;
697 surface_impl = wined3d_resource_get_parent(sub_resource);
698 hr = IDirect3DSurface8_LockRect(&surface_impl->IDirect3DSurface8_iface, locked_rect, rect, flags);
700 wined3d_mutex_unlock();
705 static HRESULT WINAPI d3d8_texture_cube_UnlockRect(IDirect3DCubeTexture8 *iface,
706 D3DCUBEMAP_FACES face, UINT level)
708 struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
709 struct wined3d_resource *sub_resource;
710 IDirect3DSurface8Impl *surface_impl;
711 UINT sub_resource_idx;
714 TRACE("iface %p, face %#x, level %u.\n", iface, face, level);
716 wined3d_mutex_lock();
717 sub_resource_idx = wined3d_texture_get_level_count(texture->wined3d_texture) * face + level;
718 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
719 hr = D3DERR_INVALIDCALL;
722 surface_impl = wined3d_resource_get_parent(sub_resource);
723 hr = IDirect3DSurface8_UnlockRect(&surface_impl->IDirect3DSurface8_iface);
725 wined3d_mutex_unlock();
730 static HRESULT WINAPI d3d8_texture_cube_AddDirtyRect(IDirect3DCubeTexture8 *iface,
731 D3DCUBEMAP_FACES face, const RECT *dirty_rect)
733 struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
736 TRACE("iface %p, face %#x, dirty_rect %s.\n",
737 iface, face, wine_dbgstr_rect(dirty_rect));
739 wined3d_mutex_lock();
741 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, NULL);
744 struct wined3d_box dirty_region;
746 dirty_region.left = dirty_rect->left;
747 dirty_region.top = dirty_rect->top;
748 dirty_region.right = dirty_rect->right;
749 dirty_region.bottom = dirty_rect->bottom;
750 dirty_region.front = 0;
751 dirty_region.back = 1;
752 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, &dirty_region);
754 wined3d_mutex_unlock();
759 static const IDirect3DCubeTexture8Vtbl Direct3DCubeTexture8_Vtbl =
762 d3d8_texture_cube_QueryInterface,
763 d3d8_texture_cube_AddRef,
764 d3d8_texture_cube_Release,
765 /* IDirect3DResource8 */
766 d3d8_texture_cube_GetDevice,
767 d3d8_texture_cube_SetPrivateData,
768 d3d8_texture_cube_GetPrivateData,
769 d3d8_texture_cube_FreePrivateData,
770 d3d8_texture_cube_SetPriority,
771 d3d8_texture_cube_GetPriority,
772 d3d8_texture_cube_PreLoad,
773 d3d8_texture_cube_GetType,
774 /* IDirect3DBaseTexture8 */
775 d3d8_texture_cube_SetLOD,
776 d3d8_texture_cube_GetLOD,
777 d3d8_texture_cube_GetLevelCount,
778 /* IDirect3DCubeTexture8 */
779 d3d8_texture_cube_GetLevelDesc,
780 d3d8_texture_cube_GetCubeMapSurface,
781 d3d8_texture_cube_LockRect,
782 d3d8_texture_cube_UnlockRect,
783 d3d8_texture_cube_AddDirtyRect,
786 static HRESULT WINAPI d3d8_texture_3d_QueryInterface(IDirect3DVolumeTexture8 *iface, REFIID riid, void **out)
788 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
790 if (IsEqualGUID(riid, &IID_IDirect3DVolumeTexture8)
791 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
792 || IsEqualGUID(riid, &IID_IDirect3DResource8)
793 || IsEqualGUID(riid, &IID_IUnknown))
795 IUnknown_AddRef(iface);
800 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
803 return E_NOINTERFACE;
806 static ULONG WINAPI d3d8_texture_3d_AddRef(IDirect3DVolumeTexture8 *iface)
808 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
809 ULONG ref = InterlockedIncrement(&texture->refcount);
811 TRACE("%p increasing refcount to %u.\n", iface, ref);
815 IDirect3DDevice8_AddRef(texture->parent_device);
816 wined3d_mutex_lock();
817 wined3d_texture_incref(texture->wined3d_texture);
818 wined3d_mutex_unlock();
824 static ULONG WINAPI d3d8_texture_3d_Release(IDirect3DVolumeTexture8 *iface)
826 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
827 ULONG ref = InterlockedDecrement(&texture->refcount);
829 TRACE("%p decreasing refcount to %u.\n", iface, ref);
833 IDirect3DDevice8 *parent_device = texture->parent_device;
835 wined3d_mutex_lock();
836 wined3d_texture_decref(texture->wined3d_texture);
837 wined3d_mutex_unlock();
839 /* Release the device last, as it may cause the device to be destroyed. */
840 IDirect3DDevice8_Release(parent_device);
845 static HRESULT WINAPI d3d8_texture_3d_GetDevice(IDirect3DVolumeTexture8 *iface, IDirect3DDevice8 **device)
847 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
849 TRACE("iface %p, device %p.\n", iface, device);
851 *device = texture->parent_device;
852 IDirect3DDevice8_AddRef(*device);
854 TRACE("Returning device %p.\n", *device);
859 static HRESULT WINAPI d3d8_texture_3d_SetPrivateData(IDirect3DVolumeTexture8 *iface,
860 REFGUID guid, const void *data, DWORD data_size, DWORD flags)
862 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
863 struct wined3d_resource *resource;
866 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
867 iface, debugstr_guid(guid), data, data_size, flags);
869 wined3d_mutex_lock();
870 resource = wined3d_texture_get_resource(texture->wined3d_texture);
871 hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags);
872 wined3d_mutex_unlock();
877 static HRESULT WINAPI d3d8_texture_3d_GetPrivateData(IDirect3DVolumeTexture8 *iface,
878 REFGUID guid, void *data, DWORD *data_size)
880 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
881 struct wined3d_resource *resource;
884 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
885 iface, debugstr_guid(guid), data, data_size);
887 wined3d_mutex_lock();
888 resource = wined3d_texture_get_resource(texture->wined3d_texture);
889 hr = wined3d_resource_get_private_data(resource, guid, data, data_size);
890 wined3d_mutex_unlock();
895 static HRESULT WINAPI d3d8_texture_3d_FreePrivateData(IDirect3DVolumeTexture8 *iface, REFGUID guid)
897 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
898 struct wined3d_resource *resource;
901 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
903 wined3d_mutex_lock();
904 resource = wined3d_texture_get_resource(texture->wined3d_texture);
905 hr = wined3d_resource_free_private_data(resource, guid);
906 wined3d_mutex_unlock();
911 static DWORD WINAPI d3d8_texture_3d_SetPriority(IDirect3DVolumeTexture8 *iface, DWORD priority)
913 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
916 TRACE("iface %p, priority %u.\n", iface, priority);
918 wined3d_mutex_lock();
919 ret = wined3d_texture_set_priority(texture->wined3d_texture, priority);
920 wined3d_mutex_unlock();
925 static DWORD WINAPI d3d8_texture_3d_GetPriority(IDirect3DVolumeTexture8 *iface)
927 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
930 TRACE("iface %p.\n", iface);
932 wined3d_mutex_lock();
933 ret = wined3d_texture_get_priority(texture->wined3d_texture);
934 wined3d_mutex_unlock();
939 static void WINAPI d3d8_texture_3d_PreLoad(IDirect3DVolumeTexture8 *iface)
941 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
943 TRACE("iface %p.\n", iface);
945 wined3d_mutex_lock();
946 wined3d_texture_preload(texture->wined3d_texture);
947 wined3d_mutex_unlock();
950 static D3DRESOURCETYPE WINAPI d3d8_texture_3d_GetType(IDirect3DVolumeTexture8 *iface)
952 TRACE("iface %p.\n", iface);
954 return D3DRTYPE_VOLUMETEXTURE;
957 static DWORD WINAPI d3d8_texture_3d_SetLOD(IDirect3DVolumeTexture8 *iface, DWORD lod)
959 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
962 TRACE("iface %p, lod %u.\n", iface, lod);
964 wined3d_mutex_lock();
965 ret = wined3d_texture_set_lod(texture->wined3d_texture, lod);
966 wined3d_mutex_unlock();
971 static DWORD WINAPI d3d8_texture_3d_GetLOD(IDirect3DVolumeTexture8 *iface)
973 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
976 TRACE("iface %p.\n", iface);
978 wined3d_mutex_lock();
979 ret = wined3d_texture_get_lod(texture->wined3d_texture);
980 wined3d_mutex_unlock();
985 static DWORD WINAPI d3d8_texture_3d_GetLevelCount(IDirect3DVolumeTexture8 *iface)
987 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
990 TRACE("iface %p.\n", iface);
992 wined3d_mutex_lock();
993 ret = wined3d_texture_get_level_count(texture->wined3d_texture);
994 wined3d_mutex_unlock();
999 static HRESULT WINAPI d3d8_texture_3d_GetLevelDesc(IDirect3DVolumeTexture8 *iface, UINT level, D3DVOLUME_DESC *desc)
1001 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
1002 struct wined3d_resource *sub_resource;
1003 HRESULT hr = D3D_OK;
1005 TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
1007 wined3d_mutex_lock();
1008 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
1009 hr = D3DERR_INVALIDCALL;
1012 struct wined3d_resource_desc wined3d_desc;
1014 wined3d_resource_get_desc(sub_resource, &wined3d_desc);
1015 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
1016 desc->Type = wined3d_desc.resource_type;
1017 desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
1018 desc->Pool = wined3d_desc.pool;
1019 desc->Size = wined3d_desc.size;
1020 desc->Width = wined3d_desc.width;
1021 desc->Height = wined3d_desc.height;
1022 desc->Depth = wined3d_desc.depth;
1024 wined3d_mutex_unlock();
1029 static HRESULT WINAPI d3d8_texture_3d_GetVolumeLevel(IDirect3DVolumeTexture8 *iface,
1030 UINT level, IDirect3DVolume8 **volume)
1032 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
1033 struct wined3d_resource *sub_resource;
1034 IDirect3DVolume8Impl *volume_impl;
1036 TRACE("iface %p, level %u, volume %p.\n", iface, level, volume);
1038 wined3d_mutex_lock();
1039 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
1041 wined3d_mutex_unlock();
1042 return D3DERR_INVALIDCALL;
1045 volume_impl = wined3d_resource_get_parent(sub_resource);
1046 *volume = &volume_impl->IDirect3DVolume8_iface;
1047 IDirect3DVolume8_AddRef(*volume);
1048 wined3d_mutex_unlock();
1053 static HRESULT WINAPI d3d8_texture_3d_LockBox(IDirect3DVolumeTexture8 *iface,
1054 UINT level, D3DLOCKED_BOX *locked_box, const D3DBOX *box, DWORD flags)
1056 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
1057 struct wined3d_resource *sub_resource;
1058 IDirect3DVolume8Impl *volume_impl;
1061 TRACE("iface %p, level %u, locked_box %p, box %p, flags %#x.\n",
1062 iface, level, locked_box, box, flags);
1064 wined3d_mutex_lock();
1065 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
1066 hr = D3DERR_INVALIDCALL;
1069 volume_impl = wined3d_resource_get_parent(sub_resource);
1070 hr = IDirect3DVolume8_LockBox(&volume_impl->IDirect3DVolume8_iface, locked_box, box, flags);
1072 wined3d_mutex_unlock();
1077 static HRESULT WINAPI d3d8_texture_3d_UnlockBox(IDirect3DVolumeTexture8 *iface, UINT level)
1079 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
1080 struct wined3d_resource *sub_resource;
1081 IDirect3DVolume8Impl *volume_impl;
1084 TRACE("iface %p, level %u.\n", iface, level);
1086 wined3d_mutex_lock();
1087 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
1088 hr = D3DERR_INVALIDCALL;
1091 volume_impl = wined3d_resource_get_parent(sub_resource);
1092 hr = IDirect3DVolume8_UnlockBox(&volume_impl->IDirect3DVolume8_iface);
1094 wined3d_mutex_unlock();
1099 static HRESULT WINAPI d3d8_texture_3d_AddDirtyBox(IDirect3DVolumeTexture8 *iface, const D3DBOX *dirty_box)
1101 struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
1104 TRACE("iface %p, dirty_box %p.\n", iface, dirty_box);
1106 wined3d_mutex_lock();
1107 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, (const struct wined3d_box *)dirty_box);
1108 wined3d_mutex_unlock();
1113 static const IDirect3DVolumeTexture8Vtbl Direct3DVolumeTexture8_Vtbl =
1116 d3d8_texture_3d_QueryInterface,
1117 d3d8_texture_3d_AddRef,
1118 d3d8_texture_3d_Release,
1119 /* IDirect3DResource8 */
1120 d3d8_texture_3d_GetDevice,
1121 d3d8_texture_3d_SetPrivateData,
1122 d3d8_texture_3d_GetPrivateData,
1123 d3d8_texture_3d_FreePrivateData,
1124 d3d8_texture_3d_SetPriority,
1125 d3d8_texture_3d_GetPriority,
1126 d3d8_texture_3d_PreLoad,
1127 d3d8_texture_3d_GetType,
1128 /* IDirect3DBaseTexture8 */
1129 d3d8_texture_3d_SetLOD,
1130 d3d8_texture_3d_GetLOD,
1131 d3d8_texture_3d_GetLevelCount,
1132 /* IDirect3DVolumeTexture8 */
1133 d3d8_texture_3d_GetLevelDesc,
1134 d3d8_texture_3d_GetVolumeLevel,
1135 d3d8_texture_3d_LockBox,
1136 d3d8_texture_3d_UnlockBox,
1137 d3d8_texture_3d_AddDirtyBox
1140 struct d3d8_texture *unsafe_impl_from_IDirect3DBaseTexture8(IDirect3DBaseTexture8 *iface)
1144 assert(iface->lpVtbl == (const IDirect3DBaseTexture8Vtbl *)&Direct3DTexture8_Vtbl
1145 || iface->lpVtbl == (const IDirect3DBaseTexture8Vtbl *)&Direct3DCubeTexture8_Vtbl
1146 || iface->lpVtbl == (const IDirect3DBaseTexture8Vtbl *)&Direct3DVolumeTexture8_Vtbl);
1147 return CONTAINING_RECORD(iface, struct d3d8_texture, IDirect3DBaseTexture8_iface);
1150 static void STDMETHODCALLTYPE d3d8_texture_wined3d_object_destroyed(void *parent)
1152 HeapFree(GetProcessHeap(), 0, parent);
1155 static const struct wined3d_parent_ops d3d8_texture_wined3d_parent_ops =
1157 d3d8_texture_wined3d_object_destroyed,
1160 HRESULT texture_init(struct d3d8_texture *texture, IDirect3DDevice8Impl *device,
1161 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
1165 texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DTexture8_Vtbl;
1166 texture->refcount = 1;
1168 wined3d_mutex_lock();
1169 hr = wined3d_texture_create_2d(device->wined3d_device, width, height, levels,
1170 usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool,
1171 texture, &d3d8_texture_wined3d_parent_ops, &texture->wined3d_texture);
1172 wined3d_mutex_unlock();
1175 WARN("Failed to create wined3d texture, hr %#x.\n", hr);
1179 texture->parent_device = &device->IDirect3DDevice8_iface;
1180 IDirect3DDevice8_AddRef(texture->parent_device);
1185 HRESULT cubetexture_init(struct d3d8_texture *texture, IDirect3DDevice8Impl *device,
1186 UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
1190 texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DCubeTexture8_Vtbl;
1191 texture->refcount = 1;
1193 wined3d_mutex_lock();
1194 hr = wined3d_texture_create_cube(device->wined3d_device, edge_length, levels,
1195 usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool, texture,
1196 &d3d8_texture_wined3d_parent_ops, &texture->wined3d_texture);
1197 wined3d_mutex_unlock();
1200 WARN("Failed to create wined3d cube texture, hr %#x.\n", hr);
1204 texture->parent_device = &device->IDirect3DDevice8_iface;
1205 IDirect3DDevice8_AddRef(texture->parent_device);
1210 HRESULT volumetexture_init(struct d3d8_texture *texture, IDirect3DDevice8Impl *device,
1211 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
1215 texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DVolumeTexture8_Vtbl;
1216 texture->refcount = 1;
1218 wined3d_mutex_lock();
1219 hr = wined3d_texture_create_3d(device->wined3d_device, width, height, depth, levels,
1220 usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool, texture,
1221 &d3d8_texture_wined3d_parent_ops, &texture->wined3d_texture);
1222 wined3d_mutex_unlock();
1225 WARN("Failed to create wined3d volume texture, hr %#x.\n", hr);
1229 texture->parent_device = &device->IDirect3DDevice8_iface;
1230 IDirect3DDevice8_AddRef(texture->parent_device);