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 static inline IDirect3DTexture9Impl
*impl_from_IDirect3DTexture9(IDirect3DTexture9
*iface
)
30 return CONTAINING_RECORD(iface
, IDirect3DTexture9Impl
, IDirect3DTexture9_iface
);
33 static HRESULT WINAPI
IDirect3DTexture9Impl_QueryInterface(IDirect3DTexture9
*iface
, REFIID riid
,
36 IDirect3DTexture9Impl
*This
= impl_from_IDirect3DTexture9(iface
);
38 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), ppobj
);
40 if (IsEqualGUID(riid
, &IID_IUnknown
)
41 || IsEqualGUID(riid
, &IID_IDirect3DResource9
)
42 || IsEqualGUID(riid
, &IID_IDirect3DBaseTexture9
)
43 || IsEqualGUID(riid
, &IID_IDirect3DTexture9
)) {
44 IDirect3DTexture9_AddRef(iface
);
49 WARN("(%p)->(%s,%p) not found\n", This
, debugstr_guid(riid
), ppobj
);
54 static ULONG WINAPI
IDirect3DTexture9Impl_AddRef(IDirect3DTexture9
*iface
)
56 IDirect3DTexture9Impl
*This
= impl_from_IDirect3DTexture9(iface
);
57 ULONG ref
= InterlockedIncrement(&This
->ref
);
59 TRACE("%p increasing refcount to %u.\n", iface
, ref
);
63 IDirect3DDevice9Ex_AddRef(This
->parentDevice
);
65 wined3d_texture_incref(This
->wined3d_texture
);
66 wined3d_mutex_unlock();
72 static ULONG WINAPI
IDirect3DTexture9Impl_Release(IDirect3DTexture9
*iface
)
74 IDirect3DTexture9Impl
*This
= impl_from_IDirect3DTexture9(iface
);
75 ULONG ref
= InterlockedDecrement(&This
->ref
);
77 TRACE("%p decreasing refcount to %u.\n", iface
, ref
);
80 IDirect3DDevice9Ex
*parentDevice
= This
->parentDevice
;
83 wined3d_texture_decref(This
->wined3d_texture
);
84 wined3d_mutex_unlock();
86 /* Release the device last, as it may cause the device to be destroyed. */
87 IDirect3DDevice9Ex_Release(parentDevice
);
92 static HRESULT WINAPI
IDirect3DTexture9Impl_GetDevice(IDirect3DTexture9
*iface
,
93 IDirect3DDevice9
**device
)
95 IDirect3DTexture9Impl
*This
= impl_from_IDirect3DTexture9(iface
);
97 TRACE("iface %p, device %p.\n", iface
, device
);
99 *device
= (IDirect3DDevice9
*)This
->parentDevice
;
100 IDirect3DDevice9_AddRef(*device
);
102 TRACE("Returning device %p.\n", *device
);
107 static HRESULT WINAPI
IDirect3DTexture9Impl_SetPrivateData(IDirect3DTexture9
*iface
,
108 REFGUID refguid
, const void *pData
, DWORD SizeOfData
, DWORD Flags
)
110 IDirect3DTexture9Impl
*This
= impl_from_IDirect3DTexture9(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
IDirect3DTexture9Impl_GetPrivateData(IDirect3DTexture9
*iface
,
126 REFGUID refguid
, void *pData
, DWORD
*pSizeOfData
)
128 IDirect3DTexture9Impl
*This
= impl_from_IDirect3DTexture9(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
IDirect3DTexture9Impl_FreePrivateData(IDirect3DTexture9
*iface
,
146 IDirect3DTexture9Impl
*This
= impl_from_IDirect3DTexture9(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
IDirect3DTexture9Impl_SetPriority(IDirect3DTexture9
*iface
, DWORD PriorityNew
)
162 IDirect3DTexture9Impl
*This
= impl_from_IDirect3DTexture9(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
IDirect3DTexture9Impl_GetPriority(IDirect3DTexture9
*iface
)
176 IDirect3DTexture9Impl
*This
= impl_from_IDirect3DTexture9(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
IDirect3DTexture9Impl_PreLoad(IDirect3DTexture9
*iface
)
190 IDirect3DTexture9Impl
*This
= impl_from_IDirect3DTexture9(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
IDirect3DTexture9Impl_GetType(IDirect3DTexture9
*iface
)
201 TRACE("iface %p.\n", iface
);
203 return D3DRTYPE_TEXTURE
;
206 /* IDirect3DTexture9 IDirect3DBaseTexture9 Interface follow: */
207 static DWORD WINAPI
IDirect3DTexture9Impl_SetLOD(IDirect3DTexture9
*iface
, DWORD LODNew
)
209 IDirect3DTexture9Impl
*This
= impl_from_IDirect3DTexture9(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
IDirect3DTexture9Impl_GetLOD(IDirect3DTexture9
*iface
)
223 IDirect3DTexture9Impl
*This
= impl_from_IDirect3DTexture9(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
IDirect3DTexture9Impl_GetLevelCount(IDirect3DTexture9
*iface
)
237 IDirect3DTexture9Impl
*This
= impl_from_IDirect3DTexture9(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
IDirect3DTexture9Impl_SetAutoGenFilterType(IDirect3DTexture9
*iface
,
250 D3DTEXTUREFILTERTYPE FilterType
)
252 IDirect3DTexture9Impl
*This
= impl_from_IDirect3DTexture9(iface
);
255 TRACE("iface %p, filter_type %#x.\n", iface
, FilterType
);
257 wined3d_mutex_lock();
258 hr
= wined3d_texture_set_autogen_filter_type(This
->wined3d_texture
, (WINED3DTEXTUREFILTERTYPE
)FilterType
);
259 wined3d_mutex_unlock();
264 static D3DTEXTUREFILTERTYPE WINAPI
IDirect3DTexture9Impl_GetAutoGenFilterType(IDirect3DTexture9
*iface
)
266 IDirect3DTexture9Impl
*This
= impl_from_IDirect3DTexture9(iface
);
267 D3DTEXTUREFILTERTYPE ret
;
269 TRACE("iface %p.\n", iface
);
271 wined3d_mutex_lock();
272 ret
= (D3DTEXTUREFILTERTYPE
)wined3d_texture_get_autogen_filter_type(This
->wined3d_texture
);
273 wined3d_mutex_unlock();
278 static void WINAPI
IDirect3DTexture9Impl_GenerateMipSubLevels(IDirect3DTexture9
*iface
)
280 IDirect3DTexture9Impl
*This
= impl_from_IDirect3DTexture9(iface
);
282 TRACE("iface %p.\n", iface
);
284 wined3d_mutex_lock();
285 wined3d_texture_generate_mipmaps(This
->wined3d_texture
);
286 wined3d_mutex_unlock();
289 static HRESULT WINAPI
IDirect3DTexture9Impl_GetLevelDesc(IDirect3DTexture9
*iface
,
290 UINT level
, D3DSURFACE_DESC
*desc
)
292 IDirect3DTexture9Impl
*texture
= impl_from_IDirect3DTexture9(iface
);
293 struct wined3d_resource
*sub_resource
;
296 TRACE("iface %p, level %u, desc %p.\n", iface
, level
, desc
);
298 wined3d_mutex_lock();
299 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
300 hr
= D3DERR_INVALIDCALL
;
303 struct wined3d_resource_desc wined3d_desc
;
305 wined3d_resource_get_desc(sub_resource
, &wined3d_desc
);
306 desc
->Format
= d3dformat_from_wined3dformat(wined3d_desc
.format
);
307 desc
->Type
= wined3d_desc
.resource_type
;
308 desc
->Usage
= wined3d_desc
.usage
;
309 desc
->Pool
= wined3d_desc
.pool
;
310 desc
->MultiSampleType
= wined3d_desc
.multisample_type
;
311 desc
->MultiSampleQuality
= wined3d_desc
.multisample_quality
;
312 desc
->Width
= wined3d_desc
.width
;
313 desc
->Height
= wined3d_desc
.height
;
315 wined3d_mutex_unlock();
320 static HRESULT WINAPI
IDirect3DTexture9Impl_GetSurfaceLevel(IDirect3DTexture9
*iface
,
321 UINT level
, IDirect3DSurface9
**surface
)
323 IDirect3DTexture9Impl
*texture
= impl_from_IDirect3DTexture9(iface
);
324 struct wined3d_resource
*sub_resource
;
326 TRACE("iface %p, level %u, surface %p.\n", iface
, level
, surface
);
328 wined3d_mutex_lock();
329 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
331 wined3d_mutex_unlock();
332 return D3DERR_INVALIDCALL
;
335 *surface
= wined3d_resource_get_parent(sub_resource
);
336 IDirect3DSurface9_AddRef(*surface
);
337 wined3d_mutex_unlock();
342 static HRESULT WINAPI
IDirect3DTexture9Impl_LockRect(IDirect3DTexture9
*iface
,
343 UINT level
, D3DLOCKED_RECT
*locked_rect
, const RECT
*rect
, DWORD flags
)
345 IDirect3DTexture9Impl
*texture
= impl_from_IDirect3DTexture9(iface
);
346 struct wined3d_resource
*sub_resource
;
349 TRACE("iface %p, level %u, locked_rect %p, rect %p, flags %#x.\n",
350 iface
, level
, locked_rect
, rect
, flags
);
352 wined3d_mutex_lock();
353 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
354 hr
= D3DERR_INVALIDCALL
;
356 hr
= IDirect3DSurface9_LockRect((IDirect3DSurface9
*)wined3d_resource_get_parent(sub_resource
),
357 locked_rect
, rect
, flags
);
358 wined3d_mutex_unlock();
363 static HRESULT WINAPI
IDirect3DTexture9Impl_UnlockRect(IDirect3DTexture9
*iface
, UINT level
)
365 IDirect3DTexture9Impl
*texture
= impl_from_IDirect3DTexture9(iface
);
366 struct wined3d_resource
*sub_resource
;
369 TRACE("iface %p, level %u.\n", iface
, level
);
371 wined3d_mutex_lock();
372 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, level
)))
373 hr
= D3DERR_INVALIDCALL
;
375 hr
= IDirect3DSurface9_UnlockRect((IDirect3DSurface9
*)wined3d_resource_get_parent(sub_resource
));
376 wined3d_mutex_unlock();
381 static HRESULT WINAPI
IDirect3DTexture9Impl_AddDirtyRect(IDirect3DTexture9
*iface
,
382 const RECT
*dirty_rect
)
384 IDirect3DTexture9Impl
*texture
= impl_from_IDirect3DTexture9(iface
);
387 TRACE("iface %p, dirty_rect %s.\n",
388 iface
, wine_dbgstr_rect(dirty_rect
));
390 wined3d_mutex_lock();
392 hr
= wined3d_texture_add_dirty_region(texture
->wined3d_texture
, 0, NULL
);
395 WINED3DBOX dirty_region
;
397 dirty_region
.Left
= dirty_rect
->left
;
398 dirty_region
.Top
= dirty_rect
->top
;
399 dirty_region
.Right
= dirty_rect
->right
;
400 dirty_region
.Bottom
= dirty_rect
->bottom
;
401 dirty_region
.Front
= 0;
402 dirty_region
.Back
= 1;
403 hr
= wined3d_texture_add_dirty_region(texture
->wined3d_texture
, 0, &dirty_region
);
405 wined3d_mutex_unlock();
410 static const IDirect3DTexture9Vtbl Direct3DTexture9_Vtbl
=
413 IDirect3DTexture9Impl_QueryInterface
,
414 IDirect3DTexture9Impl_AddRef
,
415 IDirect3DTexture9Impl_Release
,
416 /* IDirect3DResource9 */
417 IDirect3DTexture9Impl_GetDevice
,
418 IDirect3DTexture9Impl_SetPrivateData
,
419 IDirect3DTexture9Impl_GetPrivateData
,
420 IDirect3DTexture9Impl_FreePrivateData
,
421 IDirect3DTexture9Impl_SetPriority
,
422 IDirect3DTexture9Impl_GetPriority
,
423 IDirect3DTexture9Impl_PreLoad
,
424 IDirect3DTexture9Impl_GetType
,
425 /* IDirect3dBaseTexture9 */
426 IDirect3DTexture9Impl_SetLOD
,
427 IDirect3DTexture9Impl_GetLOD
,
428 IDirect3DTexture9Impl_GetLevelCount
,
429 IDirect3DTexture9Impl_SetAutoGenFilterType
,
430 IDirect3DTexture9Impl_GetAutoGenFilterType
,
431 IDirect3DTexture9Impl_GenerateMipSubLevels
,
432 /* IDirect3DTexture9 */
433 IDirect3DTexture9Impl_GetLevelDesc
,
434 IDirect3DTexture9Impl_GetSurfaceLevel
,
435 IDirect3DTexture9Impl_LockRect
,
436 IDirect3DTexture9Impl_UnlockRect
,
437 IDirect3DTexture9Impl_AddDirtyRect
440 static void STDMETHODCALLTYPE
d3d9_texture_wined3d_object_destroyed(void *parent
)
442 HeapFree(GetProcessHeap(), 0, parent
);
445 static const struct wined3d_parent_ops d3d9_texture_wined3d_parent_ops
=
447 d3d9_texture_wined3d_object_destroyed
,
450 HRESULT
texture_init(IDirect3DTexture9Impl
*texture
, IDirect3DDevice9Impl
*device
,
451 UINT width
, UINT height
, UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
)
455 texture
->IDirect3DTexture9_iface
.lpVtbl
= &Direct3DTexture9_Vtbl
;
458 wined3d_mutex_lock();
459 hr
= wined3d_texture_create_2d(device
->wined3d_device
, width
, height
, levels
,
460 usage
& WINED3DUSAGE_MASK
, wined3dformat_from_d3dformat(format
), pool
,
461 texture
, &d3d9_texture_wined3d_parent_ops
, &texture
->wined3d_texture
);
462 wined3d_mutex_unlock();
465 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
469 texture
->parentDevice
= &device
->IDirect3DDevice9Ex_iface
;
470 IDirect3DDevice9Ex_AddRef(texture
->parentDevice
);