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