utests: fix build-error
[platform/core/uifw/libtdm.git] / tools / tdm_test_server.c
index 4ea6d11..17c0121 100644 (file)
 #include <tbm_surface.h>
 #include <tbm_surface_internal.h>
 
-#include <tdm.h>
-#include <tdm_log.h>
-#include <tdm_list.h>
-#include <tdm_helper.h>
-#include <tdm_backend.h>
+#include "tdm.h"
+#include "tdm_log.h"
+#include "tdm_list.h"
+#include "tdm_helper.h"
+#include "tdm_backend.h"
 
 #include "tdm_macro.h"
 #include "tdm_private.h"
@@ -183,7 +183,6 @@ usage(char *app_name)
                printf("\t%s\n", usages[t].desc);
        }
        printf("\n");
-       exit(0);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -316,6 +315,7 @@ struct _tdm_test_server {
        tdm_display *display;
 };
 
+static void destroy(tdm_test_server *data);
 static void run_test(tdm_test_server *data);
 static void output_setup(tdm_test_server_output *o);
 static void layer_show_buffer(tdm_test_server_layer *l, tbm_surface_h b);
@@ -517,6 +517,7 @@ parse_args(tdm_test_server *data, int argc, char *argv[])
 
        if (argc < 2) {
                usage(argv[0]);
+               destroy(data);
                exit(0);
        }
 
@@ -597,6 +598,7 @@ parse_args(tdm_test_server *data, int argc, char *argv[])
                        data->do_vblank = 1;
                } else {
                        usage(argv[0]);
+                       destroy(data);
                        exit(0);
                }
        }
@@ -639,7 +641,9 @@ interpret_args(tdm_test_server *data)
                for (i = 0; i < output_count; i++) {
                        tdm_output *output = tdm_display_get_output(data->display, i, NULL);
                        tdm_output_conn_status status;
-                       tdm_output_get_conn_status(output, &status);
+                       ret = tdm_output_get_conn_status(output, &status);
+                       TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
+
                        if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
                                continue;
                        o = calloc(1, sizeof * o);
@@ -760,7 +764,6 @@ interpret_args(tdm_test_server *data)
        }
 }
 
-static unsigned int tts_screen_prerotation_hint;
 static tdm_test_server tts_data;
 static int tts_buffer_key;
 #define TTS_BUFFER_KEY ((unsigned long)&tts_buffer_key)
@@ -770,8 +773,6 @@ buffer_allocate(int width, int height, int format, int flags)
 {
        tdm_test_server_buffer *tb = calloc(1, sizeof *tb);
        TDM_EXIT_IF_FAIL(tb != NULL);
-       if (tts_screen_prerotation_hint % 180)
-               TDM_SWAP(width, height);
        tb->b = tbm_surface_internal_create_with_flags(width, height, format, flags);
        TDM_EXIT_IF_FAIL(tb->b != NULL);
        tdm_helper_clear_buffer(tb->b);
@@ -789,26 +790,50 @@ get_tts_buffer(tbm_surface_h b)
 }
 
 static void
-exit_test(int sig)
+destroy(tdm_test_server *data)
 {
-       tdm_test_server *data = &tts_data;
        tdm_test_server_output *o = NULL, *oo = NULL;
        tdm_test_server_layer *l = NULL, *ll = NULL;
        tdm_test_server_pp *p = NULL, *pp = NULL;
        tdm_test_server_capture *c = NULL, *cc = NULL;
        tdm_test_server_prop *w = NULL, *ww = NULL;
+       tdm_error ret;
        int i;
 
-       printf("got signal: %d\n", sig);
+       LIST_FOR_EACH_ENTRY_SAFE(c, cc, &data->capture_list, link) {
+               LIST_DEL(&c->link);
+               tdm_capture_destroy(c->capture);
+               free(c);
+       }
 
-       LIST_FOR_EACH_ENTRY_SAFE(o, oo, &data->output_list, link) {
-               LIST_DEL(&o->link);
+       LIST_FOR_EACH_ENTRY_SAFE(p, pp, &data->pp_list, link) {
+               tdm_display_lock(data->display);
+               tdm_event_loop_source_remove(p->timer_source);
+               tdm_display_unlock(data->display);
+
+               tdm_pp_destroy(p->pp);
+       }
 
+       LIST_FOR_EACH_ENTRY_SAFE(o, oo, &data->output_list, link) {
                LIST_FOR_EACH_ENTRY_SAFE(l, ll, &o->layer_list, link) {
-                       LIST_DEL(&l->link);
+                       ret = tdm_layer_unset_buffer(l->layer);
+                       TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
+               }
+               ret = tdm_layer_commit(l->layer, NULL, NULL);
+               TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
+       }
 
-                       tdm_layer_unset_buffer(l->layer);
+       LIST_FOR_EACH_ENTRY_SAFE(p, pp, &data->pp_list, link) {
+               LIST_DEL(&p->link);
+               for (i = 0; i < TDM_ARRAY_SIZE(p->bufs); i++)
+                       tbm_surface_destroy(p->bufs[i]);
+               free(p);
+       }
 
+       LIST_FOR_EACH_ENTRY_SAFE(o, oo, &data->output_list, link) {
+               LIST_DEL(&o->link);
+               LIST_FOR_EACH_ENTRY_SAFE(l, ll, &o->layer_list, link) {
+                       LIST_DEL(&l->link);
                        LIST_FOR_EACH_ENTRY_SAFE(w, ww, &l->prop_list, link) {
                                LIST_DEL(&w->link);
                                free(w);
@@ -817,9 +842,6 @@ exit_test(int sig)
                                tbm_surface_destroy(l->bufs[i]);
                        free(l);
                }
-
-               tdm_output_commit(o->output, 0, NULL, NULL);
-
                LIST_FOR_EACH_ENTRY_SAFE(w, ww, &o->prop_list, link) {
                        LIST_DEL(&w->link);
                        free(w);
@@ -828,26 +850,6 @@ exit_test(int sig)
                free(o);
        }
 
-
-       LIST_FOR_EACH_ENTRY_SAFE(p, pp, &data->pp_list, link) {
-               LIST_DEL(&p->link);
-
-               tdm_display_lock(data->display);
-               tdm_event_loop_source_remove(p->timer_source);
-               tdm_display_unlock(data->display);
-
-               tdm_pp_destroy(p->pp);
-               for (i = 0; i < TDM_ARRAY_SIZE(p->bufs); i++)
-                       tbm_surface_destroy(p->bufs[i]);
-               free(p);
-       }
-
-       LIST_FOR_EACH_ENTRY_SAFE(c, cc, &data->capture_list, link) {
-               LIST_DEL(&c->link);
-               tdm_capture_destroy(c->capture);
-               free(c);
-       }
-
        if (data->display)
                tdm_display_deinit(data->display);
 
@@ -861,17 +863,26 @@ main(int argc, char *argv[])
        char temp[TDM_SERVER_REPLY_MSG_LEN];
        int len = sizeof temp;
        tdm_error ret;
-       const char *value;
 
-       value = (const char*)getenv("SCREEN_PREROTATION_HINT");
-       if (value) {
-               char *end;
-               tts_screen_prerotation_hint = strtol(value, &end, 10);
-               printf("SCREEN_PREROTATION_HINT = %d", tts_screen_prerotation_hint);
+#if 1 /* for testing */
+       const char *s = (const char*)getenv("XDG_RUNTIME_DIR");
+       if (!s) {
+               char buf[32];
+               snprintf(buf, sizeof(buf), "/run");
+               int ret = setenv("XDG_RUNTIME_DIR", (const char*)buf, 1);
+               if (ret != 0)
+                       exit(0);
        }
 
-       signal(SIGINT, exit_test);    /* 2 */
-       signal(SIGTERM, exit_test);   /* 15 */
+       s = (const char*)getenv("TBM_DISPLAY_SERVER");
+       if (!s) {
+               char buf[32];
+               snprintf(buf, sizeof(buf), "1");
+               int ret = setenv("TBM_DISPLAY_SERVER", (const char*)buf, 1);
+               if (ret != 0)
+                       exit(0);
+       }
+#endif
 
        memset(data, 0, sizeof * data);
        LIST_INITHEAD(&data->output_list);
@@ -926,7 +937,7 @@ output_setup(tdm_test_server_output *o)
                }
                if (!best)
                        best = &modes[i];
-               if (modes[i].flags & TDM_OUTPUT_MODE_TYPE_PREFERRED)
+               if (modes[i].type & TDM_OUTPUT_MODE_TYPE_PREFERRED)
                        prefer = &modes[i];
        }
        if (!found && prefer) {
@@ -973,9 +984,9 @@ layer_get_buffer(tdm_test_server_layer *l)
        int i, size = TDM_ARRAY_SIZE(l->bufs);
        if (!l->bufs[0]) {
                for (i = 0; i < size; i++) {
-                       int width = (l->info.src_config.size.h)?:l->info.src_config.pos.w;
-                       int height = (l->info.src_config.size.v)?:l->info.src_config.pos.h;
-                       unsigned int format = (l->info.src_config.format)?:DEFAULT_FORMAT;
+                       int width = (l->info.src_config.size.h) ? : l->info.src_config.pos.w;
+                       int height = (l->info.src_config.size.v) ? : l->info.src_config.pos.h;
+                       unsigned int format = (l->info.src_config.format) ? : DEFAULT_FORMAT;
                        int flags = l->o->data->bflags;
                        tbm_surface_h b = buffer_allocate(width, height, format, flags);
                        TDM_EXIT_IF_FAIL(b != NULL);
@@ -993,7 +1004,7 @@ layer_get_buffer(tdm_test_server_layer *l)
 }
 
 static void
-layer_cb_commit(tdm_output *output, unsigned int sequence,
+layer_cb_commit(tdm_layer *layer, unsigned int sequence,
                                unsigned int tv_sec, unsigned int tv_usec,
                                void *user_data)
 {
@@ -1034,12 +1045,13 @@ layer_show_buffer(tdm_test_server_layer *l, tbm_surface_h b)
        TDM_EXIT_IF_FAIL(tb != NULL);
 
        tb->in_use = 1;
-       tdm_buffer_add_release_handler(b, layer_cb_buffer_release, NULL);
+       ret = tdm_buffer_add_release_handler(b, layer_cb_buffer_release, NULL);
+       TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
 
        if (data->do_vblank)
-               ret = tdm_output_commit(l->o->output, 0, layer_cb_commit, l);
+               ret = tdm_layer_commit(l->layer, layer_cb_commit, l);
        else
-               ret = tdm_output_commit(l->o->output, 0, NULL, NULL);
+               ret = tdm_layer_commit(l->layer, NULL, NULL);
        TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
 
        printf("show:\tl(%p) b(%p)\n", l, b);
@@ -1059,22 +1071,12 @@ layer_setup(tdm_test_server_layer *l, tbm_surface_h b)
 
        /* The size and format information should be same with buffer's */
        tbm_surface_get_info(b, &info);
-       if (tts_screen_prerotation_hint % 180) {
-               if (IS_RGB(info.format)) {
-                       l->info.src_config.size.h = info.height;
-                       l->info.src_config.size.v = info.planes[0].stride >> 2;
-               } else {
-                       l->info.src_config.size.h = info.height;
-                       l->info.src_config.size.v = info.planes[0].stride;
-               }
+       if (IS_RGB(info.format)) {
+               l->info.src_config.size.h = info.planes[0].stride >> 2;
+               l->info.src_config.size.v = info.height;
        } else {
-               if (IS_RGB(info.format)) {
-                       l->info.src_config.size.h = info.planes[0].stride >> 2;
-                       l->info.src_config.size.v = info.height;
-               } else {
-                       l->info.src_config.size.h = info.planes[0].stride;
-                       l->info.src_config.size.v = info.height;
-               }
+               l->info.src_config.size.h = info.planes[0].stride;
+               l->info.src_config.size.v = info.height;
        }
        l->info.src_config.format = info.format;
 
@@ -1108,9 +1110,9 @@ pp_get_buffer(tdm_test_server_pp *p)
        int i, size = TDM_ARRAY_SIZE(p->bufs);
        if (!p->bufs[0]) {
                for (i = 0; i < size; i++) {
-                       int width = (p->info.src_config.size.h)?:p->info.src_config.pos.w;
-                       int height = (p->info.src_config.size.v)?:p->info.src_config.pos.h;
-                       unsigned int format = (p->info.src_config.format)?:DEFAULT_FORMAT;
+                       int width = (p->info.src_config.size.h) ? : p->info.src_config.pos.w;
+                       int height = (p->info.src_config.size.v) ? : p->info.src_config.pos.h;
+                       unsigned int format = (p->info.src_config.format) ? : DEFAULT_FORMAT;
                        tbm_surface_h b = buffer_allocate(width, height, format, 0);
                        TDM_EXIT_IF_FAIL(b != NULL);
                        p->bufs[i] = b;
@@ -1364,6 +1366,7 @@ capture_setup(tdm_test_server_capture *c, tbm_surface_h b)
                c->info.dst_config.size.v = info.height;
        }
        c->info.dst_config.format = info.format;
+       c->info.type = TDM_CAPTURE_TYPE_ONESHOT;
 
        ret = tdm_capture_set_info(c->capture, &c->info);
        TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
@@ -1430,8 +1433,12 @@ run_test(tdm_test_server *data)
 
        printf("enter test loop\n");
 
-       while (1)
-               tdm_display_handle_events(data->display);
+       while (1) {
+               ret = tdm_display_handle_events(data->display);
+               TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
+       }
+
+       destroy(data);
 
        return;
 no_pp: