Calculate viewport size in one place, remove code duplication