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
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
);
48 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
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
);
63 ID3D10Device1_AddRef(buffer
->device
);
65 wined3d_buffer_incref(buffer
->wined3d_buffer
);
66 wined3d_mutex_unlock();
72 static ULONG STDMETHODCALLTYPE
d3d10_buffer_Release(ID3D10Buffer
*iface
)
74 struct d3d10_buffer
*buffer
= impl_from_ID3D10Buffer(iface
);
75 ULONG refcount
= InterlockedDecrement(&buffer
->refcount
);
77 TRACE("%p decreasing refcount to %u.\n", buffer
, refcount
);
81 ID3D10Device1
*device
= buffer
->device
;
84 wined3d_buffer_decref(buffer
->wined3d_buffer
);
85 wined3d_mutex_unlock();
86 /* Release the device last, it may cause the wined3d device to be
88 ID3D10Device1_Release(device
);
94 /* ID3D10DeviceChild methods */
96 static void STDMETHODCALLTYPE
d3d10_buffer_GetDevice(ID3D10Buffer
*iface
, ID3D10Device
**device
)
98 struct d3d10_buffer
*buffer
= impl_from_ID3D10Buffer(iface
);
100 TRACE("iface %p, device %p.\n", iface
, device
);
102 *device
= (ID3D10Device
*)buffer
->device
;
103 ID3D10Device_AddRef(*device
);
106 static HRESULT STDMETHODCALLTYPE
d3d10_buffer_GetPrivateData(ID3D10Buffer
*iface
,
107 REFGUID guid
, UINT
*data_size
, void *data
)
109 struct d3d10_buffer
*buffer
= impl_from_ID3D10Buffer(iface
);
111 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
112 iface
, debugstr_guid(guid
), data_size
, data
);
114 return d3d10_get_private_data(&buffer
->private_store
, guid
, data_size
, data
);
117 static HRESULT STDMETHODCALLTYPE
d3d10_buffer_SetPrivateData(ID3D10Buffer
*iface
,
118 REFGUID guid
, UINT data_size
, const void *data
)
120 struct d3d10_buffer
*buffer
= impl_from_ID3D10Buffer(iface
);
122 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
123 iface
, debugstr_guid(guid
), data_size
, data
);
125 return d3d10_set_private_data(&buffer
->private_store
, guid
, data_size
, data
);
128 static HRESULT STDMETHODCALLTYPE
d3d10_buffer_SetPrivateDataInterface(ID3D10Buffer
*iface
,
129 REFGUID guid
, const IUnknown
*data
)
131 struct d3d10_buffer
*buffer
= impl_from_ID3D10Buffer(iface
);
133 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
135 return d3d10_set_private_data_interface(&buffer
->private_store
, guid
, data
);
138 /* ID3D10Resource methods */
140 static void STDMETHODCALLTYPE
d3d10_buffer_GetType(ID3D10Buffer
*iface
, D3D10_RESOURCE_DIMENSION
*resource_dimension
)
142 TRACE("iface %p, resource_dimension %p\n", iface
, resource_dimension
);
144 *resource_dimension
= D3D10_RESOURCE_DIMENSION_BUFFER
;
147 static void STDMETHODCALLTYPE
d3d10_buffer_SetEvictionPriority(ID3D10Buffer
*iface
, UINT eviction_priority
)
149 FIXME("iface %p, eviction_priority %u stub!\n", iface
, eviction_priority
);
152 static UINT STDMETHODCALLTYPE
d3d10_buffer_GetEvictionPriority(ID3D10Buffer
*iface
)
154 FIXME("iface %p stub!\n", iface
);
159 /* ID3D10Buffer methods */
161 static HRESULT STDMETHODCALLTYPE
d3d10_buffer_Map(ID3D10Buffer
*iface
, D3D10_MAP map_type
, UINT map_flags
, void **data
)
163 struct d3d10_buffer
*buffer
= impl_from_ID3D10Buffer(iface
);
166 TRACE("iface %p, map_type %u, map_flags %#x, data %p.\n", iface
, map_type
, map_flags
, data
);
169 FIXME("Ignoring map_flags %#x.\n", map_flags
);
171 wined3d_mutex_lock();
172 hr
= wined3d_buffer_map(buffer
->wined3d_buffer
, 0, 0, (BYTE
**)data
,
173 wined3d_map_flags_from_d3d10_map_type(map_type
));
174 wined3d_mutex_unlock();
179 static void STDMETHODCALLTYPE
d3d10_buffer_Unmap(ID3D10Buffer
*iface
)
181 struct d3d10_buffer
*buffer
= impl_from_ID3D10Buffer(iface
);
183 TRACE("iface %p.\n", iface
);
185 wined3d_mutex_lock();
186 wined3d_buffer_unmap(buffer
->wined3d_buffer
);
187 wined3d_mutex_unlock();
190 static void STDMETHODCALLTYPE
d3d10_buffer_GetDesc(ID3D10Buffer
*iface
, D3D10_BUFFER_DESC
*desc
)
192 FIXME("iface %p, desc %p stub!\n", iface
, desc
);
195 static const struct ID3D10BufferVtbl d3d10_buffer_vtbl
=
197 /* IUnknown methods */
198 d3d10_buffer_QueryInterface
,
200 d3d10_buffer_Release
,
201 /* ID3D10DeviceChild methods */
202 d3d10_buffer_GetDevice
,
203 d3d10_buffer_GetPrivateData
,
204 d3d10_buffer_SetPrivateData
,
205 d3d10_buffer_SetPrivateDataInterface
,
206 /* ID3D10Resource methods */
207 d3d10_buffer_GetType
,
208 d3d10_buffer_SetEvictionPriority
,
209 d3d10_buffer_GetEvictionPriority
,
210 /* ID3D10Buffer methods */
213 d3d10_buffer_GetDesc
,
216 struct d3d10_buffer
*unsafe_impl_from_ID3D10Buffer(ID3D10Buffer
*iface
)
220 assert(iface
->lpVtbl
== &d3d10_buffer_vtbl
);
221 return CONTAINING_RECORD(iface
, struct d3d10_buffer
, ID3D10Buffer_iface
);
224 static void STDMETHODCALLTYPE
d3d10_buffer_wined3d_object_released(void *parent
)
226 struct d3d10_buffer
*buffer
= parent
;
228 wined3d_private_store_cleanup(&buffer
->private_store
);
229 HeapFree(GetProcessHeap(), 0, parent
);
232 static const struct wined3d_parent_ops d3d10_buffer_wined3d_parent_ops
=
234 d3d10_buffer_wined3d_object_released
,
237 HRESULT
d3d10_buffer_init(struct d3d10_buffer
*buffer
, struct d3d10_device
*device
,
238 const D3D10_BUFFER_DESC
*desc
, const D3D10_SUBRESOURCE_DATA
*data
)
240 struct wined3d_buffer_desc wined3d_desc
;
243 buffer
->ID3D10Buffer_iface
.lpVtbl
= &d3d10_buffer_vtbl
;
244 buffer
->refcount
= 1;
245 wined3d_mutex_lock();
246 wined3d_private_store_init(&buffer
->private_store
);
248 wined3d_desc
.byte_width
= desc
->ByteWidth
;
249 wined3d_desc
.usage
= wined3d_usage_from_d3d10core(0, desc
->Usage
);
250 wined3d_desc
.bind_flags
= desc
->BindFlags
;
251 wined3d_desc
.cpu_access_flags
= desc
->CPUAccessFlags
;
252 wined3d_desc
.misc_flags
= desc
->MiscFlags
;
254 if (FAILED(hr
= wined3d_buffer_create(device
->wined3d_device
, &wined3d_desc
,
255 (const struct wined3d_sub_resource_data
*)data
, buffer
,
256 &d3d10_buffer_wined3d_parent_ops
, &buffer
->wined3d_buffer
)))
258 WARN("Failed to create wined3d buffer, hr %#x.\n", hr
);
259 wined3d_private_store_cleanup(&buffer
->private_store
);
260 wined3d_mutex_unlock();
263 wined3d_mutex_unlock();
265 buffer
->device
= &device
->ID3D10Device1_iface
;
266 ID3D10Device1_AddRef(buffer
->device
);