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
);
69 if (refcount
== 1 && This
->wined3d_surface
)
70 wined3d_surface_incref(This
->wined3d_surface
);
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
);
92 if (This
->wined3d_surface
)
93 wined3d_surface_decref(This
->wined3d_surface
);
95 d3d10_texture2d_wined3d_object_released(This
);
101 /* ID3D10DeviceChild methods */
103 static void STDMETHODCALLTYPE
d3d10_texture2d_GetDevice(ID3D10Texture2D
*iface
, ID3D10Device
**device
)
105 FIXME("iface %p, device %p stub!\n", iface
, device
);
108 static HRESULT STDMETHODCALLTYPE
d3d10_texture2d_GetPrivateData(ID3D10Texture2D
*iface
,
109 REFGUID guid
, UINT
*data_size
, void *data
)
111 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
112 iface
, debugstr_guid(guid
), data_size
, data
);
117 static HRESULT STDMETHODCALLTYPE
d3d10_texture2d_SetPrivateData(ID3D10Texture2D
*iface
,
118 REFGUID guid
, UINT data_size
, const void *data
)
120 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
121 iface
, debugstr_guid(guid
), data_size
, data
);
126 static HRESULT STDMETHODCALLTYPE
d3d10_texture2d_SetPrivateDataInterface(ID3D10Texture2D
*iface
,
127 REFGUID guid
, const IUnknown
*data
)
129 FIXME("iface %p, guid %s, data %p stub!\n", iface
, debugstr_guid(guid
), data
);
134 /* ID3D10Resource methods */
136 static void STDMETHODCALLTYPE
d3d10_texture2d_GetType(ID3D10Texture2D
*iface
,
137 D3D10_RESOURCE_DIMENSION
*resource_dimension
)
139 TRACE("iface %p, resource_dimension %p\n", iface
, resource_dimension
);
141 *resource_dimension
= D3D10_RESOURCE_DIMENSION_TEXTURE2D
;
144 static void STDMETHODCALLTYPE
d3d10_texture2d_SetEvictionPriority(ID3D10Texture2D
*iface
, UINT eviction_priority
)
146 FIXME("iface %p, eviction_priority %u stub!\n", iface
, eviction_priority
);
149 static UINT STDMETHODCALLTYPE
d3d10_texture2d_GetEvictionPriority(ID3D10Texture2D
*iface
)
151 FIXME("iface %p stub!\n", iface
);
156 /* ID3D10Texture2D methods */
158 static HRESULT STDMETHODCALLTYPE
d3d10_texture2d_Map(ID3D10Texture2D
*iface
, UINT sub_resource
,
159 D3D10_MAP map_type
, UINT map_flags
, D3D10_MAPPED_TEXTURE2D
*mapped_texture
)
161 FIXME("iface %p, sub_resource %u, map_type %u, map_flags %#x, mapped_texture %p stub!\n",
162 iface
, sub_resource
, map_type
, map_flags
, mapped_texture
);
167 static void STDMETHODCALLTYPE
d3d10_texture2d_Unmap(ID3D10Texture2D
*iface
, UINT sub_resource
)
169 FIXME("iface %p, sub_resource %u stub!\n", iface
, sub_resource
);
172 static void STDMETHODCALLTYPE
d3d10_texture2d_GetDesc(ID3D10Texture2D
*iface
, D3D10_TEXTURE2D_DESC
*desc
)
174 struct d3d10_texture2d
*This
= impl_from_ID3D10Texture2D(iface
);
176 TRACE("iface %p, desc %p\n", iface
, desc
);
181 static const struct ID3D10Texture2DVtbl d3d10_texture2d_vtbl
=
183 /* IUnknown methods */
184 d3d10_texture2d_QueryInterface
,
185 d3d10_texture2d_AddRef
,
186 d3d10_texture2d_Release
,
187 /* ID3D10DeviceChild methods */
188 d3d10_texture2d_GetDevice
,
189 d3d10_texture2d_GetPrivateData
,
190 d3d10_texture2d_SetPrivateData
,
191 d3d10_texture2d_SetPrivateDataInterface
,
192 /* ID3D10Resource methods */
193 d3d10_texture2d_GetType
,
194 d3d10_texture2d_SetEvictionPriority
,
195 d3d10_texture2d_GetEvictionPriority
,
196 /* ID3D10Texture2D methods */
198 d3d10_texture2d_Unmap
,
199 d3d10_texture2d_GetDesc
,
202 static const struct wined3d_parent_ops d3d10_texture2d_wined3d_parent_ops
=
204 d3d10_texture2d_wined3d_object_released
,
207 HRESULT
d3d10_texture2d_init(struct d3d10_texture2d
*texture
, struct d3d10_device
*device
,
208 const D3D10_TEXTURE2D_DESC
*desc
)
212 texture
->ID3D10Texture2D_iface
.lpVtbl
= &d3d10_texture2d_vtbl
;
213 texture
->refcount
= 1;
214 texture
->desc
= *desc
;
216 if (desc
->MipLevels
== 1 && desc
->ArraySize
== 1)
218 IWineDXGIDevice
*wine_device
;
220 hr
= ID3D10Device_QueryInterface(&device
->ID3D10Device_iface
, &IID_IWineDXGIDevice
,
221 (void **)&wine_device
);
224 ERR("Device should implement IWineDXGIDevice\n");
228 hr
= IWineDXGIDevice_create_surface(wine_device
, NULL
, 0, NULL
,
229 (IUnknown
*)&texture
->ID3D10Texture2D_iface
, (void **)&texture
->dxgi_surface
);
230 IWineDXGIDevice_Release(wine_device
);
233 ERR("Failed to create DXGI surface, returning %#x\n", hr
);
237 FIXME("Implement DXGI<->wined3d usage conversion\n");
239 hr
= wined3d_surface_create(device
->wined3d_device
, desc
->Width
, desc
->Height
,
240 wined3dformat_from_dxgi_format(desc
->Format
), 0, desc
->Usage
, WINED3DPOOL_DEFAULT
,
241 desc
->SampleDesc
.Count
> 1 ? desc
->SampleDesc
.Count
: WINED3D_MULTISAMPLE_NONE
,
242 desc
->SampleDesc
.Quality
, SURFACE_OPENGL
, 0, texture
, &d3d10_texture2d_wined3d_parent_ops
,
243 &texture
->wined3d_surface
);
246 ERR("CreateSurface failed, returning %#x\n", hr
);
247 IDXGISurface_Release(texture
->dxgi_surface
);
255 static inline struct d3d10_texture3d
*impl_from_ID3D10Texture3D(ID3D10Texture3D
*iface
)
257 return CONTAINING_RECORD(iface
, struct d3d10_texture3d
, ID3D10Texture3D_iface
);
260 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_QueryInterface(ID3D10Texture3D
*iface
, REFIID riid
, void **object
)
262 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
264 if (IsEqualGUID(riid
, &IID_ID3D10Texture3D
)
265 || IsEqualGUID(riid
, &IID_ID3D10Resource
)
266 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
)
267 || IsEqualGUID(riid
, &IID_IUnknown
))
269 IUnknown_AddRef(iface
);
274 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
277 return E_NOINTERFACE
;
280 static ULONG STDMETHODCALLTYPE
d3d10_texture3d_AddRef(ID3D10Texture3D
*iface
)
282 struct d3d10_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
283 ULONG refcount
= InterlockedIncrement(&texture
->refcount
);
285 TRACE("%p increasing refcount to %u.\n", texture
, refcount
);
288 wined3d_texture_incref(texture
->wined3d_texture
);
293 static void STDMETHODCALLTYPE
d3d10_texture3d_wined3d_object_released(void *parent
)
295 HeapFree(GetProcessHeap(), 0, parent
);
298 static ULONG STDMETHODCALLTYPE
d3d10_texture3d_Release(ID3D10Texture3D
*iface
)
300 struct d3d10_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
301 ULONG refcount
= InterlockedDecrement(&texture
->refcount
);
303 TRACE("%p decreasing refcount to %u.\n", texture
, refcount
);
306 wined3d_texture_decref(texture
->wined3d_texture
);
311 static void STDMETHODCALLTYPE
d3d10_texture3d_GetDevice(ID3D10Texture3D
*iface
, ID3D10Device
**device
)
313 FIXME("iface %p, device %p stub!\n", iface
, device
);
316 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_GetPrivateData(ID3D10Texture3D
*iface
,
317 REFGUID guid
, UINT
*data_size
, void *data
)
319 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
320 iface
, debugstr_guid(guid
), data_size
, data
);
325 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_SetPrivateData(ID3D10Texture3D
*iface
,
326 REFGUID guid
, UINT data_size
, const void *data
)
328 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
329 iface
, debugstr_guid(guid
), data_size
, data
);
334 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_SetPrivateDataInterface(ID3D10Texture3D
*iface
,
335 REFGUID guid
, const IUnknown
*data
)
337 FIXME("iface %p, guid %s, data %p stub!\n", iface
, debugstr_guid(guid
), data
);
342 static void STDMETHODCALLTYPE
d3d10_texture3d_GetType(ID3D10Texture3D
*iface
,
343 D3D10_RESOURCE_DIMENSION
*resource_dimension
)
345 TRACE("iface %p, resource_dimension %p.\n", iface
, resource_dimension
);
347 *resource_dimension
= D3D10_RESOURCE_DIMENSION_TEXTURE3D
;
350 static void STDMETHODCALLTYPE
d3d10_texture3d_SetEvictionPriority(ID3D10Texture3D
*iface
, UINT eviction_priority
)
352 FIXME("iface %p, eviction_priority %u stub!\n", iface
, eviction_priority
);
355 static UINT STDMETHODCALLTYPE
d3d10_texture3d_GetEvictionPriority(ID3D10Texture3D
*iface
)
357 FIXME("iface %p stub!\n", iface
);
362 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_Map(ID3D10Texture3D
*iface
, UINT sub_resource_idx
,
363 D3D10_MAP map_type
, UINT map_flags
, D3D10_MAPPED_TEXTURE3D
*mapped_texture
)
365 struct d3d10_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
366 struct wined3d_mapped_box wined3d_map_desc
;
367 struct wined3d_resource
*sub_resource
;
370 TRACE("iface %p, sub_resource_idx %u, map_type %u, map_flags %#x, mapped_texture %p.\n",
371 iface
, sub_resource_idx
, map_type
, map_flags
, mapped_texture
);
373 if (map_type
!= D3D10_MAP_READ_WRITE
)
374 FIXME("Ignoring map_type %#x.\n", map_type
);
376 FIXME("Ignoring map_flags %#x.\n", map_flags
);
378 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, sub_resource_idx
)))
380 else if (SUCCEEDED(hr
= wined3d_volume_map(wined3d_volume_from_resource(sub_resource
),
381 &wined3d_map_desc
, NULL
, 0)))
383 mapped_texture
->pData
= wined3d_map_desc
.data
;
384 mapped_texture
->RowPitch
= wined3d_map_desc
.row_pitch
;
385 mapped_texture
->DepthPitch
= wined3d_map_desc
.slice_pitch
;
391 static void STDMETHODCALLTYPE
d3d10_texture3d_Unmap(ID3D10Texture3D
*iface
, UINT sub_resource_idx
)
393 struct d3d10_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
394 struct wined3d_resource
*sub_resource
;
396 TRACE("iface %p, sub_resource_idx %u.\n", iface
, sub_resource_idx
);
398 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, sub_resource_idx
)))
401 wined3d_volume_unmap(wined3d_volume_from_resource(sub_resource
));
404 static void STDMETHODCALLTYPE
d3d10_texture3d_GetDesc(ID3D10Texture3D
*iface
, D3D10_TEXTURE3D_DESC
*desc
)
406 struct d3d10_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
408 TRACE("iface %p, desc %p.\n", iface
, desc
);
410 *desc
= texture
->desc
;
413 static const struct ID3D10Texture3DVtbl d3d10_texture3d_vtbl
=
415 /* IUnknown methods */
416 d3d10_texture3d_QueryInterface
,
417 d3d10_texture3d_AddRef
,
418 d3d10_texture3d_Release
,
419 /* ID3D10DeviceChild methods */
420 d3d10_texture3d_GetDevice
,
421 d3d10_texture3d_GetPrivateData
,
422 d3d10_texture3d_SetPrivateData
,
423 d3d10_texture3d_SetPrivateDataInterface
,
424 /* ID3D10Resource methods */
425 d3d10_texture3d_GetType
,
426 d3d10_texture3d_SetEvictionPriority
,
427 d3d10_texture3d_GetEvictionPriority
,
428 /* ID3D10Texture3D methods */
430 d3d10_texture3d_Unmap
,
431 d3d10_texture3d_GetDesc
,
434 static const struct wined3d_parent_ops d3d10_texture3d_wined3d_parent_ops
=
436 d3d10_texture3d_wined3d_object_released
,
439 HRESULT
d3d10_texture3d_init(struct d3d10_texture3d
*texture
, struct d3d10_device
*device
,
440 const D3D10_TEXTURE3D_DESC
*desc
)
444 texture
->ID3D10Texture3D_iface
.lpVtbl
= &d3d10_texture3d_vtbl
;
445 texture
->refcount
= 1;
446 texture
->desc
= *desc
;
448 FIXME("Implement DXGI<->wined3d usage conversion.\n");
450 hr
= wined3d_texture_create_3d(device
->wined3d_device
, desc
->Width
, desc
->Height
, desc
->Depth
,
451 desc
->MipLevels
, desc
->Usage
, wined3dformat_from_dxgi_format(desc
->Format
), WINED3DPOOL_DEFAULT
,
452 texture
, &d3d10_texture3d_wined3d_parent_ops
, &texture
->wined3d_texture
);
455 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);