render: unify getter for texture formats

Instead of having separate getters for shm formats and DMA-BUF
formats, use the same pattern as wlr_output_impl.get_primary_formats
with a single function which takes buffer caps as input.
This commit is contained in:
Simon Ser 2024-04-12 11:27:57 +02:00 committed by Kenny Levinsen
parent c63275d75e
commit 85c1eda721
12 changed files with 78 additions and 67 deletions

View file

@ -536,8 +536,8 @@ void vulkan_format_props_query(struct wlr_vk_device *dev,
props.shm.features = fmtp.formatProperties.optimalTilingFeatures;
props.shm.has_mutable_srgb = has_mutable_srgb;
dev->shm_formats[dev->shm_format_count] = format->drm;
++dev->shm_format_count;
wlr_drm_format_set_add(&dev->shm_texture_formats,
format->drm, DRM_FORMAT_MOD_LINEAR);
add_fmt_props = true;
}

View file

@ -956,17 +956,16 @@ bool vulkan_sync_render_buffer(struct wlr_vk_renderer *renderer,
return true;
}
static const uint32_t *vulkan_get_shm_texture_formats(
struct wlr_renderer *wlr_renderer, size_t *len) {
static const struct wlr_drm_format_set *vulkan_get_texture_formats(
struct wlr_renderer *wlr_renderer, uint32_t buffer_caps) {
struct wlr_vk_renderer *renderer = vulkan_get_renderer(wlr_renderer);
*len = renderer->dev->shm_format_count;
return renderer->dev->shm_formats;
}
static const struct wlr_drm_format_set *vulkan_get_dmabuf_texture_formats(
struct wlr_renderer *wlr_renderer) {
struct wlr_vk_renderer *renderer = vulkan_get_renderer(wlr_renderer);
return &renderer->dev->dmabuf_texture_formats;
if (buffer_caps & WLR_BUFFER_CAP_DMABUF) {
return &renderer->dev->dmabuf_texture_formats;
} else if (buffer_caps & WLR_BUFFER_CAP_DATA_PTR) {
return &renderer->dev->shm_texture_formats;
} else {
return NULL;
}
}
static const struct wlr_drm_format_set *vulkan_get_render_formats(
@ -1324,8 +1323,7 @@ static struct wlr_render_pass *vulkan_begin_buffer_pass(struct wlr_renderer *wlr
}
static const struct wlr_renderer_impl renderer_impl = {
.get_shm_texture_formats = vulkan_get_shm_texture_formats,
.get_dmabuf_texture_formats = vulkan_get_dmabuf_texture_formats,
.get_texture_formats = vulkan_get_texture_formats,
.get_render_formats = vulkan_get_render_formats,
.destroy = vulkan_destroy,
.get_drm_fd = vulkan_get_drm_fd,

View file

@ -623,9 +623,8 @@ struct wlr_vk_device *vulkan_device_create(struct wlr_vk_instance *ini,
size_t max_fmts;
const struct wlr_vk_format *fmts = vulkan_get_format_list(&max_fmts);
dev->shm_formats = calloc(max_fmts, sizeof(*dev->shm_formats));
dev->format_props = calloc(max_fmts, sizeof(*dev->format_props));
if (!dev->shm_formats || !dev->format_props) {
if (!dev->format_props) {
wlr_log_errno(WLR_ERROR, "allocation failed");
goto error;
}
@ -657,12 +656,12 @@ void vulkan_device_destroy(struct wlr_vk_device *dev) {
wlr_drm_format_set_finish(&dev->dmabuf_render_formats);
wlr_drm_format_set_finish(&dev->dmabuf_texture_formats);
wlr_drm_format_set_finish(&dev->shm_texture_formats);
for (unsigned i = 0u; i < dev->format_prop_count; ++i) {
vulkan_format_props_finish(&dev->format_props[i]);
}
free(dev->shm_formats);
free(dev->format_props);
free(dev);
}