units: Cache the pixels value inside Units
authorEmmanuele Bassi <ebassi@gnome.org>
Fri, 16 Oct 2009 14:25:37 +0000 (15:25 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Fri, 16 Oct 2009 14:25:37 +0000 (15:25 +0100)
commit83b4ec7a12ea279b59a80f6008e1bece25de3a8c
tree41ee64011022c7462fee4712710010d2625ce6d8
parent2ff31dfbaaad3056265b05efe57eac63f8e3ce61
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
.gitignore
clutter/clutter-backend.c
clutter/clutter-private.h
clutter/clutter-units.c
clutter/clutter-units.h
tests/conform/test-clutter-units.c
tests/conform/test-conform-main.c