[PATCH 1/5] wined3d: Decouple private data from the resource structure (try 3).
Stefan Dösinger
stefan at codeweavers.com
Thu Mar 6 03:42:48 CST 2014
Try 3: Move this out of wined3d and wined3d.h and use its own header
with inline functions. This is to avoid COM-related code inside wined3d
among other reasons.
Try 2: Don't HeapAlloc the private store structure. Make the caller of
get_private_data responsible for calling AddRef on the returned
interface.
I have kept the somewhat questionable behavior where set_private_data
clears the old data in case of an IUnknown * size mismatch for now.
Native ddraw behaves the same way, but native d3d8/9 do not. I'll deal
with this in a separate patch.
---
dlls/wined3d/resource.c | 120 +++++------------------------------
dlls/wined3d/wined3d_private.h | 5 +-
include/wine/wined3d.h | 3 -
include/wine/wined3d_utils.h | 138 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 157 insertions(+), 109 deletions(-)
create mode 100644 include/wine/wined3d_utils.h
diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c
index 177d23e..670034f 100644
--- a/dlls/wined3d/resource.c
+++ b/dlls/wined3d/resource.c
@@ -27,22 +27,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
-struct private_data
-{
- struct list entry;
-
- GUID tag;
- DWORD flags; /* DDSPD_* */
-
- union
- {
- void *data;
- IUnknown *object;
- } ptr;
-
- DWORD size;
-};
-
static DWORD resource_access_from_pool(enum wined3d_pool pool)
{
switch (pool)
@@ -116,7 +100,7 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
resource->parent = parent;
resource->parent_ops = parent_ops;
resource->resource_ops = resource_ops;
- list_init(&resource->privateData);
+ wined3d_private_store_init(&resource->private_store);
if (size)
{
@@ -151,9 +135,6 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
void resource_cleanup(struct wined3d_resource *resource)
{
const struct wined3d *d3d = resource->device->wined3d;
- struct private_data *data;
- struct list *e1, *e2;
- HRESULT hr;
TRACE("Cleaning up resource %p.\n", resource);
@@ -163,13 +144,7 @@ void resource_cleanup(struct wined3d_resource *resource)
adapter_adjust_memory(resource->device->adapter, 0 - resource->size);
}
- LIST_FOR_EACH_SAFE(e1, e2, &resource->privateData)
- {
- data = LIST_ENTRY(e1, struct private_data, entry);
- hr = wined3d_resource_free_private_data(resource, &data->tag);
- if (FAILED(hr))
- ERR("Failed to free private data when destroying resource %p, hr = %#x.\n", resource, hr);
- }
+ wined3d_private_store_cleanup(&resource->private_store);
wined3d_resource_free_sysmem(resource);
@@ -185,78 +160,29 @@ void resource_unload(struct wined3d_resource *resource)
resource, resource->type);
}
-static struct private_data *resource_find_private_data(const struct wined3d_resource *resource, REFGUID tag)
-{
- struct private_data *data;
- struct list *entry;
-
- TRACE("Searching for private data %s\n", debugstr_guid(tag));
- LIST_FOR_EACH(entry, &resource->privateData)
- {
- data = LIST_ENTRY(entry, struct private_data, entry);
- if (IsEqualGUID(&data->tag, tag)) {
- TRACE("Found %p\n", data);
- return data;
- }
- }
- TRACE("Not found\n");
- return NULL;
-}
-
HRESULT CDECL wined3d_resource_set_private_data(struct wined3d_resource *resource, REFGUID guid,
const void *data, DWORD data_size, DWORD flags)
{
- struct private_data *d;
-
TRACE("resource %p, riid %s, data %p, data_size %u, flags %#x.\n",
resource, debugstr_guid(guid), data, data_size, flags);
- wined3d_resource_free_private_data(resource, guid);
-
- d = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*d));
- if (!d) return E_OUTOFMEMORY;
-
- d->tag = *guid;
- d->flags = flags;
-
- if (flags & WINED3DSPD_IUNKNOWN)
- {
- if (data_size != sizeof(IUnknown *))
- {
- WARN("IUnknown data with size %u, returning WINED3DERR_INVALIDCALL.\n", data_size);
- HeapFree(GetProcessHeap(), 0, d);
- return WINED3DERR_INVALIDCALL;
- }
- d->ptr.object = (IUnknown *)data;
- d->size = sizeof(IUnknown *);
- IUnknown_AddRef(d->ptr.object);
- }
+ if (wined3d_private_store_set_private_data(&resource->private_store, guid, data, data_size, flags))
+ return WINED3D_OK;
else
- {
- d->ptr.data = HeapAlloc(GetProcessHeap(), 0, data_size);
- if (!d->ptr.data)
- {
- HeapFree(GetProcessHeap(), 0, d);
- return E_OUTOFMEMORY;
- }
- d->size = data_size;
- memcpy(d->ptr.data, data, data_size);
- }
- list_add_tail(&resource->privateData, &d->entry);
-
- return WINED3D_OK;
+ return WINED3DERR_INVALIDCALL;
}
HRESULT CDECL wined3d_resource_get_private_data(const struct wined3d_resource *resource, REFGUID guid,
void *data, DWORD *data_size)
{
- const struct private_data *d;
+ const struct wined3d_private_data *d;
TRACE("resource %p, guid %s, data %p, data_size %p.\n",
resource, debugstr_guid(guid), data, data_size);
- d = resource_find_private_data(resource, guid);
- if (!d) return WINED3DERR_NOTFOUND;
+ d = wined3d_private_store_get_private_data(&resource->private_store, guid);
+ if (!d)
+ return WINED3DERR_NOTFOUND;
if (*data_size < d->size)
{
@@ -266,45 +192,31 @@ HRESULT CDECL wined3d_resource_get_private_data(const struct wined3d_resource *r
if (d->flags & WINED3DSPD_IUNKNOWN)
{
- *(IUnknown **)data = d->ptr.object;
+ *(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->ptr.object);
+ IUnknown_AddRef(d->content.object);
}
}
else
{
- memcpy(data, d->ptr.data, d->size);
+ memcpy(data, d->content.data, d->size);
}
return WINED3D_OK;
}
+
HRESULT CDECL wined3d_resource_free_private_data(struct wined3d_resource *resource, REFGUID guid)
{
- struct private_data *data;
-
TRACE("resource %p, guid %s.\n", resource, debugstr_guid(guid));
- data = resource_find_private_data(resource, guid);
- if (!data) return WINED3DERR_NOTFOUND;
-
- if (data->flags & WINED3DSPD_IUNKNOWN)
- {
- if (data->ptr.object)
- IUnknown_Release(data->ptr.object);
- }
+ if (wined3d_private_store_free_private_data(&resource->private_store, guid))
+ return WINED3D_OK;
else
- {
- HeapFree(GetProcessHeap(), 0, data->ptr.data);
- }
- list_remove(&data->entry);
-
- HeapFree(GetProcessHeap(), 0, data);
-
- return WINED3D_OK;
+ return WINED3DERR_NOTFOUND;
}
DWORD resource_set_priority(struct wined3d_resource *resource, DWORD priority)
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 60088e8..e237517 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -5,7 +5,7 @@
* Copyright 2002-2003 Raphael Junqueira
* Copyright 2002-2003, 2004 Jason Edmeades
* Copyright 2005 Oliver Stieber
- * Copyright 2006-2011, 2013 Stefan Dösinger for CodeWeavers
+ * Copyright 2006-2011, 2013-2014 Stefan Dösinger for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -47,6 +47,7 @@
#include "objbase.h"
#include "wine/wined3d.h"
+#include "wine/wined3d_utils.h"
#include "wined3d_gl.h"
#include "wine/list.h"
#include "wine/rbtree.h"
@@ -2006,8 +2007,8 @@ struct wined3d_resource
UINT size;
DWORD priority;
void *heap_memory;
- struct list privateData;
struct list resource_list_entry;
+ struct wined3d_private_store private_store;
void *parent;
const struct wined3d_parent_ops *parent_ops;
diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h
index 3496c5d..45b265d 100644
--- a/include/wine/wined3d.h
+++ b/include/wine/wined3d.h
@@ -911,9 +911,6 @@ enum wined3d_display_rotation
#define WINED3DSTREAMSOURCE_INDEXEDDATA (1 << 30)
#define WINED3DSTREAMSOURCE_INSTANCEDATA (2 << 30)
-/* SetPrivateData flags */
-#define WINED3DSPD_IUNKNOWN 0x00000001
-
/* IWineD3D::CreateDevice behaviour flags */
#define WINED3DCREATE_FPU_PRESERVE 0x00000002
#define WINED3DCREATE_PUREDEVICE 0x00000010
diff --git a/include/wine/wined3d_utils.h b/include/wine/wined3d_utils.h
new file mode 100644
index 0000000..75dc578
--- /dev/null
+++ b/include/wine/wined3d_utils.h
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2014 Stefan Dösinger for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+#ifndef __WINE_WINED3D_UTILS_H
+#define __WINE_WINED3D_UTILS_H
+
+#define COBJMACROS
+#include "objbase.h"
+#include "wine/list.h"
+
+#define WINED3DSPD_IUNKNOWN 0x00000001
+
+struct wined3d_private_store
+{
+ struct list content;
+};
+
+struct wined3d_private_data
+{
+ struct list entry;
+
+ GUID tag;
+ DWORD flags;
+ union
+ {
+ void *data;
+ IUnknown *object;
+ } content;
+ DWORD size;
+};
+
+
+static inline void wined3d_private_store_init(struct wined3d_private_store *store)
+{
+ list_init(&store->content);
+}
+
+static inline struct wined3d_private_data *wined3d_private_store_get_private_data(
+ const struct wined3d_private_store *store, const GUID *tag)
+{
+ struct wined3d_private_data *data;
+ struct list *entry;
+
+ LIST_FOR_EACH(entry, &store->content)
+ {
+ data = LIST_ENTRY(entry, struct wined3d_private_data, entry);
+ if (IsEqualGUID(&data->tag, tag))
+ return data;
+ }
+ return NULL;
+}
+
+static inline BOOL wined3d_private_store_free_private_data(struct wined3d_private_store *store, const GUID *guid)
+{
+ struct wined3d_private_data *entry;
+
+ entry = wined3d_private_store_get_private_data(store, guid);
+ if (!entry)
+ return FALSE;
+
+ if (entry->flags & WINED3DSPD_IUNKNOWN)
+ IUnknown_Release(entry->content.object);
+ else
+ HeapFree(GetProcessHeap(), 0, entry->content.data);
+
+ list_remove(&entry->entry);
+ HeapFree(GetProcessHeap(), 0, entry);
+
+ return TRUE;
+}
+
+static inline void wined3d_private_store_cleanup(struct wined3d_private_store *store)
+{
+ struct wined3d_private_data *data;
+ struct list *e1, *e2;
+
+ LIST_FOR_EACH_SAFE(e1, e2, &store->content)
+ {
+ data = LIST_ENTRY(e1, struct wined3d_private_data, entry);
+ wined3d_private_store_free_private_data(store, &data->tag);
+ }
+}
+
+static inline BOOL wined3d_private_store_set_private_data(struct wined3d_private_store *store,
+ const GUID *guid, const void *data, DWORD data_size, DWORD flags)
+{
+ struct wined3d_private_data *entry;
+
+ wined3d_private_store_free_private_data(store, guid);
+
+ entry = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*entry));
+ if (!entry)
+ return FALSE;
+
+ entry->tag = *guid;
+ entry->flags = flags;
+ entry->size = data_size;
+
+ if (flags & WINED3DSPD_IUNKNOWN)
+ {
+ if (data_size != sizeof(IUnknown *))
+ {
+ HeapFree(GetProcessHeap(), 0, entry);
+ return FALSE;
+ }
+ entry->content.object = (IUnknown *)data;
+ IUnknown_AddRef(entry->content.object);
+ }
+ else
+ {
+ entry->content.data = HeapAlloc(GetProcessHeap(), 0, data_size);
+ if (!entry->content.data)
+ {
+ HeapFree(GetProcessHeap(), 0, entry);
+ return E_OUTOFMEMORY;
+ }
+ memcpy(entry->content.data, data, data_size);
+ }
+ list_add_tail(&store->content, &entry->entry);
+
+ return TRUE;
+}
+
+#endif
--
1.8.3.2
More information about the wine-patches
mailing list