- Merge from trunk up to r45543
[reactos.git] / 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
30 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
31
32 if (IsEqualGUID(riid, &IID_IUnknown)
33 || IsEqualGUID(riid, &IID_IDirect3DResource8)
34 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
35 || IsEqualGUID(riid, &IID_IDirect3DCubeTexture8)) {
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 IDirect3DCubeTexture8Impl_AddRef(LPDIRECT3DCUBETEXTURE8 iface) {
47 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
48 ULONG ref = InterlockedIncrement(&This->ref);
49
50 TRACE("%p increasing refcount to %u.\n", iface, ref);
51
52 if (ref == 1)
53 {
54 IUnknown_AddRef(This->parentDevice);
55 wined3d_mutex_lock();
56 IWineD3DCubeTexture_AddRef(This->wineD3DCubeTexture);
57 wined3d_mutex_unlock();
58 }
59
60 return ref;
61 }
62
63 static ULONG WINAPI IDirect3DCubeTexture8Impl_Release(LPDIRECT3DCUBETEXTURE8 iface) {
64 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
65 ULONG ref = InterlockedDecrement(&This->ref);
66
67 TRACE("%p decreasing refcount to %u.\n", iface, ref);
68
69 if (ref == 0) {
70 IDirect3DDevice8 *parentDevice = This->parentDevice;
71
72 TRACE("Releasing child %p\n", This->wineD3DCubeTexture);
73
74 wined3d_mutex_lock();
75 IWineD3DCubeTexture_Release(This->wineD3DCubeTexture);
76 wined3d_mutex_unlock();
77
78 /* Release the device last, as it may cause the device to be destroyed. */
79 IDirect3DDevice8_Release(parentDevice);
80 }
81 return ref;
82 }
83
84 /* IDirect3DCubeTexture8 IDirect3DResource8 Interface follow: */
85 static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetDevice(IDirect3DCubeTexture8 *iface, IDirect3DDevice8 **device)
86 {
87 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
88
89 TRACE("iface %p, device %p.\n", iface, device);
90
91 *device = (IDirect3DDevice8 *)This->parentDevice;
92 IDirect3DDevice8_AddRef(*device);
93
94 TRACE("Returning device %p.\n", *device);
95
96 return D3D_OK;
97 }
98
99 static HRESULT WINAPI IDirect3DCubeTexture8Impl_SetPrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
100 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
101 HRESULT hr;
102
103 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
104 iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
105
106 wined3d_mutex_lock();
107 hr = IWineD3DCubeTexture_SetPrivateData(This->wineD3DCubeTexture,refguid,pData,SizeOfData,Flags);
108 wined3d_mutex_unlock();
109
110 return hr;
111 }
112
113 static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetPrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
114 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
115 HRESULT hr;
116
117 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
118 iface, debugstr_guid(refguid), pData, pSizeOfData);
119
120 wined3d_mutex_lock();
121 hr = IWineD3DCubeTexture_GetPrivateData(This->wineD3DCubeTexture,refguid,pData,pSizeOfData);
122 wined3d_mutex_unlock();
123
124 return hr;
125 }
126
127 static HRESULT WINAPI IDirect3DCubeTexture8Impl_FreePrivateData(LPDIRECT3DCUBETEXTURE8 iface, REFGUID refguid) {
128 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
129 HRESULT hr;
130
131 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
132
133 wined3d_mutex_lock();
134 hr = IWineD3DCubeTexture_FreePrivateData(This->wineD3DCubeTexture,refguid);
135 wined3d_mutex_unlock();
136
137 return hr;
138 }
139
140 static DWORD WINAPI IDirect3DCubeTexture8Impl_SetPriority(LPDIRECT3DCUBETEXTURE8 iface, DWORD PriorityNew) {
141 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
142 DWORD ret;
143
144 TRACE("iface %p, priority %u.\n", iface, PriorityNew);
145
146 wined3d_mutex_lock();
147 ret = IWineD3DCubeTexture_SetPriority(This->wineD3DCubeTexture, PriorityNew);
148 wined3d_mutex_unlock();
149
150 return ret;
151 }
152
153 static DWORD WINAPI IDirect3DCubeTexture8Impl_GetPriority(LPDIRECT3DCUBETEXTURE8 iface) {
154 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
155 DWORD ret;
156
157 TRACE("iface %p.\n", iface);
158
159 wined3d_mutex_lock();
160 ret = IWineD3DCubeTexture_GetPriority(This->wineD3DCubeTexture);
161 wined3d_mutex_unlock();
162
163 return ret;
164 }
165
166 static void WINAPI IDirect3DCubeTexture8Impl_PreLoad(LPDIRECT3DCUBETEXTURE8 iface) {
167 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
168
169 TRACE("iface %p.\n", iface);
170
171 wined3d_mutex_lock();
172 IWineD3DCubeTexture_PreLoad(This->wineD3DCubeTexture);
173 wined3d_mutex_unlock();
174 }
175
176 static D3DRESOURCETYPE WINAPI IDirect3DCubeTexture8Impl_GetType(LPDIRECT3DCUBETEXTURE8 iface) {
177 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
178 D3DRESOURCETYPE type;
179
180 TRACE("iface %p.\n", iface);
181
182 wined3d_mutex_lock();
183 type = IWineD3DCubeTexture_GetType(This->wineD3DCubeTexture);
184 wined3d_mutex_unlock();
185
186 return type;
187 }
188
189 /* IDirect3DCubeTexture8 IDirect3DBaseTexture8 Interface follow: */
190 static DWORD WINAPI IDirect3DCubeTexture8Impl_SetLOD(LPDIRECT3DCUBETEXTURE8 iface, DWORD LODNew) {
191 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
192 DWORD lod;
193
194 TRACE("iface %p, lod %u.\n", iface, LODNew);
195
196 wined3d_mutex_lock();
197 lod = IWineD3DCubeTexture_SetLOD(This->wineD3DCubeTexture, LODNew);
198 wined3d_mutex_unlock();
199
200 return lod;
201 }
202
203 static DWORD WINAPI IDirect3DCubeTexture8Impl_GetLOD(LPDIRECT3DCUBETEXTURE8 iface) {
204 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
205 DWORD lod;
206
207 TRACE("iface %p.\n", iface);
208
209 wined3d_mutex_lock();
210 lod = IWineD3DCubeTexture_GetLOD((LPDIRECT3DBASETEXTURE8) This);
211 wined3d_mutex_unlock();
212
213 return lod;
214 }
215
216 static DWORD WINAPI IDirect3DCubeTexture8Impl_GetLevelCount(LPDIRECT3DCUBETEXTURE8 iface) {
217 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
218 DWORD cnt;
219
220 TRACE("iface %p.\n", iface);
221
222 wined3d_mutex_lock();
223 cnt = IWineD3DCubeTexture_GetLevelCount(This->wineD3DCubeTexture);
224 wined3d_mutex_unlock();
225
226 return cnt;
227 }
228
229 /* IDirect3DCubeTexture8 Interface follow: */
230 static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetLevelDesc(LPDIRECT3DCUBETEXTURE8 iface, UINT Level, D3DSURFACE_DESC *pDesc) {
231 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
232 HRESULT hr;
233 WINED3DSURFACE_DESC wined3ddesc;
234
235 TRACE("iface %p, level %u, desc %p.\n", iface, Level, pDesc);
236
237 wined3d_mutex_lock();
238 hr = IWineD3DCubeTexture_GetLevelDesc(This->wineD3DCubeTexture, Level, &wined3ddesc);
239 wined3d_mutex_unlock();
240
241 if (SUCCEEDED(hr))
242 {
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->Size = wined3ddesc.size;
248 pDesc->MultiSampleType = wined3ddesc.multisample_type;
249 pDesc->Width = wined3ddesc.width;
250 pDesc->Height = wined3ddesc.height;
251 }
252
253 return hr;
254 }
255
256 static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetCubeMapSurface(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface8 **ppCubeMapSurface) {
257 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
258 HRESULT hrc = D3D_OK;
259 IWineD3DSurface *mySurface = NULL;
260
261 TRACE("iface %p, face %#x, level %u, surface %p.\n", iface, FaceType, Level, ppCubeMapSurface);
262
263 wined3d_mutex_lock();
264 hrc = IWineD3DCubeTexture_GetCubeMapSurface(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, &mySurface);
265 if (hrc == D3D_OK && NULL != ppCubeMapSurface) {
266 IWineD3DCubeTexture_GetParent(mySurface, (IUnknown **)ppCubeMapSurface);
267 IWineD3DCubeTexture_Release(mySurface);
268 }
269 wined3d_mutex_unlock();
270
271 return hrc;
272 }
273
274 static HRESULT WINAPI IDirect3DCubeTexture8Impl_LockRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT *pRect, DWORD Flags) {
275 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
276 HRESULT hr;
277
278 TRACE("iface %p, face %#x, level %u, locked_rect %p, rect %p, flags %#x.\n",
279 iface, FaceType, Level, pLockedRect, pRect, Flags);
280
281 wined3d_mutex_lock();
282 hr = IWineD3DCubeTexture_LockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
283 wined3d_mutex_unlock();
284
285 return hr;
286 }
287
288 static HRESULT WINAPI IDirect3DCubeTexture8Impl_UnlockRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level) {
289 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
290 HRESULT hr;
291
292 TRACE("iface %p, face %#x, level %u.\n", iface, FaceType, Level);
293
294 wined3d_mutex_lock();
295 hr = IWineD3DCubeTexture_UnlockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level);
296 wined3d_mutex_unlock();
297
298 return hr;
299 }
300
301 static HRESULT WINAPI IDirect3DCubeTexture8Impl_AddDirtyRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, CONST RECT *pDirtyRect) {
302 IDirect3DCubeTexture8Impl *This = (IDirect3DCubeTexture8Impl *)iface;
303 HRESULT hr;
304
305 TRACE("iface %p, face %#x, dirty_rect %p.\n", iface, FaceType, pDirtyRect);
306
307 wined3d_mutex_lock();
308 hr = IWineD3DCubeTexture_AddDirtyRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, pDirtyRect);
309 wined3d_mutex_unlock();
310
311 return hr;
312 }
313
314 static const IDirect3DCubeTexture8Vtbl Direct3DCubeTexture8_Vtbl =
315 {
316 /* IUnknown */
317 IDirect3DCubeTexture8Impl_QueryInterface,
318 IDirect3DCubeTexture8Impl_AddRef,
319 IDirect3DCubeTexture8Impl_Release,
320 /* IDirect3DResource8 */
321 IDirect3DCubeTexture8Impl_GetDevice,
322 IDirect3DCubeTexture8Impl_SetPrivateData,
323 IDirect3DCubeTexture8Impl_GetPrivateData,
324 IDirect3DCubeTexture8Impl_FreePrivateData,
325 IDirect3DCubeTexture8Impl_SetPriority,
326 IDirect3DCubeTexture8Impl_GetPriority,
327 IDirect3DCubeTexture8Impl_PreLoad,
328 IDirect3DCubeTexture8Impl_GetType,
329 /* IDirect3DBaseTexture8 */
330 IDirect3DCubeTexture8Impl_SetLOD,
331 IDirect3DCubeTexture8Impl_GetLOD,
332 IDirect3DCubeTexture8Impl_GetLevelCount,
333 /* IDirect3DCubeTexture8 */
334 IDirect3DCubeTexture8Impl_GetLevelDesc,
335 IDirect3DCubeTexture8Impl_GetCubeMapSurface,
336 IDirect3DCubeTexture8Impl_LockRect,
337 IDirect3DCubeTexture8Impl_UnlockRect,
338 IDirect3DCubeTexture8Impl_AddDirtyRect
339 };
340
341 static void STDMETHODCALLTYPE d3d8_cubetexture_wined3d_object_destroyed(void *parent)
342 {
343 HeapFree(GetProcessHeap(), 0, parent);
344 }
345
346 static const struct wined3d_parent_ops d3d8_cubetexture_wined3d_parent_ops =
347 {
348 d3d8_cubetexture_wined3d_object_destroyed,
349 };
350
351 HRESULT cubetexture_init(IDirect3DCubeTexture8Impl *texture, IDirect3DDevice8Impl *device,
352 UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
353 {
354 HRESULT hr;
355
356 texture->lpVtbl = &Direct3DCubeTexture8_Vtbl;
357 texture->ref = 1;
358
359 wined3d_mutex_lock();
360 hr = IWineD3DDevice_CreateCubeTexture(device->WineD3DDevice, edge_length, levels, usage & WINED3DUSAGE_MASK,
361 wined3dformat_from_d3dformat(format), pool, &texture->wineD3DCubeTexture,
362 (IUnknown *)texture, &d3d8_cubetexture_wined3d_parent_ops);
363 wined3d_mutex_unlock();
364 if (FAILED(hr))
365 {
366 WARN("Failed to create wined3d cube texture, hr %#x.\n", hr);
367 return hr;
368 }
369
370 texture->parentDevice = (IDirect3DDevice8 *)device;
371 IDirect3DDevice8_AddRef(texture->parentDevice);
372
373 return D3D_OK;
374 }