While trying to implement Henri's suggestion I realized this patch series is leaking the old textures. Releasing them exposes some refcounting problems with the new implementation, and fixing these is going to be even more involved, so for the moment I'm just cutting this series down to the first two patches.