Skip to content

Commit f1046bb

Browse files
committed
clutter/clone: Build scale factor for transformation during allocation
For ClutterClones we need to apply a scale to the texture of the clone to ensure the painted texture of the source actor actually fits the allocation of the clone. We're doing this using the transformation matrix instead of using the scale_x/scale_y properties of ClutterActor to allow users to scale ClutterClones using that API independently. Now it's quite a bad idea to get the allocation boxes for calculating that scale using clutter_actor_get_allocation_box(), since that method will internally do an immediate relayout of the stage in case the actor isn't allocated. Another side effect of that approach is that it makes it impossible to invalidate the transform (which is needed for the next commit when we start caching those matrices) properly. So since we eventually allocate both the source actor and the clone ourselves anyway, we can simply use the allocation box inside clutter_clone_allocate() (which is definitely updated and valid at that point) to calculate the scale factor.
1 parent e81e995 commit f1046bb

1 file changed

Lines changed: 25 additions & 17 deletions

File tree

clutter/clutter/clutter-clone.c

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
struct _ClutterClonePrivate
5353
{
5454
ClutterActor *clone_source;
55+
float x_scale, y_scale;
56+
5557
gulong source_destroy_id;
5658
};
5759

@@ -122,8 +124,6 @@ static void
122124
clutter_clone_apply_transform (ClutterActor *self, CoglMatrix *matrix)
123125
{
124126
ClutterClonePrivate *priv = CLUTTER_CLONE (self)->priv;
125-
ClutterActorBox box, source_box;
126-
gfloat x_scale, y_scale;
127127

128128
/* First chain up and apply all the standard ClutterActor
129129
* transformations... */
@@ -134,21 +134,7 @@ clutter_clone_apply_transform (ClutterActor *self, CoglMatrix *matrix)
134134
if (priv->clone_source == NULL)
135135
return;
136136

137-
/* get our allocated size */
138-
clutter_actor_get_allocation_box (self, &box);
139-
140-
/* and get the allocated size of the source */
141-
clutter_actor_get_allocation_box (priv->clone_source, &source_box);
142-
143-
/* We need to scale what the clone-source actor paints to fill our own
144-
* allocation...
145-
*/
146-
x_scale = clutter_actor_box_get_width (&box)
147-
/ clutter_actor_box_get_width (&source_box);
148-
y_scale = clutter_actor_box_get_height (&box)
149-
/ clutter_actor_box_get_height (&source_box);
150-
151-
cogl_matrix_scale (matrix, x_scale, y_scale, x_scale);
137+
cogl_matrix_scale (matrix, priv->x_scale, priv->y_scale, 1.f);
152138
}
153139

154140
static void
@@ -244,6 +230,8 @@ clutter_clone_allocate (ClutterActor *self,
244230
{
245231
ClutterClonePrivate *priv = CLUTTER_CLONE (self)->priv;
246232
ClutterActorClass *parent_class;
233+
ClutterActorBox source_box;
234+
float x_scale, y_scale;
247235

248236
/* chain up */
249237
parent_class = CLUTTER_ACTOR_CLASS (clutter_clone_parent_class);
@@ -259,6 +247,23 @@ clutter_clone_allocate (ClutterActor *self,
259247
!clutter_actor_has_allocation (priv->clone_source))
260248
clutter_actor_allocate_preferred_size (priv->clone_source);
261249

250+
clutter_actor_get_allocation_box (priv->clone_source, &source_box);
251+
252+
/* We need to scale what the clone-source actor paints to fill our own
253+
* allocation...
254+
*/
255+
x_scale = clutter_actor_box_get_width (box)
256+
/ clutter_actor_box_get_width (&source_box);
257+
y_scale = clutter_actor_box_get_height (box)
258+
/ clutter_actor_box_get_height (&source_box);
259+
260+
if (!G_APPROX_VALUE (priv->x_scale, x_scale, FLT_EPSILON) ||
261+
!G_APPROX_VALUE (priv->y_scale, y_scale, FLT_EPSILON))
262+
{
263+
priv->x_scale = x_scale;
264+
priv->y_scale = y_scale;
265+
}
266+
262267
#if 0
263268
/* XXX - this is wrong: ClutterClone cannot clone unparented
264269
* actors, as it will break all invariants
@@ -364,6 +369,9 @@ static void
364369
clutter_clone_init (ClutterClone *self)
365370
{
366371
self->priv = clutter_clone_get_instance_private (self);
372+
373+
self->priv->x_scale = 1.f;
374+
self->priv->y_scale = 1.f;
367375
}
368376

369377
/**

0 commit comments

Comments
 (0)