Release 1.3.7.
[wine/gsoc-2012-control.git] / dlls / d3d9 / texture.c
blob74ac2f8d1786fbfa9f037913a05ed1eb0803bc79
1 /*
2 * IDirect3DTexture9 implementation
4 * Copyright 2002-2005 Jason Edmeades
5 * Copyright 2002-2005 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
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.
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.
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
23 #include "config.h"
24 #include "d3d9_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
28 /* IDirect3DTexture9 IUnknown parts follow: */
29 static HRESULT WINAPI IDirect3DTexture9Impl_QueryInterface(LPDIRECT3DTEXTURE9 iface, REFIID riid, LPVOID* ppobj) {
30 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
32 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
34 if (IsEqualGUID(riid, &IID_IUnknown)
35 || IsEqualGUID(riid, &IID_IDirect3DResource9)
36 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
37 || IsEqualGUID(riid, &IID_IDirect3DTexture9)) {
38 IDirect3DTexture9_AddRef(iface);
39 *ppobj = This;
40 return S_OK;
43 WARN("(%p)->(%s,%p) not found\n", This, debugstr_guid(riid), ppobj);
44 *ppobj = NULL;
45 return E_NOINTERFACE;
48 static ULONG WINAPI IDirect3DTexture9Impl_AddRef(LPDIRECT3DTEXTURE9 iface) {
49 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
50 ULONG ref = InterlockedIncrement(&This->ref);
52 TRACE("%p increasing refcount to %u.\n", iface, ref);
54 if (ref == 1)
56 IDirect3DDevice9Ex_AddRef(This->parentDevice);
57 wined3d_mutex_lock();
58 IWineD3DTexture_AddRef(This->wineD3DTexture);
59 wined3d_mutex_unlock();
62 return ref;
65 static ULONG WINAPI IDirect3DTexture9Impl_Release(LPDIRECT3DTEXTURE9 iface) {
66 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
67 ULONG ref = InterlockedDecrement(&This->ref);
69 TRACE("%p decreasing refcount to %u.\n", iface, ref);
71 if (ref == 0) {
72 IDirect3DDevice9Ex *parentDevice = This->parentDevice;
74 wined3d_mutex_lock();
75 IWineD3DTexture_Release(This->wineD3DTexture);
76 wined3d_mutex_unlock();
78 /* Release the device last, as it may cause the device to be destroyed. */
79 IDirect3DDevice9Ex_Release(parentDevice);
81 return ref;
84 /* IDirect3DTexture9 IDirect3DResource9 Interface follow: */
85 static HRESULT WINAPI IDirect3DTexture9Impl_GetDevice(IDirect3DTexture9 *iface, IDirect3DDevice9 **device)
87 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
89 TRACE("iface %p, device %p.\n", iface, device);
91 *device = (IDirect3DDevice9 *)This->parentDevice;
92 IDirect3DDevice9_AddRef(*device);
94 TRACE("Returning device %p.\n", *device);
96 return D3D_OK;
99 static HRESULT WINAPI IDirect3DTexture9Impl_SetPrivateData(LPDIRECT3DTEXTURE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
100 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
101 HRESULT hr;
103 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
104 iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
106 wined3d_mutex_lock();
107 hr = IWineD3DTexture_SetPrivateData(This->wineD3DTexture, refguid, pData, SizeOfData, Flags);
108 wined3d_mutex_unlock();
110 return hr;
113 static HRESULT WINAPI IDirect3DTexture9Impl_GetPrivateData(LPDIRECT3DTEXTURE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
114 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
115 HRESULT hr;
117 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
118 iface, debugstr_guid(refguid), pData, pSizeOfData);
120 wined3d_mutex_lock();
121 hr = IWineD3DTexture_GetPrivateData(This->wineD3DTexture, refguid, pData, pSizeOfData);
122 wined3d_mutex_unlock();
124 return hr;
127 static HRESULT WINAPI IDirect3DTexture9Impl_FreePrivateData(LPDIRECT3DTEXTURE9 iface, REFGUID refguid) {
128 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
129 HRESULT hr;
131 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
133 wined3d_mutex_lock();
134 hr = IWineD3DTexture_FreePrivateData(This->wineD3DTexture, refguid);
135 wined3d_mutex_unlock();
137 return hr;
140 static DWORD WINAPI IDirect3DTexture9Impl_SetPriority(LPDIRECT3DTEXTURE9 iface, DWORD PriorityNew) {
141 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
142 DWORD ret;
144 TRACE("iface %p, priority %u.\n", iface, PriorityNew);
146 wined3d_mutex_lock();
147 ret = IWineD3DTexture_SetPriority(This->wineD3DTexture, PriorityNew);
148 wined3d_mutex_unlock();
150 return ret;
153 static DWORD WINAPI IDirect3DTexture9Impl_GetPriority(LPDIRECT3DTEXTURE9 iface) {
154 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
155 DWORD ret;
157 TRACE("iface %p.\n", iface);
159 wined3d_mutex_lock();
160 ret = IWineD3DTexture_GetPriority(This->wineD3DTexture);
161 wined3d_mutex_unlock();
163 return ret;
166 static void WINAPI IDirect3DTexture9Impl_PreLoad(LPDIRECT3DTEXTURE9 iface) {
167 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
169 TRACE("iface %p.\n", iface);
171 wined3d_mutex_lock();
172 IWineD3DTexture_PreLoad(This->wineD3DTexture);
173 wined3d_mutex_unlock();
176 static D3DRESOURCETYPE WINAPI IDirect3DTexture9Impl_GetType(LPDIRECT3DTEXTURE9 iface) {
177 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
178 HRESULT ret;
180 TRACE("iface %p.\n", iface);
182 wined3d_mutex_lock();
183 ret = IWineD3DTexture_GetType(This->wineD3DTexture);
184 wined3d_mutex_unlock();
186 return ret;
189 /* IDirect3DTexture9 IDirect3DBaseTexture9 Interface follow: */
190 static DWORD WINAPI IDirect3DTexture9Impl_SetLOD(LPDIRECT3DTEXTURE9 iface, DWORD LODNew) {
191 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
192 DWORD ret;
194 TRACE("iface %p, lod %u.\n", iface, LODNew);
196 wined3d_mutex_lock();
197 ret = IWineD3DTexture_SetLOD(This->wineD3DTexture, LODNew);
198 wined3d_mutex_unlock();
200 return ret;
203 static DWORD WINAPI IDirect3DTexture9Impl_GetLOD(LPDIRECT3DTEXTURE9 iface) {
204 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
205 DWORD ret;
207 TRACE("iface %p.\n", iface);
209 wined3d_mutex_lock();
210 ret = IWineD3DTexture_GetLOD(This->wineD3DTexture);
211 wined3d_mutex_unlock();
213 return ret;
216 static DWORD WINAPI IDirect3DTexture9Impl_GetLevelCount(LPDIRECT3DTEXTURE9 iface) {
217 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
218 DWORD ret;
220 TRACE("iface %p.\n", iface);
222 wined3d_mutex_lock();
223 ret = IWineD3DTexture_GetLevelCount(This->wineD3DTexture);
224 wined3d_mutex_unlock();
226 return ret;
229 static HRESULT WINAPI IDirect3DTexture9Impl_SetAutoGenFilterType(LPDIRECT3DTEXTURE9 iface, D3DTEXTUREFILTERTYPE FilterType) {
230 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
231 HRESULT hr;
233 TRACE("iface %p, filter_type %#x.\n", iface, FilterType);
235 wined3d_mutex_lock();
236 hr = IWineD3DTexture_SetAutoGenFilterType(This->wineD3DTexture, (WINED3DTEXTUREFILTERTYPE) FilterType);
237 wined3d_mutex_unlock();
239 return hr;
242 static D3DTEXTUREFILTERTYPE WINAPI IDirect3DTexture9Impl_GetAutoGenFilterType(LPDIRECT3DTEXTURE9 iface) {
243 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
244 D3DTEXTUREFILTERTYPE ret;
246 TRACE("iface %p.\n", iface);
248 wined3d_mutex_lock();
249 ret = (D3DTEXTUREFILTERTYPE) IWineD3DTexture_GetAutoGenFilterType(This->wineD3DTexture);
250 wined3d_mutex_unlock();
252 return ret;
255 static void WINAPI IDirect3DTexture9Impl_GenerateMipSubLevels(LPDIRECT3DTEXTURE9 iface) {
256 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
258 TRACE("iface %p.\n", iface);
260 wined3d_mutex_lock();
261 IWineD3DTexture_GenerateMipSubLevels(This->wineD3DTexture);
262 wined3d_mutex_unlock();
265 /* IDirect3DTexture9 Interface follow: */
266 static HRESULT WINAPI IDirect3DTexture9Impl_GetLevelDesc(LPDIRECT3DTEXTURE9 iface, UINT Level, D3DSURFACE_DESC* pDesc) {
267 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
268 WINED3DSURFACE_DESC wined3ddesc;
269 HRESULT hr;
271 TRACE("iface %p, level %u, desc %p.\n", iface, Level, pDesc);
273 wined3d_mutex_lock();
274 hr = IWineD3DTexture_GetLevelDesc(This->wineD3DTexture, Level, &wined3ddesc);
275 wined3d_mutex_unlock();
277 if (SUCCEEDED(hr))
279 pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.format);
280 pDesc->Type = wined3ddesc.resource_type;
281 pDesc->Usage = wined3ddesc.usage;
282 pDesc->Pool = wined3ddesc.pool;
283 pDesc->MultiSampleType = wined3ddesc.multisample_type;
284 pDesc->MultiSampleQuality = wined3ddesc.multisample_quality;
285 pDesc->Width = wined3ddesc.width;
286 pDesc->Height = wined3ddesc.height;
289 return hr;
292 static HRESULT WINAPI IDirect3DTexture9Impl_GetSurfaceLevel(IDirect3DTexture9 *iface,
293 UINT Level, IDirect3DSurface9 **ppSurfaceLevel)
295 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
296 IWineD3DSurface *mySurface = NULL;
297 HRESULT hr;
299 TRACE("iface %p, level %u, surface %p.\n", iface, Level, ppSurfaceLevel);
301 wined3d_mutex_lock();
302 hr = IWineD3DTexture_GetSurfaceLevel(This->wineD3DTexture, Level, &mySurface);
303 if (SUCCEEDED(hr) && ppSurfaceLevel)
305 *ppSurfaceLevel = IWineD3DSurface_GetParent(mySurface);
306 IDirect3DSurface9_AddRef(*ppSurfaceLevel);
307 IWineD3DSurface_Release(mySurface);
309 wined3d_mutex_unlock();
311 return hr;
314 static HRESULT WINAPI IDirect3DTexture9Impl_LockRect(LPDIRECT3DTEXTURE9 iface, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
315 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
316 HRESULT hr;
318 TRACE("iface %p, level %u, locked_rect %p, rect %p, flags %#x.\n",
319 iface, Level, pLockedRect, pRect, Flags);
321 wined3d_mutex_lock();
322 hr = IWineD3DTexture_Map(This->wineD3DTexture, Level, (WINED3DLOCKED_RECT *)pLockedRect, pRect, Flags);
323 wined3d_mutex_unlock();
325 return hr;
328 static HRESULT WINAPI IDirect3DTexture9Impl_UnlockRect(LPDIRECT3DTEXTURE9 iface, UINT Level) {
329 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
330 HRESULT hr;
332 TRACE("iface %p, level %u.\n", iface, Level);
334 wined3d_mutex_lock();
335 hr = IWineD3DTexture_Unmap(This->wineD3DTexture, Level);
336 wined3d_mutex_unlock();
338 return hr;
341 static HRESULT WINAPI IDirect3DTexture9Impl_AddDirtyRect(LPDIRECT3DTEXTURE9 iface, CONST RECT* pDirtyRect) {
342 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
343 HRESULT hr;
345 TRACE("iface %p, dirty_rect %p.\n", iface, pDirtyRect);
347 wined3d_mutex_lock();
348 hr = IWineD3DTexture_AddDirtyRect(This->wineD3DTexture, pDirtyRect);
349 wined3d_mutex_unlock();
351 return hr;
354 static const IDirect3DTexture9Vtbl Direct3DTexture9_Vtbl =
356 /* IUnknown */
357 IDirect3DTexture9Impl_QueryInterface,
358 IDirect3DTexture9Impl_AddRef,
359 IDirect3DTexture9Impl_Release,
360 /* IDirect3DResource9 */
361 IDirect3DTexture9Impl_GetDevice,
362 IDirect3DTexture9Impl_SetPrivateData,
363 IDirect3DTexture9Impl_GetPrivateData,
364 IDirect3DTexture9Impl_FreePrivateData,
365 IDirect3DTexture9Impl_SetPriority,
366 IDirect3DTexture9Impl_GetPriority,
367 IDirect3DTexture9Impl_PreLoad,
368 IDirect3DTexture9Impl_GetType,
369 /* IDirect3dBaseTexture9 */
370 IDirect3DTexture9Impl_SetLOD,
371 IDirect3DTexture9Impl_GetLOD,
372 IDirect3DTexture9Impl_GetLevelCount,
373 IDirect3DTexture9Impl_SetAutoGenFilterType,
374 IDirect3DTexture9Impl_GetAutoGenFilterType,
375 IDirect3DTexture9Impl_GenerateMipSubLevels,
376 /* IDirect3DTexture9 */
377 IDirect3DTexture9Impl_GetLevelDesc,
378 IDirect3DTexture9Impl_GetSurfaceLevel,
379 IDirect3DTexture9Impl_LockRect,
380 IDirect3DTexture9Impl_UnlockRect,
381 IDirect3DTexture9Impl_AddDirtyRect
384 static void STDMETHODCALLTYPE d3d9_texture_wined3d_object_destroyed(void *parent)
386 HeapFree(GetProcessHeap(), 0, parent);
389 static const struct wined3d_parent_ops d3d9_texture_wined3d_parent_ops =
391 d3d9_texture_wined3d_object_destroyed,
394 HRESULT texture_init(IDirect3DTexture9Impl *texture, IDirect3DDevice9Impl *device,
395 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
397 HRESULT hr;
399 texture->lpVtbl = &Direct3DTexture9_Vtbl;
400 texture->ref = 1;
402 wined3d_mutex_lock();
403 hr = IWineD3DDevice_CreateTexture(device->WineD3DDevice, width, height, levels,
404 usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool,
405 texture, &d3d9_texture_wined3d_parent_ops, &texture->wineD3DTexture);
406 wined3d_mutex_unlock();
407 if (FAILED(hr))
409 WARN("Failed to create wined3d texture, hr %#x.\n", hr);
410 return hr;
413 texture->parentDevice = (IDirect3DDevice9Ex *)device;
414 IDirect3DDevice9Ex_AddRef(texture->parentDevice);
416 return D3D_OK;