From: Harsha M M <[email protected]>

Signed-off-by: Harsha M M <[email protected]>
---
 Makefile.am      |   8 ++-
 tests/ctm-test.c | 210 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 217 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..c2ff317
--- /dev/null
+++ b/tests/ctm-test.c
@@ -0,0 +1,210 @@
+/*
+ * 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_client *client_app;
+       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 2000
+
+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;
+
+       obj = (struct ctm_tobject *)data;
+
+       if (wl_list_empty(&obj->output_list) && obj->ctm_update_timer) {
+               wl_event_source_remove(obj->ctm_update_timer);
+               obj->ctm_update_timer = NULL;
+               return 0;
+       }
+
+       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);
+
+               }
+       }
+       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 = -2.0;
+
+               loop = wl_display_get_event_loop(obj->display);
+
+               if (NULL == obj->client_app)
+                       obj->client_app = weston_client_start(obj->w_compositor,
+                                               "/usr/bin/weston-flower");
+
+               if (NULL == obj->ctm_update_timer) {
+                       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

Reply via email to