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
Current parsing of units has a number of shortcomings:
* a number followed by trailing space (without any unit specified) was
not recognized,
* "5 emeralds" was parsed as 5em,
* the way we parse the digits after the separator makes us lose
precision for no good reason (5.0 is parsed as 5.00010014...f which
makes g_assert_cmpfloat() fail)
Let's define a stricter grammar we can recognize and try to do so. The
description is in EBNF form, removing the optional <> which is a pain
when having to write DocBook, and using '' for the terminal symbols.
Last step, add more ClutterUnits unit test to get a better coverage of
the grammar we want to parse.
Reviewed-by: Emmanuele Bassi <ebassi@linux.intel.com>
We should follow the convention for boxed types initializers of:
<type_name>_from_<another_type> (boxed, value)
For ClutterUnits as well; so:
clutter_units_pixels -> clutter_units_from_pixels
clutter_units_em -> clutter_units_from_em
...
We should still keep the short-hand version as a macro, though.
Units as they have been implemented since Clutter 0.4 have always been
misdefined as "logical distance unit", while they were just pixels with
fractionary bits.
Units should be reworked to be opaque structures to hold a value and
its unit type, that can be then converted into pixels when Clutter needs
to paint or compute size requisitions and perform allocations.
The previous API should be completely removed to avoid collisions, and
a new type:
ClutterUnits
should be added; the ability to install GObject properties using
ClutterUnits should be maintained.