Remove some code duplication in the Compositor

It is possible to share the code which creates root layers.