wined3d: Merge the texture cleanup functions.

This commit is contained in:
Henri Verbeet 2011-03-17 23:15:12 +01:00 committed by Alexandre Julliard
parent d30d9d5e49
commit 96a8417a21
5 changed files with 58 additions and 87 deletions

View File

@ -78,6 +78,19 @@ HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, const struct wined3d_
void basetexture_cleanup(IWineD3DBaseTextureImpl *texture)
{
UINT sub_count = texture->baseTexture.level_count * texture->baseTexture.layer_count;
UINT i;
TRACE("texture %p.\n", texture);
for (i = 0; i < sub_count; ++i)
{
struct wined3d_resource *sub_resource = texture->baseTexture.sub_resources[i];
if (sub_resource)
texture->baseTexture.texture_ops->texture_sub_resource_cleanup(sub_resource);
}
basetexture_unload(texture);
HeapFree(GetProcessHeap(), 0, texture->baseTexture.sub_resources);
resource_cleanup(&texture->resource);

View File

@ -141,6 +141,19 @@ static void cubetexture_sub_resource_add_dirty_region(struct wined3d_resource *s
surface_add_dirty_rect(surface_from_resource(sub_resource), dirty_region);
}
static void cubetexture_sub_resource_cleanup(struct wined3d_resource *sub_resource)
{
IWineD3DSurfaceImpl *surface = surface_from_resource(sub_resource);
/* Clean out the texture name we gave to the surface so that the
* surface doesn't try and release it. */
surface_set_texture_name(surface, 0, TRUE);
surface_set_texture_name(surface, 0, FALSE);
surface_set_texture_target(surface, 0);
surface_set_container(surface, WINED3D_CONTAINER_NONE, NULL);
IWineD3DSurface_Release((IWineD3DSurface *)surface);
}
/* Do not call while under the GL lock. */
static void cubetexture_unload(struct wined3d_resource *resource)
{
@ -168,6 +181,7 @@ static const struct wined3d_texture_ops cubetexture_ops =
cubetexture_bind,
cubetexture_preload,
cubetexture_sub_resource_add_dirty_region,
cubetexture_sub_resource_cleanup,
};
static const struct wined3d_resource_ops cubetexture_resource_ops =
@ -175,33 +189,6 @@ static const struct wined3d_resource_ops cubetexture_resource_ops =
cubetexture_unload,
};
static void cubetexture_cleanup(IWineD3DBaseTextureImpl *This)
{
UINT sub_count = This->baseTexture.level_count * This->baseTexture.layer_count;
UINT i;
TRACE("(%p) : Cleaning up.\n", This);
for (i = 0; i < sub_count; ++i)
{
struct wined3d_resource *sub_resource = This->baseTexture.sub_resources[i];
if (sub_resource)
{
IWineD3DSurfaceImpl *surface = surface_from_resource(sub_resource);
/* Clean out the texture name we gave to the surface so that the
* surface doesn't try and release it. */
surface_set_texture_name(surface, 0, TRUE);
surface_set_texture_name(surface, 0, FALSE);
surface_set_texture_target(surface, 0);
surface_set_container(surface, WINED3D_CONTAINER_NONE, NULL);
IWineD3DSurface_Release((IWineD3DSurface *)surface);
}
}
basetexture_cleanup((IWineD3DBaseTextureImpl *)This);
}
static HRESULT WINAPI IWineD3DCubeTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, LPVOID *ppobj)
{
IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
@ -235,7 +222,7 @@ static ULONG WINAPI IWineD3DCubeTextureImpl_Release(IWineD3DBaseTexture *iface)
ref = InterlockedDecrement(&This->resource.ref);
if (!ref)
{
cubetexture_cleanup(This);
basetexture_cleanup(This);
This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
HeapFree(GetProcessHeap(), 0, This);
}
@ -466,7 +453,7 @@ HRESULT cubetexture_init(IWineD3DBaseTextureImpl *texture, UINT edge_length, UIN
if (FAILED(hr))
{
FIXME("(%p) Failed to create surface, hr %#x.\n", texture, hr);
cubetexture_cleanup(texture);
basetexture_cleanup(texture);
return hr;
}

View File

@ -165,6 +165,19 @@ static void texture_sub_resource_add_dirty_region(struct wined3d_resource *sub_r
surface_add_dirty_rect(surface_from_resource(sub_resource), dirty_region);
}
static void texture_sub_resource_cleanup(struct wined3d_resource *sub_resource)
{
IWineD3DSurfaceImpl *surface = surface_from_resource(sub_resource);
/* Clean out the texture name we gave to the surface so that the
* surface doesn't try and release it */
surface_set_texture_name(surface, 0, TRUE);
surface_set_texture_name(surface, 0, FALSE);
surface_set_texture_target(surface, 0);
surface_set_container(surface, WINED3D_CONTAINER_NONE, NULL);
IWineD3DSurface_Release((IWineD3DSurface *)surface);
}
/* Do not call while under the GL lock. */
static void texture_unload(struct wined3d_resource *resource)
{
@ -191,6 +204,7 @@ static const struct wined3d_texture_ops texture_ops =
texture_bind,
texture_preload,
texture_sub_resource_add_dirty_region,
texture_sub_resource_cleanup,
};
static const struct wined3d_resource_ops texture_resource_ops =
@ -198,34 +212,6 @@ static const struct wined3d_resource_ops texture_resource_ops =
texture_unload,
};
static void texture_cleanup(IWineD3DBaseTextureImpl *This)
{
unsigned int i;
TRACE("(%p) : Cleaning up\n", This);
for (i = 0; i < This->baseTexture.level_count; ++i)
{
struct wined3d_resource *sub_resource = This->baseTexture.sub_resources[i];
if (sub_resource)
{
IWineD3DSurfaceImpl *surface = surface_from_resource(sub_resource);
/* Clean out the texture name we gave to the surface so that the
* surface doesn't try and release it */
surface_set_texture_name(surface, 0, TRUE);
surface_set_texture_name(surface, 0, FALSE);
surface_set_texture_target(surface, 0);
surface_set_container(surface, WINED3D_CONTAINER_NONE, NULL);
IWineD3DSurface_Release((IWineD3DSurface *)surface);
}
}
TRACE("(%p) : Cleaning up base texture\n", This);
basetexture_cleanup((IWineD3DBaseTextureImpl *)This);
}
static HRESULT WINAPI IWineD3DTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, LPVOID *ppobj)
{
IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
@ -259,7 +245,7 @@ static ULONG WINAPI IWineD3DTextureImpl_Release(IWineD3DBaseTexture *iface)
ref = InterlockedDecrement(&This->resource.ref);
if (!ref)
{
texture_cleanup(This);
basetexture_cleanup(This);
This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
HeapFree(GetProcessHeap(), 0, This);
}
@ -531,7 +517,7 @@ HRESULT texture_init(IWineD3DBaseTextureImpl *texture, UINT width, UINT height,
if (FAILED(hr))
{
FIXME("Failed to create surface %p, hr %#x\n", texture, hr);
texture_cleanup(texture);
basetexture_cleanup(texture);
return hr;
}

View File

@ -89,6 +89,15 @@ static void volumetexture_sub_resource_add_dirty_region(struct wined3d_resource
volume_add_dirty_box(volume_from_resource(sub_resource), dirty_region);
}
static void volumetexture_sub_resource_cleanup(struct wined3d_resource *sub_resource)
{
IWineD3DVolumeImpl *volume = volume_from_resource(sub_resource);
/* Cleanup the container. */
volume_set_container(volume, NULL);
IWineD3DVolume_Release((IWineD3DVolume *)volume);
}
/* Do not call while under the GL lock. */
static void volumetexture_unload(struct wined3d_resource *resource)
{
@ -111,6 +120,7 @@ static const struct wined3d_texture_ops volumetexture_ops =
volumetexture_bind,
volumetexture_preload,
volumetexture_sub_resource_add_dirty_region,
volumetexture_sub_resource_cleanup,
};
static const struct wined3d_resource_ops volumetexture_resource_ops =
@ -118,32 +128,6 @@ static const struct wined3d_resource_ops volumetexture_resource_ops =
volumetexture_unload,
};
static void volumetexture_cleanup(IWineD3DBaseTextureImpl *This)
{
unsigned int i;
TRACE("(%p) : Cleaning up.\n", This);
for (i = 0; i < This->baseTexture.level_count; ++i)
{
struct wined3d_resource *sub_resource = This->baseTexture.sub_resources[i];
if (sub_resource)
{
IWineD3DVolumeImpl *volume = volume_from_resource(sub_resource);
/* Cleanup the container. */
volume_set_container(volume, NULL);
IWineD3DVolume_Release((IWineD3DVolume *)volume);
}
}
basetexture_cleanup((IWineD3DBaseTextureImpl *)This);
}
/* *******************************************
IWineD3DTexture IUnknown parts follow
******************************************* */
static HRESULT WINAPI IWineD3DVolumeTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, LPVOID *ppobj)
{
IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
@ -177,7 +161,7 @@ static ULONG WINAPI IWineD3DVolumeTextureImpl_Release(IWineD3DBaseTexture *iface
ref = InterlockedDecrement(&This->resource.ref);
if (!ref)
{
volumetexture_cleanup(This);
basetexture_cleanup(This);
This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
HeapFree(GetProcessHeap(), 0, This);
}
@ -381,7 +365,7 @@ HRESULT volumetexture_init(IWineD3DBaseTextureImpl *texture, UINT width, UINT he
if (FAILED(hr))
{
ERR("Creating a volume for the volume texture failed, hr %#x.\n", hr);
volumetexture_cleanup(texture);
basetexture_cleanup(texture);
return hr;
}

View File

@ -1890,6 +1890,7 @@ struct wined3d_texture_ops
void (*texture_preload)(struct IWineD3DBaseTextureImpl *texture, enum WINED3DSRGB srgb);
void (*texture_sub_resource_add_dirty_region)(struct wined3d_resource *sub_resource,
const WINED3DBOX *dirty_region);
void (*texture_sub_resource_cleanup)(struct wined3d_resource *sub_resource);
};
typedef struct IWineD3DBaseTextureClass