d3d9: Remove trailing spaces.
[wine] / dlls / d3d9 / indexbuffer.c
1 /*
2  * IDirect3DIndexBuffer9 implementation
3  *
4  * Copyright 2002-2004 Jason Edmeades
5  *                     Raphael Junqueira
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include "config.h"
23 #include "d3d9_private.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
26
27 /* IDirect3DIndexBuffer9 IUnknown parts follow: */
28 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_QueryInterface(LPDIRECT3DINDEXBUFFER9 iface, REFIID riid, LPVOID* ppobj) {
29     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
30
31     if (IsEqualGUID(riid, &IID_IUnknown)
32         || IsEqualGUID(riid, &IID_IDirect3DResource9)
33         || IsEqualGUID(riid, &IID_IDirect3DIndexBuffer9)) {
34         IDirect3DIndexBuffer9_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 IDirect3DIndexBuffer9Impl_AddRef(LPDIRECT3DINDEXBUFFER9 iface) {
45     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)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 IDirect3DIndexBuffer9Impl_Release(LPDIRECT3DINDEXBUFFER9 iface) {
54     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
55     ULONG ref = InterlockedDecrement(&This->ref);
56
57     TRACE("(%p) : ReleaseRef to %d\n", This, ref);
58
59     if (ref == 0) {
60         wined3d_mutex_lock();
61         IWineD3DBuffer_Release(This->wineD3DIndexBuffer);
62         wined3d_mutex_unlock();
63
64         IDirect3DDevice9Ex_Release(This->parentDevice);
65         HeapFree(GetProcessHeap(), 0, This);
66     }
67     return ref;
68 }
69
70 /* IDirect3DIndexBuffer9 IDirect3DResource9 Interface follow: */
71 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetDevice(LPDIRECT3DINDEXBUFFER9 iface, IDirect3DDevice9** ppDevice) {
72     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
73     IWineD3DDevice *wined3d_device;
74     HRESULT hr;
75     TRACE("(%p) Relay\n", This);
76
77     wined3d_mutex_lock();
78     hr = IWineD3DBuffer_GetDevice(This->wineD3DIndexBuffer, &wined3d_device);
79     if (SUCCEEDED(hr))
80     {
81         IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
82         IWineD3DDevice_Release(wined3d_device);
83     }
84     wined3d_mutex_unlock();
85
86     return hr;
87 }
88
89 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_SetPrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
90     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
91     HRESULT hr;
92     TRACE("(%p) Relay\n", This);
93
94     wined3d_mutex_lock();
95     hr = IWineD3DBuffer_SetPrivateData(This->wineD3DIndexBuffer, refguid, pData, SizeOfData, Flags);
96     wined3d_mutex_unlock();
97
98     return hr;
99 }
100
101 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetPrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
102     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
103     HRESULT hr;
104     TRACE("(%p) Relay\n", This);
105
106     wined3d_mutex_lock();
107     hr = IWineD3DBuffer_GetPrivateData(This->wineD3DIndexBuffer, refguid, pData, pSizeOfData);
108     wined3d_mutex_unlock();
109
110     return hr;
111 }
112
113 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_FreePrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid) {
114     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
115     HRESULT hr;
116     TRACE("(%p) Relay\n", This);
117
118     wined3d_mutex_lock();
119     hr = IWineD3DBuffer_FreePrivateData(This->wineD3DIndexBuffer, refguid);
120     wined3d_mutex_unlock();
121
122     return hr;
123 }
124
125 static DWORD WINAPI IDirect3DIndexBuffer9Impl_SetPriority(LPDIRECT3DINDEXBUFFER9 iface, DWORD PriorityNew) {
126     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
127     DWORD ret;
128     TRACE("(%p) Relay\n", This);
129
130     wined3d_mutex_lock();
131     ret = IWineD3DBuffer_SetPriority(This->wineD3DIndexBuffer, PriorityNew);
132     wined3d_mutex_unlock();
133
134     return ret;
135 }
136
137 static DWORD WINAPI IDirect3DIndexBuffer9Impl_GetPriority(LPDIRECT3DINDEXBUFFER9 iface) {
138     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
139     DWORD ret;
140     TRACE("(%p) Relay\n", This);
141
142     wined3d_mutex_lock();
143     ret = IWineD3DBuffer_GetPriority(This->wineD3DIndexBuffer);
144     wined3d_mutex_unlock();
145
146     return ret;
147 }
148
149 static void WINAPI IDirect3DIndexBuffer9Impl_PreLoad(LPDIRECT3DINDEXBUFFER9 iface) {
150     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
151     TRACE("(%p) Relay\n", This);
152
153     wined3d_mutex_lock();
154     IWineD3DBuffer_PreLoad(This->wineD3DIndexBuffer);
155     wined3d_mutex_unlock();
156 }
157
158 static D3DRESOURCETYPE WINAPI IDirect3DIndexBuffer9Impl_GetType(LPDIRECT3DINDEXBUFFER9 iface) {
159     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
160     TRACE("(%p)\n", This);
161
162     return D3DRTYPE_INDEXBUFFER;
163 }
164
165 /* IDirect3DIndexBuffer9 Interface follow: */
166 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_Lock(LPDIRECT3DINDEXBUFFER9 iface, UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags) {
167     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
168     HRESULT hr;
169     TRACE("(%p) Relay\n", This);
170
171     wined3d_mutex_lock();
172     hr = IWineD3DBuffer_Map(This->wineD3DIndexBuffer, OffsetToLock, SizeToLock, (BYTE **)ppbData, Flags);
173     wined3d_mutex_unlock();
174
175     return hr;
176 }
177
178 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_Unlock(LPDIRECT3DINDEXBUFFER9 iface) {
179     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
180     HRESULT hr;
181     TRACE("(%p) Relay\n", This);
182
183     wined3d_mutex_lock();
184     hr = IWineD3DBuffer_Unmap(This->wineD3DIndexBuffer);
185     wined3d_mutex_unlock();
186
187     return hr;
188 }
189
190 static HRESULT  WINAPI        IDirect3DIndexBuffer9Impl_GetDesc(LPDIRECT3DINDEXBUFFER9 iface, D3DINDEXBUFFER_DESC *pDesc) {
191     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
192     HRESULT hr;
193     WINED3DBUFFER_DESC desc;
194     TRACE("(%p) Relay\n", This);
195
196     wined3d_mutex_lock();
197     hr = IWineD3DBuffer_GetDesc(This->wineD3DIndexBuffer, &desc);
198     wined3d_mutex_unlock();
199
200     if (SUCCEEDED(hr)) {
201         pDesc->Format = d3dformat_from_wined3dformat(This->format);
202         pDesc->Usage = desc.Usage;
203         pDesc->Pool = desc.Pool;
204         pDesc->Size = desc.Size;
205         pDesc->Type = D3DRTYPE_INDEXBUFFER;
206     }
207
208     return hr;
209 }
210
211
212 static const IDirect3DIndexBuffer9Vtbl Direct3DIndexBuffer9_Vtbl =
213 {
214     /* IUnknown */
215     IDirect3DIndexBuffer9Impl_QueryInterface,
216     IDirect3DIndexBuffer9Impl_AddRef,
217     IDirect3DIndexBuffer9Impl_Release,
218     /* IDirect3DResource9 */
219     IDirect3DIndexBuffer9Impl_GetDevice,
220     IDirect3DIndexBuffer9Impl_SetPrivateData,
221     IDirect3DIndexBuffer9Impl_GetPrivateData,
222     IDirect3DIndexBuffer9Impl_FreePrivateData,
223     IDirect3DIndexBuffer9Impl_SetPriority,
224     IDirect3DIndexBuffer9Impl_GetPriority,
225     IDirect3DIndexBuffer9Impl_PreLoad,
226     IDirect3DIndexBuffer9Impl_GetType,
227     /* IDirect3DIndexBuffer9 */
228     IDirect3DIndexBuffer9Impl_Lock,
229     IDirect3DIndexBuffer9Impl_Unlock,
230     IDirect3DIndexBuffer9Impl_GetDesc
231 };
232
233
234 /* IDirect3DDevice9 IDirect3DIndexBuffer9 Methods follow: */
235 HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(IDirect3DDevice9Ex *iface, UINT Length, DWORD Usage,
236         D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer9 **ppIndexBuffer, HANDLE *pSharedHandle)
237 {
238     IDirect3DIndexBuffer9Impl *object;
239     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
240     HRESULT hrc = D3D_OK;
241
242     TRACE("(%p) Relay\n", This);
243     /* Allocate the storage for the device */
244     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
245     if (NULL == object) {
246         FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
247         return D3DERR_OUTOFVIDEOMEMORY;
248     }
249
250     object->lpVtbl = &Direct3DIndexBuffer9_Vtbl;
251     object->ref = 1;
252     object->format = wined3dformat_from_d3dformat(Format);
253     TRACE("Calling wined3d create index buffer\n");
254
255     wined3d_mutex_lock();
256     hrc = IWineD3DDevice_CreateIndexBuffer(This->WineD3DDevice, Length, Usage & WINED3DUSAGE_MASK,
257             (WINED3DPOOL)Pool, &object->wineD3DIndexBuffer, (IUnknown *)object);
258     wined3d_mutex_unlock();
259
260     if (hrc != D3D_OK) {
261
262         /* free up object */
263         FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This);
264         HeapFree(GetProcessHeap(), 0, object);
265     } else {
266         IDirect3DDevice9Ex_AddRef(iface);
267         object->parentDevice = iface;
268         *ppIndexBuffer = (LPDIRECT3DINDEXBUFFER9) object;
269         TRACE("(%p) : Created index buffer %p\n", This, object);
270     }
271     return hrc;
272 }