2 * IDirect3DTexture9 implementation
4 * Copyright 2002-2005 Jason Edmeades
5 * Copyright 2002-2005 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "d3d9_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9
);
28 /* IDirect3DTexture9 IUnknown parts follow: */
29 static HRESULT WINAPI
IDirect3DTexture9Impl_QueryInterface(LPDIRECT3DTEXTURE9 iface
, REFIID riid
, LPVOID
* ppobj
) {
30 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
32 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), ppobj
);
34 if (IsEqualGUID(riid
, &IID_IUnknown
)
35 || IsEqualGUID(riid
, &IID_IDirect3DResource9
)
36 || IsEqualGUID(riid
, &IID_IDirect3DBaseTexture9
)
37 || IsEqualGUID(riid
, &IID_IDirect3DTexture9
)) {
38 IDirect3DTexture9_AddRef(iface
);
43 WARN("(%p)->(%s,%p) not found\n", This
, debugstr_guid(riid
), ppobj
);
48 static ULONG WINAPI
IDirect3DTexture9Impl_AddRef(LPDIRECT3DTEXTURE9 iface
) {
49 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
50 ULONG ref
= InterlockedIncrement(&This
->ref
);
52 TRACE("%p increasing refcount to %u.\n", iface
, ref
);
56 IDirect3DDevice9Ex_AddRef(This
->parentDevice
);
58 wined3d_texture_incref(This
->wined3d_texture
);
59 wined3d_mutex_unlock();
65 static ULONG WINAPI
IDirect3DTexture9Impl_Release(LPDIRECT3DTEXTURE9 iface
) {
66 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
67 ULONG ref
= InterlockedDecrement(&This
->ref
);
69 TRACE("%p decreasing refcount to %u.\n", iface
, ref
);
72 IDirect3DDevice9Ex
*parentDevice
= This
->parentDevice
;
75 wined3d_texture_decref(This
->wined3d_texture
);
76 wined3d_mutex_unlock();
78 /* Release the device last, as it may cause the device to be destroyed. */
79 IDirect3DDevice9Ex_Release(parentDevice
);
84 /* IDirect3DTexture9 IDirect3DResource9 Interface follow: */
85 static HRESULT WINAPI
IDirect3DTexture9Impl_GetDevice(IDirect3DTexture9
*iface
, IDirect3DDevice9
**device
)
87 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
89 TRACE("iface %p, device %p.\n", iface
, device
);
91 *device
= (IDirect3DDevice9
*)This
->parentDevice
;
92 IDirect3DDevice9_AddRef(*device
);
94 TRACE("Returning device %p.\n", *device
);
99 static HRESULT WINAPI
IDirect3DTexture9Impl_SetPrivateData(LPDIRECT3DTEXTURE9 iface
, REFGUID refguid
, CONST
void* pData
, DWORD SizeOfData
, DWORD Flags
) {
100 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
103 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
104 iface
, debugstr_guid(refguid
), pData
, SizeOfData
, Flags
);
106 wined3d_mutex_lock();
107 hr
= wined3d_texture_set_private_data(This
->wined3d_texture
, refguid
, pData
, SizeOfData
, Flags
);
108 wined3d_mutex_unlock();
113 static HRESULT WINAPI
IDirect3DTexture9Impl_GetPrivateData(LPDIRECT3DTEXTURE9 iface
, REFGUID refguid
, void* pData
, DWORD
* pSizeOfData
) {
114 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
117 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
118 iface
, debugstr_guid(refguid
), pData
, pSizeOfData
);
120 wined3d_mutex_lock();
121 hr
= wined3d_texture_get_private_data(This
->wined3d_texture
, refguid
, pData
, pSizeOfData
);
122 wined3d_mutex_unlock();
127 static HRESULT WINAPI
IDirect3DTexture9Impl_FreePrivateData(LPDIRECT3DTEXTURE9 iface
, REFGUID refguid
) {
128 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
131 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(refguid
));
133 wined3d_mutex_lock();
134 hr
= wined3d_texture_free_private_data(This
->wined3d_texture
, refguid
);
135 wined3d_mutex_unlock();
140 static DWORD WINAPI
IDirect3DTexture9Impl_SetPriority(LPDIRECT3DTEXTURE9 iface
, DWORD PriorityNew
) {
141 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
144 TRACE("iface %p, priority %u.\n", iface
, PriorityNew
);
146 wined3d_mutex_lock();
147 ret
= wined3d_texture_set_priority(This
->wined3d_texture
, PriorityNew
);
148 wined3d_mutex_unlock();
153 static DWORD WINAPI
IDirect3DTexture9Impl_GetPriority(LPDIRECT3DTEXTURE9 iface
) {
154 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
157 TRACE("iface %p.\n", iface
);
159 wined3d_mutex_lock();
160 ret
= wined3d_texture_get_priority(This
->wined3d_texture
);
161 wined3d_mutex_unlock();
166 static void WINAPI
IDirect3DTexture9Impl_PreLoad(LPDIRECT3DTEXTURE9 iface
) {
167 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
169 TRACE("iface %p.\n", iface
);
171 wined3d_mutex_lock();
172 wined3d_texture_preload(This
->wined3d_texture
);
173 wined3d_mutex_unlock();
176 static D3DRESOURCETYPE WINAPI
IDirect3DTexture9Impl_GetType(LPDIRECT3DTEXTURE9 iface
) {
177 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
180 TRACE("iface %p.\n", iface
);
182 wined3d_mutex_lock();
183 ret
= wined3d_texture_get_type(This
->wined3d_texture
);
184 wined3d_mutex_unlock();
189 /* IDirect3DTexture9 IDirect3DBaseTexture9 Interface follow: */
190 static DWORD WINAPI
IDirect3DTexture9Impl_SetLOD(LPDIRECT3DTEXTURE9 iface
, DWORD LODNew
) {
191 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
194 TRACE("iface %p, lod %u.\n", iface
, LODNew
);
196 wined3d_mutex_lock();
197 ret
= wined3d_texture_set_lod(This
->wined3d_texture
, LODNew
);
198 wined3d_mutex_unlock();
203 static DWORD WINAPI
IDirect3DTexture9Impl_GetLOD(LPDIRECT3DTEXTURE9 iface
) {
204 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
207 TRACE("iface %p.\n", iface
);
209 wined3d_mutex_lock();
210 ret
= wined3d_texture_get_lod(This
->wined3d_texture
);
211 wined3d_mutex_unlock();
216 static DWORD WINAPI
IDirect3DTexture9Impl_GetLevelCount(LPDIRECT3DTEXTURE9 iface
) {
217 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
220 TRACE("iface %p.\n", iface
);
222 wined3d_mutex_lock();
223 ret
= wined3d_texture_get_level_count(This
->wined3d_texture
);
224 wined3d_mutex_unlock();
229 static HRESULT WINAPI
IDirect3DTexture9Impl_SetAutoGenFilterType(LPDIRECT3DTEXTURE9 iface
, D3DTEXTUREFILTERTYPE FilterType
) {
230 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
233 TRACE("iface %p, filter_type %#x.\n", iface
, FilterType
);
235 wined3d_mutex_lock();
236 hr
= wined3d_texture_set_autogen_filter_type(This
->wined3d_texture
, (WINED3DTEXTUREFILTERTYPE
)FilterType
);
237 wined3d_mutex_unlock();
242 static D3DTEXTUREFILTERTYPE WINAPI
IDirect3DTexture9Impl_GetAutoGenFilterType(LPDIRECT3DTEXTURE9 iface
) {
243 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
244 D3DTEXTUREFILTERTYPE ret
;
246 TRACE("iface %p.\n", iface
);
248 wined3d_mutex_lock();
249 ret
= (D3DTEXTUREFILTERTYPE
)wined3d_texture_get_autogen_filter_type(This
->wined3d_texture
);
250 wined3d_mutex_unlock();
255 static void WINAPI
IDirect3DTexture9Impl_GenerateMipSubLevels(LPDIRECT3DTEXTURE9 iface
) {
256 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
258 TRACE("iface %p.\n", iface
);
260 wined3d_mutex_lock();
261 wined3d_texture_generate_mipmaps(This
->wined3d_texture
);
262 wined3d_mutex_unlock();
265 static HRESULT WINAPI
IDirect3DTexture9Impl_GetLevelDesc(IDirect3DTexture9
*iface
,
266 UINT level
, D3DSURFACE_DESC
*desc
)
268 IDirect3DTexture9Impl
*texture
= (IDirect3DTexture9Impl
*)iface
;
269 struct wined3d_resource
*sub_resource
;
272 TRACE("iface %p, level %u, desc %p.\n", iface
, level
, desc
);
274 wined3d_mutex_lock();
275 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
276 hr
= D3DERR_INVALIDCALL
;
279 struct wined3d_resource_desc wined3d_desc
;
281 wined3d_resource_get_desc(sub_resource
, &wined3d_desc
);
282 desc
->Format
= d3dformat_from_wined3dformat(wined3d_desc
.format
);
283 desc
->Type
= wined3d_desc
.resource_type
;
284 desc
->Usage
= wined3d_desc
.usage
;
285 desc
->Pool
= wined3d_desc
.pool
;
286 desc
->MultiSampleType
= wined3d_desc
.multisample_type
;
287 desc
->MultiSampleQuality
= wined3d_desc
.multisample_quality
;
288 desc
->Width
= wined3d_desc
.width
;
289 desc
->Height
= wined3d_desc
.height
;
291 wined3d_mutex_unlock();
296 static HRESULT WINAPI
IDirect3DTexture9Impl_GetSurfaceLevel(IDirect3DTexture9
*iface
,
297 UINT level
, IDirect3DSurface9
**surface
)
299 IDirect3DTexture9Impl
*texture
= (IDirect3DTexture9Impl
*)iface
;
300 struct wined3d_resource
*sub_resource
;
302 TRACE("iface %p, level %u, surface %p.\n", iface
, level
, surface
);
304 wined3d_mutex_lock();
305 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
307 wined3d_mutex_unlock();
308 return D3DERR_INVALIDCALL
;
311 *surface
= wined3d_resource_get_parent(sub_resource
);
312 IDirect3DSurface9_AddRef(*surface
);
313 wined3d_mutex_unlock();
318 static HRESULT WINAPI
IDirect3DTexture9Impl_LockRect(IDirect3DTexture9
*iface
,
319 UINT level
, D3DLOCKED_RECT
*locked_rect
, const RECT
*rect
, DWORD flags
)
321 IDirect3DTexture9Impl
*texture
= (IDirect3DTexture9Impl
*)iface
;
322 struct wined3d_resource
*sub_resource
;
325 TRACE("iface %p, level %u, locked_rect %p, rect %p, flags %#x.\n",
326 iface
, level
, locked_rect
, rect
, flags
);
328 wined3d_mutex_lock();
329 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
330 hr
= D3DERR_INVALIDCALL
;
332 hr
= IDirect3DSurface9_LockRect((IDirect3DSurface9
*)wined3d_resource_get_parent(sub_resource
),
333 locked_rect
, rect
, flags
);
334 wined3d_mutex_unlock();
339 static HRESULT WINAPI
IDirect3DTexture9Impl_UnlockRect(IDirect3DTexture9
*iface
, UINT level
)
341 IDirect3DTexture9Impl
*texture
= (IDirect3DTexture9Impl
*)iface
;
342 struct wined3d_resource
*sub_resource
;
345 TRACE("iface %p, level %u.\n", iface
, level
);
347 wined3d_mutex_lock();
348 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
349 hr
= D3DERR_INVALIDCALL
;
351 hr
= IDirect3DSurface9_UnlockRect((IDirect3DSurface9
*)wined3d_resource_get_parent(sub_resource
));
352 wined3d_mutex_unlock();
357 static HRESULT WINAPI
IDirect3DTexture9Impl_AddDirtyRect(IDirect3DTexture9
*iface
, const RECT
*dirty_rect
)
359 IDirect3DTexture9Impl
*texture
= (IDirect3DTexture9Impl
*)iface
;
362 TRACE("iface %p, dirty_rect %s.\n",
363 iface
, wine_dbgstr_rect(dirty_rect
));
365 wined3d_mutex_lock();
367 hr
= wined3d_texture_add_dirty_region(texture
->wined3d_texture
, 0, NULL
);
370 WINED3DBOX dirty_region
;
372 dirty_region
.Left
= dirty_rect
->left
;
373 dirty_region
.Top
= dirty_rect
->top
;
374 dirty_region
.Right
= dirty_rect
->right
;
375 dirty_region
.Bottom
= dirty_rect
->bottom
;
376 dirty_region
.Front
= 0;
377 dirty_region
.Back
= 1;
378 hr
= wined3d_texture_add_dirty_region(texture
->wined3d_texture
, 0, &dirty_region
);
380 wined3d_mutex_unlock();
385 static const IDirect3DTexture9Vtbl Direct3DTexture9_Vtbl
=
388 IDirect3DTexture9Impl_QueryInterface
,
389 IDirect3DTexture9Impl_AddRef
,
390 IDirect3DTexture9Impl_Release
,
391 /* IDirect3DResource9 */
392 IDirect3DTexture9Impl_GetDevice
,
393 IDirect3DTexture9Impl_SetPrivateData
,
394 IDirect3DTexture9Impl_GetPrivateData
,
395 IDirect3DTexture9Impl_FreePrivateData
,
396 IDirect3DTexture9Impl_SetPriority
,
397 IDirect3DTexture9Impl_GetPriority
,
398 IDirect3DTexture9Impl_PreLoad
,
399 IDirect3DTexture9Impl_GetType
,
400 /* IDirect3dBaseTexture9 */
401 IDirect3DTexture9Impl_SetLOD
,
402 IDirect3DTexture9Impl_GetLOD
,
403 IDirect3DTexture9Impl_GetLevelCount
,
404 IDirect3DTexture9Impl_SetAutoGenFilterType
,
405 IDirect3DTexture9Impl_GetAutoGenFilterType
,
406 IDirect3DTexture9Impl_GenerateMipSubLevels
,
407 /* IDirect3DTexture9 */
408 IDirect3DTexture9Impl_GetLevelDesc
,
409 IDirect3DTexture9Impl_GetSurfaceLevel
,
410 IDirect3DTexture9Impl_LockRect
,
411 IDirect3DTexture9Impl_UnlockRect
,
412 IDirect3DTexture9Impl_AddDirtyRect
415 static void STDMETHODCALLTYPE
d3d9_texture_wined3d_object_destroyed(void *parent
)
417 HeapFree(GetProcessHeap(), 0, parent
);
420 static const struct wined3d_parent_ops d3d9_texture_wined3d_parent_ops
=
422 d3d9_texture_wined3d_object_destroyed
,
425 HRESULT
texture_init(IDirect3DTexture9Impl
*texture
, IDirect3DDevice9Impl
*device
,
426 UINT width
, UINT height
, UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
)
430 texture
->lpVtbl
= &Direct3DTexture9_Vtbl
;
433 wined3d_mutex_lock();
434 hr
= IWineD3DDevice_CreateTexture(device
->WineD3DDevice
, width
, height
, levels
,
435 usage
& WINED3DUSAGE_MASK
, wined3dformat_from_d3dformat(format
), pool
,
436 texture
, &d3d9_texture_wined3d_parent_ops
, &texture
->wined3d_texture
);
437 wined3d_mutex_unlock();
440 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
444 texture
->parentDevice
= (IDirect3DDevice9Ex
*)device
;
445 IDirect3DDevice9Ex_AddRef(texture
->parentDevice
);