color-noop: avoid assert hit in cmnoop_destroy()

When we are destroying the color manager, the components referencing
color profiles should have already been destroyed. We have an assert
in cmnoop_destroy() to make sure that the stock profile has refcount
equal to 1.

But we currently have an issue in Weston. While shutting down with
client surfaces alive, we may leak them. So we try to destroy
the color manager with surfaces still alive, and they may be
referencing color profiles.

We already have a workaround for this in our LittleCMS color plugin,
but we've missed that in color-noop. This fixes that, so now we don't
hit the assert anymore.

As we are already dealing with asserts in color-noop, I took the
liberty to replace the last usage of assert with our own wrapper
in this file.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
This commit is contained in:
Leandro Ribeiro 2024-02-21 13:08:42 -03:00 committed by Pekka Paalanen
parent 238d5274a2
commit 6da5b8a5a5
2 changed files with 13 additions and 3 deletions

View File

@ -174,11 +174,13 @@ static struct weston_output_color_outcome *
cmnoop_create_output_color_outcome(struct weston_color_manager *cm_base, cmnoop_create_output_color_outcome(struct weston_color_manager *cm_base,
struct weston_output *output) struct weston_output *output)
{ {
struct weston_compositor *compositor = cm_base->compositor;
struct weston_color_manager_noop *cmnoop = get_cmnoop(cm_base); struct weston_color_manager_noop *cmnoop = get_cmnoop(cm_base);
struct weston_output_color_outcome *co; struct weston_output_color_outcome *co;
assert(output->color_profile && weston_assert_ptr(compositor, output->color_profile);
get_cprof(output->color_profile) == cmnoop->stock_cprof); weston_assert_ptr_eq(compositor, get_cprof(output->color_profile),
cmnoop->stock_cprof);
if (!check_output_eotf_mode(output)) if (!check_output_eotf_mode(output))
return NULL; return NULL;
@ -228,7 +230,12 @@ cmnoop_destroy(struct weston_color_manager *cm_base)
{ {
struct weston_color_manager_noop *cmnoop = get_cmnoop(cm_base); struct weston_color_manager_noop *cmnoop = get_cmnoop(cm_base);
assert(cmnoop->stock_cprof->base.ref_count == 1); /* TODO: change this assert to make sure that ref_count is equal to 1.
* Currently we have a bug in which we leak surfaces when shutting down
* Weston with client surfaces alive, and these surfaces may have a
* reference to the stock sRGB profile. */
weston_assert_uint32_gt_or_eq(cm_base->compositor,
cmnoop->stock_cprof->base.ref_count, 1);
unref_cprof(cmnoop->stock_cprof); unref_cprof(cmnoop->stock_cprof);
free(cmnoop); free(cmnoop);

View File

@ -102,6 +102,9 @@ do { \
#define weston_assert_uint32_gt(compositor, a, b) \ #define weston_assert_uint32_gt(compositor, a, b) \
weston_assert_(compositor, a, b, uint32_t, "%u", >) weston_assert_(compositor, a, b, uint32_t, "%u", >)
#define weston_assert_uint32_gt_or_eq(compositor, a, b) \
weston_assert_(compositor, a, b, uint32_t, "%u", >=)
#define weston_assert_uint32_lt(compositor, a, b) \ #define weston_assert_uint32_lt(compositor, a, b) \
weston_assert_(compositor, a, b, uint32_t, "%u", <) weston_assert_(compositor, a, b, uint32_t, "%u", <)