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 |
|
---|
34 | WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
|
---|
35 |
|
---|
36 | /* IDirect3DIndexBuffer9 IUnknown parts follow: */
|
---|
37 | static 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 |
|
---|
53 | static 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 |
|
---|
62 | static 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 | IWineD3DBuffer_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: */
|
---|
79 | static HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetDevice(LPDIRECT3DINDEXBUFFER9 iface, IDirect3DDevice9** ppDevice) {
|
---|
80 | IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
|
---|
81 | IWineD3DDevice *wined3d_device;
|
---|
82 | HRESULT hr;
|
---|
83 | TRACE("(%p) Relay\n", This);
|
---|
84 |
|
---|
85 | EnterCriticalSection(&d3d9_cs);
|
---|
86 | hr = IWineD3DBuffer_GetDevice(This->wineD3DIndexBuffer, &wined3d_device);
|
---|
87 | if (SUCCEEDED(hr))
|
---|
88 | {
|
---|
89 | IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
|
---|
90 | IWineD3DDevice_Release(wined3d_device);
|
---|
91 | }
|
---|
92 | LeaveCriticalSection(&d3d9_cs);
|
---|
93 | return hr;
|
---|
94 | }
|
---|
95 |
|
---|
96 | static HRESULT WINAPI IDirect3DIndexBuffer9Impl_SetPrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
|
---|
97 | IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
|
---|
98 | HRESULT hr;
|
---|
99 | TRACE("(%p) Relay\n", This);
|
---|
100 |
|
---|
101 | EnterCriticalSection(&d3d9_cs);
|
---|
102 | hr = IWineD3DBuffer_SetPrivateData(This->wineD3DIndexBuffer, refguid, pData, SizeOfData, Flags);
|
---|
103 | LeaveCriticalSection(&d3d9_cs);
|
---|
104 | return hr;
|
---|
105 | }
|
---|
106 |
|
---|
107 | static HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetPrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
|
---|
108 | IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
|
---|
109 | HRESULT hr;
|
---|
110 | TRACE("(%p) Relay\n", This);
|
---|
111 |
|
---|
112 | EnterCriticalSection(&d3d9_cs);
|
---|
113 | hr = IWineD3DBuffer_GetPrivateData(This->wineD3DIndexBuffer, refguid, pData, pSizeOfData);
|
---|
114 | LeaveCriticalSection(&d3d9_cs);
|
---|
115 | return hr;
|
---|
116 | }
|
---|
117 |
|
---|
118 | static HRESULT WINAPI IDirect3DIndexBuffer9Impl_FreePrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid) {
|
---|
119 | IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
|
---|
120 | HRESULT hr;
|
---|
121 | TRACE("(%p) Relay\n", This);
|
---|
122 |
|
---|
123 | EnterCriticalSection(&d3d9_cs);
|
---|
124 | hr = IWineD3DBuffer_FreePrivateData(This->wineD3DIndexBuffer, refguid);
|
---|
125 | LeaveCriticalSection(&d3d9_cs);
|
---|
126 | return hr;
|
---|
127 | }
|
---|
128 |
|
---|
129 | static DWORD WINAPI IDirect3DIndexBuffer9Impl_SetPriority(LPDIRECT3DINDEXBUFFER9 iface, DWORD PriorityNew) {
|
---|
130 | IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
|
---|
131 | DWORD ret;
|
---|
132 | TRACE("(%p) Relay\n", This);
|
---|
133 |
|
---|
134 | EnterCriticalSection(&d3d9_cs);
|
---|
135 | ret = IWineD3DBuffer_SetPriority(This->wineD3DIndexBuffer, PriorityNew);
|
---|
136 | LeaveCriticalSection(&d3d9_cs);
|
---|
137 | return ret;
|
---|
138 | }
|
---|
139 |
|
---|
140 | static DWORD WINAPI IDirect3DIndexBuffer9Impl_GetPriority(LPDIRECT3DINDEXBUFFER9 iface) {
|
---|
141 | IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
|
---|
142 | DWORD ret;
|
---|
143 | TRACE("(%p) Relay\n", This);
|
---|
144 |
|
---|
145 | EnterCriticalSection(&d3d9_cs);
|
---|
146 | ret = IWineD3DBuffer_GetPriority(This->wineD3DIndexBuffer);
|
---|
147 | LeaveCriticalSection(&d3d9_cs);
|
---|
148 | return ret;
|
---|
149 | }
|
---|
150 |
|
---|
151 | static void WINAPI IDirect3DIndexBuffer9Impl_PreLoad(LPDIRECT3DINDEXBUFFER9 iface) {
|
---|
152 | IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
|
---|
153 | TRACE("(%p) Relay\n", This);
|
---|
154 |
|
---|
155 | EnterCriticalSection(&d3d9_cs);
|
---|
156 | IWineD3DBuffer_PreLoad(This->wineD3DIndexBuffer);
|
---|
157 | LeaveCriticalSection(&d3d9_cs);
|
---|
158 | }
|
---|
159 |
|
---|
160 | static D3DRESOURCETYPE WINAPI IDirect3DIndexBuffer9Impl_GetType(LPDIRECT3DINDEXBUFFER9 iface) {
|
---|
161 | IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
|
---|
162 | TRACE("(%p)\n", This);
|
---|
163 |
|
---|
164 | return D3DRTYPE_INDEXBUFFER;
|
---|
165 | }
|
---|
166 |
|
---|
167 | /* IDirect3DIndexBuffer9 Interface follow: */
|
---|
168 | static HRESULT WINAPI IDirect3DIndexBuffer9Impl_Lock(LPDIRECT3DINDEXBUFFER9 iface, UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags) {
|
---|
169 | IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
|
---|
170 | HRESULT hr;
|
---|
171 | TRACE("(%p) Relay\n", This);
|
---|
172 |
|
---|
173 | EnterCriticalSection(&d3d9_cs);
|
---|
174 | hr = IWineD3DBuffer_Map(This->wineD3DIndexBuffer, OffsetToLock, SizeToLock, (BYTE **)ppbData, Flags);
|
---|
175 | LeaveCriticalSection(&d3d9_cs);
|
---|
176 | return hr;
|
---|
177 | }
|
---|
178 |
|
---|
179 | static HRESULT WINAPI IDirect3DIndexBuffer9Impl_Unlock(LPDIRECT3DINDEXBUFFER9 iface) {
|
---|
180 | IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
|
---|
181 | HRESULT hr;
|
---|
182 | TRACE("(%p) Relay\n", This);
|
---|
183 |
|
---|
184 | EnterCriticalSection(&d3d9_cs);
|
---|
185 | hr = IWineD3DBuffer_Unmap(This->wineD3DIndexBuffer);
|
---|
186 | LeaveCriticalSection(&d3d9_cs);
|
---|
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 | EnterCriticalSection(&d3d9_cs);
|
---|
197 | hr = IWineD3DBuffer_GetDesc(This->wineD3DIndexBuffer, &desc);
|
---|
198 | LeaveCriticalSection(&d3d9_cs);
|
---|
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(LPDIRECT3DDEVICE9EX iface,
|
---|
236 | UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool,
|
---|
237 | IDirect3DIndexBuffer9** ppIndexBuffer, HANDLE* pSharedHandle) {
|
---|
238 |
|
---|
239 | IDirect3DIndexBuffer9Impl *object;
|
---|
240 | IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
|
---|
241 | HRESULT hrc = D3D_OK;
|
---|
242 |
|
---|
243 | TRACE("(%p) Relay\n", This);
|
---|
244 | /* Allocate the storage for the device */
|
---|
245 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
---|
246 | if (NULL == object) {
|
---|
247 | FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
|
---|
248 | return D3DERR_OUTOFVIDEOMEMORY;
|
---|
249 | }
|
---|
250 |
|
---|
251 | object->lpVtbl = &Direct3DIndexBuffer9_Vtbl;
|
---|
252 | object->ref = 1;
|
---|
253 | object->format = wined3dformat_from_d3dformat(Format);
|
---|
254 | TRACE("Calling wined3d create index buffer\n");
|
---|
255 | EnterCriticalSection(&d3d9_cs);
|
---|
256 | hrc = IWineD3DDevice_CreateIndexBuffer(This->WineD3DDevice, Length, Usage & WINED3DUSAGE_MASK,
|
---|
257 | (WINED3DPOOL)Pool, &object->wineD3DIndexBuffer, (IUnknown *)object);
|
---|
258 | LeaveCriticalSection(&d3d9_cs);
|
---|
259 | if (hrc != D3D_OK) {
|
---|
260 |
|
---|
261 | /* free up object */
|
---|
262 | FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This);
|
---|
263 | HeapFree(GetProcessHeap(), 0, object);
|
---|
264 | } else {
|
---|
265 | IDirect3DDevice9Ex_AddRef(iface);
|
---|
266 | object->parentDevice = iface;
|
---|
267 | *ppIndexBuffer = (LPDIRECT3DINDEXBUFFER9) object;
|
---|
268 | TRACE("(%p) : Created index buffer %p\n", This, object);
|
---|
269 | }
|
---|
270 | return hrc;
|
---|
271 | }
|
---|