diff options
author | Simon Ser <contact@emersion.fr> | 2021-11-30 20:26:11 +0100 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2021-11-30 20:49:33 +0100 |
commit | 697a1cd0f59f9a64f02e47b0f62a7184d04ad794 (patch) | |
tree | 51950c11cdf1c45573a4e3573bb4b2286ebafd43 | |
parent | e93435016e0dfad0fefed3b68a9b60fe453c723e (diff) |
output: add wlr_output_get_primary_formats
This allows compositors to get primary formats without manually
calling wlr_output_impl.get_primary_formats.
For example, the Sway patch for linux-dmabuf feedback [1] needs
this.
[1]: https://github.com/swaywm/sway/pull/6313
-rw-r--r-- | include/wlr/types/wlr_output.h | 10 | ||||
-rw-r--r-- | types/output/output.c | 30 | ||||
-rw-r--r-- | types/output/render.c | 12 |
3 files changed, 32 insertions, 20 deletions
diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 7d7fbaad..9e18a216 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -460,6 +460,16 @@ void wlr_output_lock_software_cursors(struct wlr_output *output, bool lock); */ void wlr_output_render_software_cursors(struct wlr_output *output, pixman_region32_t *damage); +/** + * Get the set of DRM formats suitable for the primary buffer, assuming a + * buffer with the specified capabilities. + * + * NULL is returned if the backend doesn't have any format constraint, ie. all + * formats are supported. An empty set is returned if the backend doesn't + * support any format. + */ +const struct wlr_drm_format_set *wlr_output_get_primary_formats( + struct wlr_output *output, uint32_t buffer_caps); struct wlr_output_cursor *wlr_output_cursor_create(struct wlr_output *output); diff --git a/types/output/output.c b/types/output/output.c index d6f8f97a..e82ec1dc 100644 --- a/types/output/output.c +++ b/types/output/output.c @@ -560,16 +560,8 @@ static bool output_basic_test(struct wlr_output *output) { struct wlr_allocator *allocator = output->allocator; assert(allocator != NULL); - const struct wlr_drm_format_set *display_formats = NULL; - if (output->impl->get_primary_formats) { - display_formats = - output->impl->get_primary_formats(output, allocator->buffer_caps); - if (display_formats == NULL) { - wlr_log(WLR_ERROR, "Failed to get primary display formats"); - return false; - } - } - + const struct wlr_drm_format_set *display_formats = + wlr_output_get_primary_formats(output, allocator->buffer_caps); struct wlr_drm_format *format = output_pick_format(output, display_formats, output->pending.render_format); if (format == NULL) { @@ -868,3 +860,21 @@ void wlr_output_damage_whole(struct wlr_output *output) { pixman_region32_fini(&damage); } + +const struct wlr_drm_format_set *wlr_output_get_primary_formats( + struct wlr_output *output, uint32_t buffer_caps) { + if (!output->impl->get_primary_formats) { + return NULL; + } + + const struct wlr_drm_format_set *formats = + output->impl->get_primary_formats(output, buffer_caps); + if (formats == NULL) { + wlr_log(WLR_ERROR, "Failed to get primary display formats"); + + static const struct wlr_drm_format_set empty_format_set = {0}; + return &empty_format_set; + } + + return formats; +} diff --git a/types/output/render.c b/types/output/render.c index f23d1a9a..97c62a58 100644 --- a/types/output/render.c +++ b/types/output/render.c @@ -51,16 +51,8 @@ static bool output_create_swapchain(struct wlr_output *output, struct wlr_allocator *allocator = output->allocator; assert(allocator != NULL); - const struct wlr_drm_format_set *display_formats = NULL; - if (output->impl->get_primary_formats) { - display_formats = - output->impl->get_primary_formats(output, allocator->buffer_caps); - if (display_formats == NULL) { - wlr_log(WLR_ERROR, "Failed to get primary display formats"); - return false; - } - } - + const struct wlr_drm_format_set *display_formats = + wlr_output_get_primary_formats(output, allocator->buffer_caps); struct wlr_drm_format *format = output_pick_format(output, display_formats, output->render_format); if (format == NULL) { |