weston: update patch for libweston for version 12
[AGL/meta-agl.git] / meta-agl-core / recipes-graphics / wayland / weston / 0001-libweston-weston-log-Add-a-iterator-helper-for-debug.patch
1 From d8517b45bf11f5a1a838637a0474375549292d9a Mon Sep 17 00:00:00 2001
2 From: Marius Vlad <marius.vlad@collabora.com>
3 Date: Mon, 29 May 2023 16:30:02 +0300
4 Subject: [PATCH] libweston/weston-log: Add a iterator helper for debug scope
5
6 This adds three new helpers: one to iterate over all debug scopes
7 created/added and other two are for simpler getters for the scope name
8 and the description.
9
10 Included with this change is also a simple test to retrieve them.
11
12 This is an alternative to using the debug scope list advertised when
13 using the weston-debug private extension. libweston users can use this
14 directly to know which scopes they can subscribe to, and there's no need
15 to have a client implementation for the weston-debug protocol.
16
17 Upstream-Status: Pending
18
19 Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
20
21 ---
22  include/libweston/weston-log.h    | 10 ++++
23  libweston/weston-log.c            | 63 +++++++++++++++++++++++
24  tests/iterate-debug-scopes-test.c | 84 +++++++++++++++++++++++++++++++
25  tests/meson.build                 |  6 +++
26  4 files changed, 163 insertions(+)
27  create mode 100644 tests/iterate-debug-scopes-test.c
28
29 diff --git a/include/libweston/weston-log.h b/include/libweston/weston-log.h
30 index 1786dea..818d9de 100644
31 --- a/include/libweston/weston-log.h
32 +++ b/include/libweston/weston-log.h
33 @@ -136,6 +136,16 @@ weston_log_subscription_iterate(struct weston_log_scope *scope,
34  void
35  weston_log_flight_recorder_display_buffer(FILE *file);
36  
37 +const char *
38 +weston_log_scope_get_description(struct weston_log_scope *scope);
39 +
40 +const char *
41 +weston_log_scope_get_name(struct weston_log_scope *scope);
42 +
43 +struct weston_log_scope *
44 +weston_log_scopes_iterate(struct weston_log_context *log_ctx,
45 +                          struct weston_log_scope *nscope);
46 +
47  #ifdef  __cplusplus
48  }
49  #endif
50 diff --git a/libweston/weston-log.c b/libweston/weston-log.c
51 index 93f95c9..5d6ff2b 100644
52 --- a/libweston/weston-log.c
53 +++ b/libweston/weston-log.c
54 @@ -1057,3 +1057,66 @@ weston_log_subscription_iterate(struct weston_log_scope *scope,
55  
56         return container_of(node, struct weston_log_subscription, source_link);
57  }
58 +
59 +/** Iterate over all debug scopes added to a weston_log_context
60 + *
61 + * @param log_ctx the log context
62 + * @param nscope the iterator, use NULL to start from the head of the list
63 + * @returns the next log scope from list added to weston_log_ctx
64 + *
65 + * Note that that \c nscope needs to be NULL-initialized before calling
66 + * this function.
67 + *
68 + * This helper can be used by libweston users to grab all the debug scopes
69 + * created. This would be an alternative to using weston-debug private
70 + * extension.
71 + *
72 + */
73 +WL_EXPORT struct weston_log_scope *
74 +weston_log_scopes_iterate(struct weston_log_context *log_ctx,
75 +                          struct weston_log_scope *nscope)
76 +{
77 +        struct wl_list *list;
78 +        struct wl_list *node;
79 +
80 +        assert(log_ctx);
81 +
82 +        list = &log_ctx->scope_list;
83 +
84 +        if (nscope) {
85 +                node = nscope->compositor_link.next;
86 +        } else {
87 +                node = list->next;
88 +        }
89 +
90 +       assert(node);
91 +       assert(!nscope || node != &nscope->compositor_link);
92 +
93 +        if (node == list)
94 +                return NULL;
95 +
96 +        return container_of(node, struct weston_log_scope, compositor_link);
97 +}
98 +
99 +/** Helper to retrieve, in human readable form,  the name of a log scope
100 + *
101 + * @param scope the scope in question
102 + * @returns the name of the scope as a pointer to a string
103 + */
104 +WL_EXPORT const char *
105 +weston_log_scope_get_name(struct weston_log_scope *scope)
106 +{
107 +        return scope->name;
108 +}
109 +
110 +/** Helper to retreive, in human reable form, the description of a log scope
111 + *
112 + * @param scope the scope in question
113 + * @returns the description of the scope as pointer to a string
114 + *
115 + */
116 +WL_EXPORT const char *
117 +weston_log_scope_get_description(struct weston_log_scope *scope)
118 +{
119 +        return scope->desc;
120 +}
121 diff --git a/tests/iterate-debug-scopes-test.c b/tests/iterate-debug-scopes-test.c
122 new file mode 100644
123 index 0000000..82c6c5c
124 --- /dev/null
125 +++ b/tests/iterate-debug-scopes-test.c
126 @@ -0,0 +1,84 @@
127 +/*
128 + * Copyright 2023 Collabora, Ltd.
129 + *
130 + * Permission is hereby granted, free of charge, to any person obtaining
131 + * a copy of this software and associated documentation files (the
132 + * "Software"), to deal in the Software without restriction, including
133 + * without limitation the rights to use, copy, modify, merge, publish,
134 + * distribute, sublicense, and/or sell copies of the Software, and to
135 + * permit persons to whom the Software is furnished to do so, subject to
136 + * the following conditions:
137 + *
138 + * The above copyright notice and this permission notice (including the
139 + * next paragraph) shall be included in all copies or substantial
140 + * portions of the Software.
141 + *
142 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
143 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
144 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
145 + * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
146 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
147 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
148 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
149 + * SOFTWARE.
150 + */
151 +#include "config.h"
152 +
153 +#include <unistd.h>
154 +#include <assert.h>
155 +#include <stdlib.h>
156 +#include <stdio.h>
157 +#include <string.h>
158 +
159 +#include <libweston/weston-log.h>
160 +#include "weston-test-client-helper.h"
161 +#include "weston-test-fixture-compositor.h"
162 +
163 +
164 +static enum test_result_code
165 +fixture_setup(struct weston_test_harness *harness)
166 +{
167 +       struct compositor_setup setup;
168 +
169 +       compositor_setup_defaults(&setup);
170 +       setup.shell = SHELL_TEST_DESKTOP;
171 +
172 +       return weston_test_harness_execute_as_plugin(harness, &setup);
173 +}
174 +
175 +DECLARE_FIXTURE_SETUP(fixture_setup);
176 +
177 +static void
178 +iterate_debug_scopes(struct weston_compositor *compositor)
179 +{
180 +       struct weston_log_scope *nscope = NULL;
181 +       const char *test_harness_scope = "test-harness-plugin";
182 +       bool found_test_harness_debug_scope = false;
183 +       struct weston_log_context *log_ctx = compositor->weston_log_ctx;
184 +
185 +       weston_log("Printing available debug scopes:\n");
186 +
187 +       while ((nscope = weston_log_scopes_iterate(log_ctx, nscope))) {
188 +               const char *scope_name;
189 +               const char *desc_name;
190 +
191 +               scope_name = weston_log_scope_get_name(nscope);
192 +               assert(scope_name);
193 +
194 +               desc_name = weston_log_scope_get_description(nscope);
195 +               assert(desc_name);
196 +
197 +               weston_log("\tscope name: %s, desc: %s\n", scope_name, desc_name);
198 +
199 +               if (strcmp(test_harness_scope, scope_name) == 0)
200 +                       found_test_harness_debug_scope = true;
201 +       }
202 +       weston_log("\n");
203 +
204 +       assert(found_test_harness_debug_scope);
205 +}
206 +
207 +PLUGIN_TEST(iterate_default_debug_scopes)
208 +{
209 +       iterate_debug_scopes(compositor);
210 +}
211 diff --git a/tests/meson.build b/tests/meson.build
212 index 1d59a93..7908896 100644
213 --- a/tests/meson.build
214 +++ b/tests/meson.build
215 @@ -269,6 +269,12 @@ tests = [
216                 ],
217                 'dep_objs': [ dep_libweston_public ]
218         },
219 +       {       'name': 'iterate-debug-scopes',
220 +               'sources': [
221 +                 'iterate-debug-scopes-test.c',
222 +               ],
223 +               'dep_objs': [ dep_libweston_public ]
224 +       },
225  ]
226  
227  if get_option('renderer-gl')