screencast: announce supported explicit modifiers

We query the supported modifiers via a wrapper and announce them via
PipeWire.

This wrapper queries the supported formats from wlroots and returns them
as a simple array. The purpose of this wrapper is to ease the use of the
query functions which are kept in the style of the equivalent egl
queries.
This commit is contained in:
columbarius 2021-07-11 01:04:10 +02:00
parent 18efde6dde
commit 29f86168b6

View file

@ -121,17 +121,36 @@ static struct spa_pod *build_format(struct spa_pod_builder *b, enum spa_video_fo
return spa_pod_builder_pop(b, &f[0]);
}
static bool build_modifierlist(struct xdpw_screencast_instance *cast,
uint32_t drm_format, uint64_t **modifiers, uint32_t *modifier_count) {
if (!wlr_query_dmabuf_modifiers(cast->ctx, drm_format, 0, NULL, modifier_count)) {
*modifiers = NULL;
*modifier_count = 0;
return false;
}
if (*modifier_count == 0) {
logprint(INFO, "wlroots: no modifiers available for format %u", drm_format);
*modifiers = NULL;
return true;
}
*modifiers = calloc(*modifier_count, sizeof(uint64_t));
bool ret = wlr_query_dmabuf_modifiers(cast->ctx, drm_format, *modifier_count, *modifiers, modifier_count);
logprint(INFO, "wlroots: num_modififiers %d", *modifier_count);
return ret;
}
static uint32_t build_formats(struct spa_pod_builder *b, struct xdpw_screencast_instance *cast,
const struct spa_pod *params[static 2]) {
uint32_t param_count;
uint32_t modifier_count = 1;
uint64_t modifier = DRM_FORMAT_MOD_INVALID;
uint32_t modifier_count;
uint64_t *modifiers = NULL;
if (cast->ctx->gbm && !cast->avoid_dmabufs) {
if (!cast->avoid_dmabufs &&
build_modifierlist(cast, cast->screencopy_frame_info[DMABUF].format, &modifiers, &modifier_count) && modifier_count > 0) {
param_count = 2;
params[0] = build_format(b, xdpw_format_pw_from_drm_fourcc(cast->screencopy_frame_info[DMABUF].format),
cast->screencopy_frame_info[DMABUF].width, cast->screencopy_frame_info[DMABUF].height, cast->framerate,
&modifier, modifier_count);
modifiers, modifier_count);
params[1] = build_format(b, xdpw_format_pw_from_drm_fourcc(cast->screencopy_frame_info[WL_SHM].format),
cast->screencopy_frame_info[WL_SHM].width, cast->screencopy_frame_info[WL_SHM].height, cast->framerate,
NULL, 0);
@ -141,7 +160,7 @@ static uint32_t build_formats(struct spa_pod_builder *b, struct xdpw_screencast_
cast->screencopy_frame_info[WL_SHM].width, cast->screencopy_frame_info[WL_SHM].height, cast->framerate,
NULL, 0);
}
free(modifiers);
return param_count;
}