Viewport refactoring.

#2220