summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Roberts <neil@linux.intel.com>2011-11-14 15:09:13 +0000
committerNeil Roberts <neil@linux.intel.com>2011-11-14 18:40:28 +0000
commit39ca3e51dfaa652ae4a0d936fff32a5edaca6c5f (patch)
tree16306a6ba4c351ce8cd8b2fffd15ed6c2395532b
parent18b0ad652c77723f88fa0154a28d418bd0bce035 (diff)
downloadcogl-39ca3e51dfaa652ae4a0d936fff32a5edaca6c5f.tar.gz
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>
-rw-r--r--cogl/cogl-context.c6
-rw-r--r--cogl/cogl-framebuffer.c18
-rw-r--r--cogl/cogl-onscreen.c3
3 files changed, 11 insertions, 16 deletions
diff --git a/cogl/cogl-context.c b/cogl/cogl-context.c
index da41a820..b8296ece 100644
--- a/cogl/cogl-context.c
+++ b/cogl/cogl-context.c
@@ -408,12 +408,6 @@ _cogl_context_free (CoglContext *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);
if (context->current_path)
diff --git a/cogl/cogl-framebuffer.c b/cogl/cogl-framebuffer.c
index e28d4489..6d99e339 100644
--- a/cogl/cogl-framebuffer.c
+++ b/cogl/cogl-framebuffer.c
@@ -1141,18 +1141,16 @@ notify_buffers_changed (CoglFramebuffer *old_draw_buffer,
}
}
- /* XXX:
- * To support the deprecated cogl_set_draw_buffer API we keep track
- * of the last onscreen framebuffer that was set so that it can
- * be restored if the COGL_WINDOW_BUFFER enum is used. */
+ /* XXX: To support the deprecated cogl_set_draw_buffer API we keep
+ * track of the last onscreen framebuffer that was set so that it
+ * can be restored if the COGL_WINDOW_BUFFER enum is used. A
+ * 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 &&
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
diff --git a/cogl/cogl-onscreen.c b/cogl/cogl-onscreen.c
index f95f96c7..f9439930 100644
--- a/cogl/cogl-onscreen.c
+++ b/cogl/cogl-onscreen.c
@@ -112,6 +112,9 @@ _cogl_onscreen_free (CoglOnscreen *onscreen)
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
const CoglWinsysVtable *winsys = _cogl_framebuffer_get_winsys (framebuffer);
+ if (framebuffer->context->window_buffer == onscreen)
+ framebuffer->context->window_buffer = NULL;
+
winsys->onscreen_deinit (onscreen);
_COGL_RETURN_IF_FAIL (onscreen->winsys == NULL);