Refactor frame invalidation in preparation for animation cycles
Notably, identical frame functions now take a range parameter, as it is
not always possible to exactly represent all the identical frames of
cycles in a reasonable amount of space. E.g. several cycles on different
layers with slightly different intervals.