From: Harsha M M <[email protected]> v3: --Terminate the compositor after test completion to fix stuck problem during make check --Do not launch client binary as it is optional for the test.
Signed-off-by: Harsha M M <[email protected]> --- Makefile.am | 8 ++- tests/ctm-test.c | 207 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 tests/ctm-test.c diff --git a/Makefile.am b/Makefile.am index 6b1c560..f8cda15 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1239,7 +1239,8 @@ module_tests = \ plugin-registry-test.la \ surface-test.la \ surface-global-test.la \ - gamma-test.la + gamma-test.la \ + ctm-test.la weston_tests = \ bad_buffer.weston \ @@ -1382,6 +1383,11 @@ gamma_test_la_LIBADD = $(test_module_libadd) gamma_test_la_LDFLAGS = $(test_module_ldflags) gamma_test_la_CFLAGS = $(AM_CFLAGS) $(COMPOSITOR_CFLAGS) +ctm_test_la_SOURCES = tests/ctm-test.c +ctm_test_la_LIBADD = $(test_module_libadd) +ctm_test_la_LDFLAGS = $(test_module_ldflags) +ctm_test_la_CFLAGS = $(AM_CFLAGS) $(COMPOSITOR_CFLAGS) + # # Internal tests - tests functionality of the testsuite itself # diff --git a/tests/ctm-test.c b/tests/ctm-test.c new file mode 100644 index 0000000..03a42c9 --- /dev/null +++ b/tests/ctm-test.c @@ -0,0 +1,207 @@ +/* + * Copyright © 2018 Advanced Driver Information Technology, GmbH. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "config.h" + +#include <stdint.h> +#include <unistd.h> +#include <signal.h> +#include <string.h> +#include <assert.h> + +#include "compositor.h" +#include "compositor/weston.h" +#include "shared/helpers.h" +#include <wayland-server.h> + +struct ctm_tobject { + struct weston_compositor *w_compositor; + struct wl_listener output_add_listener; + struct wl_listener compositor_destroy; + struct wl_display *display; + struct wl_event_source *ctm_update_timer; + struct wl_list output_list; +}; + +struct output_obj { + struct weston_output *output; + struct wl_listener output_remove_listener; + struct weston_matrix* ctm_mat; + float brightness; + bool test_complete; + + struct wl_list link; +}; + + +/* gamma change interval in milli seconds*/ +#define CTM_UPDATE_INTERVAL 1000 + +static void +compute_ctm_mat(struct weston_matrix *ctm_mat, float brightness) +{ + uint32_t i; + + /*set all diagonal elements of the matrix*/ + for (i = 0; i < 4; i++) { + ctm_mat->d[(i * 4) + i] = brightness; + } +} + +static int +ctm_update_event(void *data) +{ + struct ctm_tobject *obj; + struct output_obj *op_obj; + bool all_tests_complete = true; + + obj = (struct ctm_tobject *)data; + + wl_list_for_each(op_obj, &obj->output_list, link) { + /*compute Ctm lookup table*/ + if (!op_obj->test_complete) { + op_obj->brightness += 0.1; + if (op_obj->brightness > 2.0) { + op_obj->test_complete = true; + /*End the test with ctm set to 1*/ + op_obj->brightness = 1.0; + } + + + compute_ctm_mat(op_obj->ctm_mat, op_obj->brightness); + + op_obj->output->set_ctm(op_obj->output, + op_obj->ctm_mat); + + all_tests_complete=false; + } + } + if (all_tests_complete) { + if (obj->ctm_update_timer) { + wl_event_source_remove(obj->ctm_update_timer); + obj->ctm_update_timer = NULL; + } + wl_display_terminate(obj->display); + } + else + wl_event_source_timer_update(obj->ctm_update_timer, + CTM_UPDATE_INTERVAL); + + return 0; +} + + +static +void output_remove(struct wl_listener *listener, void *data) +{ + struct output_obj *op_obj; + op_obj = container_of(listener, struct output_obj, + output_remove_listener); + wl_list_remove(&op_obj->link); + free(op_obj); +} + + +static void +output_add_ctm_test_loop(struct ctm_tobject *obj, + struct weston_output *output) +{ + struct wl_event_loop *loop; + struct output_obj *op_obj = zalloc(sizeof(struct output_obj)); + + if (output->set_ctm) { + op_obj->output_remove_listener.notify = output_remove; + wl_signal_add(&output->destroy_signal, + &op_obj->output_remove_listener); + wl_list_insert(&obj->output_list, &op_obj->link); + + op_obj->ctm_mat = zalloc(sizeof(struct weston_matrix)); + op_obj->test_complete = false; + op_obj->output = output; + op_obj->brightness = 0.5; + + } + if (NULL == obj->ctm_update_timer) { + loop = wl_display_get_event_loop(obj->display); + obj->ctm_update_timer = + wl_event_loop_add_timer(loop, + ctm_update_event, + obj); + wl_event_source_timer_update(obj->ctm_update_timer, + CTM_UPDATE_INTERVAL); + } +} + +static +void output_add(struct wl_listener *listener, void *data) +{ + struct weston_output *output = (struct weston_output *)data; + struct ctm_tobject *obj = container_of(listener, struct ctm_tobject, + output_add_listener); + + output_add_ctm_test_loop(obj, output); +} + + +static +void wet_compositor_destroy(struct wl_listener *listener, void *data) +{ + struct ctm_tobject *obj; + struct output_obj *op_obj; + struct output_obj *tmp; + obj = container_of(listener, struct ctm_tobject, + compositor_destroy); + + wl_list_for_each_safe(op_obj, tmp, &obj->output_list, link) { + wl_list_remove(&op_obj->output_remove_listener.link); + wl_list_remove(&op_obj->link); + free(op_obj); + } + + if (obj->ctm_update_timer) + wl_event_source_remove(obj->ctm_update_timer); + + free(obj); +} + +WL_EXPORT int +wet_module_init(struct weston_compositor *compositor, int *argc, char *argv[]) +{ + struct ctm_tobject *obj = zalloc(sizeof(struct ctm_tobject)); + struct weston_output *output; + + obj->output_add_listener.notify = output_add; + obj->w_compositor = compositor; + obj->compositor_destroy.notify = wet_compositor_destroy; + wl_signal_add(&compositor->destroy_signal, &obj->compositor_destroy); + wl_signal_add(&compositor->output_created_signal, &obj->output_add_listener); + + wl_list_init(&obj->output_list); + obj->display = compositor->wl_display; + + wl_list_for_each(output, &compositor->output_list, link) + output_add_ctm_test_loop(obj, output); + + return 0; +} -- 2.7.4 _______________________________________________ wayland-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/wayland-devel
