winecoreaudio: Fix a potential leak. (Clang).
[wine/wine-gecko.git] / dlls / d3d10core / texture.c
blob6fca08bd72ac9c95b36b2c55577a40d6285f7968
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 static inline struct d3d10_texture2d *impl_from_ID3D10Texture2D(ID3D10Texture2D *iface)
29 return CONTAINING_RECORD(iface, struct d3d10_texture2d, ID3D10Texture2D_iface);
32 /* IUnknown methods */
34 static HRESULT STDMETHODCALLTYPE d3d10_texture2d_QueryInterface(ID3D10Texture2D *iface, REFIID riid, void **object)
36 struct d3d10_texture2d *This = impl_from_ID3D10Texture2D(iface);
38 TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
40 if (IsEqualGUID(riid, &IID_ID3D10Texture2D)
41 || IsEqualGUID(riid, &IID_ID3D10Resource)
42 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
43 || IsEqualGUID(riid, &IID_IUnknown))
45 IUnknown_AddRef(iface);
46 *object = iface;
47 return S_OK;
50 if (This->dxgi_surface)
52 TRACE("Forwarding to dxgi surface\n");
53 return IUnknown_QueryInterface(This->dxgi_surface, riid, object);
56 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
58 *object = NULL;
59 return E_NOINTERFACE;
62 static ULONG STDMETHODCALLTYPE d3d10_texture2d_AddRef(ID3D10Texture2D *iface)
64 struct d3d10_texture2d *This = impl_from_ID3D10Texture2D(iface);
65 ULONG refcount = InterlockedIncrement(&This->refcount);
67 TRACE("%p increasing refcount to %u\n", This, refcount);
69 if (refcount == 1)
70 wined3d_texture_incref(This->wined3d_texture);
72 return refcount;
75 static void STDMETHODCALLTYPE d3d10_texture2d_wined3d_object_released(void *parent)
77 struct d3d10_texture2d *This = parent;
79 if (This->dxgi_surface) IUnknown_Release(This->dxgi_surface);
80 HeapFree(GetProcessHeap(), 0, This);
83 static ULONG STDMETHODCALLTYPE d3d10_texture2d_Release(ID3D10Texture2D *iface)
85 struct d3d10_texture2d *This = impl_from_ID3D10Texture2D(iface);
86 ULONG refcount = InterlockedDecrement(&This->refcount);
88 TRACE("%p decreasing refcount to %u\n", This, refcount);
90 if (!refcount)
91 wined3d_texture_decref(This->wined3d_texture);
93 return refcount;
96 /* ID3D10DeviceChild methods */
98 static void STDMETHODCALLTYPE d3d10_texture2d_GetDevice(ID3D10Texture2D *iface, ID3D10Device **device)
100 FIXME("iface %p, device %p stub!\n", iface, device);
103 static HRESULT STDMETHODCALLTYPE d3d10_texture2d_GetPrivateData(ID3D10Texture2D *iface,
104 REFGUID guid, UINT *data_size, void *data)
106 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
107 iface, debugstr_guid(guid), data_size, data);
109 return E_NOTIMPL;
112 static HRESULT STDMETHODCALLTYPE d3d10_texture2d_SetPrivateData(ID3D10Texture2D *iface,
113 REFGUID guid, UINT data_size, const void *data)
115 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
116 iface, debugstr_guid(guid), data_size, data);
118 return E_NOTIMPL;
121 static HRESULT STDMETHODCALLTYPE d3d10_texture2d_SetPrivateDataInterface(ID3D10Texture2D *iface,
122 REFGUID guid, const IUnknown *data)
124 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
126 return E_NOTIMPL;
129 /* ID3D10Resource methods */
131 static void STDMETHODCALLTYPE d3d10_texture2d_GetType(ID3D10Texture2D *iface,
132 D3D10_RESOURCE_DIMENSION *resource_dimension)
134 TRACE("iface %p, resource_dimension %p\n", iface, resource_dimension);
136 *resource_dimension = D3D10_RESOURCE_DIMENSION_TEXTURE2D;
139 static void STDMETHODCALLTYPE d3d10_texture2d_SetEvictionPriority(ID3D10Texture2D *iface, UINT eviction_priority)
141 FIXME("iface %p, eviction_priority %u stub!\n", iface, eviction_priority);
144 static UINT STDMETHODCALLTYPE d3d10_texture2d_GetEvictionPriority(ID3D10Texture2D *iface)
146 FIXME("iface %p stub!\n", iface);
148 return 0;
151 /* ID3D10Texture2D methods */
153 static HRESULT STDMETHODCALLTYPE d3d10_texture2d_Map(ID3D10Texture2D *iface, UINT sub_resource_idx,
154 D3D10_MAP map_type, UINT map_flags, D3D10_MAPPED_TEXTURE2D *mapped_texture)
156 struct d3d10_texture2d *texture = impl_from_ID3D10Texture2D(iface);
157 struct wined3d_map_desc wined3d_map_desc;
158 struct wined3d_resource *sub_resource;
159 HRESULT hr;
161 TRACE("iface %p, sub_resource_idx %u, map_type %u, map_flags %#x, mapped_texture %p.\n",
162 iface, sub_resource_idx, map_type, map_flags, mapped_texture);
164 if (map_type != D3D10_MAP_READ_WRITE)
165 FIXME("Ignoring map_type %#x.\n", map_type);
166 if (map_flags)
167 FIXME("Ignoring map_flags %#x.\n", map_flags);
169 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
170 hr = E_INVALIDARG;
171 else if (SUCCEEDED(hr = wined3d_surface_map(wined3d_surface_from_resource(sub_resource),
172 &wined3d_map_desc, NULL, 0)))
174 mapped_texture->pData = wined3d_map_desc.data;
175 mapped_texture->RowPitch = wined3d_map_desc.row_pitch;
178 return hr;
181 static void STDMETHODCALLTYPE d3d10_texture2d_Unmap(ID3D10Texture2D *iface, UINT sub_resource_idx)
183 struct d3d10_texture2d *texture = impl_from_ID3D10Texture2D(iface);
184 struct wined3d_resource *sub_resource;
186 TRACE("iface %p, sub_resource_idx %u.\n", iface, sub_resource_idx);
188 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
189 return;
191 wined3d_surface_unmap(wined3d_surface_from_resource(sub_resource));
194 static void STDMETHODCALLTYPE d3d10_texture2d_GetDesc(ID3D10Texture2D *iface, D3D10_TEXTURE2D_DESC *desc)
196 struct d3d10_texture2d *This = impl_from_ID3D10Texture2D(iface);
198 TRACE("iface %p, desc %p\n", iface, desc);
200 *desc = This->desc;
203 static const struct ID3D10Texture2DVtbl d3d10_texture2d_vtbl =
205 /* IUnknown methods */
206 d3d10_texture2d_QueryInterface,
207 d3d10_texture2d_AddRef,
208 d3d10_texture2d_Release,
209 /* ID3D10DeviceChild methods */
210 d3d10_texture2d_GetDevice,
211 d3d10_texture2d_GetPrivateData,
212 d3d10_texture2d_SetPrivateData,
213 d3d10_texture2d_SetPrivateDataInterface,
214 /* ID3D10Resource methods */
215 d3d10_texture2d_GetType,
216 d3d10_texture2d_SetEvictionPriority,
217 d3d10_texture2d_GetEvictionPriority,
218 /* ID3D10Texture2D methods */
219 d3d10_texture2d_Map,
220 d3d10_texture2d_Unmap,
221 d3d10_texture2d_GetDesc,
224 static const struct wined3d_parent_ops d3d10_texture2d_wined3d_parent_ops =
226 d3d10_texture2d_wined3d_object_released,
229 HRESULT d3d10_texture2d_init(struct d3d10_texture2d *texture, struct d3d10_device *device,
230 const D3D10_TEXTURE2D_DESC *desc)
232 struct wined3d_resource_desc wined3d_desc;
233 HRESULT hr;
235 texture->ID3D10Texture2D_iface.lpVtbl = &d3d10_texture2d_vtbl;
236 texture->refcount = 1;
237 texture->desc = *desc;
239 if (desc->MipLevels == 1 && desc->ArraySize == 1)
241 IWineDXGIDevice *wine_device;
243 hr = ID3D10Device_QueryInterface(&device->ID3D10Device_iface, &IID_IWineDXGIDevice,
244 (void **)&wine_device);
245 if (FAILED(hr))
247 ERR("Device should implement IWineDXGIDevice\n");
248 return E_FAIL;
251 hr = IWineDXGIDevice_create_surface(wine_device, NULL, 0, NULL,
252 (IUnknown *)&texture->ID3D10Texture2D_iface, (void **)&texture->dxgi_surface);
253 IWineDXGIDevice_Release(wine_device);
254 if (FAILED(hr))
256 ERR("Failed to create DXGI surface, returning %#x\n", hr);
257 return hr;
261 if (desc->ArraySize != 1)
262 FIXME("Array textures not implemented.\n");
263 if (desc->SampleDesc.Count > 1)
264 FIXME("Multisampled textures not implemented.\n");
266 wined3d_desc.resource_type = WINED3D_RTYPE_TEXTURE;
267 wined3d_desc.format = wined3dformat_from_dxgi_format(desc->Format);
268 wined3d_desc.multisample_type = desc->SampleDesc.Count > 1 ? desc->SampleDesc.Count : WINED3D_MULTISAMPLE_NONE;
269 wined3d_desc.multisample_quality = desc->SampleDesc.Quality;
270 wined3d_desc.usage = wined3d_usage_from_d3d10core(desc->BindFlags, desc->Usage);
271 wined3d_desc.pool = WINED3D_POOL_DEFAULT;
272 wined3d_desc.width = desc->Width;
273 wined3d_desc.height = desc->Height;
274 wined3d_desc.depth = 1;
275 wined3d_desc.size = 0;
277 if (FAILED(hr = wined3d_texture_create_2d(device->wined3d_device, &wined3d_desc, desc->MipLevels,
278 0, texture, &d3d10_texture2d_wined3d_parent_ops, &texture->wined3d_texture)))
280 WARN("Failed to create wined3d texture, hr %#x.\n", hr);
281 if (texture->dxgi_surface)
282 IUnknown_Release(texture->dxgi_surface);
283 return hr;
285 texture->desc.MipLevels = wined3d_texture_get_level_count(texture->wined3d_texture);
287 return S_OK;
290 static inline struct d3d10_texture3d *impl_from_ID3D10Texture3D(ID3D10Texture3D *iface)
292 return CONTAINING_RECORD(iface, struct d3d10_texture3d, ID3D10Texture3D_iface);
295 static HRESULT STDMETHODCALLTYPE d3d10_texture3d_QueryInterface(ID3D10Texture3D *iface, REFIID riid, void **object)
297 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
299 if (IsEqualGUID(riid, &IID_ID3D10Texture3D)
300 || IsEqualGUID(riid, &IID_ID3D10Resource)
301 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
302 || IsEqualGUID(riid, &IID_IUnknown))
304 IUnknown_AddRef(iface);
305 *object = iface;
306 return S_OK;
309 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
311 *object = NULL;
312 return E_NOINTERFACE;
315 static ULONG STDMETHODCALLTYPE d3d10_texture3d_AddRef(ID3D10Texture3D *iface)
317 struct d3d10_texture3d *texture = impl_from_ID3D10Texture3D(iface);
318 ULONG refcount = InterlockedIncrement(&texture->refcount);
320 TRACE("%p increasing refcount to %u.\n", texture, refcount);
322 if (refcount == 1)
323 wined3d_texture_incref(texture->wined3d_texture);
325 return refcount;
328 static void STDMETHODCALLTYPE d3d10_texture3d_wined3d_object_released(void *parent)
330 HeapFree(GetProcessHeap(), 0, parent);
333 static ULONG STDMETHODCALLTYPE d3d10_texture3d_Release(ID3D10Texture3D *iface)
335 struct d3d10_texture3d *texture = impl_from_ID3D10Texture3D(iface);
336 ULONG refcount = InterlockedDecrement(&texture->refcount);
338 TRACE("%p decreasing refcount to %u.\n", texture, refcount);
340 if (!refcount)
341 wined3d_texture_decref(texture->wined3d_texture);
343 return refcount;
346 static void STDMETHODCALLTYPE d3d10_texture3d_GetDevice(ID3D10Texture3D *iface, ID3D10Device **device)
348 FIXME("iface %p, device %p stub!\n", iface, device);
351 static HRESULT STDMETHODCALLTYPE d3d10_texture3d_GetPrivateData(ID3D10Texture3D *iface,
352 REFGUID guid, UINT *data_size, void *data)
354 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
355 iface, debugstr_guid(guid), data_size, data);
357 return E_NOTIMPL;
360 static HRESULT STDMETHODCALLTYPE d3d10_texture3d_SetPrivateData(ID3D10Texture3D *iface,
361 REFGUID guid, UINT data_size, const void *data)
363 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
364 iface, debugstr_guid(guid), data_size, data);
366 return E_NOTIMPL;
369 static HRESULT STDMETHODCALLTYPE d3d10_texture3d_SetPrivateDataInterface(ID3D10Texture3D *iface,
370 REFGUID guid, const IUnknown *data)
372 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
374 return E_NOTIMPL;
377 static void STDMETHODCALLTYPE d3d10_texture3d_GetType(ID3D10Texture3D *iface,
378 D3D10_RESOURCE_DIMENSION *resource_dimension)
380 TRACE("iface %p, resource_dimension %p.\n", iface, resource_dimension);
382 *resource_dimension = D3D10_RESOURCE_DIMENSION_TEXTURE3D;
385 static void STDMETHODCALLTYPE d3d10_texture3d_SetEvictionPriority(ID3D10Texture3D *iface, UINT eviction_priority)
387 FIXME("iface %p, eviction_priority %u stub!\n", iface, eviction_priority);
390 static UINT STDMETHODCALLTYPE d3d10_texture3d_GetEvictionPriority(ID3D10Texture3D *iface)
392 FIXME("iface %p stub!\n", iface);
394 return 0;
397 static HRESULT STDMETHODCALLTYPE d3d10_texture3d_Map(ID3D10Texture3D *iface, UINT sub_resource_idx,
398 D3D10_MAP map_type, UINT map_flags, D3D10_MAPPED_TEXTURE3D *mapped_texture)
400 struct d3d10_texture3d *texture = impl_from_ID3D10Texture3D(iface);
401 struct wined3d_map_desc wined3d_map_desc;
402 struct wined3d_resource *sub_resource;
403 HRESULT hr;
405 TRACE("iface %p, sub_resource_idx %u, map_type %u, map_flags %#x, mapped_texture %p.\n",
406 iface, sub_resource_idx, map_type, map_flags, mapped_texture);
408 if (map_type != D3D10_MAP_READ_WRITE)
409 FIXME("Ignoring map_type %#x.\n", map_type);
410 if (map_flags)
411 FIXME("Ignoring map_flags %#x.\n", map_flags);
413 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
414 hr = E_INVALIDARG;
415 else if (SUCCEEDED(hr = wined3d_volume_map(wined3d_volume_from_resource(sub_resource),
416 &wined3d_map_desc, NULL, 0)))
418 mapped_texture->pData = wined3d_map_desc.data;
419 mapped_texture->RowPitch = wined3d_map_desc.row_pitch;
420 mapped_texture->DepthPitch = wined3d_map_desc.slice_pitch;
423 return hr;
426 static void STDMETHODCALLTYPE d3d10_texture3d_Unmap(ID3D10Texture3D *iface, UINT sub_resource_idx)
428 struct d3d10_texture3d *texture = impl_from_ID3D10Texture3D(iface);
429 struct wined3d_resource *sub_resource;
431 TRACE("iface %p, sub_resource_idx %u.\n", iface, sub_resource_idx);
433 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
434 return;
436 wined3d_volume_unmap(wined3d_volume_from_resource(sub_resource));
439 static void STDMETHODCALLTYPE d3d10_texture3d_GetDesc(ID3D10Texture3D *iface, D3D10_TEXTURE3D_DESC *desc)
441 struct d3d10_texture3d *texture = impl_from_ID3D10Texture3D(iface);
443 TRACE("iface %p, desc %p.\n", iface, desc);
445 *desc = texture->desc;
448 static const struct ID3D10Texture3DVtbl d3d10_texture3d_vtbl =
450 /* IUnknown methods */
451 d3d10_texture3d_QueryInterface,
452 d3d10_texture3d_AddRef,
453 d3d10_texture3d_Release,
454 /* ID3D10DeviceChild methods */
455 d3d10_texture3d_GetDevice,
456 d3d10_texture3d_GetPrivateData,
457 d3d10_texture3d_SetPrivateData,
458 d3d10_texture3d_SetPrivateDataInterface,
459 /* ID3D10Resource methods */
460 d3d10_texture3d_GetType,
461 d3d10_texture3d_SetEvictionPriority,
462 d3d10_texture3d_GetEvictionPriority,
463 /* ID3D10Texture3D methods */
464 d3d10_texture3d_Map,
465 d3d10_texture3d_Unmap,
466 d3d10_texture3d_GetDesc,
469 static const struct wined3d_parent_ops d3d10_texture3d_wined3d_parent_ops =
471 d3d10_texture3d_wined3d_object_released,
474 HRESULT d3d10_texture3d_init(struct d3d10_texture3d *texture, struct d3d10_device *device,
475 const D3D10_TEXTURE3D_DESC *desc)
477 struct wined3d_resource_desc wined3d_desc;
478 HRESULT hr;
480 texture->ID3D10Texture3D_iface.lpVtbl = &d3d10_texture3d_vtbl;
481 texture->refcount = 1;
482 texture->desc = *desc;
484 wined3d_desc.resource_type = WINED3D_RTYPE_VOLUME_TEXTURE;
485 wined3d_desc.format = wined3dformat_from_dxgi_format(desc->Format);
486 wined3d_desc.multisample_type = WINED3D_MULTISAMPLE_NONE;
487 wined3d_desc.multisample_quality = 0;
488 wined3d_desc.usage = wined3d_usage_from_d3d10core(desc->BindFlags, desc->Usage);
489 wined3d_desc.pool = WINED3D_POOL_DEFAULT;
490 wined3d_desc.width = desc->Width;
491 wined3d_desc.height = desc->Height;
492 wined3d_desc.depth = desc->Depth;
493 wined3d_desc.size = 0;
495 if (FAILED(hr = wined3d_texture_create_3d(device->wined3d_device, &wined3d_desc, desc->MipLevels,
496 texture, &d3d10_texture3d_wined3d_parent_ops, &texture->wined3d_texture)))
498 WARN("Failed to create wined3d texture, hr %#x.\n", hr);
499 return hr;
501 texture->desc.MipLevels = wined3d_texture_get_level_count(texture->wined3d_texture);
503 return S_OK;