user32: Remove a unused variable from ES_PASSWORD test.
[wine] / dlls / d3d9 / cubetexture.c
1 /*
2  * IDirect3DCubeTexture9 implementation
3  *
4  * Copyright 2002-2005 Jason Edmeades
5  * Copyright 2002-2005 Raphael Junqueira
6  * Copyright 2005 Oliver Stieber
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #include "config.h"
24 #include "d3d9_private.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
27
28
29 /* IDirect3DCubeTexture9 IUnknown parts follow: */
30 static HRESULT WINAPI IDirect3DCubeTexture9Impl_QueryInterface(LPDIRECT3DCUBETEXTURE9 iface, REFIID riid, LPVOID* ppobj) {
31     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
32     if (IsEqualGUID(riid, &IID_IUnknown)
33         || IsEqualGUID(riid, &IID_IDirect3DResource9)
34         || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
35         || IsEqualGUID(riid, &IID_IDirect3DCubeTexture9)) {
36         IUnknown_AddRef(iface);
37         *ppobj = This;
38         return S_OK;
39     }
40
41     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
42     *ppobj = NULL;
43     return E_NOINTERFACE;
44 }
45
46 static ULONG WINAPI IDirect3DCubeTexture9Impl_AddRef(LPDIRECT3DCUBETEXTURE9 iface) {
47     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
48     ULONG ref = InterlockedIncrement(&This->ref);
49
50     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
51
52     return ref;
53 }
54
55 static ULONG WINAPI IDirect3DCubeTexture9Impl_Release(LPDIRECT3DCUBETEXTURE9 iface) {
56     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
57     ULONG ref = InterlockedDecrement(&This->ref);
58
59     TRACE("(%p) : ReleaseRef to %d\n", This, ref);
60
61     if (ref == 0) {
62         TRACE("Releasing child %p\n", This->wineD3DCubeTexture);
63         IWineD3DCubeTexture_Destroy(This->wineD3DCubeTexture, D3D9CB_DestroySurface);
64         IUnknown_Release(This->parentDevice);
65         HeapFree(GetProcessHeap(), 0, This);
66     }
67     return ref;
68 }
69
70 /* IDirect3DCubeTexture9 IDirect3DResource9 Interface follow: */
71 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetDevice(LPDIRECT3DCUBETEXTURE9 iface, IDirect3DDevice9** ppDevice) {
72     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
73     TRACE("(%p) Relay\n" , This);
74     return IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9) This, ppDevice);
75 }
76
77 static HRESULT WINAPI IDirect3DCubeTexture9Impl_SetPrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
78     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
79     TRACE("(%p) Relay\n", This);
80     return IWineD3DCubeTexture_SetPrivateData(This->wineD3DCubeTexture,refguid,pData,SizeOfData,Flags);
81 }
82
83 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetPrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
84     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
85     TRACE("(%p) Relay\n", This);
86     return IWineD3DCubeTexture_GetPrivateData(This->wineD3DCubeTexture,refguid,pData,pSizeOfData);
87 }
88
89 static HRESULT WINAPI IDirect3DCubeTexture9Impl_FreePrivateData(LPDIRECT3DCUBETEXTURE9 iface, REFGUID refguid) {
90     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
91     TRACE("(%p) Relay\n", This);
92     return IWineD3DCubeTexture_FreePrivateData(This->wineD3DCubeTexture,refguid);
93 }
94
95 static DWORD WINAPI IDirect3DCubeTexture9Impl_SetPriority(LPDIRECT3DCUBETEXTURE9 iface, DWORD PriorityNew) {
96     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
97     TRACE("(%p) Relay\n", This);
98     return IWineD3DCubeTexture_SetPriority(This->wineD3DCubeTexture, PriorityNew);
99 }
100
101 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetPriority(LPDIRECT3DCUBETEXTURE9 iface) {
102     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
103     TRACE("(%p) Relay\n", This);
104     return IWineD3DCubeTexture_GetPriority(This->wineD3DCubeTexture);
105 }
106
107 static void WINAPI IDirect3DCubeTexture9Impl_PreLoad(LPDIRECT3DCUBETEXTURE9 iface) {
108     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
109     TRACE("(%p) Relay\n", This);
110     IWineD3DCubeTexture_PreLoad(This->wineD3DCubeTexture);
111 }
112
113 static D3DRESOURCETYPE WINAPI IDirect3DCubeTexture9Impl_GetType(LPDIRECT3DCUBETEXTURE9 iface) {
114     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
115     TRACE("(%p) Relay\n", This);
116     return IWineD3DCubeTexture_GetType(This->wineD3DCubeTexture);
117 }
118
119 /* IDirect3DCubeTexture9 IDirect3DBaseTexture9 Interface follow: */
120 static DWORD WINAPI IDirect3DCubeTexture9Impl_SetLOD(LPDIRECT3DCUBETEXTURE9 iface, DWORD LODNew) {
121     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
122     TRACE("(%p) Relay\n", This);
123     return IWineD3DCubeTexture_SetLOD(This->wineD3DCubeTexture, LODNew);
124 }
125
126 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetLOD(LPDIRECT3DCUBETEXTURE9 iface) {
127     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
128     TRACE("(%p) Relay\n", This);
129     return IDirect3DBaseTexture9Impl_GetLOD((LPDIRECT3DBASETEXTURE9) This);
130 }
131
132 static DWORD WINAPI IDirect3DCubeTexture9Impl_GetLevelCount(LPDIRECT3DCUBETEXTURE9 iface) {
133     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
134     TRACE("(%p) Relay\n", This);
135     return IWineD3DCubeTexture_GetLevelCount(This->wineD3DCubeTexture);
136 }
137
138 static HRESULT WINAPI IDirect3DCubeTexture9Impl_SetAutoGenFilterType(LPDIRECT3DCUBETEXTURE9 iface, D3DTEXTUREFILTERTYPE FilterType) {
139     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
140     TRACE("(%p) Relay\n", This);
141     return IWineD3DCubeTexture_SetAutoGenFilterType(This->wineD3DCubeTexture, (WINED3DTEXTUREFILTERTYPE) FilterType);
142 }
143
144 static D3DTEXTUREFILTERTYPE WINAPI IDirect3DCubeTexture9Impl_GetAutoGenFilterType(LPDIRECT3DCUBETEXTURE9 iface) {
145     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
146     TRACE("(%p) Relay\n", This);
147     return (D3DTEXTUREFILTERTYPE) IWineD3DCubeTexture_GetAutoGenFilterType(This->wineD3DCubeTexture);
148 }
149
150 static void WINAPI IDirect3DCubeTexture9Impl_GenerateMipSubLevels(LPDIRECT3DCUBETEXTURE9 iface) {
151     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
152     TRACE("(%p) Relay\n", This);
153     IWineD3DCubeTexture_GenerateMipSubLevels(This->wineD3DCubeTexture);
154 }
155
156 /* IDirect3DCubeTexture9 Interface follow: */
157 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetLevelDesc(LPDIRECT3DCUBETEXTURE9 iface, UINT Level, D3DSURFACE_DESC* pDesc) {
158     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
159     WINED3DSURFACE_DESC    wined3ddesc;
160     UINT                   tmpInt = -1;
161
162     TRACE("(%p) Relay\n", This);
163
164     /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
165     wined3ddesc.Format              = (WINED3DFORMAT *)&pDesc->Format;
166     wined3ddesc.Type                = (WINED3DRESOURCETYPE *) &pDesc->Type;
167     wined3ddesc.Usage               = &pDesc->Usage;
168     wined3ddesc.Pool                = (WINED3DPOOL *) &pDesc->Pool;
169     wined3ddesc.Size                = &tmpInt;
170     wined3ddesc.MultiSampleType     = (WINED3DMULTISAMPLE_TYPE *) &pDesc->MultiSampleType;
171     wined3ddesc.MultiSampleQuality  = &pDesc->MultiSampleQuality;
172     wined3ddesc.Width               = &pDesc->Width;
173     wined3ddesc.Height              = &pDesc->Height;
174
175     return IWineD3DCubeTexture_GetLevelDesc(This->wineD3DCubeTexture, Level, &wined3ddesc);
176 }
177
178 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetCubeMapSurface(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface9** ppCubeMapSurface) {
179     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
180     HRESULT hrc = D3D_OK;
181     IWineD3DSurface *mySurface = NULL;
182
183     TRACE("(%p) Relay\n", This);
184
185     hrc = IWineD3DCubeTexture_GetCubeMapSurface(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, &mySurface);
186     if (hrc == D3D_OK && NULL != ppCubeMapSurface) {
187        IWineD3DCubeTexture_GetParent(mySurface, (IUnknown **)ppCubeMapSurface);
188        IWineD3DCubeTexture_Release(mySurface);
189     }
190     return hrc;
191 }
192
193 static HRESULT WINAPI IDirect3DCubeTexture9Impl_LockRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
194     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
195     TRACE("(%p) Relay\n", This);
196     return IWineD3DCubeTexture_LockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
197 }
198
199 static HRESULT WINAPI IDirect3DCubeTexture9Impl_UnlockRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, UINT Level) {
200     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
201     TRACE("(%p) Relay\n", This);
202     return IWineD3DCubeTexture_UnlockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level);
203 }
204
205 static HRESULT  WINAPI IDirect3DCubeTexture9Impl_AddDirtyRect(LPDIRECT3DCUBETEXTURE9 iface, D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) {
206     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
207     TRACE("(%p) Relay\n", This);
208     return IWineD3DCubeTexture_AddDirtyRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, pDirtyRect);
209 }
210
211
212 static const IDirect3DCubeTexture9Vtbl Direct3DCubeTexture9_Vtbl =
213 {
214     /* IUnknown */
215     IDirect3DCubeTexture9Impl_QueryInterface,
216     IDirect3DCubeTexture9Impl_AddRef,
217     IDirect3DCubeTexture9Impl_Release,
218     /* IDirect3DResource9 */
219     IDirect3DCubeTexture9Impl_GetDevice,
220     IDirect3DCubeTexture9Impl_SetPrivateData,
221     IDirect3DCubeTexture9Impl_GetPrivateData,
222     IDirect3DCubeTexture9Impl_FreePrivateData,
223     IDirect3DCubeTexture9Impl_SetPriority,
224     IDirect3DCubeTexture9Impl_GetPriority,
225     IDirect3DCubeTexture9Impl_PreLoad,
226     IDirect3DCubeTexture9Impl_GetType,
227     /* IDirect3DBaseTexture9 */
228     IDirect3DCubeTexture9Impl_SetLOD,
229     IDirect3DCubeTexture9Impl_GetLOD,
230     IDirect3DCubeTexture9Impl_GetLevelCount,
231     IDirect3DCubeTexture9Impl_SetAutoGenFilterType,
232     IDirect3DCubeTexture9Impl_GetAutoGenFilterType,
233     IDirect3DCubeTexture9Impl_GenerateMipSubLevels,
234     IDirect3DCubeTexture9Impl_GetLevelDesc,
235     IDirect3DCubeTexture9Impl_GetCubeMapSurface,
236     IDirect3DCubeTexture9Impl_LockRect,
237     IDirect3DCubeTexture9Impl_UnlockRect,
238     IDirect3DCubeTexture9Impl_AddDirtyRect
239 };
240
241
242
243
244 /* IDirect3DDevice9 IDirect3DCubeTexture9 Methods follow: */
245 HRESULT  WINAPI  IDirect3DDevice9Impl_CreateCubeTexture(LPDIRECT3DDEVICE9 iface,
246                                                         UINT EdgeLength, UINT Levels, DWORD Usage,
247                                                         D3DFORMAT Format, D3DPOOL Pool,
248                                                         IDirect3DCubeTexture9** ppCubeTexture, HANDLE* pSharedHandle) {
249
250     IDirect3DCubeTexture9Impl *object;
251     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
252     HRESULT hr = D3D_OK;
253
254     TRACE("(%p) : ELen(%d) Lvl(%d) Usage(%d) fmt(%u), Pool(%d)  Shared(%p)\n", This, EdgeLength, Levels, Usage, Format, Pool, pSharedHandle);
255
256     /* Allocate the storage for the device */
257     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
258
259     if (NULL == object) {
260         FIXME("(%p) allocation of CubeTexture failed\n", This);
261         return D3DERR_OUTOFVIDEOMEMORY;
262     }
263     object->lpVtbl = &Direct3DCubeTexture9_Vtbl;
264     object->ref = 1;
265     hr = IWineD3DDevice_CreateCubeTexture(This->WineD3DDevice, EdgeLength, Levels, Usage,
266                                  (WINED3DFORMAT)Format, (WINED3DPOOL) Pool, &object->wineD3DCubeTexture, pSharedHandle, (IUnknown*)object,
267                                  D3D9CB_CreateSurface);
268
269     if (hr != D3D_OK){
270
271         /* free up object */
272         FIXME("(%p) call to IWineD3DDevice_CreateCubeTexture failed\n", This);
273         HeapFree(GetProcessHeap(), 0, object);
274     } else {
275         IUnknown_AddRef(iface);
276         object->parentDevice = iface;
277         *ppCubeTexture = (LPDIRECT3DCUBETEXTURE9) object;
278         TRACE("(%p) : Created cube texture %p\n", This, object);
279     }
280
281     TRACE("(%p) returning %p\n",This, *ppCubeTexture);
282     return hr;
283 }