Estimating Generalization under Distribution Shifts via Domain-Invariant Representations