[PATCH 5/5] d3d8: Use the private store api for buffers.

Stefan Dösinger stefan at codeweavers.com
Sat Mar 8 15:53:15 CST 2014


---
 dlls/d3d8/buffer.c       | 60 +++++----------------------------------------
 dlls/d3d8/d3d8_main.c    | 64 ++++++++++++++++++++++++++++++++++++++++++++++++
 dlls/d3d8/d3d8_private.h |  6 +++++
 3 files changed, 76 insertions(+), 54 deletions(-)

diff --git a/dlls/d3d8/buffer.c b/dlls/d3d8/buffer.c
index badd341..223e266 100644
--- a/dlls/d3d8/buffer.c
+++ b/dlls/d3d8/buffer.c
@@ -104,52 +104,28 @@ static HRESULT WINAPI d3d8_vertexbuffer_SetPrivateData(IDirect3DVertexBuffer8 *i
         REFGUID guid, const void *data, DWORD data_size, DWORD flags)
 {
     struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
-    struct wined3d_resource *resource;
-    HRESULT hr;
-
     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
             iface, debugstr_guid(guid), data, data_size, flags);
 
-    wined3d_mutex_lock();
-    resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
-    hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags);
-    wined3d_mutex_unlock();
-
-    return hr;
+    return d3d8_resource_set_private_data(&buffer->resource, guid, data, data_size, flags);
 }
 
 static HRESULT WINAPI d3d8_vertexbuffer_GetPrivateData(IDirect3DVertexBuffer8 *iface,
         REFGUID guid, void *data, DWORD *data_size)
 {
     struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
-    struct wined3d_resource *resource;
-    HRESULT hr;
-
     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
             iface, debugstr_guid(guid), data, data_size);
 
-    wined3d_mutex_lock();
-    resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
-    hr = wined3d_resource_get_private_data(resource, guid, data, data_size);
-    wined3d_mutex_unlock();
-
-    return hr;
+    return d3d8_resource_get_private_data(&buffer->resource, guid, data, data_size);
 }
 
 static HRESULT WINAPI d3d8_vertexbuffer_FreePrivateData(IDirect3DVertexBuffer8 *iface, REFGUID guid)
 {
     struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
-    struct wined3d_resource *resource;
-    HRESULT hr;
-
     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
 
-    wined3d_mutex_lock();
-    resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
-    hr = wined3d_resource_free_private_data(resource, guid);
-    wined3d_mutex_unlock();
-
-    return hr;
+    return d3d8_resource_free_private_data(&buffer->resource, guid);
 }
 
 static DWORD WINAPI d3d8_vertexbuffer_SetPriority(IDirect3DVertexBuffer8 *iface, DWORD priority)
@@ -401,52 +377,28 @@ static HRESULT WINAPI d3d8_indexbuffer_SetPrivateData(IDirect3DIndexBuffer8 *ifa
         REFGUID guid, const void *data, DWORD data_size, DWORD flags)
 {
     struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
-    struct wined3d_resource *resource;
-    HRESULT hr;
-
     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
             iface, debugstr_guid(guid), data, data_size, flags);
 
-    wined3d_mutex_lock();
-    resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
-    hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags);
-    wined3d_mutex_unlock();
-
-    return hr;
+    return d3d8_resource_set_private_data(&buffer->resource, guid, data, data_size, flags);
 }
 
 static HRESULT WINAPI d3d8_indexbuffer_GetPrivateData(IDirect3DIndexBuffer8 *iface,
         REFGUID guid, void *data, DWORD *data_size)
 {
     struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
-    struct wined3d_resource *resource;
-    HRESULT hr;
-
     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
             iface, debugstr_guid(guid), data, data_size);
 
-    wined3d_mutex_lock();
-    resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
-    hr = wined3d_resource_get_private_data(resource, guid, data, data_size);
-    wined3d_mutex_unlock();
-
-    return hr;
+    return d3d8_resource_get_private_data(&buffer->resource, guid, data, data_size);
 }
 
 static HRESULT WINAPI d3d8_indexbuffer_FreePrivateData(IDirect3DIndexBuffer8 *iface, REFGUID guid)
 {
     struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
-    struct wined3d_resource *resource;
-    HRESULT hr;
-
     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
 
-    wined3d_mutex_lock();
-    resource = wined3d_buffer_get_resource(buffer->wined3d_buffer);
-    hr = wined3d_resource_free_private_data(resource, guid);
-    wined3d_mutex_unlock();
-
-    return hr;
+    return d3d8_resource_free_private_data(&buffer->resource, guid);
 }
 
 static DWORD WINAPI d3d8_indexbuffer_SetPriority(IDirect3DIndexBuffer8 *iface, DWORD priority)
diff --git a/dlls/d3d8/d3d8_main.c b/dlls/d3d8/d3d8_main.c
index 2175a33..db93648 100644
--- a/dlls/d3d8/d3d8_main.c
+++ b/dlls/d3d8/d3d8_main.c
@@ -140,9 +140,73 @@ HRESULT WINAPI ValidatePixelShader(DWORD* pixelshader, DWORD* reserved1, BOOL bo
 
 void d3d8_resource_cleanup(struct d3d8_resource *resource)
 {
+    wined3d_private_store_cleanup(&resource->private_store);
+}
+
+HRESULT d3d8_resource_free_private_data(struct d3d8_resource *resource, const GUID *guid)
+{
+    struct wined3d_private_data *entry;
+
+    wined3d_mutex_lock();
+    entry = wined3d_private_store_get_private_data(&resource->private_store, guid);
+    if (!entry)
+    {
+        wined3d_mutex_unlock();
+        return D3DERR_NOTFOUND;
+    }
+
+    wined3d_private_store_free_private_data(&resource->private_store, entry);
+    wined3d_mutex_unlock();
+
+    return D3D_OK;
+}
+
+HRESULT d3d8_resource_get_private_data(struct d3d8_resource *resource, const GUID *guid,
+        void *data, DWORD *data_size)
+{
+    const struct wined3d_private_data *stored_data;
+
+    wined3d_mutex_lock();
+    stored_data = wined3d_private_store_get_private_data(&resource->private_store, guid);
+    if (!stored_data)
+    {
+        wined3d_mutex_unlock();
+        return D3DERR_NOTFOUND;
+    }
+
+    if (*data_size < stored_data->size)
+    {
+        *data_size = stored_data->size;
+        wined3d_mutex_unlock();
+        return D3DERR_MOREDATA;
+    }
+    *data_size = stored_data->size;
+
+    if (stored_data->flags & WINED3DSPD_IUNKNOWN)
+    {
+        *(IUnknown **)data = stored_data->content.object;
+        IUnknown_AddRef(*(IUnknown **)data);
+    }
+    else
+        memcpy(data, stored_data->content.data, stored_data->size);
+
+    wined3d_mutex_unlock();
+    return D3D_OK;
 }
 
 void d3d8_resource_init(struct d3d8_resource *resource)
 {
     resource->refcount = 1;
+    wined3d_private_store_init(&resource->private_store);
+}
+
+HRESULT d3d8_resource_set_private_data(struct d3d8_resource *resource, const GUID *guid,
+        const void *data, DWORD data_size, DWORD flags)
+{
+    HRESULT hr;
+
+    wined3d_mutex_lock();
+    hr = wined3d_private_store_set_private_data(&resource->private_store, guid, data, data_size, flags);
+    wined3d_mutex_unlock();
+    return hr;
 }
diff --git a/dlls/d3d8/d3d8_private.h b/dlls/d3d8/d3d8_private.h
index df0066b..b3a4fdd 100644
--- a/dlls/d3d8/d3d8_private.h
+++ b/dlls/d3d8/d3d8_private.h
@@ -178,10 +178,16 @@ struct d3d8_resource
 {
     LONG refcount;
     IDirect3DDevice8 *parent_device;
+    struct wined3d_private_store private_store;
 };
 
 void d3d8_resource_cleanup(struct d3d8_resource *resource) DECLSPEC_HIDDEN;
+HRESULT d3d8_resource_free_private_data(struct d3d8_resource *resource, const GUID *guid) DECLSPEC_HIDDEN;
+HRESULT d3d8_resource_get_private_data(struct d3d8_resource *resource, const GUID *guid,
+        void *data, DWORD *data_size) DECLSPEC_HIDDEN;
 void d3d8_resource_init(struct d3d8_resource *resource) DECLSPEC_HIDDEN;
+HRESULT d3d8_resource_set_private_data(struct d3d8_resource *resource, const GUID *guid,
+        const void *data, DWORD data_size, DWORD flags) DECLSPEC_HIDDEN;
 
 struct d3d8_volume
 {
-- 
1.8.3.2




More information about the wine-patches mailing list