widl: Renamed --rt option to --winrt for midl compatibility.
[wine.git] / dlls / d3d10core / buffer.c
blob84882a7dff503af53016c5d759a7e8debae07d65
1 /*
2 * Copyright 2009 Henri Verbeet for CodeWeavers
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.
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.
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
20 #include "config.h"
21 #include "wine/port.h"
23 #include "d3d10core_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d10core);
27 static inline struct d3d10_buffer *impl_from_ID3D10Buffer(ID3D10Buffer *iface)
29 return CONTAINING_RECORD(iface, struct d3d10_buffer, ID3D10Buffer_iface);
32 /* IUnknown methods */
34 static HRESULT STDMETHODCALLTYPE d3d10_buffer_QueryInterface(ID3D10Buffer *iface, REFIID riid, void **out)
36 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
38 if (IsEqualGUID(riid, &IID_ID3D10Buffer)
39 || IsEqualGUID(riid, &IID_ID3D10Resource)
40 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
41 || IsEqualGUID(riid, &IID_IUnknown))
43 IUnknown_AddRef(iface);
44 *out = iface;
45 return S_OK;
48 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
50 *out = NULL;
51 return E_NOINTERFACE;
54 static ULONG STDMETHODCALLTYPE d3d10_buffer_AddRef(ID3D10Buffer *iface)
56 struct d3d10_buffer *buffer = impl_from_ID3D10Buffer(iface);
57 ULONG refcount = InterlockedIncrement(&buffer->refcount);
59 TRACE("%p increasing refcount to %u.\n", buffer, refcount);
61 if (refcount == 1)
63 ID3D10Device1_AddRef(buffer->device);
64 wined3d_buffer_incref(buffer->wined3d_buffer);
67 return refcount;
70 static ULONG STDMETHODCALLTYPE d3d10_buffer_Release(ID3D10Buffer *iface)
72 struct d3d10_buffer *buffer = impl_from_ID3D10Buffer(iface);
73 ULONG refcount = InterlockedDecrement(&buffer->refcount);
75 TRACE("%p decreasing refcount to %u.\n", buffer, refcount);
77 if (!refcount)
79 ID3D10Device1 *device = buffer->device;
81 wined3d_buffer_decref(buffer->wined3d_buffer);
82 /* Release the device last, it may cause the wined3d device to be
83 * destroyed. */
84 ID3D10Device1_Release(device);
87 return refcount;
90 /* ID3D10DeviceChild methods */
92 static void STDMETHODCALLTYPE d3d10_buffer_GetDevice(ID3D10Buffer *iface, ID3D10Device **device)
94 struct d3d10_buffer *buffer = impl_from_ID3D10Buffer(iface);
96 TRACE("iface %p, device %p.\n", iface, device);
98 *device = (ID3D10Device *)buffer->device;
99 ID3D10Device_AddRef(*device);
102 static HRESULT STDMETHODCALLTYPE d3d10_buffer_GetPrivateData(ID3D10Buffer *iface,
103 REFGUID guid, UINT *data_size, void *data)
105 struct d3d10_buffer *buffer = impl_from_ID3D10Buffer(iface);
107 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
108 iface, debugstr_guid(guid), data_size, data);
110 return d3d10_get_private_data(&buffer->private_store, guid, data_size, data);
113 static HRESULT STDMETHODCALLTYPE d3d10_buffer_SetPrivateData(ID3D10Buffer *iface,
114 REFGUID guid, UINT data_size, const void *data)
116 struct d3d10_buffer *buffer = impl_from_ID3D10Buffer(iface);
118 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
119 iface, debugstr_guid(guid), data_size, data);
121 return d3d10_set_private_data(&buffer->private_store, guid, data_size, data);
124 static HRESULT STDMETHODCALLTYPE d3d10_buffer_SetPrivateDataInterface(ID3D10Buffer *iface,
125 REFGUID guid, const IUnknown *data)
127 struct d3d10_buffer *buffer = impl_from_ID3D10Buffer(iface);
129 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
131 return d3d10_set_private_data_interface(&buffer->private_store, guid, data);
134 /* ID3D10Resource methods */
136 static void STDMETHODCALLTYPE d3d10_buffer_GetType(ID3D10Buffer *iface, D3D10_RESOURCE_DIMENSION *resource_dimension)
138 TRACE("iface %p, resource_dimension %p\n", iface, resource_dimension);
140 *resource_dimension = D3D10_RESOURCE_DIMENSION_BUFFER;
143 static void STDMETHODCALLTYPE d3d10_buffer_SetEvictionPriority(ID3D10Buffer *iface, UINT eviction_priority)
145 FIXME("iface %p, eviction_priority %u stub!\n", iface, eviction_priority);
148 static UINT STDMETHODCALLTYPE d3d10_buffer_GetEvictionPriority(ID3D10Buffer *iface)
150 FIXME("iface %p stub!\n", iface);
152 return 0;
155 /* ID3D10Buffer methods */
157 static HRESULT STDMETHODCALLTYPE d3d10_buffer_Map(ID3D10Buffer *iface, D3D10_MAP map_type, UINT map_flags, void **data)
159 struct d3d10_buffer *buffer = impl_from_ID3D10Buffer(iface);
161 TRACE("iface %p, map_type %u, map_flags %#x, data %p.\n", iface, map_type, map_flags, data);
163 if (map_flags)
164 FIXME("Ignoring map_flags %#x.\n", map_flags);
166 return wined3d_buffer_map(buffer->wined3d_buffer, 0, 0, (BYTE **)data,
167 wined3d_map_flags_from_d3d10_map_type(map_type));
170 static void STDMETHODCALLTYPE d3d10_buffer_Unmap(ID3D10Buffer *iface)
172 struct d3d10_buffer *buffer = impl_from_ID3D10Buffer(iface);
174 TRACE("iface %p.\n", iface);
176 wined3d_buffer_unmap(buffer->wined3d_buffer);
179 static void STDMETHODCALLTYPE d3d10_buffer_GetDesc(ID3D10Buffer *iface, D3D10_BUFFER_DESC *desc)
181 FIXME("iface %p, desc %p stub!\n", iface, desc);
184 static const struct ID3D10BufferVtbl d3d10_buffer_vtbl =
186 /* IUnknown methods */
187 d3d10_buffer_QueryInterface,
188 d3d10_buffer_AddRef,
189 d3d10_buffer_Release,
190 /* ID3D10DeviceChild methods */
191 d3d10_buffer_GetDevice,
192 d3d10_buffer_GetPrivateData,
193 d3d10_buffer_SetPrivateData,
194 d3d10_buffer_SetPrivateDataInterface,
195 /* ID3D10Resource methods */
196 d3d10_buffer_GetType,
197 d3d10_buffer_SetEvictionPriority,
198 d3d10_buffer_GetEvictionPriority,
199 /* ID3D10Buffer methods */
200 d3d10_buffer_Map,
201 d3d10_buffer_Unmap,
202 d3d10_buffer_GetDesc,
205 struct d3d10_buffer *unsafe_impl_from_ID3D10Buffer(ID3D10Buffer *iface)
207 if (!iface)
208 return NULL;
209 assert(iface->lpVtbl == &d3d10_buffer_vtbl);
210 return CONTAINING_RECORD(iface, struct d3d10_buffer, ID3D10Buffer_iface);
213 static void STDMETHODCALLTYPE d3d10_buffer_wined3d_object_released(void *parent)
215 struct d3d10_buffer *buffer = parent;
217 wined3d_private_store_cleanup(&buffer->private_store);
218 HeapFree(GetProcessHeap(), 0, parent);
221 static const struct wined3d_parent_ops d3d10_buffer_wined3d_parent_ops =
223 d3d10_buffer_wined3d_object_released,
226 HRESULT d3d10_buffer_init(struct d3d10_buffer *buffer, struct d3d10_device *device,
227 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data)
229 struct wined3d_buffer_desc wined3d_desc;
230 HRESULT hr;
232 buffer->ID3D10Buffer_iface.lpVtbl = &d3d10_buffer_vtbl;
233 buffer->refcount = 1;
234 wined3d_private_store_init(&buffer->private_store);
236 wined3d_desc.byte_width = desc->ByteWidth;
237 wined3d_desc.usage = wined3d_usage_from_d3d10core(0, desc->Usage);
238 wined3d_desc.bind_flags = desc->BindFlags;
239 wined3d_desc.cpu_access_flags = desc->CPUAccessFlags;
240 wined3d_desc.misc_flags = desc->MiscFlags;
242 hr = wined3d_buffer_create(device->wined3d_device, &wined3d_desc,
243 data ? data->pSysMem : NULL, buffer, &d3d10_buffer_wined3d_parent_ops,
244 &buffer->wined3d_buffer);
245 if (FAILED(hr))
247 WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
248 wined3d_private_store_cleanup(&buffer->private_store);
249 return hr;
252 buffer->device = &device->ID3D10Device1_iface;
253 ID3D10Device1_AddRef(buffer->device);
255 return S_OK;