wineps: Simplify the failure path.
[wine/multimedia.git] / dlls / d3d10core / buffer.c
blobfd2175e9a12c220c4b148e2bfc9ea2e7906d63e4
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)
57 wined3d_buffer_incref(This->wined3d_buffer);
59 return refcount;
62 static ULONG STDMETHODCALLTYPE d3d10_buffer_Release(ID3D10Buffer *iface)
64 struct d3d10_buffer *This = (struct d3d10_buffer *)iface;
65 ULONG refcount = InterlockedDecrement(&This->refcount);
67 TRACE("%p decreasing refcount to %u\n", This, refcount);
69 if (!refcount)
71 wined3d_buffer_decref(This->wined3d_buffer);
74 return refcount;
77 /* ID3D10DeviceChild methods */
79 static void STDMETHODCALLTYPE d3d10_buffer_GetDevice(ID3D10Buffer *iface, ID3D10Device **device)
81 FIXME("iface %p, device %p stub!\n", iface, device);
84 static HRESULT STDMETHODCALLTYPE d3d10_buffer_GetPrivateData(ID3D10Buffer *iface,
85 REFGUID guid, UINT *data_size, void *data)
87 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
88 iface, debugstr_guid(guid), data_size, data);
90 return E_NOTIMPL;
93 static HRESULT STDMETHODCALLTYPE d3d10_buffer_SetPrivateData(ID3D10Buffer *iface,
94 REFGUID guid, UINT data_size, const void *data)
96 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
97 iface, debugstr_guid(guid), data_size, data);
99 return E_NOTIMPL;
102 static HRESULT STDMETHODCALLTYPE d3d10_buffer_SetPrivateDataInterface(ID3D10Buffer *iface,
103 REFGUID guid, const IUnknown *data)
105 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
107 return E_NOTIMPL;
110 /* ID3D10Resource methods */
112 static void STDMETHODCALLTYPE d3d10_buffer_GetType(ID3D10Buffer *iface, D3D10_RESOURCE_DIMENSION *resource_dimension)
114 TRACE("iface %p, resource_dimension %p\n", iface, resource_dimension);
116 *resource_dimension = D3D10_RESOURCE_DIMENSION_BUFFER;
119 static void STDMETHODCALLTYPE d3d10_buffer_SetEvictionPriority(ID3D10Buffer *iface, UINT eviction_priority)
121 FIXME("iface %p, eviction_priority %u stub!\n", iface, eviction_priority);
124 static UINT STDMETHODCALLTYPE d3d10_buffer_GetEvictionPriority(ID3D10Buffer *iface)
126 FIXME("iface %p stub!\n", iface);
128 return 0;
131 /* ID3D10Buffer methods */
133 static HRESULT STDMETHODCALLTYPE d3d10_buffer_Map(ID3D10Buffer *iface, D3D10_MAP map_type, UINT map_flags, void **data)
135 struct d3d10_buffer *buffer = (struct d3d10_buffer *)iface;
137 TRACE("iface %p, map_type %u, map_flags %#x, data %p.\n", iface, map_type, map_flags, data);
139 if (map_type != D3D10_MAP_READ_WRITE)
140 FIXME("Ignoring map_type %#x.\n", map_type);
141 if (map_flags)
142 FIXME("Ignoring map_flags %#x.\n", map_flags);
144 return wined3d_buffer_map(buffer->wined3d_buffer, 0, 0, (BYTE **)data, 0);
147 static void STDMETHODCALLTYPE d3d10_buffer_Unmap(ID3D10Buffer *iface)
149 TRACE("iface %p.\n", iface);
151 wined3d_buffer_unmap(((struct d3d10_buffer *)iface)->wined3d_buffer);
154 static void STDMETHODCALLTYPE d3d10_buffer_GetDesc(ID3D10Buffer *iface, D3D10_BUFFER_DESC *desc)
156 FIXME("iface %p, desc %p stub!\n", iface, desc);
159 static const struct ID3D10BufferVtbl d3d10_buffer_vtbl =
161 /* IUnknown methods */
162 d3d10_buffer_QueryInterface,
163 d3d10_buffer_AddRef,
164 d3d10_buffer_Release,
165 /* ID3D10DeviceChild methods */
166 d3d10_buffer_GetDevice,
167 d3d10_buffer_GetPrivateData,
168 d3d10_buffer_SetPrivateData,
169 d3d10_buffer_SetPrivateDataInterface,
170 /* ID3D10Resource methods */
171 d3d10_buffer_GetType,
172 d3d10_buffer_SetEvictionPriority,
173 d3d10_buffer_GetEvictionPriority,
174 /* ID3D10Buffer methods */
175 d3d10_buffer_Map,
176 d3d10_buffer_Unmap,
177 d3d10_buffer_GetDesc,
180 static void STDMETHODCALLTYPE d3d10_buffer_wined3d_object_released(void *parent)
182 HeapFree(GetProcessHeap(), 0, parent);
185 static const struct wined3d_parent_ops d3d10_buffer_wined3d_parent_ops =
187 d3d10_buffer_wined3d_object_released,
190 HRESULT d3d10_buffer_init(struct d3d10_buffer *buffer, struct d3d10_device *device,
191 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data)
193 struct wined3d_buffer_desc wined3d_desc;
194 HRESULT hr;
196 buffer->vtbl = &d3d10_buffer_vtbl;
197 buffer->refcount = 1;
199 FIXME("Implement DXGI<->wined3d usage conversion\n");
201 wined3d_desc.byte_width = desc->ByteWidth;
202 wined3d_desc.usage = desc->Usage;
203 wined3d_desc.bind_flags = desc->BindFlags;
204 wined3d_desc.cpu_access_flags = desc->CPUAccessFlags;
205 wined3d_desc.misc_flags = desc->MiscFlags;
207 hr = wined3d_buffer_create(device->wined3d_device, &wined3d_desc,
208 data ? data->pSysMem : NULL, buffer, &d3d10_buffer_wined3d_parent_ops,
209 &buffer->wined3d_buffer);
210 if (FAILED(hr))
212 WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
213 return hr;
216 return S_OK;