[PATCH 2/5] ddraw: Use the new private store api.

Stefan Dösinger stefan at codeweavers.com
Thu Mar 6 03:42:49 CST 2014


---
 dlls/ddraw/ddraw_private.h |  2 ++
 dlls/ddraw/surface.c       | 64 +++++++++++++++++++++++++++-------------------
 dlls/wined3d/resource.c    |  8 +-----
 3 files changed, 40 insertions(+), 34 deletions(-)

diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h
index 0f7f755..2443b25 100644
--- a/dlls/ddraw/ddraw_private.h
+++ b/dlls/ddraw/ddraw_private.h
@@ -36,6 +36,7 @@
 #endif
 #include "wine/list.h"
 #include "wine/wined3d.h"
+#include "wine/wined3d_utils.h"
 
 extern const struct wined3d_parent_ops ddraw_null_wined3d_parent_ops DECLSPEC_HIDDEN;
 extern DWORD force_refresh_rate DECLSPEC_HIDDEN;
@@ -150,6 +151,7 @@ struct ddraw_surface
     struct ddraw *ddraw;
     struct wined3d_surface *wined3d_surface;
     struct wined3d_texture *wined3d_texture;
+    struct wined3d_private_store private_store;
     struct d3d_device *device1;
 
     /* This implementation handles attaching surfaces to other surfaces */
diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c
index 13aa813..30c3643 100644
--- a/dlls/ddraw/surface.c
+++ b/dlls/ddraw/surface.c
@@ -2246,25 +2246,18 @@ static HRESULT WINAPI ddraw_surface7_GetPriority(IDirectDrawSurface7 *iface, DWO
  *
  *****************************************************************************/
 static HRESULT WINAPI ddraw_surface7_SetPrivateData(IDirectDrawSurface7 *iface,
-        REFGUID tag, void *Data, DWORD Size, DWORD Flags)
+        REFGUID tag, void *data, DWORD size, DWORD flags)
 {
     struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
-    struct wined3d_resource *resource;
-    HRESULT hr;
+    BOOL result;
 
     TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
-            iface, debugstr_guid(tag), Data, Size, Flags);
+            iface, debugstr_guid(tag), data, size, flags);
 
     wined3d_mutex_lock();
-    resource = wined3d_surface_get_resource(surface->wined3d_surface);
-    hr = wined3d_resource_set_private_data(resource, tag, Data, Size, Flags);
+    result = wined3d_private_store_set_private_data(&surface->private_store, tag, data, size, flags);
     wined3d_mutex_unlock();
-
-    switch(hr)
-    {
-        case WINED3DERR_INVALIDCALL:        return DDERR_INVALIDPARAMS;
-        default:                            return hr;
-    }
+    return result ? DD_OK : DDERR_INVALIDPARAMS;
 }
 
 static HRESULT WINAPI ddraw_surface4_SetPrivateData(IDirectDrawSurface4 *iface,
@@ -2294,24 +2287,40 @@ static HRESULT WINAPI ddraw_surface4_SetPrivateData(IDirectDrawSurface4 *iface,
  *  For more details, see IWineD3DSurface::GetPrivateData
  *
  *****************************************************************************/
-static HRESULT WINAPI ddraw_surface7_GetPrivateData(IDirectDrawSurface7 *iface, REFGUID tag, void *Data, DWORD *Size)
+static HRESULT WINAPI ddraw_surface7_GetPrivateData(IDirectDrawSurface7 *iface, REFGUID tag, void *data, DWORD *size)
 {
     struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
-    struct wined3d_resource *resource;
-    HRESULT hr;
+    const struct wined3d_private_data *stored_data;
 
     TRACE("iface %p, tag %s, data %p, data_size %p.\n",
-            iface, debugstr_guid(tag), Data, Size);
+            iface, debugstr_guid(tag), data, size);
 
-    if(!Data)
+    if (!data)
         return DDERR_INVALIDPARAMS;
 
     wined3d_mutex_lock();
-    resource = wined3d_surface_get_resource(surface->wined3d_surface);
-    hr = wined3d_resource_get_private_data(resource, tag, Data, Size);
-    wined3d_mutex_unlock();
+    stored_data = wined3d_private_store_get_private_data(&surface->private_store, tag);
+    if (!stored_data)
+    {
+        wined3d_mutex_unlock();
+        return DDERR_NOTFOUND;
+    }
 
-    return hr;
+    if (*size < stored_data->size)
+    {
+        *size = stored_data->size;
+        wined3d_mutex_unlock();
+        return DDERR_MOREDATA;
+    }
+    *size = stored_data->size;
+
+    if (stored_data->flags & WINED3DSPD_IUNKNOWN)
+        *(IUnknown **)data = stored_data->content.object;
+    else
+        memcpy(data, stored_data->content.data, stored_data->size);
+
+    wined3d_mutex_unlock();
+    return DD_OK;
 }
 
 static HRESULT WINAPI ddraw_surface4_GetPrivateData(IDirectDrawSurface4 *iface, REFGUID tag, void *data, DWORD *size)
@@ -2340,17 +2349,14 @@ static HRESULT WINAPI ddraw_surface4_GetPrivateData(IDirectDrawSurface4 *iface,
 static HRESULT WINAPI ddraw_surface7_FreePrivateData(IDirectDrawSurface7 *iface, REFGUID tag)
 {
     struct ddraw_surface *surface = impl_from_IDirectDrawSurface7(iface);
-    struct wined3d_resource *resource;
-    HRESULT hr;
+    BOOL result;
 
     TRACE("iface %p, tag %s.\n", iface, debugstr_guid(tag));
 
     wined3d_mutex_lock();
-    resource = wined3d_surface_get_resource(surface->wined3d_surface);
-    hr = wined3d_resource_free_private_data(resource, tag);
+    result = wined3d_private_store_free_private_data(&surface->private_store, tag);
     wined3d_mutex_unlock();
-
-    return hr;
+    return result ? DD_OK : DDERR_NOTFOUND;
 }
 
 static HRESULT WINAPI ddraw_surface4_FreePrivateData(IDirectDrawSurface4 *iface, REFGUID tag)
@@ -5469,6 +5475,8 @@ static void STDMETHODCALLTYPE ddraw_surface_wined3d_object_destroyed(void *paren
     if (surface == surface->ddraw->primary)
         surface->ddraw->primary = NULL;
 
+    wined3d_private_store_cleanup(&surface->private_store);
+
     HeapFree(GetProcessHeap(), 0, surface);
 }
 
@@ -6095,5 +6103,7 @@ HRESULT ddraw_surface_init(struct ddraw_surface *surface, struct ddraw *ddraw, s
     surface->wined3d_surface = wined3d_surface;
     *parent_ops = &ddraw_surface_wined3d_parent_ops;
 
+    wined3d_private_store_init(&surface->private_store);
+
     return DD_OK;
 }
diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c
index 670034f..7046314 100644
--- a/dlls/wined3d/resource.c
+++ b/dlls/wined3d/resource.c
@@ -193,13 +193,7 @@ HRESULT CDECL wined3d_resource_get_private_data(const struct wined3d_resource *r
     if (d->flags & WINED3DSPD_IUNKNOWN)
     {
         *(IUnknown **)data = d->content.object;
-        if (resource->device->wined3d->dxVersion != 7)
-        {
-            /* D3D8 and D3D9 addref the private data, DDraw does not. This
-             * can't be handled in ddraw because it doesn't know if the
-             * pointer returned is an IUnknown * or just a blob. */
-            IUnknown_AddRef(d->content.object);
-        }
+        IUnknown_AddRef(*(IUnknown **)data);
     }
     else
     {
-- 
1.8.3.2




More information about the wine-patches mailing list