units: Cache the pixels value inside Units

When computing the pixels value of a ClutterUnits value we should
be caching the value to avoid recomputing for every call of
clutter_units_to_pixels(). We already have a flag telling us to
return the cached value, but we miss the mechanism to evict the
cache whenever the Backend settings affecting the conversion, that
is default font and resolution, change.

In order to implement the eviction we can use a "serial"; the
Backend will have an internal serial field which we retrieve and
put inside the ClutterUnits structure (we split one of the two
64 bit padding fields into two 32 bit fields to maintain ABI); every
time we call clutter_units_to_pixels() we compare the units serial
with that of the Backend; if they match and pixels_set is set to
TRUE then we just return the stored pixels value. If the serials
do not match then we unset the pixels_set flag and recompute the
pixels value.

We can verify this by adding a simple test unit checking that
by changing the resolution of ClutterBackend we get different
pixel values for 1 em.

http://bugzilla.openedhand.com/show_bug.cgi?id=1843
This commit is contained in:
Emmanuele Bassi
2009-10-16 15:25:37 +01:00
parent 2ff31dfbaa
commit 83b4ec7a12
7 changed files with 99 additions and 3 deletions

View File

@ -63,6 +63,7 @@ struct _ClutterBackendPrivate
gdouble resolution;
gfloat units_per_em;
gint32 units_serial;
cairo_font_options_t *font_options;
@ -160,7 +161,10 @@ get_units_per_em (ClutterBackend *backend,
static void
clutter_backend_real_resolution_changed (ClutterBackend *backend)
{
backend->priv->units_per_em = get_units_per_em (backend, NULL);
ClutterBackendPrivate *priv = backend->priv;
priv->units_per_em = get_units_per_em (backend, NULL);
priv->units_serial += 1;
CLUTTER_NOTE (BACKEND, "Units per em: %.2f", backend->priv->units_per_em);
}
@ -168,7 +172,10 @@ clutter_backend_real_resolution_changed (ClutterBackend *backend)
static void
clutter_backend_real_font_changed (ClutterBackend *backend)
{
backend->priv->units_per_em = get_units_per_em (backend, NULL);
ClutterBackendPrivate *priv = backend->priv;
priv->units_per_em = get_units_per_em (backend, NULL);
priv->units_serial += 1;
CLUTTER_NOTE (BACKEND, "Units per em: %.2f", backend->priv->units_per_em);
}
@ -212,7 +219,9 @@ clutter_backend_init (ClutterBackend *backend)
priv = backend->priv = CLUTTER_BACKEND_GET_PRIVATE (backend);
priv->resolution = -1.0;
priv->units_per_em = -1.0;
priv->units_serial = 1;
}
void
@ -721,3 +730,11 @@ clutter_backend_get_font_name (ClutterBackend *backend)
return priv->font_name;
}
gint32
_clutter_backend_get_units_serial (ClutterBackend *backend)
{
g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), 0);
return backend->priv->units_serial;
}