Sync ddraw, d3d8 and d3d9 + wined3d to wine 1.1.28
[reactos.git] / reactos / dll / directx / wine / d3d8 / texture.c
1 /*
2 * IDirect3DTexture8 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 /* IDirect3DTexture8 IUnknown parts follow: */
27 static HRESULT WINAPI IDirect3DTexture8Impl_QueryInterface(LPDIRECT3DTEXTURE8 iface, REFIID riid, LPVOID *ppobj) {
28 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
29
30 if (IsEqualGUID(riid, &IID_IUnknown)
31 || IsEqualGUID(riid, &IID_IDirect3DResource8)
32 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
33 || IsEqualGUID(riid, &IID_IDirect3DTexture8)) {
34 IUnknown_AddRef(iface);
35 *ppobj = This;
36 return S_OK;
37 }
38
39 WARN("(%p)->(%s,%p) not found\n", This, debugstr_guid(riid), ppobj);
40 *ppobj = NULL;
41 return E_NOINTERFACE;
42 }
43
44 static ULONG WINAPI IDirect3DTexture8Impl_AddRef(LPDIRECT3DTEXTURE8 iface) {
45 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
46 ULONG ref = InterlockedIncrement(&This->ref);
47
48 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
49
50 return ref;
51 }
52
53 static ULONG WINAPI IDirect3DTexture8Impl_Release(LPDIRECT3DTEXTURE8 iface) {
54 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
55 ULONG ref = InterlockedDecrement(&This->ref);
56
57 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
58
59 if (ref == 0) {
60 wined3d_mutex_lock();
61 IWineD3DTexture_Destroy(This->wineD3DTexture, D3D8CB_DestroySurface);
62 wined3d_mutex_unlock();
63
64 IUnknown_Release(This->parentDevice);
65 HeapFree(GetProcessHeap(), 0, This);
66 }
67 return ref;
68 }
69
70 /* IDirect3DTexture8 IDirect3DResource8 Interface follow: */
71 static HRESULT WINAPI IDirect3DTexture8Impl_GetDevice(LPDIRECT3DTEXTURE8 iface, IDirect3DDevice8 **ppDevice) {
72 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
73 IWineD3DDevice *wined3d_device;
74 HRESULT hr;
75 TRACE("(%p) Relay\n", This);
76
77 wined3d_mutex_lock();
78 hr = IWineD3DTexture_GetDevice(This->wineD3DTexture, &wined3d_device);
79 if (SUCCEEDED(hr))
80 {
81 IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
82 IWineD3DDevice_Release(wined3d_device);
83 }
84 wined3d_mutex_unlock();
85
86 return hr;
87 }
88
89 static HRESULT WINAPI IDirect3DTexture8Impl_SetPrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
90 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
91 HRESULT hr;
92 TRACE("(%p) Relay\n", This);
93
94 wined3d_mutex_lock();
95 hr = IWineD3DTexture_SetPrivateData(This->wineD3DTexture, refguid, pData, SizeOfData, Flags);
96 wined3d_mutex_unlock();
97
98 return hr;
99 }
100
101 static HRESULT WINAPI IDirect3DTexture8Impl_GetPrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid, void *pData, DWORD* pSizeOfData) {
102 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
103 HRESULT hr;
104 TRACE("(%p) Relay\n", This);
105
106 wined3d_mutex_lock();
107 hr = IWineD3DTexture_GetPrivateData(This->wineD3DTexture, refguid, pData, pSizeOfData);
108 wined3d_mutex_unlock();
109
110 return hr;
111 }
112
113 static HRESULT WINAPI IDirect3DTexture8Impl_FreePrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid) {
114 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
115 HRESULT hr;
116 TRACE("(%p) Relay\n", This);
117
118 wined3d_mutex_lock();
119 hr = IWineD3DTexture_FreePrivateData(This->wineD3DTexture, refguid);
120 wined3d_mutex_unlock();
121
122 return hr;
123 }
124
125 static DWORD WINAPI IDirect3DTexture8Impl_SetPriority(LPDIRECT3DTEXTURE8 iface, DWORD PriorityNew) {
126 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
127 DWORD ret;
128 TRACE("(%p) Relay\n", This);
129
130 wined3d_mutex_lock();
131 ret = IWineD3DTexture_SetPriority(This->wineD3DTexture, PriorityNew);
132 wined3d_mutex_unlock();
133
134 return ret;
135 }
136
137 static DWORD WINAPI IDirect3DTexture8Impl_GetPriority(LPDIRECT3DTEXTURE8 iface) {
138 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
139 DWORD ret;
140 TRACE("(%p) Relay\n", This);
141
142 wined3d_mutex_lock();
143 ret = IWineD3DTexture_GetPriority(This->wineD3DTexture);
144 wined3d_mutex_unlock();
145
146 return ret;
147 }
148
149 static void WINAPI IDirect3DTexture8Impl_PreLoad(LPDIRECT3DTEXTURE8 iface) {
150 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
151 TRACE("(%p) Relay\n", This);
152
153 wined3d_mutex_lock();
154 IWineD3DTexture_PreLoad(This->wineD3DTexture);
155 wined3d_mutex_unlock();
156 }
157
158 static D3DRESOURCETYPE WINAPI IDirect3DTexture8Impl_GetType(LPDIRECT3DTEXTURE8 iface) {
159 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
160 D3DRESOURCETYPE type;
161 TRACE("(%p) Relay\n", This);
162
163 wined3d_mutex_lock();
164 type = IWineD3DTexture_GetType(This->wineD3DTexture);
165 wined3d_mutex_unlock();
166
167 return type;
168 }
169
170 /* IDirect3DTexture8 IDirect3DBaseTexture8 Interface follow: */
171 static DWORD WINAPI IDirect3DTexture8Impl_SetLOD(LPDIRECT3DTEXTURE8 iface, DWORD LODNew) {
172 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
173 DWORD ret;
174 TRACE("(%p) Relay\n", This);
175
176 wined3d_mutex_lock();
177 ret = IWineD3DTexture_SetLOD(This->wineD3DTexture, LODNew);
178 wined3d_mutex_unlock();
179
180 return ret;
181 }
182
183 static DWORD WINAPI IDirect3DTexture8Impl_GetLOD(LPDIRECT3DTEXTURE8 iface) {
184 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
185 DWORD ret;
186 TRACE("(%p) Relay\n", This);
187
188 wined3d_mutex_lock();
189 ret = IWineD3DTexture_GetLOD(This->wineD3DTexture);
190 wined3d_mutex_unlock();
191
192 return ret;
193 }
194
195 static DWORD WINAPI IDirect3DTexture8Impl_GetLevelCount(LPDIRECT3DTEXTURE8 iface) {
196 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
197 DWORD ret;
198 TRACE("(%p) Relay\n", This);
199
200 wined3d_mutex_lock();
201 ret = IWineD3DTexture_GetLevelCount(This->wineD3DTexture);
202 wined3d_mutex_unlock();
203
204 return ret;
205 }
206
207 /* IDirect3DTexture8 Interface follow: */
208 static HRESULT WINAPI IDirect3DTexture8Impl_GetLevelDesc(LPDIRECT3DTEXTURE8 iface, UINT Level, D3DSURFACE_DESC *pDesc) {
209 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
210 HRESULT hr;
211
212 WINED3DSURFACE_DESC wined3ddesc;
213 TRACE("(%p) Relay\n", This);
214
215 wined3d_mutex_lock();
216 hr = IWineD3DTexture_GetLevelDesc(This->wineD3DTexture, Level, &wined3ddesc);
217 wined3d_mutex_unlock();
218
219 if (SUCCEEDED(hr))
220 {
221 pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.format);
222 pDesc->Type = wined3ddesc.resource_type;
223 pDesc->Usage = wined3ddesc.usage;
224 pDesc->Pool = wined3ddesc.pool;
225 pDesc->Size = wined3ddesc.size;
226 pDesc->MultiSampleType = wined3ddesc.multisample_type;
227 pDesc->Width = wined3ddesc.width;
228 pDesc->Height = wined3ddesc.height;
229 }
230
231 return hr;
232 }
233
234 static HRESULT WINAPI IDirect3DTexture8Impl_GetSurfaceLevel(LPDIRECT3DTEXTURE8 iface, UINT Level, IDirect3DSurface8 **ppSurfaceLevel) {
235 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
236 HRESULT hrc = D3D_OK;
237 IWineD3DSurface *mySurface = NULL;
238
239 TRACE("(%p) Relay\n", This);
240
241 wined3d_mutex_lock();
242 hrc = IWineD3DTexture_GetSurfaceLevel(This->wineD3DTexture, Level, &mySurface);
243 if (hrc == D3D_OK && NULL != ppSurfaceLevel) {
244 IWineD3DSurface_GetParent(mySurface, (IUnknown **)ppSurfaceLevel);
245 IWineD3DSurface_Release(mySurface);
246 }
247 wined3d_mutex_unlock();
248
249 return hrc;
250 }
251
252 static HRESULT WINAPI IDirect3DTexture8Impl_LockRect(LPDIRECT3DTEXTURE8 iface, UINT Level, D3DLOCKED_RECT *pLockedRect, CONST RECT *pRect, DWORD Flags) {
253 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
254 HRESULT hr;
255 TRACE("(%p) Relay\n", This);
256
257 wined3d_mutex_lock();
258 hr = IWineD3DTexture_LockRect(This->wineD3DTexture, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
259 wined3d_mutex_unlock();
260
261 return hr;
262 }
263
264 static HRESULT WINAPI IDirect3DTexture8Impl_UnlockRect(LPDIRECT3DTEXTURE8 iface, UINT Level) {
265 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
266 HRESULT hr;
267 TRACE("(%p) Relay\n", This);
268
269 wined3d_mutex_lock();
270 hr = IWineD3DTexture_UnlockRect(This->wineD3DTexture, Level);
271 wined3d_mutex_unlock();
272
273 return hr;
274 }
275
276 static HRESULT WINAPI IDirect3DTexture8Impl_AddDirtyRect(LPDIRECT3DTEXTURE8 iface, CONST RECT *pDirtyRect) {
277 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
278 HRESULT hr;
279 TRACE("(%p) Relay\n", This);
280
281 wined3d_mutex_lock();
282 hr = IWineD3DTexture_AddDirtyRect(This->wineD3DTexture, pDirtyRect);
283 wined3d_mutex_unlock();
284
285 return hr;
286 }
287
288 const IDirect3DTexture8Vtbl Direct3DTexture8_Vtbl =
289 {
290 /* IUnknown */
291 IDirect3DTexture8Impl_QueryInterface,
292 IDirect3DTexture8Impl_AddRef,
293 IDirect3DTexture8Impl_Release,
294 /* IDirect3DResource8 */
295 IDirect3DTexture8Impl_GetDevice,
296 IDirect3DTexture8Impl_SetPrivateData,
297 IDirect3DTexture8Impl_GetPrivateData,
298 IDirect3DTexture8Impl_FreePrivateData,
299 IDirect3DTexture8Impl_SetPriority,
300 IDirect3DTexture8Impl_GetPriority,
301 IDirect3DTexture8Impl_PreLoad,
302 IDirect3DTexture8Impl_GetType,
303 /* IDirect3dBaseTexture8 */
304 IDirect3DTexture8Impl_SetLOD,
305 IDirect3DTexture8Impl_GetLOD,
306 IDirect3DTexture8Impl_GetLevelCount,
307 /* IDirect3DTexture8 */
308 IDirect3DTexture8Impl_GetLevelDesc,
309 IDirect3DTexture8Impl_GetSurfaceLevel,
310 IDirect3DTexture8Impl_LockRect,
311 IDirect3DTexture8Impl_UnlockRect,
312 IDirect3DTexture8Impl_AddDirtyRect
313 };