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

wined3d: Explicitly destroy the surface in texture2d_sub_resource_cleanup().

Like volumes. We can do this now because we no longer have standalone surfaces.
parent 64a1fde1
...@@ -103,6 +103,15 @@ static void surface_cleanup(struct wined3d_surface *surface) ...@@ -103,6 +103,15 @@ static void surface_cleanup(struct wined3d_surface *surface)
resource_cleanup(&surface->resource); resource_cleanup(&surface->resource);
} }
void wined3d_surface_destroy(struct wined3d_surface *surface)
{
TRACE("surface %p.\n", surface);
surface_cleanup(surface);
surface->resource.parent_ops->wined3d_object_destroyed(surface->resource.parent);
HeapFree(GetProcessHeap(), 0, surface);
}
void surface_update_draw_binding(struct wined3d_surface *surface) void surface_update_draw_binding(struct wined3d_surface *surface)
{ {
if (!surface_is_offscreen(surface) || wined3d_settings.offscreen_rendering_mode != ORM_FBO) if (!surface_is_offscreen(surface) || wined3d_settings.offscreen_rendering_mode != ORM_FBO)
...@@ -151,14 +160,6 @@ void surface_set_swapchain(struct wined3d_surface *surface, struct wined3d_swapc ...@@ -151,14 +160,6 @@ void surface_set_swapchain(struct wined3d_surface *surface, struct wined3d_swapc
surface_update_draw_binding(surface); surface_update_draw_binding(surface);
} }
void surface_set_container(struct wined3d_surface *surface, struct wined3d_texture *container)
{
TRACE("surface %p, container %p.\n", surface, container);
surface->container = container;
surface_update_draw_binding(surface);
}
struct blt_info struct blt_info
{ {
GLenum binding; GLenum binding;
...@@ -2135,49 +2136,24 @@ static inline unsigned short float_32_to_16(const float *in) ...@@ -2135,49 +2136,24 @@ static inline unsigned short float_32_to_16(const float *in)
ULONG CDECL wined3d_surface_incref(struct wined3d_surface *surface) ULONG CDECL wined3d_surface_incref(struct wined3d_surface *surface)
{ {
ULONG refcount;
TRACE("surface %p, swapchain %p, container %p.\n", TRACE("surface %p, swapchain %p, container %p.\n",
surface, surface->swapchain, surface->container); surface, surface->swapchain, surface->container);
if (surface->swapchain) if (surface->swapchain)
return wined3d_swapchain_incref(surface->swapchain); return wined3d_swapchain_incref(surface->swapchain);
if (surface->container)
return wined3d_texture_incref(surface->container); return wined3d_texture_incref(surface->container);
refcount = InterlockedIncrement(&surface->resource.ref);
TRACE("%p increasing refcount to %u.\n", surface, refcount);
return refcount;
} }
ULONG CDECL wined3d_surface_decref(struct wined3d_surface *surface) ULONG CDECL wined3d_surface_decref(struct wined3d_surface *surface)
{ {
ULONG refcount;
TRACE("surface %p, swapchain %p, container %p.\n", TRACE("surface %p, swapchain %p, container %p.\n",
surface, surface->swapchain, surface->container); surface, surface->swapchain, surface->container);
if (surface->swapchain) if (surface->swapchain)
return wined3d_swapchain_decref(surface->swapchain); return wined3d_swapchain_decref(surface->swapchain);
if (surface->container)
return wined3d_texture_decref(surface->container); return wined3d_texture_decref(surface->container);
refcount = InterlockedDecrement(&surface->resource.ref);
TRACE("%p decreasing refcount to %u.\n", surface, refcount);
if (!refcount)
{
surface_cleanup(surface);
surface->resource.parent_ops->wined3d_object_destroyed(surface->resource.parent);
TRACE("Destroyed surface %p.\n", surface);
HeapFree(GetProcessHeap(), 0, surface);
}
return refcount;
} }
void CDECL wined3d_surface_preload(struct wined3d_surface *surface) void CDECL wined3d_surface_preload(struct wined3d_surface *surface)
...@@ -6016,7 +5992,8 @@ static HRESULT surface_init(struct wined3d_surface *surface, struct wined3d_text ...@@ -6016,7 +5992,8 @@ static HRESULT surface_init(struct wined3d_surface *surface, struct wined3d_text
return hr; return hr;
} }
surface_set_container(surface, container); surface->container = container;
surface_update_draw_binding(surface);
surface_validate_location(surface, WINED3D_LOCATION_SYSMEM); surface_validate_location(surface, WINED3D_LOCATION_SYSMEM);
list_init(&surface->renderbuffers); list_init(&surface->renderbuffers);
list_init(&surface->overlays); list_init(&surface->overlays);
...@@ -6036,11 +6013,9 @@ static HRESULT surface_init(struct wined3d_surface *surface, struct wined3d_text ...@@ -6036,11 +6013,9 @@ static HRESULT surface_init(struct wined3d_surface *surface, struct wined3d_text
surface->texture_level = level; surface->texture_level = level;
/* Call the private setup routine */ /* Call the private setup routine */
hr = surface->surface_ops->surface_private_setup(surface); if (FAILED(hr = surface->surface_ops->surface_private_setup(surface)))
if (FAILED(hr))
{ {
ERR("Private setup failed, returning %#x\n", hr); ERR("Private setup failed, hr %#x.\n", hr);
surface_set_container(surface, NULL);
surface_cleanup(surface); surface_cleanup(surface);
return hr; return hr;
} }
...@@ -6091,8 +6066,7 @@ HRESULT wined3d_surface_create(struct wined3d_texture *container, const struct w ...@@ -6091,8 +6066,7 @@ HRESULT wined3d_surface_create(struct wined3d_texture *container, const struct w
wined3d_texture_get_parent(container), object, &parent, &parent_ops))) wined3d_texture_get_parent(container), object, &parent, &parent_ops)))
{ {
WARN("Failed to create surface parent, hr %#x.\n", hr); WARN("Failed to create surface parent, hr %#x.\n", hr);
surface_set_container(object, NULL); wined3d_surface_destroy(object);
wined3d_surface_decref(object);
return hr; return hr;
} }
......
...@@ -742,8 +742,7 @@ static void texture2d_sub_resource_cleanup(struct wined3d_resource *sub_resource ...@@ -742,8 +742,7 @@ static void texture2d_sub_resource_cleanup(struct wined3d_resource *sub_resource
{ {
struct wined3d_surface *surface = surface_from_resource(sub_resource); struct wined3d_surface *surface = surface_from_resource(sub_resource);
surface_set_container(surface, NULL); wined3d_surface_destroy(surface);
wined3d_surface_decref(surface);
} }
static const struct wined3d_texture_ops texture2d_ops = static const struct wined3d_texture_ops texture2d_ops =
......
...@@ -2303,7 +2303,6 @@ void surface_prepare_texture(struct wined3d_surface *surface, ...@@ -2303,7 +2303,6 @@ void surface_prepare_texture(struct wined3d_surface *surface,
struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN; struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN;
void surface_set_compatible_renderbuffer(struct wined3d_surface *surface, void surface_set_compatible_renderbuffer(struct wined3d_surface *surface,
const struct wined3d_surface *rt) DECLSPEC_HIDDEN; const struct wined3d_surface *rt) DECLSPEC_HIDDEN;
void surface_set_container(struct wined3d_surface *surface, struct wined3d_texture *container) DECLSPEC_HIDDEN;
void surface_set_swapchain(struct wined3d_surface *surface, struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN; void surface_set_swapchain(struct wined3d_surface *surface, struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
void surface_set_texture_target(struct wined3d_surface *surface, GLenum target, GLint level) DECLSPEC_HIDDEN; void surface_set_texture_target(struct wined3d_surface *surface, GLenum target, GLint level) DECLSPEC_HIDDEN;
void surface_translate_drawable_coords(const struct wined3d_surface *surface, HWND window, RECT *rect) DECLSPEC_HIDDEN; void surface_translate_drawable_coords(const struct wined3d_surface *surface, HWND window, RECT *rect) DECLSPEC_HIDDEN;
...@@ -2313,6 +2312,7 @@ HRESULT surface_upload_from_surface(struct wined3d_surface *dst_surface, const P ...@@ -2313,6 +2312,7 @@ HRESULT surface_upload_from_surface(struct wined3d_surface *dst_surface, const P
void surface_validate_location(struct wined3d_surface *surface, DWORD location) DECLSPEC_HIDDEN; void surface_validate_location(struct wined3d_surface *surface, DWORD location) DECLSPEC_HIDDEN;
HRESULT wined3d_surface_create(struct wined3d_texture *container, const struct wined3d_resource_desc *desc, HRESULT wined3d_surface_create(struct wined3d_texture *container, const struct wined3d_resource_desc *desc,
GLenum target, GLint level, DWORD flags, struct wined3d_surface **surface) DECLSPEC_HIDDEN; GLenum target, GLint level, DWORD flags, struct wined3d_surface **surface) DECLSPEC_HIDDEN;
void wined3d_surface_destroy(struct wined3d_surface *surface) DECLSPEC_HIDDEN;
void surface_prepare_map_memory(struct wined3d_surface *surface) DECLSPEC_HIDDEN; void surface_prepare_map_memory(struct wined3d_surface *surface) DECLSPEC_HIDDEN;
void draw_textured_quad(const struct wined3d_surface *src_surface, struct wined3d_context *context, void draw_textured_quad(const struct wined3d_surface *src_surface, struct wined3d_context *context,
......
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