Factor out most compositing code into a separate object.