Sync ddraw, d3d8 and d3d9 + wined3d to wine 1.1.28
[reactos.git] / reactos / dll / directx / wine / 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
61 wined3d_mutex_lock();
62 IWineD3DCubeTexture_Destroy(This->wineD3DCubeTexture, D3D8CB_DestroySurface);
63 wined3d_mutex_unlock();
64
65 IUnknown_Release(This->parentDevice);
66 HeapFree(GetProcessHeap(), 0, This);
67 }
68 return ref;
69 }
70
71 /* IDirect3DCubeTexture8 IDirect3DResource8 Interface follow: */
72 static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetDevice(LPDIRECT3DCUBETEXTURE8 iface, IDirect3DDevice8 **ppDevice) {
73 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
74 IWineD3DDevice *wined3d_device;
75 HRESULT hr;
76 TRACE("(%p) Relay\n" , This);
77
78 wined3d_mutex_lock();
79 hr = IWineD3DCubeTexture_GetDevice(This->wineD3DCubeTexture, &wined3d_device);
80 if (SUCCEEDED(hr))
81 {
82 IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
83 IWineD3DDevice_Release(wined3d_device);
84 }
85 wined3d_mutex_unlock();
86
87 return hr;
88 }
89
90 static HRESULT WINAPI IDirect3DCubeTexture8Impl_SetPrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
91 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
92 HRESULT hr;
93 TRACE("(%p) Relay\n", This);
94
95 wined3d_mutex_lock();
96 hr = IWineD3DCubeTexture_SetPrivateData(This->wineD3DCubeTexture,refguid,pData,SizeOfData,Flags);
97 wined3d_mutex_unlock();
98
99 return hr;
100 }
101
102 static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetPrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
103 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
104 HRESULT hr;
105 TRACE("(%p) Relay\n", This);
106
107 wined3d_mutex_lock();
108 hr = IWineD3DCubeTexture_GetPrivateData(This->wineD3DCubeTexture,refguid,pData,pSizeOfData);
109 wined3d_mutex_unlock();
110
111 return hr;
112 }
113
114 static HRESULT WINAPI IDirect3DCubeTexture8Impl_FreePrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid) {
115 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
116 HRESULT hr;
117 TRACE("(%p) Relay\n", This);
118
119 wined3d_mutex_lock();
120 hr = IWineD3DCubeTexture_FreePrivateData(This->wineD3DCubeTexture,refguid);
121 wined3d_mutex_unlock();
122
123 return hr;
124 }
125
126 static DWORD WINAPI IDirect3DCubeTexture8Impl_SetPriority(LPDIRECT3DCUBETEXTURE8 iface, DWORD PriorityNew) {
127 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
128 DWORD ret;
129 TRACE("(%p) Relay\n", This);
130
131 wined3d_mutex_lock();
132 ret = IWineD3DCubeTexture_SetPriority(This->wineD3DCubeTexture, PriorityNew);
133 wined3d_mutex_unlock();
134
135 return ret;
136 }
137
138 static DWORD WINAPI IDirect3DCubeTexture8Impl_GetPriority(LPDIRECT3DCUBETEXTURE8 iface) {
139 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
140 DWORD ret;
141 TRACE("(%p) Relay\n", This);
142
143 wined3d_mutex_lock();
144 ret = IWineD3DCubeTexture_GetPriority(This->wineD3DCubeTexture);
145 wined3d_mutex_unlock();
146
147 return ret;
148 }
149
150 static void WINAPI IDirect3DCubeTexture8Impl_PreLoad(LPDIRECT3DCUBETEXTURE8 iface) {
151 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
152 TRACE("(%p) Relay\n", This);
153
154 wined3d_mutex_lock();
155 IWineD3DCubeTexture_PreLoad(This->wineD3DCubeTexture);
156 wined3d_mutex_unlock();
157 }
158
159 static D3DRESOURCETYPE WINAPI IDirect3DCubeTexture8Impl_GetType(LPDIRECT3DCUBETEXTURE8 iface) {
160 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
161 D3DRESOURCETYPE type;
162 TRACE("(%p) Relay\n", This);
163
164 wined3d_mutex_lock();
165 type = IWineD3DCubeTexture_GetType(This->wineD3DCubeTexture);
166 wined3d_mutex_unlock();
167
168 return type;
169 }
170
171 /* IDirect3DCubeTexture8 IDirect3DBaseTexture8 Interface follow: */
172 static DWORD WINAPI IDirect3DCubeTexture8Impl_SetLOD(LPDIRECT3DCUBETEXTURE8 iface, DWORD LODNew) {
173 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
174 DWORD lod;
175 TRACE("(%p) Relay\n", This);
176
177 wined3d_mutex_lock();
178 lod = IWineD3DCubeTexture_SetLOD(This->wineD3DCubeTexture, LODNew);
179 wined3d_mutex_unlock();
180
181 return lod;
182 }
183
184 static DWORD WINAPI IDirect3DCubeTexture8Impl_GetLOD(LPDIRECT3DCUBETEXTURE8 iface) {
185 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
186 DWORD lod;
187 TRACE("(%p) Relay\n", This);
188
189 wined3d_mutex_lock();
190 lod = IWineD3DCubeTexture_GetLOD((LPDIRECT3DBASETEXTURE8) This);
191 wined3d_mutex_unlock();
192
193 return lod;
194 }
195
196 static DWORD WINAPI IDirect3DCubeTexture8Impl_GetLevelCount(LPDIRECT3DCUBETEXTURE8 iface) {
197 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
198 DWORD cnt;
199 TRACE("(%p) Relay\n", This);
200
201 wined3d_mutex_lock();
202 cnt = IWineD3DCubeTexture_GetLevelCount(This->wineD3DCubeTexture);
203 wined3d_mutex_unlock();
204
205 return cnt;
206 }
207
208 /* IDirect3DCubeTexture8 Interface follow: */
209 static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetLevelDesc(LPDIRECT3DCUBETEXTURE8 iface, UINT Level, D3DSURFACE_DESC *pDesc) {
210 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
211 HRESULT hr;
212 WINED3DSURFACE_DESC wined3ddesc;
213
214 TRACE("(%p) Relay\n", This);
215
216 wined3d_mutex_lock();
217 hr = IWineD3DCubeTexture_GetLevelDesc(This->wineD3DCubeTexture, Level, &wined3ddesc);
218 wined3d_mutex_unlock();
219
220 if (SUCCEEDED(hr))
221 {
222 pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.format);
223 pDesc->Type = wined3ddesc.resource_type;
224 pDesc->Usage = wined3ddesc.usage;
225 pDesc->Pool = wined3ddesc.pool;
226 pDesc->Size = wined3ddesc.size;
227 pDesc->MultiSampleType = wined3ddesc.multisample_type;
228 pDesc->Width = wined3ddesc.width;
229 pDesc->Height = wined3ddesc.height;
230 }
231
232 return hr;
233 }
234
235 static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetCubeMapSurface(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface8 **ppCubeMapSurface) {
236 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
237 HRESULT hrc = D3D_OK;
238 IWineD3DSurface *mySurface = NULL;
239
240 TRACE("(%p) Relay\n", This);
241
242 wined3d_mutex_lock();
243 hrc = IWineD3DCubeTexture_GetCubeMapSurface(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, &mySurface);
244 if (hrc == D3D_OK && NULL != ppCubeMapSurface) {
245 IWineD3DCubeTexture_GetParent(mySurface, (IUnknown **)ppCubeMapSurface);
246 IWineD3DCubeTexture_Release(mySurface);
247 }
248 wined3d_mutex_unlock();
249
250 return hrc;
251 }
252
253 static HRESULT WINAPI IDirect3DCubeTexture8Impl_LockRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT *pRect, DWORD Flags) {
254 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
255 HRESULT hr;
256 TRACE("(%p) Relay\n", This);
257
258 wined3d_mutex_lock();
259 hr = IWineD3DCubeTexture_LockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
260 wined3d_mutex_unlock();
261
262 return hr;
263 }
264
265 static HRESULT WINAPI IDirect3DCubeTexture8Impl_UnlockRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level) {
266 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
267 HRESULT hr;
268 TRACE("(%p) Relay\n", This);
269
270 wined3d_mutex_lock();
271 hr = IWineD3DCubeTexture_UnlockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level);
272 wined3d_mutex_unlock();
273
274 return hr;
275 }
276
277 static HRESULT WINAPI IDirect3DCubeTexture8Impl_AddDirtyRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, CONST RECT *pDirtyRect) {
278 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
279 HRESULT hr;
280 TRACE("(%p) Relay\n", This);
281
282 wined3d_mutex_lock();
283 hr = IWineD3DCubeTexture_AddDirtyRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, pDirtyRect);
284 wined3d_mutex_unlock();
285
286 return hr;
287 }
288
289
290 const IDirect3DCubeTexture8Vtbl Direct3DCubeTexture8_Vtbl =
291 {
292 /* IUnknown */
293 IDirect3DCubeTexture8Impl_QueryInterface,
294 IDirect3DCubeTexture8Impl_AddRef,
295 IDirect3DCubeTexture8Impl_Release,
296 /* IDirect3DResource8 */
297 IDirect3DCubeTexture8Impl_GetDevice,
298 IDirect3DCubeTexture8Impl_SetPrivateData,
299 IDirect3DCubeTexture8Impl_GetPrivateData,
300 IDirect3DCubeTexture8Impl_FreePrivateData,
301 IDirect3DCubeTexture8Impl_SetPriority,
302 IDirect3DCubeTexture8Impl_GetPriority,
303 IDirect3DCubeTexture8Impl_PreLoad,
304 IDirect3DCubeTexture8Impl_GetType,
305 /* IDirect3DBaseTexture8 */
306 IDirect3DCubeTexture8Impl_SetLOD,
307 IDirect3DCubeTexture8Impl_GetLOD,
308 IDirect3DCubeTexture8Impl_GetLevelCount,
309 /* IDirect3DCubeTexture8 */
310 IDirect3DCubeTexture8Impl_GetLevelDesc,
311 IDirect3DCubeTexture8Impl_GetCubeMapSurface,
312 IDirect3DCubeTexture8Impl_LockRect,
313 IDirect3DCubeTexture8Impl_UnlockRect,
314 IDirect3DCubeTexture8Impl_AddDirtyRect
315 };