Add AppDefaults app selection to control panel
[wine/gsoc-2012-control.git] / dlls / d3d10core / buffer.c
blob90ff0e8a5d0ec947083eb57f5165670312b36372
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)
62 wined3d_buffer_incref(buffer->wined3d_buffer);
64 return refcount;
67 static ULONG STDMETHODCALLTYPE d3d10_buffer_Release(ID3D10Buffer *iface)
69 struct d3d10_buffer *buffer = impl_from_ID3D10Buffer(iface);
70 ULONG refcount = InterlockedDecrement(&buffer->refcount);
72 TRACE("%p decreasing refcount to %u.\n", buffer, refcount);
74 if (!refcount)
75 wined3d_buffer_decref(buffer->wined3d_buffer);
77 return refcount;
80 /* ID3D10DeviceChild methods */
82 static void STDMETHODCALLTYPE d3d10_buffer_GetDevice(ID3D10Buffer *iface, ID3D10Device **device)
84 FIXME("iface %p, device %p stub!\n", iface, device);
87 static HRESULT STDMETHODCALLTYPE d3d10_buffer_GetPrivateData(ID3D10Buffer *iface,
88 REFGUID guid, UINT *data_size, void *data)
90 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
91 iface, debugstr_guid(guid), data_size, data);
93 return E_NOTIMPL;
96 static HRESULT STDMETHODCALLTYPE d3d10_buffer_SetPrivateData(ID3D10Buffer *iface,
97 REFGUID guid, UINT data_size, const void *data)
99 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
100 iface, debugstr_guid(guid), data_size, data);
102 return E_NOTIMPL;
105 static HRESULT STDMETHODCALLTYPE d3d10_buffer_SetPrivateDataInterface(ID3D10Buffer *iface,
106 REFGUID guid, const IUnknown *data)
108 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
110 return E_NOTIMPL;
113 /* ID3D10Resource methods */
115 static void STDMETHODCALLTYPE d3d10_buffer_GetType(ID3D10Buffer *iface, D3D10_RESOURCE_DIMENSION *resource_dimension)
117 TRACE("iface %p, resource_dimension %p\n", iface, resource_dimension);
119 *resource_dimension = D3D10_RESOURCE_DIMENSION_BUFFER;
122 static void STDMETHODCALLTYPE d3d10_buffer_SetEvictionPriority(ID3D10Buffer *iface, UINT eviction_priority)
124 FIXME("iface %p, eviction_priority %u stub!\n", iface, eviction_priority);
127 static UINT STDMETHODCALLTYPE d3d10_buffer_GetEvictionPriority(ID3D10Buffer *iface)
129 FIXME("iface %p stub!\n", iface);
131 return 0;
134 /* ID3D10Buffer methods */
136 static HRESULT STDMETHODCALLTYPE d3d10_buffer_Map(ID3D10Buffer *iface, D3D10_MAP map_type, UINT map_flags, void **data)
138 struct d3d10_buffer *buffer = impl_from_ID3D10Buffer(iface);
140 TRACE("iface %p, map_type %u, map_flags %#x, data %p.\n", iface, map_type, map_flags, data);
142 if (map_type != D3D10_MAP_READ_WRITE)
143 FIXME("Ignoring map_type %#x.\n", map_type);
144 if (map_flags)
145 FIXME("Ignoring map_flags %#x.\n", map_flags);
147 return wined3d_buffer_map(buffer->wined3d_buffer, 0, 0, (BYTE **)data, 0);
150 static void STDMETHODCALLTYPE d3d10_buffer_Unmap(ID3D10Buffer *iface)
152 struct d3d10_buffer *buffer = impl_from_ID3D10Buffer(iface);
154 TRACE("iface %p.\n", iface);
156 wined3d_buffer_unmap(buffer->wined3d_buffer);
159 static void STDMETHODCALLTYPE d3d10_buffer_GetDesc(ID3D10Buffer *iface, D3D10_BUFFER_DESC *desc)
161 FIXME("iface %p, desc %p stub!\n", iface, desc);
164 static const struct ID3D10BufferVtbl d3d10_buffer_vtbl =
166 /* IUnknown methods */
167 d3d10_buffer_QueryInterface,
168 d3d10_buffer_AddRef,
169 d3d10_buffer_Release,
170 /* ID3D10DeviceChild methods */
171 d3d10_buffer_GetDevice,
172 d3d10_buffer_GetPrivateData,
173 d3d10_buffer_SetPrivateData,
174 d3d10_buffer_SetPrivateDataInterface,
175 /* ID3D10Resource methods */
176 d3d10_buffer_GetType,
177 d3d10_buffer_SetEvictionPriority,
178 d3d10_buffer_GetEvictionPriority,
179 /* ID3D10Buffer methods */
180 d3d10_buffer_Map,
181 d3d10_buffer_Unmap,
182 d3d10_buffer_GetDesc,
185 struct d3d10_buffer *unsafe_impl_from_ID3D10Buffer(ID3D10Buffer *iface)
187 if (!iface)
188 return NULL;
189 assert(iface->lpVtbl == &d3d10_buffer_vtbl);
190 return CONTAINING_RECORD(iface, struct d3d10_buffer, ID3D10Buffer_iface);
193 static void STDMETHODCALLTYPE d3d10_buffer_wined3d_object_released(void *parent)
195 HeapFree(GetProcessHeap(), 0, parent);
198 static const struct wined3d_parent_ops d3d10_buffer_wined3d_parent_ops =
200 d3d10_buffer_wined3d_object_released,
203 HRESULT d3d10_buffer_init(struct d3d10_buffer *buffer, struct d3d10_device *device,
204 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data)
206 struct wined3d_buffer_desc wined3d_desc;
207 HRESULT hr;
209 buffer->ID3D10Buffer_iface.lpVtbl = &d3d10_buffer_vtbl;
210 buffer->refcount = 1;
212 FIXME("Implement DXGI<->wined3d usage conversion\n");
214 wined3d_desc.byte_width = desc->ByteWidth;
215 wined3d_desc.usage = desc->Usage;
216 wined3d_desc.bind_flags = desc->BindFlags;
217 wined3d_desc.cpu_access_flags = desc->CPUAccessFlags;
218 wined3d_desc.misc_flags = desc->MiscFlags;
220 hr = wined3d_buffer_create(device->wined3d_device, &wined3d_desc,
221 data ? data->pSysMem : NULL, buffer, &d3d10_buffer_wined3d_parent_ops,
222 &buffer->wined3d_buffer);
223 if (FAILED(hr))
225 WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
226 return hr;
229 return S_OK;