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 HRESULT WINAPI
IDirect3DTexture8Impl_QueryInterface(LPDIRECT3DTEXTURE8 iface
, REFIID riid
, LPVOID
*ppobj
) {
28 IDirect3DTexture8Impl
*This
= (IDirect3DTexture8Impl
*)iface
;
30 if (IsEqualGUID(riid
, &IID_IUnknown
)
31 || IsEqualGUID(riid
, &IID_IDirect3DResource8
)
32 || IsEqualGUID(riid
, &IID_IDirect3DBaseTexture8
)
33 || IsEqualGUID(riid
, &IID_IDirect3DTexture8
)) {
34 IUnknown_AddRef(iface
);
39 WARN("(%p)->(%s,%p) not found\n", This
, debugstr_guid(riid
), ppobj
);
44 static ULONG WINAPI
IDirect3DTexture8Impl_AddRef(LPDIRECT3DTEXTURE8 iface
) {
45 IDirect3DTexture8Impl
*This
= (IDirect3DTexture8Impl
*)iface
;
46 ULONG ref
= InterlockedIncrement(&This
->ref
);
48 TRACE("(%p) : AddRef from %d\n", This
, ref
- 1);
52 IDirect3DDevice8_AddRef(This
->parentDevice
);
54 IWineD3DTexture_AddRef(This
->wineD3DTexture
);
55 wined3d_mutex_unlock();
61 static ULONG WINAPI
IDirect3DTexture8Impl_Release(LPDIRECT3DTEXTURE8 iface
) {
62 IDirect3DTexture8Impl
*This
= (IDirect3DTexture8Impl
*)iface
;
63 ULONG ref
= InterlockedDecrement(&This
->ref
);
65 TRACE("(%p) : ReleaseRef to %d\n", This
, ref
);
68 IDirect3DDevice8
*parentDevice
= This
->parentDevice
;
71 IWineD3DTexture_Release(This
->wineD3DTexture
);
72 wined3d_mutex_unlock();
74 /* Release the device last, as it may cause the device to be destroyed. */
75 IDirect3DDevice8_Release(parentDevice
);
80 /* IDirect3DTexture8 IDirect3DResource8 Interface follow: */
81 static HRESULT WINAPI
IDirect3DTexture8Impl_GetDevice(LPDIRECT3DTEXTURE8 iface
, IDirect3DDevice8
**ppDevice
) {
82 IDirect3DTexture8Impl
*This
= (IDirect3DTexture8Impl
*)iface
;
83 IWineD3DDevice
*wined3d_device
;
85 TRACE("(%p) Relay\n", This
);
88 hr
= IWineD3DTexture_GetDevice(This
->wineD3DTexture
, &wined3d_device
);
91 IWineD3DDevice_GetParent(wined3d_device
, (IUnknown
**)ppDevice
);
92 IWineD3DDevice_Release(wined3d_device
);
94 wined3d_mutex_unlock();
99 static HRESULT WINAPI
IDirect3DTexture8Impl_SetPrivateData(LPDIRECT3DTEXTURE8 iface
, REFGUID refguid
, CONST
void *pData
, DWORD SizeOfData
, DWORD Flags
) {
100 IDirect3DTexture8Impl
*This
= (IDirect3DTexture8Impl
*)iface
;
102 TRACE("(%p) Relay\n", This
);
104 wined3d_mutex_lock();
105 hr
= IWineD3DTexture_SetPrivateData(This
->wineD3DTexture
, refguid
, pData
, SizeOfData
, Flags
);
106 wined3d_mutex_unlock();
111 static HRESULT WINAPI
IDirect3DTexture8Impl_GetPrivateData(LPDIRECT3DTEXTURE8 iface
, REFGUID refguid
, void *pData
, DWORD
* pSizeOfData
) {
112 IDirect3DTexture8Impl
*This
= (IDirect3DTexture8Impl
*)iface
;
114 TRACE("(%p) Relay\n", This
);
116 wined3d_mutex_lock();
117 hr
= IWineD3DTexture_GetPrivateData(This
->wineD3DTexture
, refguid
, pData
, pSizeOfData
);
118 wined3d_mutex_unlock();
123 static HRESULT WINAPI
IDirect3DTexture8Impl_FreePrivateData(LPDIRECT3DTEXTURE8 iface
, REFGUID refguid
) {
124 IDirect3DTexture8Impl
*This
= (IDirect3DTexture8Impl
*)iface
;
126 TRACE("(%p) Relay\n", This
);
128 wined3d_mutex_lock();
129 hr
= IWineD3DTexture_FreePrivateData(This
->wineD3DTexture
, refguid
);
130 wined3d_mutex_unlock();
135 static DWORD WINAPI
IDirect3DTexture8Impl_SetPriority(LPDIRECT3DTEXTURE8 iface
, DWORD PriorityNew
) {
136 IDirect3DTexture8Impl
*This
= (IDirect3DTexture8Impl
*)iface
;
138 TRACE("(%p) Relay\n", This
);
140 wined3d_mutex_lock();
141 ret
= IWineD3DTexture_SetPriority(This
->wineD3DTexture
, PriorityNew
);
142 wined3d_mutex_unlock();
147 static DWORD WINAPI
IDirect3DTexture8Impl_GetPriority(LPDIRECT3DTEXTURE8 iface
) {
148 IDirect3DTexture8Impl
*This
= (IDirect3DTexture8Impl
*)iface
;
150 TRACE("(%p) Relay\n", This
);
152 wined3d_mutex_lock();
153 ret
= IWineD3DTexture_GetPriority(This
->wineD3DTexture
);
154 wined3d_mutex_unlock();
159 static void WINAPI
IDirect3DTexture8Impl_PreLoad(LPDIRECT3DTEXTURE8 iface
) {
160 IDirect3DTexture8Impl
*This
= (IDirect3DTexture8Impl
*)iface
;
161 TRACE("(%p) Relay\n", This
);
163 wined3d_mutex_lock();
164 IWineD3DTexture_PreLoad(This
->wineD3DTexture
);
165 wined3d_mutex_unlock();
168 static D3DRESOURCETYPE WINAPI
IDirect3DTexture8Impl_GetType(LPDIRECT3DTEXTURE8 iface
) {
169 IDirect3DTexture8Impl
*This
= (IDirect3DTexture8Impl
*)iface
;
170 D3DRESOURCETYPE type
;
171 TRACE("(%p) Relay\n", This
);
173 wined3d_mutex_lock();
174 type
= IWineD3DTexture_GetType(This
->wineD3DTexture
);
175 wined3d_mutex_unlock();
180 /* IDirect3DTexture8 IDirect3DBaseTexture8 Interface follow: */
181 static DWORD WINAPI
IDirect3DTexture8Impl_SetLOD(LPDIRECT3DTEXTURE8 iface
, DWORD LODNew
) {
182 IDirect3DTexture8Impl
*This
= (IDirect3DTexture8Impl
*)iface
;
184 TRACE("(%p) Relay\n", This
);
186 wined3d_mutex_lock();
187 ret
= IWineD3DTexture_SetLOD(This
->wineD3DTexture
, LODNew
);
188 wined3d_mutex_unlock();
193 static DWORD WINAPI
IDirect3DTexture8Impl_GetLOD(LPDIRECT3DTEXTURE8 iface
) {
194 IDirect3DTexture8Impl
*This
= (IDirect3DTexture8Impl
*)iface
;
196 TRACE("(%p) Relay\n", This
);
198 wined3d_mutex_lock();
199 ret
= IWineD3DTexture_GetLOD(This
->wineD3DTexture
);
200 wined3d_mutex_unlock();
205 static DWORD WINAPI
IDirect3DTexture8Impl_GetLevelCount(LPDIRECT3DTEXTURE8 iface
) {
206 IDirect3DTexture8Impl
*This
= (IDirect3DTexture8Impl
*)iface
;
208 TRACE("(%p) Relay\n", This
);
210 wined3d_mutex_lock();
211 ret
= IWineD3DTexture_GetLevelCount(This
->wineD3DTexture
);
212 wined3d_mutex_unlock();
217 /* IDirect3DTexture8 Interface follow: */
218 static HRESULT WINAPI
IDirect3DTexture8Impl_GetLevelDesc(LPDIRECT3DTEXTURE8 iface
, UINT Level
, D3DSURFACE_DESC
*pDesc
) {
219 IDirect3DTexture8Impl
*This
= (IDirect3DTexture8Impl
*)iface
;
222 WINED3DSURFACE_DESC wined3ddesc
;
223 TRACE("(%p) Relay\n", This
);
225 wined3d_mutex_lock();
226 hr
= IWineD3DTexture_GetLevelDesc(This
->wineD3DTexture
, Level
, &wined3ddesc
);
227 wined3d_mutex_unlock();
231 pDesc
->Format
= d3dformat_from_wined3dformat(wined3ddesc
.format
);
232 pDesc
->Type
= wined3ddesc
.resource_type
;
233 pDesc
->Usage
= wined3ddesc
.usage
;
234 pDesc
->Pool
= wined3ddesc
.pool
;
235 pDesc
->Size
= wined3ddesc
.size
;
236 pDesc
->MultiSampleType
= wined3ddesc
.multisample_type
;
237 pDesc
->Width
= wined3ddesc
.width
;
238 pDesc
->Height
= wined3ddesc
.height
;
244 static HRESULT WINAPI
IDirect3DTexture8Impl_GetSurfaceLevel(LPDIRECT3DTEXTURE8 iface
, UINT Level
, IDirect3DSurface8
**ppSurfaceLevel
) {
245 IDirect3DTexture8Impl
*This
= (IDirect3DTexture8Impl
*)iface
;
246 HRESULT hrc
= D3D_OK
;
247 IWineD3DSurface
*mySurface
= NULL
;
249 TRACE("(%p) Relay\n", This
);
251 wined3d_mutex_lock();
252 hrc
= IWineD3DTexture_GetSurfaceLevel(This
->wineD3DTexture
, Level
, &mySurface
);
253 if (hrc
== D3D_OK
&& NULL
!= ppSurfaceLevel
) {
254 IWineD3DSurface_GetParent(mySurface
, (IUnknown
**)ppSurfaceLevel
);
255 IWineD3DSurface_Release(mySurface
);
257 wined3d_mutex_unlock();
262 static HRESULT WINAPI
IDirect3DTexture8Impl_LockRect(LPDIRECT3DTEXTURE8 iface
, UINT Level
, D3DLOCKED_RECT
*pLockedRect
, CONST RECT
*pRect
, DWORD Flags
) {
263 IDirect3DTexture8Impl
*This
= (IDirect3DTexture8Impl
*)iface
;
265 TRACE("(%p) Relay\n", This
);
267 wined3d_mutex_lock();
268 hr
= IWineD3DTexture_LockRect(This
->wineD3DTexture
, Level
, (WINED3DLOCKED_RECT
*) pLockedRect
, pRect
, Flags
);
269 wined3d_mutex_unlock();
274 static HRESULT WINAPI
IDirect3DTexture8Impl_UnlockRect(LPDIRECT3DTEXTURE8 iface
, UINT Level
) {
275 IDirect3DTexture8Impl
*This
= (IDirect3DTexture8Impl
*)iface
;
277 TRACE("(%p) Relay\n", This
);
279 wined3d_mutex_lock();
280 hr
= IWineD3DTexture_UnlockRect(This
->wineD3DTexture
, Level
);
281 wined3d_mutex_unlock();
286 static HRESULT WINAPI
IDirect3DTexture8Impl_AddDirtyRect(LPDIRECT3DTEXTURE8 iface
, CONST RECT
*pDirtyRect
) {
287 IDirect3DTexture8Impl
*This
= (IDirect3DTexture8Impl
*)iface
;
289 TRACE("(%p) Relay\n", This
);
291 wined3d_mutex_lock();
292 hr
= IWineD3DTexture_AddDirtyRect(This
->wineD3DTexture
, pDirtyRect
);
293 wined3d_mutex_unlock();
298 static const IDirect3DTexture8Vtbl Direct3DTexture8_Vtbl
=
301 IDirect3DTexture8Impl_QueryInterface
,
302 IDirect3DTexture8Impl_AddRef
,
303 IDirect3DTexture8Impl_Release
,
304 /* IDirect3DResource8 */
305 IDirect3DTexture8Impl_GetDevice
,
306 IDirect3DTexture8Impl_SetPrivateData
,
307 IDirect3DTexture8Impl_GetPrivateData
,
308 IDirect3DTexture8Impl_FreePrivateData
,
309 IDirect3DTexture8Impl_SetPriority
,
310 IDirect3DTexture8Impl_GetPriority
,
311 IDirect3DTexture8Impl_PreLoad
,
312 IDirect3DTexture8Impl_GetType
,
313 /* IDirect3dBaseTexture8 */
314 IDirect3DTexture8Impl_SetLOD
,
315 IDirect3DTexture8Impl_GetLOD
,
316 IDirect3DTexture8Impl_GetLevelCount
,
317 /* IDirect3DTexture8 */
318 IDirect3DTexture8Impl_GetLevelDesc
,
319 IDirect3DTexture8Impl_GetSurfaceLevel
,
320 IDirect3DTexture8Impl_LockRect
,
321 IDirect3DTexture8Impl_UnlockRect
,
322 IDirect3DTexture8Impl_AddDirtyRect
325 static void STDMETHODCALLTYPE
d3d8_texture_wined3d_object_destroyed(void *parent
)
327 HeapFree(GetProcessHeap(), 0, parent
);
330 static const struct wined3d_parent_ops d3d8_texture_wined3d_parent_ops
=
332 d3d8_texture_wined3d_object_destroyed
,
335 HRESULT
texture_init(IDirect3DTexture8Impl
*texture
, IDirect3DDevice8Impl
*device
,
336 UINT width
, UINT height
, UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
)
340 texture
->lpVtbl
= &Direct3DTexture8_Vtbl
;
343 wined3d_mutex_lock();
344 hr
= IWineD3DDevice_CreateTexture(device
->WineD3DDevice
, width
, height
, levels
,
345 usage
& WINED3DUSAGE_MASK
, wined3dformat_from_d3dformat(format
), pool
,
346 &texture
->wineD3DTexture
, (IUnknown
*)texture
, &d3d8_texture_wined3d_parent_ops
);
347 wined3d_mutex_unlock();
350 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
354 texture
->parentDevice
= (IDirect3DDevice8
*)device
;
355 IDirect3DDevice8_AddRef(texture
->parentDevice
);