st/mesa: refactor some bitmap drawing code