[PATCH 5/8] d3d11: Implement d3d11_depthstencil_view_GetResource().

Józef Kucia jkucia at codeweavers.com
Mon Sep 7 18:12:45 CDT 2015


The intent is to eventually eliminate wined3d_resource_from_d3d10_resource().
---
 dlls/d3d11/buffer.c        |  8 ++++++++
 dlls/d3d11/d3d11_private.h |  7 +++++--
 dlls/d3d11/device.c        | 13 ++++++++++++-
 dlls/d3d11/texture.c       |  8 ++++++++
 dlls/d3d11/utils.c         | 22 ++++++++++++++++++++++
 dlls/d3d11/view.c          | 38 +++++++++++++++++++++-----------------
 6 files changed, 76 insertions(+), 20 deletions(-)

diff --git a/dlls/d3d11/buffer.c b/dlls/d3d11/buffer.c
index 26123e8..043e7da 100644
--- a/dlls/d3d11/buffer.c
+++ b/dlls/d3d11/buffer.c
@@ -190,6 +190,14 @@ static const struct ID3D11BufferVtbl d3d11_buffer_vtbl =
     d3d11_buffer_GetDesc,
 };
 
+struct d3d_buffer *unsafe_impl_from_ID3D11Buffer(ID3D11Buffer *iface)
+{
+    if (!iface)
+        return NULL;
+    assert(iface->lpVtbl == &d3d11_buffer_vtbl);
+    return CONTAINING_RECORD(iface, struct d3d_buffer, ID3D11Buffer_iface);
+}
+
 /* ID3D10Buffer methods */
 
 static inline struct d3d_buffer *impl_from_ID3D10Buffer(ID3D10Buffer *iface)
diff --git a/dlls/d3d11/d3d11_private.h b/dlls/d3d11/d3d11_private.h
index 6c88747..1b92886 100644
--- a/dlls/d3d11/d3d11_private.h
+++ b/dlls/d3d11/d3d11_private.h
@@ -63,6 +63,7 @@ const char *debug_dxgi_format(DXGI_FORMAT format) DECLSPEC_HIDDEN;
 DXGI_FORMAT dxgi_format_from_wined3dformat(enum wined3d_format_id format) DECLSPEC_HIDDEN;
 enum wined3d_format_id wined3dformat_from_dxgi_format(DXGI_FORMAT format) DECLSPEC_HIDDEN;
 DWORD wined3d_usage_from_d3d11(UINT bind_flags, enum D3D11_USAGE usage) DECLSPEC_HIDDEN;
+struct wined3d_resource *wined3d_resource_from_d3d11_resource(ID3D11Resource *resource) DECLSPEC_HIDDEN;
 struct wined3d_resource *wined3d_resource_from_d3d10_resource(ID3D10Resource *resource) DECLSPEC_HIDDEN;
 DWORD wined3d_map_flags_from_d3d10_map_type(D3D10_MAP map_type) DECLSPEC_HIDDEN;
 
@@ -114,6 +115,7 @@ static inline struct d3d_texture2d *impl_from_ID3D10Texture2D(ID3D10Texture2D *i
 
 HRESULT d3d_texture2d_create(struct d3d_device *device, const D3D11_TEXTURE2D_DESC *desc,
         const D3D11_SUBRESOURCE_DATA *data, struct d3d_texture2d **texture) DECLSPEC_HIDDEN;
+struct d3d_texture2d *unsafe_impl_from_ID3D11Texture2D(ID3D11Texture2D *iface) DECLSPEC_HIDDEN;
 struct d3d_texture2d *unsafe_impl_from_ID3D10Texture2D(ID3D10Texture2D *iface) DECLSPEC_HIDDEN;
 
 /* ID3D11Texture3D, ID3D10Texture3D */
@@ -147,6 +149,7 @@ struct d3d_buffer
 
 HRESULT d3d_buffer_create(struct d3d_device *device, const D3D11_BUFFER_DESC *desc,
         const D3D11_SUBRESOURCE_DATA *data, struct d3d_buffer **buffer) DECLSPEC_HIDDEN;
+struct d3d_buffer *unsafe_impl_from_ID3D11Buffer(ID3D11Buffer *iface) DECLSPEC_HIDDEN;
 struct d3d_buffer *unsafe_impl_from_ID3D10Buffer(ID3D10Buffer *iface) DECLSPEC_HIDDEN;
 
 /* ID3D11DepthStencilView, ID3D10DepthStencilView */
@@ -159,12 +162,12 @@ struct d3d_depthstencil_view
     struct wined3d_private_store private_store;
     struct wined3d_rendertarget_view *wined3d_view;
     D3D10_DEPTH_STENCIL_VIEW_DESC desc;
-    ID3D10Resource *resource;
+    ID3D11Resource *resource;
     ID3D11Device *device;
 };
 
 HRESULT d3d_depthstencil_view_init(struct d3d_depthstencil_view *view, struct d3d_device *device,
-        ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc) DECLSPEC_HIDDEN;
+        ID3D11Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc) DECLSPEC_HIDDEN;
 struct d3d_depthstencil_view *unsafe_impl_from_ID3D10DepthStencilView(ID3D10DepthStencilView *iface) DECLSPEC_HIDDEN;
 
 /* ID3D10RenderTargetView */
diff --git a/dlls/d3d11/device.c b/dlls/d3d11/device.c
index 069c565..9dcf7b6 100644
--- a/dlls/d3d11/device.c
+++ b/dlls/d3d11/device.c
@@ -2138,6 +2138,7 @@ static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Devic
 {
     struct d3d_device *device = impl_from_ID3D10Device(iface);
     struct d3d_depthstencil_view *object;
+    ID3D11Resource *d3d11_resource;
     HRESULT hr;
 
     TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
@@ -2145,13 +2146,23 @@ static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Devic
     if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
         return E_OUTOFMEMORY;
 
-    if (FAILED(hr = d3d_depthstencil_view_init(object, device, resource, desc)))
+    if (FAILED(hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D11Resource, (void **)&d3d11_resource)))
+    {
+        ERR("Resource does not implement ID3D11Resource.\n");
+        HeapFree(GetProcessHeap(), 0, object);
+        return E_FAIL;
+    }
+
+    if (FAILED(hr = d3d_depthstencil_view_init(object, device, d3d11_resource, desc)))
     {
         WARN("Failed to initialize depthstencil view, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
+        ID3D11Resource_Release(d3d11_resource);
         return hr;
     }
 
+    ID3D11Resource_Release(d3d11_resource);
+
     TRACE("Created depthstencil view %p.\n", object);
     *view = &object->ID3D10DepthStencilView_iface;
 
diff --git a/dlls/d3d11/texture.c b/dlls/d3d11/texture.c
index dbb9a27..85d001f 100644
--- a/dlls/d3d11/texture.c
+++ b/dlls/d3d11/texture.c
@@ -241,6 +241,14 @@ static const struct ID3D11Texture2DVtbl d3d11_texture2d_vtbl =
     d3d11_texture2d_GetDesc,
 };
 
+struct d3d_texture2d *unsafe_impl_from_ID3D11Texture2D(ID3D11Texture2D *iface)
+{
+    if (!iface)
+        return NULL;
+    assert(iface->lpVtbl == &d3d11_texture2d_vtbl);
+    return CONTAINING_RECORD(iface, struct d3d_texture2d, ID3D11Texture2D_iface);
+}
+
 /* IUnknown methods */
 
 static HRESULT STDMETHODCALLTYPE d3d10_texture2d_QueryInterface(ID3D10Texture2D *iface, REFIID riid, void **object)
diff --git a/dlls/d3d11/utils.c b/dlls/d3d11/utils.c
index 514b147..9bf3ada 100644
--- a/dlls/d3d11/utils.c
+++ b/dlls/d3d11/utils.c
@@ -502,6 +502,28 @@ UINT d3d10_resource_misc_flags_from_d3d11_resource_misc_flags(UINT resource_misc
     return d3d10_resource_misc_flags;
 }
 
+struct wined3d_resource *wined3d_resource_from_d3d11_resource(ID3D11Resource *resource)
+{
+    D3D11_RESOURCE_DIMENSION dimension;
+
+    ID3D11Resource_GetType(resource, &dimension);
+
+    switch (dimension)
+    {
+        case D3D11_RESOURCE_DIMENSION_BUFFER:
+            return wined3d_buffer_get_resource(unsafe_impl_from_ID3D11Buffer(
+                    (ID3D11Buffer *)resource)->wined3d_buffer);
+
+        case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
+            return wined3d_texture_get_resource(unsafe_impl_from_ID3D11Texture2D(
+                    (ID3D11Texture2D *)resource)->wined3d_texture);
+
+        default:
+            FIXME("Unhandled resource dimension %#x.\n", dimension);
+            return NULL;
+    }
+}
+
 struct wined3d_resource *wined3d_resource_from_d3d10_resource(ID3D10Resource *resource)
 {
     D3D10_RESOURCE_DIMENSION dimension;
diff --git a/dlls/d3d11/view.c b/dlls/d3d11/view.c
index 0d20314..aab3ffe 100644
--- a/dlls/d3d11/view.c
+++ b/dlls/d3d11/view.c
@@ -25,20 +25,20 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
 
-static HRESULT set_dsdesc_from_resource(D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10Resource *resource)
+static HRESULT set_dsdesc_from_resource(D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11Resource *resource)
 {
-    D3D10_RESOURCE_DIMENSION dimension;
+    D3D11_RESOURCE_DIMENSION dimension;
 
-    ID3D10Resource_GetType(resource, &dimension);
+    ID3D11Resource_GetType(resource, &dimension);
 
     switch (dimension)
     {
-        case D3D10_RESOURCE_DIMENSION_TEXTURE1D:
+        case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
         {
             D3D10_TEXTURE1D_DESC texture_desc;
             ID3D10Texture1D *texture;
 
-            if (FAILED(ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture1D, (void **)&texture)))
+            if (FAILED(ID3D11Resource_QueryInterface(resource, &IID_ID3D10Texture1D, (void **)&texture)))
             {
                 ERR("Resource of type TEXTURE1D doesn't implement ID3D10Texture1D.\n");
                 return E_INVALIDARG;
@@ -64,12 +64,12 @@ static HRESULT set_dsdesc_from_resource(D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3
             return S_OK;
         }
 
-        case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
+        case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
         {
             D3D10_TEXTURE2D_DESC texture_desc;
             ID3D10Texture2D *texture;
 
-            if (FAILED(ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture2D, (void **)&texture)))
+            if (FAILED(ID3D11Resource_QueryInterface(resource, &IID_ID3D10Texture2D, (void **)&texture)))
             {
                 ERR("Resource of type TEXTURE2D doesn't implement ID3D10Texture2D.\n");
                 return E_INVALIDARG;
@@ -113,8 +113,8 @@ static HRESULT set_dsdesc_from_resource(D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3
 
         default:
             FIXME("Unhandled resource dimension %#x.\n", dimension);
-        case D3D10_RESOURCE_DIMENSION_BUFFER:
-        case D3D10_RESOURCE_DIMENSION_TEXTURE3D:
+        case D3D11_RESOURCE_DIMENSION_BUFFER:
+        case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
             return E_INVALIDARG;
     }
 }
@@ -417,7 +417,7 @@ static ULONG STDMETHODCALLTYPE d3d11_depthstencil_view_Release(ID3D11DepthStenci
     {
         wined3d_mutex_lock();
         wined3d_rendertarget_view_decref(view->wined3d_view);
-        ID3D10Resource_Release(view->resource);
+        ID3D11Resource_Release(view->resource);
         ID3D11Device_Release(view->device);
         wined3d_private_store_cleanup(&view->private_store);
         wined3d_mutex_unlock();
@@ -471,7 +471,12 @@ static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_view_SetPrivateDataInterface
 static void STDMETHODCALLTYPE d3d11_depthstencil_view_GetResource(ID3D11DepthStencilView *iface,
         ID3D11Resource **resource)
 {
-    FIXME("iface %p, resource %p stub!\n", iface, resource);
+    struct d3d_depthstencil_view *view = impl_from_ID3D11DepthStencilView(iface);
+
+    TRACE("iface %p, resource %p.\n", iface, resource);
+
+    *resource = view->resource;
+    ID3D11Resource_AddRef(*resource);
 }
 
 static void STDMETHODCALLTYPE d3d11_depthstencil_view_GetDesc(ID3D11DepthStencilView *iface,
@@ -586,8 +591,7 @@ static void STDMETHODCALLTYPE d3d10_depthstencil_view_GetResource(ID3D10DepthSte
 
     TRACE("iface %p, resource %p.\n", iface, resource);
 
-    *resource = view->resource;
-    ID3D10Resource_AddRef(*resource);
+    ID3D11Resource_QueryInterface(view->resource, &IID_ID3D10Resource, (void **)resource);
 }
 
 /* ID3D10DepthStencilView methods */
@@ -672,7 +676,7 @@ static void wined3d_depth_stencil_view_desc_from_d3d10core(struct wined3d_render
 }
 
 HRESULT d3d_depthstencil_view_init(struct d3d_depthstencil_view *view, struct d3d_device *device,
-        ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc)
+        ID3D11Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc)
 {
     struct wined3d_rendertarget_view_desc wined3d_desc;
     struct wined3d_resource *wined3d_resource;
@@ -693,10 +697,10 @@ HRESULT d3d_depthstencil_view_init(struct d3d_depthstencil_view *view, struct d3
     }
 
     wined3d_mutex_lock();
-    if (!(wined3d_resource = wined3d_resource_from_d3d10_resource(resource)))
+    if (!(wined3d_resource = wined3d_resource_from_d3d11_resource(resource)))
     {
         wined3d_mutex_unlock();
-        ERR("Failed to get wined3d resource for d3d10 resource %p.\n", resource);
+        ERR("Failed to get wined3d resource for d3d11 resource %p.\n", resource);
         return E_FAIL;
     }
 
@@ -712,7 +716,7 @@ HRESULT d3d_depthstencil_view_init(struct d3d_depthstencil_view *view, struct d3
     wined3d_private_store_init(&view->private_store);
     wined3d_mutex_unlock();
     view->resource = resource;
-    ID3D10Resource_AddRef(resource);
+    ID3D11Resource_AddRef(resource);
     view->device = &device->ID3D11Device_iface;
     ID3D11Device_AddRef(view->device);
 
-- 
2.4.6




More information about the wine-patches mailing list