widget: Add optimizations to gtk_widget_compute_transform()

Try to catch 2 common cases with as little work as necessary.
This commit is contained in:
Benjamin Otte 2019-02-20 04:04:29 +01:00
parent 8222631d63
commit cfc7dc016e

View File

@ -11259,6 +11259,13 @@ gtk_widget_compute_transform (GtkWidget *widget,
g_return_val_if_fail (GTK_IS_WIDGET (target), FALSE); g_return_val_if_fail (GTK_IS_WIDGET (target), FALSE);
g_return_val_if_fail (out_transform != NULL, FALSE); g_return_val_if_fail (out_transform != NULL, FALSE);
/* optimization for common case: parent wants coordinates of a direct child */
if (target == widget->priv->parent)
{
graphene_matrix_init_from_matrix (out_transform, &widget->priv->transform);
return TRUE;
}
ancestor = gtk_widget_common_ancestor (widget, target); ancestor = gtk_widget_common_ancestor (widget, target);
if (ancestor == NULL) if (ancestor == NULL)
return FALSE; return FALSE;
@ -11271,6 +11278,13 @@ gtk_widget_compute_transform (GtkWidget *widget,
graphene_matrix_multiply (&transform, &priv->transform, &transform); graphene_matrix_multiply (&transform, &priv->transform, &transform);
} }
/* optimization for common case: parent wants coordinates of a non-direct child */
if (ancestor == target)
{
graphene_matrix_init_from_matrix (out_transform, &transform);
return TRUE;
}
graphene_matrix_init_identity (&inverse); graphene_matrix_init_identity (&inverse);
for (iter = target; iter != ancestor; iter = iter->priv->parent) for (iter = target; iter != ancestor; iter = iter->priv->parent)
{ {