$\cos x (1+2\sin x + \sin^2 x) = \cos x (1+\sin x)^2$ let $t=1+\sin x$ then $t' = \cos x$ and use substitution rule.