d3d10core: Implement ID3D10Buffer::Unmap().
[wine.git] / dlls / d3d10core / buffer.c
blob9230e9d52f64c087c6a975831986a894a188c7b9
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 /* IUnknown methods */
29 static HRESULT STDMETHODCALLTYPE d3d10_buffer_QueryInterface(ID3D10Buffer *iface, REFIID riid, void **object)
31 TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
33 if (IsEqualGUID(riid, &IID_ID3D10Buffer)
34 || IsEqualGUID(riid, &IID_ID3D10Resource)
35 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
36 || IsEqualGUID(riid, &IID_IUnknown))
38 IUnknown_AddRef(iface);
39 *object = iface;
40 return S_OK;
43 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
45 *object = NULL;
46 return E_NOINTERFACE;
49 static ULONG STDMETHODCALLTYPE d3d10_buffer_AddRef(ID3D10Buffer *iface)
51 struct d3d10_buffer *This = (struct d3d10_buffer *)iface;
52 ULONG refcount = InterlockedIncrement(&This->refcount);
54 TRACE("%p increasing refcount to %u\n", This, refcount);
56 if (refcount == 1) IWineD3DBuffer_AddRef(This->wined3d_buffer);
58 return refcount;
61 static ULONG STDMETHODCALLTYPE d3d10_buffer_Release(ID3D10Buffer *iface)
63 struct d3d10_buffer *This = (struct d3d10_buffer *)iface;
64 ULONG refcount = InterlockedDecrement(&This->refcount);
66 TRACE("%p decreasing refcount to %u\n", This, refcount);
68 if (!refcount)
70 IWineD3DBuffer_Release(This->wined3d_buffer);
73 return refcount;
76 /* ID3D10DeviceChild methods */
78 static void STDMETHODCALLTYPE d3d10_buffer_GetDevice(ID3D10Buffer *iface, ID3D10Device **device)
80 FIXME("iface %p, device %p stub!\n", iface, device);
83 static HRESULT STDMETHODCALLTYPE d3d10_buffer_GetPrivateData(ID3D10Buffer *iface,
84 REFGUID guid, UINT *data_size, void *data)
86 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
87 iface, debugstr_guid(guid), data_size, data);
89 return E_NOTIMPL;
92 static HRESULT STDMETHODCALLTYPE d3d10_buffer_SetPrivateData(ID3D10Buffer *iface,
93 REFGUID guid, UINT data_size, const void *data)
95 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
96 iface, debugstr_guid(guid), data_size, data);
98 return E_NOTIMPL;
101 static HRESULT STDMETHODCALLTYPE d3d10_buffer_SetPrivateDataInterface(ID3D10Buffer *iface,
102 REFGUID guid, const IUnknown *data)
104 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
106 return E_NOTIMPL;
109 /* ID3D10Resource methods */
111 static void STDMETHODCALLTYPE d3d10_buffer_GetType(ID3D10Buffer *iface, D3D10_RESOURCE_DIMENSION *resource_dimension)
113 TRACE("iface %p, resource_dimension %p\n", iface, resource_dimension);
115 *resource_dimension = D3D10_RESOURCE_DIMENSION_BUFFER;
118 static void STDMETHODCALLTYPE d3d10_buffer_SetEvictionPriority(ID3D10Buffer *iface, UINT eviction_priority)
120 FIXME("iface %p, eviction_priority %u stub!\n", iface, eviction_priority);
123 static UINT STDMETHODCALLTYPE d3d10_buffer_GetEvictionPriority(ID3D10Buffer *iface)
125 FIXME("iface %p stub!\n", iface);
127 return 0;
130 /* ID3D10Buffer methods */
132 static HRESULT STDMETHODCALLTYPE d3d10_buffer_Map(ID3D10Buffer *iface, D3D10_MAP map_type, UINT map_flags, void **data)
134 FIXME("iface %p, map_type %u, map_flags %#x, data %p stub!\n", iface, map_type, map_flags, data);
136 return E_NOTIMPL;
139 static void STDMETHODCALLTYPE d3d10_buffer_Unmap(ID3D10Buffer *iface)
141 TRACE("iface %p.\n", iface);
143 IWineD3DBuffer_Unmap(((struct d3d10_buffer *)iface)->wined3d_buffer);
146 static void STDMETHODCALLTYPE d3d10_buffer_GetDesc(ID3D10Buffer *iface, D3D10_BUFFER_DESC *desc)
148 FIXME("iface %p, desc %p stub!\n", iface, desc);
151 static const struct ID3D10BufferVtbl d3d10_buffer_vtbl =
153 /* IUnknown methods */
154 d3d10_buffer_QueryInterface,
155 d3d10_buffer_AddRef,
156 d3d10_buffer_Release,
157 /* ID3D10DeviceChild methods */
158 d3d10_buffer_GetDevice,
159 d3d10_buffer_GetPrivateData,
160 d3d10_buffer_SetPrivateData,
161 d3d10_buffer_SetPrivateDataInterface,
162 /* ID3D10Resource methods */
163 d3d10_buffer_GetType,
164 d3d10_buffer_SetEvictionPriority,
165 d3d10_buffer_GetEvictionPriority,
166 /* ID3D10Buffer methods */
167 d3d10_buffer_Map,
168 d3d10_buffer_Unmap,
169 d3d10_buffer_GetDesc,
172 static void STDMETHODCALLTYPE d3d10_buffer_wined3d_object_released(void *parent)
174 HeapFree(GetProcessHeap(), 0, parent);
177 static const struct wined3d_parent_ops d3d10_buffer_wined3d_parent_ops =
179 d3d10_buffer_wined3d_object_released,
182 HRESULT d3d10_buffer_init(struct d3d10_buffer *buffer, struct d3d10_device *device,
183 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data)
185 struct wined3d_buffer_desc wined3d_desc;
186 HRESULT hr;
188 buffer->vtbl = &d3d10_buffer_vtbl;
189 buffer->refcount = 1;
191 FIXME("Implement DXGI<->wined3d usage conversion\n");
193 wined3d_desc.byte_width = desc->ByteWidth;
194 wined3d_desc.usage = desc->Usage;
195 wined3d_desc.bind_flags = desc->BindFlags;
196 wined3d_desc.cpu_access_flags = desc->CPUAccessFlags;
197 wined3d_desc.misc_flags = desc->MiscFlags;
199 hr = IWineD3DDevice_CreateBuffer(device->wined3d_device, &wined3d_desc,
200 data ? data->pSysMem : NULL, (IUnknown *)buffer, &d3d10_buffer_wined3d_parent_ops,
201 &buffer->wined3d_buffer);
202 if (FAILED(hr))
204 WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
205 return hr;
208 return S_OK;