backend/drm: extract linear format creation into function

Simplifies error handling.
This commit is contained in:
Simon Ser 2020-12-18 12:47:50 +01:00 committed by Ilia Bozhinov
parent c4635c68d2
commit 92a0fc0435
1 changed files with 13 additions and 6 deletions

View File

@ -208,6 +208,18 @@ static uint32_t strip_alpha_channel(uint32_t format) {
} }
} }
static struct wlr_drm_format *create_linear_format(uint32_t format) {
struct wlr_drm_format *fmt = wlr_drm_format_create(format);
if (fmt == NULL) {
return NULL;
}
if (!wlr_drm_format_add(&fmt, DRM_FORMAT_MOD_LINEAR)) {
free(fmt);
return NULL;
}
return fmt;
}
bool drm_plane_init_surface(struct wlr_drm_plane *plane, bool drm_plane_init_surface(struct wlr_drm_plane *plane,
struct wlr_drm_backend *drm, int32_t width, uint32_t height, struct wlr_drm_backend *drm, int32_t width, uint32_t height,
uint32_t format, bool force_linear, bool with_modifiers) { uint32_t format, bool force_linear, bool with_modifiers) {
@ -249,16 +261,11 @@ bool drm_plane_init_surface(struct wlr_drm_plane *plane,
drm_format = wlr_drm_format_create(format); drm_format = wlr_drm_format_create(format);
} }
struct wlr_drm_format *drm_format_linear = wlr_drm_format_create(format); struct wlr_drm_format *drm_format_linear = create_linear_format(format);
if (drm_format_linear == NULL) { if (drm_format_linear == NULL) {
free(drm_format); free(drm_format);
return false; return false;
} }
if (!wlr_drm_format_add(&drm_format_linear, DRM_FORMAT_MOD_LINEAR)) {
free(drm_format_linear);
free(drm_format);
return false;
}
if (force_linear) { if (force_linear) {
free(drm_format); free(drm_format);