2 * Copyright 2009 Henri Verbeet for CodeWeavers
3 * Copyright 2015 Józef Kucia for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
24 #include "d3d11_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d11
);
28 /* ID3D11Texture2D methods */
30 static inline struct d3d_texture2d
*impl_from_ID3D11Texture2D(ID3D11Texture2D
*iface
)
32 return CONTAINING_RECORD(iface
, struct d3d_texture2d
, ID3D11Texture2D_iface
);
35 static HRESULT STDMETHODCALLTYPE
d3d11_texture2d_QueryInterface(ID3D11Texture2D
*iface
, REFIID riid
, void **object
)
37 struct d3d_texture2d
*texture
= impl_from_ID3D11Texture2D(iface
);
39 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
41 if (IsEqualGUID(riid
, &IID_ID3D11Texture2D
)
42 || IsEqualGUID(riid
, &IID_ID3D11Resource
)
43 || IsEqualGUID(riid
, &IID_ID3D11DeviceChild
)
44 || IsEqualGUID(riid
, &IID_IUnknown
))
46 *object
= &texture
->ID3D11Texture2D_iface
;
47 IUnknown_AddRef((IUnknown
*)*object
);
50 else if (IsEqualGUID(riid
, &IID_ID3D10Texture2D
)
51 || IsEqualGUID(riid
, &IID_ID3D10Resource
)
52 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
))
54 *object
= &texture
->ID3D10Texture2D_iface
;
55 IUnknown_AddRef((IUnknown
*)*object
);
59 if (texture
->dxgi_surface
)
61 TRACE("Forwarding to dxgi surface.\n");
62 return IUnknown_QueryInterface(texture
->dxgi_surface
, riid
, object
);
65 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
71 static ULONG STDMETHODCALLTYPE
d3d11_texture2d_AddRef(ID3D11Texture2D
*iface
)
73 struct d3d_texture2d
*texture
= impl_from_ID3D11Texture2D(iface
);
74 ULONG refcount
= InterlockedIncrement(&texture
->refcount
);
76 TRACE("%p increasing refcount to %u.\n", texture
, refcount
);
80 ID3D11Device_AddRef(texture
->device
);
82 wined3d_texture_incref(texture
->wined3d_texture
);
83 wined3d_mutex_unlock();
89 static ULONG STDMETHODCALLTYPE
d3d11_texture2d_Release(ID3D11Texture2D
*iface
)
91 struct d3d_texture2d
*texture
= impl_from_ID3D11Texture2D(iface
);
92 ULONG refcount
= InterlockedDecrement(&texture
->refcount
);
94 TRACE("%p decreasing refcount to %u.\n", texture
, refcount
);
98 ID3D11Device
*device
= texture
->device
;
100 wined3d_mutex_lock();
101 wined3d_texture_decref(texture
->wined3d_texture
);
102 wined3d_mutex_unlock();
103 /* Release the device last, it may cause the wined3d device to be
105 ID3D11Device_Release(device
);
111 static void STDMETHODCALLTYPE
d3d11_texture2d_GetDevice(ID3D11Texture2D
*iface
, ID3D11Device
**device
)
113 struct d3d_texture2d
*texture
= impl_from_ID3D11Texture2D(iface
);
115 TRACE("iface %p, device %p.\n", iface
, device
);
117 *device
= texture
->device
;
118 ID3D11Device_AddRef(*device
);
121 static HRESULT STDMETHODCALLTYPE
d3d11_texture2d_GetPrivateData(ID3D11Texture2D
*iface
,
122 REFGUID guid
, UINT
*data_size
, void *data
)
124 struct d3d_texture2d
*texture
= impl_from_ID3D11Texture2D(iface
);
125 IDXGISurface
*dxgi_surface
;
128 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
130 if (texture
->dxgi_surface
131 && SUCCEEDED(IUnknown_QueryInterface(texture
->dxgi_surface
, &IID_IDXGISurface
, (void **)&dxgi_surface
)))
133 hr
= IDXGISurface_GetPrivateData(dxgi_surface
, guid
, data_size
, data
);
134 IDXGISurface_Release(dxgi_surface
);
138 return d3d_get_private_data(&texture
->private_store
, guid
, data_size
, data
);
141 static HRESULT STDMETHODCALLTYPE
d3d11_texture2d_SetPrivateData(ID3D11Texture2D
*iface
,
142 REFGUID guid
, UINT data_size
, const void *data
)
144 struct d3d_texture2d
*texture
= impl_from_ID3D11Texture2D(iface
);
145 IDXGISurface
*dxgi_surface
;
148 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
150 if (texture
->dxgi_surface
151 && SUCCEEDED(IUnknown_QueryInterface(texture
->dxgi_surface
, &IID_IDXGISurface
, (void **)&dxgi_surface
)))
153 hr
= IDXGISurface_SetPrivateData(dxgi_surface
, guid
, data_size
, data
);
154 IDXGISurface_Release(dxgi_surface
);
158 return d3d_set_private_data(&texture
->private_store
, guid
, data_size
, data
);
161 static HRESULT STDMETHODCALLTYPE
d3d11_texture2d_SetPrivateDataInterface(ID3D11Texture2D
*iface
,
162 REFGUID guid
, const IUnknown
*data
)
164 struct d3d_texture2d
*texture
= impl_from_ID3D11Texture2D(iface
);
165 IDXGISurface
*dxgi_surface
;
168 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
170 if (texture
->dxgi_surface
171 && SUCCEEDED(IUnknown_QueryInterface(texture
->dxgi_surface
, &IID_IDXGISurface
, (void **)&dxgi_surface
)))
173 hr
= IDXGISurface_SetPrivateDataInterface(dxgi_surface
, guid
, data
);
174 IDXGISurface_Release(dxgi_surface
);
178 return d3d_set_private_data_interface(&texture
->private_store
, guid
, data
);
181 static void STDMETHODCALLTYPE
d3d11_texture2d_GetType(ID3D11Texture2D
*iface
,
182 D3D11_RESOURCE_DIMENSION
*resource_dimension
)
184 TRACE("iface %p, resource_dimension %p.\n", iface
, resource_dimension
);
186 *resource_dimension
= D3D11_RESOURCE_DIMENSION_TEXTURE2D
;
189 static void STDMETHODCALLTYPE
d3d11_texture2d_SetEvictionPriority(ID3D11Texture2D
*iface
, UINT eviction_priority
)
191 FIXME("iface %p, eviction_priority %#x stub!\n", iface
, eviction_priority
);
194 static UINT STDMETHODCALLTYPE
d3d11_texture2d_GetEvictionPriority(ID3D11Texture2D
*iface
)
196 FIXME("iface %p stub!\n", iface
);
201 static void STDMETHODCALLTYPE
d3d11_texture2d_GetDesc(ID3D11Texture2D
*iface
, D3D11_TEXTURE2D_DESC
*desc
)
203 struct d3d_texture2d
*texture
= impl_from_ID3D11Texture2D(iface
);
204 struct wined3d_resource_desc wined3d_desc
;
206 TRACE("iface %p, desc %p.\n", iface
, desc
);
208 *desc
= texture
->desc
;
210 wined3d_mutex_lock();
211 wined3d_resource_get_desc(wined3d_texture_get_resource(texture
->wined3d_texture
), &wined3d_desc
);
212 wined3d_mutex_unlock();
214 /* FIXME: Resizing swapchain buffers can cause these to change. We'd like
215 * to get everything from wined3d, but e.g. bind flags don't exist as such
217 desc
->Width
= wined3d_desc
.width
;
218 desc
->Height
= wined3d_desc
.height
;
219 desc
->Format
= dxgi_format_from_wined3dformat(wined3d_desc
.format
);
220 desc
->SampleDesc
.Count
= wined3d_desc
.multisample_type
== WINED3D_MULTISAMPLE_NONE
221 ? 1 : wined3d_desc
.multisample_type
;
222 desc
->SampleDesc
.Quality
= wined3d_desc
.multisample_quality
;
225 static const struct ID3D11Texture2DVtbl d3d11_texture2d_vtbl
=
227 /* IUnknown methods */
228 d3d11_texture2d_QueryInterface
,
229 d3d11_texture2d_AddRef
,
230 d3d11_texture2d_Release
,
231 /* ID3D11DeviceChild methods */
232 d3d11_texture2d_GetDevice
,
233 d3d11_texture2d_GetPrivateData
,
234 d3d11_texture2d_SetPrivateData
,
235 d3d11_texture2d_SetPrivateDataInterface
,
236 /* ID3D11Resource methods */
237 d3d11_texture2d_GetType
,
238 d3d11_texture2d_SetEvictionPriority
,
239 d3d11_texture2d_GetEvictionPriority
,
240 /* ID3D11Texture2D methods */
241 d3d11_texture2d_GetDesc
,
244 struct d3d_texture2d
*unsafe_impl_from_ID3D11Texture2D(ID3D11Texture2D
*iface
)
248 assert(iface
->lpVtbl
== &d3d11_texture2d_vtbl
);
249 return CONTAINING_RECORD(iface
, struct d3d_texture2d
, ID3D11Texture2D_iface
);
252 /* IUnknown methods */
254 static HRESULT STDMETHODCALLTYPE
d3d10_texture2d_QueryInterface(ID3D10Texture2D
*iface
, REFIID riid
, void **object
)
256 struct d3d_texture2d
*texture
= impl_from_ID3D10Texture2D(iface
);
258 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
260 return d3d11_texture2d_QueryInterface(&texture
->ID3D11Texture2D_iface
, riid
, object
);
263 static ULONG STDMETHODCALLTYPE
d3d10_texture2d_AddRef(ID3D10Texture2D
*iface
)
265 struct d3d_texture2d
*texture
= impl_from_ID3D10Texture2D(iface
);
267 TRACE("iface %p.\n", iface
);
269 return d3d11_texture2d_AddRef(&texture
->ID3D11Texture2D_iface
);
272 static void STDMETHODCALLTYPE
d3d_texture2d_wined3d_object_released(void *parent
)
274 struct d3d_texture2d
*texture
= parent
;
276 if (texture
->dxgi_surface
) IUnknown_Release(texture
->dxgi_surface
);
277 wined3d_private_store_cleanup(&texture
->private_store
);
278 HeapFree(GetProcessHeap(), 0, texture
);
281 static ULONG STDMETHODCALLTYPE
d3d10_texture2d_Release(ID3D10Texture2D
*iface
)
283 struct d3d_texture2d
*texture
= impl_from_ID3D10Texture2D(iface
);
285 TRACE("iface %p.\n", iface
);
287 return d3d11_texture2d_Release(&texture
->ID3D11Texture2D_iface
);
290 /* ID3D10DeviceChild methods */
292 static void STDMETHODCALLTYPE
d3d10_texture2d_GetDevice(ID3D10Texture2D
*iface
, ID3D10Device
**device
)
294 struct d3d_texture2d
*texture
= impl_from_ID3D10Texture2D(iface
);
296 TRACE("iface %p, device %p.\n", iface
, device
);
298 ID3D11Device_QueryInterface(texture
->device
, &IID_ID3D10Device
, (void **)device
);
301 static HRESULT STDMETHODCALLTYPE
d3d10_texture2d_GetPrivateData(ID3D10Texture2D
*iface
,
302 REFGUID guid
, UINT
*data_size
, void *data
)
304 struct d3d_texture2d
*texture
= impl_from_ID3D10Texture2D(iface
);
306 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
308 return d3d11_texture2d_GetPrivateData(&texture
->ID3D11Texture2D_iface
, guid
, data_size
, data
);
311 static HRESULT STDMETHODCALLTYPE
d3d10_texture2d_SetPrivateData(ID3D10Texture2D
*iface
,
312 REFGUID guid
, UINT data_size
, const void *data
)
314 struct d3d_texture2d
*texture
= impl_from_ID3D10Texture2D(iface
);
316 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
318 return d3d11_texture2d_SetPrivateData(&texture
->ID3D11Texture2D_iface
, guid
, data_size
, data
);
321 static HRESULT STDMETHODCALLTYPE
d3d10_texture2d_SetPrivateDataInterface(ID3D10Texture2D
*iface
,
322 REFGUID guid
, const IUnknown
*data
)
324 struct d3d_texture2d
*texture
= impl_from_ID3D10Texture2D(iface
);
326 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
328 return d3d11_texture2d_SetPrivateDataInterface(&texture
->ID3D11Texture2D_iface
, guid
, data
);
331 /* ID3D10Resource methods */
333 static void STDMETHODCALLTYPE
d3d10_texture2d_GetType(ID3D10Texture2D
*iface
,
334 D3D10_RESOURCE_DIMENSION
*resource_dimension
)
336 TRACE("iface %p, resource_dimension %p\n", iface
, resource_dimension
);
338 *resource_dimension
= D3D10_RESOURCE_DIMENSION_TEXTURE2D
;
341 static void STDMETHODCALLTYPE
d3d10_texture2d_SetEvictionPriority(ID3D10Texture2D
*iface
, UINT eviction_priority
)
343 FIXME("iface %p, eviction_priority %u stub!\n", iface
, eviction_priority
);
346 static UINT STDMETHODCALLTYPE
d3d10_texture2d_GetEvictionPriority(ID3D10Texture2D
*iface
)
348 FIXME("iface %p stub!\n", iface
);
353 /* ID3D10Texture2D methods */
355 static HRESULT STDMETHODCALLTYPE
d3d10_texture2d_Map(ID3D10Texture2D
*iface
, UINT sub_resource_idx
,
356 D3D10_MAP map_type
, UINT map_flags
, D3D10_MAPPED_TEXTURE2D
*mapped_texture
)
358 struct d3d_texture2d
*texture
= impl_from_ID3D10Texture2D(iface
);
359 struct wined3d_map_desc wined3d_map_desc
;
362 TRACE("iface %p, sub_resource_idx %u, map_type %u, map_flags %#x, mapped_texture %p.\n",
363 iface
, sub_resource_idx
, map_type
, map_flags
, mapped_texture
);
366 FIXME("Ignoring map_flags %#x.\n", map_flags
);
368 wined3d_mutex_lock();
369 if (SUCCEEDED(hr
= wined3d_resource_map(wined3d_texture_get_resource(texture
->wined3d_texture
), sub_resource_idx
,
370 &wined3d_map_desc
, NULL
, wined3d_map_flags_from_d3d11_map_type(map_type
))))
372 mapped_texture
->pData
= wined3d_map_desc
.data
;
373 mapped_texture
->RowPitch
= wined3d_map_desc
.row_pitch
;
375 wined3d_mutex_unlock();
380 static void STDMETHODCALLTYPE
d3d10_texture2d_Unmap(ID3D10Texture2D
*iface
, UINT sub_resource_idx
)
382 struct d3d_texture2d
*texture
= impl_from_ID3D10Texture2D(iface
);
384 TRACE("iface %p, sub_resource_idx %u.\n", iface
, sub_resource_idx
);
386 wined3d_mutex_lock();
387 wined3d_resource_unmap(wined3d_texture_get_resource(texture
->wined3d_texture
), sub_resource_idx
);
388 wined3d_mutex_unlock();
391 static void STDMETHODCALLTYPE
d3d10_texture2d_GetDesc(ID3D10Texture2D
*iface
, D3D10_TEXTURE2D_DESC
*desc
)
393 struct d3d_texture2d
*texture
= impl_from_ID3D10Texture2D(iface
);
394 D3D11_TEXTURE2D_DESC d3d11_desc
;
396 TRACE("iface %p, desc %p\n", iface
, desc
);
398 d3d11_texture2d_GetDesc(&texture
->ID3D11Texture2D_iface
, &d3d11_desc
);
400 desc
->Width
= d3d11_desc
.Width
;
401 desc
->Height
= d3d11_desc
.Height
;
402 desc
->MipLevels
= d3d11_desc
.MipLevels
;
403 desc
->ArraySize
= d3d11_desc
.ArraySize
;
404 desc
->Format
= d3d11_desc
.Format
;
405 desc
->SampleDesc
= d3d11_desc
.SampleDesc
;
406 desc
->Usage
= d3d10_usage_from_d3d11_usage(d3d11_desc
.Usage
);
407 desc
->BindFlags
= d3d10_bind_flags_from_d3d11_bind_flags(d3d11_desc
.BindFlags
);
408 desc
->CPUAccessFlags
= d3d10_cpu_access_flags_from_d3d11_cpu_access_flags(d3d11_desc
.CPUAccessFlags
);
409 desc
->MiscFlags
= d3d10_resource_misc_flags_from_d3d11_resource_misc_flags(d3d11_desc
.MiscFlags
);
412 static const struct ID3D10Texture2DVtbl d3d10_texture2d_vtbl
=
414 /* IUnknown methods */
415 d3d10_texture2d_QueryInterface
,
416 d3d10_texture2d_AddRef
,
417 d3d10_texture2d_Release
,
418 /* ID3D10DeviceChild methods */
419 d3d10_texture2d_GetDevice
,
420 d3d10_texture2d_GetPrivateData
,
421 d3d10_texture2d_SetPrivateData
,
422 d3d10_texture2d_SetPrivateDataInterface
,
423 /* ID3D10Resource methods */
424 d3d10_texture2d_GetType
,
425 d3d10_texture2d_SetEvictionPriority
,
426 d3d10_texture2d_GetEvictionPriority
,
427 /* ID3D10Texture2D methods */
429 d3d10_texture2d_Unmap
,
430 d3d10_texture2d_GetDesc
,
433 struct d3d_texture2d
*unsafe_impl_from_ID3D10Texture2D(ID3D10Texture2D
*iface
)
437 assert(iface
->lpVtbl
== &d3d10_texture2d_vtbl
);
438 return CONTAINING_RECORD(iface
, struct d3d_texture2d
, ID3D10Texture2D_iface
);
441 static const struct wined3d_parent_ops d3d_texture2d_wined3d_parent_ops
=
443 d3d_texture2d_wined3d_object_released
,
446 static BOOL
is_gdi_compatible_texture(const D3D11_TEXTURE2D_DESC
*desc
)
448 if (!(desc
->Format
== DXGI_FORMAT_B8G8R8A8_UNORM
449 || desc
->Format
== DXGI_FORMAT_B8G8R8A8_TYPELESS
450 || desc
->Format
== DXGI_FORMAT_B8G8R8A8_UNORM_SRGB
))
453 if (desc
->Usage
!= D3D11_USAGE_DEFAULT
)
459 static BOOL
validate_texture2d_desc(const D3D11_TEXTURE2D_DESC
*desc
)
461 if (desc
->MiscFlags
& D3D11_RESOURCE_MISC_TEXTURECUBE
462 && desc
->ArraySize
< 6)
464 WARN("Invalid array size %u for cube texture.\n", desc
->ArraySize
);
468 if (desc
->MiscFlags
& D3D11_RESOURCE_MISC_GDI_COMPATIBLE
469 && !is_gdi_compatible_texture(desc
))
471 WARN("Incompatible description used to create GDI compatible texture.\n");
478 static HRESULT
d3d_texture2d_init(struct d3d_texture2d
*texture
, struct d3d_device
*device
,
479 const D3D11_TEXTURE2D_DESC
*desc
, const D3D11_SUBRESOURCE_DATA
*data
)
481 struct wined3d_resource_desc wined3d_desc
;
486 if (!validate_texture2d_desc(desc
))
489 texture
->ID3D11Texture2D_iface
.lpVtbl
= &d3d11_texture2d_vtbl
;
490 texture
->ID3D10Texture2D_iface
.lpVtbl
= &d3d10_texture2d_vtbl
;
491 texture
->refcount
= 1;
492 wined3d_mutex_lock();
493 wined3d_private_store_init(&texture
->private_store
);
494 texture
->desc
= *desc
;
496 if (desc
->SampleDesc
.Count
> 1)
497 FIXME("Multisampled textures not implemented.\n");
499 wined3d_desc
.resource_type
= WINED3D_RTYPE_TEXTURE_2D
;
500 wined3d_desc
.format
= wined3dformat_from_dxgi_format(desc
->Format
);
501 wined3d_desc
.multisample_type
= desc
->SampleDesc
.Count
> 1 ? desc
->SampleDesc
.Count
: WINED3D_MULTISAMPLE_NONE
;
502 wined3d_desc
.multisample_quality
= desc
->SampleDesc
.Quality
;
503 wined3d_desc
.usage
= wined3d_usage_from_d3d11(desc
->BindFlags
, desc
->Usage
);
504 wined3d_desc
.pool
= WINED3D_POOL_DEFAULT
;
505 wined3d_desc
.width
= desc
->Width
;
506 wined3d_desc
.height
= desc
->Height
;
507 wined3d_desc
.depth
= 1;
508 wined3d_desc
.size
= 0;
510 levels
= desc
->MipLevels
? desc
->MipLevels
: wined3d_log2i(max(desc
->Width
, desc
->Height
)) + 1;
512 if (desc
->MiscFlags
& D3D11_RESOURCE_MISC_GDI_COMPATIBLE
)
513 flags
|= WINED3D_TEXTURE_CREATE_GET_DC
;
515 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, &wined3d_desc
,
516 desc
->ArraySize
, levels
, flags
, (struct wined3d_sub_resource_data
*)data
,
517 texture
, &d3d_texture2d_wined3d_parent_ops
, &texture
->wined3d_texture
)))
519 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
520 wined3d_private_store_cleanup(&texture
->private_store
);
521 wined3d_mutex_unlock();
522 if (hr
== WINED3DERR_NOTAVAILABLE
|| hr
== WINED3DERR_INVALIDCALL
)
526 texture
->desc
.MipLevels
= levels
;
528 if (desc
->MipLevels
== 1 && desc
->ArraySize
== 1)
530 IWineDXGIDevice
*wine_device
;
532 if (FAILED(hr
= ID3D10Device1_QueryInterface(&device
->ID3D10Device1_iface
, &IID_IWineDXGIDevice
,
533 (void **)&wine_device
)))
535 ERR("Device should implement IWineDXGIDevice.\n");
536 wined3d_texture_decref(texture
->wined3d_texture
);
537 wined3d_mutex_unlock();
541 hr
= IWineDXGIDevice_create_surface(wine_device
, texture
->wined3d_texture
, 0, NULL
,
542 (IUnknown
*)&texture
->ID3D10Texture2D_iface
, (void **)&texture
->dxgi_surface
);
543 IWineDXGIDevice_Release(wine_device
);
546 ERR("Failed to create DXGI surface, returning %#x\n", hr
);
547 texture
->dxgi_surface
= NULL
;
548 wined3d_texture_decref(texture
->wined3d_texture
);
549 wined3d_mutex_unlock();
553 wined3d_mutex_unlock();
555 texture
->device
= &device
->ID3D11Device_iface
;
556 ID3D11Device_AddRef(texture
->device
);
561 HRESULT
d3d_texture2d_create(struct d3d_device
*device
, const D3D11_TEXTURE2D_DESC
*desc
,
562 const D3D11_SUBRESOURCE_DATA
*data
, struct d3d_texture2d
**texture
)
564 struct d3d_texture2d
*object
;
567 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
568 return E_OUTOFMEMORY
;
570 if (FAILED(hr
= d3d_texture2d_init(object
, device
, desc
, data
)))
572 WARN("Failed to initialize texture, hr %#x.\n", hr
);
573 HeapFree(GetProcessHeap(), 0, object
);
577 TRACE("Created texture %p.\n", object
);
583 /* ID3D11Texture3D methods */
585 static inline struct d3d_texture3d
*impl_from_ID3D11Texture3D(ID3D11Texture3D
*iface
)
587 return CONTAINING_RECORD(iface
, struct d3d_texture3d
, ID3D11Texture3D_iface
);
590 static HRESULT STDMETHODCALLTYPE
d3d11_texture3d_QueryInterface(ID3D11Texture3D
*iface
, REFIID riid
, void **object
)
592 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
594 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
596 if (IsEqualGUID(riid
, &IID_ID3D11Texture3D
)
597 || IsEqualGUID(riid
, &IID_ID3D11Resource
)
598 || IsEqualGUID(riid
, &IID_ID3D11DeviceChild
)
599 || IsEqualGUID(riid
, &IID_IUnknown
))
601 IUnknown_AddRef(iface
);
605 else if (IsEqualGUID(riid
, &IID_ID3D10Texture3D
)
606 || IsEqualGUID(riid
, &IID_ID3D10Resource
)
607 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
))
609 IUnknown_AddRef(iface
);
610 *object
= &texture
->ID3D10Texture3D_iface
;
614 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
617 return E_NOINTERFACE
;
620 static ULONG STDMETHODCALLTYPE
d3d11_texture3d_AddRef(ID3D11Texture3D
*iface
)
622 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
623 ULONG refcount
= InterlockedIncrement(&texture
->refcount
);
625 TRACE("%p increasing refcount to %u.\n", texture
, refcount
);
629 ID3D11Device_AddRef(texture
->device
);
630 wined3d_mutex_lock();
631 wined3d_texture_incref(texture
->wined3d_texture
);
632 wined3d_mutex_unlock();
638 static void STDMETHODCALLTYPE
d3d_texture3d_wined3d_object_released(void *parent
)
640 struct d3d_texture3d
*texture
= parent
;
642 wined3d_private_store_cleanup(&texture
->private_store
);
643 HeapFree(GetProcessHeap(), 0, parent
);
646 static ULONG STDMETHODCALLTYPE
d3d11_texture3d_Release(ID3D11Texture3D
*iface
)
648 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
649 ULONG refcount
= InterlockedDecrement(&texture
->refcount
);
651 TRACE("%p decreasing refcount to %u.\n", texture
, refcount
);
655 ID3D11Device
*device
= texture
->device
;
657 wined3d_mutex_lock();
658 wined3d_texture_decref(texture
->wined3d_texture
);
659 wined3d_mutex_unlock();
660 /* Release the device last, it may cause the wined3d device to be
662 ID3D11Device_Release(device
);
668 static void STDMETHODCALLTYPE
d3d11_texture3d_GetDevice(ID3D11Texture3D
*iface
, ID3D11Device
**device
)
670 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
672 TRACE("iface %p, device %p.\n", iface
, device
);
674 *device
= texture
->device
;
675 ID3D11Device_AddRef(*device
);
678 static HRESULT STDMETHODCALLTYPE
d3d11_texture3d_GetPrivateData(ID3D11Texture3D
*iface
,
679 REFGUID guid
, UINT
*data_size
, void *data
)
681 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
683 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
685 return d3d_get_private_data(&texture
->private_store
, guid
, data_size
, data
);
688 static HRESULT STDMETHODCALLTYPE
d3d11_texture3d_SetPrivateData(ID3D11Texture3D
*iface
,
689 REFGUID guid
, UINT data_size
, const void *data
)
691 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
693 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface
, debugstr_guid(guid
), data_size
, data
);
695 return d3d_set_private_data(&texture
->private_store
, guid
, data_size
, data
);
698 static HRESULT STDMETHODCALLTYPE
d3d11_texture3d_SetPrivateDataInterface(ID3D11Texture3D
*iface
,
699 REFGUID guid
, const IUnknown
*data
)
701 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
703 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
705 return d3d_set_private_data_interface(&texture
->private_store
, guid
, data
);
708 static void STDMETHODCALLTYPE
d3d11_texture3d_GetType(ID3D11Texture3D
*iface
,
709 D3D11_RESOURCE_DIMENSION
*resource_dimension
)
711 TRACE("iface %p, resource_dimension %p.\n", iface
, resource_dimension
);
713 *resource_dimension
= D3D11_RESOURCE_DIMENSION_TEXTURE3D
;
716 static void STDMETHODCALLTYPE
d3d11_texture3d_SetEvictionPriority(ID3D11Texture3D
*iface
, UINT eviction_priority
)
718 FIXME("iface %p, eviction_priority %#x stub!\n", iface
, eviction_priority
);
721 static UINT STDMETHODCALLTYPE
d3d11_texture3d_GetEvictionPriority(ID3D11Texture3D
*iface
)
723 FIXME("iface %p stub!\n", iface
);
728 static void STDMETHODCALLTYPE
d3d11_texture3d_GetDesc(ID3D11Texture3D
*iface
, D3D11_TEXTURE3D_DESC
*desc
)
730 struct d3d_texture3d
*texture
= impl_from_ID3D11Texture3D(iface
);
732 TRACE("iface %p, desc %p.\n", iface
, desc
);
734 *desc
= texture
->desc
;
737 static const struct ID3D11Texture3DVtbl d3d11_texture3d_vtbl
=
739 /* IUnknown methods */
740 d3d11_texture3d_QueryInterface
,
741 d3d11_texture3d_AddRef
,
742 d3d11_texture3d_Release
,
743 /* ID3D11DeviceChild methods */
744 d3d11_texture3d_GetDevice
,
745 d3d11_texture3d_GetPrivateData
,
746 d3d11_texture3d_SetPrivateData
,
747 d3d11_texture3d_SetPrivateDataInterface
,
748 /* ID3D11Resource methods */
749 d3d11_texture3d_GetType
,
750 d3d11_texture3d_SetEvictionPriority
,
751 d3d11_texture3d_GetEvictionPriority
,
752 /* ID3D11Texture3D methods */
753 d3d11_texture3d_GetDesc
,
756 /* ID3D10Texture3D methods */
758 static inline struct d3d_texture3d
*impl_from_ID3D10Texture3D(ID3D10Texture3D
*iface
)
760 return CONTAINING_RECORD(iface
, struct d3d_texture3d
, ID3D10Texture3D_iface
);
763 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_QueryInterface(ID3D10Texture3D
*iface
, REFIID riid
, void **object
)
765 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
767 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
769 return d3d11_texture3d_QueryInterface(&texture
->ID3D11Texture3D_iface
, riid
, object
);
772 static ULONG STDMETHODCALLTYPE
d3d10_texture3d_AddRef(ID3D10Texture3D
*iface
)
774 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
776 TRACE("iface %p.\n", iface
);
778 return d3d11_texture3d_AddRef(&texture
->ID3D11Texture3D_iface
);
781 static ULONG STDMETHODCALLTYPE
d3d10_texture3d_Release(ID3D10Texture3D
*iface
)
783 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
785 TRACE("iface %p.\n", iface
);
787 return d3d11_texture3d_Release(&texture
->ID3D11Texture3D_iface
);
790 static void STDMETHODCALLTYPE
d3d10_texture3d_GetDevice(ID3D10Texture3D
*iface
, ID3D10Device
**device
)
792 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
794 TRACE("iface %p, device %p.\n", iface
, device
);
796 ID3D11Device_QueryInterface(texture
->device
, &IID_ID3D10Device
, (void **)device
);
799 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_GetPrivateData(ID3D10Texture3D
*iface
,
800 REFGUID guid
, UINT
*data_size
, void *data
)
802 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
804 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
805 iface
, debugstr_guid(guid
), data_size
, data
);
807 return d3d_get_private_data(&texture
->private_store
, guid
, data_size
, data
);
810 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_SetPrivateData(ID3D10Texture3D
*iface
,
811 REFGUID guid
, UINT data_size
, const void *data
)
813 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
815 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
816 iface
, debugstr_guid(guid
), data_size
, data
);
818 return d3d_set_private_data(&texture
->private_store
, guid
, data_size
, data
);
821 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_SetPrivateDataInterface(ID3D10Texture3D
*iface
,
822 REFGUID guid
, const IUnknown
*data
)
824 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
826 TRACE("iface %p, guid %s, data %p.\n", iface
, debugstr_guid(guid
), data
);
828 return d3d_set_private_data_interface(&texture
->private_store
, guid
, data
);
831 static void STDMETHODCALLTYPE
d3d10_texture3d_GetType(ID3D10Texture3D
*iface
,
832 D3D10_RESOURCE_DIMENSION
*resource_dimension
)
834 TRACE("iface %p, resource_dimension %p.\n", iface
, resource_dimension
);
836 *resource_dimension
= D3D10_RESOURCE_DIMENSION_TEXTURE3D
;
839 static void STDMETHODCALLTYPE
d3d10_texture3d_SetEvictionPriority(ID3D10Texture3D
*iface
, UINT eviction_priority
)
841 FIXME("iface %p, eviction_priority %u stub!\n", iface
, eviction_priority
);
844 static UINT STDMETHODCALLTYPE
d3d10_texture3d_GetEvictionPriority(ID3D10Texture3D
*iface
)
846 FIXME("iface %p stub!\n", iface
);
851 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_Map(ID3D10Texture3D
*iface
, UINT sub_resource_idx
,
852 D3D10_MAP map_type
, UINT map_flags
, D3D10_MAPPED_TEXTURE3D
*mapped_texture
)
854 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
855 struct wined3d_map_desc wined3d_map_desc
;
858 TRACE("iface %p, sub_resource_idx %u, map_type %u, map_flags %#x, mapped_texture %p.\n",
859 iface
, sub_resource_idx
, map_type
, map_flags
, mapped_texture
);
862 FIXME("Ignoring map_flags %#x.\n", map_flags
);
864 wined3d_mutex_lock();
865 if (SUCCEEDED(hr
= wined3d_resource_map(wined3d_texture_get_resource(texture
->wined3d_texture
), sub_resource_idx
,
866 &wined3d_map_desc
, NULL
, wined3d_map_flags_from_d3d11_map_type(map_type
))))
868 mapped_texture
->pData
= wined3d_map_desc
.data
;
869 mapped_texture
->RowPitch
= wined3d_map_desc
.row_pitch
;
870 mapped_texture
->DepthPitch
= wined3d_map_desc
.slice_pitch
;
872 wined3d_mutex_unlock();
877 static void STDMETHODCALLTYPE
d3d10_texture3d_Unmap(ID3D10Texture3D
*iface
, UINT sub_resource_idx
)
879 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
881 TRACE("iface %p, sub_resource_idx %u.\n", iface
, sub_resource_idx
);
883 wined3d_mutex_lock();
884 wined3d_resource_unmap(wined3d_texture_get_resource(texture
->wined3d_texture
), sub_resource_idx
);
885 wined3d_mutex_unlock();
888 static void STDMETHODCALLTYPE
d3d10_texture3d_GetDesc(ID3D10Texture3D
*iface
, D3D10_TEXTURE3D_DESC
*desc
)
890 struct d3d_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
891 D3D11_TEXTURE3D_DESC d3d11_desc
;
893 TRACE("iface %p, desc %p.\n", iface
, desc
);
895 d3d11_texture3d_GetDesc(&texture
->ID3D11Texture3D_iface
, &d3d11_desc
);
897 desc
->Width
= d3d11_desc
.Width
;
898 desc
->Height
= d3d11_desc
.Height
;
899 desc
->Depth
= d3d11_desc
.Depth
;
900 desc
->MipLevels
= d3d11_desc
.MipLevels
;
901 desc
->Format
= d3d11_desc
.Format
;
902 desc
->Usage
= d3d10_usage_from_d3d11_usage(d3d11_desc
.Usage
);
903 desc
->BindFlags
= d3d10_bind_flags_from_d3d11_bind_flags(d3d11_desc
.BindFlags
);
904 desc
->CPUAccessFlags
= d3d10_cpu_access_flags_from_d3d11_cpu_access_flags(d3d11_desc
.CPUAccessFlags
);
905 desc
->MiscFlags
= d3d10_resource_misc_flags_from_d3d11_resource_misc_flags(d3d11_desc
.MiscFlags
);
908 static const struct ID3D10Texture3DVtbl d3d10_texture3d_vtbl
=
910 /* IUnknown methods */
911 d3d10_texture3d_QueryInterface
,
912 d3d10_texture3d_AddRef
,
913 d3d10_texture3d_Release
,
914 /* ID3D10DeviceChild methods */
915 d3d10_texture3d_GetDevice
,
916 d3d10_texture3d_GetPrivateData
,
917 d3d10_texture3d_SetPrivateData
,
918 d3d10_texture3d_SetPrivateDataInterface
,
919 /* ID3D10Resource methods */
920 d3d10_texture3d_GetType
,
921 d3d10_texture3d_SetEvictionPriority
,
922 d3d10_texture3d_GetEvictionPriority
,
923 /* ID3D10Texture3D methods */
925 d3d10_texture3d_Unmap
,
926 d3d10_texture3d_GetDesc
,
929 struct d3d_texture3d
*unsafe_impl_from_ID3D11Texture3D(ID3D11Texture3D
*iface
)
933 assert(iface
->lpVtbl
== &d3d11_texture3d_vtbl
);
934 return impl_from_ID3D11Texture3D(iface
);
937 static const struct wined3d_parent_ops d3d_texture3d_wined3d_parent_ops
=
939 d3d_texture3d_wined3d_object_released
,
942 static HRESULT
d3d_texture3d_init(struct d3d_texture3d
*texture
, struct d3d_device
*device
,
943 const D3D11_TEXTURE3D_DESC
*desc
, const D3D11_SUBRESOURCE_DATA
*data
)
945 struct wined3d_resource_desc wined3d_desc
;
949 texture
->ID3D11Texture3D_iface
.lpVtbl
= &d3d11_texture3d_vtbl
;
950 texture
->ID3D10Texture3D_iface
.lpVtbl
= &d3d10_texture3d_vtbl
;
951 texture
->refcount
= 1;
952 wined3d_mutex_lock();
953 wined3d_private_store_init(&texture
->private_store
);
954 texture
->desc
= *desc
;
956 wined3d_desc
.resource_type
= WINED3D_RTYPE_TEXTURE_3D
;
957 wined3d_desc
.format
= wined3dformat_from_dxgi_format(desc
->Format
);
958 wined3d_desc
.multisample_type
= WINED3D_MULTISAMPLE_NONE
;
959 wined3d_desc
.multisample_quality
= 0;
960 wined3d_desc
.usage
= wined3d_usage_from_d3d11(desc
->BindFlags
, desc
->Usage
);
961 wined3d_desc
.pool
= desc
->Usage
== D3D11_USAGE_STAGING
? WINED3D_POOL_MANAGED
: WINED3D_POOL_DEFAULT
;
962 wined3d_desc
.width
= desc
->Width
;
963 wined3d_desc
.height
= desc
->Height
;
964 wined3d_desc
.depth
= desc
->Depth
;
965 wined3d_desc
.size
= 0;
967 levels
= desc
->MipLevels
? desc
->MipLevels
: wined3d_log2i(max(max(desc
->Width
, desc
->Height
), desc
->Depth
)) + 1;
969 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, &wined3d_desc
,
970 1, levels
, 0, (struct wined3d_sub_resource_data
*)data
, texture
,
971 &d3d_texture3d_wined3d_parent_ops
, &texture
->wined3d_texture
)))
973 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
974 wined3d_private_store_cleanup(&texture
->private_store
);
975 wined3d_mutex_unlock();
976 if (hr
== WINED3DERR_INVALIDCALL
)
980 wined3d_mutex_unlock();
981 texture
->desc
.MipLevels
= levels
;
983 texture
->device
= &device
->ID3D11Device_iface
;
984 ID3D11Device_AddRef(texture
->device
);
989 HRESULT
d3d_texture3d_create(struct d3d_device
*device
, const D3D11_TEXTURE3D_DESC
*desc
,
990 const D3D11_SUBRESOURCE_DATA
*data
, struct d3d_texture3d
**texture
)
992 struct d3d_texture3d
*object
;
995 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
996 return E_OUTOFMEMORY
;
998 if (FAILED(hr
= d3d_texture3d_init(object
, device
, desc
, data
)))
1000 WARN("Failed to initialize texture, hr %#x.\n", hr
);
1001 HeapFree(GetProcessHeap(), 0, object
);
1005 TRACE("Created texture %p.\n", object
);