Commit 96a8417a authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Merge the texture cleanup functions.

parent d30d9d5e
...@@ -78,6 +78,19 @@ HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, const struct wined3d_ ...@@ -78,6 +78,19 @@ HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, const struct wined3d_
void basetexture_cleanup(IWineD3DBaseTextureImpl *texture) 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); basetexture_unload(texture);
HeapFree(GetProcessHeap(), 0, texture->baseTexture.sub_resources); HeapFree(GetProcessHeap(), 0, texture->baseTexture.sub_resources);
resource_cleanup(&texture->resource); resource_cleanup(&texture->resource);
......
...@@ -141,6 +141,19 @@ static void cubetexture_sub_resource_add_dirty_region(struct wined3d_resource *s ...@@ -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); 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. */ /* Do not call while under the GL lock. */
static void cubetexture_unload(struct wined3d_resource *resource) static void cubetexture_unload(struct wined3d_resource *resource)
{ {
...@@ -168,6 +181,7 @@ static const struct wined3d_texture_ops cubetexture_ops = ...@@ -168,6 +181,7 @@ static const struct wined3d_texture_ops cubetexture_ops =
cubetexture_bind, cubetexture_bind,
cubetexture_preload, cubetexture_preload,
cubetexture_sub_resource_add_dirty_region, cubetexture_sub_resource_add_dirty_region,
cubetexture_sub_resource_cleanup,
}; };
static const struct wined3d_resource_ops cubetexture_resource_ops = static const struct wined3d_resource_ops cubetexture_resource_ops =
...@@ -175,33 +189,6 @@ static const struct wined3d_resource_ops cubetexture_resource_ops = ...@@ -175,33 +189,6 @@ static const struct wined3d_resource_ops cubetexture_resource_ops =
cubetexture_unload, 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) static HRESULT WINAPI IWineD3DCubeTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, LPVOID *ppobj)
{ {
IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface; IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
...@@ -235,7 +222,7 @@ static ULONG WINAPI IWineD3DCubeTextureImpl_Release(IWineD3DBaseTexture *iface) ...@@ -235,7 +222,7 @@ static ULONG WINAPI IWineD3DCubeTextureImpl_Release(IWineD3DBaseTexture *iface)
ref = InterlockedDecrement(&This->resource.ref); ref = InterlockedDecrement(&This->resource.ref);
if (!ref) if (!ref)
{ {
cubetexture_cleanup(This); basetexture_cleanup(This);
This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent); This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
HeapFree(GetProcessHeap(), 0, This); HeapFree(GetProcessHeap(), 0, This);
} }
...@@ -466,7 +453,7 @@ HRESULT cubetexture_init(IWineD3DBaseTextureImpl *texture, UINT edge_length, UIN ...@@ -466,7 +453,7 @@ HRESULT cubetexture_init(IWineD3DBaseTextureImpl *texture, UINT edge_length, UIN
if (FAILED(hr)) if (FAILED(hr))
{ {
FIXME("(%p) Failed to create surface, hr %#x.\n", texture, hr); FIXME("(%p) Failed to create surface, hr %#x.\n", texture, hr);
cubetexture_cleanup(texture); basetexture_cleanup(texture);
return hr; return hr;
} }
......
...@@ -165,6 +165,19 @@ static void texture_sub_resource_add_dirty_region(struct wined3d_resource *sub_r ...@@ -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); 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. */ /* Do not call while under the GL lock. */
static void texture_unload(struct wined3d_resource *resource) static void texture_unload(struct wined3d_resource *resource)
{ {
...@@ -191,6 +204,7 @@ static const struct wined3d_texture_ops texture_ops = ...@@ -191,6 +204,7 @@ static const struct wined3d_texture_ops texture_ops =
texture_bind, texture_bind,
texture_preload, texture_preload,
texture_sub_resource_add_dirty_region, texture_sub_resource_add_dirty_region,
texture_sub_resource_cleanup,
}; };
static const struct wined3d_resource_ops texture_resource_ops = static const struct wined3d_resource_ops texture_resource_ops =
...@@ -198,34 +212,6 @@ static const struct wined3d_resource_ops texture_resource_ops = ...@@ -198,34 +212,6 @@ static const struct wined3d_resource_ops texture_resource_ops =
texture_unload, 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) static HRESULT WINAPI IWineD3DTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, LPVOID *ppobj)
{ {
IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface; IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
...@@ -259,7 +245,7 @@ static ULONG WINAPI IWineD3DTextureImpl_Release(IWineD3DBaseTexture *iface) ...@@ -259,7 +245,7 @@ static ULONG WINAPI IWineD3DTextureImpl_Release(IWineD3DBaseTexture *iface)
ref = InterlockedDecrement(&This->resource.ref); ref = InterlockedDecrement(&This->resource.ref);
if (!ref) if (!ref)
{ {
texture_cleanup(This); basetexture_cleanup(This);
This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent); This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
HeapFree(GetProcessHeap(), 0, This); HeapFree(GetProcessHeap(), 0, This);
} }
...@@ -531,7 +517,7 @@ HRESULT texture_init(IWineD3DBaseTextureImpl *texture, UINT width, UINT height, ...@@ -531,7 +517,7 @@ HRESULT texture_init(IWineD3DBaseTextureImpl *texture, UINT width, UINT height,
if (FAILED(hr)) if (FAILED(hr))
{ {
FIXME("Failed to create surface %p, hr %#x\n", texture, hr); FIXME("Failed to create surface %p, hr %#x\n", texture, hr);
texture_cleanup(texture); basetexture_cleanup(texture);
return hr; return hr;
} }
......
...@@ -89,6 +89,15 @@ static void volumetexture_sub_resource_add_dirty_region(struct wined3d_resource ...@@ -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); 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. */ /* Do not call while under the GL lock. */
static void volumetexture_unload(struct wined3d_resource *resource) static void volumetexture_unload(struct wined3d_resource *resource)
{ {
...@@ -111,6 +120,7 @@ static const struct wined3d_texture_ops volumetexture_ops = ...@@ -111,6 +120,7 @@ static const struct wined3d_texture_ops volumetexture_ops =
volumetexture_bind, volumetexture_bind,
volumetexture_preload, volumetexture_preload,
volumetexture_sub_resource_add_dirty_region, volumetexture_sub_resource_add_dirty_region,
volumetexture_sub_resource_cleanup,
}; };
static const struct wined3d_resource_ops volumetexture_resource_ops = static const struct wined3d_resource_ops volumetexture_resource_ops =
...@@ -118,32 +128,6 @@ static const struct wined3d_resource_ops volumetexture_resource_ops = ...@@ -118,32 +128,6 @@ static const struct wined3d_resource_ops volumetexture_resource_ops =
volumetexture_unload, 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) static HRESULT WINAPI IWineD3DVolumeTextureImpl_QueryInterface(IWineD3DBaseTexture *iface, REFIID riid, LPVOID *ppobj)
{ {
IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface; IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
...@@ -177,7 +161,7 @@ static ULONG WINAPI IWineD3DVolumeTextureImpl_Release(IWineD3DBaseTexture *iface ...@@ -177,7 +161,7 @@ static ULONG WINAPI IWineD3DVolumeTextureImpl_Release(IWineD3DBaseTexture *iface
ref = InterlockedDecrement(&This->resource.ref); ref = InterlockedDecrement(&This->resource.ref);
if (!ref) if (!ref)
{ {
volumetexture_cleanup(This); basetexture_cleanup(This);
This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent); This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
HeapFree(GetProcessHeap(), 0, This); HeapFree(GetProcessHeap(), 0, This);
} }
...@@ -381,7 +365,7 @@ HRESULT volumetexture_init(IWineD3DBaseTextureImpl *texture, UINT width, UINT he ...@@ -381,7 +365,7 @@ HRESULT volumetexture_init(IWineD3DBaseTextureImpl *texture, UINT width, UINT he
if (FAILED(hr)) if (FAILED(hr))
{ {
ERR("Creating a volume for the volume texture failed, hr %#x.\n", hr); ERR("Creating a volume for the volume texture failed, hr %#x.\n", hr);
volumetexture_cleanup(texture); basetexture_cleanup(texture);
return hr; return hr;
} }
......
...@@ -1890,6 +1890,7 @@ struct wined3d_texture_ops ...@@ -1890,6 +1890,7 @@ struct wined3d_texture_ops
void (*texture_preload)(struct IWineD3DBaseTextureImpl *texture, enum WINED3DSRGB srgb); void (*texture_preload)(struct IWineD3DBaseTextureImpl *texture, enum WINED3DSRGB srgb);
void (*texture_sub_resource_add_dirty_region)(struct wined3d_resource *sub_resource, void (*texture_sub_resource_add_dirty_region)(struct wined3d_resource *sub_resource,
const WINED3DBOX *dirty_region); const WINED3DBOX *dirty_region);
void (*texture_sub_resource_cleanup)(struct wined3d_resource *sub_resource);
}; };
typedef struct IWineD3DBaseTextureClass typedef struct IWineD3DBaseTextureClass
......
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