The production of D+- and D0 mesons has been measured with the ZEUS detector at HERA using an integrated luminosity of 133.6 pb-1. The measurements cover the kinematic range 5 < Q^2 < 1000 GeV^2, 0.02 < y < 0.7, 1.5 < p_T^D < 15 GeV and eta^D < 1.6. Combinatorial background to the D meson signals is reduced by using the ZEUS microvertex detector to reconstruct displaced secondary vertices. Production cross sections are compared with the predictions of next-to-leading-order QCD which is found to describe the data well. Measurements are extrapolated to the full kinematic phase space in order to obtain the open-charm contribution, F2^ccbar, to the proton structure function, F2.