Commit d1e44ff7 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Pass a resource to wined3d_resource_free_sysmem().

parent 261246ef
...@@ -198,9 +198,8 @@ static void buffer_create_buffer_object(struct wined3d_buffer *This, struct wine ...@@ -198,9 +198,8 @@ static void buffer_create_buffer_object(struct wined3d_buffer *This, struct wine
} }
else else
{ {
wined3d_resource_free_sysmem(This->resource.heap_memory); wined3d_resource_free_sysmem(&This->resource);
This->resource.allocatedMemory = NULL; This->resource.allocatedMemory = NULL;
This->resource.heap_memory = NULL;
} }
return; return;
......
...@@ -138,7 +138,7 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device * ...@@ -138,7 +138,7 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
if (size > wined3d_device_get_available_texture_mem(device)) if (size > wined3d_device_get_available_texture_mem(device))
{ {
ERR("Out of adapter memory\n"); ERR("Out of adapter memory\n");
wined3d_resource_free_sysmem(resource->heap_memory); wined3d_resource_free_sysmem(resource);
return WINED3DERR_OUTOFVIDEOMEMORY; return WINED3DERR_OUTOFVIDEOMEMORY;
} }
adapter_adjust_memory(device->adapter, size); adapter_adjust_memory(device->adapter, size);
...@@ -172,9 +172,8 @@ void resource_cleanup(struct wined3d_resource *resource) ...@@ -172,9 +172,8 @@ void resource_cleanup(struct wined3d_resource *resource)
ERR("Failed to free private data when destroying resource %p, hr = %#x.\n", resource, hr); ERR("Failed to free private data when destroying resource %p, hr = %#x.\n", resource, hr);
} }
wined3d_resource_free_sysmem(resource->heap_memory); wined3d_resource_free_sysmem(resource);
resource->allocatedMemory = NULL; resource->allocatedMemory = NULL;
resource->heap_memory = NULL;
device_resource_released(resource->device, resource); device_resource_released(resource->device, resource);
} }
...@@ -360,14 +359,15 @@ BOOL wined3d_resource_allocate_sysmem(struct wined3d_resource *resource) ...@@ -360,14 +359,15 @@ BOOL wined3d_resource_allocate_sysmem(struct wined3d_resource *resource)
return TRUE; return TRUE;
} }
void wined3d_resource_free_sysmem(void *mem) void wined3d_resource_free_sysmem(struct wined3d_resource *resource)
{ {
void **p = mem; void **p = resource->heap_memory;
if (!mem) if (!p)
return; return;
HeapFree(GetProcessHeap(), 0, *(--p)); HeapFree(GetProcessHeap(), 0, *(--p));
resource->heap_memory = NULL;
} }
DWORD wined3d_resource_sanitize_map_flags(const struct wined3d_resource *resource, DWORD flags) DWORD wined3d_resource_sanitize_map_flags(const struct wined3d_resource *resource, DWORD flags)
......
...@@ -566,10 +566,7 @@ static void surface_load_pbo(struct wined3d_surface *surface, const struct wined ...@@ -566,10 +566,7 @@ static void surface_load_pbo(struct wined3d_surface *surface, const struct wined
/* We don't need the system memory anymore and we can't even use it for PBOs. */ /* We don't need the system memory anymore and we can't even use it for PBOs. */
if (!(surface->flags & SFLAG_CLIENT)) if (!(surface->flags & SFLAG_CLIENT))
{ wined3d_resource_free_sysmem(&surface->resource);
wined3d_resource_free_sysmem(surface->resource.heap_memory);
surface->resource.heap_memory = NULL;
}
surface->resource.allocatedMemory = NULL; surface->resource.allocatedMemory = NULL;
surface->flags |= SFLAG_PBO; surface->flags |= SFLAG_PBO;
context_release(context); context_release(context);
...@@ -601,9 +598,8 @@ static void surface_evict_sysmem(struct wined3d_surface *surface) ...@@ -601,9 +598,8 @@ static void surface_evict_sysmem(struct wined3d_surface *surface)
if (surface->resource.map_count || (surface->flags & SFLAG_DONOTFREE)) if (surface->resource.map_count || (surface->flags & SFLAG_DONOTFREE))
return; return;
wined3d_resource_free_sysmem(surface->resource.heap_memory); wined3d_resource_free_sysmem(&surface->resource);
surface->resource.allocatedMemory = NULL; surface->resource.allocatedMemory = NULL;
surface->resource.heap_memory = NULL;
surface_invalidate_location(surface, SFLAG_INSYSMEM); surface_invalidate_location(surface, SFLAG_INSYSMEM);
} }
...@@ -1611,8 +1607,7 @@ static HRESULT gdi_surface_private_setup(struct wined3d_surface *surface) ...@@ -1611,8 +1607,7 @@ static HRESULT gdi_surface_private_setup(struct wined3d_surface *surface)
hr = surface_create_dib_section(surface); hr = surface_create_dib_section(surface);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
wined3d_resource_free_sysmem(surface->resource.heap_memory); wined3d_resource_free_sysmem(&surface->resource);
surface->resource.heap_memory = NULL;
surface->resource.allocatedMemory = surface->dib.bitmap_data; surface->resource.allocatedMemory = surface->dib.bitmap_data;
} }
...@@ -1671,8 +1666,7 @@ static void gdi_surface_map(struct wined3d_surface *surface, const RECT *rect, D ...@@ -1671,8 +1666,7 @@ static void gdi_surface_map(struct wined3d_surface *surface, const RECT *rect, D
ERR("Failed to create dib section, hr %#x.\n", hr); ERR("Failed to create dib section, hr %#x.\n", hr);
return; return;
} }
wined3d_resource_free_sysmem(surface->resource.heap_memory); wined3d_resource_free_sysmem(&surface->resource);
surface->resource.heap_memory = NULL;
surface->resource.allocatedMemory = surface->dib.bitmap_data; surface->resource.allocatedMemory = surface->dib.bitmap_data;
} }
} }
...@@ -2867,8 +2861,6 @@ HRESULT CDECL wined3d_surface_set_mem(struct wined3d_surface *surface, void *mem ...@@ -2867,8 +2861,6 @@ HRESULT CDECL wined3d_surface_set_mem(struct wined3d_surface *surface, void *mem
if (mem && mem != surface->resource.allocatedMemory) if (mem && mem != surface->resource.allocatedMemory)
{ {
void *release = NULL;
/* Do I have to copy the old surface content? */ /* Do I have to copy the old surface content? */
if (surface->flags & SFLAG_DIBSECTION) if (surface->flags & SFLAG_DIBSECTION)
{ {
...@@ -2881,8 +2873,7 @@ HRESULT CDECL wined3d_surface_set_mem(struct wined3d_surface *surface, void *mem ...@@ -2881,8 +2873,7 @@ HRESULT CDECL wined3d_surface_set_mem(struct wined3d_surface *surface, void *mem
} }
else if (!(surface->flags & SFLAG_USERPTR)) else if (!(surface->flags & SFLAG_USERPTR))
{ {
release = surface->resource.heap_memory; wined3d_resource_free_sysmem(&surface->resource);
surface->resource.heap_memory = NULL;
} }
surface->resource.allocatedMemory = mem; surface->resource.allocatedMemory = mem;
surface->flags |= SFLAG_USERPTR; surface->flags |= SFLAG_USERPTR;
...@@ -2894,9 +2885,6 @@ HRESULT CDECL wined3d_surface_set_mem(struct wined3d_surface *surface, void *mem ...@@ -2894,9 +2885,6 @@ HRESULT CDECL wined3d_surface_set_mem(struct wined3d_surface *surface, void *mem
/* For client textures OpenGL has to be notified. */ /* For client textures OpenGL has to be notified. */
if (surface->flags & SFLAG_CLIENT) if (surface->flags & SFLAG_CLIENT)
surface_release_client_storage(surface); surface_release_client_storage(surface);
/* Now free the old memory if any. */
wined3d_resource_free_sysmem(release);
} }
else if (surface->flags & SFLAG_USERPTR) else if (surface->flags & SFLAG_USERPTR)
{ {
...@@ -3086,8 +3074,7 @@ HRESULT CDECL wined3d_surface_update_desc(struct wined3d_surface *surface, ...@@ -3086,8 +3074,7 @@ HRESULT CDECL wined3d_surface_update_desc(struct wined3d_surface *surface,
surface->flags &= ~(SFLAG_LOCATIONS | SFLAG_USERPTR); surface->flags &= ~(SFLAG_LOCATIONS | SFLAG_USERPTR);
surface->resource.allocatedMemory = NULL; surface->resource.allocatedMemory = NULL;
wined3d_resource_free_sysmem(surface->resource.heap_memory); wined3d_resource_free_sysmem(&surface->resource);
surface->resource.heap_memory = NULL;
surface->resource.width = width; surface->resource.width = width;
surface->resource.height = height; surface->resource.height = height;
...@@ -3583,8 +3570,7 @@ HRESULT CDECL wined3d_surface_getdc(struct wined3d_surface *surface, HDC *dc) ...@@ -3583,8 +3570,7 @@ HRESULT CDECL wined3d_surface_getdc(struct wined3d_surface *surface, HDC *dc)
/* Use the DIB section from now on if we are not using a PBO. */ /* Use the DIB section from now on if we are not using a PBO. */
if (!(surface->flags & (SFLAG_PBO | SFLAG_PIN_SYSMEM))) if (!(surface->flags & (SFLAG_PBO | SFLAG_PIN_SYSMEM)))
{ {
wined3d_resource_free_sysmem(surface->resource.heap_memory); wined3d_resource_free_sysmem(&surface->resource);
surface->resource.heap_memory = NULL;
surface->resource.allocatedMemory = surface->dib.bitmap_data; surface->resource.allocatedMemory = surface->dib.bitmap_data;
} }
} }
...@@ -5004,9 +4990,8 @@ static HRESULT surface_blt_special(struct wined3d_surface *dst_surface, const RE ...@@ -5004,9 +4990,8 @@ static HRESULT surface_blt_special(struct wined3d_surface *dst_surface, const RE
if (!dst_surface->resource.map_count && !(dst_surface->flags & SFLAG_DONOTFREE)) if (!dst_surface->resource.map_count && !(dst_surface->flags & SFLAG_DONOTFREE))
{ {
wined3d_resource_free_sysmem(dst_surface->resource.heap_memory); wined3d_resource_free_sysmem(&dst_surface->resource);
dst_surface->resource.allocatedMemory = NULL; dst_surface->resource.allocatedMemory = NULL;
dst_surface->resource.heap_memory = NULL;
} }
else else
{ {
...@@ -6933,8 +6918,7 @@ static HRESULT surface_init(struct wined3d_surface *surface, UINT alignment, UIN ...@@ -6933,8 +6918,7 @@ static HRESULT surface_init(struct wined3d_surface *surface, UINT alignment, UIN
if ((usage & WINED3DUSAGE_OWNDC) && !surface->hDC if ((usage & WINED3DUSAGE_OWNDC) && !surface->hDC
&& SUCCEEDED(surface_create_dib_section(surface))) && SUCCEEDED(surface_create_dib_section(surface)))
{ {
wined3d_resource_free_sysmem(surface->resource.heap_memory); wined3d_resource_free_sysmem(&surface->resource);
surface->resource.heap_memory = NULL;
surface->resource.allocatedMemory = surface->dib.bitmap_data; surface->resource.allocatedMemory = surface->dib.bitmap_data;
} }
......
...@@ -142,8 +142,7 @@ static void wined3d_volume_download_data(struct wined3d_volume *volume, ...@@ -142,8 +142,7 @@ static void wined3d_volume_download_data(struct wined3d_volume *volume,
static void wined3d_volume_evict_sysmem(struct wined3d_volume *volume) static void wined3d_volume_evict_sysmem(struct wined3d_volume *volume)
{ {
wined3d_resource_free_sysmem(volume->resource.heap_memory); wined3d_resource_free_sysmem(&volume->resource);
volume->resource.heap_memory = NULL;
volume->resource.allocatedMemory = NULL; volume->resource.allocatedMemory = NULL;
wined3d_volume_invalidate_location(volume, WINED3D_LOCATION_SYSMEM); wined3d_volume_invalidate_location(volume, WINED3D_LOCATION_SYSMEM);
} }
...@@ -702,8 +701,7 @@ static HRESULT volume_init(struct wined3d_volume *volume, struct wined3d_device ...@@ -702,8 +701,7 @@ static HRESULT volume_init(struct wined3d_volume *volume, struct wined3d_device
if (pool == WINED3D_POOL_DEFAULT && usage & WINED3DUSAGE_DYNAMIC if (pool == WINED3D_POOL_DEFAULT && usage & WINED3DUSAGE_DYNAMIC
&& gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]) && gl_info->supported[ARB_PIXEL_BUFFER_OBJECT])
{ {
wined3d_resource_free_sysmem(volume->resource.heap_memory); wined3d_resource_free_sysmem(&volume->resource);
volume->resource.heap_memory = NULL;
volume->resource.allocatedMemory = NULL; volume->resource.allocatedMemory = NULL;
volume->flags |= WINED3D_VFLAG_PBO; volume->flags |= WINED3D_VFLAG_PBO;
} }
......
...@@ -1984,8 +1984,6 @@ struct wined3d_resource_ops ...@@ -1984,8 +1984,6 @@ struct wined3d_resource_ops
void (*resource_unload)(struct wined3d_resource *resource); void (*resource_unload)(struct wined3d_resource *resource);
}; };
void wined3d_resource_free_sysmem(void *mem) DECLSPEC_HIDDEN;
struct wined3d_resource struct wined3d_resource
{ {
LONG ref; LONG ref;
...@@ -2025,6 +2023,7 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device * ...@@ -2025,6 +2023,7 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
DWORD resource_set_priority(struct wined3d_resource *resource, DWORD priority) DECLSPEC_HIDDEN; DWORD resource_set_priority(struct wined3d_resource *resource, DWORD priority) DECLSPEC_HIDDEN;
void resource_unload(struct wined3d_resource *resource) DECLSPEC_HIDDEN; void resource_unload(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
BOOL wined3d_resource_allocate_sysmem(struct wined3d_resource *resource) DECLSPEC_HIDDEN; BOOL wined3d_resource_allocate_sysmem(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
void wined3d_resource_free_sysmem(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
DWORD wined3d_resource_sanitize_map_flags(const struct wined3d_resource *resource, DWORD wined3d_resource_sanitize_map_flags(const struct wined3d_resource *resource,
DWORD flags) DECLSPEC_HIDDEN; DWORD flags) DECLSPEC_HIDDEN;
GLbitfield wined3d_resource_gl_map_flags(DWORD d3d_flags) DECLSPEC_HIDDEN; GLbitfield wined3d_resource_gl_map_flags(DWORD d3d_flags) DECLSPEC_HIDDEN;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment