mshtml: HTMLWindow_item code clean up.
[wine] / dlls / d3d10core / buffer.c
1 /*
2  * Copyright 2009 Henri Verbeet for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  *
18  */
19
20 #include "config.h"
21 #include "wine/port.h"
22
23 #include "d3d10core_private.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d10core);
26
27 /* IUnknown methods */
28
29 static HRESULT STDMETHODCALLTYPE d3d10_buffer_QueryInterface(ID3D10Buffer *iface, REFIID riid, void **object)
30 {
31     TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
32
33     if (IsEqualGUID(riid, &IID_ID3D10Buffer)
34             || IsEqualGUID(riid, &IID_ID3D10Resource)
35             || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
36             || IsEqualGUID(riid, &IID_IUnknown))
37     {
38         IUnknown_AddRef(iface);
39         *object = iface;
40         return S_OK;
41     }
42
43     WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
44
45     *object = NULL;
46     return E_NOINTERFACE;
47 }
48
49 static ULONG STDMETHODCALLTYPE d3d10_buffer_AddRef(ID3D10Buffer *iface)
50 {
51     struct d3d10_buffer *This = (struct d3d10_buffer *)iface;
52     ULONG refcount = InterlockedIncrement(&This->refcount);
53
54     TRACE("%p increasing refcount to %u\n", This, refcount);
55
56     if (refcount == 1)
57         wined3d_buffer_incref(This->wined3d_buffer);
58
59     return refcount;
60 }
61
62 static ULONG STDMETHODCALLTYPE d3d10_buffer_Release(ID3D10Buffer *iface)
63 {
64     struct d3d10_buffer *This = (struct d3d10_buffer *)iface;
65     ULONG refcount = InterlockedDecrement(&This->refcount);
66
67     TRACE("%p decreasing refcount to %u\n", This, refcount);
68
69     if (!refcount)
70     {
71         wined3d_buffer_decref(This->wined3d_buffer);
72     }
73
74     return refcount;
75 }
76
77 /* ID3D10DeviceChild methods */
78
79 static void STDMETHODCALLTYPE d3d10_buffer_GetDevice(ID3D10Buffer *iface, ID3D10Device **device)
80 {
81     FIXME("iface %p, device %p stub!\n", iface, device);
82 }
83
84 static HRESULT STDMETHODCALLTYPE d3d10_buffer_GetPrivateData(ID3D10Buffer *iface,
85         REFGUID guid, UINT *data_size, void *data)
86 {
87     FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
88             iface, debugstr_guid(guid), data_size, data);
89
90     return E_NOTIMPL;
91 }
92
93 static HRESULT STDMETHODCALLTYPE d3d10_buffer_SetPrivateData(ID3D10Buffer *iface,
94         REFGUID guid, UINT data_size, const void *data)
95 {
96     FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
97             iface, debugstr_guid(guid), data_size, data);
98
99     return E_NOTIMPL;
100 }
101
102 static HRESULT STDMETHODCALLTYPE d3d10_buffer_SetPrivateDataInterface(ID3D10Buffer *iface,
103         REFGUID guid, const IUnknown *data)
104 {
105     FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
106
107     return E_NOTIMPL;
108 }
109
110 /* ID3D10Resource methods */
111
112 static void STDMETHODCALLTYPE d3d10_buffer_GetType(ID3D10Buffer *iface, D3D10_RESOURCE_DIMENSION *resource_dimension)
113 {
114     TRACE("iface %p, resource_dimension %p\n", iface, resource_dimension);
115
116     *resource_dimension = D3D10_RESOURCE_DIMENSION_BUFFER;
117 }
118
119 static void STDMETHODCALLTYPE d3d10_buffer_SetEvictionPriority(ID3D10Buffer *iface, UINT eviction_priority)
120 {
121     FIXME("iface %p, eviction_priority %u stub!\n", iface, eviction_priority);
122 }
123
124 static UINT STDMETHODCALLTYPE d3d10_buffer_GetEvictionPriority(ID3D10Buffer *iface)
125 {
126     FIXME("iface %p stub!\n", iface);
127
128     return 0;
129 }
130
131 /* ID3D10Buffer methods */
132
133 static HRESULT STDMETHODCALLTYPE d3d10_buffer_Map(ID3D10Buffer *iface, D3D10_MAP map_type, UINT map_flags, void **data)
134 {
135     struct d3d10_buffer *buffer = (struct d3d10_buffer *)iface;
136
137     TRACE("iface %p, map_type %u, map_flags %#x, data %p.\n", iface, map_type, map_flags, data);
138
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);
143
144     return wined3d_buffer_map(buffer->wined3d_buffer, 0, 0, (BYTE **)data, 0);
145 }
146
147 static void STDMETHODCALLTYPE d3d10_buffer_Unmap(ID3D10Buffer *iface)
148 {
149     TRACE("iface %p.\n", iface);
150
151     wined3d_buffer_unmap(((struct d3d10_buffer *)iface)->wined3d_buffer);
152 }
153
154 static void STDMETHODCALLTYPE d3d10_buffer_GetDesc(ID3D10Buffer *iface, D3D10_BUFFER_DESC *desc)
155 {
156     FIXME("iface %p, desc %p stub!\n", iface, desc);
157 }
158
159 static const struct ID3D10BufferVtbl d3d10_buffer_vtbl =
160 {
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,
178 };
179
180 static void STDMETHODCALLTYPE d3d10_buffer_wined3d_object_released(void *parent)
181 {
182     HeapFree(GetProcessHeap(), 0, parent);
183 }
184
185 static const struct wined3d_parent_ops d3d10_buffer_wined3d_parent_ops =
186 {
187     d3d10_buffer_wined3d_object_released,
188 };
189
190 HRESULT d3d10_buffer_init(struct d3d10_buffer *buffer, struct d3d10_device *device,
191         const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data)
192 {
193     struct wined3d_buffer_desc wined3d_desc;
194     HRESULT hr;
195
196     buffer->vtbl = &d3d10_buffer_vtbl;
197     buffer->refcount = 1;
198
199     FIXME("Implement DXGI<->wined3d usage conversion\n");
200
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;
206
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))
211     {
212         WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
213         return hr;
214     }
215
216     return S_OK;
217 }