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;
74 IWineD3DDevice *wined3d_device;
76 TRACE("(%p) Relay\n", This);
78 EnterCriticalSection(&d3d9_cs);
79 hr = IWineD3DTexture_GetDevice(This->wineD3DTexture, &wined3d_device);
82 IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
83 IWineD3DDevice_Release(wined3d_device);
85 LeaveCriticalSection(&d3d9_cs);
89 static HRESULT WINAPI IDirect3DTexture9Impl_SetPrivateData(LPDIRECT3DTEXTURE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
90 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
92 TRACE("(%p) Relay\n", This);
94 EnterCriticalSection(&d3d9_cs);
95 hr = IWineD3DTexture_SetPrivateData(This->wineD3DTexture, refguid, pData, SizeOfData, Flags);
96 LeaveCriticalSection(&d3d9_cs);
100 static HRESULT WINAPI IDirect3DTexture9Impl_GetPrivateData(LPDIRECT3DTEXTURE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
101 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
103 TRACE("(%p) Relay\n", This);
105 EnterCriticalSection(&d3d9_cs);
106 hr = IWineD3DTexture_GetPrivateData(This->wineD3DTexture, refguid, pData, pSizeOfData);
107 LeaveCriticalSection(&d3d9_cs);
111 static HRESULT WINAPI IDirect3DTexture9Impl_FreePrivateData(LPDIRECT3DTEXTURE9 iface, REFGUID refguid) {
112 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
114 TRACE("(%p) Relay\n", This);
116 EnterCriticalSection(&d3d9_cs);
117 hr = IWineD3DTexture_FreePrivateData(This->wineD3DTexture, refguid);
118 LeaveCriticalSection(&d3d9_cs);
122 static DWORD WINAPI IDirect3DTexture9Impl_SetPriority(LPDIRECT3DTEXTURE9 iface, DWORD PriorityNew) {
123 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
125 TRACE("(%p) Relay\n", This);
127 EnterCriticalSection(&d3d9_cs);
128 ret = IWineD3DTexture_SetPriority(This->wineD3DTexture, PriorityNew);
129 LeaveCriticalSection(&d3d9_cs);
133 static DWORD WINAPI IDirect3DTexture9Impl_GetPriority(LPDIRECT3DTEXTURE9 iface) {
134 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
136 TRACE("(%p) Relay\n", This);
138 EnterCriticalSection(&d3d9_cs);
139 ret = IWineD3DTexture_GetPriority(This->wineD3DTexture);
140 LeaveCriticalSection(&d3d9_cs);
144 static void WINAPI IDirect3DTexture9Impl_PreLoad(LPDIRECT3DTEXTURE9 iface) {
145 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
146 TRACE("(%p) Relay\n", This);
148 EnterCriticalSection(&d3d9_cs);
149 IWineD3DTexture_PreLoad(This->wineD3DTexture);
150 LeaveCriticalSection(&d3d9_cs);
153 static D3DRESOURCETYPE WINAPI IDirect3DTexture9Impl_GetType(LPDIRECT3DTEXTURE9 iface) {
154 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
156 TRACE("(%p) Relay\n", This);
158 EnterCriticalSection(&d3d9_cs);
159 ret = IWineD3DTexture_GetType(This->wineD3DTexture);
160 LeaveCriticalSection(&d3d9_cs);
164 /* IDirect3DTexture9 IDirect3DBaseTexture9 Interface follow: */
165 static DWORD WINAPI IDirect3DTexture9Impl_SetLOD(LPDIRECT3DTEXTURE9 iface, DWORD LODNew) {
166 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
168 TRACE("(%p) Relay\n", This);
170 EnterCriticalSection(&d3d9_cs);
171 ret = IWineD3DTexture_SetLOD(This->wineD3DTexture, LODNew);
172 LeaveCriticalSection(&d3d9_cs);
176 static DWORD WINAPI IDirect3DTexture9Impl_GetLOD(LPDIRECT3DTEXTURE9 iface) {
177 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
179 TRACE("(%p) Relay\n", This);
181 EnterCriticalSection(&d3d9_cs);
182 ret = IWineD3DTexture_GetLOD(This->wineD3DTexture);
183 LeaveCriticalSection(&d3d9_cs);
187 static DWORD WINAPI IDirect3DTexture9Impl_GetLevelCount(LPDIRECT3DTEXTURE9 iface) {
188 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
190 TRACE("(%p) Relay\n", This);
192 EnterCriticalSection(&d3d9_cs);
193 ret = IWineD3DTexture_GetLevelCount(This->wineD3DTexture);
194 LeaveCriticalSection(&d3d9_cs);
198 static HRESULT WINAPI IDirect3DTexture9Impl_SetAutoGenFilterType(LPDIRECT3DTEXTURE9 iface, D3DTEXTUREFILTERTYPE FilterType) {
199 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
201 TRACE("(%p) Relay\n", This);
203 EnterCriticalSection(&d3d9_cs);
204 hr = IWineD3DTexture_SetAutoGenFilterType(This->wineD3DTexture, (WINED3DTEXTUREFILTERTYPE) FilterType);
205 LeaveCriticalSection(&d3d9_cs);
209 static D3DTEXTUREFILTERTYPE WINAPI IDirect3DTexture9Impl_GetAutoGenFilterType(LPDIRECT3DTEXTURE9 iface) {
210 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
211 D3DTEXTUREFILTERTYPE ret;
212 TRACE("(%p) Relay\n", This);
214 EnterCriticalSection(&d3d9_cs);
215 ret = (D3DTEXTUREFILTERTYPE) IWineD3DTexture_GetAutoGenFilterType(This->wineD3DTexture);
216 LeaveCriticalSection(&d3d9_cs);
220 static void WINAPI IDirect3DTexture9Impl_GenerateMipSubLevels(LPDIRECT3DTEXTURE9 iface) {
221 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
222 TRACE("(%p) Relay\n", This);
224 EnterCriticalSection(&d3d9_cs);
225 IWineD3DTexture_GenerateMipSubLevels(This->wineD3DTexture);
226 LeaveCriticalSection(&d3d9_cs);
229 /* IDirect3DTexture9 Interface follow: */
230 static HRESULT WINAPI IDirect3DTexture9Impl_GetLevelDesc(LPDIRECT3DTEXTURE9 iface, UINT Level, D3DSURFACE_DESC* pDesc) {
231 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
232 WINED3DSURFACE_DESC wined3ddesc;
235 TRACE("(%p) Relay\n", This);
237 EnterCriticalSection(&d3d9_cs);
238 hr = IWineD3DTexture_GetLevelDesc(This->wineD3DTexture, Level, &wined3ddesc);
239 LeaveCriticalSection(&d3d9_cs);
243 pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.format);
244 pDesc->Type = wined3ddesc.resource_type;
245 pDesc->Usage = wined3ddesc.usage;
246 pDesc->Pool = wined3ddesc.pool;
247 pDesc->MultiSampleType = wined3ddesc.multisample_type;
248 pDesc->MultiSampleQuality = wined3ddesc.multisample_quality;
249 pDesc->Width = wined3ddesc.width;
250 pDesc->Height = wined3ddesc.height;
256 static HRESULT WINAPI IDirect3DTexture9Impl_GetSurfaceLevel(LPDIRECT3DTEXTURE9 iface, UINT Level, IDirect3DSurface9** ppSurfaceLevel) {
257 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
258 HRESULT hrc = D3D_OK;
259 IWineD3DSurface *mySurface = NULL;
261 TRACE("(%p) Relay\n", This);
262 EnterCriticalSection(&d3d9_cs);
263 hrc = IWineD3DTexture_GetSurfaceLevel(This->wineD3DTexture, Level, &mySurface);
264 if (hrc == D3D_OK && NULL != ppSurfaceLevel) {
265 IWineD3DSurface_GetParent(mySurface, (IUnknown **)ppSurfaceLevel);
266 IWineD3DSurface_Release(mySurface);
268 LeaveCriticalSection(&d3d9_cs);
272 static HRESULT WINAPI IDirect3DTexture9Impl_LockRect(LPDIRECT3DTEXTURE9 iface, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
273 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
275 TRACE("(%p) Relay\n", This);
277 EnterCriticalSection(&d3d9_cs);
278 hr = IWineD3DTexture_LockRect(This->wineD3DTexture, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
279 LeaveCriticalSection(&d3d9_cs);
283 static HRESULT WINAPI IDirect3DTexture9Impl_UnlockRect(LPDIRECT3DTEXTURE9 iface, UINT Level) {
284 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
286 TRACE("(%p) Relay\n", This);
288 EnterCriticalSection(&d3d9_cs);
289 hr = IWineD3DTexture_UnlockRect(This->wineD3DTexture, Level);
290 LeaveCriticalSection(&d3d9_cs);
294 static HRESULT WINAPI IDirect3DTexture9Impl_AddDirtyRect(LPDIRECT3DTEXTURE9 iface, CONST RECT* pDirtyRect) {
295 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
297 TRACE("(%p) Relay\n", This);
299 EnterCriticalSection(&d3d9_cs);
300 hr = IWineD3DTexture_AddDirtyRect(This->wineD3DTexture, pDirtyRect);
301 LeaveCriticalSection(&d3d9_cs);
305 static const IDirect3DTexture9Vtbl Direct3DTexture9_Vtbl =
308 IDirect3DTexture9Impl_QueryInterface,
309 IDirect3DTexture9Impl_AddRef,
310 IDirect3DTexture9Impl_Release,
311 /* IDirect3DResource9 */
312 IDirect3DTexture9Impl_GetDevice,
313 IDirect3DTexture9Impl_SetPrivateData,
314 IDirect3DTexture9Impl_GetPrivateData,
315 IDirect3DTexture9Impl_FreePrivateData,
316 IDirect3DTexture9Impl_SetPriority,
317 IDirect3DTexture9Impl_GetPriority,
318 IDirect3DTexture9Impl_PreLoad,
319 IDirect3DTexture9Impl_GetType,
320 /* IDirect3dBaseTexture9 */
321 IDirect3DTexture9Impl_SetLOD,
322 IDirect3DTexture9Impl_GetLOD,
323 IDirect3DTexture9Impl_GetLevelCount,
324 IDirect3DTexture9Impl_SetAutoGenFilterType,
325 IDirect3DTexture9Impl_GetAutoGenFilterType,
326 IDirect3DTexture9Impl_GenerateMipSubLevels,
327 /* IDirect3DTexture9 */
328 IDirect3DTexture9Impl_GetLevelDesc,
329 IDirect3DTexture9Impl_GetSurfaceLevel,
330 IDirect3DTexture9Impl_LockRect,
331 IDirect3DTexture9Impl_UnlockRect,
332 IDirect3DTexture9Impl_AddDirtyRect
336 /* IDirect3DDevice9 IDirect3DTexture9 Methods follow: */
337 HRESULT WINAPI IDirect3DDevice9Impl_CreateTexture(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, UINT Levels, DWORD Usage,
338 D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture9** ppTexture, HANDLE* pSharedHandle) {
339 IDirect3DTexture9Impl *object;
340 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
341 HRESULT hrc = D3D_OK;
343 TRACE("(%p) : W(%d) H(%d), Lvl(%d) d(%d), Fmt(%#x), Pool(%d)\n", This, Width, Height, Levels, Usage, Format, Pool);
345 /* Allocate the storage for the device */
346 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DTexture9Impl));
348 if (NULL == object) {
349 ERR("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
350 return D3DERR_OUTOFVIDEOMEMORY;
353 object->lpVtbl = &Direct3DTexture9_Vtbl;
355 EnterCriticalSection(&d3d9_cs);
356 hrc = IWineD3DDevice_CreateTexture(This->WineD3DDevice, Width, Height, Levels, Usage & WINED3DUSAGE_MASK,
357 wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DTexture, (IUnknown *)object);
358 LeaveCriticalSection(&d3d9_cs);
362 WARN("(%p) call to IWineD3DDevice_CreateTexture failed\n", This);
363 HeapFree(GetProcessHeap(), 0, object);
365 IDirect3DDevice9Ex_AddRef(iface);
366 object->parentDevice = iface;
367 *ppTexture= (LPDIRECT3DTEXTURE9) object;
368 TRACE("(%p) Created Texture %p, %p\n", This, object, object->wineD3DTexture);