msi: Fix ACTION_AppSearchDr on empty path.
[wine] / dlls / 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         EnterCriticalSection(&d3d8_cs);
61         IWineD3DTexture_Destroy(This->wineD3DTexture, D3D8CB_DestroySurface);
62         LeaveCriticalSection(&d3d8_cs);
63         IUnknown_Release(This->parentDevice);
64         HeapFree(GetProcessHeap(), 0, This);
65     }
66     return ref;
67 }
68
69 /* IDirect3DTexture8 IDirect3DResource8 Interface follow: */
70 static HRESULT WINAPI IDirect3DTexture8Impl_GetDevice(LPDIRECT3DTEXTURE8 iface, IDirect3DDevice8 **ppDevice) {
71     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
72     IWineD3DDevice *wined3d_device;
73     HRESULT hr;
74     TRACE("(%p) Relay\n", This);
75     EnterCriticalSection(&d3d8_cs);
76     hr = IWineD3DTexture_GetDevice(This->wineD3DTexture, &wined3d_device);
77     if (SUCCEEDED(hr))
78     {
79         IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
80         IWineD3DDevice_Release(wined3d_device);
81     }
82     LeaveCriticalSection(&d3d8_cs);
83     return hr;
84 }
85
86 static HRESULT WINAPI IDirect3DTexture8Impl_SetPrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
87     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
88     HRESULT hr;
89     TRACE("(%p) Relay\n", This);
90
91     EnterCriticalSection(&d3d8_cs);
92     hr = IWineD3DTexture_SetPrivateData(This->wineD3DTexture, refguid, pData, SizeOfData, Flags);
93     LeaveCriticalSection(&d3d8_cs);
94     return hr;
95 }
96
97 static HRESULT WINAPI IDirect3DTexture8Impl_GetPrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid, void *pData, DWORD* pSizeOfData) {
98     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
99     HRESULT hr;
100     TRACE("(%p) Relay\n", This);
101
102     EnterCriticalSection(&d3d8_cs);
103     hr = IWineD3DTexture_GetPrivateData(This->wineD3DTexture, refguid, pData, pSizeOfData);
104     LeaveCriticalSection(&d3d8_cs);
105     return hr;
106 }
107
108 static HRESULT WINAPI IDirect3DTexture8Impl_FreePrivateData(LPDIRECT3DTEXTURE8 iface, REFGUID refguid) {
109     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
110     HRESULT hr;
111     TRACE("(%p) Relay\n", This);
112
113     EnterCriticalSection(&d3d8_cs);
114     hr = IWineD3DTexture_FreePrivateData(This->wineD3DTexture, refguid);
115     LeaveCriticalSection(&d3d8_cs);
116     return hr;
117 }
118
119 static DWORD WINAPI IDirect3DTexture8Impl_SetPriority(LPDIRECT3DTEXTURE8 iface, DWORD PriorityNew) {
120     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
121     DWORD ret;
122     TRACE("(%p) Relay\n", This);
123
124     EnterCriticalSection(&d3d8_cs);
125     ret = IWineD3DTexture_SetPriority(This->wineD3DTexture, PriorityNew);
126     LeaveCriticalSection(&d3d8_cs);
127     return ret;
128 }
129
130 static DWORD WINAPI IDirect3DTexture8Impl_GetPriority(LPDIRECT3DTEXTURE8 iface) {
131     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
132     DWORD ret;
133     TRACE("(%p) Relay\n", This);
134
135     EnterCriticalSection(&d3d8_cs);
136     ret = IWineD3DTexture_GetPriority(This->wineD3DTexture);
137     LeaveCriticalSection(&d3d8_cs);
138     return ret;
139 }
140
141 static void WINAPI IDirect3DTexture8Impl_PreLoad(LPDIRECT3DTEXTURE8 iface) {
142     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
143     TRACE("(%p) Relay\n", This);
144
145     EnterCriticalSection(&d3d8_cs);
146     IWineD3DTexture_PreLoad(This->wineD3DTexture);
147     LeaveCriticalSection(&d3d8_cs);
148 }
149
150 static D3DRESOURCETYPE WINAPI IDirect3DTexture8Impl_GetType(LPDIRECT3DTEXTURE8 iface) {
151     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
152     D3DRESOURCETYPE type;
153     TRACE("(%p) Relay\n", This);
154
155     EnterCriticalSection(&d3d8_cs);
156     type = IWineD3DTexture_GetType(This->wineD3DTexture);
157     LeaveCriticalSection(&d3d8_cs);
158     return type;
159 }
160
161 /* IDirect3DTexture8 IDirect3DBaseTexture8 Interface follow: */
162 static DWORD WINAPI IDirect3DTexture8Impl_SetLOD(LPDIRECT3DTEXTURE8 iface, DWORD LODNew) {
163     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
164     DWORD ret;
165     TRACE("(%p) Relay\n", This);
166
167     EnterCriticalSection(&d3d8_cs);
168     ret = IWineD3DTexture_SetLOD(This->wineD3DTexture, LODNew);
169     LeaveCriticalSection(&d3d8_cs);
170     return ret;
171 }
172
173 static DWORD WINAPI IDirect3DTexture8Impl_GetLOD(LPDIRECT3DTEXTURE8 iface) {
174     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
175     DWORD ret;
176     TRACE("(%p) Relay\n", This);
177
178     EnterCriticalSection(&d3d8_cs);
179     ret = IWineD3DTexture_GetLOD(This->wineD3DTexture);
180     LeaveCriticalSection(&d3d8_cs);
181     return ret;
182 }
183
184 static DWORD WINAPI IDirect3DTexture8Impl_GetLevelCount(LPDIRECT3DTEXTURE8 iface) {
185     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
186     DWORD ret;
187     TRACE("(%p) Relay\n", This);
188
189     EnterCriticalSection(&d3d8_cs);
190     ret = IWineD3DTexture_GetLevelCount(This->wineD3DTexture);
191     LeaveCriticalSection(&d3d8_cs);
192     return ret;
193 }
194
195 /* IDirect3DTexture8 Interface follow: */
196 static HRESULT WINAPI IDirect3DTexture8Impl_GetLevelDesc(LPDIRECT3DTEXTURE8 iface, UINT Level, D3DSURFACE_DESC *pDesc) {
197     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
198     HRESULT hr;
199
200     WINED3DSURFACE_DESC    wined3ddesc;
201     TRACE("(%p) Relay\n", This);
202
203     /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
204     memset(&wined3ddesc, 0, sizeof(wined3ddesc));
205     wined3ddesc.Format              = (WINED3DFORMAT *)&pDesc->Format;
206     wined3ddesc.Type                = (WINED3DRESOURCETYPE *)&pDesc->Type;
207     wined3ddesc.Usage               = &pDesc->Usage;
208     wined3ddesc.Pool                = (WINED3DPOOL *) &pDesc->Pool;
209     wined3ddesc.Size                = &pDesc->Size;
210     wined3ddesc.MultiSampleType     = (WINED3DMULTISAMPLE_TYPE *) &pDesc->MultiSampleType;
211     wined3ddesc.Width               = &pDesc->Width;
212     wined3ddesc.Height              = &pDesc->Height;
213
214     EnterCriticalSection(&d3d8_cs);
215     hr = IWineD3DTexture_GetLevelDesc(This->wineD3DTexture, Level, &wined3ddesc);
216     LeaveCriticalSection(&d3d8_cs);
217
218     if (SUCCEEDED(hr)) pDesc->Format = d3dformat_from_wined3dformat(pDesc->Format);
219
220     return hr;
221 }
222
223 static HRESULT WINAPI IDirect3DTexture8Impl_GetSurfaceLevel(LPDIRECT3DTEXTURE8 iface, UINT Level, IDirect3DSurface8 **ppSurfaceLevel) {
224     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
225     HRESULT hrc = D3D_OK;
226     IWineD3DSurface *mySurface = NULL;
227
228     TRACE("(%p) Relay\n", This);
229     EnterCriticalSection(&d3d8_cs);
230     hrc = IWineD3DTexture_GetSurfaceLevel(This->wineD3DTexture, Level, &mySurface);
231     if (hrc == D3D_OK && NULL != ppSurfaceLevel) {
232        IWineD3DSurface_GetParent(mySurface, (IUnknown **)ppSurfaceLevel);
233        IWineD3DSurface_Release(mySurface);
234     }
235     LeaveCriticalSection(&d3d8_cs);
236     return hrc;
237 }
238
239 static HRESULT WINAPI IDirect3DTexture8Impl_LockRect(LPDIRECT3DTEXTURE8 iface, UINT Level, D3DLOCKED_RECT *pLockedRect, CONST RECT *pRect, DWORD Flags) {
240     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
241     HRESULT hr;
242     TRACE("(%p) Relay\n", This);
243
244     EnterCriticalSection(&d3d8_cs);
245     hr = IWineD3DTexture_LockRect(This->wineD3DTexture, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
246     LeaveCriticalSection(&d3d8_cs);
247     return hr;
248 }
249
250 static HRESULT WINAPI IDirect3DTexture8Impl_UnlockRect(LPDIRECT3DTEXTURE8 iface, UINT Level) {
251     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
252     HRESULT hr;
253     TRACE("(%p) Relay\n", This);
254
255     EnterCriticalSection(&d3d8_cs);
256     hr = IWineD3DTexture_UnlockRect(This->wineD3DTexture, Level);
257     LeaveCriticalSection(&d3d8_cs);
258     return hr;
259 }
260
261 static HRESULT WINAPI IDirect3DTexture8Impl_AddDirtyRect(LPDIRECT3DTEXTURE8 iface, CONST RECT *pDirtyRect) {
262     IDirect3DTexture8Impl *This = (IDirect3DTexture8Impl *)iface;
263     HRESULT hr;
264     TRACE("(%p) Relay\n", This);
265
266     EnterCriticalSection(&d3d8_cs);
267     hr = IWineD3DTexture_AddDirtyRect(This->wineD3DTexture, pDirtyRect);
268     LeaveCriticalSection(&d3d8_cs);
269     return hr;
270 }
271
272 const IDirect3DTexture8Vtbl Direct3DTexture8_Vtbl =
273 {
274     /* IUnknown */
275     IDirect3DTexture8Impl_QueryInterface,
276     IDirect3DTexture8Impl_AddRef,
277     IDirect3DTexture8Impl_Release,
278      /* IDirect3DResource8 */
279     IDirect3DTexture8Impl_GetDevice,
280     IDirect3DTexture8Impl_SetPrivateData,
281     IDirect3DTexture8Impl_GetPrivateData,
282     IDirect3DTexture8Impl_FreePrivateData,
283     IDirect3DTexture8Impl_SetPriority,
284     IDirect3DTexture8Impl_GetPriority,
285     IDirect3DTexture8Impl_PreLoad,
286     IDirect3DTexture8Impl_GetType,
287     /* IDirect3dBaseTexture8 */
288     IDirect3DTexture8Impl_SetLOD,
289     IDirect3DTexture8Impl_GetLOD,
290     IDirect3DTexture8Impl_GetLevelCount,
291     /* IDirect3DTexture8 */
292     IDirect3DTexture8Impl_GetLevelDesc,
293     IDirect3DTexture8Impl_GetSurfaceLevel,
294     IDirect3DTexture8Impl_LockRect,
295     IDirect3DTexture8Impl_UnlockRect,
296     IDirect3DTexture8Impl_AddDirtyRect
297 };