2 * IDirect3DTexture8 implementation
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
22 #include "d3d8_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
26 /* IDirect3DTexture8 IUnknown parts follow: */
27 static inline IDirect3DTexture8Impl *impl_from_IDirect3DTexture8(IDirect3DTexture8 *iface)
29 return CONTAINING_RECORD(iface, IDirect3DTexture8Impl, IDirect3DTexture8_iface);
32 static HRESULT WINAPI IDirect3DTexture8Impl_QueryInterface(IDirect3DTexture8 *iface, REFIID riid,
35 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
37 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
39 if (IsEqualGUID(riid, &IID_IUnknown)
40 || IsEqualGUID(riid, &IID_IDirect3DResource8)
41 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
42 || IsEqualGUID(riid, &IID_IDirect3DTexture8)) {
43 IUnknown_AddRef(iface);
48 WARN("(%p)->(%s,%p) not found\n", This, debugstr_guid(riid), ppobj);
53 static ULONG WINAPI IDirect3DTexture8Impl_AddRef(IDirect3DTexture8 *iface)
55 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
56 ULONG ref = InterlockedIncrement(&This->ref);
58 TRACE("%p increasing refcount to %u.\n", iface, ref);
62 IDirect3DDevice8_AddRef(This->parentDevice);
64 wined3d_texture_incref(This->wined3d_texture);
65 wined3d_mutex_unlock();
71 static ULONG WINAPI IDirect3DTexture8Impl_Release(IDirect3DTexture8 *iface)
73 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
74 ULONG ref = InterlockedDecrement(&This->ref);
76 TRACE("%p decreasing refcount to %u.\n", iface, ref);
79 IDirect3DDevice8 *parentDevice = This->parentDevice;
82 wined3d_texture_decref(This->wined3d_texture);
83 wined3d_mutex_unlock();
85 /* Release the device last, as it may cause the device to be destroyed. */
86 IDirect3DDevice8_Release(parentDevice);
91 /* IDirect3DTexture8 IDirect3DResource8 Interface follow: */
92 static HRESULT WINAPI IDirect3DTexture8Impl_GetDevice(IDirect3DTexture8 *iface,
93 IDirect3DDevice8 **device)
95 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
97 TRACE("iface %p, device %p.\n", iface, device);
99 *device = This->parentDevice;
100 IDirect3DDevice8_AddRef(*device);
102 TRACE("Returning device %p.\n", *device);
107 static HRESULT WINAPI IDirect3DTexture8Impl_SetPrivateData(IDirect3DTexture8 *iface,
108 REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags)
110 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
111 struct wined3d_resource *resource;
114 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
115 iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
117 wined3d_mutex_lock();
118 resource = wined3d_texture_get_resource(This->wined3d_texture);
119 hr = wined3d_resource_set_private_data(resource, refguid, pData, SizeOfData, Flags);
120 wined3d_mutex_unlock();
125 static HRESULT WINAPI IDirect3DTexture8Impl_GetPrivateData(IDirect3DTexture8 *iface,
126 REFGUID refguid, void *pData, DWORD *pSizeOfData)
128 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
129 struct wined3d_resource *resource;
132 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
133 iface, debugstr_guid(refguid), pData, pSizeOfData);
135 wined3d_mutex_lock();
136 resource = wined3d_texture_get_resource(This->wined3d_texture);
137 hr = wined3d_resource_get_private_data(resource, refguid, pData, pSizeOfData);
138 wined3d_mutex_unlock();
143 static HRESULT WINAPI IDirect3DTexture8Impl_FreePrivateData(IDirect3DTexture8 *iface,
146 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
147 struct wined3d_resource *resource;
150 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
152 wined3d_mutex_lock();
153 resource = wined3d_texture_get_resource(This->wined3d_texture);
154 hr = wined3d_resource_free_private_data(resource, refguid);
155 wined3d_mutex_unlock();
160 static DWORD WINAPI IDirect3DTexture8Impl_SetPriority(IDirect3DTexture8 *iface, DWORD PriorityNew)
162 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
165 TRACE("iface %p, priority %u.\n", iface, PriorityNew);
167 wined3d_mutex_lock();
168 ret = wined3d_texture_set_priority(This->wined3d_texture, PriorityNew);
169 wined3d_mutex_unlock();
174 static DWORD WINAPI IDirect3DTexture8Impl_GetPriority(IDirect3DTexture8 *iface)
176 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
179 TRACE("iface %p.\n", iface);
181 wined3d_mutex_lock();
182 ret = wined3d_texture_get_priority(This->wined3d_texture);
183 wined3d_mutex_unlock();
188 static void WINAPI IDirect3DTexture8Impl_PreLoad(IDirect3DTexture8 *iface)
190 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
192 TRACE("iface %p.\n", iface);
194 wined3d_mutex_lock();
195 wined3d_texture_preload(This->wined3d_texture);
196 wined3d_mutex_unlock();
199 static D3DRESOURCETYPE WINAPI IDirect3DTexture8Impl_GetType(IDirect3DTexture8 *iface)
201 TRACE("iface %p.\n", iface);
203 return D3DRTYPE_TEXTURE;
206 /* IDirect3DTexture8 IDirect3DBaseTexture8 Interface follow: */
207 static DWORD WINAPI IDirect3DTexture8Impl_SetLOD(IDirect3DTexture8 *iface, DWORD LODNew)
209 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
212 TRACE("iface %p, lod %u.\n", iface, LODNew);
214 wined3d_mutex_lock();
215 ret = wined3d_texture_set_lod(This->wined3d_texture, LODNew);
216 wined3d_mutex_unlock();
221 static DWORD WINAPI IDirect3DTexture8Impl_GetLOD(IDirect3DTexture8 *iface)
223 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
226 TRACE("iface %p.\n", iface);
228 wined3d_mutex_lock();
229 ret = wined3d_texture_get_lod(This->wined3d_texture);
230 wined3d_mutex_unlock();
235 static DWORD WINAPI IDirect3DTexture8Impl_GetLevelCount(IDirect3DTexture8 *iface)
237 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
240 TRACE("iface %p.\n", iface);
242 wined3d_mutex_lock();
243 ret = wined3d_texture_get_level_count(This->wined3d_texture);
244 wined3d_mutex_unlock();
249 static HRESULT WINAPI IDirect3DTexture8Impl_GetLevelDesc(IDirect3DTexture8 *iface,
250 UINT level, D3DSURFACE_DESC *desc)
252 IDirect3DTexture8Impl *texture = impl_from_IDirect3DTexture8(iface);
253 struct wined3d_resource *sub_resource;
256 TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
258 wined3d_mutex_lock();
259 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
260 hr = D3DERR_INVALIDCALL;
263 struct wined3d_resource_desc wined3d_desc;
265 wined3d_resource_get_desc(sub_resource, &wined3d_desc);
266 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
267 desc->Type = wined3d_desc.resource_type;
268 desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
269 desc->Pool = wined3d_desc.pool;
270 desc->Size = wined3d_desc.size;
271 desc->MultiSampleType = wined3d_desc.multisample_type;
272 desc->Width = wined3d_desc.width;
273 desc->Height = wined3d_desc.height;
275 wined3d_mutex_unlock();
280 static HRESULT WINAPI IDirect3DTexture8Impl_GetSurfaceLevel(IDirect3DTexture8 *iface,
281 UINT level, IDirect3DSurface8 **surface)
283 IDirect3DTexture8Impl *texture = impl_from_IDirect3DTexture8(iface);
284 struct wined3d_resource *sub_resource;
286 TRACE("iface %p, level %u, surface %p.\n", iface, level, surface);
288 wined3d_mutex_lock();
289 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
291 wined3d_mutex_unlock();
292 return D3DERR_INVALIDCALL;
295 *surface = wined3d_resource_get_parent(sub_resource);
296 IDirect3DSurface8_AddRef(*surface);
297 wined3d_mutex_unlock();
302 static HRESULT WINAPI IDirect3DTexture8Impl_LockRect(IDirect3DTexture8 *iface, UINT level,
303 D3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags)
305 IDirect3DTexture8Impl *texture = impl_from_IDirect3DTexture8(iface);
306 struct wined3d_resource *sub_resource;
309 TRACE("iface %p, level %u, locked_rect %p, rect %p, flags %#x.\n",
310 iface, level, locked_rect, rect, flags);
312 wined3d_mutex_lock();
313 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
314 hr = D3DERR_INVALIDCALL;
316 hr = IDirect3DSurface8_LockRect((IDirect3DSurface8 *)wined3d_resource_get_parent(sub_resource),
317 locked_rect, rect, flags);
318 wined3d_mutex_unlock();
323 static HRESULT WINAPI IDirect3DTexture8Impl_UnlockRect(IDirect3DTexture8 *iface, UINT level)
325 IDirect3DTexture8Impl *texture = impl_from_IDirect3DTexture8(iface);
326 struct wined3d_resource *sub_resource;
329 TRACE("iface %p, level %u.\n", iface, level);
331 wined3d_mutex_lock();
332 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, level)))
333 hr = D3DERR_INVALIDCALL;
335 hr = IDirect3DSurface8_UnlockRect((IDirect3DSurface8 *)wined3d_resource_get_parent(sub_resource));
336 wined3d_mutex_unlock();
341 static HRESULT WINAPI IDirect3DTexture8Impl_AddDirtyRect(IDirect3DTexture8 *iface, const RECT *dirty_rect)
343 IDirect3DTexture8Impl *texture = impl_from_IDirect3DTexture8(iface);
346 TRACE("iface %p, dirty_rect %s.\n",
347 iface, wine_dbgstr_rect(dirty_rect));
349 wined3d_mutex_lock();
351 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, NULL);
354 struct wined3d_box dirty_region;
356 dirty_region.left = dirty_rect->left;
357 dirty_region.top = dirty_rect->top;
358 dirty_region.right = dirty_rect->right;
359 dirty_region.bottom = dirty_rect->bottom;
360 dirty_region.front = 0;
361 dirty_region.back = 1;
362 hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, &dirty_region);
364 wined3d_mutex_unlock();
369 static const IDirect3DTexture8Vtbl Direct3DTexture8_Vtbl =
372 IDirect3DTexture8Impl_QueryInterface,
373 IDirect3DTexture8Impl_AddRef,
374 IDirect3DTexture8Impl_Release,
375 /* IDirect3DResource8 */
376 IDirect3DTexture8Impl_GetDevice,
377 IDirect3DTexture8Impl_SetPrivateData,
378 IDirect3DTexture8Impl_GetPrivateData,
379 IDirect3DTexture8Impl_FreePrivateData,
380 IDirect3DTexture8Impl_SetPriority,
381 IDirect3DTexture8Impl_GetPriority,
382 IDirect3DTexture8Impl_PreLoad,
383 IDirect3DTexture8Impl_GetType,
384 /* IDirect3dBaseTexture8 */
385 IDirect3DTexture8Impl_SetLOD,
386 IDirect3DTexture8Impl_GetLOD,
387 IDirect3DTexture8Impl_GetLevelCount,
388 /* IDirect3DTexture8 */
389 IDirect3DTexture8Impl_GetLevelDesc,
390 IDirect3DTexture8Impl_GetSurfaceLevel,
391 IDirect3DTexture8Impl_LockRect,
392 IDirect3DTexture8Impl_UnlockRect,
393 IDirect3DTexture8Impl_AddDirtyRect
396 static void STDMETHODCALLTYPE d3d8_texture_wined3d_object_destroyed(void *parent)
398 HeapFree(GetProcessHeap(), 0, parent);
401 static const struct wined3d_parent_ops d3d8_texture_wined3d_parent_ops =
403 d3d8_texture_wined3d_object_destroyed,
406 HRESULT texture_init(IDirect3DTexture8Impl *texture, IDirect3DDevice8Impl *device,
407 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
411 texture->IDirect3DTexture8_iface.lpVtbl = &Direct3DTexture8_Vtbl;
414 wined3d_mutex_lock();
415 hr = wined3d_texture_create_2d(device->wined3d_device, width, height, levels,
416 usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool,
417 texture, &d3d8_texture_wined3d_parent_ops, &texture->wined3d_texture);
418 wined3d_mutex_unlock();
421 WARN("Failed to create wined3d texture, hr %#x.\n", hr);
425 texture->parentDevice = &device->IDirect3DDevice8_iface;
426 IDirect3DDevice8_AddRef(texture->parentDevice);