d3d10core: Implement d3d10_depthstencil_view_GetDevice().

This commit is contained in:
Henri Verbeet 2014-02-13 10:14:22 +01:00 committed by Alexandre Julliard
parent 82fc81b644
commit 01d435288f
4 changed files with 27 additions and 8 deletions

View File

@ -123,9 +123,10 @@ struct d3d10_depthstencil_view
D3D10_DEPTH_STENCIL_VIEW_DESC desc; D3D10_DEPTH_STENCIL_VIEW_DESC desc;
ID3D10Resource *resource; ID3D10Resource *resource;
ID3D10Device1 *device;
}; };
HRESULT d3d10_depthstencil_view_init(struct d3d10_depthstencil_view *view, HRESULT d3d10_depthstencil_view_init(struct d3d10_depthstencil_view *view, struct d3d10_device *device,
ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc) DECLSPEC_HIDDEN; ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc) DECLSPEC_HIDDEN;
/* ID3D10RenderTargetView */ /* ID3D10RenderTargetView */

View File

@ -1214,16 +1214,16 @@ static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Devic
static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface, static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view) ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
{ {
struct d3d10_device *device = impl_from_ID3D10Device(iface);
struct d3d10_depthstencil_view *object; struct d3d10_depthstencil_view *object;
HRESULT hr; HRESULT hr;
TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view); TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
if (!object)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
if (FAILED(hr = d3d10_depthstencil_view_init(object, resource, desc))) if (FAILED(hr = d3d10_depthstencil_view_init(object, device, resource, desc)))
{ {
WARN("Failed to initialize depthstencil view, hr %#x.\n", hr); WARN("Failed to initialize depthstencil view, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, object); HeapFree(GetProcessHeap(), 0, object);

View File

@ -213,10 +213,10 @@ static void test_create_depthstencil_view(void)
{ {
D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc; D3D10_DEPTH_STENCIL_VIEW_DESC dsv_desc;
D3D10_TEXTURE2D_DESC texture_desc; D3D10_TEXTURE2D_DESC texture_desc;
ULONG refcount, expected_refcount;
ID3D10DepthStencilView *dsview; ID3D10DepthStencilView *dsview;
ID3D10Device *device, *tmp;
ID3D10Texture2D *texture; ID3D10Texture2D *texture;
ID3D10Device *device;
ULONG refcount;
HRESULT hr; HRESULT hr;
if (!(device = create_device())) if (!(device = create_device()))
@ -240,8 +240,18 @@ static void test_create_depthstencil_view(void)
hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture); hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr); ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
expected_refcount = get_refcount((IUnknown *)device) + 1;
hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsview); hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsview);
ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x\n", hr); ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x\n", hr);
refcount = get_refcount((IUnknown *)device);
ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
tmp = NULL;
expected_refcount = refcount + 1;
ID3D10DepthStencilView_GetDevice(dsview, &tmp);
ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
refcount = get_refcount((IUnknown *)device);
ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
ID3D10Device_Release(tmp);
ID3D10DepthStencilView_GetDesc(dsview, &dsv_desc); ID3D10DepthStencilView_GetDesc(dsview, &dsv_desc);
ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format); ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);

View File

@ -425,6 +425,7 @@ static ULONG STDMETHODCALLTYPE d3d10_depthstencil_view_Release(ID3D10DepthStenci
if (!refcount) if (!refcount)
{ {
ID3D10Resource_Release(This->resource); ID3D10Resource_Release(This->resource);
ID3D10Device1_Release(This->device);
HeapFree(GetProcessHeap(), 0, This); HeapFree(GetProcessHeap(), 0, This);
} }
@ -435,7 +436,12 @@ static ULONG STDMETHODCALLTYPE d3d10_depthstencil_view_Release(ID3D10DepthStenci
static void STDMETHODCALLTYPE d3d10_depthstencil_view_GetDevice(ID3D10DepthStencilView *iface, ID3D10Device **device) static void STDMETHODCALLTYPE d3d10_depthstencil_view_GetDevice(ID3D10DepthStencilView *iface, ID3D10Device **device)
{ {
FIXME("iface %p, device %p stub!\n", iface, device); struct d3d10_depthstencil_view *view = impl_from_ID3D10DepthStencilView(iface);
TRACE("iface %p, device %p.\n", iface, device);
*device = (ID3D10Device *)view->device;
ID3D10Device_AddRef(*device);
} }
static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_GetPrivateData(ID3D10DepthStencilView *iface, static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_GetPrivateData(ID3D10DepthStencilView *iface,
@ -506,7 +512,7 @@ static const struct ID3D10DepthStencilViewVtbl d3d10_depthstencil_view_vtbl =
d3d10_depthstencil_view_GetDesc, d3d10_depthstencil_view_GetDesc,
}; };
HRESULT d3d10_depthstencil_view_init(struct d3d10_depthstencil_view *view, HRESULT d3d10_depthstencil_view_init(struct d3d10_depthstencil_view *view, struct d3d10_device *device,
ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc) ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc)
{ {
HRESULT hr; HRESULT hr;
@ -526,6 +532,8 @@ HRESULT d3d10_depthstencil_view_init(struct d3d10_depthstencil_view *view,
view->resource = resource; view->resource = resource;
ID3D10Resource_AddRef(resource); ID3D10Resource_AddRef(resource);
view->device = &device->ID3D10Device1_iface;
ID3D10Device1_AddRef(view->device);
return S_OK; return S_OK;
} }