Spelling fix.
[wine] / dlls / d3d9 / texture.c
1 /*
2  * IDirect3DTexture9 implementation
3  *
4  * Copyright 2002-2003 Jason Edmeades
5  *                     Raphael Junqueira
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "config.h"
23
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "wingdi.h"
30 #include "wine/debug.h"
31
32 #include "d3d9_private.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
35
36 /* IDirect3DTexture9 IUnknown parts follow: */
37 HRESULT WINAPI IDirect3DTexture9Impl_QueryInterface(LPDIRECT3DTEXTURE9 iface, REFIID riid, LPVOID* ppobj) {
38     ICOM_THIS(IDirect3DTexture9Impl,iface);
39
40     if (IsEqualGUID(riid, &IID_IUnknown)
41         || IsEqualGUID(riid, &IID_IDirect3DResource9)
42         || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
43         || IsEqualGUID(riid, &IID_IDirect3DTexture9)) {
44         IDirect3DTexture9Impl_AddRef(iface);
45         *ppobj = This;
46         return D3D_OK;
47     }
48
49     WARN("(%p)->(%s,%p) not found\n", This, debugstr_guid(riid), ppobj);
50     return E_NOINTERFACE;
51 }
52
53 ULONG WINAPI IDirect3DTexture9Impl_AddRef(LPDIRECT3DTEXTURE9 iface) {
54     ICOM_THIS(IDirect3DTexture9Impl,iface);
55     TRACE("(%p) : AddRef from %ld\n", This, This->ref);
56     return ++(This->ref);
57 }
58
59 ULONG WINAPI IDirect3DTexture9Impl_Release(LPDIRECT3DTEXTURE9 iface) {
60     ICOM_THIS(IDirect3DTexture9Impl,iface);
61     ULONG ref = --This->ref;
62     int i;
63
64     TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
65     if (ref == 0) {
66         for (i = 0; i < This->levels; i++) {
67             if (NULL != This->surfaces[i]) {
68                 TRACE("(%p) : Releasing surface %p\n", This, This->surfaces[i]);
69                 IDirect3DSurface9Impl_Release((LPDIRECT3DSURFACE9) This->surfaces[i]);
70             }
71         }
72         HeapFree(GetProcessHeap(), 0, This);
73     }
74     return ref;
75 }
76
77 /* IDirect3DTexture9 IDirect3DResource9 Interface follow: */
78 HRESULT WINAPI IDirect3DTexture9Impl_GetDevice(LPDIRECT3DTEXTURE9 iface, IDirect3DDevice9** ppDevice) {
79     ICOM_THIS(IDirect3DTexture9Impl,iface);
80     return IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9) This, ppDevice);
81 }
82
83 HRESULT WINAPI IDirect3DTexture9Impl_SetPrivateData(LPDIRECT3DTEXTURE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
84     ICOM_THIS(IDirect3DTexture9Impl,iface);
85     FIXME("(%p) : stub\n", This);
86     return D3D_OK;
87 }
88
89 HRESULT WINAPI IDirect3DTexture9Impl_GetPrivateData(LPDIRECT3DTEXTURE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
90     ICOM_THIS(IDirect3DTexture9Impl,iface);
91     FIXME("(%p) : stub\n", This);
92     return D3D_OK;
93 }
94
95 HRESULT WINAPI IDirect3DTexture9Impl_FreePrivateData(LPDIRECT3DTEXTURE9 iface, REFGUID refguid) {
96     ICOM_THIS(IDirect3DTexture9Impl,iface);
97     FIXME("(%p) : stub\n", This);
98     return D3D_OK;
99 }
100
101 DWORD WINAPI IDirect3DTexture9Impl_SetPriority(LPDIRECT3DTEXTURE9 iface, DWORD PriorityNew) {
102     ICOM_THIS(IDirect3DTexture9Impl,iface);
103     return IDirect3DResource9Impl_SetPriority((LPDIRECT3DRESOURCE9) This, PriorityNew);
104 }
105
106 DWORD WINAPI IDirect3DTexture9Impl_GetPriority(LPDIRECT3DTEXTURE9 iface) {
107     ICOM_THIS(IDirect3DTexture9Impl,iface);
108     return IDirect3DResource9Impl_GetPriority((LPDIRECT3DRESOURCE9) This);
109 }
110
111 void WINAPI IDirect3DTexture9Impl_PreLoad(LPDIRECT3DTEXTURE9 iface) {
112     ICOM_THIS(IDirect3DTexture9Impl,iface);
113     FIXME("(%p) : stub\n", This);
114     return ;
115 }
116
117 D3DRESOURCETYPE WINAPI IDirect3DTexture9Impl_GetType(LPDIRECT3DTEXTURE9 iface) {
118     ICOM_THIS(IDirect3DTexture9Impl,iface);
119     return IDirect3DResource9Impl_GetType((LPDIRECT3DRESOURCE9) This);
120 }
121
122 /* IDirect3DTexture9 IDirect3DBaseTexture9 Interface follow: */
123 DWORD WINAPI IDirect3DTexture9Impl_SetLOD(LPDIRECT3DTEXTURE9 iface, DWORD LODNew) {
124     ICOM_THIS(IDirect3DTexture9Impl,iface);
125     return IDirect3DBaseTexture9Impl_SetLOD((LPDIRECT3DBASETEXTURE9) This, LODNew);
126 }
127
128 DWORD WINAPI IDirect3DTexture9Impl_GetLOD(LPDIRECT3DTEXTURE9 iface) {
129     ICOM_THIS(IDirect3DTexture9Impl,iface);
130     return IDirect3DBaseTexture9Impl_GetLOD((LPDIRECT3DBASETEXTURE9) This);
131 }
132
133 DWORD WINAPI IDirect3DTexture9Impl_GetLevelCount(LPDIRECT3DTEXTURE9 iface) {
134     ICOM_THIS(IDirect3DTexture9Impl,iface);
135     return IDirect3DBaseTexture9Impl_GetLevelCount((LPDIRECT3DBASETEXTURE9) This);
136 }
137
138 HRESULT WINAPI IDirect3DTexture9Impl_SetAutoGenFilterType(LPDIRECT3DTEXTURE9 iface, D3DTEXTUREFILTERTYPE FilterType) {
139     ICOM_THIS(IDirect3DTexture9Impl,iface);
140     return IDirect3DBaseTexture9Impl_SetAutoGenFilterType((LPDIRECT3DBASETEXTURE9) This, FilterType);
141 }
142
143 D3DTEXTUREFILTERTYPE WINAPI IDirect3DTexture9Impl_GetAutoGenFilterType(LPDIRECT3DTEXTURE9 iface) {
144     ICOM_THIS(IDirect3DTexture9Impl,iface);
145     return IDirect3DBaseTexture9Impl_GetAutoGenFilterType((LPDIRECT3DBASETEXTURE9) This);
146 }
147
148 void WINAPI IDirect3DTexture9Impl_GenerateMipSubLevels(LPDIRECT3DTEXTURE9 iface) {
149     ICOM_THIS(IDirect3DTexture9Impl,iface);
150     FIXME("(%p) : stub\n", This);
151     return ;
152 }
153
154 /* IDirect3DTexture9 Interface follow: */
155 HRESULT WINAPI IDirect3DTexture9Impl_GetLevelDesc(LPDIRECT3DTEXTURE9 iface, UINT Level, D3DSURFACE_DESC* pDesc) {
156     ICOM_THIS(IDirect3DTexture9Impl,iface);
157
158     if (Level < This->levels) {
159         TRACE("(%p) Level (%d)\n", This, Level);
160         return IDirect3DSurface9Impl_GetDesc((LPDIRECT3DSURFACE9) This->surfaces[Level], pDesc);
161     } else {
162         FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
163         return D3DERR_INVALIDCALL;
164     }
165     return D3D_OK;
166 }
167
168 HRESULT WINAPI IDirect3DTexture9Impl_GetSurfaceLevel(LPDIRECT3DTEXTURE9 iface, UINT Level, IDirect3DSurface9** ppSurfaceLevel) {
169     ICOM_THIS(IDirect3DTexture9Impl,iface);
170     *ppSurfaceLevel = (LPDIRECT3DSURFACE9) This->surfaces[Level];
171     IDirect3DSurface9Impl_AddRef((LPDIRECT3DSURFACE9) This->surfaces[Level]);
172     TRACE("(%p) : returning %p for level %d\n", This, *ppSurfaceLevel, Level);
173     return D3D_OK;
174 }
175
176 HRESULT WINAPI IDirect3DTexture9Impl_LockRect(LPDIRECT3DTEXTURE9 iface, UINT Level,D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
177     HRESULT hr;
178     ICOM_THIS(IDirect3DTexture9Impl,iface);
179     if (Level < This->levels) {
180         /**
181          * Not dirtified while Surfaces don't notify dirtification
182          * This->impl.parent.Dirty = TRUE;
183          */
184         hr = IDirect3DSurface9Impl_LockRect((LPDIRECT3DSURFACE9) This->surfaces[Level], pLockedRect, pRect, Flags);
185         TRACE("(%p) Level (%d) success(%lu)\n", This, Level, hr);
186     } else {
187         FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
188         return D3DERR_INVALIDCALL;
189     }
190     return hr;
191 }
192
193 HRESULT WINAPI IDirect3DTexture9Impl_UnlockRect(LPDIRECT3DTEXTURE9 iface, UINT Level) {
194     HRESULT hr;
195     ICOM_THIS(IDirect3DTexture9Impl,iface);
196     if (Level < This->levels) {
197         hr = IDirect3DSurface9Impl_UnlockRect((LPDIRECT3DSURFACE9) This->surfaces[Level]);
198         TRACE("(%p) Level (%d) success(%lu)\n", This, Level, hr);
199     } else {
200         FIXME("(%p) level(%d) overflow Levels(%d)\n", This, Level, This->levels);
201         return D3DERR_INVALIDCALL;
202     }
203     return hr;
204 }
205
206 HRESULT WINAPI IDirect3DTexture9Impl_AddDirtyRect(LPDIRECT3DTEXTURE9 iface, CONST RECT* pDirtyRect) {
207     ICOM_THIS(IDirect3DTexture9Impl,iface);
208     FIXME("(%p) : stub\n", This);
209     This->Dirty = TRUE;
210     return D3D_OK;
211 }
212
213
214 ICOM_VTABLE(IDirect3DTexture9) Direct3DTexture9_Vtbl =
215 {
216     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
217     IDirect3DTexture9Impl_QueryInterface,
218     IDirect3DTexture9Impl_AddRef,
219     IDirect3DTexture9Impl_Release,
220     IDirect3DTexture9Impl_GetDevice,
221     IDirect3DTexture9Impl_SetPrivateData,
222     IDirect3DTexture9Impl_GetPrivateData,
223     IDirect3DTexture9Impl_FreePrivateData,
224     IDirect3DTexture9Impl_SetPriority,
225     IDirect3DTexture9Impl_GetPriority,
226     IDirect3DTexture9Impl_PreLoad,
227     IDirect3DTexture9Impl_GetType,
228     IDirect3DTexture9Impl_SetLOD,
229     IDirect3DTexture9Impl_GetLOD,
230     IDirect3DTexture9Impl_GetLevelCount,
231     IDirect3DTexture9Impl_SetAutoGenFilterType,
232     IDirect3DTexture9Impl_GetAutoGenFilterType,
233     IDirect3DTexture9Impl_GenerateMipSubLevels,
234     IDirect3DTexture9Impl_GetLevelDesc,
235     IDirect3DTexture9Impl_GetSurfaceLevel,
236     IDirect3DTexture9Impl_LockRect,
237     IDirect3DTexture9Impl_UnlockRect,
238     IDirect3DTexture9Impl_AddDirtyRect
239 };
240
241
242 /* IDirect3DDevice9 IDirect3DTexture9 Methods follow: */
243 HRESULT  WINAPI  IDirect3DDevice9Impl_CreateTexture(LPDIRECT3DDEVICE9 iface, UINT Width, UINT Height, UINT Levels, DWORD Usage,
244                                                     D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture9** ppTexture, HANDLE* pSharedHandle) {
245     ICOM_THIS(IDirect3DDevice9Impl,iface);
246     FIXME("(%p) : stub\n", This);    
247     return D3D_OK;
248 }