kernel32: Add stub for GetSystemTimes.
[wine.git] / dlls / d3d9 / texture.c
blobe1283508a80253338780a2552a7a2f7c2505fb92
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 if (IsEqualGUID(riid, &IID_IUnknown)
33 || IsEqualGUID(riid, &IID_IDirect3DResource9)
34 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
35 || IsEqualGUID(riid, &IID_IDirect3DTexture9)) {
36 IDirect3DTexture9_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 IDirect3DTexture9Impl_AddRef(LPDIRECT3DTEXTURE9 iface) {
47 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
48 ULONG ref = InterlockedIncrement(&This->ref);
50 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
52 return ref;
55 static ULONG WINAPI IDirect3DTexture9Impl_Release(LPDIRECT3DTEXTURE9 iface) {
56 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
57 ULONG ref = InterlockedDecrement(&This->ref);
59 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
61 if (ref == 0) {
62 EnterCriticalSection(&d3d9_cs);
63 IWineD3DTexture_Destroy(This->wineD3DTexture, D3D9CB_DestroySurface);
64 LeaveCriticalSection(&d3d9_cs);
65 IDirect3DDevice9Ex_Release(This->parentDevice);
66 HeapFree(GetProcessHeap(), 0, This);
68 return ref;
71 /* IDirect3DTexture9 IDirect3DResource9 Interface follow: */
72 static HRESULT WINAPI IDirect3DTexture9Impl_GetDevice(LPDIRECT3DTEXTURE9 iface, IDirect3DDevice9** ppDevice) {
73 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
74 IWineD3DDevice *wined3d_device;
75 HRESULT hr;
76 TRACE("(%p) Relay\n", This);
78 EnterCriticalSection(&d3d9_cs);
79 hr = IWineD3DTexture_GetDevice(This->wineD3DTexture, &wined3d_device);
80 if (SUCCEEDED(hr))
82 IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
83 IWineD3DDevice_Release(wined3d_device);
85 LeaveCriticalSection(&d3d9_cs);
86 return hr;
89 static HRESULT WINAPI IDirect3DTexture9Impl_SetPrivateData(LPDIRECT3DTEXTURE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
90 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
91 HRESULT hr;
92 TRACE("(%p) Relay\n", This);
94 EnterCriticalSection(&d3d9_cs);
95 hr = IWineD3DTexture_SetPrivateData(This->wineD3DTexture, refguid, pData, SizeOfData, Flags);
96 LeaveCriticalSection(&d3d9_cs);
97 return hr;
100 static HRESULT WINAPI IDirect3DTexture9Impl_GetPrivateData(LPDIRECT3DTEXTURE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
101 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
102 HRESULT hr;
103 TRACE("(%p) Relay\n", This);
105 EnterCriticalSection(&d3d9_cs);
106 hr = IWineD3DTexture_GetPrivateData(This->wineD3DTexture, refguid, pData, pSizeOfData);
107 LeaveCriticalSection(&d3d9_cs);
108 return hr;
111 static HRESULT WINAPI IDirect3DTexture9Impl_FreePrivateData(LPDIRECT3DTEXTURE9 iface, REFGUID refguid) {
112 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
113 HRESULT hr;
114 TRACE("(%p) Relay\n", This);
116 EnterCriticalSection(&d3d9_cs);
117 hr = IWineD3DTexture_FreePrivateData(This->wineD3DTexture, refguid);
118 LeaveCriticalSection(&d3d9_cs);
119 return hr;
122 static DWORD WINAPI IDirect3DTexture9Impl_SetPriority(LPDIRECT3DTEXTURE9 iface, DWORD PriorityNew) {
123 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
124 DWORD ret;
125 TRACE("(%p) Relay\n", This);
127 EnterCriticalSection(&d3d9_cs);
128 ret = IWineD3DTexture_SetPriority(This->wineD3DTexture, PriorityNew);
129 LeaveCriticalSection(&d3d9_cs);
130 return ret;
133 static DWORD WINAPI IDirect3DTexture9Impl_GetPriority(LPDIRECT3DTEXTURE9 iface) {
134 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
135 DWORD ret;
136 TRACE("(%p) Relay\n", This);
138 EnterCriticalSection(&d3d9_cs);
139 ret = IWineD3DTexture_GetPriority(This->wineD3DTexture);
140 LeaveCriticalSection(&d3d9_cs);
141 return ret;
144 static void WINAPI IDirect3DTexture9Impl_PreLoad(LPDIRECT3DTEXTURE9 iface) {
145 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
146 TRACE("(%p) Relay\n", This);
148 EnterCriticalSection(&d3d9_cs);
149 IWineD3DTexture_PreLoad(This->wineD3DTexture);
150 LeaveCriticalSection(&d3d9_cs);
153 static D3DRESOURCETYPE WINAPI IDirect3DTexture9Impl_GetType(LPDIRECT3DTEXTURE9 iface) {
154 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
155 HRESULT ret;
156 TRACE("(%p) Relay\n", This);
158 EnterCriticalSection(&d3d9_cs);
159 ret = IWineD3DTexture_GetType(This->wineD3DTexture);
160 LeaveCriticalSection(&d3d9_cs);
161 return ret;
164 /* IDirect3DTexture9 IDirect3DBaseTexture9 Interface follow: */
165 static DWORD WINAPI IDirect3DTexture9Impl_SetLOD(LPDIRECT3DTEXTURE9 iface, DWORD LODNew) {
166 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
167 DWORD ret;
168 TRACE("(%p) Relay\n", This);
170 EnterCriticalSection(&d3d9_cs);
171 ret = IWineD3DTexture_SetLOD(This->wineD3DTexture, LODNew);
172 LeaveCriticalSection(&d3d9_cs);
173 return ret;
176 static DWORD WINAPI IDirect3DTexture9Impl_GetLOD(LPDIRECT3DTEXTURE9 iface) {
177 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
178 DWORD ret;
179 TRACE("(%p) Relay\n", This);
181 EnterCriticalSection(&d3d9_cs);
182 ret = IWineD3DTexture_GetLOD(This->wineD3DTexture);
183 LeaveCriticalSection(&d3d9_cs);
184 return ret;
187 static DWORD WINAPI IDirect3DTexture9Impl_GetLevelCount(LPDIRECT3DTEXTURE9 iface) {
188 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
189 DWORD ret;
190 TRACE("(%p) Relay\n", This);
192 EnterCriticalSection(&d3d9_cs);
193 ret = IWineD3DTexture_GetLevelCount(This->wineD3DTexture);
194 LeaveCriticalSection(&d3d9_cs);
195 return ret;
198 static HRESULT WINAPI IDirect3DTexture9Impl_SetAutoGenFilterType(LPDIRECT3DTEXTURE9 iface, D3DTEXTUREFILTERTYPE FilterType) {
199 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
200 HRESULT hr;
201 TRACE("(%p) Relay\n", This);
203 EnterCriticalSection(&d3d9_cs);
204 hr = IWineD3DTexture_SetAutoGenFilterType(This->wineD3DTexture, (WINED3DTEXTUREFILTERTYPE) FilterType);
205 LeaveCriticalSection(&d3d9_cs);
206 return hr;
209 static D3DTEXTUREFILTERTYPE WINAPI IDirect3DTexture9Impl_GetAutoGenFilterType(LPDIRECT3DTEXTURE9 iface) {
210 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
211 D3DTEXTUREFILTERTYPE ret;
212 TRACE("(%p) Relay\n", This);
214 EnterCriticalSection(&d3d9_cs);
215 ret = (D3DTEXTUREFILTERTYPE) IWineD3DTexture_GetAutoGenFilterType(This->wineD3DTexture);
216 LeaveCriticalSection(&d3d9_cs);
217 return ret;
220 static void WINAPI IDirect3DTexture9Impl_GenerateMipSubLevels(LPDIRECT3DTEXTURE9 iface) {
221 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
222 TRACE("(%p) Relay\n", This);
224 EnterCriticalSection(&d3d9_cs);
225 IWineD3DTexture_GenerateMipSubLevels(This->wineD3DTexture);
226 LeaveCriticalSection(&d3d9_cs);
229 /* IDirect3DTexture9 Interface follow: */
230 static HRESULT WINAPI IDirect3DTexture9Impl_GetLevelDesc(LPDIRECT3DTEXTURE9 iface, UINT Level, D3DSURFACE_DESC* pDesc) {
231 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
233 WINED3DSURFACE_DESC wined3ddesc;
234 UINT tmpInt = -1;
235 HRESULT hr;
236 WINED3DFORMAT format;
238 TRACE("(%p) Relay\n", This);
240 /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
241 wined3ddesc.Format = &format;
242 wined3ddesc.Type = (WINED3DRESOURCETYPE *)&pDesc->Type;
243 wined3ddesc.Usage = &pDesc->Usage;
244 wined3ddesc.Pool = (WINED3DPOOL *) &pDesc->Pool;
245 wined3ddesc.Size = &tmpInt; /* required for d3d8 */
246 wined3ddesc.MultiSampleType = (WINED3DMULTISAMPLE_TYPE *) &pDesc->MultiSampleType;
247 wined3ddesc.MultiSampleQuality = &pDesc->MultiSampleQuality;
248 wined3ddesc.Width = &pDesc->Width;
249 wined3ddesc.Height = &pDesc->Height;
251 EnterCriticalSection(&d3d9_cs);
252 hr = IWineD3DTexture_GetLevelDesc(This->wineD3DTexture, Level, &wined3ddesc);
253 LeaveCriticalSection(&d3d9_cs);
255 if (SUCCEEDED(hr)) pDesc->Format = d3dformat_from_wined3dformat(format);
257 return hr;
260 static HRESULT WINAPI IDirect3DTexture9Impl_GetSurfaceLevel(LPDIRECT3DTEXTURE9 iface, UINT Level, IDirect3DSurface9** ppSurfaceLevel) {
261 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
262 HRESULT hrc = D3D_OK;
263 IWineD3DSurface *mySurface = NULL;
265 TRACE("(%p) Relay\n", This);
266 EnterCriticalSection(&d3d9_cs);
267 hrc = IWineD3DTexture_GetSurfaceLevel(This->wineD3DTexture, Level, &mySurface);
268 if (hrc == D3D_OK && NULL != ppSurfaceLevel) {
269 IWineD3DSurface_GetParent(mySurface, (IUnknown **)ppSurfaceLevel);
270 IWineD3DSurface_Release(mySurface);
272 LeaveCriticalSection(&d3d9_cs);
273 return hrc;
276 static HRESULT WINAPI IDirect3DTexture9Impl_LockRect(LPDIRECT3DTEXTURE9 iface, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
277 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
278 HRESULT hr;
279 TRACE("(%p) Relay\n", This);
281 EnterCriticalSection(&d3d9_cs);
282 hr = IWineD3DTexture_LockRect(This->wineD3DTexture, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
283 LeaveCriticalSection(&d3d9_cs);
284 return hr;
287 static HRESULT WINAPI IDirect3DTexture9Impl_UnlockRect(LPDIRECT3DTEXTURE9 iface, UINT Level) {
288 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
289 HRESULT hr;
290 TRACE("(%p) Relay\n", This);
292 EnterCriticalSection(&d3d9_cs);
293 hr = IWineD3DTexture_UnlockRect(This->wineD3DTexture, Level);
294 LeaveCriticalSection(&d3d9_cs);
295 return hr;
298 static HRESULT WINAPI IDirect3DTexture9Impl_AddDirtyRect(LPDIRECT3DTEXTURE9 iface, CONST RECT* pDirtyRect) {
299 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
300 HRESULT hr;
301 TRACE("(%p) Relay\n", This);
303 EnterCriticalSection(&d3d9_cs);
304 hr = IWineD3DTexture_AddDirtyRect(This->wineD3DTexture, pDirtyRect);
305 LeaveCriticalSection(&d3d9_cs);
306 return hr;
309 static const IDirect3DTexture9Vtbl Direct3DTexture9_Vtbl =
311 /* IUnknown */
312 IDirect3DTexture9Impl_QueryInterface,
313 IDirect3DTexture9Impl_AddRef,
314 IDirect3DTexture9Impl_Release,
315 /* IDirect3DResource9 */
316 IDirect3DTexture9Impl_GetDevice,
317 IDirect3DTexture9Impl_SetPrivateData,
318 IDirect3DTexture9Impl_GetPrivateData,
319 IDirect3DTexture9Impl_FreePrivateData,
320 IDirect3DTexture9Impl_SetPriority,
321 IDirect3DTexture9Impl_GetPriority,
322 IDirect3DTexture9Impl_PreLoad,
323 IDirect3DTexture9Impl_GetType,
324 /* IDirect3dBaseTexture9 */
325 IDirect3DTexture9Impl_SetLOD,
326 IDirect3DTexture9Impl_GetLOD,
327 IDirect3DTexture9Impl_GetLevelCount,
328 IDirect3DTexture9Impl_SetAutoGenFilterType,
329 IDirect3DTexture9Impl_GetAutoGenFilterType,
330 IDirect3DTexture9Impl_GenerateMipSubLevels,
331 /* IDirect3DTexture9 */
332 IDirect3DTexture9Impl_GetLevelDesc,
333 IDirect3DTexture9Impl_GetSurfaceLevel,
334 IDirect3DTexture9Impl_LockRect,
335 IDirect3DTexture9Impl_UnlockRect,
336 IDirect3DTexture9Impl_AddDirtyRect
340 /* IDirect3DDevice9 IDirect3DTexture9 Methods follow: */
341 HRESULT WINAPI IDirect3DDevice9Impl_CreateTexture(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, UINT Levels, DWORD Usage,
342 D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture9** ppTexture, HANDLE* pSharedHandle) {
343 IDirect3DTexture9Impl *object;
344 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
345 HRESULT hrc = D3D_OK;
347 TRACE("(%p) : W(%d) H(%d), Lvl(%d) d(%d), Fmt(%#x), Pool(%d)\n", This, Width, Height, Levels, Usage, Format, Pool);
349 /* Allocate the storage for the device */
350 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DTexture9Impl));
352 if (NULL == object) {
353 ERR("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
354 return D3DERR_OUTOFVIDEOMEMORY;
357 object->lpVtbl = &Direct3DTexture9_Vtbl;
358 object->ref = 1;
359 EnterCriticalSection(&d3d9_cs);
360 hrc = IWineD3DDevice_CreateTexture(This->WineD3DDevice, Width, Height, Levels, Usage & WINED3DUSAGE_MASK,
361 wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DTexture, pSharedHandle, (IUnknown *)object);
362 LeaveCriticalSection(&d3d9_cs);
363 if (FAILED(hrc)) {
365 /* free up object */
366 WARN("(%p) call to IWineD3DDevice_CreateTexture failed\n", This);
367 HeapFree(GetProcessHeap(), 0, object);
368 } else {
369 IDirect3DDevice9Ex_AddRef(iface);
370 object->parentDevice = iface;
371 *ppTexture= (LPDIRECT3DTEXTURE9) object;
372 TRACE("(%p) Created Texture %p, %p\n", This, object, object->wineD3DTexture);
375 return hrc;