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((ID3D10Device
*)device
, &IID_IWineDXGIDevice
, (void **)&wine_device
);
223 ERR("Device should implement IWineDXGIDevice\n");
227 hr
= IWineDXGIDevice_create_surface(wine_device
, NULL
, 0, NULL
,
228 (IUnknown
*)&texture
->ID3D10Texture2D_iface
, (void **)&texture
->dxgi_surface
);
229 IWineDXGIDevice_Release(wine_device
);
232 ERR("Failed to create DXGI surface, returning %#x\n", hr
);
236 FIXME("Implement DXGI<->wined3d usage conversion\n");
238 hr
= wined3d_surface_create(device
->wined3d_device
, desc
->Width
, desc
->Height
,
239 wined3dformat_from_dxgi_format(desc
->Format
), FALSE
, FALSE
, 0, desc
->Usage
, WINED3DPOOL_DEFAULT
,
240 desc
->SampleDesc
.Count
> 1 ? desc
->SampleDesc
.Count
: WINED3DMULTISAMPLE_NONE
,
241 desc
->SampleDesc
.Quality
, SURFACE_OPENGL
, texture
, &d3d10_texture2d_wined3d_parent_ops
,
242 &texture
->wined3d_surface
);
245 ERR("CreateSurface failed, returning %#x\n", hr
);
246 IDXGISurface_Release(texture
->dxgi_surface
);
254 static inline struct d3d10_texture3d
*impl_from_ID3D10Texture3D(ID3D10Texture3D
*iface
)
256 return CONTAINING_RECORD(iface
, struct d3d10_texture3d
, ID3D10Texture3D_iface
);
259 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_QueryInterface(ID3D10Texture3D
*iface
, REFIID riid
, void **object
)
261 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
263 if (IsEqualGUID(riid
, &IID_ID3D10Texture3D
)
264 || IsEqualGUID(riid
, &IID_ID3D10Resource
)
265 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
)
266 || IsEqualGUID(riid
, &IID_IUnknown
))
268 IUnknown_AddRef(iface
);
273 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
276 return E_NOINTERFACE
;
279 static ULONG STDMETHODCALLTYPE
d3d10_texture3d_AddRef(ID3D10Texture3D
*iface
)
281 struct d3d10_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
282 ULONG refcount
= InterlockedIncrement(&texture
->refcount
);
284 TRACE("%p increasing refcount to %u.\n", texture
, refcount
);
287 wined3d_texture_incref(texture
->wined3d_texture
);
292 static void STDMETHODCALLTYPE
d3d10_texture3d_wined3d_object_released(void *parent
)
294 HeapFree(GetProcessHeap(), 0, parent
);
297 static ULONG STDMETHODCALLTYPE
d3d10_texture3d_Release(ID3D10Texture3D
*iface
)
299 struct d3d10_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
300 ULONG refcount
= InterlockedDecrement(&texture
->refcount
);
302 TRACE("%p decreasing refcount to %u.\n", texture
, refcount
);
305 wined3d_texture_decref(texture
->wined3d_texture
);
310 static void STDMETHODCALLTYPE
d3d10_texture3d_GetDevice(ID3D10Texture3D
*iface
, ID3D10Device
**device
)
312 FIXME("iface %p, device %p stub!\n", iface
, device
);
315 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_GetPrivateData(ID3D10Texture3D
*iface
,
316 REFGUID guid
, UINT
*data_size
, void *data
)
318 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
319 iface
, debugstr_guid(guid
), data_size
, data
);
324 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_SetPrivateData(ID3D10Texture3D
*iface
,
325 REFGUID guid
, UINT data_size
, const void *data
)
327 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
328 iface
, debugstr_guid(guid
), data_size
, data
);
333 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_SetPrivateDataInterface(ID3D10Texture3D
*iface
,
334 REFGUID guid
, const IUnknown
*data
)
336 FIXME("iface %p, guid %s, data %p stub!\n", iface
, debugstr_guid(guid
), data
);
341 static void STDMETHODCALLTYPE
d3d10_texture3d_GetType(ID3D10Texture3D
*iface
,
342 D3D10_RESOURCE_DIMENSION
*resource_dimension
)
344 TRACE("iface %p, resource_dimension %p.\n", iface
, resource_dimension
);
346 *resource_dimension
= D3D10_RESOURCE_DIMENSION_TEXTURE3D
;
349 static void STDMETHODCALLTYPE
d3d10_texture3d_SetEvictionPriority(ID3D10Texture3D
*iface
, UINT eviction_priority
)
351 FIXME("iface %p, eviction_priority %u stub!\n", iface
, eviction_priority
);
354 static UINT STDMETHODCALLTYPE
d3d10_texture3d_GetEvictionPriority(ID3D10Texture3D
*iface
)
356 FIXME("iface %p stub!\n", iface
);
361 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_Map(ID3D10Texture3D
*iface
, UINT sub_resource_idx
,
362 D3D10_MAP map_type
, UINT map_flags
, D3D10_MAPPED_TEXTURE3D
*mapped_texture
)
364 struct d3d10_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
365 struct wined3d_resource
*sub_resource
;
366 WINED3DLOCKED_BOX wined3d_map_desc
;
369 TRACE("iface %p, sub_resource_idx %u, map_type %u, map_flags %#x, mapped_texture %p.\n",
370 iface
, sub_resource_idx
, map_type
, map_flags
, mapped_texture
);
372 if (map_type
!= D3D10_MAP_READ_WRITE
)
373 FIXME("Ignoring map_type %#x.\n", map_type
);
375 FIXME("Ignoring map_flags %#x.\n", map_flags
);
377 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, sub_resource_idx
)))
379 else if (SUCCEEDED(hr
= wined3d_volume_map(wined3d_volume_from_resource(sub_resource
),
380 &wined3d_map_desc
, NULL
, 0)))
382 mapped_texture
->pData
= wined3d_map_desc
.pBits
;
383 mapped_texture
->RowPitch
= wined3d_map_desc
.RowPitch
;
384 mapped_texture
->DepthPitch
= wined3d_map_desc
.SlicePitch
;
390 static void STDMETHODCALLTYPE
d3d10_texture3d_Unmap(ID3D10Texture3D
*iface
, UINT sub_resource_idx
)
392 struct d3d10_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
393 struct wined3d_resource
*sub_resource
;
395 TRACE("iface %p, sub_resource_idx %u.\n", iface
, sub_resource_idx
);
397 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, sub_resource_idx
)))
400 wined3d_volume_unmap(wined3d_volume_from_resource(sub_resource
));
403 static void STDMETHODCALLTYPE
d3d10_texture3d_GetDesc(ID3D10Texture3D
*iface
, D3D10_TEXTURE3D_DESC
*desc
)
405 struct d3d10_texture3d
*texture
= impl_from_ID3D10Texture3D(iface
);
407 TRACE("iface %p, desc %p.\n", iface
, desc
);
409 *desc
= texture
->desc
;
412 static const struct ID3D10Texture3DVtbl d3d10_texture3d_vtbl
=
414 /* IUnknown methods */
415 d3d10_texture3d_QueryInterface
,
416 d3d10_texture3d_AddRef
,
417 d3d10_texture3d_Release
,
418 /* ID3D10DeviceChild methods */
419 d3d10_texture3d_GetDevice
,
420 d3d10_texture3d_GetPrivateData
,
421 d3d10_texture3d_SetPrivateData
,
422 d3d10_texture3d_SetPrivateDataInterface
,
423 /* ID3D10Resource methods */
424 d3d10_texture3d_GetType
,
425 d3d10_texture3d_SetEvictionPriority
,
426 d3d10_texture3d_GetEvictionPriority
,
427 /* ID3D10Texture3D methods */
429 d3d10_texture3d_Unmap
,
430 d3d10_texture3d_GetDesc
,
433 static const struct wined3d_parent_ops d3d10_texture3d_wined3d_parent_ops
=
435 d3d10_texture3d_wined3d_object_released
,
438 HRESULT
d3d10_texture3d_init(struct d3d10_texture3d
*texture
, struct d3d10_device
*device
,
439 const D3D10_TEXTURE3D_DESC
*desc
)
443 texture
->ID3D10Texture3D_iface
.lpVtbl
= &d3d10_texture3d_vtbl
;
444 texture
->refcount
= 1;
445 texture
->desc
= *desc
;
447 FIXME("Implement DXGI<->wined3d usage conversion.\n");
449 hr
= wined3d_texture_create_3d(device
->wined3d_device
, desc
->Width
, desc
->Height
, desc
->Depth
,
450 desc
->MipLevels
, desc
->Usage
, wined3dformat_from_dxgi_format(desc
->Format
), WINED3DPOOL_DEFAULT
,
451 texture
, &d3d10_texture3d_wined3d_parent_ops
, &texture
->wined3d_texture
);
454 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);