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 if (IsEqualGUID(riid
, &IID_IUnknown
)
33 || IsEqualGUID(riid
, &IID_IDirect3DResource9
)
34 || IsEqualGUID(riid
, &IID_IDirect3DBaseTexture9
)
35 || IsEqualGUID(riid
, &IID_IDirect3DTexture9
)) {
36 IUnknown_AddRef(iface
);
41 WARN("(%p)->(%s,%p) not found\n", This
, debugstr_guid(riid
), ppobj
);
46 static ULONG WINAPI
IDirect3DTexture9Impl_AddRef(LPDIRECT3DTEXTURE9 iface
) {
47 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
48 ULONG ref
= InterlockedIncrement(&This
->ref
);
50 TRACE("(%p) : AddRef from %d\n", This
, ref
- 1);
55 static ULONG WINAPI
IDirect3DTexture9Impl_Release(LPDIRECT3DTEXTURE9 iface
) {
56 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
57 ULONG ref
= InterlockedDecrement(&This
->ref
);
59 TRACE("(%p) : ReleaseRef to %d\n", This
, ref
);
62 EnterCriticalSection(&d3d9_cs
);
63 IWineD3DTexture_Destroy(This
->wineD3DTexture
, D3D9CB_DestroySurface
);
64 LeaveCriticalSection(&d3d9_cs
);
65 IUnknown_Release(This
->parentDevice
);
66 HeapFree(GetProcessHeap(), 0, This
);
71 /* IDirect3DTexture9 IDirect3DResource9 Interface follow: */
72 static HRESULT WINAPI
IDirect3DTexture9Impl_GetDevice(LPDIRECT3DTEXTURE9 iface
, IDirect3DDevice9
** ppDevice
) {
73 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
75 TRACE("(%p) Relay\n", This
);
77 EnterCriticalSection(&d3d9_cs
);
78 hr
= IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9
) This
, ppDevice
);
79 LeaveCriticalSection(&d3d9_cs
);
83 static HRESULT WINAPI
IDirect3DTexture9Impl_SetPrivateData(LPDIRECT3DTEXTURE9 iface
, REFGUID refguid
, CONST
void* pData
, DWORD SizeOfData
, DWORD Flags
) {
84 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
86 TRACE("(%p) Relay\n", This
);
88 EnterCriticalSection(&d3d9_cs
);
89 hr
= IWineD3DTexture_SetPrivateData(This
->wineD3DTexture
, refguid
, pData
, SizeOfData
, Flags
);
90 LeaveCriticalSection(&d3d9_cs
);
94 static HRESULT WINAPI
IDirect3DTexture9Impl_GetPrivateData(LPDIRECT3DTEXTURE9 iface
, REFGUID refguid
, void* pData
, DWORD
* pSizeOfData
) {
95 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
97 TRACE("(%p) Relay\n", This
);
99 EnterCriticalSection(&d3d9_cs
);
100 hr
= IWineD3DTexture_GetPrivateData(This
->wineD3DTexture
, refguid
, pData
, pSizeOfData
);
101 LeaveCriticalSection(&d3d9_cs
);
105 static HRESULT WINAPI
IDirect3DTexture9Impl_FreePrivateData(LPDIRECT3DTEXTURE9 iface
, REFGUID refguid
) {
106 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
108 TRACE("(%p) Relay\n", This
);
110 EnterCriticalSection(&d3d9_cs
);
111 hr
= IWineD3DTexture_FreePrivateData(This
->wineD3DTexture
, refguid
);
112 LeaveCriticalSection(&d3d9_cs
);
116 static DWORD WINAPI
IDirect3DTexture9Impl_SetPriority(LPDIRECT3DTEXTURE9 iface
, DWORD PriorityNew
) {
117 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
119 TRACE("(%p) Relay\n", This
);
121 EnterCriticalSection(&d3d9_cs
);
122 ret
= IWineD3DTexture_SetPriority(This
->wineD3DTexture
, PriorityNew
);
123 LeaveCriticalSection(&d3d9_cs
);
127 static DWORD WINAPI
IDirect3DTexture9Impl_GetPriority(LPDIRECT3DTEXTURE9 iface
) {
128 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
130 TRACE("(%p) Relay\n", This
);
132 EnterCriticalSection(&d3d9_cs
);
133 ret
= IWineD3DTexture_GetPriority(This
->wineD3DTexture
);
134 LeaveCriticalSection(&d3d9_cs
);
138 static void WINAPI
IDirect3DTexture9Impl_PreLoad(LPDIRECT3DTEXTURE9 iface
) {
139 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
140 TRACE("(%p) Relay\n", This
);
142 EnterCriticalSection(&d3d9_cs
);
143 IWineD3DTexture_PreLoad(This
->wineD3DTexture
);
144 LeaveCriticalSection(&d3d9_cs
);
147 static D3DRESOURCETYPE WINAPI
IDirect3DTexture9Impl_GetType(LPDIRECT3DTEXTURE9 iface
) {
148 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
150 TRACE("(%p) Relay\n", This
);
152 EnterCriticalSection(&d3d9_cs
);
153 ret
= IWineD3DTexture_GetType(This
->wineD3DTexture
);
154 LeaveCriticalSection(&d3d9_cs
);
158 /* IDirect3DTexture9 IDirect3DBaseTexture9 Interface follow: */
159 static DWORD WINAPI
IDirect3DTexture9Impl_SetLOD(LPDIRECT3DTEXTURE9 iface
, DWORD LODNew
) {
160 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
162 TRACE("(%p) Relay\n", This
);
164 EnterCriticalSection(&d3d9_cs
);
165 ret
= IWineD3DTexture_SetLOD(This
->wineD3DTexture
, LODNew
);
166 LeaveCriticalSection(&d3d9_cs
);
170 static DWORD WINAPI
IDirect3DTexture9Impl_GetLOD(LPDIRECT3DTEXTURE9 iface
) {
171 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
173 TRACE("(%p) Relay\n", This
);
175 EnterCriticalSection(&d3d9_cs
);
176 ret
= IWineD3DTexture_GetLOD(This
->wineD3DTexture
);
177 LeaveCriticalSection(&d3d9_cs
);
181 static DWORD WINAPI
IDirect3DTexture9Impl_GetLevelCount(LPDIRECT3DTEXTURE9 iface
) {
182 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
184 TRACE("(%p) Relay\n", This
);
186 EnterCriticalSection(&d3d9_cs
);
187 ret
= IWineD3DTexture_GetLevelCount(This
->wineD3DTexture
);
188 LeaveCriticalSection(&d3d9_cs
);
192 static HRESULT WINAPI
IDirect3DTexture9Impl_SetAutoGenFilterType(LPDIRECT3DTEXTURE9 iface
, D3DTEXTUREFILTERTYPE FilterType
) {
193 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
195 TRACE("(%p) Relay\n", This
);
197 EnterCriticalSection(&d3d9_cs
);
198 hr
= IWineD3DTexture_SetAutoGenFilterType(This
->wineD3DTexture
, (WINED3DTEXTUREFILTERTYPE
) FilterType
);
199 LeaveCriticalSection(&d3d9_cs
);
203 static D3DTEXTUREFILTERTYPE WINAPI
IDirect3DTexture9Impl_GetAutoGenFilterType(LPDIRECT3DTEXTURE9 iface
) {
204 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
205 D3DTEXTUREFILTERTYPE ret
;
206 TRACE("(%p) Relay\n", This
);
208 EnterCriticalSection(&d3d9_cs
);
209 ret
= (D3DTEXTUREFILTERTYPE
) IWineD3DTexture_GetAutoGenFilterType(This
->wineD3DTexture
);
210 LeaveCriticalSection(&d3d9_cs
);
214 static void WINAPI
IDirect3DTexture9Impl_GenerateMipSubLevels(LPDIRECT3DTEXTURE9 iface
) {
215 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
216 TRACE("(%p) Relay\n", This
);
218 EnterCriticalSection(&d3d9_cs
);
219 IWineD3DTexture_GenerateMipSubLevels(This
->wineD3DTexture
);
220 LeaveCriticalSection(&d3d9_cs
);
223 /* IDirect3DTexture9 Interface follow: */
224 static HRESULT WINAPI
IDirect3DTexture9Impl_GetLevelDesc(LPDIRECT3DTEXTURE9 iface
, UINT Level
, D3DSURFACE_DESC
* pDesc
) {
225 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
227 WINED3DSURFACE_DESC wined3ddesc
;
230 TRACE("(%p) Relay\n", This
);
232 /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
233 wined3ddesc
.Format
= (WINED3DFORMAT
*)&pDesc
->Format
;
234 wined3ddesc
.Type
= (WINED3DRESOURCETYPE
*)&pDesc
->Type
;
235 wined3ddesc
.Usage
= &pDesc
->Usage
;
236 wined3ddesc
.Pool
= (WINED3DPOOL
*) &pDesc
->Pool
;
237 wined3ddesc
.Size
= &tmpInt
; /* required for d3d8 */
238 wined3ddesc
.MultiSampleType
= (WINED3DMULTISAMPLE_TYPE
*) &pDesc
->MultiSampleType
;
239 wined3ddesc
.MultiSampleQuality
= &pDesc
->MultiSampleQuality
;
240 wined3ddesc
.Width
= &pDesc
->Width
;
241 wined3ddesc
.Height
= &pDesc
->Height
;
243 EnterCriticalSection(&d3d9_cs
);
244 hr
= IWineD3DTexture_GetLevelDesc(This
->wineD3DTexture
, Level
, &wined3ddesc
);
245 LeaveCriticalSection(&d3d9_cs
);
249 static HRESULT WINAPI
IDirect3DTexture9Impl_GetSurfaceLevel(LPDIRECT3DTEXTURE9 iface
, UINT Level
, IDirect3DSurface9
** ppSurfaceLevel
) {
250 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
251 HRESULT hrc
= D3D_OK
;
252 IWineD3DSurface
*mySurface
= NULL
;
254 TRACE("(%p) Relay\n", This
);
255 EnterCriticalSection(&d3d9_cs
);
256 hrc
= IWineD3DTexture_GetSurfaceLevel(This
->wineD3DTexture
, Level
, &mySurface
);
257 if (hrc
== D3D_OK
&& NULL
!= ppSurfaceLevel
) {
258 IWineD3DSurface_GetParent(mySurface
, (IUnknown
**)ppSurfaceLevel
);
259 IWineD3DSurface_Release(mySurface
);
261 LeaveCriticalSection(&d3d9_cs
);
265 static HRESULT WINAPI
IDirect3DTexture9Impl_LockRect(LPDIRECT3DTEXTURE9 iface
, UINT Level
, D3DLOCKED_RECT
* pLockedRect
, CONST RECT
* pRect
, DWORD Flags
) {
266 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
268 TRACE("(%p) Relay\n", This
);
270 EnterCriticalSection(&d3d9_cs
);
271 hr
= IWineD3DTexture_LockRect(This
->wineD3DTexture
, Level
, (WINED3DLOCKED_RECT
*) pLockedRect
, pRect
, Flags
);
272 LeaveCriticalSection(&d3d9_cs
);
276 static HRESULT WINAPI
IDirect3DTexture9Impl_UnlockRect(LPDIRECT3DTEXTURE9 iface
, UINT Level
) {
277 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
279 TRACE("(%p) Relay\n", This
);
281 EnterCriticalSection(&d3d9_cs
);
282 hr
= IWineD3DTexture_UnlockRect(This
->wineD3DTexture
, Level
);
283 LeaveCriticalSection(&d3d9_cs
);
287 static HRESULT WINAPI
IDirect3DTexture9Impl_AddDirtyRect(LPDIRECT3DTEXTURE9 iface
, CONST RECT
* pDirtyRect
) {
288 IDirect3DTexture9Impl
*This
= (IDirect3DTexture9Impl
*)iface
;
290 TRACE("(%p) Relay\n", This
);
292 EnterCriticalSection(&d3d9_cs
);
293 hr
= IWineD3DTexture_AddDirtyRect(This
->wineD3DTexture
, pDirtyRect
);
294 LeaveCriticalSection(&d3d9_cs
);
298 static const IDirect3DTexture9Vtbl Direct3DTexture9_Vtbl
=
301 IDirect3DTexture9Impl_QueryInterface
,
302 IDirect3DTexture9Impl_AddRef
,
303 IDirect3DTexture9Impl_Release
,
304 /* IDirect3DResource9 */
305 IDirect3DTexture9Impl_GetDevice
,
306 IDirect3DTexture9Impl_SetPrivateData
,
307 IDirect3DTexture9Impl_GetPrivateData
,
308 IDirect3DTexture9Impl_FreePrivateData
,
309 IDirect3DTexture9Impl_SetPriority
,
310 IDirect3DTexture9Impl_GetPriority
,
311 IDirect3DTexture9Impl_PreLoad
,
312 IDirect3DTexture9Impl_GetType
,
313 /* IDirect3dBaseTexture9 */
314 IDirect3DTexture9Impl_SetLOD
,
315 IDirect3DTexture9Impl_GetLOD
,
316 IDirect3DTexture9Impl_GetLevelCount
,
317 IDirect3DTexture9Impl_SetAutoGenFilterType
,
318 IDirect3DTexture9Impl_GetAutoGenFilterType
,
319 IDirect3DTexture9Impl_GenerateMipSubLevels
,
320 /* IDirect3DTexture9 */
321 IDirect3DTexture9Impl_GetLevelDesc
,
322 IDirect3DTexture9Impl_GetSurfaceLevel
,
323 IDirect3DTexture9Impl_LockRect
,
324 IDirect3DTexture9Impl_UnlockRect
,
325 IDirect3DTexture9Impl_AddDirtyRect
329 /* IDirect3DDevice9 IDirect3DTexture9 Methods follow: */
330 HRESULT WINAPI
IDirect3DDevice9Impl_CreateTexture(LPDIRECT3DDEVICE9EX iface
, UINT Width
, UINT Height
, UINT Levels
, DWORD Usage
,
331 D3DFORMAT Format
, D3DPOOL Pool
, IDirect3DTexture9
** ppTexture
, HANDLE
* pSharedHandle
) {
332 IDirect3DTexture9Impl
*object
;
333 IDirect3DDevice9Impl
*This
= (IDirect3DDevice9Impl
*)iface
;
334 HRESULT hrc
= D3D_OK
;
336 TRACE("(%p) : W(%d) H(%d), Lvl(%d) d(%d), Fmt(%#x), Pool(%d)\n", This
, Width
, Height
, Levels
, Usage
, Format
, Pool
);
338 /* Allocate the storage for the device */
339 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DTexture9Impl
));
341 if (NULL
== object
) {
342 FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
343 return D3DERR_OUTOFVIDEOMEMORY
;
346 object
->lpVtbl
= &Direct3DTexture9_Vtbl
;
348 EnterCriticalSection(&d3d9_cs
);
349 hrc
= IWineD3DDevice_CreateTexture(This
->WineD3DDevice
, Width
, Height
, Levels
, Usage
& WINED3DUSAGE_MASK
,
350 (WINED3DFORMAT
)Format
, (WINED3DPOOL
) Pool
, &object
->wineD3DTexture
, pSharedHandle
, (IUnknown
*)object
, D3D9CB_CreateSurface
);
351 LeaveCriticalSection(&d3d9_cs
);
356 FIXME("(%p) call to IWineD3DDevice_CreateTexture failed\n", This
);
357 HeapFree(GetProcessHeap(), 0, object
);
359 IUnknown_AddRef(iface
);
360 object
->parentDevice
= iface
;
361 *ppTexture
= (LPDIRECT3DTEXTURE9
) object
;
362 TRACE("(%p) Created Texture %p, %p\n", This
, object
, object
->wineD3DTexture
);