Don't take a reference to the last used onscreen framebuffer

Cogl keeps a pointer to the last used onscreen framebuffer from the
context to implement the deprecated cogl_set_draw_buffer function
which can take COGL_WINDOW_BUFFER as the target to use the last
onscreen buffer. Previously this would also take a reference to that
pointer. However that was causing a circular reference between the
framebuffer and the context which makes it impossible to clean up
resources properly when onscreen buffers are used. This patch instead
changes it to just store the pointer and then clear the pointer during
_cogl_onscreen_free as a kind of cheap weak reference.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
This commit is contained in:
Neil Roberts 2011-11-14 15:09:13 +00:00
parent 18b0ad652c
commit 39ca3e51df
3 changed files with 11 additions and 16 deletions

View File

@ -408,12 +408,6 @@ _cogl_context_free (CoglContext *context)
winsys->context_deinit (context); winsys->context_deinit (context);
if (context->window_buffer)
{
cogl_object_unref (context->window_buffer);
context->window_buffer = NULL;
}
_cogl_free_framebuffer_stack (context->framebuffer_stack); _cogl_free_framebuffer_stack (context->framebuffer_stack);
if (context->current_path) if (context->current_path)

View File

@ -1141,19 +1141,17 @@ notify_buffers_changed (CoglFramebuffer *old_draw_buffer,
} }
} }
/* XXX: /* XXX: To support the deprecated cogl_set_draw_buffer API we keep
* To support the deprecated cogl_set_draw_buffer API we keep track * track of the last onscreen framebuffer that was set so that it
* of the last onscreen framebuffer that was set so that it can * can be restored if the COGL_WINDOW_BUFFER enum is used. A
* be restored if the COGL_WINDOW_BUFFER enum is used. */ * reference isn't taken to the framebuffer because otherwise we
* would have a circular reference between the context and the
* framebuffer. Instead the pointer is set to NULL in
* _cogl_onscreen_free as a kind of a cheap weak reference */
if (new_draw_buffer && if (new_draw_buffer &&
new_draw_buffer->type == COGL_FRAMEBUFFER_TYPE_ONSCREEN) new_draw_buffer->type == COGL_FRAMEBUFFER_TYPE_ONSCREEN)
{
cogl_object_ref (new_draw_buffer);
if (ctx->window_buffer)
cogl_object_unref (ctx->window_buffer);
ctx->window_buffer = new_draw_buffer; ctx->window_buffer = new_draw_buffer;
} }
}
/* Set the current framebuffer without checking if it's already the /* Set the current framebuffer without checking if it's already the
* current framebuffer. This is used by cogl_pop_framebuffer while * current framebuffer. This is used by cogl_pop_framebuffer while

View File

@ -112,6 +112,9 @@ _cogl_onscreen_free (CoglOnscreen *onscreen)
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen); CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
const CoglWinsysVtable *winsys = _cogl_framebuffer_get_winsys (framebuffer); const CoglWinsysVtable *winsys = _cogl_framebuffer_get_winsys (framebuffer);
if (framebuffer->context->window_buffer == onscreen)
framebuffer->context->window_buffer = NULL;
winsys->onscreen_deinit (onscreen); winsys->onscreen_deinit (onscreen);
_COGL_RETURN_IF_FAIL (onscreen->winsys == NULL); _COGL_RETURN_IF_FAIL (onscreen->winsys == NULL);