offscreen-effect: limit offscreen fbo size to the stage's size

When using a ClutterOffscreenEffect, the size of the offscreen buffer
allocated to perform the effect is currently computed using the paint
volume of the actor it's attached to and in the case the paint volume
cannot be computed, the effect falls back to using the stage's size.

If you scale an actor enough so its paint volume is much bigger that
the size of the stage, you can end up running out of memory (which
leads to your application crashing).

https://bugzilla.gnome.org/show_bug.cgi?id=699675
This commit is contained in:
Lionel Landwerlin 2013-05-04 17:37:33 +01:00 committed by Emmanuele Bassi
parent 8a6aae14c8
commit 9c6f3793e8

View File

@ -223,9 +223,11 @@ clutter_offscreen_effect_pre_paint (ClutterEffect *effect)
ClutterOffscreenEffect *self = CLUTTER_OFFSCREEN_EFFECT (effect); ClutterOffscreenEffect *self = CLUTTER_OFFSCREEN_EFFECT (effect);
ClutterOffscreenEffectPrivate *priv = self->priv; ClutterOffscreenEffectPrivate *priv = self->priv;
ClutterActorBox box; ClutterActorBox box;
ClutterActor *stage;
CoglMatrix projection; CoglMatrix projection;
CoglColor transparent; CoglColor transparent;
gfloat fbo_width, fbo_height; gfloat stage_width, stage_height;
gfloat fbo_width = -1, fbo_height = -1;
gfloat width, height; gfloat width, height;
gfloat xexpand, yexpand; gfloat xexpand, yexpand;
int texture_width, texture_height; int texture_width, texture_height;
@ -236,6 +238,9 @@ clutter_offscreen_effect_pre_paint (ClutterEffect *effect)
if (priv->actor == NULL) if (priv->actor == NULL)
return FALSE; return FALSE;
stage = _clutter_actor_get_stage_internal (priv->actor);
clutter_actor_get_size (stage, &stage_width, &stage_height);
/* The paint box is the bounding box of the actor's paint volume in /* The paint box is the bounding box of the actor's paint volume in
* stage coordinates. This will give us the size for the framebuffer * stage coordinates. This will give us the size for the framebuffer
* we need to redirect its rendering offscreen and its position will * we need to redirect its rendering offscreen and its position will
@ -244,17 +249,21 @@ clutter_offscreen_effect_pre_paint (ClutterEffect *effect)
{ {
clutter_actor_box_get_size (&box, &fbo_width, &fbo_height); clutter_actor_box_get_size (&box, &fbo_width, &fbo_height);
clutter_actor_box_get_origin (&box, &priv->x_offset, &priv->y_offset); clutter_actor_box_get_origin (&box, &priv->x_offset, &priv->y_offset);
fbo_width = MIN (fbo_width, stage_width);
fbo_height = MIN (fbo_height, stage_height);
} }
else else
{ {
/* If we can't get a valid paint box then we fallback to fbo_width = stage_width;
* creating a full stage size fbo. */ fbo_height = stage_height;
ClutterActor *stage = _clutter_actor_get_stage_internal (priv->actor);
clutter_actor_get_size (stage, &fbo_width, &fbo_height);
priv->x_offset = 0.0f;
priv->y_offset = 0.0f;
} }
if (fbo_width == stage_width)
priv->x_offset = 0.0f;
if (fbo_height == stage_height)
priv->y_offset = 0.0f;
/* First assert that the framebuffer is the right size... */ /* First assert that the framebuffer is the right size... */
if (!update_fbo (effect, fbo_width, fbo_height)) if (!update_fbo (effect, fbo_width, fbo_height))
return FALSE; return FALSE;