osx: Avoid leaks in Stage::realize

clutter_stage_osx_realize() can now be called multiple times without
leaking views and windows.

https://bugzilla.gnome.org/show_bug.cgi?id=655307
This commit is contained in:
Kirk A. Baker 2011-07-25 15:00:30 -07:00 committed by Emmanuele Bassi
parent e144378f5a
commit 01fd673505
2 changed files with 34 additions and 23 deletions

View File

@ -306,7 +306,6 @@ static gboolean
clutter_stage_osx_realize (ClutterStageWindow *stage_window) clutter_stage_osx_realize (ClutterStageWindow *stage_window)
{ {
ClutterStageOSX *self = CLUTTER_STAGE_OSX (stage_window); ClutterStageOSX *self = CLUTTER_STAGE_OSX (stage_window);
ClutterBackendOSX *backend_osx;
gfloat width, height; gfloat width, height;
NSRect rect; NSRect rect;
@ -314,6 +313,10 @@ clutter_stage_osx_realize (ClutterStageWindow *stage_window)
CLUTTER_NOTE (BACKEND, "[%p] realize", self); CLUTTER_NOTE (BACKEND, "[%p] realize", self);
if (!self->haveRealized)
{
ClutterBackendOSX *backend_osx;
backend_osx = CLUTTER_BACKEND_OSX (self->backend); backend_osx = CLUTTER_BACKEND_OSX (self->backend);
/* Call get_size - this will either get the geometry size (which /* Call get_size - this will either get the geometry size (which
@ -323,15 +326,15 @@ clutter_stage_osx_realize (ClutterStageWindow *stage_window)
*/ */
clutter_actor_get_size (CLUTTER_ACTOR (self->wrapper), &width, &height); clutter_actor_get_size (CLUTTER_ACTOR (self->wrapper), &width, &height);
self->requisition_width = width; self->requisition_width = width;
self->requisition_height = height; self->requisition_height= height;
rect = NSMakeRect(0, 0, self->requisition_width, self->requisition_height); rect = NSMakeRect (0, 0, self->requisition_width, self->requisition_height);
self->view = [[ClutterGLView alloc] self->view = [[ClutterGLView alloc]
initWithFrame: rect initWithFrame: rect
pixelFormat: backend_osx->pixel_format pixelFormat: backend_osx->pixel_format
stage: self]; stage: self];
[self->view setOpenGLContext: backend_osx->context]; [self->view setOpenGLContext:backend_osx->context];
self->window = [[ClutterGLWindow alloc] self->window = [[ClutterGLWindow alloc]
initWithView: self->view initWithView: self->view
@ -339,8 +342,10 @@ clutter_stage_osx_realize (ClutterStageWindow *stage_window)
stage: self]; stage: self];
/* looks better than positioning to 0,0 (bottom right) */ /* looks better than positioning to 0,0 (bottom right) */
[self->window center]; [self->window center];
self->haveRealized = true;
CLUTTER_NOTE (BACKEND, "Stage successfully realized"); CLUTTER_NOTE (BACKEND, "Stage successfully realized");
}
CLUTTER_OSX_POOL_RELEASE(); CLUTTER_OSX_POOL_RELEASE();
@ -364,6 +369,7 @@ clutter_stage_osx_unrealize (ClutterStageWindow *stage_window)
self->view = NULL; self->view = NULL;
self->window = NULL; self->window = NULL;
self->haveRealized = false;
CLUTTER_OSX_POOL_RELEASE(); CLUTTER_OSX_POOL_RELEASE();
} }
@ -605,6 +611,10 @@ _clutter_stage_osx_new (ClutterBackend *backend,
self = g_object_new (CLUTTER_TYPE_STAGE_OSX, NULL); self = g_object_new (CLUTTER_TYPE_STAGE_OSX, NULL);
self->backend = backend; self->backend = backend;
self->wrapper = wrapper; self->wrapper = wrapper;
self->isHiding = false;
self->haveRealized = false;
self->view = NULL;
self->window = NULL;
return CLUTTER_STAGE_WINDOW(self); return CLUTTER_STAGE_WINDOW(self);
} }

View File

@ -68,6 +68,7 @@ struct _ClutterStageOSX
gboolean acceptFocus; gboolean acceptFocus;
gboolean isHiding; gboolean isHiding;
gboolean haveRealized;
gfloat scroll_pos_x; gfloat scroll_pos_x;
gfloat scroll_pos_y; gfloat scroll_pos_y;