VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/indexbuffer.c@ 16477

Last change on this file since 16477 was 16477, checked in by vboxsync, 16 years ago

LGPL disclaimer by filemuncher

  • Property svn:eol-style set to native
File size: 9.6 KB
Line 
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/*
23 * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
24 * other than GPL or LGPL is available it will apply instead, Sun elects to use only
25 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
26 * a choice of LGPL license versions is made available with the language indicating
27 * that LGPLv2 or any later version may be used, or where a choice of which version
28 * of the LGPL is applied is otherwise unspecified.
29 */
30
31#include "config.h"
32#include "d3d9_private.h"
33
34WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
35
36/* IDirect3DIndexBuffer9 IUnknown parts follow: */
37static HRESULT WINAPI IDirect3DIndexBuffer9Impl_QueryInterface(LPDIRECT3DINDEXBUFFER9 iface, REFIID riid, LPVOID* ppobj) {
38 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
39
40 if (IsEqualGUID(riid, &IID_IUnknown)
41 || IsEqualGUID(riid, &IID_IDirect3DResource9)
42 || IsEqualGUID(riid, &IID_IDirect3DIndexBuffer9)) {
43 IDirect3DIndexBuffer9_AddRef(iface);
44 *ppobj = This;
45 return S_OK;
46 }
47
48 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
49 *ppobj = NULL;
50 return E_NOINTERFACE;
51}
52
53static ULONG WINAPI IDirect3DIndexBuffer9Impl_AddRef(LPDIRECT3DINDEXBUFFER9 iface) {
54 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
55 ULONG ref = InterlockedIncrement(&This->ref);
56
57 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
58
59 return ref;
60}
61
62static ULONG WINAPI IDirect3DIndexBuffer9Impl_Release(LPDIRECT3DINDEXBUFFER9 iface) {
63 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
64 ULONG ref = InterlockedDecrement(&This->ref);
65
66 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
67
68 if (ref == 0) {
69 EnterCriticalSection(&d3d9_cs);
70 IWineD3DIndexBuffer_Release(This->wineD3DIndexBuffer);
71 LeaveCriticalSection(&d3d9_cs);
72 IDirect3DDevice9Ex_Release(This->parentDevice);
73 HeapFree(GetProcessHeap(), 0, This);
74 }
75 return ref;
76}
77
78/* IDirect3DIndexBuffer9 IDirect3DResource9 Interface follow: */
79static HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetDevice(LPDIRECT3DINDEXBUFFER9 iface, IDirect3DDevice9** ppDevice) {
80 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
81 HRESULT hr;
82 TRACE("(%p) Relay\n", This);
83
84 EnterCriticalSection(&d3d9_cs);
85 hr = IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9) This, ppDevice);
86 LeaveCriticalSection(&d3d9_cs);
87 return hr;
88}
89
90static HRESULT WINAPI IDirect3DIndexBuffer9Impl_SetPrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
91 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
92 HRESULT hr;
93 TRACE("(%p) Relay\n", This);
94
95 EnterCriticalSection(&d3d9_cs);
96 hr = IWineD3DIndexBuffer_SetPrivateData(This->wineD3DIndexBuffer, refguid, pData, SizeOfData, Flags);
97 LeaveCriticalSection(&d3d9_cs);
98 return hr;
99}
100
101static 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 EnterCriticalSection(&d3d9_cs);
107 hr = IWineD3DIndexBuffer_GetPrivateData(This->wineD3DIndexBuffer, refguid, pData, pSizeOfData);
108 LeaveCriticalSection(&d3d9_cs);
109 return hr;
110}
111
112static HRESULT WINAPI IDirect3DIndexBuffer9Impl_FreePrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid) {
113 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
114 HRESULT hr;
115 TRACE("(%p) Relay\n", This);
116
117 EnterCriticalSection(&d3d9_cs);
118 hr = IWineD3DIndexBuffer_FreePrivateData(This->wineD3DIndexBuffer, refguid);
119 LeaveCriticalSection(&d3d9_cs);
120 return hr;
121}
122
123static DWORD WINAPI IDirect3DIndexBuffer9Impl_SetPriority(LPDIRECT3DINDEXBUFFER9 iface, DWORD PriorityNew) {
124 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
125 DWORD ret;
126 TRACE("(%p) Relay\n", This);
127
128 EnterCriticalSection(&d3d9_cs);
129 ret = IWineD3DIndexBuffer_SetPriority(This->wineD3DIndexBuffer, PriorityNew);
130 LeaveCriticalSection(&d3d9_cs);
131 return ret;
132}
133
134static DWORD WINAPI IDirect3DIndexBuffer9Impl_GetPriority(LPDIRECT3DINDEXBUFFER9 iface) {
135 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
136 DWORD ret;
137 TRACE("(%p) Relay\n", This);
138
139 EnterCriticalSection(&d3d9_cs);
140 ret = IWineD3DIndexBuffer_GetPriority(This->wineD3DIndexBuffer);
141 LeaveCriticalSection(&d3d9_cs);
142 return ret;
143}
144
145static void WINAPI IDirect3DIndexBuffer9Impl_PreLoad(LPDIRECT3DINDEXBUFFER9 iface) {
146 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
147 TRACE("(%p) Relay\n", This);
148
149 EnterCriticalSection(&d3d9_cs);
150 IWineD3DIndexBuffer_PreLoad(This->wineD3DIndexBuffer);
151 LeaveCriticalSection(&d3d9_cs);
152}
153
154static D3DRESOURCETYPE WINAPI IDirect3DIndexBuffer9Impl_GetType(LPDIRECT3DINDEXBUFFER9 iface) {
155 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
156 D3DRESOURCETYPE ret;
157 TRACE("(%p) Relay\n", This);
158
159 EnterCriticalSection(&d3d9_cs);
160 ret = IWineD3DIndexBuffer_GetType(This->wineD3DIndexBuffer);
161 LeaveCriticalSection(&d3d9_cs);
162 return ret;
163}
164
165/* IDirect3DIndexBuffer9 Interface follow: */
166static 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 EnterCriticalSection(&d3d9_cs);
172 hr = IWineD3DIndexBuffer_Lock(This->wineD3DIndexBuffer, OffsetToLock, SizeToLock, (BYTE **)ppbData, Flags);
173 LeaveCriticalSection(&d3d9_cs);
174 return hr;
175}
176
177static HRESULT WINAPI IDirect3DIndexBuffer9Impl_Unlock(LPDIRECT3DINDEXBUFFER9 iface) {
178 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
179 HRESULT hr;
180 TRACE("(%p) Relay\n", This);
181
182 EnterCriticalSection(&d3d9_cs);
183 hr = IWineD3DIndexBuffer_Unlock(This->wineD3DIndexBuffer);
184 LeaveCriticalSection(&d3d9_cs);
185 return hr;
186}
187
188static HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetDesc(LPDIRECT3DINDEXBUFFER9 iface, D3DINDEXBUFFER_DESC *pDesc) {
189 IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
190 HRESULT hr;
191 TRACE("(%p) Relay\n", This);
192
193 EnterCriticalSection(&d3d9_cs);
194 hr = IWineD3DIndexBuffer_GetDesc(This->wineD3DIndexBuffer, (WINED3DINDEXBUFFER_DESC *) pDesc);
195 LeaveCriticalSection(&d3d9_cs);
196 return hr;
197}
198
199
200static const IDirect3DIndexBuffer9Vtbl Direct3DIndexBuffer9_Vtbl =
201{
202 /* IUnknown */
203 IDirect3DIndexBuffer9Impl_QueryInterface,
204 IDirect3DIndexBuffer9Impl_AddRef,
205 IDirect3DIndexBuffer9Impl_Release,
206 /* IDirect3DResource9 */
207 IDirect3DIndexBuffer9Impl_GetDevice,
208 IDirect3DIndexBuffer9Impl_SetPrivateData,
209 IDirect3DIndexBuffer9Impl_GetPrivateData,
210 IDirect3DIndexBuffer9Impl_FreePrivateData,
211 IDirect3DIndexBuffer9Impl_SetPriority,
212 IDirect3DIndexBuffer9Impl_GetPriority,
213 IDirect3DIndexBuffer9Impl_PreLoad,
214 IDirect3DIndexBuffer9Impl_GetType,
215 /* IDirect3DIndexBuffer9 */
216 IDirect3DIndexBuffer9Impl_Lock,
217 IDirect3DIndexBuffer9Impl_Unlock,
218 IDirect3DIndexBuffer9Impl_GetDesc
219};
220
221
222/* IDirect3DDevice9 IDirect3DIndexBuffer9 Methods follow: */
223HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(LPDIRECT3DDEVICE9EX iface,
224 UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool,
225 IDirect3DIndexBuffer9** ppIndexBuffer, HANDLE* pSharedHandle) {
226
227 IDirect3DIndexBuffer9Impl *object;
228 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
229 HRESULT hrc = D3D_OK;
230
231 TRACE("(%p) Relay\n", This);
232 /* Allocate the storage for the device */
233 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
234 if (NULL == object) {
235 FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
236 return D3DERR_OUTOFVIDEOMEMORY;
237 }
238
239 object->lpVtbl = &Direct3DIndexBuffer9_Vtbl;
240 object->ref = 1;
241 TRACE("Calling wined3d create index buffer\n");
242 hrc = IWineD3DDevice_CreateIndexBuffer(This->WineD3DDevice, Length, Usage & WINED3DUSAGE_MASK, Format, (WINED3DPOOL) Pool, &object->wineD3DIndexBuffer, pSharedHandle, (IUnknown *)object);
243 if (hrc != D3D_OK) {
244
245 /* free up object */
246 FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This);
247 HeapFree(GetProcessHeap(), 0, object);
248 } else {
249 IDirect3DDevice9Ex_AddRef(iface);
250 object->parentDevice = iface;
251 *ppIndexBuffer = (LPDIRECT3DINDEXBUFFER9) object;
252 TRACE("(%p) : Created index buffer %p\n", This, object);
253 }
254 return hrc;
255}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette