usp10: Correct matra type for Oriya 0x0B57.
[wine/multimedia.git] / dlls / d3d9 / buffer.c
blobd9a5564d57787bc1280928e11e0045bf89de42c5
1 /*
2 * Copyright 2002-2004 Jason Edmeades
3 * Copyright 2002-2004 Raphael Junqueira
4 * Copyright 2005 Oliver Stieber
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.
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.
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
21 #include "config.h"
22 #include "d3d9_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
26 static HRESULT WINAPI d3d9_vertexbuffer_QueryInterface(IDirect3DVertexBuffer9 *iface, REFIID riid, void **object)
28 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
30 if (IsEqualGUID(riid, &IID_IDirect3DVertexBuffer9)
31 || IsEqualGUID(riid, &IID_IDirect3DResource9)
32 || IsEqualGUID(riid, &IID_IUnknown))
34 IDirect3DVertexBuffer9_AddRef(iface);
35 *object = iface;
36 return S_OK;
39 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
41 *object = NULL;
42 return E_NOINTERFACE;
45 static ULONG WINAPI d3d9_vertexbuffer_AddRef(IDirect3DVertexBuffer9 *iface)
47 IDirect3DVertexBuffer9Impl *buffer = (IDirect3DVertexBuffer9Impl *)iface;
48 ULONG refcount = InterlockedIncrement(&buffer->ref);
50 TRACE("%p increasing refcount to %u.\n", iface, refcount);
52 if (refcount == 1)
54 IDirect3DDevice9Ex_AddRef(buffer->parentDevice);
55 wined3d_mutex_lock();
56 wined3d_buffer_incref(buffer->wineD3DVertexBuffer);
57 wined3d_mutex_unlock();
60 return refcount;
63 static ULONG WINAPI d3d9_vertexbuffer_Release(IDirect3DVertexBuffer9 *iface)
65 IDirect3DVertexBuffer9Impl *buffer = (IDirect3DVertexBuffer9Impl *)iface;
66 ULONG refcount = InterlockedDecrement(&buffer->ref);
68 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
70 if (!refcount)
72 IDirect3DDevice9Ex *device = buffer->parentDevice;
74 wined3d_mutex_lock();
75 wined3d_buffer_decref(buffer->wineD3DVertexBuffer);
76 wined3d_mutex_unlock();
78 /* Release the device last, as it may cause the device to be destroyed. */
79 IDirect3DDevice9Ex_Release(device);
82 return refcount;
85 static HRESULT WINAPI d3d9_vertexbuffer_GetDevice(IDirect3DVertexBuffer9 *iface, IDirect3DDevice9 **device)
87 TRACE("iface %p, device %p.\n", iface, device);
89 *device = (IDirect3DDevice9 *)((IDirect3DVertexBuffer9Impl *)iface)->parentDevice;
90 IDirect3DDevice9_AddRef(*device);
92 TRACE("Returning device %p.\n", *device);
94 return D3D_OK;
97 static HRESULT WINAPI d3d9_vertexbuffer_SetPrivateData(IDirect3DVertexBuffer9 *iface,
98 REFGUID guid, const void *data, DWORD data_size, DWORD flags)
100 HRESULT hr;
102 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
103 iface, debugstr_guid(guid), data, data_size, flags);
105 wined3d_mutex_lock();
106 hr = wined3d_buffer_set_private_data(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer,
107 guid, data, data_size, flags);
108 wined3d_mutex_unlock();
110 return hr;
113 static HRESULT WINAPI d3d9_vertexbuffer_GetPrivateData(IDirect3DVertexBuffer9 *iface,
114 REFGUID guid, void *data, DWORD *data_size)
116 HRESULT hr;
118 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
119 iface, debugstr_guid(guid), data, data_size);
121 wined3d_mutex_lock();
122 hr = wined3d_buffer_get_private_data(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer,
123 guid, data, data_size);
124 wined3d_mutex_unlock();
126 return hr;
129 static HRESULT WINAPI d3d9_vertexbuffer_FreePrivateData(IDirect3DVertexBuffer9 *iface, REFGUID guid)
131 HRESULT hr;
133 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
135 wined3d_mutex_lock();
136 hr = wined3d_buffer_free_private_data(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer, guid);
137 wined3d_mutex_unlock();
139 return hr;
142 static DWORD WINAPI d3d9_vertexbuffer_SetPriority(IDirect3DVertexBuffer9 *iface, DWORD priority)
144 DWORD previous;
146 TRACE("iface %p, priority %u.\n", iface, priority);
148 wined3d_mutex_lock();
149 previous = wined3d_buffer_set_priority(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer, priority);
150 wined3d_mutex_unlock();
152 return previous;
155 static DWORD WINAPI d3d9_vertexbuffer_GetPriority(IDirect3DVertexBuffer9 *iface)
157 DWORD priority;
159 TRACE("iface %p.\n", iface);
161 wined3d_mutex_lock();
162 priority = wined3d_buffer_get_priority(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer);
163 wined3d_mutex_unlock();
165 return priority;
168 static void WINAPI d3d9_vertexbuffer_PreLoad(IDirect3DVertexBuffer9 *iface)
170 TRACE("iface %p.\n", iface);
172 wined3d_mutex_lock();
173 wined3d_buffer_preload(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer);
174 wined3d_mutex_unlock();
177 static D3DRESOURCETYPE WINAPI d3d9_vertexbuffer_GetType(IDirect3DVertexBuffer9 *iface)
179 TRACE("iface %p.\n", iface);
181 return D3DRTYPE_VERTEXBUFFER;
184 static HRESULT WINAPI d3d9_vertexbuffer_Lock(IDirect3DVertexBuffer9 *iface,
185 UINT offset, UINT size, void **data, DWORD flags)
187 HRESULT hr;
189 TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
190 iface, offset, size, data, flags);
192 wined3d_mutex_lock();
193 hr = wined3d_buffer_map(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer,
194 offset, size, (BYTE **)data, flags);
195 wined3d_mutex_unlock();
197 return hr;
200 static HRESULT WINAPI d3d9_vertexbuffer_Unlock(IDirect3DVertexBuffer9 *iface)
202 TRACE("iface %p.\n", iface);
204 wined3d_mutex_lock();
205 wined3d_buffer_unmap(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer);
206 wined3d_mutex_unlock();
208 return D3D_OK;
211 static HRESULT WINAPI d3d9_vertexbuffer_GetDesc(IDirect3DVertexBuffer9 *iface, D3DVERTEXBUFFER_DESC *desc)
213 IDirect3DVertexBuffer9Impl *buffer = (IDirect3DVertexBuffer9Impl *)iface;
214 struct wined3d_resource_desc wined3d_desc;
215 struct wined3d_resource *wined3d_resource;
217 TRACE("iface %p, desc %p.\n", iface, desc);
219 wined3d_mutex_lock();
220 wined3d_resource = wined3d_buffer_get_resource(buffer->wineD3DVertexBuffer);
221 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
222 wined3d_mutex_unlock();
224 desc->Format = D3DFMT_VERTEXDATA;
225 desc->Usage = wined3d_desc.usage;
226 desc->Pool = wined3d_desc.pool;
227 desc->Size = wined3d_desc.size;
228 desc->Type = D3DRTYPE_VERTEXBUFFER;
229 desc->FVF = buffer->fvf;
231 return D3D_OK;
234 static const IDirect3DVertexBuffer9Vtbl d3d9_vertexbuffer_vtbl =
236 /* IUnknown */
237 d3d9_vertexbuffer_QueryInterface,
238 d3d9_vertexbuffer_AddRef,
239 d3d9_vertexbuffer_Release,
240 /* IDirect3DResource9 */
241 d3d9_vertexbuffer_GetDevice,
242 d3d9_vertexbuffer_SetPrivateData,
243 d3d9_vertexbuffer_GetPrivateData,
244 d3d9_vertexbuffer_FreePrivateData,
245 d3d9_vertexbuffer_SetPriority,
246 d3d9_vertexbuffer_GetPriority,
247 d3d9_vertexbuffer_PreLoad,
248 d3d9_vertexbuffer_GetType,
249 /* IDirect3DVertexBuffer9 */
250 d3d9_vertexbuffer_Lock,
251 d3d9_vertexbuffer_Unlock,
252 d3d9_vertexbuffer_GetDesc,
255 static void STDMETHODCALLTYPE d3d9_vertexbuffer_wined3d_object_destroyed(void *parent)
257 HeapFree(GetProcessHeap(), 0, parent);
260 static const struct wined3d_parent_ops d3d9_vertexbuffer_wined3d_parent_ops =
262 d3d9_vertexbuffer_wined3d_object_destroyed,
265 HRESULT vertexbuffer_init(IDirect3DVertexBuffer9Impl *buffer, IDirect3DDevice9Impl *device,
266 UINT size, UINT usage, DWORD fvf, D3DPOOL pool)
268 HRESULT hr;
270 buffer->lpVtbl = &d3d9_vertexbuffer_vtbl;
271 buffer->ref = 1;
272 buffer->fvf = fvf;
274 wined3d_mutex_lock();
275 hr = wined3d_buffer_create_vb(device->wined3d_device, size, usage & WINED3DUSAGE_MASK,
276 (WINED3DPOOL)pool, buffer, &d3d9_vertexbuffer_wined3d_parent_ops, &buffer->wineD3DVertexBuffer);
277 wined3d_mutex_unlock();
278 if (FAILED(hr))
280 WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
281 return hr;
284 buffer->parentDevice = &device->IDirect3DDevice9Ex_iface;
285 IDirect3DDevice9Ex_AddRef(buffer->parentDevice);
287 return D3D_OK;
290 static HRESULT WINAPI d3d9_indexbuffer_QueryInterface(IDirect3DIndexBuffer9 *iface, REFIID riid, void **object)
292 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
294 if (IsEqualGUID(riid, &IID_IDirect3DIndexBuffer9)
295 || IsEqualGUID(riid, &IID_IDirect3DResource9)
296 || IsEqualGUID(riid, &IID_IUnknown))
298 IDirect3DIndexBuffer9_AddRef(iface);
299 *object = iface;
300 return S_OK;
303 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
305 *object = NULL;
306 return E_NOINTERFACE;
309 static ULONG WINAPI d3d9_indexbuffer_AddRef(IDirect3DIndexBuffer9 *iface)
311 IDirect3DIndexBuffer9Impl *buffer = (IDirect3DIndexBuffer9Impl *)iface;
312 ULONG refcount = InterlockedIncrement(&buffer->ref);
314 TRACE("%p increasing refcount to %u.\n", iface, refcount);
316 if (refcount == 1)
318 IDirect3DDevice9Ex_AddRef(buffer->parentDevice);
319 wined3d_mutex_lock();
320 wined3d_buffer_incref(buffer->wineD3DIndexBuffer);
321 wined3d_mutex_unlock();
324 return refcount;
327 static ULONG WINAPI d3d9_indexbuffer_Release(IDirect3DIndexBuffer9 *iface)
329 IDirect3DIndexBuffer9Impl *buffer = (IDirect3DIndexBuffer9Impl *)iface;
330 ULONG refcount = InterlockedDecrement(&buffer->ref);
332 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
334 if (!refcount)
336 IDirect3DDevice9Ex *device = buffer->parentDevice;
338 wined3d_mutex_lock();
339 wined3d_buffer_decref(buffer->wineD3DIndexBuffer);
340 wined3d_mutex_unlock();
342 /* Release the device last, as it may cause the device to be destroyed. */
343 IDirect3DDevice9Ex_Release(device);
346 return refcount;
349 static HRESULT WINAPI d3d9_indexbuffer_GetDevice(IDirect3DIndexBuffer9 *iface, IDirect3DDevice9 **device)
351 TRACE("iface %p, device %p.\n", iface, device);
353 *device = (IDirect3DDevice9 *)((IDirect3DIndexBuffer9Impl *)iface)->parentDevice;
354 IDirect3DDevice9_AddRef(*device);
356 TRACE("Returning device %p.\n", *device);
358 return D3D_OK;
361 static HRESULT WINAPI d3d9_indexbuffer_SetPrivateData(IDirect3DIndexBuffer9 *iface,
362 REFGUID guid, const void *data, DWORD data_size, DWORD flags)
364 HRESULT hr;
366 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
367 iface, debugstr_guid(guid), data, data_size, flags);
369 wined3d_mutex_lock();
370 hr = wined3d_buffer_set_private_data(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer,
371 guid, data, data_size, flags);
372 wined3d_mutex_unlock();
374 return hr;
377 static HRESULT WINAPI d3d9_indexbuffer_GetPrivateData(IDirect3DIndexBuffer9 *iface,
378 REFGUID guid, void *data, DWORD *data_size)
380 HRESULT hr;
382 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
383 iface, debugstr_guid(guid), data, data_size);
385 wined3d_mutex_lock();
386 hr = wined3d_buffer_get_private_data(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer,
387 guid, data, data_size);
388 wined3d_mutex_unlock();
390 return hr;
393 static HRESULT WINAPI d3d9_indexbuffer_FreePrivateData(IDirect3DIndexBuffer9 *iface, REFGUID guid)
395 HRESULT hr;
397 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
399 wined3d_mutex_lock();
400 hr = wined3d_buffer_free_private_data(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer, guid);
401 wined3d_mutex_unlock();
403 return hr;
406 static DWORD WINAPI d3d9_indexbuffer_SetPriority(IDirect3DIndexBuffer9 *iface, DWORD priority)
408 DWORD previous;
410 TRACE("iface %p, priority %u.\n", iface, priority);
412 wined3d_mutex_lock();
413 previous = wined3d_buffer_set_priority(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer, priority);
414 wined3d_mutex_unlock();
416 return previous;
419 static DWORD WINAPI d3d9_indexbuffer_GetPriority(IDirect3DIndexBuffer9 *iface)
421 DWORD priority;
423 TRACE("iface %p.\n", iface);
425 wined3d_mutex_lock();
426 priority = wined3d_buffer_get_priority(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer);
427 wined3d_mutex_unlock();
429 return priority;
432 static void WINAPI d3d9_indexbuffer_PreLoad(IDirect3DIndexBuffer9 *iface)
434 TRACE("iface %p.\n", iface);
436 wined3d_mutex_lock();
437 wined3d_buffer_preload(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer);
438 wined3d_mutex_unlock();
441 static D3DRESOURCETYPE WINAPI d3d9_indexbuffer_GetType(IDirect3DIndexBuffer9 *iface)
443 TRACE("iface %p.\n", iface);
445 return D3DRTYPE_INDEXBUFFER;
448 static HRESULT WINAPI d3d9_indexbuffer_Lock(IDirect3DIndexBuffer9 *iface,
449 UINT offset, UINT size, void **data, DWORD flags)
451 HRESULT hr;
453 TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
454 iface, offset, size, data, flags);
456 wined3d_mutex_lock();
457 hr = wined3d_buffer_map(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer,
458 offset, size, (BYTE **)data, flags);
459 wined3d_mutex_unlock();
461 return hr;
464 static HRESULT WINAPI d3d9_indexbuffer_Unlock(IDirect3DIndexBuffer9 *iface)
466 TRACE("iface %p.\n", iface);
468 wined3d_mutex_lock();
469 wined3d_buffer_unmap(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer);
470 wined3d_mutex_unlock();
472 return D3D_OK;
475 static HRESULT WINAPI d3d9_indexbuffer_GetDesc(IDirect3DIndexBuffer9 *iface, D3DINDEXBUFFER_DESC *desc)
477 IDirect3DIndexBuffer9Impl *buffer = (IDirect3DIndexBuffer9Impl *)iface;
478 struct wined3d_resource_desc wined3d_desc;
479 struct wined3d_resource *wined3d_resource;
481 TRACE("iface %p, desc %p.\n", iface, desc);
483 wined3d_mutex_lock();
484 wined3d_resource = wined3d_buffer_get_resource(buffer->wineD3DIndexBuffer);
485 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
486 wined3d_mutex_unlock();
488 desc->Format = d3dformat_from_wined3dformat(buffer->format);
489 desc->Usage = wined3d_desc.usage;
490 desc->Pool = wined3d_desc.pool;
491 desc->Size = wined3d_desc.size;
492 desc->Type = D3DRTYPE_INDEXBUFFER;
494 return D3D_OK;
497 static const IDirect3DIndexBuffer9Vtbl d3d9_indexbuffer_vtbl =
499 /* IUnknown */
500 d3d9_indexbuffer_QueryInterface,
501 d3d9_indexbuffer_AddRef,
502 d3d9_indexbuffer_Release,
503 /* IDirect3DResource9 */
504 d3d9_indexbuffer_GetDevice,
505 d3d9_indexbuffer_SetPrivateData,
506 d3d9_indexbuffer_GetPrivateData,
507 d3d9_indexbuffer_FreePrivateData,
508 d3d9_indexbuffer_SetPriority,
509 d3d9_indexbuffer_GetPriority,
510 d3d9_indexbuffer_PreLoad,
511 d3d9_indexbuffer_GetType,
512 /* IDirect3DIndexBuffer9 */
513 d3d9_indexbuffer_Lock,
514 d3d9_indexbuffer_Unlock,
515 d3d9_indexbuffer_GetDesc,
518 static void STDMETHODCALLTYPE d3d9_indexbuffer_wined3d_object_destroyed(void *parent)
520 HeapFree(GetProcessHeap(), 0, parent);
523 static const struct wined3d_parent_ops d3d9_indexbuffer_wined3d_parent_ops =
525 d3d9_indexbuffer_wined3d_object_destroyed,
528 HRESULT indexbuffer_init(IDirect3DIndexBuffer9Impl *buffer, IDirect3DDevice9Impl *device,
529 UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool)
531 HRESULT hr;
533 buffer->lpVtbl = &d3d9_indexbuffer_vtbl;
534 buffer->ref = 1;
535 buffer->format = wined3dformat_from_d3dformat(format);
537 wined3d_mutex_lock();
538 hr = wined3d_buffer_create_ib(device->wined3d_device, size, usage & WINED3DUSAGE_MASK,
539 (WINED3DPOOL)pool, buffer, &d3d9_indexbuffer_wined3d_parent_ops, &buffer->wineD3DIndexBuffer);
540 wined3d_mutex_unlock();
541 if (FAILED(hr))
543 WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
544 return hr;
547 buffer->parentDevice = &device->IDirect3DDevice9Ex_iface;
548 IDirect3DDevice9Ex_AddRef(buffer->parentDevice);
550 return D3D_OK;