Release 1.3.7.
[wine/gsoc-2012-control.git] / dlls / d3d8 / texture.c
blobb4f3258373c69f03f1dab52f800d2efb54ebe16a
1 /*
2 * IDirect3DTexture8 implementation
4 * Copyright 2005 Oliver Stieber
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.
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.
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
21 #include "config.h"
22 #include "d3d8_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
26 /* IDirect3DTexture8 IUnknown parts follow: */
27 static HRESULT WINAPI IDirect3DTexture8Impl_QueryInterface(LPDIRECT3DTEXTURE8 iface, REFIID riid, LPVOID *ppobj) {
28 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
30 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
32 if (IsEqualGUID(riid, &IID_IUnknown)
33 || IsEqualGUID(riid, &IID_IDirect3DResource8)
34 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture8)
35 || IsEqualGUID(riid, &IID_IDirect3DTexture8)) {
36 IUnknown_AddRef(iface);
37 *ppobj = This;
38 return S_OK;
41 WARN("(%p)->(%s,%p) not found\n", This, debugstr_guid(riid), ppobj);
42 *ppobj = NULL;
43 return E_NOINTERFACE;
46 static ULONG WINAPI IDirect3DTexture8Impl_AddRef(LPDIRECT3DTEXTURE8 iface) {
47 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
48 ULONG ref = InterlockedIncrement(&This->ref);
50 TRACE("%p increasing refcount to %u.\n", iface, ref);
52 if (ref == 1)
54 IDirect3DDevice8_AddRef(This->parentDevice);
55 wined3d_mutex_lock();
56 IWineD3DTexture_AddRef(This->wineD3DTexture);
57 wined3d_mutex_unlock();
60 return ref;
63 static ULONG WINAPI IDirect3DTexture8Impl_Release(LPDIRECT3DTEXTURE8 iface) {
64 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
65 ULONG ref = InterlockedDecrement(&This->ref);
67 TRACE("%p decreasing refcount to %u.\n", iface, ref);
69 if (ref == 0) {
70 IDirect3DDevice8 *parentDevice = This->parentDevice;
72 wined3d_mutex_lock();
73 IWineD3DTexture_Release(This->wineD3DTexture);
74 wined3d_mutex_unlock();
76 /* Release the device last, as it may cause the device to be destroyed. */
77 IDirect3DDevice8_Release(parentDevice);
79 return ref;
82 /* IDirect3DTexture8 IDirect3DResource8 Interface follow: */
83 static HRESULT WINAPI IDirect3DTexture8Impl_GetDevice(IDirect3DTexture8 *iface, IDirect3DDevice8 **device)
85 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
87 TRACE("iface %p, device %p.\n", iface, device);
89 *device = (IDirect3DDevice8 *)This->parentDevice;
90 IDirect3DDevice8_AddRef(*device);
92 TRACE("Returning device %p.\n", *device);
94 return D3D_OK;
97 static HRESULT WINAPI IDirect3DTexture8Impl_SetPrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
98 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
99 HRESULT hr;
101 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
102 iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
104 wined3d_mutex_lock();
105 hr = IWineD3DTexture_SetPrivateData(This->wineD3DTexture, refguid, pData, SizeOfData, Flags);
106 wined3d_mutex_unlock();
108 return hr;
111 static HRESULT WINAPI IDirect3DTexture8Impl_GetPrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid, void *pData, DWORD* pSizeOfData) {
112 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
113 HRESULT hr;
115 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
116 iface, debugstr_guid(refguid), pData, pSizeOfData);
118 wined3d_mutex_lock();
119 hr = IWineD3DTexture_GetPrivateData(This->wineD3DTexture, refguid, pData, pSizeOfData);
120 wined3d_mutex_unlock();
122 return hr;
125 static HRESULT WINAPI IDirect3DTexture8Impl_FreePrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid) {
126 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
127 HRESULT hr;
129 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
131 wined3d_mutex_lock();
132 hr = IWineD3DTexture_FreePrivateData(This->wineD3DTexture, refguid);
133 wined3d_mutex_unlock();
135 return hr;
138 static DWORD WINAPI IDirect3DTexture8Impl_SetPriority(LPDIRECT3DTEXTURE8 iface, DWORD PriorityNew) {
139 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
140 DWORD ret;
142 TRACE("iface %p, priority %u.\n", iface, PriorityNew);
144 wined3d_mutex_lock();
145 ret = IWineD3DTexture_SetPriority(This->wineD3DTexture, PriorityNew);
146 wined3d_mutex_unlock();
148 return ret;
151 static DWORD WINAPI IDirect3DTexture8Impl_GetPriority(LPDIRECT3DTEXTURE8 iface) {
152 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
153 DWORD ret;
155 TRACE("iface %p.\n", iface);
157 wined3d_mutex_lock();
158 ret = IWineD3DTexture_GetPriority(This->wineD3DTexture);
159 wined3d_mutex_unlock();
161 return ret;
164 static void WINAPI IDirect3DTexture8Impl_PreLoad(LPDIRECT3DTEXTURE8 iface) {
165 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
167 TRACE("iface %p.\n", iface);
169 wined3d_mutex_lock();
170 IWineD3DTexture_PreLoad(This->wineD3DTexture);
171 wined3d_mutex_unlock();
174 static D3DRESOURCETYPE WINAPI IDirect3DTexture8Impl_GetType(LPDIRECT3DTEXTURE8 iface) {
175 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
176 D3DRESOURCETYPE type;
178 TRACE("iface %p.\n", iface);
180 wined3d_mutex_lock();
181 type = IWineD3DTexture_GetType(This->wineD3DTexture);
182 wined3d_mutex_unlock();
184 return type;
187 /* IDirect3DTexture8 IDirect3DBaseTexture8 Interface follow: */
188 static DWORD WINAPI IDirect3DTexture8Impl_SetLOD(LPDIRECT3DTEXTURE8 iface, DWORD LODNew) {
189 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
190 DWORD ret;
192 TRACE("iface %p, lod %u.\n", iface, LODNew);
194 wined3d_mutex_lock();
195 ret = IWineD3DTexture_SetLOD(This->wineD3DTexture, LODNew);
196 wined3d_mutex_unlock();
198 return ret;
201 static DWORD WINAPI IDirect3DTexture8Impl_GetLOD(LPDIRECT3DTEXTURE8 iface) {
202 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
203 DWORD ret;
205 TRACE("iface %p.\n", iface);
207 wined3d_mutex_lock();
208 ret = IWineD3DTexture_GetLOD(This->wineD3DTexture);
209 wined3d_mutex_unlock();
211 return ret;
214 static DWORD WINAPI IDirect3DTexture8Impl_GetLevelCount(LPDIRECT3DTEXTURE8 iface) {
215 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
216 DWORD ret;
218 TRACE("iface %p.\n", iface);
220 wined3d_mutex_lock();
221 ret = IWineD3DTexture_GetLevelCount(This->wineD3DTexture);
222 wined3d_mutex_unlock();
224 return ret;
227 /* IDirect3DTexture8 Interface follow: */
228 static HRESULT WINAPI IDirect3DTexture8Impl_GetLevelDesc(LPDIRECT3DTEXTURE8 iface, UINT Level, D3DSURFACE_DESC *pDesc) {
229 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
230 WINED3DSURFACE_DESC wined3ddesc;
231 HRESULT hr;
233 TRACE("iface %p, level %u, desc %p.\n", iface, Level, pDesc);
235 wined3d_mutex_lock();
236 hr = IWineD3DTexture_GetLevelDesc(This->wineD3DTexture, Level, &wined3ddesc);
237 wined3d_mutex_unlock();
239 if (SUCCEEDED(hr))
241 pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.format);
242 pDesc->Type = wined3ddesc.resource_type;
243 pDesc->Usage = wined3ddesc.usage;
244 pDesc->Pool = wined3ddesc.pool;
245 pDesc->Size = wined3ddesc.size;
246 pDesc->MultiSampleType = wined3ddesc.multisample_type;
247 pDesc->Width = wined3ddesc.width;
248 pDesc->Height = wined3ddesc.height;
251 return hr;
254 static HRESULT WINAPI IDirect3DTexture8Impl_GetSurfaceLevel(IDirect3DTexture8 *iface,
255 UINT Level, IDirect3DSurface8 **ppSurfaceLevel)
257 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
258 IWineD3DSurface *mySurface = NULL;
259 HRESULT hr;
261 TRACE("iface %p, level %u, surface %p.\n", iface, Level, ppSurfaceLevel);
263 wined3d_mutex_lock();
264 hr = IWineD3DTexture_GetSurfaceLevel(This->wineD3DTexture, Level, &mySurface);
265 if (SUCCEEDED(hr) && ppSurfaceLevel)
267 *ppSurfaceLevel = IWineD3DSurface_GetParent(mySurface);
268 IDirect3DSurface8_AddRef(*ppSurfaceLevel);
269 IWineD3DSurface_Release(mySurface);
271 wined3d_mutex_unlock();
273 return hr;
276 static HRESULT WINAPI IDirect3DTexture8Impl_LockRect(LPDIRECT3DTEXTURE8 iface, UINT Level, D3DLOCKED_RECT *pLockedRect, CONST RECT *pRect, DWORD Flags) {
277 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
278 HRESULT hr;
280 TRACE("iface %p, level %u, locked_rect %p, rect %p, flags %#x.\n",
281 iface, Level, pLockedRect, pRect, Flags);
283 wined3d_mutex_lock();
284 hr = IWineD3DTexture_Map(This->wineD3DTexture, Level, (WINED3DLOCKED_RECT *)pLockedRect, pRect, Flags);
285 wined3d_mutex_unlock();
287 return hr;
290 static HRESULT WINAPI IDirect3DTexture8Impl_UnlockRect(LPDIRECT3DTEXTURE8 iface, UINT Level) {
291 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
292 HRESULT hr;
294 TRACE("iface %p, level %u.\n", iface, Level);
296 wined3d_mutex_lock();
297 hr = IWineD3DTexture_Unmap(This->wineD3DTexture, Level);
298 wined3d_mutex_unlock();
300 return hr;
303 static HRESULT WINAPI IDirect3DTexture8Impl_AddDirtyRect(LPDIRECT3DTEXTURE8 iface, CONST RECT *pDirtyRect) {
304 IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
305 HRESULT hr;
307 TRACE("iface %p, dirty_rect %p.\n", iface, pDirtyRect);
309 wined3d_mutex_lock();
310 hr = IWineD3DTexture_AddDirtyRect(This->wineD3DTexture, pDirtyRect);
311 wined3d_mutex_unlock();
313 return hr;
316 static const IDirect3DTexture8Vtbl Direct3DTexture8_Vtbl =
318 /* IUnknown */
319 IDirect3DTexture8Impl_QueryInterface,
320 IDirect3DTexture8Impl_AddRef,
321 IDirect3DTexture8Impl_Release,
322 /* IDirect3DResource8 */
323 IDirect3DTexture8Impl_GetDevice,
324 IDirect3DTexture8Impl_SetPrivateData,
325 IDirect3DTexture8Impl_GetPrivateData,
326 IDirect3DTexture8Impl_FreePrivateData,
327 IDirect3DTexture8Impl_SetPriority,
328 IDirect3DTexture8Impl_GetPriority,
329 IDirect3DTexture8Impl_PreLoad,
330 IDirect3DTexture8Impl_GetType,
331 /* IDirect3dBaseTexture8 */
332 IDirect3DTexture8Impl_SetLOD,
333 IDirect3DTexture8Impl_GetLOD,
334 IDirect3DTexture8Impl_GetLevelCount,
335 /* IDirect3DTexture8 */
336 IDirect3DTexture8Impl_GetLevelDesc,
337 IDirect3DTexture8Impl_GetSurfaceLevel,
338 IDirect3DTexture8Impl_LockRect,
339 IDirect3DTexture8Impl_UnlockRect,
340 IDirect3DTexture8Impl_AddDirtyRect
343 static void STDMETHODCALLTYPE d3d8_texture_wined3d_object_destroyed(void *parent)
345 HeapFree(GetProcessHeap(), 0, parent);
348 static const struct wined3d_parent_ops d3d8_texture_wined3d_parent_ops =
350 d3d8_texture_wined3d_object_destroyed,
353 HRESULT texture_init(IDirect3DTexture8Impl *texture, IDirect3DDevice8Impl *device,
354 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
356 HRESULT hr;
358 texture->lpVtbl = &Direct3DTexture8_Vtbl;
359 texture->ref = 1;
361 wined3d_mutex_lock();
362 hr = IWineD3DDevice_CreateTexture(device->WineD3DDevice, width, height, levels,
363 usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool,
364 texture, &d3d8_texture_wined3d_parent_ops, &texture->wineD3DTexture);
365 wined3d_mutex_unlock();
366 if (FAILED(hr))
368 WARN("Failed to create wined3d texture, hr %#x.\n", hr);
369 return hr;
372 texture->parentDevice = (IDirect3DDevice8 *)device;
373 IDirect3DDevice8_AddRef(texture->parentDevice);
375 return D3D_OK;