drm_buffer_gbm: reduce code duplication
There are three very similar functions in this file, this factors the common logic out to a function that takes a callback. As part of this refactoring also avoid calling gbm_bo_get_plane_count() for every iteration by saving the result in a local variable.