Computation, mechanisms, and optimal coding in retinal adaptation