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

@ -77,11 +77,18 @@ struct _ClutterUnits
gfloat value;
/* pre-filled by the provided constructors */
/* cached pixel value */
gfloat pixels;
/* whether the :pixels field is set */
guint pixels_set;
/* the serial coming from the backend, used to evict the cache */
gint32 serial;
/* padding for eventual expansion */
gint64 __padding_1;
gint32 __padding_1;
gint64 __padding_2;
};