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 IWineD3DTexture_AddRef(This->wineD3DTexture);
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 IWineD3DTexture_Release(This->wineD3DTexture);
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 = (IDirect3DDevice8 *)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);
113 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
114 iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
116 wined3d_mutex_lock();
117 hr = IWineD3DTexture_SetPrivateData(This->wineD3DTexture, refguid, pData, SizeOfData, Flags);
118 wined3d_mutex_unlock();
123 static HRESULT WINAPI IDirect3DTexture8Impl_GetPrivateData(IDirect3DTexture8 *iface,
124 REFGUID refguid, void *pData, DWORD *pSizeOfData)
126 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
129 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
130 iface, debugstr_guid(refguid), pData, pSizeOfData);
132 wined3d_mutex_lock();
133 hr = IWineD3DTexture_GetPrivateData(This->wineD3DTexture, refguid, pData, pSizeOfData);
134 wined3d_mutex_unlock();
139 static HRESULT WINAPI IDirect3DTexture8Impl_FreePrivateData(IDirect3DTexture8 *iface,
142 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
145 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
147 wined3d_mutex_lock();
148 hr = IWineD3DTexture_FreePrivateData(This->wineD3DTexture, refguid);
149 wined3d_mutex_unlock();
154 static DWORD WINAPI IDirect3DTexture8Impl_SetPriority(IDirect3DTexture8 *iface, DWORD PriorityNew)
156 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
159 TRACE("iface %p, priority %u.\n", iface, PriorityNew);
161 wined3d_mutex_lock();
162 ret = IWineD3DTexture_SetPriority(This->wineD3DTexture, PriorityNew);
163 wined3d_mutex_unlock();
168 static DWORD WINAPI IDirect3DTexture8Impl_GetPriority(IDirect3DTexture8 *iface)
170 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
173 TRACE("iface %p.\n", iface);
175 wined3d_mutex_lock();
176 ret = IWineD3DTexture_GetPriority(This->wineD3DTexture);
177 wined3d_mutex_unlock();
182 static void WINAPI IDirect3DTexture8Impl_PreLoad(IDirect3DTexture8 *iface)
184 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
186 TRACE("iface %p.\n", iface);
188 wined3d_mutex_lock();
189 IWineD3DTexture_PreLoad(This->wineD3DTexture);
190 wined3d_mutex_unlock();
193 static D3DRESOURCETYPE WINAPI IDirect3DTexture8Impl_GetType(IDirect3DTexture8 *iface)
195 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
196 D3DRESOURCETYPE type;
198 TRACE("iface %p.\n", iface);
200 wined3d_mutex_lock();
201 type = IWineD3DTexture_GetType(This->wineD3DTexture);
202 wined3d_mutex_unlock();
207 /* IDirect3DTexture8 IDirect3DBaseTexture8 Interface follow: */
208 static DWORD WINAPI IDirect3DTexture8Impl_SetLOD(IDirect3DTexture8 *iface, DWORD LODNew)
210 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
213 TRACE("iface %p, lod %u.\n", iface, LODNew);
215 wined3d_mutex_lock();
216 ret = IWineD3DTexture_SetLOD(This->wineD3DTexture, LODNew);
217 wined3d_mutex_unlock();
222 static DWORD WINAPI IDirect3DTexture8Impl_GetLOD(IDirect3DTexture8 *iface)
224 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
227 TRACE("iface %p.\n", iface);
229 wined3d_mutex_lock();
230 ret = IWineD3DTexture_GetLOD(This->wineD3DTexture);
231 wined3d_mutex_unlock();
236 static DWORD WINAPI IDirect3DTexture8Impl_GetLevelCount(IDirect3DTexture8 *iface)
238 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
241 TRACE("iface %p.\n", iface);
243 wined3d_mutex_lock();
244 ret = IWineD3DTexture_GetLevelCount(This->wineD3DTexture);
245 wined3d_mutex_unlock();
250 static HRESULT WINAPI IDirect3DTexture8Impl_GetLevelDesc(IDirect3DTexture8 *iface,
251 UINT level, D3DSURFACE_DESC *desc)
253 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
254 struct wined3d_resource_desc wined3d_desc;
257 TRACE("iface %p, level %u, desc %p.\n", iface, level, desc);
259 wined3d_mutex_lock();
260 hr = IWineD3DTexture_GetLevelDesc(This->wineD3DTexture, level, &wined3d_desc);
261 wined3d_mutex_unlock();
265 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
266 desc->Type = wined3d_desc.resource_type;
267 desc->Usage = wined3d_desc.usage;
268 desc->Pool = wined3d_desc.pool;
269 desc->Size = wined3d_desc.size;
270 desc->MultiSampleType = wined3d_desc.multisample_type;
271 desc->Width = wined3d_desc.width;
272 desc->Height = wined3d_desc.height;
278 static HRESULT WINAPI IDirect3DTexture8Impl_GetSurfaceLevel(IDirect3DTexture8 *iface,
279 UINT Level, IDirect3DSurface8 **ppSurfaceLevel)
281 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
282 IWineD3DSurface *mySurface = NULL;
285 TRACE("iface %p, level %u, surface %p.\n", iface, Level, ppSurfaceLevel);
287 wined3d_mutex_lock();
288 hr = IWineD3DTexture_GetSurfaceLevel(This->wineD3DTexture, Level, &mySurface);
289 if (SUCCEEDED(hr) && ppSurfaceLevel)
291 *ppSurfaceLevel = IWineD3DSurface_GetParent(mySurface);
292 IDirect3DSurface8_AddRef(*ppSurfaceLevel);
293 IWineD3DSurface_Release(mySurface);
295 wined3d_mutex_unlock();
300 static HRESULT WINAPI IDirect3DTexture8Impl_LockRect(IDirect3DTexture8 *iface, UINT Level,
301 D3DLOCKED_RECT *pLockedRect, const RECT *pRect, DWORD Flags)
303 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
306 TRACE("iface %p, level %u, locked_rect %p, rect %p, flags %#x.\n",
307 iface, Level, pLockedRect, pRect, Flags);
309 wined3d_mutex_lock();
310 hr = IWineD3DTexture_Map(This->wineD3DTexture, Level, (WINED3DLOCKED_RECT *)pLockedRect, pRect, Flags);
311 wined3d_mutex_unlock();
316 static HRESULT WINAPI IDirect3DTexture8Impl_UnlockRect(IDirect3DTexture8 *iface, UINT Level)
318 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
321 TRACE("iface %p, level %u.\n", iface, Level);
323 wined3d_mutex_lock();
324 hr = IWineD3DTexture_Unmap(This->wineD3DTexture, Level);
325 wined3d_mutex_unlock();
330 static HRESULT WINAPI IDirect3DTexture8Impl_AddDirtyRect(IDirect3DTexture8 *iface,
331 const RECT *pDirtyRect)
333 IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
336 TRACE("iface %p, dirty_rect %p.\n", iface, pDirtyRect);
338 wined3d_mutex_lock();
339 hr = IWineD3DTexture_AddDirtyRect(This->wineD3DTexture, pDirtyRect);
340 wined3d_mutex_unlock();
345 static const IDirect3DTexture8Vtbl Direct3DTexture8_Vtbl =
348 IDirect3DTexture8Impl_QueryInterface,
349 IDirect3DTexture8Impl_AddRef,
350 IDirect3DTexture8Impl_Release,
351 /* IDirect3DResource8 */
352 IDirect3DTexture8Impl_GetDevice,
353 IDirect3DTexture8Impl_SetPrivateData,
354 IDirect3DTexture8Impl_GetPrivateData,
355 IDirect3DTexture8Impl_FreePrivateData,
356 IDirect3DTexture8Impl_SetPriority,
357 IDirect3DTexture8Impl_GetPriority,
358 IDirect3DTexture8Impl_PreLoad,
359 IDirect3DTexture8Impl_GetType,
360 /* IDirect3dBaseTexture8 */
361 IDirect3DTexture8Impl_SetLOD,
362 IDirect3DTexture8Impl_GetLOD,
363 IDirect3DTexture8Impl_GetLevelCount,
364 /* IDirect3DTexture8 */
365 IDirect3DTexture8Impl_GetLevelDesc,
366 IDirect3DTexture8Impl_GetSurfaceLevel,
367 IDirect3DTexture8Impl_LockRect,
368 IDirect3DTexture8Impl_UnlockRect,
369 IDirect3DTexture8Impl_AddDirtyRect
372 static void STDMETHODCALLTYPE d3d8_texture_wined3d_object_destroyed(void *parent)
374 HeapFree(GetProcessHeap(), 0, parent);
377 static const struct wined3d_parent_ops d3d8_texture_wined3d_parent_ops =
379 d3d8_texture_wined3d_object_destroyed,
382 HRESULT texture_init(IDirect3DTexture8Impl *texture, IDirect3DDevice8Impl *device,
383 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
387 texture->IDirect3DTexture8_iface.lpVtbl = &Direct3DTexture8_Vtbl;
390 wined3d_mutex_lock();
391 hr = IWineD3DDevice_CreateTexture(device->WineD3DDevice, width, height, levels,
392 usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool,
393 texture, &d3d8_texture_wined3d_parent_ops, &texture->wineD3DTexture);
394 wined3d_mutex_unlock();
397 WARN("Failed to create wined3d texture, hr %#x.\n", hr);
401 texture->parentDevice = &device->IDirect3DDevice8_iface;
402 IDirect3DDevice8_AddRef(texture->parentDevice);