ntdll: Fix race in NtRead/WriteFile.
[wine/testsucceed.git] / dlls / d3d10core / buffer.c
blob4a68299514a1ca514e225c2f927d5edbbab698ac
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 FIXME("iface %p stub!\n", iface);
144 static void STDMETHODCALLTYPE d3d10_buffer_GetDesc(ID3D10Buffer *iface, D3D10_BUFFER_DESC *desc)
146 FIXME("iface %p, desc %p stub!\n", iface, desc);
149 static const struct ID3D10BufferVtbl d3d10_buffer_vtbl =
151 /* IUnknown methods */
152 d3d10_buffer_QueryInterface,
153 d3d10_buffer_AddRef,
154 d3d10_buffer_Release,
155 /* ID3D10DeviceChild methods */
156 d3d10_buffer_GetDevice,
157 d3d10_buffer_GetPrivateData,
158 d3d10_buffer_SetPrivateData,
159 d3d10_buffer_SetPrivateDataInterface,
160 /* ID3D10Resource methods */
161 d3d10_buffer_GetType,
162 d3d10_buffer_SetEvictionPriority,
163 d3d10_buffer_GetEvictionPriority,
164 /* ID3D10Buffer methods */
165 d3d10_buffer_Map,
166 d3d10_buffer_Unmap,
167 d3d10_buffer_GetDesc,
170 static void STDMETHODCALLTYPE d3d10_buffer_wined3d_object_released(void *parent)
172 HeapFree(GetProcessHeap(), 0, parent);
175 static const struct wined3d_parent_ops d3d10_buffer_wined3d_parent_ops =
177 d3d10_buffer_wined3d_object_released,
180 HRESULT d3d10_buffer_init(struct d3d10_buffer *buffer, struct d3d10_device *device,
181 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data)
183 struct wined3d_buffer_desc wined3d_desc;
184 HRESULT hr;
186 buffer->vtbl = &d3d10_buffer_vtbl;
187 buffer->refcount = 1;
189 FIXME("Implement DXGI<->wined3d usage conversion\n");
191 wined3d_desc.byte_width = desc->ByteWidth;
192 wined3d_desc.usage = desc->Usage;
193 wined3d_desc.bind_flags = desc->BindFlags;
194 wined3d_desc.cpu_access_flags = desc->CPUAccessFlags;
195 wined3d_desc.misc_flags = desc->MiscFlags;
197 hr = IWineD3DDevice_CreateBuffer(device->wined3d_device, &wined3d_desc,
198 data ? data->pSysMem : NULL, (IUnknown *)buffer, &d3d10_buffer_wined3d_parent_ops,
199 &buffer->wined3d_buffer);
200 if (FAILED(hr))
202 WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
203 return hr;
206 return S_OK;