Begin porting layout managers to the new child iteration API

Instead of getting the list of children to iterate over it, let's use
the newly added child iteration API; this should save us a bunch of
allocations, as well as indirections.

Ported: ClutterBinLayout and ClutterBoxLayout.
This commit is contained in:
Emmanuele Bassi 2011-12-18 10:29:01 +00:00
parent 8b430507b5
commit 9c9ab42060
2 changed files with 53 additions and 67 deletions

View File

@ -335,15 +335,16 @@ clutter_bin_layout_get_preferred_width (ClutterLayoutManager *manager,
gfloat *min_width_p,
gfloat *nat_width_p)
{
GList *children = clutter_container_get_children (container);
GList *l;
ClutterActor *actor = CLUTTER_ACTOR (container);
ClutterActor *child;
gfloat min_width, nat_width;
min_width = nat_width = 0.0;
for (l = children; l != NULL; l = l->next)
for (child = clutter_actor_get_first_child (actor);
child != NULL;
child = clutter_actor_get_next_sibling (child))
{
ClutterActor *child = l->data;
gfloat minimum, natural;
clutter_actor_get_preferred_width (child, for_height,
@ -359,8 +360,6 @@ clutter_bin_layout_get_preferred_width (ClutterLayoutManager *manager,
if (nat_width_p)
*nat_width_p = nat_width;
g_list_free (children);
}
static void
@ -370,15 +369,16 @@ clutter_bin_layout_get_preferred_height (ClutterLayoutManager *manager,
gfloat *min_height_p,
gfloat *nat_height_p)
{
GList *children = clutter_container_get_children (container);
GList *l;
ClutterActor *actor = CLUTTER_ACTOR (container);
ClutterActor *child;
gfloat min_height, nat_height;
min_height = nat_height = 0.0;
for (l = children; l != NULL; l = l->next)
for (child = clutter_actor_get_first_child (actor);
child != NULL;
child = clutter_actor_get_next_sibling (child))
{
ClutterActor *child = l->data;
gfloat minimum, natural;
clutter_actor_get_preferred_height (child, for_width,
@ -394,8 +394,6 @@ clutter_bin_layout_get_preferred_height (ClutterLayoutManager *manager,
if (nat_height_p)
*nat_height_p = nat_height;
g_list_free (children);
}
static gdouble
@ -426,17 +424,19 @@ clutter_bin_layout_allocate (ClutterLayoutManager *manager,
const ClutterActorBox *allocation,
ClutterAllocationFlags flags)
{
GList *children = clutter_container_get_children (container);
GList *l;
gfloat allocation_x, allocation_y;
gfloat available_w, available_h;
ClutterActor *actor, *child;
clutter_actor_box_get_origin (allocation, &allocation_x, &allocation_y);
clutter_actor_box_get_size (allocation, &available_w, &available_h);
for (l = children; l != NULL; l = l->next)
actor = CLUTTER_ACTOR (container);
for (child = clutter_actor_get_first_child (actor);
child != NULL;
child = clutter_actor_get_next_sibling (child))
{
ClutterActor *child = l->data;
ClutterLayoutMeta *meta;
ClutterBinLayer *layer;
ClutterActorBox child_alloc = { 0, };
@ -471,8 +471,6 @@ clutter_bin_layout_allocate (ClutterLayoutManager *manager,
x_fill, y_fill,
flags);
}
g_list_free (children);
}
static GType

View File

@ -476,16 +476,15 @@ clutter_box_layout_set_container (ClutterLayoutManager *layout,
static void
get_preferred_width (ClutterBoxLayout *self,
ClutterContainer *container,
GList *children,
ClutterActor *container,
gfloat for_height,
gfloat *min_width_p,
gfloat *natural_width_p)
{
ClutterBoxLayoutPrivate *priv = self->priv;
ClutterActor *child;
gint n_children = 0;
gboolean is_rtl;
GList *l;
if (min_width_p)
*min_width_p = 0;
@ -497,17 +496,18 @@ get_preferred_width (ClutterBoxLayout *self,
{
ClutterTextDirection text_dir;
text_dir = clutter_actor_get_text_direction (CLUTTER_ACTOR (container));
text_dir = clutter_actor_get_text_direction (container);
is_rtl = (text_dir == CLUTTER_TEXT_DIRECTION_RTL) ? TRUE : FALSE;
}
else
is_rtl = FALSE;
for (l = (is_rtl) ? g_list_last (children) : children;
l != NULL;
l = (is_rtl) ? l->prev : l->next)
for (child = (is_rtl) ? clutter_actor_get_last_child (container)
: clutter_actor_get_first_child (container);
child != NULL;
child = (is_rtl) ? clutter_actor_get_previous_sibling (child)
: clutter_actor_get_next_sibling (child))
{
ClutterActor *child = l->data;
gfloat child_min = 0, child_nat = 0;
if (!CLUTTER_ACTOR_IS_VISIBLE (child))
@ -553,16 +553,15 @@ get_preferred_width (ClutterBoxLayout *self,
static void
get_preferred_height (ClutterBoxLayout *self,
ClutterContainer *container,
GList *children,
ClutterActor *container,
gfloat for_width,
gfloat *min_height_p,
gfloat *natural_height_p)
{
ClutterBoxLayoutPrivate *priv = self->priv;
ClutterActor *child;
gint n_children = 0;
gboolean is_rtl;
GList *l;
if (min_height_p)
*min_height_p = 0;
@ -574,17 +573,18 @@ get_preferred_height (ClutterBoxLayout *self,
{
ClutterTextDirection text_dir;
text_dir = clutter_actor_get_text_direction (CLUTTER_ACTOR (container));
text_dir = clutter_actor_get_text_direction (container);
is_rtl = (text_dir == CLUTTER_TEXT_DIRECTION_RTL) ? TRUE : FALSE;
}
else
is_rtl = FALSE;
for (l = (is_rtl) ? g_list_last (children) : children;
l != NULL;
l = (is_rtl) ? l->prev : l->next)
for (child = (is_rtl) ? clutter_actor_get_last_child (container)
: clutter_actor_get_first_child (container);
child != NULL;
child = (is_rtl) ? clutter_actor_get_previous_sibling (child)
: clutter_actor_get_next_sibling (child))
{
ClutterActor *child = l->data;
gfloat child_min = 0, child_nat = 0;
if (!CLUTTER_ACTOR_IS_VISIBLE (child))
@ -713,15 +713,10 @@ clutter_box_layout_get_preferred_width (ClutterLayoutManager *layout,
gfloat *natural_width_p)
{
ClutterBoxLayout *self = CLUTTER_BOX_LAYOUT (layout);
GList *children;
children = clutter_container_get_children (container);
get_preferred_width (self, container, children, for_height,
get_preferred_width (self, CLUTTER_ACTOR (container), for_height,
min_width_p,
natural_width_p);
g_list_free (children);
}
static void
@ -732,15 +727,10 @@ clutter_box_layout_get_preferred_height (ClutterLayoutManager *layout,
gfloat *natural_height_p)
{
ClutterBoxLayout *self = CLUTTER_BOX_LAYOUT (layout);
GList *children;
children = clutter_container_get_children (container);
get_preferred_height (self, container, children, for_width,
get_preferred_height (self, CLUTTER_ACTOR (container), for_width,
min_height_p,
natural_height_p);
g_list_free (children);
}
static void
@ -749,16 +739,16 @@ count_expand_children (ClutterLayoutManager *layout,
gint *visible_children,
gint *expand_children)
{
GList *children, *l;
ClutterActor *child;
ClutterActor *actor, *child;
actor = CLUTTER_ACTOR (container);
*visible_children = *expand_children = 0;
children = clutter_container_get_children (container);
for (l = children; l != NULL; l = l->next)
for (child = clutter_actor_get_first_child (actor);
child != NULL;
child = clutter_actor_get_next_sibling (child))
{
child = l->data;
if (CLUTTER_ACTOR_IS_VISIBLE (child))
{
ClutterLayoutMeta *meta;
@ -773,7 +763,6 @@ count_expand_children (ClutterLayoutManager *layout,
*expand_children += 1;
}
}
g_list_free (children);
}
struct _ClutterRequestedSize
@ -899,8 +888,7 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
ClutterAllocationFlags flags)
{
ClutterBoxLayoutPrivate *priv = CLUTTER_BOX_LAYOUT (layout)->priv;
ClutterActor *child;
GList *children, *l;
ClutterActor *actor, *child;
gint nvis_children;
gint nexpand_children;
gboolean is_rtl;
@ -927,12 +915,13 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
else
size = box->x2 - box->x1 - (nvis_children - 1) * priv->spacing;
/* Retrieve desired size for visible children. */
children = clutter_container_get_children (container);
for (i = 0, l = children; l != NULL; l = l->next)
{
child = l->data;
actor = CLUTTER_ACTOR (container);
/* Retrieve desired size for visible children. */
for (i = 0, child = clutter_actor_get_first_child (actor);
child != NULL;
child = clutter_actor_get_next_sibling (child))
{
if (!CLUTTER_ACTOR_IS_VISIBLE (child))
continue;
@ -972,7 +961,6 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
i++;
}
g_list_free (children);
if (priv->is_homogeneous)
{
@ -1034,15 +1022,16 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
x = 0.0 + box->x2 - box->x1;
}
children = clutter_container_get_children (container);
for (i = g_list_length (children) - 1, l = g_list_last (children);
l != NULL;
l = l->prev, i--)
i = clutter_actor_get_n_children (actor);
for (child = clutter_actor_get_last_child (actor);
child != NULL;
child = clutter_actor_get_previous_sibling (child))
{
ClutterLayoutMeta *meta;
ClutterBoxChild *box_child;
child = l->data;
i -= 1;
meta = clutter_layout_manager_get_child_meta (layout,
container,
child);
@ -1146,7 +1135,6 @@ clutter_box_layout_allocate (ClutterLayoutManager *layout,
&child_allocation,
flags);
}
g_list_free (children);
}
static ClutterAlpha *