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 /* IUnknown methods */
29 static HRESULT STDMETHODCALLTYPE
d3d10_texture2d_QueryInterface(ID3D10Texture2D
*iface
, REFIID riid
, void **object
)
31 struct d3d10_texture2d
*This
= (struct d3d10_texture2d
*)iface
;
33 TRACE("iface %p, riid %s, object %p\n", iface
, debugstr_guid(riid
), object
);
35 if (IsEqualGUID(riid
, &IID_ID3D10Texture2D
)
36 || IsEqualGUID(riid
, &IID_ID3D10Resource
)
37 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
)
38 || IsEqualGUID(riid
, &IID_IUnknown
))
40 IUnknown_AddRef(iface
);
45 if (This
->dxgi_surface
)
47 TRACE("Forwarding to dxgi surface\n");
48 return IDXGISurface_QueryInterface(This
->dxgi_surface
, riid
, object
);
51 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
57 static ULONG STDMETHODCALLTYPE
d3d10_texture2d_AddRef(ID3D10Texture2D
*iface
)
59 struct d3d10_texture2d
*This
= (struct d3d10_texture2d
*)iface
;
60 ULONG refcount
= InterlockedIncrement(&This
->refcount
);
62 TRACE("%p increasing refcount to %u\n", This
, refcount
);
64 if (refcount
== 1 && This
->wined3d_surface
)
65 wined3d_surface_incref(This
->wined3d_surface
);
70 static void STDMETHODCALLTYPE
d3d10_texture2d_wined3d_object_released(void *parent
)
72 struct d3d10_texture2d
*This
= parent
;
74 if (This
->dxgi_surface
) IDXGISurface_Release(This
->dxgi_surface
);
75 HeapFree(GetProcessHeap(), 0, This
);
78 static ULONG STDMETHODCALLTYPE
d3d10_texture2d_Release(ID3D10Texture2D
*iface
)
80 struct d3d10_texture2d
*This
= (struct d3d10_texture2d
*)iface
;
81 ULONG refcount
= InterlockedDecrement(&This
->refcount
);
83 TRACE("%p decreasing refcount to %u\n", This
, refcount
);
87 if (This
->wined3d_surface
)
88 wined3d_surface_decref(This
->wined3d_surface
);
90 d3d10_texture2d_wined3d_object_released(This
);
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
= (struct d3d10_texture2d
*)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
->vtbl
= &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((ID3D10Device
*)device
, &IID_IWineDXGIDevice
, (void **)&wine_device
);
218 ERR("Device should implement IWineDXGIDevice\n");
222 hr
= IWineDXGIDevice_create_surface(wine_device
, NULL
, 0, NULL
,
223 (IUnknown
*)texture
, (void **)&texture
->dxgi_surface
);
224 IWineDXGIDevice_Release(wine_device
);
227 ERR("Failed to create DXGI surface, returning %#x\n", hr
);
231 FIXME("Implement DXGI<->wined3d usage conversion\n");
233 hr
= wined3d_surface_create(device
->wined3d_device
, desc
->Width
, desc
->Height
,
234 wined3dformat_from_dxgi_format(desc
->Format
), FALSE
, FALSE
, 0, desc
->Usage
, WINED3DPOOL_DEFAULT
,
235 desc
->SampleDesc
.Count
> 1 ? desc
->SampleDesc
.Count
: WINED3DMULTISAMPLE_NONE
,
236 desc
->SampleDesc
.Quality
, SURFACE_OPENGL
, texture
, &d3d10_texture2d_wined3d_parent_ops
,
237 &texture
->wined3d_surface
);
240 ERR("CreateSurface failed, returning %#x\n", hr
);
241 IDXGISurface_Release(texture
->dxgi_surface
);
249 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_QueryInterface(ID3D10Texture3D
*iface
, REFIID riid
, void **object
)
251 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
253 if (IsEqualGUID(riid
, &IID_ID3D10Texture3D
)
254 || IsEqualGUID(riid
, &IID_ID3D10Resource
)
255 || IsEqualGUID(riid
, &IID_ID3D10DeviceChild
)
256 || IsEqualGUID(riid
, &IID_IUnknown
))
258 IUnknown_AddRef(iface
);
263 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
266 return E_NOINTERFACE
;
269 static ULONG STDMETHODCALLTYPE
d3d10_texture3d_AddRef(ID3D10Texture3D
*iface
)
271 struct d3d10_texture3d
*texture
= (struct d3d10_texture3d
*)iface
;
272 ULONG refcount
= InterlockedIncrement(&texture
->refcount
);
274 TRACE("%p increasing refcount to %u.\n", texture
, refcount
);
277 wined3d_texture_incref(texture
->wined3d_texture
);
282 static void STDMETHODCALLTYPE
d3d10_texture3d_wined3d_object_released(void *parent
)
284 HeapFree(GetProcessHeap(), 0, parent
);
287 static ULONG STDMETHODCALLTYPE
d3d10_texture3d_Release(ID3D10Texture3D
*iface
)
289 struct d3d10_texture3d
*texture
= (struct d3d10_texture3d
*)iface
;
290 ULONG refcount
= InterlockedDecrement(&texture
->refcount
);
292 TRACE("%p decreasing refcount to %u.\n", texture
, refcount
);
295 wined3d_texture_decref(texture
->wined3d_texture
);
300 static void STDMETHODCALLTYPE
d3d10_texture3d_GetDevice(ID3D10Texture3D
*iface
, ID3D10Device
**device
)
302 FIXME("iface %p, device %p stub!\n", iface
, device
);
305 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_GetPrivateData(ID3D10Texture3D
*iface
,
306 REFGUID guid
, UINT
*data_size
, void *data
)
308 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
309 iface
, debugstr_guid(guid
), data_size
, data
);
314 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_SetPrivateData(ID3D10Texture3D
*iface
,
315 REFGUID guid
, UINT data_size
, const void *data
)
317 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
318 iface
, debugstr_guid(guid
), data_size
, data
);
323 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_SetPrivateDataInterface(ID3D10Texture3D
*iface
,
324 REFGUID guid
, const IUnknown
*data
)
326 FIXME("iface %p, guid %s, data %p stub!\n", iface
, debugstr_guid(guid
), data
);
331 static void STDMETHODCALLTYPE
d3d10_texture3d_GetType(ID3D10Texture3D
*iface
,
332 D3D10_RESOURCE_DIMENSION
*resource_dimension
)
334 TRACE("iface %p, resource_dimension %p.\n", iface
, resource_dimension
);
336 *resource_dimension
= D3D10_RESOURCE_DIMENSION_TEXTURE3D
;
339 static void STDMETHODCALLTYPE
d3d10_texture3d_SetEvictionPriority(ID3D10Texture3D
*iface
, UINT eviction_priority
)
341 FIXME("iface %p, eviction_priority %u stub!\n", iface
, eviction_priority
);
344 static UINT STDMETHODCALLTYPE
d3d10_texture3d_GetEvictionPriority(ID3D10Texture3D
*iface
)
346 FIXME("iface %p stub!\n", iface
);
351 static HRESULT STDMETHODCALLTYPE
d3d10_texture3d_Map(ID3D10Texture3D
*iface
, UINT sub_resource_idx
,
352 D3D10_MAP map_type
, UINT map_flags
, D3D10_MAPPED_TEXTURE3D
*mapped_texture
)
354 struct d3d10_texture3d
*texture
= (struct d3d10_texture3d
*)iface
;
355 struct wined3d_resource
*sub_resource
;
356 WINED3DLOCKED_BOX wined3d_map_desc
;
359 TRACE("iface %p, sub_resource_idx %u, map_type %u, map_flags %#x, mapped_texture %p.\n",
360 iface
, sub_resource_idx
, map_type
, map_flags
, mapped_texture
);
362 if (map_type
!= D3D10_MAP_READ_WRITE
)
363 FIXME("Ignoring map_type %#x.\n", map_type
);
365 FIXME("Ignoring map_flags %#x.\n", map_flags
);
367 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, sub_resource_idx
)))
369 else if (SUCCEEDED(hr
= wined3d_volume_map(wined3d_volume_from_resource(sub_resource
),
370 &wined3d_map_desc
, NULL
, 0)))
372 mapped_texture
->pData
= wined3d_map_desc
.pBits
;
373 mapped_texture
->RowPitch
= wined3d_map_desc
.RowPitch
;
374 mapped_texture
->DepthPitch
= wined3d_map_desc
.SlicePitch
;
380 static void STDMETHODCALLTYPE
d3d10_texture3d_Unmap(ID3D10Texture3D
*iface
, UINT sub_resource_idx
)
382 struct d3d10_texture3d
*texture
= (struct d3d10_texture3d
*)iface
;
383 struct wined3d_resource
*sub_resource
;
385 TRACE("iface %p, sub_resource_idx %u.\n", iface
, sub_resource_idx
);
387 if (!(sub_resource
= wined3d_texture_get_sub_resource(texture
->wined3d_texture
, sub_resource_idx
)))
390 wined3d_volume_unmap(wined3d_volume_from_resource(sub_resource
));
393 static void STDMETHODCALLTYPE
d3d10_texture3d_GetDesc(ID3D10Texture3D
*iface
, D3D10_TEXTURE3D_DESC
*desc
)
395 struct d3d10_texture3d
*texture
= (struct d3d10_texture3d
*)iface
;
397 TRACE("iface %p, desc %p.\n", iface
, desc
);
399 *desc
= texture
->desc
;
402 static const struct ID3D10Texture3DVtbl d3d10_texture3d_vtbl
=
404 /* IUnknown methods */
405 d3d10_texture3d_QueryInterface
,
406 d3d10_texture3d_AddRef
,
407 d3d10_texture3d_Release
,
408 /* ID3D10DeviceChild methods */
409 d3d10_texture3d_GetDevice
,
410 d3d10_texture3d_GetPrivateData
,
411 d3d10_texture3d_SetPrivateData
,
412 d3d10_texture3d_SetPrivateDataInterface
,
413 /* ID3D10Resource methods */
414 d3d10_texture3d_GetType
,
415 d3d10_texture3d_SetEvictionPriority
,
416 d3d10_texture3d_GetEvictionPriority
,
417 /* ID3D10Texture3D methods */
419 d3d10_texture3d_Unmap
,
420 d3d10_texture3d_GetDesc
,
423 static const struct wined3d_parent_ops d3d10_texture3d_wined3d_parent_ops
=
425 d3d10_texture3d_wined3d_object_released
,
428 HRESULT
d3d10_texture3d_init(struct d3d10_texture3d
*texture
, struct d3d10_device
*device
,
429 const D3D10_TEXTURE3D_DESC
*desc
)
433 texture
->vtbl
= &d3d10_texture3d_vtbl
;
434 texture
->refcount
= 1;
435 texture
->desc
= *desc
;
437 FIXME("Implement DXGI<->wined3d usage conversion.\n");
439 hr
= wined3d_texture_create_3d(device
->wined3d_device
, desc
->Width
, desc
->Height
, desc
->Depth
,
440 desc
->MipLevels
, desc
->Usage
, wined3dformat_from_dxgi_format(desc
->Format
), WINED3DPOOL_DEFAULT
,
441 texture
, &d3d10_texture3d_wined3d_parent_ops
, &texture
->wined3d_texture
);
444 WARN("Failed to create wined3d texture, hr %#x.\n", hr
);