PageRenderTime 50ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/dlls/d3d10core/buffer.c

https://github.com/aragaer/wine
C | 217 lines | 144 code | 47 blank | 26 comment | 11 complexity | a506825294374ebaeca9dc32396a4a53 MD5 | raw file
  1. /*
  2. * Copyright 2009 Henri Verbeet for CodeWeavers
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  17. *
  18. */
  19. #include "config.h"
  20. #include "wine/port.h"
  21. #include "d3d10core_private.h"
  22. WINE_DEFAULT_DEBUG_CHANNEL(d3d10core);
  23. /* IUnknown methods */
  24. static HRESULT STDMETHODCALLTYPE d3d10_buffer_QueryInterface(ID3D10Buffer *iface, REFIID riid, void **object)
  25. {
  26. TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
  27. if (IsEqualGUID(riid, &IID_ID3D10Buffer)
  28. || IsEqualGUID(riid, &IID_ID3D10Resource)
  29. || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
  30. || IsEqualGUID(riid, &IID_IUnknown))
  31. {
  32. IUnknown_AddRef(iface);
  33. *object = iface;
  34. return S_OK;
  35. }
  36. WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
  37. *object = NULL;
  38. return E_NOINTERFACE;
  39. }
  40. static ULONG STDMETHODCALLTYPE d3d10_buffer_AddRef(ID3D10Buffer *iface)
  41. {
  42. struct d3d10_buffer *This = (struct d3d10_buffer *)iface;
  43. ULONG refcount = InterlockedIncrement(&This->refcount);
  44. TRACE("%p increasing refcount to %u\n", This, refcount);
  45. if (refcount == 1)
  46. wined3d_buffer_incref(This->wined3d_buffer);
  47. return refcount;
  48. }
  49. static ULONG STDMETHODCALLTYPE d3d10_buffer_Release(ID3D10Buffer *iface)
  50. {
  51. struct d3d10_buffer *This = (struct d3d10_buffer *)iface;
  52. ULONG refcount = InterlockedDecrement(&This->refcount);
  53. TRACE("%p decreasing refcount to %u\n", This, refcount);
  54. if (!refcount)
  55. {
  56. wined3d_buffer_decref(This->wined3d_buffer);
  57. }
  58. return refcount;
  59. }
  60. /* ID3D10DeviceChild methods */
  61. static void STDMETHODCALLTYPE d3d10_buffer_GetDevice(ID3D10Buffer *iface, ID3D10Device **device)
  62. {
  63. FIXME("iface %p, device %p stub!\n", iface, device);
  64. }
  65. static HRESULT STDMETHODCALLTYPE d3d10_buffer_GetPrivateData(ID3D10Buffer *iface,
  66. REFGUID guid, UINT *data_size, void *data)
  67. {
  68. FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
  69. iface, debugstr_guid(guid), data_size, data);
  70. return E_NOTIMPL;
  71. }
  72. static HRESULT STDMETHODCALLTYPE d3d10_buffer_SetPrivateData(ID3D10Buffer *iface,
  73. REFGUID guid, UINT data_size, const void *data)
  74. {
  75. FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
  76. iface, debugstr_guid(guid), data_size, data);
  77. return E_NOTIMPL;
  78. }
  79. static HRESULT STDMETHODCALLTYPE d3d10_buffer_SetPrivateDataInterface(ID3D10Buffer *iface,
  80. REFGUID guid, const IUnknown *data)
  81. {
  82. FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
  83. return E_NOTIMPL;
  84. }
  85. /* ID3D10Resource methods */
  86. static void STDMETHODCALLTYPE d3d10_buffer_GetType(ID3D10Buffer *iface, D3D10_RESOURCE_DIMENSION *resource_dimension)
  87. {
  88. TRACE("iface %p, resource_dimension %p\n", iface, resource_dimension);
  89. *resource_dimension = D3D10_RESOURCE_DIMENSION_BUFFER;
  90. }
  91. static void STDMETHODCALLTYPE d3d10_buffer_SetEvictionPriority(ID3D10Buffer *iface, UINT eviction_priority)
  92. {
  93. FIXME("iface %p, eviction_priority %u stub!\n", iface, eviction_priority);
  94. }
  95. static UINT STDMETHODCALLTYPE d3d10_buffer_GetEvictionPriority(ID3D10Buffer *iface)
  96. {
  97. FIXME("iface %p stub!\n", iface);
  98. return 0;
  99. }
  100. /* ID3D10Buffer methods */
  101. static HRESULT STDMETHODCALLTYPE d3d10_buffer_Map(ID3D10Buffer *iface, D3D10_MAP map_type, UINT map_flags, void **data)
  102. {
  103. struct d3d10_buffer *buffer = (struct d3d10_buffer *)iface;
  104. TRACE("iface %p, map_type %u, map_flags %#x, data %p.\n", iface, map_type, map_flags, data);
  105. if (map_type != D3D10_MAP_READ_WRITE)
  106. FIXME("Ignoring map_type %#x.\n", map_type);
  107. if (map_flags)
  108. FIXME("Ignoring map_flags %#x.\n", map_flags);
  109. return wined3d_buffer_map(buffer->wined3d_buffer, 0, 0, (BYTE **)data, 0);
  110. }
  111. static void STDMETHODCALLTYPE d3d10_buffer_Unmap(ID3D10Buffer *iface)
  112. {
  113. TRACE("iface %p.\n", iface);
  114. wined3d_buffer_unmap(((struct d3d10_buffer *)iface)->wined3d_buffer);
  115. }
  116. static void STDMETHODCALLTYPE d3d10_buffer_GetDesc(ID3D10Buffer *iface, D3D10_BUFFER_DESC *desc)
  117. {
  118. FIXME("iface %p, desc %p stub!\n", iface, desc);
  119. }
  120. static const struct ID3D10BufferVtbl d3d10_buffer_vtbl =
  121. {
  122. /* IUnknown methods */
  123. d3d10_buffer_QueryInterface,
  124. d3d10_buffer_AddRef,
  125. d3d10_buffer_Release,
  126. /* ID3D10DeviceChild methods */
  127. d3d10_buffer_GetDevice,
  128. d3d10_buffer_GetPrivateData,
  129. d3d10_buffer_SetPrivateData,
  130. d3d10_buffer_SetPrivateDataInterface,
  131. /* ID3D10Resource methods */
  132. d3d10_buffer_GetType,
  133. d3d10_buffer_SetEvictionPriority,
  134. d3d10_buffer_GetEvictionPriority,
  135. /* ID3D10Buffer methods */
  136. d3d10_buffer_Map,
  137. d3d10_buffer_Unmap,
  138. d3d10_buffer_GetDesc,
  139. };
  140. static void STDMETHODCALLTYPE d3d10_buffer_wined3d_object_released(void *parent)
  141. {
  142. HeapFree(GetProcessHeap(), 0, parent);
  143. }
  144. static const struct wined3d_parent_ops d3d10_buffer_wined3d_parent_ops =
  145. {
  146. d3d10_buffer_wined3d_object_released,
  147. };
  148. HRESULT d3d10_buffer_init(struct d3d10_buffer *buffer, struct d3d10_device *device,
  149. const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data)
  150. {
  151. struct wined3d_buffer_desc wined3d_desc;
  152. HRESULT hr;
  153. buffer->vtbl = &d3d10_buffer_vtbl;
  154. buffer->refcount = 1;
  155. FIXME("Implement DXGI<->wined3d usage conversion\n");
  156. wined3d_desc.byte_width = desc->ByteWidth;
  157. wined3d_desc.usage = desc->Usage;
  158. wined3d_desc.bind_flags = desc->BindFlags;
  159. wined3d_desc.cpu_access_flags = desc->CPUAccessFlags;
  160. wined3d_desc.misc_flags = desc->MiscFlags;
  161. hr = wined3d_buffer_create(device->wined3d_device, &wined3d_desc,
  162. data ? data->pSysMem : NULL, buffer, &d3d10_buffer_wined3d_parent_ops,
  163. &buffer->wined3d_buffer);
  164. if (FAILED(hr))
  165. {
  166. WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
  167. return hr;
  168. }
  169. return S_OK;
  170. }