~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/d3d9/indexbuffer.c

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  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     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
 32 
 33     if (IsEqualGUID(riid, &IID_IUnknown)
 34         || IsEqualGUID(riid, &IID_IDirect3DResource9)
 35         || IsEqualGUID(riid, &IID_IDirect3DIndexBuffer9)) {
 36         IDirect3DIndexBuffer9_AddRef(iface);
 37         *ppobj = This;
 38         return S_OK;
 39     }
 40 
 41     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
 42     *ppobj = NULL;
 43     return E_NOINTERFACE;
 44 }
 45 
 46 static ULONG WINAPI IDirect3DIndexBuffer9Impl_AddRef(LPDIRECT3DINDEXBUFFER9 iface) {
 47     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
 48     ULONG ref = InterlockedIncrement(&This->ref);
 49 
 50     TRACE("%p increasing refcount to %u.\n", iface, ref);
 51 
 52     if (ref == 1)
 53     {
 54         IDirect3DDevice9Ex_AddRef(This->parentDevice);
 55         wined3d_mutex_lock();
 56         IWineD3DBuffer_AddRef(This->wineD3DIndexBuffer);
 57         wined3d_mutex_unlock();
 58     }
 59 
 60     return ref;
 61 }
 62 
 63 static ULONG WINAPI IDirect3DIndexBuffer9Impl_Release(LPDIRECT3DINDEXBUFFER9 iface) {
 64     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
 65     ULONG ref = InterlockedDecrement(&This->ref);
 66 
 67     TRACE("%p decreasing refcount to %u.\n", iface, ref);
 68 
 69     if (ref == 0) {
 70         IDirect3DDevice9Ex *parentDevice = This->parentDevice;
 71 
 72         wined3d_mutex_lock();
 73         IWineD3DBuffer_Release(This->wineD3DIndexBuffer);
 74         wined3d_mutex_unlock();
 75 
 76         /* Release the device last, as it may cause the device to be destroyed. */
 77         IDirect3DDevice9Ex_Release(parentDevice);
 78     }
 79     return ref;
 80 }
 81 
 82 /* IDirect3DIndexBuffer9 IDirect3DResource9 Interface follow: */
 83 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetDevice(LPDIRECT3DINDEXBUFFER9 iface, IDirect3DDevice9** ppDevice) {
 84     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
 85     IWineD3DDevice *wined3d_device;
 86     HRESULT hr;
 87 
 88     TRACE("iface %p, device %p.\n", iface, ppDevice);
 89 
 90     wined3d_mutex_lock();
 91     hr = IWineD3DBuffer_GetDevice(This->wineD3DIndexBuffer, &wined3d_device);
 92     if (SUCCEEDED(hr))
 93     {
 94         IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
 95         IWineD3DDevice_Release(wined3d_device);
 96     }
 97     wined3d_mutex_unlock();
 98 
 99     return hr;
100 }
101 
102 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_SetPrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
103     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
104     HRESULT hr;
105 
106     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
107             iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
108 
109     wined3d_mutex_lock();
110     hr = IWineD3DBuffer_SetPrivateData(This->wineD3DIndexBuffer, refguid, pData, SizeOfData, Flags);
111     wined3d_mutex_unlock();
112 
113     return hr;
114 }
115 
116 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetPrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
117     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
118     HRESULT hr;
119 
120     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
121             iface, debugstr_guid(refguid), pData, pSizeOfData);
122 
123     wined3d_mutex_lock();
124     hr = IWineD3DBuffer_GetPrivateData(This->wineD3DIndexBuffer, refguid, pData, pSizeOfData);
125     wined3d_mutex_unlock();
126 
127     return hr;
128 }
129 
130 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_FreePrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid) {
131     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
132     HRESULT hr;
133 
134     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
135 
136     wined3d_mutex_lock();
137     hr = IWineD3DBuffer_FreePrivateData(This->wineD3DIndexBuffer, refguid);
138     wined3d_mutex_unlock();
139 
140     return hr;
141 }
142 
143 static DWORD WINAPI IDirect3DIndexBuffer9Impl_SetPriority(LPDIRECT3DINDEXBUFFER9 iface, DWORD PriorityNew) {
144     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
145     DWORD ret;
146 
147     TRACE("iface %p, priority %u.\n", iface, PriorityNew);
148 
149     wined3d_mutex_lock();
150     ret = IWineD3DBuffer_SetPriority(This->wineD3DIndexBuffer, PriorityNew);
151     wined3d_mutex_unlock();
152 
153     return ret;
154 }
155 
156 static DWORD WINAPI IDirect3DIndexBuffer9Impl_GetPriority(LPDIRECT3DINDEXBUFFER9 iface) {
157     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
158     DWORD ret;
159 
160     TRACE("iface %p.\n", iface);
161 
162     wined3d_mutex_lock();
163     ret = IWineD3DBuffer_GetPriority(This->wineD3DIndexBuffer);
164     wined3d_mutex_unlock();
165 
166     return ret;
167 }
168 
169 static void WINAPI IDirect3DIndexBuffer9Impl_PreLoad(LPDIRECT3DINDEXBUFFER9 iface) {
170     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
171 
172     TRACE("iface %p.\n", iface);
173 
174     wined3d_mutex_lock();
175     IWineD3DBuffer_PreLoad(This->wineD3DIndexBuffer);
176     wined3d_mutex_unlock();
177 }
178 
179 static D3DRESOURCETYPE WINAPI IDirect3DIndexBuffer9Impl_GetType(IDirect3DIndexBuffer9 *iface)
180 {
181     TRACE("iface %p.\n", iface);
182 
183     return D3DRTYPE_INDEXBUFFER;
184 }
185 
186 /* IDirect3DIndexBuffer9 Interface follow: */
187 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_Lock(LPDIRECT3DINDEXBUFFER9 iface, UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags) {
188     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
189     HRESULT hr;
190 
191     TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
192             iface, OffsetToLock, SizeToLock, ppbData, Flags);
193 
194     wined3d_mutex_lock();
195     hr = IWineD3DBuffer_Map(This->wineD3DIndexBuffer, OffsetToLock, SizeToLock, (BYTE **)ppbData, Flags);
196     wined3d_mutex_unlock();
197 
198     return hr;
199 }
200 
201 static HRESULT WINAPI IDirect3DIndexBuffer9Impl_Unlock(LPDIRECT3DINDEXBUFFER9 iface) {
202     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
203     HRESULT hr;
204 
205     TRACE("iface %p.\n", iface);
206 
207     wined3d_mutex_lock();
208     hr = IWineD3DBuffer_Unmap(This->wineD3DIndexBuffer);
209     wined3d_mutex_unlock();
210 
211     return hr;
212 }
213 
214 static HRESULT  WINAPI        IDirect3DIndexBuffer9Impl_GetDesc(LPDIRECT3DINDEXBUFFER9 iface, D3DINDEXBUFFER_DESC *pDesc) {
215     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
216     HRESULT hr;
217     WINED3DBUFFER_DESC desc;
218 
219     TRACE("iface %p, desc %p.\n", iface, pDesc);
220 
221     wined3d_mutex_lock();
222     hr = IWineD3DBuffer_GetDesc(This->wineD3DIndexBuffer, &desc);
223     wined3d_mutex_unlock();
224 
225     if (SUCCEEDED(hr)) {
226         pDesc->Format = d3dformat_from_wined3dformat(This->format);
227         pDesc->Usage = desc.Usage;
228         pDesc->Pool = desc.Pool;
229         pDesc->Size = desc.Size;
230         pDesc->Type = D3DRTYPE_INDEXBUFFER;
231     }
232 
233     return hr;
234 }
235 
236 
237 static const IDirect3DIndexBuffer9Vtbl Direct3DIndexBuffer9_Vtbl =
238 {
239     /* IUnknown */
240     IDirect3DIndexBuffer9Impl_QueryInterface,
241     IDirect3DIndexBuffer9Impl_AddRef,
242     IDirect3DIndexBuffer9Impl_Release,
243     /* IDirect3DResource9 */
244     IDirect3DIndexBuffer9Impl_GetDevice,
245     IDirect3DIndexBuffer9Impl_SetPrivateData,
246     IDirect3DIndexBuffer9Impl_GetPrivateData,
247     IDirect3DIndexBuffer9Impl_FreePrivateData,
248     IDirect3DIndexBuffer9Impl_SetPriority,
249     IDirect3DIndexBuffer9Impl_GetPriority,
250     IDirect3DIndexBuffer9Impl_PreLoad,
251     IDirect3DIndexBuffer9Impl_GetType,
252     /* IDirect3DIndexBuffer9 */
253     IDirect3DIndexBuffer9Impl_Lock,
254     IDirect3DIndexBuffer9Impl_Unlock,
255     IDirect3DIndexBuffer9Impl_GetDesc
256 };
257 
258 static void STDMETHODCALLTYPE d3d9_indexbuffer_wined3d_object_destroyed(void *parent)
259 {
260     HeapFree(GetProcessHeap(), 0, parent);
261 }
262 
263 static const struct wined3d_parent_ops d3d9_indexbuffer_wined3d_parent_ops =
264 {
265     d3d9_indexbuffer_wined3d_object_destroyed,
266 };
267 
268 HRESULT indexbuffer_init(IDirect3DIndexBuffer9Impl *buffer, IDirect3DDevice9Impl *device,
269         UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool)
270 {
271     HRESULT hr;
272 
273     buffer->lpVtbl = &Direct3DIndexBuffer9_Vtbl;
274     buffer->ref = 1;
275     buffer->format = wined3dformat_from_d3dformat(format);
276 
277     wined3d_mutex_lock();
278     hr = IWineD3DDevice_CreateIndexBuffer(device->WineD3DDevice, size,
279             usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool, &buffer->wineD3DIndexBuffer,
280             (IUnknown *)buffer, &d3d9_indexbuffer_wined3d_parent_ops);
281     wined3d_mutex_unlock();
282     if (FAILED(hr))
283     {
284         WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
285         return hr;
286     }
287 
288     buffer->parentDevice = (IDirect3DDevice9Ex *)device;
289     IDirect3DDevice9Ex_AddRef(buffer->parentDevice);
290 
291     return D3D_OK;
292 }
293 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.