msvcrt: Add small blocks heap tests.
[wine.git] / dlls / d3d10core / texture.c
blobf1691905e0de134ad4099f182b182f389f6a933f
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)
71 ID3D10Device1_AddRef(This->device);
72 wined3d_texture_incref(This->wined3d_texture);
75 return refcount;
78 static void STDMETHODCALLTYPE d3d10_texture2d_wined3d_object_released(void *parent)
80 struct d3d10_texture2d *This = parent;
82 if (This->dxgi_surface) IUnknown_Release(This->dxgi_surface);
83 HeapFree(GetProcessHeap(), 0, This);
86 static ULONG STDMETHODCALLTYPE d3d10_texture2d_Release(ID3D10Texture2D *iface)
88 struct d3d10_texture2d *This = impl_from_ID3D10Texture2D(iface);
89 ULONG refcount = InterlockedDecrement(&This->refcount);
91 TRACE("%p decreasing refcount to %u\n", This, refcount);
93 if (!refcount)
95 ID3D10Device1 *device = This->device;
97 wined3d_texture_decref(This->wined3d_texture);
98 /* Release the device last, it may cause the wined3d device to be
99 * destroyed. */
100 ID3D10Device1_Release(device);
103 return refcount;
106 /* ID3D10DeviceChild methods */
108 static void STDMETHODCALLTYPE d3d10_texture2d_GetDevice(ID3D10Texture2D *iface, ID3D10Device **device)
110 struct d3d10_texture2d *texture = impl_from_ID3D10Texture2D(iface);
112 TRACE("iface %p, device %p.\n", iface, device);
114 *device = (ID3D10Device *)texture->device;
115 ID3D10Device_AddRef(*device);
118 static HRESULT STDMETHODCALLTYPE d3d10_texture2d_GetPrivateData(ID3D10Texture2D *iface,
119 REFGUID guid, UINT *data_size, void *data)
121 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
122 iface, debugstr_guid(guid), data_size, data);
124 return E_NOTIMPL;
127 static HRESULT STDMETHODCALLTYPE d3d10_texture2d_SetPrivateData(ID3D10Texture2D *iface,
128 REFGUID guid, UINT data_size, const void *data)
130 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
131 iface, debugstr_guid(guid), data_size, data);
133 return E_NOTIMPL;
136 static HRESULT STDMETHODCALLTYPE d3d10_texture2d_SetPrivateDataInterface(ID3D10Texture2D *iface,
137 REFGUID guid, const IUnknown *data)
139 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
141 return E_NOTIMPL;
144 /* ID3D10Resource methods */
146 static void STDMETHODCALLTYPE d3d10_texture2d_GetType(ID3D10Texture2D *iface,
147 D3D10_RESOURCE_DIMENSION *resource_dimension)
149 TRACE("iface %p, resource_dimension %p\n", iface, resource_dimension);
151 *resource_dimension = D3D10_RESOURCE_DIMENSION_TEXTURE2D;
154 static void STDMETHODCALLTYPE d3d10_texture2d_SetEvictionPriority(ID3D10Texture2D *iface, UINT eviction_priority)
156 FIXME("iface %p, eviction_priority %u stub!\n", iface, eviction_priority);
159 static UINT STDMETHODCALLTYPE d3d10_texture2d_GetEvictionPriority(ID3D10Texture2D *iface)
161 FIXME("iface %p stub!\n", iface);
163 return 0;
166 /* ID3D10Texture2D methods */
168 static HRESULT STDMETHODCALLTYPE d3d10_texture2d_Map(ID3D10Texture2D *iface, UINT sub_resource_idx,
169 D3D10_MAP map_type, UINT map_flags, D3D10_MAPPED_TEXTURE2D *mapped_texture)
171 struct d3d10_texture2d *texture = impl_from_ID3D10Texture2D(iface);
172 struct wined3d_map_desc wined3d_map_desc;
173 struct wined3d_resource *sub_resource;
174 HRESULT hr;
176 TRACE("iface %p, sub_resource_idx %u, map_type %u, map_flags %#x, mapped_texture %p.\n",
177 iface, sub_resource_idx, map_type, map_flags, mapped_texture);
179 if (map_type != D3D10_MAP_READ_WRITE)
180 FIXME("Ignoring map_type %#x.\n", map_type);
181 if (map_flags)
182 FIXME("Ignoring map_flags %#x.\n", map_flags);
184 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
185 hr = E_INVALIDARG;
186 else if (SUCCEEDED(hr = wined3d_surface_map(wined3d_surface_from_resource(sub_resource),
187 &wined3d_map_desc, NULL, 0)))
189 mapped_texture->pData = wined3d_map_desc.data;
190 mapped_texture->RowPitch = wined3d_map_desc.row_pitch;
193 return hr;
196 static void STDMETHODCALLTYPE d3d10_texture2d_Unmap(ID3D10Texture2D *iface, UINT sub_resource_idx)
198 struct d3d10_texture2d *texture = impl_from_ID3D10Texture2D(iface);
199 struct wined3d_resource *sub_resource;
201 TRACE("iface %p, sub_resource_idx %u.\n", iface, sub_resource_idx);
203 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
204 return;
206 wined3d_surface_unmap(wined3d_surface_from_resource(sub_resource));
209 static void STDMETHODCALLTYPE d3d10_texture2d_GetDesc(ID3D10Texture2D *iface, D3D10_TEXTURE2D_DESC *desc)
211 struct d3d10_texture2d *This = impl_from_ID3D10Texture2D(iface);
213 TRACE("iface %p, desc %p\n", iface, desc);
215 *desc = This->desc;
218 static const struct ID3D10Texture2DVtbl d3d10_texture2d_vtbl =
220 /* IUnknown methods */
221 d3d10_texture2d_QueryInterface,
222 d3d10_texture2d_AddRef,
223 d3d10_texture2d_Release,
224 /* ID3D10DeviceChild methods */
225 d3d10_texture2d_GetDevice,
226 d3d10_texture2d_GetPrivateData,
227 d3d10_texture2d_SetPrivateData,
228 d3d10_texture2d_SetPrivateDataInterface,
229 /* ID3D10Resource methods */
230 d3d10_texture2d_GetType,
231 d3d10_texture2d_SetEvictionPriority,
232 d3d10_texture2d_GetEvictionPriority,
233 /* ID3D10Texture2D methods */
234 d3d10_texture2d_Map,
235 d3d10_texture2d_Unmap,
236 d3d10_texture2d_GetDesc,
239 static const struct wined3d_parent_ops d3d10_texture2d_wined3d_parent_ops =
241 d3d10_texture2d_wined3d_object_released,
244 HRESULT d3d10_texture2d_init(struct d3d10_texture2d *texture, struct d3d10_device *device,
245 const D3D10_TEXTURE2D_DESC *desc)
247 struct wined3d_resource_desc wined3d_desc;
248 HRESULT hr;
250 texture->ID3D10Texture2D_iface.lpVtbl = &d3d10_texture2d_vtbl;
251 texture->refcount = 1;
252 texture->desc = *desc;
254 if (desc->MipLevels == 1 && desc->ArraySize == 1)
256 IWineDXGIDevice *wine_device;
258 if (FAILED(hr = ID3D10Device1_QueryInterface(&device->ID3D10Device1_iface, &IID_IWineDXGIDevice,
259 (void **)&wine_device)))
261 ERR("Device should implement IWineDXGIDevice.\n");
262 return E_FAIL;
265 hr = IWineDXGIDevice_create_surface(wine_device, NULL, 0, NULL,
266 (IUnknown *)&texture->ID3D10Texture2D_iface, (void **)&texture->dxgi_surface);
267 IWineDXGIDevice_Release(wine_device);
268 if (FAILED(hr))
270 ERR("Failed to create DXGI surface, returning %#x\n", hr);
271 return hr;
275 if (desc->ArraySize != 1)
276 FIXME("Array textures not implemented.\n");
277 if (desc->SampleDesc.Count > 1)
278 FIXME("Multisampled textures not implemented.\n");
280 wined3d_desc.resource_type = WINED3D_RTYPE_TEXTURE;
281 wined3d_desc.format = wined3dformat_from_dxgi_format(desc->Format);
282 wined3d_desc.multisample_type = desc->SampleDesc.Count > 1 ? desc->SampleDesc.Count : WINED3D_MULTISAMPLE_NONE;
283 wined3d_desc.multisample_quality = desc->SampleDesc.Quality;
284 wined3d_desc.usage = wined3d_usage_from_d3d10core(desc->BindFlags, desc->Usage);
285 wined3d_desc.pool = WINED3D_POOL_DEFAULT;
286 wined3d_desc.width = desc->Width;
287 wined3d_desc.height = desc->Height;
288 wined3d_desc.depth = 1;
289 wined3d_desc.size = 0;
291 if (FAILED(hr = wined3d_texture_create(device->wined3d_device, &wined3d_desc, desc->MipLevels,
292 0, texture, &d3d10_texture2d_wined3d_parent_ops, &texture->wined3d_texture)))
294 WARN("Failed to create wined3d texture, hr %#x.\n", hr);
295 if (texture->dxgi_surface)
296 IUnknown_Release(texture->dxgi_surface);
297 return hr;
299 texture->desc.MipLevels = wined3d_texture_get_level_count(texture->wined3d_texture);
301 texture->device = &device->ID3D10Device1_iface;
302 ID3D10Device1_AddRef(texture->device);
304 return S_OK;
307 static inline struct d3d10_texture3d *impl_from_ID3D10Texture3D(ID3D10Texture3D *iface)
309 return CONTAINING_RECORD(iface, struct d3d10_texture3d, ID3D10Texture3D_iface);
312 static HRESULT STDMETHODCALLTYPE d3d10_texture3d_QueryInterface(ID3D10Texture3D *iface, REFIID riid, void **object)
314 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
316 if (IsEqualGUID(riid, &IID_ID3D10Texture3D)
317 || IsEqualGUID(riid, &IID_ID3D10Resource)
318 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
319 || IsEqualGUID(riid, &IID_IUnknown))
321 IUnknown_AddRef(iface);
322 *object = iface;
323 return S_OK;
326 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
328 *object = NULL;
329 return E_NOINTERFACE;
332 static ULONG STDMETHODCALLTYPE d3d10_texture3d_AddRef(ID3D10Texture3D *iface)
334 struct d3d10_texture3d *texture = impl_from_ID3D10Texture3D(iface);
335 ULONG refcount = InterlockedIncrement(&texture->refcount);
337 TRACE("%p increasing refcount to %u.\n", texture, refcount);
339 if (refcount == 1)
341 ID3D10Device1_AddRef(texture->device);
342 wined3d_texture_incref(texture->wined3d_texture);
345 return refcount;
348 static void STDMETHODCALLTYPE d3d10_texture3d_wined3d_object_released(void *parent)
350 HeapFree(GetProcessHeap(), 0, parent);
353 static ULONG STDMETHODCALLTYPE d3d10_texture3d_Release(ID3D10Texture3D *iface)
355 struct d3d10_texture3d *texture = impl_from_ID3D10Texture3D(iface);
356 ULONG refcount = InterlockedDecrement(&texture->refcount);
358 TRACE("%p decreasing refcount to %u.\n", texture, refcount);
360 if (!refcount)
362 ID3D10Device1 *device = texture->device;
364 wined3d_texture_decref(texture->wined3d_texture);
365 /* Release the device last, it may cause the wined3d device to be
366 * destroyed. */
367 ID3D10Device1_Release(device);
370 return refcount;
373 static void STDMETHODCALLTYPE d3d10_texture3d_GetDevice(ID3D10Texture3D *iface, ID3D10Device **device)
375 struct d3d10_texture3d *texture = impl_from_ID3D10Texture3D(iface);
377 TRACE("iface %p, device %p.\n", iface, device);
379 *device = (ID3D10Device *)texture->device;
380 ID3D10Device_AddRef(*device);
383 static HRESULT STDMETHODCALLTYPE d3d10_texture3d_GetPrivateData(ID3D10Texture3D *iface,
384 REFGUID guid, UINT *data_size, void *data)
386 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
387 iface, debugstr_guid(guid), data_size, data);
389 return E_NOTIMPL;
392 static HRESULT STDMETHODCALLTYPE d3d10_texture3d_SetPrivateData(ID3D10Texture3D *iface,
393 REFGUID guid, UINT data_size, const void *data)
395 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
396 iface, debugstr_guid(guid), data_size, data);
398 return E_NOTIMPL;
401 static HRESULT STDMETHODCALLTYPE d3d10_texture3d_SetPrivateDataInterface(ID3D10Texture3D *iface,
402 REFGUID guid, const IUnknown *data)
404 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
406 return E_NOTIMPL;
409 static void STDMETHODCALLTYPE d3d10_texture3d_GetType(ID3D10Texture3D *iface,
410 D3D10_RESOURCE_DIMENSION *resource_dimension)
412 TRACE("iface %p, resource_dimension %p.\n", iface, resource_dimension);
414 *resource_dimension = D3D10_RESOURCE_DIMENSION_TEXTURE3D;
417 static void STDMETHODCALLTYPE d3d10_texture3d_SetEvictionPriority(ID3D10Texture3D *iface, UINT eviction_priority)
419 FIXME("iface %p, eviction_priority %u stub!\n", iface, eviction_priority);
422 static UINT STDMETHODCALLTYPE d3d10_texture3d_GetEvictionPriority(ID3D10Texture3D *iface)
424 FIXME("iface %p stub!\n", iface);
426 return 0;
429 static HRESULT STDMETHODCALLTYPE d3d10_texture3d_Map(ID3D10Texture3D *iface, UINT sub_resource_idx,
430 D3D10_MAP map_type, UINT map_flags, D3D10_MAPPED_TEXTURE3D *mapped_texture)
432 struct d3d10_texture3d *texture = impl_from_ID3D10Texture3D(iface);
433 struct wined3d_map_desc wined3d_map_desc;
434 struct wined3d_resource *sub_resource;
435 HRESULT hr;
437 TRACE("iface %p, sub_resource_idx %u, map_type %u, map_flags %#x, mapped_texture %p.\n",
438 iface, sub_resource_idx, map_type, map_flags, mapped_texture);
440 if (map_type != D3D10_MAP_READ_WRITE)
441 FIXME("Ignoring map_type %#x.\n", map_type);
442 if (map_flags)
443 FIXME("Ignoring map_flags %#x.\n", map_flags);
445 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
446 hr = E_INVALIDARG;
447 else if (SUCCEEDED(hr = wined3d_volume_map(wined3d_volume_from_resource(sub_resource),
448 &wined3d_map_desc, NULL, 0)))
450 mapped_texture->pData = wined3d_map_desc.data;
451 mapped_texture->RowPitch = wined3d_map_desc.row_pitch;
452 mapped_texture->DepthPitch = wined3d_map_desc.slice_pitch;
455 return hr;
458 static void STDMETHODCALLTYPE d3d10_texture3d_Unmap(ID3D10Texture3D *iface, UINT sub_resource_idx)
460 struct d3d10_texture3d *texture = impl_from_ID3D10Texture3D(iface);
461 struct wined3d_resource *sub_resource;
463 TRACE("iface %p, sub_resource_idx %u.\n", iface, sub_resource_idx);
465 if (!(sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, sub_resource_idx)))
466 return;
468 wined3d_volume_unmap(wined3d_volume_from_resource(sub_resource));
471 static void STDMETHODCALLTYPE d3d10_texture3d_GetDesc(ID3D10Texture3D *iface, D3D10_TEXTURE3D_DESC *desc)
473 struct d3d10_texture3d *texture = impl_from_ID3D10Texture3D(iface);
475 TRACE("iface %p, desc %p.\n", iface, desc);
477 *desc = texture->desc;
480 static const struct ID3D10Texture3DVtbl d3d10_texture3d_vtbl =
482 /* IUnknown methods */
483 d3d10_texture3d_QueryInterface,
484 d3d10_texture3d_AddRef,
485 d3d10_texture3d_Release,
486 /* ID3D10DeviceChild methods */
487 d3d10_texture3d_GetDevice,
488 d3d10_texture3d_GetPrivateData,
489 d3d10_texture3d_SetPrivateData,
490 d3d10_texture3d_SetPrivateDataInterface,
491 /* ID3D10Resource methods */
492 d3d10_texture3d_GetType,
493 d3d10_texture3d_SetEvictionPriority,
494 d3d10_texture3d_GetEvictionPriority,
495 /* ID3D10Texture3D methods */
496 d3d10_texture3d_Map,
497 d3d10_texture3d_Unmap,
498 d3d10_texture3d_GetDesc,
501 static const struct wined3d_parent_ops d3d10_texture3d_wined3d_parent_ops =
503 d3d10_texture3d_wined3d_object_released,
506 HRESULT d3d10_texture3d_init(struct d3d10_texture3d *texture, struct d3d10_device *device,
507 const D3D10_TEXTURE3D_DESC *desc)
509 struct wined3d_resource_desc wined3d_desc;
510 HRESULT hr;
512 texture->ID3D10Texture3D_iface.lpVtbl = &d3d10_texture3d_vtbl;
513 texture->refcount = 1;
514 texture->desc = *desc;
516 wined3d_desc.resource_type = WINED3D_RTYPE_VOLUME_TEXTURE;
517 wined3d_desc.format = wined3dformat_from_dxgi_format(desc->Format);
518 wined3d_desc.multisample_type = WINED3D_MULTISAMPLE_NONE;
519 wined3d_desc.multisample_quality = 0;
520 wined3d_desc.usage = wined3d_usage_from_d3d10core(desc->BindFlags, desc->Usage);
521 wined3d_desc.pool = WINED3D_POOL_DEFAULT;
522 wined3d_desc.width = desc->Width;
523 wined3d_desc.height = desc->Height;
524 wined3d_desc.depth = desc->Depth;
525 wined3d_desc.size = 0;
527 if (FAILED(hr = wined3d_texture_create(device->wined3d_device, &wined3d_desc, desc->MipLevels,
528 0, texture, &d3d10_texture3d_wined3d_parent_ops, &texture->wined3d_texture)))
530 WARN("Failed to create wined3d texture, hr %#x.\n", hr);
531 return hr;
533 texture->desc.MipLevels = wined3d_texture_get_level_count(texture->wined3d_texture);
535 texture->device = &device->ID3D10Device1_iface;
536 ID3D10Device1_AddRef(texture->device);
538 return S_OK;