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 IDirect3DTexture9_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 IDirect3DDevice9Ex_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 WINED3DFORMAT format;
232 TRACE("(%p) Relay\n", This);
234 /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
235 wined3ddesc.Format = &format;
236 wined3ddesc.Type = (WINED3DRESOURCETYPE *)&pDesc->Type;
237 wined3ddesc.Usage = &pDesc->Usage;
238 wined3ddesc.Pool = (WINED3DPOOL *) &pDesc->Pool;
239 wined3ddesc.Size = &tmpInt; /* required for d3d8 */
240 wined3ddesc.MultiSampleType = (WINED3DMULTISAMPLE_TYPE *) &pDesc->MultiSampleType;
241 wined3ddesc.MultiSampleQuality = &pDesc->MultiSampleQuality;
242 wined3ddesc.Width = &pDesc->Width;
243 wined3ddesc.Height = &pDesc->Height;
245 EnterCriticalSection(&d3d9_cs);
246 hr = IWineD3DTexture_GetLevelDesc(This->wineD3DTexture, Level, &wined3ddesc);
247 LeaveCriticalSection(&d3d9_cs);
249 if (SUCCEEDED(hr)) pDesc->Format = d3dformat_from_wined3dformat(format);
254 static HRESULT WINAPI IDirect3DTexture9Impl_GetSurfaceLevel(LPDIRECT3DTEXTURE9 iface, UINT Level, IDirect3DSurface9** ppSurfaceLevel) {
255 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
256 HRESULT hrc = D3D_OK;
257 IWineD3DSurface *mySurface = NULL;
259 TRACE("(%p) Relay\n", This);
260 EnterCriticalSection(&d3d9_cs);
261 hrc = IWineD3DTexture_GetSurfaceLevel(This->wineD3DTexture, Level, &mySurface);
262 if (hrc == D3D_OK && NULL != ppSurfaceLevel) {
263 IWineD3DSurface_GetParent(mySurface, (IUnknown **)ppSurfaceLevel);
264 IWineD3DSurface_Release(mySurface);
266 LeaveCriticalSection(&d3d9_cs);
270 static HRESULT WINAPI IDirect3DTexture9Impl_LockRect(LPDIRECT3DTEXTURE9 iface, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
271 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
273 TRACE("(%p) Relay\n", This);
275 EnterCriticalSection(&d3d9_cs);
276 hr = IWineD3DTexture_LockRect(This->wineD3DTexture, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
277 LeaveCriticalSection(&d3d9_cs);
281 static HRESULT WINAPI IDirect3DTexture9Impl_UnlockRect(LPDIRECT3DTEXTURE9 iface, UINT Level) {
282 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
284 TRACE("(%p) Relay\n", This);
286 EnterCriticalSection(&d3d9_cs);
287 hr = IWineD3DTexture_UnlockRect(This->wineD3DTexture, Level);
288 LeaveCriticalSection(&d3d9_cs);
292 static HRESULT WINAPI IDirect3DTexture9Impl_AddDirtyRect(LPDIRECT3DTEXTURE9 iface, CONST RECT* pDirtyRect) {
293 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
295 TRACE("(%p) Relay\n", This);
297 EnterCriticalSection(&d3d9_cs);
298 hr = IWineD3DTexture_AddDirtyRect(This->wineD3DTexture, pDirtyRect);
299 LeaveCriticalSection(&d3d9_cs);
303 static const IDirect3DTexture9Vtbl Direct3DTexture9_Vtbl =
306 IDirect3DTexture9Impl_QueryInterface,
307 IDirect3DTexture9Impl_AddRef,
308 IDirect3DTexture9Impl_Release,
309 /* IDirect3DResource9 */
310 IDirect3DTexture9Impl_GetDevice,
311 IDirect3DTexture9Impl_SetPrivateData,
312 IDirect3DTexture9Impl_GetPrivateData,
313 IDirect3DTexture9Impl_FreePrivateData,
314 IDirect3DTexture9Impl_SetPriority,
315 IDirect3DTexture9Impl_GetPriority,
316 IDirect3DTexture9Impl_PreLoad,
317 IDirect3DTexture9Impl_GetType,
318 /* IDirect3dBaseTexture9 */
319 IDirect3DTexture9Impl_SetLOD,
320 IDirect3DTexture9Impl_GetLOD,
321 IDirect3DTexture9Impl_GetLevelCount,
322 IDirect3DTexture9Impl_SetAutoGenFilterType,
323 IDirect3DTexture9Impl_GetAutoGenFilterType,
324 IDirect3DTexture9Impl_GenerateMipSubLevels,
325 /* IDirect3DTexture9 */
326 IDirect3DTexture9Impl_GetLevelDesc,
327 IDirect3DTexture9Impl_GetSurfaceLevel,
328 IDirect3DTexture9Impl_LockRect,
329 IDirect3DTexture9Impl_UnlockRect,
330 IDirect3DTexture9Impl_AddDirtyRect
334 /* IDirect3DDevice9 IDirect3DTexture9 Methods follow: */
335 HRESULT WINAPI IDirect3DDevice9Impl_CreateTexture(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, UINT Levels, DWORD Usage,
336 D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture9** ppTexture, HANDLE* pSharedHandle) {
337 IDirect3DTexture9Impl *object;
338 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
339 HRESULT hrc = D3D_OK;
341 TRACE("(%p) : W(%d) H(%d), Lvl(%d) d(%d), Fmt(%#x), Pool(%d)\n", This, Width, Height, Levels, Usage, Format, Pool);
343 /* Allocate the storage for the device */
344 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DTexture9Impl));
346 if (NULL == object) {
347 ERR("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
348 return D3DERR_OUTOFVIDEOMEMORY;
351 object->lpVtbl = &Direct3DTexture9_Vtbl;
353 EnterCriticalSection(&d3d9_cs);
354 hrc = IWineD3DDevice_CreateTexture(This->WineD3DDevice, Width, Height, Levels, Usage & WINED3DUSAGE_MASK,
355 wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DTexture, pSharedHandle, (IUnknown *)object);
356 LeaveCriticalSection(&d3d9_cs);
360 WARN("(%p) call to IWineD3DDevice_CreateTexture failed\n", This);
361 HeapFree(GetProcessHeap(), 0, object);
363 IDirect3DDevice9Ex_AddRef(iface);
364 object->parentDevice = iface;
365 *ppTexture= (LPDIRECT3DTEXTURE9) object;
366 TRACE("(%p) Created Texture %p, %p\n", This, object, object->wineD3DTexture);