d3d8: Get rid of the format switching code in d3d8_device_CopyRects().
[wine.git] / dlls / d3d10core / buffer.c
blobc5d851e3f483b293c403def644c898bb09b87c2c
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 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
106 iface, debugstr_guid(guid), data_size, data);
108 return E_NOTIMPL;
111 static HRESULT STDMETHODCALLTYPE d3d10_buffer_SetPrivateData(ID3D10Buffer *iface,
112 REFGUID guid, UINT data_size, const void *data)
114 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
115 iface, debugstr_guid(guid), data_size, data);
117 return E_NOTIMPL;
120 static HRESULT STDMETHODCALLTYPE d3d10_buffer_SetPrivateDataInterface(ID3D10Buffer *iface,
121 REFGUID guid, const IUnknown *data)
123 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
125 return E_NOTIMPL;
128 /* ID3D10Resource methods */
130 static void STDMETHODCALLTYPE d3d10_buffer_GetType(ID3D10Buffer *iface, D3D10_RESOURCE_DIMENSION *resource_dimension)
132 TRACE("iface %p, resource_dimension %p\n", iface, resource_dimension);
134 *resource_dimension = D3D10_RESOURCE_DIMENSION_BUFFER;
137 static void STDMETHODCALLTYPE d3d10_buffer_SetEvictionPriority(ID3D10Buffer *iface, UINT eviction_priority)
139 FIXME("iface %p, eviction_priority %u stub!\n", iface, eviction_priority);
142 static UINT STDMETHODCALLTYPE d3d10_buffer_GetEvictionPriority(ID3D10Buffer *iface)
144 FIXME("iface %p stub!\n", iface);
146 return 0;
149 /* ID3D10Buffer methods */
151 static HRESULT STDMETHODCALLTYPE d3d10_buffer_Map(ID3D10Buffer *iface, D3D10_MAP map_type, UINT map_flags, void **data)
153 struct d3d10_buffer *buffer = impl_from_ID3D10Buffer(iface);
155 TRACE("iface %p, map_type %u, map_flags %#x, data %p.\n", iface, map_type, map_flags, data);
157 if (map_flags)
158 FIXME("Ignoring map_flags %#x.\n", map_flags);
160 return wined3d_buffer_map(buffer->wined3d_buffer, 0, 0, (BYTE **)data,
161 wined3d_map_flags_from_d3d10_map_type(map_type));
164 static void STDMETHODCALLTYPE d3d10_buffer_Unmap(ID3D10Buffer *iface)
166 struct d3d10_buffer *buffer = impl_from_ID3D10Buffer(iface);
168 TRACE("iface %p.\n", iface);
170 wined3d_buffer_unmap(buffer->wined3d_buffer);
173 static void STDMETHODCALLTYPE d3d10_buffer_GetDesc(ID3D10Buffer *iface, D3D10_BUFFER_DESC *desc)
175 FIXME("iface %p, desc %p stub!\n", iface, desc);
178 static const struct ID3D10BufferVtbl d3d10_buffer_vtbl =
180 /* IUnknown methods */
181 d3d10_buffer_QueryInterface,
182 d3d10_buffer_AddRef,
183 d3d10_buffer_Release,
184 /* ID3D10DeviceChild methods */
185 d3d10_buffer_GetDevice,
186 d3d10_buffer_GetPrivateData,
187 d3d10_buffer_SetPrivateData,
188 d3d10_buffer_SetPrivateDataInterface,
189 /* ID3D10Resource methods */
190 d3d10_buffer_GetType,
191 d3d10_buffer_SetEvictionPriority,
192 d3d10_buffer_GetEvictionPriority,
193 /* ID3D10Buffer methods */
194 d3d10_buffer_Map,
195 d3d10_buffer_Unmap,
196 d3d10_buffer_GetDesc,
199 struct d3d10_buffer *unsafe_impl_from_ID3D10Buffer(ID3D10Buffer *iface)
201 if (!iface)
202 return NULL;
203 assert(iface->lpVtbl == &d3d10_buffer_vtbl);
204 return CONTAINING_RECORD(iface, struct d3d10_buffer, ID3D10Buffer_iface);
207 static void STDMETHODCALLTYPE d3d10_buffer_wined3d_object_released(void *parent)
209 HeapFree(GetProcessHeap(), 0, parent);
212 static const struct wined3d_parent_ops d3d10_buffer_wined3d_parent_ops =
214 d3d10_buffer_wined3d_object_released,
217 HRESULT d3d10_buffer_init(struct d3d10_buffer *buffer, struct d3d10_device *device,
218 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data)
220 struct wined3d_buffer_desc wined3d_desc;
221 HRESULT hr;
223 buffer->ID3D10Buffer_iface.lpVtbl = &d3d10_buffer_vtbl;
224 buffer->refcount = 1;
226 FIXME("Implement DXGI<->wined3d usage conversion\n");
228 wined3d_desc.byte_width = desc->ByteWidth;
229 wined3d_desc.usage = desc->Usage;
230 wined3d_desc.bind_flags = desc->BindFlags;
231 wined3d_desc.cpu_access_flags = desc->CPUAccessFlags;
232 wined3d_desc.misc_flags = desc->MiscFlags;
234 hr = wined3d_buffer_create(device->wined3d_device, &wined3d_desc,
235 data ? data->pSysMem : NULL, buffer, &d3d10_buffer_wined3d_parent_ops,
236 &buffer->wined3d_buffer);
237 if (FAILED(hr))
239 WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
240 return hr;
243 buffer->device = &device->ID3D10Device1_iface;
244 ID3D10Device1_AddRef(buffer->device);
246 return S_OK;