Dynamics of glasses and glass-forming liquids studied by inelastic x-ray scattering