winecfg: Update Portuguese translation.
[wine/testsucceed.git] / dlls / d3d9 / texture.c
blob564057f33f1544485c000b0cd5f7f808d1b8e13f
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(LPDIRECT3DTEXTURE9 iface, UINT Level, IDirect3DSurface9** ppSurfaceLevel) {
293 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
294 HRESULT hrc = D3D_OK;
295 IWineD3DSurface *mySurface = NULL;
297 TRACE("iface %p, level %u, surface %p.\n", iface, Level, ppSurfaceLevel);
299 wined3d_mutex_lock();
300 hrc = IWineD3DTexture_GetSurfaceLevel(This->wineD3DTexture, Level, &mySurface);
301 if (hrc == D3D_OK && NULL != ppSurfaceLevel) {
302 IWineD3DSurface_GetParent(mySurface, (IUnknown **)ppSurfaceLevel);
303 IWineD3DSurface_Release(mySurface);
305 wined3d_mutex_unlock();
307 return hrc;
310 static HRESULT WINAPI IDirect3DTexture9Impl_LockRect(LPDIRECT3DTEXTURE9 iface, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
311 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
312 HRESULT hr;
314 TRACE("iface %p, level %u, locked_rect %p, rect %p, flags %#x.\n",
315 iface, Level, pLockedRect, pRect, Flags);
317 wined3d_mutex_lock();
318 hr = IWineD3DTexture_LockRect(This->wineD3DTexture, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
319 wined3d_mutex_unlock();
321 return hr;
324 static HRESULT WINAPI IDirect3DTexture9Impl_UnlockRect(LPDIRECT3DTEXTURE9 iface, UINT Level) {
325 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
326 HRESULT hr;
328 TRACE("iface %p, level %u.\n", iface, Level);
330 wined3d_mutex_lock();
331 hr = IWineD3DTexture_UnlockRect(This->wineD3DTexture, Level);
332 wined3d_mutex_unlock();
334 return hr;
337 static HRESULT WINAPI IDirect3DTexture9Impl_AddDirtyRect(LPDIRECT3DTEXTURE9 iface, CONST RECT* pDirtyRect) {
338 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
339 HRESULT hr;
341 TRACE("iface %p, dirty_rect %p.\n", iface, pDirtyRect);
343 wined3d_mutex_lock();
344 hr = IWineD3DTexture_AddDirtyRect(This->wineD3DTexture, pDirtyRect);
345 wined3d_mutex_unlock();
347 return hr;
350 static const IDirect3DTexture9Vtbl Direct3DTexture9_Vtbl =
352 /* IUnknown */
353 IDirect3DTexture9Impl_QueryInterface,
354 IDirect3DTexture9Impl_AddRef,
355 IDirect3DTexture9Impl_Release,
356 /* IDirect3DResource9 */
357 IDirect3DTexture9Impl_GetDevice,
358 IDirect3DTexture9Impl_SetPrivateData,
359 IDirect3DTexture9Impl_GetPrivateData,
360 IDirect3DTexture9Impl_FreePrivateData,
361 IDirect3DTexture9Impl_SetPriority,
362 IDirect3DTexture9Impl_GetPriority,
363 IDirect3DTexture9Impl_PreLoad,
364 IDirect3DTexture9Impl_GetType,
365 /* IDirect3dBaseTexture9 */
366 IDirect3DTexture9Impl_SetLOD,
367 IDirect3DTexture9Impl_GetLOD,
368 IDirect3DTexture9Impl_GetLevelCount,
369 IDirect3DTexture9Impl_SetAutoGenFilterType,
370 IDirect3DTexture9Impl_GetAutoGenFilterType,
371 IDirect3DTexture9Impl_GenerateMipSubLevels,
372 /* IDirect3DTexture9 */
373 IDirect3DTexture9Impl_GetLevelDesc,
374 IDirect3DTexture9Impl_GetSurfaceLevel,
375 IDirect3DTexture9Impl_LockRect,
376 IDirect3DTexture9Impl_UnlockRect,
377 IDirect3DTexture9Impl_AddDirtyRect
380 static void STDMETHODCALLTYPE d3d9_texture_wined3d_object_destroyed(void *parent)
382 HeapFree(GetProcessHeap(), 0, parent);
385 static const struct wined3d_parent_ops d3d9_texture_wined3d_parent_ops =
387 d3d9_texture_wined3d_object_destroyed,
390 HRESULT texture_init(IDirect3DTexture9Impl *texture, IDirect3DDevice9Impl *device,
391 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
393 HRESULT hr;
395 texture->lpVtbl = &Direct3DTexture9_Vtbl;
396 texture->ref = 1;
398 wined3d_mutex_lock();
399 hr = IWineD3DDevice_CreateTexture(device->WineD3DDevice, width, height, levels,
400 usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool,
401 &texture->wineD3DTexture, (IUnknown *)texture, &d3d9_texture_wined3d_parent_ops);
402 wined3d_mutex_unlock();
403 if (FAILED(hr))
405 WARN("Failed to create wined3d texture, hr %#x.\n", hr);
406 return hr;
409 texture->parentDevice = (IDirect3DDevice9Ex *)device;
410 IDirect3DDevice9Ex_AddRef(texture->parentDevice);
412 return D3D_OK;