backend-drm: move code that creates gbm surface to a separate function

The function drm_output_init_egl() is too big, so move the code to
create the gbm surface to a separate function: create_gbm_surface().

Also made some minor style changes to the code that has been moved, in
order to improve readability.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
dev
Leandro Ribeiro 4 years ago committed by Daniel Stone
parent 7466309c12
commit 3459bad63d
  1. 61
      libweston/backend-drm/drm-gbm.c

@ -177,58 +177,59 @@ err:
return -1; return -1;
} }
/* Init output state that depends on gl or gbm */ static void
int create_gbm_surface(struct gbm_device *gbm, struct drm_output *output)
drm_output_init_egl(struct drm_output *output, struct drm_backend *b)
{ {
struct weston_mode *mode = output->base.current_mode;
struct drm_plane *plane = output->scanout_plane;
struct weston_drm_format *fmt; struct weston_drm_format *fmt;
const uint64_t *modifiers; const uint64_t *modifiers;
unsigned int num_modifiers; unsigned int num_modifiers;
uint32_t format[2] = { fmt = weston_drm_format_array_find_format(&plane->formats,
output->gbm_format, output->gbm_format);
fallback_format_for(output->gbm_format),
};
struct gl_renderer_output_options options = {
.drm_formats = format,
.drm_formats_count = 1,
};
struct weston_mode *mode = output->base.current_mode;
struct drm_plane *plane = output->scanout_plane;
assert(output->gbm_surface == NULL);
fmt = weston_drm_format_array_find_format(&plane->formats, output->gbm_format);
if (!fmt) { if (!fmt) {
weston_log("format 0x%x not supported by output %s\n", weston_log("format 0x%x not supported by output %s\n",
output->gbm_format, output->base.name); output->gbm_format, output->base.name);
return -1; return;
} }
#ifdef HAVE_GBM_MODIFIERS #ifdef HAVE_GBM_MODIFIERS
modifiers = weston_drm_format_get_modifiers(fmt, &num_modifiers); modifiers = weston_drm_format_get_modifiers(fmt, &num_modifiers);
if (num_modifiers > 0) { if (num_modifiers > 0) {
output->gbm_surface = output->gbm_surface =
gbm_surface_create_with_modifiers(b->gbm, gbm_surface_create_with_modifiers(gbm,
mode->width, mode->width, mode->height,
mode->height,
output->gbm_format, output->gbm_format,
modifiers, modifiers, num_modifiers);
num_modifiers);
} }
#endif
/* If allocating with modifiers fails, try again without. This can /* If allocating with modifiers fails, try again without. This can
* happen when the KMS display device supports modifiers but the * happen when the KMS display device supports modifiers but the
* GBM driver does not, e.g. the old i915 Mesa driver. */ * GBM driver does not, e.g. the old i915 Mesa driver. */
if (!output->gbm_surface) if (!output->gbm_surface)
#endif output->gbm_surface = gbm_surface_create(gbm,
{ mode->width, mode->height,
output->gbm_surface = output->gbm_format,
gbm_surface_create(b->gbm, mode->width, mode->height, output->gbm_bo_flags);
output->gbm_format, }
output->gbm_bo_flags);
} /* Init output state that depends on gl or gbm */
int
drm_output_init_egl(struct drm_output *output, struct drm_backend *b)
{
uint32_t format[2] = {
output->gbm_format,
fallback_format_for(output->gbm_format),
};
struct gl_renderer_output_options options = {
.drm_formats = format,
.drm_formats_count = 1,
};
assert(output->gbm_surface == NULL);
create_gbm_surface(b->gbm, output);
if (!output->gbm_surface) { if (!output->gbm_surface) {
weston_log("failed to create gbm surface\n"); weston_log("failed to create gbm surface\n");
return -1; return -1;

Loading…
Cancel
Save