drm-formats: remove create() and destroy() from the API

Since commit "drm-formats: save result of intersection in the first
array", every block of code where weston_drm_format_array_create() and
destroy() are being called could use init() and fini() instead.

Remove these two functions from the API to make it leaner. This patch
also modifies the code that depends on these functions to use init() and
fini().

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
Reviewed-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
dev
Leandro Ribeiro 3 years ago committed by Pekka Paalanen
parent c51d4ad9c8
commit 0750ceae6c
  1. 67
      libweston/drm-formats.c
  2. 6
      libweston/libweston-internal.h
  3. 469
      tests/drm-formats-test.c

@ -31,27 +31,6 @@
#include "libweston-internal.h" #include "libweston-internal.h"
#include "shared/weston-drm-fourcc.h" #include "shared/weston-drm-fourcc.h"
/**
* Create and initialize a weston_drm_format_array
*
* @return The weston_drm_format_array, or NULL on failure
*/
WL_EXPORT struct weston_drm_format_array *
weston_drm_format_array_create(void)
{
struct weston_drm_format_array *formats;
formats = zalloc(sizeof(*formats));
if (!formats) {
weston_log("%s: out of memory\n", __func__);
return NULL;
}
weston_drm_format_array_init(formats);
return formats;
}
/** /**
* Initialize a weston_drm_format_array * Initialize a weston_drm_format_array
* *
@ -63,18 +42,6 @@ weston_drm_format_array_init(struct weston_drm_format_array *formats)
wl_array_init(&formats->arr); wl_array_init(&formats->arr);
} }
/**
* Fini and destroy a weston_drm_format_array
*
* @param formats The weston_drm_format_array to destroy
*/
WL_EXPORT void
weston_drm_format_array_destroy(struct weston_drm_format_array *formats)
{
weston_drm_format_array_fini(formats);
free(formats);
}
/** /**
* Finish a weston_drm_format_array * Finish a weston_drm_format_array
* *
@ -330,13 +297,11 @@ WL_EXPORT int
weston_drm_format_array_intersect(struct weston_drm_format_array *formats_A, weston_drm_format_array_intersect(struct weston_drm_format_array *formats_A,
const struct weston_drm_format_array *formats_B) const struct weston_drm_format_array *formats_B)
{ {
struct weston_drm_format_array *formats_result; struct weston_drm_format_array formats_result;
struct weston_drm_format *fmt_result, *fmt_A, *fmt_B; struct weston_drm_format *fmt_result, *fmt_A, *fmt_B;
int ret; int ret;
formats_result = weston_drm_format_array_create(); weston_drm_format_array_init(&formats_result);
if (!formats_result)
return -1;
wl_array_for_each(fmt_A, &formats_A->arr) { wl_array_for_each(fmt_A, &formats_A->arr) {
fmt_B = weston_drm_format_array_find_format(formats_B, fmt_B = weston_drm_format_array_find_format(formats_B,
@ -344,7 +309,7 @@ weston_drm_format_array_intersect(struct weston_drm_format_array *formats_A,
if (!fmt_B) if (!fmt_B)
continue; continue;
fmt_result = weston_drm_format_array_add_format(formats_result, fmt_result = weston_drm_format_array_add_format(&formats_result,
fmt_A->format); fmt_A->format);
if (!fmt_result) if (!fmt_result)
goto err; goto err;
@ -354,18 +319,18 @@ weston_drm_format_array_intersect(struct weston_drm_format_array *formats_A,
goto err; goto err;
if (fmt_result->modifiers.size == 0) if (fmt_result->modifiers.size == 0)
weston_drm_format_array_remove_latest_format(formats_result); weston_drm_format_array_remove_latest_format(&formats_result);
} }
ret = weston_drm_format_array_replace(formats_A, formats_result); ret = weston_drm_format_array_replace(formats_A, &formats_result);
if (ret < 0) if (ret < 0)
goto err; goto err;
weston_drm_format_array_destroy(formats_result); weston_drm_format_array_fini(&formats_result);
return 0; return 0;
err: err:
weston_drm_format_array_destroy(formats_result); weston_drm_format_array_fini(&formats_result);
return -1; return -1;
} }
@ -405,19 +370,17 @@ WL_EXPORT int
weston_drm_format_array_subtract(struct weston_drm_format_array *formats_A, weston_drm_format_array_subtract(struct weston_drm_format_array *formats_A,
const struct weston_drm_format_array *formats_B) const struct weston_drm_format_array *formats_B)
{ {
struct weston_drm_format_array *formats_result; struct weston_drm_format_array formats_result;
struct weston_drm_format *fmt_result, *fmt_A, *fmt_B; struct weston_drm_format *fmt_result, *fmt_A, *fmt_B;
int ret; int ret;
formats_result = weston_drm_format_array_create(); weston_drm_format_array_init(&formats_result);
if (!formats_result)
return -1;
wl_array_for_each(fmt_A, &formats_A->arr) { wl_array_for_each(fmt_A, &formats_A->arr) {
fmt_B = weston_drm_format_array_find_format(formats_B, fmt_B = weston_drm_format_array_find_format(formats_B,
fmt_A->format); fmt_A->format);
if (!fmt_B) { if (!fmt_B) {
ret = add_format_and_modifiers(formats_result, fmt_A->format, ret = add_format_and_modifiers(&formats_result, fmt_A->format,
&fmt_A->modifiers); &fmt_A->modifiers);
if (ret < 0) if (ret < 0)
goto err; goto err;
@ -425,7 +388,7 @@ weston_drm_format_array_subtract(struct weston_drm_format_array *formats_A,
continue; continue;
} }
fmt_result = weston_drm_format_array_add_format(formats_result, fmt_result = weston_drm_format_array_add_format(&formats_result,
fmt_A->format); fmt_A->format);
if (!fmt_result) if (!fmt_result)
goto err; goto err;
@ -435,18 +398,18 @@ weston_drm_format_array_subtract(struct weston_drm_format_array *formats_A,
goto err; goto err;
if (fmt_result->modifiers.size == 0) if (fmt_result->modifiers.size == 0)
weston_drm_format_array_remove_latest_format(formats_result); weston_drm_format_array_remove_latest_format(&formats_result);
} }
ret = weston_drm_format_array_replace(formats_A, formats_result); ret = weston_drm_format_array_replace(formats_A, &formats_result);
if (ret < 0) if (ret < 0)
goto err; goto err;
weston_drm_format_array_destroy(formats_result); weston_drm_format_array_fini(&formats_result);
return 0; return 0;
err: err:
weston_drm_format_array_destroy(formats_result); weston_drm_format_array_fini(&formats_result);
return -1; return -1;
} }

@ -337,15 +337,9 @@ struct weston_drm_format_array {
struct wl_array arr; struct wl_array arr;
}; };
struct weston_drm_format_array *
weston_drm_format_array_create(void);
void void
weston_drm_format_array_init(struct weston_drm_format_array *formats); weston_drm_format_array_init(struct weston_drm_format_array *formats);
void
weston_drm_format_array_destroy(struct weston_drm_format_array *formats);
void void
weston_drm_format_array_fini(struct weston_drm_format_array *formats); weston_drm_format_array_fini(struct weston_drm_format_array *formats);

@ -73,139 +73,129 @@ format_array_add_format_and_modifiers(struct weston_drm_format_array *formats,
TEST(basic_operations) TEST(basic_operations)
{ {
struct weston_drm_format_array *format_array; struct weston_drm_format_array format_array;
struct weston_drm_format *fmt; struct weston_drm_format *fmt;
uint32_t formats[] = {1, 2, 3, 4, 5}; uint32_t formats[] = {1, 2, 3, 4, 5};
uint64_t modifiers[] = {11, 12, 13, 14, 15}; uint64_t modifiers[] = {11, 12, 13, 14, 15};
unsigned int i, j; unsigned int i, j;
format_array = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array);
assert(format_array);
ADD_FORMATS_AND_MODS(format_array, formats, modifiers); ADD_FORMATS_AND_MODS(&format_array, formats, modifiers);
for (i = 0; i < ARRAY_LENGTH(formats); i++) { for (i = 0; i < ARRAY_LENGTH(formats); i++) {
fmt = weston_drm_format_array_find_format(format_array, formats[i]); fmt = weston_drm_format_array_find_format(&format_array, formats[i]);
assert(fmt && fmt->format == formats[i]); assert(fmt && fmt->format == formats[i]);
for (j = 0; j < ARRAY_LENGTH(modifiers); j++) for (j = 0; j < ARRAY_LENGTH(modifiers); j++)
assert(weston_drm_format_has_modifier(fmt, modifiers[j])); assert(weston_drm_format_has_modifier(fmt, modifiers[j]));
} }
weston_drm_format_array_destroy(format_array); weston_drm_format_array_fini(&format_array);
} }
TEST(compare_arrays_same_content) TEST(compare_arrays_same_content)
{ {
struct weston_drm_format_array *format_array_A, *format_array_B; struct weston_drm_format_array format_array_A, format_array_B;
uint32_t formats[] = {1, 2, 3, 4, 5}; uint32_t formats[] = {1, 2, 3, 4, 5};
uint64_t modifiers[] = {11, 12, 13, 14, 15}; uint64_t modifiers[] = {11, 12, 13, 14, 15};
format_array_A = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_A);
format_array_B = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_B);
assert(format_array_A);
assert(format_array_B);
/* Both are empty arrays, so they have the same content. */ /* Both are empty arrays, so they have the same content. */
assert(weston_drm_format_array_equal(format_array_A, format_array_B)); assert(weston_drm_format_array_equal(&format_array_A, &format_array_B));
/* Test non-empty arrays with same content. */ /* Test non-empty arrays with same content. */
ADD_FORMATS_AND_MODS(format_array_A, formats, modifiers); ADD_FORMATS_AND_MODS(&format_array_A, formats, modifiers);
ADD_FORMATS_AND_MODS(format_array_B, formats, modifiers); ADD_FORMATS_AND_MODS(&format_array_B, formats, modifiers);
assert(weston_drm_format_array_equal(format_array_A, format_array_B)); assert(weston_drm_format_array_equal(&format_array_A, &format_array_B));
/* Test non-empty arrays with same content, but add elements to B in /* Test non-empty arrays with same content, but add elements to B in
* reverse order. This is important as in the future we may keep * reverse order. This is important as in the future we may keep
* DRM-format arrays ordered to improve performance. */ * DRM-format arrays ordered to improve performance. */
weston_drm_format_array_fini(format_array_B); weston_drm_format_array_fini(&format_array_B);
weston_drm_format_array_init(format_array_B); weston_drm_format_array_init(&format_array_B);
ADD_FORMATS_AND_MODS_REVERSE(format_array_B, formats, modifiers); ADD_FORMATS_AND_MODS_REVERSE(&format_array_B, formats, modifiers);
assert(weston_drm_format_array_equal(format_array_A, format_array_B)); assert(weston_drm_format_array_equal(&format_array_A, &format_array_B));
weston_drm_format_array_destroy(format_array_A); weston_drm_format_array_fini(&format_array_A);
weston_drm_format_array_destroy(format_array_B); weston_drm_format_array_fini(&format_array_B);
} }
TEST(compare_arrays_exclusive_content) TEST(compare_arrays_exclusive_content)
{ {
struct weston_drm_format_array *format_array_A, *format_array_B; struct weston_drm_format_array format_array_A, format_array_B;
uint32_t formats_A[] = {1, 2, 3, 4, 5}; uint32_t formats_A[] = {1, 2, 3, 4, 5};
uint32_t formats_B[] = {6, 7, 8, 9, 10}; uint32_t formats_B[] = {6, 7, 8, 9, 10};
uint64_t modifiers_A[] = {11, 12, 13, 14, 15}; uint64_t modifiers_A[] = {11, 12, 13, 14, 15};
uint64_t modifiers_B[] = {16, 17, 18, 19, 20}; uint64_t modifiers_B[] = {16, 17, 18, 19, 20};
format_array_A = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_A);
format_array_B = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_B);
assert(format_array_A);
assert(format_array_B);
/* Arrays with formats that are mutually exclusive. */ /* Arrays with formats that are mutually exclusive. */
ADD_FORMATS_AND_MODS(format_array_A, formats_A, modifiers_A); ADD_FORMATS_AND_MODS(&format_array_A, formats_A, modifiers_A);
ADD_FORMATS_AND_MODS(format_array_B, formats_B, modifiers_B); ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers_B);
assert(!weston_drm_format_array_equal(format_array_A, format_array_B)); assert(!weston_drm_format_array_equal(&format_array_A, &format_array_B));
weston_drm_format_array_destroy(format_array_A); weston_drm_format_array_fini(&format_array_A);
weston_drm_format_array_destroy(format_array_B); weston_drm_format_array_fini(&format_array_B);
} }
TEST(replace_array) TEST(replace_array)
{ {
struct weston_drm_format_array *format_array_A, *format_array_B; struct weston_drm_format_array format_array_A, format_array_B;
uint32_t formats[] = {1, 2, 3, 4, 5}; uint32_t formats[] = {1, 2, 3, 4, 5};
uint64_t modifiers[] = {11, 12, 13, 14, 15}; uint64_t modifiers[] = {11, 12, 13, 14, 15};
int ret; int ret;
format_array_A = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_A);
format_array_B = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_B);
assert(format_array_A);
assert(format_array_B);
/* Replace content of B with the content of A, so they should /* Replace content of B with the content of A, so they should
* have the same content. */ * have the same content. */
ADD_FORMATS_AND_MODS(format_array_A, formats, modifiers); ADD_FORMATS_AND_MODS(&format_array_A, formats, modifiers);
ret = weston_drm_format_array_replace(format_array_B, format_array_A); ret = weston_drm_format_array_replace(&format_array_B, &format_array_A);
assert(ret == 0); assert(ret == 0);
assert(weston_drm_format_array_equal(format_array_A, format_array_B)); assert(weston_drm_format_array_equal(&format_array_A, &format_array_B));
weston_drm_format_array_destroy(format_array_A); weston_drm_format_array_fini(&format_array_A);
weston_drm_format_array_destroy(format_array_B); weston_drm_format_array_fini(&format_array_B);
} }
TEST(remove_from_array) TEST(remove_from_array)
{ {
struct weston_drm_format_array *format_array_A, *format_array_B, *format_array_C; struct weston_drm_format_array format_array_A, format_array_B, format_array_C;
uint32_t formats_A[] = {1, 2, 3, 4, 5}; uint32_t formats_A[] = {1, 2, 3, 4, 5};
uint32_t formats_B[] = {1, 2, 3, 4}; uint32_t formats_B[] = {1, 2, 3, 4};
uint32_t formats_C[] = {1, 2, 3, 4, 6}; uint32_t formats_C[] = {1, 2, 3, 4, 6};
uint64_t modifiers[] = {11, 12, 13, 14, 15}; uint64_t modifiers[] = {11, 12, 13, 14, 15};
format_array_A = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_A);
format_array_B = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_B);
format_array_C = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_C);
assert(format_array_A);
assert(format_array_B);
assert(format_array_C);
/* After removing latest added format from array A, it should /* After removing latest added format from array A, it should
* be equal to B. */ * be equal to B. */
ADD_FORMATS_AND_MODS(format_array_A, formats_A, modifiers); ADD_FORMATS_AND_MODS(&format_array_A, formats_A, modifiers);
ADD_FORMATS_AND_MODS(format_array_B, formats_B, modifiers); ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers);
weston_drm_format_array_remove_latest_format(format_array_A); weston_drm_format_array_remove_latest_format(&format_array_A);
assert(weston_drm_format_array_equal(format_array_A, format_array_B)); assert(weston_drm_format_array_equal(&format_array_A, &format_array_B));
/* Add 6 to the format array A, so it should be equal to C. */ /* Add 6 to the format array A, so it should be equal to C. */
ADD_FORMATS_AND_MODS(format_array_A, (uint32_t[]){6}, modifiers); ADD_FORMATS_AND_MODS(&format_array_A, (uint32_t[]){6}, modifiers);
ADD_FORMATS_AND_MODS(format_array_C, formats_C, modifiers); ADD_FORMATS_AND_MODS(&format_array_C, formats_C, modifiers);
assert(weston_drm_format_array_equal(format_array_A, format_array_C)); assert(weston_drm_format_array_equal(&format_array_A, &format_array_C));
weston_drm_format_array_destroy(format_array_A); weston_drm_format_array_fini(&format_array_A);
weston_drm_format_array_destroy(format_array_B); weston_drm_format_array_fini(&format_array_B);
weston_drm_format_array_destroy(format_array_C); weston_drm_format_array_fini(&format_array_C);
} }
TEST(join_arrays) TEST(join_arrays)
{ {
struct weston_drm_format_array *format_array_A, *format_array_B; struct weston_drm_format_array format_array_A, format_array_B;
struct weston_drm_format_array *format_array_C; struct weston_drm_format_array format_array_C;
uint32_t formats_A[] = {1, 2, 6, 9, 10}; uint32_t formats_A[] = {1, 2, 6, 9, 10};
uint32_t formats_B[] = {2, 5, 7, 9, 10}; uint32_t formats_B[] = {2, 5, 7, 9, 10};
uint64_t modifiers_A[] = {1, 2, 3, 4, 7}; uint64_t modifiers_A[] = {1, 2, 3, 4, 7};
@ -213,133 +203,122 @@ TEST(join_arrays)
uint64_t modifiers_join[] = {0, 1, 2, 3, 4, 5, 6, 7}; uint64_t modifiers_join[] = {0, 1, 2, 3, 4, 5, 6, 7};
int ret; int ret;
format_array_A = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_A);
format_array_B = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_B);
format_array_C = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_C);
assert(format_array_A);
assert(format_array_B);
assert(format_array_C);
ADD_FORMATS_AND_MODS(format_array_A, formats_A, modifiers_A); ADD_FORMATS_AND_MODS(&format_array_A, formats_A, modifiers_A);
ADD_FORMATS_AND_MODS(format_array_B, formats_B, modifiers_B); ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers_B);
ret = weston_drm_format_array_join(format_array_A, format_array_B); ret = weston_drm_format_array_join(&format_array_A, &format_array_B);
assert(ret == 0); assert(ret == 0);
/* The result of the joint (which is saved in A) should have /* The result of the joint (which is saved in A) should have
* the same content as C. */ * the same content as C. */
ADD_FORMATS_AND_MODS(format_array_C, (uint32_t[]){1}, modifiers_A); ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){1}, modifiers_A);
ADD_FORMATS_AND_MODS(format_array_C, (uint32_t[]){2}, modifiers_join); ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){2}, modifiers_join);
ADD_FORMATS_AND_MODS(format_array_C, (uint32_t[]){5}, modifiers_B); ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){5}, modifiers_B);
ADD_FORMATS_AND_MODS(format_array_C, (uint32_t[]){6}, modifiers_A); ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){6}, modifiers_A);
ADD_FORMATS_AND_MODS(format_array_C, (uint32_t[]){7}, modifiers_B); ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){7}, modifiers_B);
ADD_FORMATS_AND_MODS(format_array_C, (uint32_t[]){9}, modifiers_join); ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){9}, modifiers_join);
ADD_FORMATS_AND_MODS(format_array_C, (uint32_t[]){10}, modifiers_join); ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){10}, modifiers_join);
assert(weston_drm_format_array_equal(format_array_A, format_array_C)); assert(weston_drm_format_array_equal(&format_array_A, &format_array_C));
weston_drm_format_array_destroy(format_array_A); weston_drm_format_array_fini(&format_array_A);
weston_drm_format_array_destroy(format_array_B); weston_drm_format_array_fini(&format_array_B);
weston_drm_format_array_destroy(format_array_C); weston_drm_format_array_fini(&format_array_C);
} }
TEST(join_arrays_same_content) TEST(join_arrays_same_content)
{ {
struct weston_drm_format_array *format_array_A, *format_array_B; struct weston_drm_format_array format_array_A, format_array_B;
uint32_t formats[] = {1, 2, 3, 4, 5}; uint32_t formats[] = {1, 2, 3, 4, 5};
uint64_t modifiers[] = {11, 12, 13, 14, 15}; uint64_t modifiers[] = {11, 12, 13, 14, 15};
int ret; int ret;
format_array_A = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_A);
format_array_B = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_B);
assert(format_array_A);
assert(format_array_B);
/* Joint of empty arrays must be empty. */ /* Joint of empty arrays must be empty. */
ret = weston_drm_format_array_join(format_array_A, format_array_B); ret = weston_drm_format_array_join(&format_array_A, &format_array_B);
assert(ret == 0); assert(ret == 0);
assert(format_array_A->arr.size == 0); assert(format_array_A.arr.size == 0);
/* Join B, which is empty, with A, which is non-empty. The joint (which /* Join B, which is empty, with A, which is non-empty. The joint (which
* is saved in B) should have the same content as A. */ * is saved in B) should have the same content as A. */
ADD_FORMATS_AND_MODS(format_array_A, formats, modifiers); ADD_FORMATS_AND_MODS(&format_array_A, formats, modifiers);
ret = weston_drm_format_array_join(format_array_B, format_array_A); ret = weston_drm_format_array_join(&format_array_B, &format_array_A);
assert(ret == 0); assert(ret == 0);
assert(weston_drm_format_array_equal(format_array_A, format_array_B)); assert(weston_drm_format_array_equal(&format_array_A, &format_array_B));
/* Now A and B are non-empty and have the same content. The joint (which /* Now A and B are non-empty and have the same content. The joint (which
* is saved in A) should not change its content. */ * is saved in A) should not change its content. */
ret = weston_drm_format_array_join(format_array_A, format_array_B); ret = weston_drm_format_array_join(&format_array_A, &format_array_B);
assert(ret == 0); assert(ret == 0);
assert(weston_drm_format_array_equal(format_array_A, format_array_B)); assert(weston_drm_format_array_equal(&format_array_A, &format_array_B));
weston_drm_format_array_destroy(format_array_A); weston_drm_format_array_fini(&format_array_A);
weston_drm_format_array_destroy(format_array_B); weston_drm_format_array_fini(&format_array_B);
} }
TEST(join_arrays_exclusive_content) TEST(join_arrays_exclusive_content)
{ {
struct weston_drm_format_array *format_array_A, *format_array_B; struct weston_drm_format_array format_array_A, format_array_B;
struct weston_drm_format_array *format_array_C; struct weston_drm_format_array format_array_C;
uint32_t formats_A[] = {1, 2, 3, 4, 5}; uint32_t formats_A[] = {1, 2, 3, 4, 5};
uint32_t formats_B[] = {6, 7, 8, 9, 10}; uint32_t formats_B[] = {6, 7, 8, 9, 10};
uint32_t formats_C[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; uint32_t formats_C[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
uint64_t modifiers[] = {11, 12, 13, 14, 15}; uint64_t modifiers[] = {11, 12, 13, 14, 15};
int ret; int ret;
format_array_A = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_A);
format_array_B = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_B);
format_array_C = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_C);
assert(format_array_A);
assert(format_array_B);
assert(format_array_C);
/* The joint of DRM-format arrays A and B should be equal to C. */ /* The joint of DRM-format arrays A and B should be equal to C. */
ADD_FORMATS_AND_MODS(format_array_A, formats_A, modifiers); ADD_FORMATS_AND_MODS(&format_array_A, formats_A, modifiers);
ADD_FORMATS_AND_MODS(format_array_B, formats_B, modifiers); ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers);
ADD_FORMATS_AND_MODS(format_array_C, formats_C, modifiers); ADD_FORMATS_AND_MODS(&format_array_C, formats_C, modifiers);
ret = weston_drm_format_array_join(format_array_A, format_array_B); ret = weston_drm_format_array_join(&format_array_A, &format_array_B);
assert(ret == 0); assert(ret == 0);
assert(weston_drm_format_array_equal(format_array_A, format_array_C)); assert(weston_drm_format_array_equal(&format_array_A, &format_array_C));
weston_drm_format_array_destroy(format_array_A); weston_drm_format_array_fini(&format_array_A);
weston_drm_format_array_destroy(format_array_B); weston_drm_format_array_fini(&format_array_B);
weston_drm_format_array_destroy(format_array_C); weston_drm_format_array_fini(&format_array_C);
} }
TEST(join_arrays_modifier_invalid) TEST(join_arrays_modifier_invalid)
{ {
struct weston_drm_format_array *format_array_A, *format_array_B; struct weston_drm_format_array format_array_A, format_array_B;
struct weston_drm_format_array *format_array_C; struct weston_drm_format_array format_array_C;
uint64_t regular_modifiers[] = {1, 2, 3, 4, 5}; uint64_t regular_modifiers[] = {1, 2, 3, 4, 5};
uint64_t modifier_invalid[] = {DRM_FORMAT_MOD_INVALID}; uint64_t modifier_invalid[] = {DRM_FORMAT_MOD_INVALID};
uint64_t regular_modifiers_plus_invalid[] = {1, 2, 3, 4, 5, DRM_FORMAT_MOD_INVALID}; uint64_t regular_modifiers_plus_invalid[] = {1, 2, 3, 4, 5, DRM_FORMAT_MOD_INVALID};
int ret; int ret;
format_array_A = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_A);
format_array_B = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_B);
format_array_C = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_C);
assert(format_array_A);
assert(format_array_B);
assert(format_array_C);
/* DRM-format array A has only one format with MOD_INVALID, and B has /* DRM-format array A has only one format with MOD_INVALID, and B has
* the same format but with a regular set of formats. The joint should * the same format but with a regular set of formats. The joint should
* contain both MOD_INVALID and the regular modifiers. */ * contain both MOD_INVALID and the regular modifiers. */
ADD_FORMATS_AND_MODS(format_array_A, (uint32_t[]){1}, modifier_invalid); ADD_FORMATS_AND_MODS(&format_array_A, (uint32_t[]){1}, modifier_invalid);
ADD_FORMATS_AND_MODS(format_array_B, (uint32_t[]){1}, regular_modifiers); ADD_FORMATS_AND_MODS(&format_array_B, (uint32_t[]){1}, regular_modifiers);
ADD_FORMATS_AND_MODS(format_array_C, (uint32_t[]){1}, regular_modifiers_plus_invalid); ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){1}, regular_modifiers_plus_invalid);
ret = weston_drm_format_array_join(format_array_A, format_array_B); ret = weston_drm_format_array_join(&format_array_A, &format_array_B);
assert(ret == 0); assert(ret == 0);
assert(weston_drm_format_array_equal(format_array_A, format_array_C)); assert(weston_drm_format_array_equal(&format_array_A, &format_array_C));
weston_drm_format_array_destroy(format_array_A); weston_drm_format_array_fini(&format_array_A);
weston_drm_format_array_destroy(format_array_B); weston_drm_format_array_fini(&format_array_B);
weston_drm_format_array_destroy(format_array_C); weston_drm_format_array_fini(&format_array_C);
} }
TEST(intersect_arrays) TEST(intersect_arrays)
{ {
struct weston_drm_format_array *format_array_A, *format_array_B; struct weston_drm_format_array format_array_A, format_array_B;
struct weston_drm_format_array *format_array_C; struct weston_drm_format_array format_array_C;
uint32_t formats_A[] = {1, 2, 6, 9, 10}; uint32_t formats_A[] = {1, 2, 6, 9, 10};
uint32_t formats_B[] = {2, 5, 7, 9, 10}; uint32_t formats_B[] = {2, 5, 7, 9, 10};
uint64_t modifiers_A[] = {1, 2, 3, 4, 7}; uint64_t modifiers_A[] = {1, 2, 3, 4, 7};
@ -347,118 +326,109 @@ TEST(intersect_arrays)
uint64_t modifiers_intersect[] = {2, 3}; uint64_t modifiers_intersect[] = {2, 3};
int ret; int ret;
format_array_A = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_A);
format_array_B = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_B);
format_array_C = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_C);
assert(format_array_A);
assert(format_array_B);
assert(format_array_C);
ADD_FORMATS_AND_MODS(format_array_A, formats_A, modifiers_A); ADD_FORMATS_AND_MODS(&format_array_A, formats_A, modifiers_A);
ADD_FORMATS_AND_MODS(format_array_B, formats_B, modifiers_B); ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers_B);
ret = weston_drm_format_array_intersect(format_array_A, format_array_B); ret = weston_drm_format_array_intersect(&format_array_A, &format_array_B);
assert(ret == 0); assert(ret == 0);
/* The result of the intersection (stored in A) should have the same /* The result of the intersection (stored in A) should have the same
* content as C. */ * content as C. */
ADD_FORMATS_AND_MODS(format_array_C, (uint32_t[]){2}, modifiers_intersect); ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){2}, modifiers_intersect);
ADD_FORMATS_AND_MODS(format_array_C, (uint32_t[]){9}, modifiers_intersect); ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){9}, modifiers_intersect);
ADD_FORMATS_AND_MODS(format_array_C, (uint32_t[]){10}, modifiers_intersect); ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){10}, modifiers_intersect);
assert(weston_drm_format_array_equal(format_array_A, format_array_C)); assert(weston_drm_format_array_equal(&format_array_A, &format_array_C));
weston_drm_format_array_destroy(format_array_A); weston_drm_format_array_fini(&format_array_A);
weston_drm_format_array_destroy(format_array_B); weston_drm_format_array_fini(&format_array_B);
weston_drm_format_array_destroy(format_array_C); weston_drm_format_array_fini(&format_array_C);
} }
TEST(intersect_arrays_same_content) TEST(intersect_arrays_same_content)
{ {
struct weston_drm_format_array *format_array_A, *format_array_B; struct weston_drm_format_array format_array_A, format_array_B;
uint32_t formats[] = {1, 2, 3, 4, 5}; uint32_t formats[] = {1, 2, 3, 4, 5};
uint64_t modifiers[] = {11, 12, 13, 14, 15}; uint64_t modifiers[] = {11, 12, 13, 14, 15};
int ret; int ret;
format_array_A = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_A);
format_array_B = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_B);
assert(format_array_A);
assert(format_array_B);
/* The intersection between two empty arrays must be an /* The intersection between two empty arrays must be an
* empty array. */ * empty array. */
ret = weston_drm_format_array_intersect(format_array_A, format_array_B); ret = weston_drm_format_array_intersect(&format_array_A, &format_array_B);
assert(ret == 0); assert(ret == 0);
assert(format_array_A->arr.size == 0); assert(format_array_A.arr.size == 0);
/* DRM-format arrays A and B have the same content, so the intersection /* DRM-format arrays A and B have the same content, so the intersection
* should be equal to them. A keeps the result of the intersection, and B * should be equal to them. A keeps the result of the intersection, and B
* does not change. So we compare them. */ * does not change. So we compare them. */
ADD_FORMATS_AND_MODS(format_array_A, formats, modifiers); ADD_FORMATS_AND_MODS(&format_array_A, formats, modifiers);
ret = weston_drm_format_array_replace(format_array_B, format_array_A); ret = weston_drm_format_array_replace(&format_array_B, &format_array_A);
assert(ret == 0); assert(ret == 0);
ret = weston_drm_format_array_intersect(format_array_A, format_array_B); ret = weston_drm_format_array_intersect(&format_array_A, &format_array_B);
assert(ret == 0); assert(ret == 0);
assert(weston_drm_format_array_equal(format_array_A, format_array_B)); assert(weston_drm_format_array_equal(&format_array_A, &format_array_B));
weston_drm_format_array_destroy(format_array_A); weston_drm_format_array_fini(&format_array_A);
weston_drm_format_array_destroy(format_array_B); weston_drm_format_array_fini(&format_array_B);
} }
TEST(intersect_arrays_exclusive_formats) TEST(intersect_arrays_exclusive_formats)
{ {
struct weston_drm_format_array *format_array_A, *format_array_B; struct weston_drm_format_array format_array_A, format_array_B;
uint64_t formats_A[] = {1, 2, 3, 4, 5}; uint64_t formats_A[] = {1, 2, 3, 4, 5};
uint64_t formats_B[] = {6, 7, 8, 9, 10}; uint64_t formats_B[] = {6, 7, 8, 9, 10};
uint64_t modifiers[] = {11, 12, 13, 14, 15}; uint64_t modifiers[] = {11, 12, 13, 14, 15};
int ret; int ret;
format_array_A = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_A);
format_array_B = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_B);
assert(format_array_A);
assert(format_array_B);
/* DRM-format arrays A and B have formats that are mutually exclusive, /* DRM-format arrays A and B have formats that are mutually exclusive,
* so the intersection (which is stored in A) must be empty. */ * so the intersection (which is stored in A) must be empty. */
ADD_FORMATS_AND_MODS(format_array_A, formats_A, modifiers); ADD_FORMATS_AND_MODS(&format_array_A, formats_A, modifiers);
ADD_FORMATS_AND_MODS(format_array_B, formats_B, modifiers); ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers);
ret = weston_drm_format_array_intersect(format_array_A, format_array_B); ret = weston_drm_format_array_intersect(&format_array_A, &format_array_B);
assert(ret == 0); assert(ret == 0);
assert(format_array_A->arr.size == 0); assert(format_array_A.arr.size == 0);
weston_drm_format_array_destroy(format_array_A); weston_drm_format_array_fini(&format_array_A);
weston_drm_format_array_destroy(format_array_B); weston_drm_format_array_fini(&format_array_B);
} }
TEST(intersect_arrays_exclusive_modifiers) TEST(intersect_arrays_exclusive_modifiers)
{ {
struct weston_drm_format_array *format_array_A, *format_array_B; struct weston_drm_format_array format_array_A, format_array_B;
uint64_t modifiers_A[] = {1, 2, 3, 4, 5}; uint64_t modifiers_A[] = {1, 2, 3, 4, 5};
uint64_t modifiers_B[] = {6, 7, 8, 9, 10}; uint64_t modifiers_B[] = {6, 7, 8, 9, 10};
int ret; int ret;
format_array_A = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_A);
format_array_B = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_B);
assert(format_array_A);
assert(format_array_B);
/* Both DRM-format arrays A and B have the same format but with modifier /* Both DRM-format arrays A and B have the same format but with modifier
* sets that are mutually exclusive. The intersection (which is stored * sets that are mutually exclusive. The intersection (which is stored
* in A) between mutually exclusive modifier must be empty, and so the * in A) between mutually exclusive modifier must be empty, and so the
* format should not be added to the array. So the array must also be * format should not be added to the array. So the array must also be
* empty. */ * empty. */
ADD_FORMATS_AND_MODS(format_array_A, (uint32_t[]){1}, modifiers_A); ADD_FORMATS_AND_MODS(&format_array_A, (uint32_t[]){1}, modifiers_A);
ADD_FORMATS_AND_MODS(format_array_B, (uint32_t[]){1}, modifiers_B); ADD_FORMATS_AND_MODS(&format_array_B, (uint32_t[]){1}, modifiers_B);
ret = weston_drm_format_array_intersect(format_array_A, format_array_B); ret = weston_drm_format_array_intersect(&format_array_A, &format_array_B);
assert(ret == 0); assert(ret == 0);
assert(format_array_A->arr.size == 0); assert(format_array_A.arr.size == 0);
weston_drm_format_array_destroy(format_array_A); weston_drm_format_array_fini(&format_array_A);
weston_drm_format_array_destroy(format_array_B); weston_drm_format_array_fini(&format_array_B);
} }
TEST(subtract_arrays) TEST(subtract_arrays)
{ {
struct weston_drm_format_array *format_array_A, *format_array_B; struct weston_drm_format_array format_array_A, format_array_B;
struct weston_drm_format_array *format_array_C; struct weston_drm_format_array format_array_C;
uint32_t formats_A[] = {1, 2, 6, 9, 10}; uint32_t formats_A[] = {1, 2, 6, 9, 10};
uint32_t formats_B[] = {2, 5, 7, 9, 10}; uint32_t formats_B[] = {2, 5, 7, 9, 10};
uint64_t modifiers_A[] = {1, 2, 3, 4, 7}; uint64_t modifiers_A[] = {1, 2, 3, 4, 7};
@ -466,132 +436,119 @@ TEST(subtract_arrays)
uint64_t modifiers_subtract[] = {1, 4, 7}; uint64_t modifiers_subtract[] = {1, 4, 7};
int ret; int ret;
format_array_A = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_A);
format_array_B = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_B);
format_array_C = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_C);
assert(format_array_A);
assert(format_array_B);
assert(format_array_C);
ADD_FORMATS_AND_MODS(format_array_A, formats_A, modifiers_A); ADD_FORMATS_AND_MODS(&format_array_A, formats_A, modifiers_A);
ADD_FORMATS_AND_MODS(format_array_B, formats_B, modifiers_B); ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers_B);
ret = weston_drm_format_array_subtract(format_array_A, format_array_B); ret = weston_drm_format_array_subtract(&format_array_A, &format_array_B);
assert(ret == 0); assert(ret == 0);
/* The result of the subtraction (which is saved in A) should have /* The result of the subtraction (which is saved in A) should have
* the same content as C. */ * the same content as C. */
ADD_FORMATS_AND_MODS(format_array_C, (uint32_t[]){1}, modifiers_A); ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){1}, modifiers_A);
ADD_FORMATS_AND_MODS(format_array_C, (uint32_t[]){2}, modifiers_subtract); ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){2}, modifiers_subtract);
ADD_FORMATS_AND_MODS(format_array_C, (uint32_t[]){6}, modifiers_A); ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){6}, modifiers_A);
ADD_FORMATS_AND_MODS(format_array_C, (uint32_t[]){9}, modifiers_subtract); ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){9}, modifiers_subtract);
ADD_FORMATS_AND_MODS(format_array_C, (uint32_t[]){10}, modifiers_subtract); ADD_FORMATS_AND_MODS(&format_array_C, (uint32_t[]){10}, modifiers_subtract);
assert(weston_drm_format_array_equal(format_array_A, format_array_C)); assert(weston_drm_format_array_equal(&format_array_A, &format_array_C));
weston_drm_format_array_destroy(format_array_A); weston_drm_format_array_fini(&format_array_A);
weston_drm_format_array_destroy(format_array_B); weston_drm_format_array_fini(&format_array_B);
weston_drm_format_array_destroy(format_array_C); weston_drm_format_array_fini(&format_array_C);
} }
TEST(subtract_arrays_same_content) TEST(subtract_arrays_same_content)
{ {
struct weston_drm_format_array *format_array_A, *format_array_B; struct weston_drm_format_array format_array_A, format_array_B;
uint32_t formats[] = {1, 2, 3, 4, 5}; uint32_t formats[] = {1, 2, 3, 4, 5};
uint64_t modifiers[] = {11, 12, 13, 14, 15}; uint64_t modifiers[] = {11, 12, 13, 14, 15};
int ret; int ret;
format_array_A = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_A);
format_array_B = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_B);
assert(format_array_A);
assert(format_array_B);
/* Minuend and subtrahend have the same content. The subtraction /* Minuend and subtrahend have the same content. The subtraction
* (which is saved in A) should be an empty array. */ * (which is saved in A) should be an empty array. */
ADD_FORMATS_AND_MODS(format_array_A, formats, modifiers); ADD_FORMATS_AND_MODS(&format_array_A, formats, modifiers);
ret = weston_drm_format_array_replace(format_array_B, format_array_A); ret = weston_drm_format_array_replace(&format_array_B, &format_array_A);
assert(ret == 0); assert(ret == 0);
ret = weston_drm_format_array_subtract(format_array_A, format_array_B); ret = weston_drm_format_array_subtract(&format_array_A, &format_array_B);
assert(ret == 0); assert(ret == 0);
assert(format_array_A->arr.size == 0); assert(format_array_A.arr.size == 0);
weston_drm_format_array_destroy(format_array_A); weston_drm_format_array_fini(&format_array_A);
weston_drm_format_array_destroy(format_array_B); weston_drm_format_array_fini(&format_array_B);
} }
TEST(subtract_arrays_exclusive_formats) TEST(subtract_arrays_exclusive_formats)
{ {
struct weston_drm_format_array *format_array_A, *format_array_B; struct weston_drm_format_array format_array_A, format_array_B;
struct weston_drm_format_array *format_array_C; struct weston_drm_format_array format_array_C;
uint32_t formats_A[] = {1, 2, 3, 4, 5}; uint32_t formats_A[] = {1, 2, 3, 4, 5};
uint32_t formats_B[] = {6, 7, 8, 9, 10}; uint32_t formats_B[] = {6, 7, 8, 9, 10};
uint64_t modifiers[] = {11, 12, 13, 14, 15}; uint64_t modifiers[] = {11, 12, 13, 14, 15};
int ret; int ret;
format_array_A = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_A);
format_array_B = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_B);
format_array_C = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_C);
assert(format_array_A);
assert(format_array_B);
assert(format_array_C);
/* Minuend and subtrahend have mutually exclusive formats. The /* Minuend and subtrahend have mutually exclusive formats. The
* subtraction (which is saved in A) should be equal the minuend. */ * subtraction (which is saved in A) should be equal the minuend. */
ADD_FORMATS_AND_MODS(format_array_A, formats_A, modifiers); ADD_FORMATS_AND_MODS(&format_array_A, formats_A, modifiers);
ADD_FORMATS_AND_MODS(format_array_B, formats_B, modifiers); ADD_FORMATS_AND_MODS(&format_array_B, formats_B, modifiers);
ret = weston_drm_format_array_replace(format_array_C, format_array_A); ret = weston_drm_format_array_replace(&format_array_C, &format_array_A);
assert(ret == 0); assert(ret == 0);
ret = weston_drm_format_array_subtract(format_array_A, format_array_B); ret = weston_drm_format_array_subtract(&format_array_A, &format_array_B);
assert(ret == 0); assert(ret == 0);
assert(weston_drm_format_array_equal(format_array_A, format_array_C)); assert(weston_drm_format_array_equal(&format_array_A, &format_array_C));
weston_drm_format_array_destroy(format_array_A); weston_drm_format_array_fini(&format_array_A);
weston_drm_format_array_destroy(format_array_B); weston_drm_format_array_fini(&format_array_B);
weston_drm_format_array_destroy(format_array_C); weston_drm_format_array_fini(&format_array_C);
} }
TEST(subtract_arrays_exclusive_modifiers) TEST(subtract_arrays_exclusive_modifiers)
{ {
struct weston_drm_format_array *format_array_A, *format_array_B; struct weston_drm_format_array format_array_A, format_array_B;
struct weston_drm_format_array *format_array_C; struct weston_drm_format_array format_array_C;
uint64_t modifiers_A[] = {1, 2, 3, 4, 5}; uint64_t modifiers_A[] = {1, 2, 3, 4, 5};
uint64_t modifiers_B[] = {6, 7, 8, 9, 10}; uint64_t modifiers_B[] = {6, 7, 8, 9, 10};
int ret; int ret;
format_array_A = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_A);
format_array_B = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_B);
format_array_C = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_C);
assert(format_array_A);
assert(format_array_B);
assert(format_array_C);
/* Minuend and subtrahend have the same format but with modifiers that /* Minuend and subtrahend have the same format but with modifiers that
* are mutually exclusive. The subtraction (which is saved in A) should * are mutually exclusive. The subtraction (which is saved in A) should
* contain the format and the modifier set of the minuend. */ * contain the format and the modifier set of the minuend. */
ADD_FORMATS_AND_MODS(format_array_A, (uint32_t[]){1}, modifiers_A); ADD_FORMATS_AND_MODS(&format_array_A, (uint32_t[]){1}, modifiers_A);
ADD_FORMATS_AND_MODS(format_array_B, (uint32_t[]){1}, modifiers_B); ADD_FORMATS_AND_MODS(&format_array_B, (uint32_t[]){1}, modifiers_B);
ret = weston_drm_format_array_replace(format_array_C, format_array_A); ret = weston_drm_format_array_replace(&format_array_C, &format_array_A);
assert(ret == 0); assert(ret == 0);
ret = weston_drm_format_array_subtract(format_array_A, format_array_B); ret = weston_drm_format_array_subtract(&format_array_A, &format_array_B);
assert(ret == 0); assert(ret == 0);
assert(weston_drm_format_array_equal(format_array_A, format_array_C)); assert(weston_drm_format_array_equal(&format_array_A, &format_array_C));
weston_drm_format_array_destroy(format_array_A); weston_drm_format_array_fini(&format_array_A);
weston_drm_format_array_destroy(format_array_B); weston_drm_format_array_fini(&format_array_B);
weston_drm_format_array_destroy(format_array_C); weston_drm_format_array_fini(&format_array_C);
} }
TEST(subtract_arrays_modifier_invalid) TEST(subtract_arrays_modifier_invalid)
{ {
struct weston_drm_format_array *format_array_A, *format_array_B; struct weston_drm_format_array format_array_A, format_array_B;
uint64_t modifier_invalid[] = {DRM_FORMAT_MOD_INVALID}; uint64_t modifier_invalid[] = {DRM_FORMAT_MOD_INVALID};
uint64_t regular_modifiers_plus_invalid[] = {1, 2, 3, 4, 5, DRM_FORMAT_MOD_INVALID}; uint64_t regular_modifiers_plus_invalid[] = {1, 2, 3, 4, 5, DRM_FORMAT_MOD_INVALID};
int ret; int ret;
format_array_A = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_A);
format_array_B = weston_drm_format_array_create(); weston_drm_format_array_init(&format_array_B);
assert(format_array_A);
assert(format_array_B);
/* The minuend has a format with modifier set that contains MOD_INVALID /* The minuend has a format with modifier set that contains MOD_INVALID
* and the subtrahend contains the same format but with a regular set of * and the subtrahend contains the same format but with a regular set of
@ -599,12 +556,12 @@ TEST(subtract_arrays_modifier_invalid)
* sets results in empty, and so the format should not be included to * sets results in empty, and so the format should not be included to
* the result. As it is the only format in the minuend, the resulting * the result. As it is the only format in the minuend, the resulting
* array must be empty. */ * array must be empty. */
ADD_FORMATS_AND_MODS(format_array_A, (uint32_t[]){1}, modifier_invalid); ADD_FORMATS_AND_MODS(&format_array_A, (uint32_t[]){1}, modifier_invalid);
ADD_FORMATS_AND_MODS(format_array_B, (uint32_t[]){1}, regular_modifiers_plus_invalid); ADD_FORMATS_AND_MODS(&format_array_B, (uint32_t[]){1}, regular_modifiers_plus_invalid);
ret = weston_drm_format_array_subtract(format_array_A, format_array_B); ret = weston_drm_format_array_subtract(&format_array_A, &format_array_B);
assert(ret == 0); assert(ret == 0);
assert(format_array_A->arr.size == 0); assert(format_array_A.arr.size == 0);
weston_drm_format_array_destroy(format_array_A); weston_drm_format_array_fini(&format_array_A);
weston_drm_format_array_destroy(format_array_B); weston_drm_format_array_fini(&format_array_B);
} }

Loading…
Cancel
Save