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 IDXGISurface_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
);
70 wined3d_texture_incref(This
->wined3d_texture
);
75 static void STDMETHODCALLTYPE
d3d10_texture2d_wined3d_object_released(void *parent
)
77 struct d3d10_texture2d
*This
= parent
;
79 if (This
->dxgi_surface
) IDXGISurface_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
);
91 wined3d_texture_decref(This
->wined3d_texture
);
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
);
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
);
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
);
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
);
151 /* ID3D10Texture2D methods */
153 static HRESULT STDMETHODCALLTYPE
d3d10_texture2d_Map(ID3D10Texture2D
*iface
, UINT sub_resource
,
154 D3D10_MAP map_type
, UINT map_flags
, D3D10_MAPPED_TEXTURE2D
*mapped_texture
)
156 FIXME("iface %p, sub_resource %u, map_type %u, map_flags %#x, mapped_texture %p stub!\n",
157 iface
, sub_resource
, map_type
, map_flags
, mapped_texture
);
162 static void STDMETHODCALLTYPE
d3d10_texture2d_Unmap(ID3D10Texture2D
*iface
, UINT sub_resource
)
164 FIXME("iface %p, sub_resource %u stub!\n", iface
, sub_resource
);
167 static void STDMETHODCALLTYPE
d3d10_texture2d_GetDesc(ID3D10Texture2D
*iface
, D3D10_TEXTURE2D_DESC
*desc
)
169 struct d3d10_texture2d
*This
= impl_from_ID3D10Texture2D(iface
);
171 TRACE("iface %p, desc %p\n", iface
, desc
);
176 static const struct ID3D10Texture2DVtbl d3d10_texture2d_vtbl
=
178 /* IUnknown methods */
179 d3d10_texture2d_QueryInterface
,
180 d3d10_texture2d_AddRef
,
181 d3d10_texture2d_Release
,
182 /* ID3D10DeviceChild methods */
183 d3d10_texture2d_GetDevice
,
184 d3d10_texture2d_GetPrivateData
,
185 d3d10_texture2d_SetPrivateData
,
186 d3d10_texture2d_SetPrivateDataInterface
,
187 /* ID3D10Resource methods */
188 d3d10_texture2d_GetType
,
189 d3d10_texture2d_SetEvictionPriority
,
190 d3d10_texture2d_GetEvictionPriority
,
191 /* ID3D10Texture2D methods */
193 d3d10_texture2d_Unmap
,
194 d3d10_texture2d_GetDesc
,
197 static const struct wined3d_parent_ops d3d10_texture2d_wined3d_parent_ops
=
199 d3d10_texture2d_wined3d_object_released
,
202 HRESULT
d3d10_texture2d_init(struct d3d10_texture2d
*texture
, struct d3d10_device
*device
,
203 const D3D10_TEXTURE2D_DESC
*desc
)
207 texture
->ID3D10Texture2D_iface
.lpVtbl
= &d3d10_texture2d_vtbl
;
208 texture
->refcount
= 1;
209 texture
->desc
= *desc
;
211 if (desc
->MipLevels
== 1 && desc
->ArraySize
== 1)
213 IWineDXGIDevice
*wine_device
;
215 hr
= ID3D10Device_QueryInterface(&device
->ID3D10Device_iface
, &IID_IWineDXGIDevice
,
216 (void **)&wine_device
);
219 ERR("Device should implement IWineDXGIDevice\n");
223 hr
= IWineDXGIDevice_create_surface(wine_device
, NULL
, 0, NULL
,
224 (IUnknown
*)&texture
->ID3D10Texture2D_iface
, (void **)&texture
->dxgi_surface
);
225 IWineDXGIDevice_Release(wine_device
);
228 ERR("Failed to create DXGI surface, returning %#x\n", hr
);
233 FIXME("Implement DXGI<->wined3d usage conversion\n");
234 if (desc
->ArraySize
!= 1)
235 FIXME("Array textures not implemented.\n");
236 if (desc
->SampleDesc
.Count
> 1)
237 FIXME("Multisampled textures not implemented.\n");
239 hr
= wined3d_texture_create_2d(device
->wined3d_device
, desc
->Width
, desc
->Height
,
240 desc
->MipLevels
, desc
->Usage
, wined3dformat_from_dxgi_format(desc
->Format
), WINED3D_POOL_DEFAULT
,
241 texture
, &d3d10_texture2d_wined3d_parent_ops
, &texture
->wined3d_texture
);
244 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);
245 if (texture
->dxgi_surface
)
246 IDXGISurface_Release(texture
->dxgi_surface
);
253 static inline struct d3d10_texture3d
*impl_from_ID3D10Texture3D(ID3D10Texture3D
*iface
)
255 return CONTAINING_RECORD(iface
, struct d3d10_texture3d
, ID3D10Texture3D_iface
);
258 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_QueryInterface(ID3D10Texture3D
*iface
, REFIID riid
, void **object
)
260 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
262 if (IsEqualGUID(riid
, &IID_ID3D10Texture3D
)
263 || IsEqualGUID(riid
, &IID_ID3D10Resource
)
264 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
)
265 || IsEqualGUID(riid
, &IID_IUnknown
))
267 IUnknown_AddRef(iface
);
272 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
275 return E_NOINTERFACE
;
278 static ULONG STDMETHODCALLTYPE
d3d10_texture3d_AddRef(ID3D10Texture3D
*iface
)
280 struct d3d10_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
281 ULONG refcount
= InterlockedIncrement(&texture
->refcount
);
283 TRACE("%p increasing refcount to %u.\n", texture
, refcount
);
286 wined3d_texture_incref(texture
->wined3d_texture
);
291 static void STDMETHODCALLTYPE
d3d10_texture3d_wined3d_object_released(void *parent
)
293 HeapFree(GetProcessHeap(), 0, parent
);
296 static ULONG STDMETHODCALLTYPE
d3d10_texture3d_Release(ID3D10Texture3D
*iface
)
298 struct d3d10_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
299 ULONG refcount
= InterlockedDecrement(&texture
->refcount
);
301 TRACE("%p decreasing refcount to %u.\n", texture
, refcount
);
304 wined3d_texture_decref(texture
->wined3d_texture
);
309 static void STDMETHODCALLTYPE
d3d10_texture3d_GetDevice(ID3D10Texture3D
*iface
, ID3D10Device
**device
)
311 FIXME("iface %p, device %p stub!\n", iface
, device
);
314 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_GetPrivateData(ID3D10Texture3D
*iface
,
315 REFGUID guid
, UINT
*data_size
, void *data
)
317 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
318 iface
, debugstr_guid(guid
), data_size
, data
);
323 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_SetPrivateData(ID3D10Texture3D
*iface
,
324 REFGUID guid
, UINT data_size
, const void *data
)
326 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
327 iface
, debugstr_guid(guid
), data_size
, data
);
332 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_SetPrivateDataInterface(ID3D10Texture3D
*iface
,
333 REFGUID guid
, const IUnknown
*data
)
335 FIXME("iface %p, guid %s, data %p stub!\n", iface
, debugstr_guid(guid
), data
);
340 static void STDMETHODCALLTYPE
d3d10_texture3d_GetType(ID3D10Texture3D
*iface
,
341 D3D10_RESOURCE_DIMENSION
*resource_dimension
)
343 TRACE("iface %p, resource_dimension %p.\n", iface
, resource_dimension
);
345 *resource_dimension
= D3D10_RESOURCE_DIMENSION_TEXTURE3D
;
348 static void STDMETHODCALLTYPE
d3d10_texture3d_SetEvictionPriority(ID3D10Texture3D
*iface
, UINT eviction_priority
)
350 FIXME("iface %p, eviction_priority %u stub!\n", iface
, eviction_priority
);
353 static UINT STDMETHODCALLTYPE
d3d10_texture3d_GetEvictionPriority(ID3D10Texture3D
*iface
)
355 FIXME("iface %p stub!\n", iface
);
360 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_Map(ID3D10Texture3D
*iface
, UINT sub_resource_idx
,
361 D3D10_MAP map_type
, UINT map_flags
, D3D10_MAPPED_TEXTURE3D
*mapped_texture
)
363 struct d3d10_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
364 struct wined3d_map_desc wined3d_map_desc
;
365 struct wined3d_resource
*sub_resource
;
368 TRACE("iface %p, sub_resource_idx %u, map_type %u, map_flags %#x, mapped_texture %p.\n",
369 iface
, sub_resource_idx
, map_type
, map_flags
, mapped_texture
);
371 if (map_type
!= D3D10_MAP_READ_WRITE
)
372 FIXME("Ignoring map_type %#x.\n", map_type
);
374 FIXME("Ignoring map_flags %#x.\n", map_flags
);
376 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, sub_resource_idx
)))
378 else if (SUCCEEDED(hr
= wined3d_volume_map(wined3d_volume_from_resource(sub_resource
),
379 &wined3d_map_desc
, NULL
, 0)))
381 mapped_texture
->pData
= wined3d_map_desc
.data
;
382 mapped_texture
->RowPitch
= wined3d_map_desc
.row_pitch
;
383 mapped_texture
->DepthPitch
= wined3d_map_desc
.slice_pitch
;
389 static void STDMETHODCALLTYPE
d3d10_texture3d_Unmap(ID3D10Texture3D
*iface
, UINT sub_resource_idx
)
391 struct d3d10_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
392 struct wined3d_resource
*sub_resource
;
394 TRACE("iface %p, sub_resource_idx %u.\n", iface
, sub_resource_idx
);
396 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, sub_resource_idx
)))
399 wined3d_volume_unmap(wined3d_volume_from_resource(sub_resource
));
402 static void STDMETHODCALLTYPE
d3d10_texture3d_GetDesc(ID3D10Texture3D
*iface
, D3D10_TEXTURE3D_DESC
*desc
)
404 struct d3d10_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
406 TRACE("iface %p, desc %p.\n", iface
, desc
);
408 *desc
= texture
->desc
;
411 static const struct ID3D10Texture3DVtbl d3d10_texture3d_vtbl
=
413 /* IUnknown methods */
414 d3d10_texture3d_QueryInterface
,
415 d3d10_texture3d_AddRef
,
416 d3d10_texture3d_Release
,
417 /* ID3D10DeviceChild methods */
418 d3d10_texture3d_GetDevice
,
419 d3d10_texture3d_GetPrivateData
,
420 d3d10_texture3d_SetPrivateData
,
421 d3d10_texture3d_SetPrivateDataInterface
,
422 /* ID3D10Resource methods */
423 d3d10_texture3d_GetType
,
424 d3d10_texture3d_SetEvictionPriority
,
425 d3d10_texture3d_GetEvictionPriority
,
426 /* ID3D10Texture3D methods */
428 d3d10_texture3d_Unmap
,
429 d3d10_texture3d_GetDesc
,
432 static const struct wined3d_parent_ops d3d10_texture3d_wined3d_parent_ops
=
434 d3d10_texture3d_wined3d_object_released
,
437 HRESULT
d3d10_texture3d_init(struct d3d10_texture3d
*texture
, struct d3d10_device
*device
,
438 const D3D10_TEXTURE3D_DESC
*desc
)
442 texture
->ID3D10Texture3D_iface
.lpVtbl
= &d3d10_texture3d_vtbl
;
443 texture
->refcount
= 1;
444 texture
->desc
= *desc
;
446 FIXME("Implement DXGI<->wined3d usage conversion.\n");
448 hr
= wined3d_texture_create_3d(device
->wined3d_device
, desc
->Width
, desc
->Height
, desc
->Depth
,
449 desc
->MipLevels
, desc
->Usage
, wined3dformat_from_dxgi_format(desc
->Format
), WINED3D_POOL_DEFAULT
,
450 texture
, &d3d10_texture3d_wined3d_parent_ops
, &texture
->wined3d_texture
);
453 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);