output: split output_pick_cursor_format

Introduce output_pick_format that can be re-used for the primary
buffer too.
This commit is contained in:
Simon Ser 2021-04-07 09:57:40 +02:00
parent 4d603826c8
commit 233a2617cf

View file

@ -1008,7 +1008,8 @@ static void output_cursor_update_visible(struct wlr_output_cursor *cursor) {
cursor->visible = visible; cursor->visible = visible;
} }
static struct wlr_drm_format *output_pick_cursor_format(struct wlr_output *output) { static struct wlr_drm_format *output_pick_format(struct wlr_output *output,
const struct wlr_drm_format_set *display_formats) {
struct wlr_renderer *renderer = wlr_backend_get_renderer(output->backend); struct wlr_renderer *renderer = wlr_backend_get_renderer(output->backend);
struct wlr_allocator *allocator = backend_get_allocator(output->backend); struct wlr_allocator *allocator = backend_get_allocator(output->backend);
assert(renderer != NULL && allocator != NULL); assert(renderer != NULL && allocator != NULL);
@ -1020,19 +1021,6 @@ static struct wlr_drm_format *output_pick_cursor_format(struct wlr_output *outpu
return NULL; return NULL;
} }
const struct wlr_drm_format_set *display_formats;
if (output->impl->get_cursor_formats) {
display_formats =
output->impl->get_cursor_formats(output, allocator->buffer_caps);
if (display_formats == NULL) {
wlr_log(WLR_ERROR, "Failed to get display formats");
return NULL;
}
} else {
// The backend can display any format
display_formats = render_formats;
}
uint32_t fmt = DRM_FORMAT_ARGB8888; uint32_t fmt = DRM_FORMAT_ARGB8888;
const struct wlr_drm_format *render_format = const struct wlr_drm_format *render_format =
@ -1042,12 +1030,17 @@ static struct wlr_drm_format *output_pick_cursor_format(struct wlr_output *outpu
return NULL; return NULL;
} }
const struct wlr_drm_format *display_format = const struct wlr_drm_format *display_format;
wlr_drm_format_set_get(display_formats, fmt); if (display_formats != NULL) {
display_format = wlr_drm_format_set_get(display_formats, fmt);
if (display_format == NULL) { if (display_format == NULL) {
wlr_log(WLR_DEBUG, "Output doesn't support format 0x%"PRIX32, fmt); wlr_log(WLR_DEBUG, "Output doesn't support format 0x%"PRIX32, fmt);
return NULL; return NULL;
} }
} else {
// The output can display any format
display_format = render_format;
}
struct wlr_drm_format *format = struct wlr_drm_format *format =
wlr_drm_format_intersect(display_format, render_format); wlr_drm_format_intersect(display_format, render_format);
@ -1060,6 +1053,23 @@ static struct wlr_drm_format *output_pick_cursor_format(struct wlr_output *outpu
return format; return format;
} }
static struct wlr_drm_format *output_pick_cursor_format(struct wlr_output *output) {
struct wlr_allocator *allocator = backend_get_allocator(output->backend);
assert(allocator != NULL);
const struct wlr_drm_format_set *display_formats = NULL;
if (output->impl->get_cursor_formats) {
display_formats =
output->impl->get_cursor_formats(output, allocator->buffer_caps);
if (display_formats == NULL) {
wlr_log(WLR_ERROR, "Failed to get cursor display formats");
return NULL;
}
}
return output_pick_format(output, display_formats);
}
static struct wlr_buffer *render_cursor_buffer(struct wlr_output_cursor *cursor) { static struct wlr_buffer *render_cursor_buffer(struct wlr_output_cursor *cursor) {
struct wlr_output *output = cursor->output; struct wlr_output *output = cursor->output;