comctl32/toolbar: When a null lParam is passed to TB_GETBUTTONTEXTA, we should not...
[wine] / dlls / d3d8 / cubetexture.c
1 /*
2  * IDirect3DCubeTexture8 implementation
3  *
4  * Copyright 2005 Oliver Stieber
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "config.h"
22 #include "d3d8_private.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
25
26 /* IDirect3DCubeTexture8 IUnknown parts follow: */
27 static HRESULT WINAPI IDirect3DCubeTexture8Impl_QueryInterface(LPDIRECT3DCUBETEXTURE8 iface, REFIID riid, LPVOID *ppobj) {
28     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
29     if (IsEqualGUID(riid, &IID_IUnknown)
30         || IsEqualGUID(riid, &IID_IDirect3DResource8)
31         || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
32         || IsEqualGUID(riid, &IID_IDirect3DCubeTexture8)) {
33         IUnknown_AddRef(iface);
34         *ppobj = This;
35         return S_OK;
36     }
37
38     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
39     *ppobj = NULL;
40     return E_NOINTERFACE;
41 }
42
43 static ULONG WINAPI IDirect3DCubeTexture8Impl_AddRef(LPDIRECT3DCUBETEXTURE8 iface) {
44     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
45     ULONG ref = InterlockedIncrement(&This->ref);
46
47     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
48
49     return ref;
50 }
51
52 static ULONG WINAPI IDirect3DCubeTexture8Impl_Release(LPDIRECT3DCUBETEXTURE8 iface) {
53     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
54     ULONG ref = InterlockedDecrement(&This->ref);
55
56     TRACE("(%p) : ReleaseRef to %d\n", This, ref);
57
58     if (ref == 0) {
59         TRACE("Releasing child %p\n", This->wineD3DCubeTexture);
60         EnterCriticalSection(&d3d8_cs);
61         IWineD3DCubeTexture_Destroy(This->wineD3DCubeTexture, D3D8CB_DestroySurface);
62         LeaveCriticalSection(&d3d8_cs);
63         IUnknown_Release(This->parentDevice);
64         HeapFree(GetProcessHeap(), 0, This);
65     }
66     return ref;
67 }
68
69 /* IDirect3DCubeTexture8 IDirect3DResource8 Interface follow: */
70 static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetDevice(LPDIRECT3DCUBETEXTURE8 iface, IDirect3DDevice8 **ppDevice) {
71     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
72     IWineD3DDevice *wined3d_device;
73     HRESULT hr;
74     TRACE("(%p) Relay\n" , This);
75
76     EnterCriticalSection(&d3d8_cs);
77     hr = IWineD3DCubeTexture_GetDevice(This->wineD3DCubeTexture, &wined3d_device);
78     if (SUCCEEDED(hr))
79     {
80         IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
81         IWineD3DDevice_Release(wined3d_device);
82     }
83     LeaveCriticalSection(&d3d8_cs);
84     return hr;
85 }
86
87 static HRESULT WINAPI IDirect3DCubeTexture8Impl_SetPrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
88     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
89     HRESULT hr;
90     TRACE("(%p) Relay\n", This);
91
92     EnterCriticalSection(&d3d8_cs);
93     hr = IWineD3DCubeTexture_SetPrivateData(This->wineD3DCubeTexture,refguid,pData,SizeOfData,Flags);
94     LeaveCriticalSection(&d3d8_cs);
95     return hr;
96 }
97
98 static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetPrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
99     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
100     HRESULT hr;
101     TRACE("(%p) Relay\n", This);
102
103     EnterCriticalSection(&d3d8_cs);
104     hr = IWineD3DCubeTexture_GetPrivateData(This->wineD3DCubeTexture,refguid,pData,pSizeOfData);
105     LeaveCriticalSection(&d3d8_cs);
106     return hr;
107 }
108
109 static HRESULT WINAPI IDirect3DCubeTexture8Impl_FreePrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid) {
110     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
111     HRESULT hr;
112     TRACE("(%p) Relay\n", This);
113
114     EnterCriticalSection(&d3d8_cs);
115     hr = IWineD3DCubeTexture_FreePrivateData(This->wineD3DCubeTexture,refguid);
116     LeaveCriticalSection(&d3d8_cs);
117     return hr;
118 }
119
120 static DWORD WINAPI IDirect3DCubeTexture8Impl_SetPriority(LPDIRECT3DCUBETEXTURE8 iface, DWORD PriorityNew) {
121     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
122     DWORD ret;
123     TRACE("(%p) Relay\n", This);
124
125     EnterCriticalSection(&d3d8_cs);
126     ret = IWineD3DCubeTexture_SetPriority(This->wineD3DCubeTexture, PriorityNew);
127     LeaveCriticalSection(&d3d8_cs);
128     return ret;
129 }
130
131 static DWORD WINAPI IDirect3DCubeTexture8Impl_GetPriority(LPDIRECT3DCUBETEXTURE8 iface) {
132     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
133     DWORD ret;
134     TRACE("(%p) Relay\n", This);
135
136     EnterCriticalSection(&d3d8_cs);
137     ret =  IWineD3DCubeTexture_GetPriority(This->wineD3DCubeTexture);
138     LeaveCriticalSection(&d3d8_cs);
139     return ret;
140 }
141
142 static void WINAPI IDirect3DCubeTexture8Impl_PreLoad(LPDIRECT3DCUBETEXTURE8 iface) {
143     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
144     TRACE("(%p) Relay\n", This);
145
146     EnterCriticalSection(&d3d8_cs);
147     IWineD3DCubeTexture_PreLoad(This->wineD3DCubeTexture);
148     LeaveCriticalSection(&d3d8_cs);
149 }
150
151 static D3DRESOURCETYPE WINAPI IDirect3DCubeTexture8Impl_GetType(LPDIRECT3DCUBETEXTURE8 iface) {
152     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
153     D3DRESOURCETYPE type;
154     TRACE("(%p) Relay\n", This);
155
156     EnterCriticalSection(&d3d8_cs);
157     type = IWineD3DCubeTexture_GetType(This->wineD3DCubeTexture);
158     LeaveCriticalSection(&d3d8_cs);
159     return type;
160 }
161
162 /* IDirect3DCubeTexture8 IDirect3DBaseTexture8 Interface follow: */
163 static DWORD WINAPI IDirect3DCubeTexture8Impl_SetLOD(LPDIRECT3DCUBETEXTURE8 iface, DWORD LODNew) {
164     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
165     DWORD lod;
166     TRACE("(%p) Relay\n", This);
167
168     EnterCriticalSection(&d3d8_cs);
169     lod = IWineD3DCubeTexture_SetLOD(This->wineD3DCubeTexture, LODNew);
170     LeaveCriticalSection(&d3d8_cs);
171     return lod;
172 }
173
174 static DWORD WINAPI IDirect3DCubeTexture8Impl_GetLOD(LPDIRECT3DCUBETEXTURE8 iface) {
175     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
176     DWORD lod;
177     TRACE("(%p) Relay\n", This);
178
179     EnterCriticalSection(&d3d8_cs);
180     lod = IWineD3DCubeTexture_GetLOD((LPDIRECT3DBASETEXTURE8) This);
181     LeaveCriticalSection(&d3d8_cs);
182     return lod;
183 }
184
185 static DWORD WINAPI IDirect3DCubeTexture8Impl_GetLevelCount(LPDIRECT3DCUBETEXTURE8 iface) {
186     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
187     DWORD cnt;
188     TRACE("(%p) Relay\n", This);
189
190     EnterCriticalSection(&d3d8_cs);
191     cnt = IWineD3DCubeTexture_GetLevelCount(This->wineD3DCubeTexture);
192     LeaveCriticalSection(&d3d8_cs);
193     return cnt;
194 }
195
196 /* IDirect3DCubeTexture8 Interface follow: */
197 static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetLevelDesc(LPDIRECT3DCUBETEXTURE8 iface, UINT Level, D3DSURFACE_DESC *pDesc) {
198     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
199     HRESULT hr;
200     WINED3DSURFACE_DESC    wined3ddesc;
201
202     TRACE("(%p) Relay\n", This);
203
204     /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
205     wined3ddesc.Format              = (WINED3DFORMAT *)&pDesc->Format;
206     wined3ddesc.Type                = (WINED3DRESOURCETYPE *)&pDesc->Type;
207     wined3ddesc.Usage               = &pDesc->Usage;
208     wined3ddesc.Pool                = (WINED3DPOOL *) &pDesc->Pool;
209     wined3ddesc.Size                = &pDesc->Size;
210     wined3ddesc.MultiSampleType     = (WINED3DMULTISAMPLE_TYPE *) &pDesc->MultiSampleType;
211     wined3ddesc.MultiSampleQuality  = NULL; /* DirectX9 only */
212     wined3ddesc.Width               = &pDesc->Width;
213     wined3ddesc.Height              = &pDesc->Height;
214
215     EnterCriticalSection(&d3d8_cs);
216     hr = IWineD3DCubeTexture_GetLevelDesc(This->wineD3DCubeTexture, Level, &wined3ddesc);
217     LeaveCriticalSection(&d3d8_cs);
218
219     if (SUCCEEDED(hr)) pDesc->Format = d3dformat_from_wined3dformat(pDesc->Format);
220
221     return hr;
222 }
223
224 static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetCubeMapSurface(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface8 **ppCubeMapSurface) {
225     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
226     HRESULT hrc = D3D_OK;
227     IWineD3DSurface *mySurface = NULL;
228
229     TRACE("(%p) Relay\n", This);
230
231     EnterCriticalSection(&d3d8_cs);
232     hrc = IWineD3DCubeTexture_GetCubeMapSurface(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, &mySurface);
233     if (hrc == D3D_OK && NULL != ppCubeMapSurface) {
234        IWineD3DCubeTexture_GetParent(mySurface, (IUnknown **)ppCubeMapSurface);
235        IWineD3DCubeTexture_Release(mySurface);
236     }
237     LeaveCriticalSection(&d3d8_cs);
238     return hrc;
239 }
240
241 static HRESULT WINAPI IDirect3DCubeTexture8Impl_LockRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT *pRect, DWORD Flags) {
242     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
243     HRESULT hr;
244     TRACE("(%p) Relay\n", This);
245
246     EnterCriticalSection(&d3d8_cs);
247     hr = IWineD3DCubeTexture_LockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
248     LeaveCriticalSection(&d3d8_cs);
249     return hr;
250 }
251
252 static HRESULT WINAPI IDirect3DCubeTexture8Impl_UnlockRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level) {
253     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
254     HRESULT hr;
255     TRACE("(%p) Relay\n", This);
256
257     EnterCriticalSection(&d3d8_cs);
258     hr = IWineD3DCubeTexture_UnlockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level);
259     LeaveCriticalSection(&d3d8_cs);
260     return hr;
261 }
262
263 static HRESULT WINAPI IDirect3DCubeTexture8Impl_AddDirtyRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, CONST RECT *pDirtyRect) {
264     IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
265     HRESULT hr;
266     TRACE("(%p) Relay\n", This);
267
268     EnterCriticalSection(&d3d8_cs);
269     hr = IWineD3DCubeTexture_AddDirtyRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, pDirtyRect);
270     LeaveCriticalSection(&d3d8_cs);
271     return hr;
272 }
273
274
275 const IDirect3DCubeTexture8Vtbl Direct3DCubeTexture8_Vtbl =
276 {
277     /* IUnknown */
278     IDirect3DCubeTexture8Impl_QueryInterface,
279     IDirect3DCubeTexture8Impl_AddRef,
280     IDirect3DCubeTexture8Impl_Release,
281     /* IDirect3DResource8 */
282     IDirect3DCubeTexture8Impl_GetDevice,
283     IDirect3DCubeTexture8Impl_SetPrivateData,
284     IDirect3DCubeTexture8Impl_GetPrivateData,
285     IDirect3DCubeTexture8Impl_FreePrivateData,
286     IDirect3DCubeTexture8Impl_SetPriority,
287     IDirect3DCubeTexture8Impl_GetPriority,
288     IDirect3DCubeTexture8Impl_PreLoad,
289     IDirect3DCubeTexture8Impl_GetType,
290     /* IDirect3DBaseTexture8 */
291     IDirect3DCubeTexture8Impl_SetLOD,
292     IDirect3DCubeTexture8Impl_GetLOD,
293     IDirect3DCubeTexture8Impl_GetLevelCount,
294     /* IDirect3DCubeTexture8 */
295     IDirect3DCubeTexture8Impl_GetLevelDesc,
296     IDirect3DCubeTexture8Impl_GetCubeMapSurface,
297     IDirect3DCubeTexture8Impl_LockRect,
298     IDirect3DCubeTexture8Impl_UnlockRect,
299     IDirect3DCubeTexture8Impl_AddDirtyRect
300 };