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
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
);
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
));
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
);
71 ID3D10Device1_AddRef(This
->device
);
72 wined3d_texture_incref(This
->wined3d_texture
);
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
);
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
100 ID3D10Device1_Release(device
);
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
);
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
);
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
);
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
);
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
;
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
);
182 FIXME("Ignoring map_flags %#x.\n", map_flags
);
184 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, sub_resource_idx
)))
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
;
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
)))
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
);
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 */
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
;
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 DXGI_SURFACE_DESC surface_desc
;
257 IWineDXGIDevice
*wine_device
;
259 if (FAILED(hr
= ID3D10Device1_QueryInterface(&device
->ID3D10Device1_iface
, &IID_IWineDXGIDevice
,
260 (void **)&wine_device
)))
262 ERR("Device should implement IWineDXGIDevice.\n");
266 surface_desc
.Width
= desc
->Width
;
267 surface_desc
.Height
= desc
->Height
;
268 surface_desc
.Format
= desc
->Format
;
269 surface_desc
.SampleDesc
= desc
->SampleDesc
;
271 hr
= IWineDXGIDevice_create_surface(wine_device
, &surface_desc
, 0, NULL
,
272 (IUnknown
*)&texture
->ID3D10Texture2D_iface
, (void **)&texture
->dxgi_surface
);
273 IWineDXGIDevice_Release(wine_device
);
276 ERR("Failed to create DXGI surface, returning %#x\n", hr
);
281 if (desc
->ArraySize
!= 1)
282 FIXME("Array textures not implemented.\n");
283 if (desc
->SampleDesc
.Count
> 1)
284 FIXME("Multisampled textures not implemented.\n");
286 wined3d_desc
.resource_type
= WINED3D_RTYPE_TEXTURE
;
287 wined3d_desc
.format
= wined3dformat_from_dxgi_format(desc
->Format
);
288 wined3d_desc
.multisample_type
= desc
->SampleDesc
.Count
> 1 ? desc
->SampleDesc
.Count
: WINED3D_MULTISAMPLE_NONE
;
289 wined3d_desc
.multisample_quality
= desc
->SampleDesc
.Quality
;
290 wined3d_desc
.usage
= wined3d_usage_from_d3d10core(desc
->BindFlags
, desc
->Usage
);
291 wined3d_desc
.pool
= WINED3D_POOL_DEFAULT
;
292 wined3d_desc
.width
= desc
->Width
;
293 wined3d_desc
.height
= desc
->Height
;
294 wined3d_desc
.depth
= 1;
295 wined3d_desc
.size
= 0;
297 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, &wined3d_desc
, desc
->MipLevels
,
298 0, texture
, &d3d10_texture2d_wined3d_parent_ops
, &texture
->wined3d_texture
)))
300 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
301 if (texture
->dxgi_surface
)
302 IUnknown_Release(texture
->dxgi_surface
);
305 texture
->desc
.MipLevels
= wined3d_texture_get_level_count(texture
->wined3d_texture
);
307 texture
->device
= &device
->ID3D10Device1_iface
;
308 ID3D10Device1_AddRef(texture
->device
);
313 static inline struct d3d10_texture3d
*impl_from_ID3D10Texture3D(ID3D10Texture3D
*iface
)
315 return CONTAINING_RECORD(iface
, struct d3d10_texture3d
, ID3D10Texture3D_iface
);
318 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_QueryInterface(ID3D10Texture3D
*iface
, REFIID riid
, void **object
)
320 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
322 if (IsEqualGUID(riid
, &IID_ID3D10Texture3D
)
323 || IsEqualGUID(riid
, &IID_ID3D10Resource
)
324 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
)
325 || IsEqualGUID(riid
, &IID_IUnknown
))
327 IUnknown_AddRef(iface
);
332 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
335 return E_NOINTERFACE
;
338 static ULONG STDMETHODCALLTYPE
d3d10_texture3d_AddRef(ID3D10Texture3D
*iface
)
340 struct d3d10_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
341 ULONG refcount
= InterlockedIncrement(&texture
->refcount
);
343 TRACE("%p increasing refcount to %u.\n", texture
, refcount
);
347 ID3D10Device1_AddRef(texture
->device
);
348 wined3d_texture_incref(texture
->wined3d_texture
);
354 static void STDMETHODCALLTYPE
d3d10_texture3d_wined3d_object_released(void *parent
)
356 HeapFree(GetProcessHeap(), 0, parent
);
359 static ULONG STDMETHODCALLTYPE
d3d10_texture3d_Release(ID3D10Texture3D
*iface
)
361 struct d3d10_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
362 ULONG refcount
= InterlockedDecrement(&texture
->refcount
);
364 TRACE("%p decreasing refcount to %u.\n", texture
, refcount
);
368 ID3D10Device1
*device
= texture
->device
;
370 wined3d_texture_decref(texture
->wined3d_texture
);
371 /* Release the device last, it may cause the wined3d device to be
373 ID3D10Device1_Release(device
);
379 static void STDMETHODCALLTYPE
d3d10_texture3d_GetDevice(ID3D10Texture3D
*iface
, ID3D10Device
**device
)
381 struct d3d10_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
383 TRACE("iface %p, device %p.\n", iface
, device
);
385 *device
= (ID3D10Device
*)texture
->device
;
386 ID3D10Device_AddRef(*device
);
389 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_GetPrivateData(ID3D10Texture3D
*iface
,
390 REFGUID guid
, UINT
*data_size
, void *data
)
392 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
393 iface
, debugstr_guid(guid
), data_size
, data
);
398 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_SetPrivateData(ID3D10Texture3D
*iface
,
399 REFGUID guid
, UINT data_size
, const void *data
)
401 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
402 iface
, debugstr_guid(guid
), data_size
, data
);
407 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_SetPrivateDataInterface(ID3D10Texture3D
*iface
,
408 REFGUID guid
, const IUnknown
*data
)
410 FIXME("iface %p, guid %s, data %p stub!\n", iface
, debugstr_guid(guid
), data
);
415 static void STDMETHODCALLTYPE
d3d10_texture3d_GetType(ID3D10Texture3D
*iface
,
416 D3D10_RESOURCE_DIMENSION
*resource_dimension
)
418 TRACE("iface %p, resource_dimension %p.\n", iface
, resource_dimension
);
420 *resource_dimension
= D3D10_RESOURCE_DIMENSION_TEXTURE3D
;
423 static void STDMETHODCALLTYPE
d3d10_texture3d_SetEvictionPriority(ID3D10Texture3D
*iface
, UINT eviction_priority
)
425 FIXME("iface %p, eviction_priority %u stub!\n", iface
, eviction_priority
);
428 static UINT STDMETHODCALLTYPE
d3d10_texture3d_GetEvictionPriority(ID3D10Texture3D
*iface
)
430 FIXME("iface %p stub!\n", iface
);
435 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_Map(ID3D10Texture3D
*iface
, UINT sub_resource_idx
,
436 D3D10_MAP map_type
, UINT map_flags
, D3D10_MAPPED_TEXTURE3D
*mapped_texture
)
438 struct d3d10_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
439 struct wined3d_map_desc wined3d_map_desc
;
440 struct wined3d_resource
*sub_resource
;
443 TRACE("iface %p, sub_resource_idx %u, map_type %u, map_flags %#x, mapped_texture %p.\n",
444 iface
, sub_resource_idx
, map_type
, map_flags
, mapped_texture
);
446 if (map_type
!= D3D10_MAP_READ_WRITE
)
447 FIXME("Ignoring map_type %#x.\n", map_type
);
449 FIXME("Ignoring map_flags %#x.\n", map_flags
);
451 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, sub_resource_idx
)))
453 else if (SUCCEEDED(hr
= wined3d_volume_map(wined3d_volume_from_resource(sub_resource
),
454 &wined3d_map_desc
, NULL
, 0)))
456 mapped_texture
->pData
= wined3d_map_desc
.data
;
457 mapped_texture
->RowPitch
= wined3d_map_desc
.row_pitch
;
458 mapped_texture
->DepthPitch
= wined3d_map_desc
.slice_pitch
;
464 static void STDMETHODCALLTYPE
d3d10_texture3d_Unmap(ID3D10Texture3D
*iface
, UINT sub_resource_idx
)
466 struct d3d10_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
467 struct wined3d_resource
*sub_resource
;
469 TRACE("iface %p, sub_resource_idx %u.\n", iface
, sub_resource_idx
);
471 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, sub_resource_idx
)))
474 wined3d_volume_unmap(wined3d_volume_from_resource(sub_resource
));
477 static void STDMETHODCALLTYPE
d3d10_texture3d_GetDesc(ID3D10Texture3D
*iface
, D3D10_TEXTURE3D_DESC
*desc
)
479 struct d3d10_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
481 TRACE("iface %p, desc %p.\n", iface
, desc
);
483 *desc
= texture
->desc
;
486 static const struct ID3D10Texture3DVtbl d3d10_texture3d_vtbl
=
488 /* IUnknown methods */
489 d3d10_texture3d_QueryInterface
,
490 d3d10_texture3d_AddRef
,
491 d3d10_texture3d_Release
,
492 /* ID3D10DeviceChild methods */
493 d3d10_texture3d_GetDevice
,
494 d3d10_texture3d_GetPrivateData
,
495 d3d10_texture3d_SetPrivateData
,
496 d3d10_texture3d_SetPrivateDataInterface
,
497 /* ID3D10Resource methods */
498 d3d10_texture3d_GetType
,
499 d3d10_texture3d_SetEvictionPriority
,
500 d3d10_texture3d_GetEvictionPriority
,
501 /* ID3D10Texture3D methods */
503 d3d10_texture3d_Unmap
,
504 d3d10_texture3d_GetDesc
,
507 static const struct wined3d_parent_ops d3d10_texture3d_wined3d_parent_ops
=
509 d3d10_texture3d_wined3d_object_released
,
512 HRESULT
d3d10_texture3d_init(struct d3d10_texture3d
*texture
, struct d3d10_device
*device
,
513 const D3D10_TEXTURE3D_DESC
*desc
)
515 struct wined3d_resource_desc wined3d_desc
;
518 texture
->ID3D10Texture3D_iface
.lpVtbl
= &d3d10_texture3d_vtbl
;
519 texture
->refcount
= 1;
520 texture
->desc
= *desc
;
522 wined3d_desc
.resource_type
= WINED3D_RTYPE_VOLUME_TEXTURE
;
523 wined3d_desc
.format
= wined3dformat_from_dxgi_format(desc
->Format
);
524 wined3d_desc
.multisample_type
= WINED3D_MULTISAMPLE_NONE
;
525 wined3d_desc
.multisample_quality
= 0;
526 wined3d_desc
.usage
= wined3d_usage_from_d3d10core(desc
->BindFlags
, desc
->Usage
);
527 wined3d_desc
.pool
= WINED3D_POOL_DEFAULT
;
528 wined3d_desc
.width
= desc
->Width
;
529 wined3d_desc
.height
= desc
->Height
;
530 wined3d_desc
.depth
= desc
->Depth
;
531 wined3d_desc
.size
= 0;
533 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, &wined3d_desc
, desc
->MipLevels
,
534 0, texture
, &d3d10_texture3d_wined3d_parent_ops
, &texture
->wined3d_texture
)))
536 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
539 texture
->desc
.MipLevels
= wined3d_texture_get_level_count(texture
->wined3d_texture
);
541 texture
->device
= &device
->ID3D10Device1_iface
;
542 ID3D10Device1_AddRef(texture
->device
);