xwayland: Move xwl_format array management to its own function
This creates xwl_add_format_and_mod_to_list, which is a helper that adds a format/mod combo to a xwl_format* list. This will be used by both the modifier event handling and the tranche format handling. Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
This commit is contained in:
parent
16e7cdba48
commit
2930eb113b
|
@ -213,40 +213,52 @@ xwl_dmabuf_handle_format(void *data, struct zwp_linux_dmabuf_v1 *dmabuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xwl_dmabuf_handle_modifier(void *data, struct zwp_linux_dmabuf_v1 *dmabuf,
|
xwl_add_format_and_mod_to_list(struct xwl_format **formats,
|
||||||
uint32_t format, uint32_t modifier_hi,
|
uint32_t *num_formats,
|
||||||
uint32_t modifier_lo)
|
uint32_t format,
|
||||||
|
uint64_t modifier)
|
||||||
{
|
{
|
||||||
struct xwl_screen *xwl_screen = data;
|
|
||||||
struct xwl_format *xwl_format = NULL;
|
struct xwl_format *xwl_format = NULL;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < xwl_screen->num_formats; i++) {
|
for (i = 0; i < *num_formats; i++) {
|
||||||
if (xwl_screen->formats[i].format == format) {
|
if ((*formats)[i].format == format) {
|
||||||
xwl_format = &xwl_screen->formats[i];
|
xwl_format = &(*formats)[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xwl_format == NULL) {
|
if (xwl_format == NULL) {
|
||||||
xwl_screen->num_formats++;
|
(*num_formats)++;
|
||||||
xwl_screen->formats = realloc(xwl_screen->formats,
|
*formats = xnfrealloc(*formats, *num_formats * sizeof(*xwl_format));
|
||||||
xwl_screen->num_formats * sizeof(*xwl_format));
|
xwl_format = &(*formats)[*num_formats - 1];
|
||||||
if (!xwl_screen->formats)
|
|
||||||
return;
|
|
||||||
xwl_format = &xwl_screen->formats[xwl_screen->num_formats - 1];
|
|
||||||
xwl_format->format = format;
|
xwl_format->format = format;
|
||||||
xwl_format->num_modifiers = 0;
|
xwl_format->num_modifiers = 0;
|
||||||
xwl_format->modifiers = NULL;
|
xwl_format->modifiers = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < xwl_format->num_modifiers; i++) {
|
||||||
|
/* don't add it if the modifier already exists */
|
||||||
|
if (xwl_format->modifiers[i] == modifier)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
xwl_format->num_modifiers++;
|
xwl_format->num_modifiers++;
|
||||||
xwl_format->modifiers = realloc(xwl_format->modifiers,
|
xwl_format->modifiers = xnfrealloc(xwl_format->modifiers,
|
||||||
xwl_format->num_modifiers * sizeof(uint64_t));
|
xwl_format->num_modifiers * sizeof(uint64_t));
|
||||||
if (!xwl_format->modifiers)
|
xwl_format->modifiers[xwl_format->num_modifiers - 1] = modifier;
|
||||||
return;
|
}
|
||||||
xwl_format->modifiers[xwl_format->num_modifiers - 1] = (uint64_t) modifier_lo;
|
|
||||||
xwl_format->modifiers[xwl_format->num_modifiers - 1] |= (uint64_t) modifier_hi << 32;
|
static void
|
||||||
|
xwl_dmabuf_handle_modifier(void *data, struct zwp_linux_dmabuf_v1 *dmabuf,
|
||||||
|
uint32_t format, uint32_t modifier_hi,
|
||||||
|
uint32_t modifier_lo)
|
||||||
|
{
|
||||||
|
struct xwl_screen *xwl_screen = data;
|
||||||
|
|
||||||
|
xwl_add_format_and_mod_to_list(&xwl_screen->formats, &xwl_screen->num_formats,
|
||||||
|
format,
|
||||||
|
((uint64_t)modifier_hi << 32 | (uint64_t)modifier_lo));
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct zwp_linux_dmabuf_v1_listener xwl_dmabuf_listener = {
|
static const struct zwp_linux_dmabuf_v1_listener xwl_dmabuf_listener = {
|
||||||
|
|
Loading…
Reference in New Issue