Henri Verbeet : wined3d: Pass a resource to wined3d_resource_allocate_sysmem().
Alexandre Julliard
julliard at winehq.org
Mon Sep 16 16:57:22 CDT 2013
Module: wine
Branch: master
Commit: 261246ef21d285727fc2da69fb223b649d56d142
URL: http://source.winehq.org/git/wine.git/?a=commit;h=261246ef21d285727fc2da69fb223b649d56d142
Author: Henri Verbeet <hverbeet at codeweavers.com>
Date: Mon Sep 16 10:57:24 2013 +0200
wined3d: Pass a resource to wined3d_resource_allocate_sysmem().
---
dlls/wined3d/buffer.c | 3 ++-
dlls/wined3d/resource.c | 17 +++++++++--------
dlls/wined3d/surface.c | 11 +++++------
dlls/wined3d/volume.c | 6 ++++--
dlls/wined3d/wined3d_private.h | 2 +-
5 files changed, 21 insertions(+), 18 deletions(-)
diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c
index 2deb7d2..b61c3ce 100644
--- a/dlls/wined3d/buffer.c
+++ b/dlls/wined3d/buffer.c
@@ -500,7 +500,8 @@ BYTE *buffer_get_sysmem(struct wined3d_buffer *This, struct wined3d_context *con
/* AllocatedMemory exists if the buffer is double buffered or has no buffer object at all */
if(This->resource.allocatedMemory) return This->resource.allocatedMemory;
- This->resource.heap_memory = wined3d_resource_allocate_sysmem(This->resource.size);
+ if (!wined3d_resource_allocate_sysmem(&This->resource))
+ ERR("Failed to allocate system memory.\n");
This->resource.allocatedMemory = This->resource.heap_memory;
if (This->buffer_type_hint == GL_ELEMENT_ARRAY_BUFFER_ARB)
diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c
index a677d00..78f35e9 100644
--- a/dlls/wined3d/resource.c
+++ b/dlls/wined3d/resource.c
@@ -120,11 +120,10 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
if (size)
{
- resource->heap_memory = wined3d_resource_allocate_sysmem(size);
- if (!resource->heap_memory)
+ if (!wined3d_resource_allocate_sysmem(resource))
{
- ERR("Out of memory!\n");
- return WINED3DERR_OUTOFVIDEOMEMORY;
+ ERR("Failed to allocate system memory.\n");
+ return E_OUTOFMEMORY;
}
}
else
@@ -344,19 +343,21 @@ void CDECL wined3d_resource_get_desc(const struct wined3d_resource *resource, st
desc->size = resource->size;
}
-void *wined3d_resource_allocate_sysmem(SIZE_T size)
+BOOL wined3d_resource_allocate_sysmem(struct wined3d_resource *resource)
{
void **p;
SIZE_T align = RESOURCE_ALIGNMENT - 1 + sizeof(*p);
void *mem;
- if (!(mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + align)))
- return NULL;
+ if (!(mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, resource->size + align)))
+ return FALSE;
p = (void **)(((ULONG_PTR)mem + align) & ~(RESOURCE_ALIGNMENT - 1)) - 1;
*p = mem;
- return ++p;
+ resource->heap_memory = ++p;
+
+ return TRUE;
}
void wined3d_resource_free_sysmem(void *mem)
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index b64c8e9..e40a65a 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -587,9 +587,8 @@ static void surface_prepare_system_memory(struct wined3d_surface *surface)
{
/* Whatever surface we have, make sure that there is memory allocated
* for the downloaded copy, or a PBO to map. */
- if (!surface->resource.heap_memory)
- surface->resource.heap_memory = wined3d_resource_allocate_sysmem(surface->resource.size);
-
+ if (!surface->resource.heap_memory && !wined3d_resource_allocate_sysmem(&surface->resource))
+ ERR("Failed to allocate system memory.\n");
surface->resource.allocatedMemory = surface->resource.heap_memory;
if (surface->flags & SFLAG_INSYSMEM)
@@ -1432,7 +1431,7 @@ static void surface_remove_pbo(struct wined3d_surface *surface, const struct win
else
{
if (!surface->resource.heap_memory)
- surface->resource.heap_memory = wined3d_resource_allocate_sysmem(surface->resource.size);
+ wined3d_resource_allocate_sysmem(&surface->resource);
else if (!(surface->flags & SFLAG_CLIENT))
ERR("Surface %p has heap_memory %p and flags %#x.\n",
surface, surface->resource.heap_memory, surface->flags);
@@ -1458,9 +1457,9 @@ static BOOL surface_init_sysmem(struct wined3d_surface *surface)
{
if (!surface->resource.heap_memory)
{
- if (!(surface->resource.heap_memory = wined3d_resource_allocate_sysmem(surface->resource.size)))
+ if (!wined3d_resource_allocate_sysmem(&surface->resource))
{
- ERR("Failed to allocate memory.\n");
+ ERR("Failed to allocate system memory.\n");
return FALSE;
}
}
diff --git a/dlls/wined3d/volume.c b/dlls/wined3d/volume.c
index 7f2dbf9..62c6ab9 100644
--- a/dlls/wined3d/volume.c
+++ b/dlls/wined3d/volume.c
@@ -391,9 +391,11 @@ static BOOL volume_prepare_system_memory(struct wined3d_volume *volume)
if (volume->resource.allocatedMemory)
return TRUE;
- volume->resource.heap_memory = wined3d_resource_allocate_sysmem(volume->resource.size);
- if (!volume->resource.heap_memory)
+ if (!wined3d_resource_allocate_sysmem(&volume->resource))
+ {
+ ERR("Failed to allocate system memory.\n");
return FALSE;
+ }
volume->resource.allocatedMemory = volume->resource.heap_memory;
return TRUE;
}
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index a30db57..cbf6e78 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -1984,7 +1984,6 @@ struct wined3d_resource_ops
void (*resource_unload)(struct wined3d_resource *resource);
};
-void *wined3d_resource_allocate_sysmem(SIZE_T size) DECLSPEC_HIDDEN;
void wined3d_resource_free_sysmem(void *mem) DECLSPEC_HIDDEN;
struct wined3d_resource
@@ -2025,6 +2024,7 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
const struct wined3d_resource_ops *resource_ops) DECLSPEC_HIDDEN;
DWORD resource_set_priority(struct wined3d_resource *resource, DWORD priority) DECLSPEC_HIDDEN;
void resource_unload(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
+BOOL wined3d_resource_allocate_sysmem(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
DWORD wined3d_resource_sanitize_map_flags(const struct wined3d_resource *resource,
DWORD flags) DECLSPEC_HIDDEN;
GLbitfield wined3d_resource_gl_map_flags(DWORD d3d_flags) DECLSPEC_HIDDEN;
More information about the wine-cvs
mailing list