1 /**************************************************************************
5 * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
7 * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
8 * JinYoung Jeon <jy0.jeon@samsung.com>,
9 * Taeheon Kim <th908.kim@samsung.com>,
10 * YoungJun Cho <yj44.cho@samsung.com>,
11 * SooChan Lim <sc1.lim@samsung.com>,
12 * Boram Park <sc1.lim@samsung.com>
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the
16 * "Software"), to deal in the Software without restriction, including
17 * without limitation the rights to use, copy, modify, merge, publish,
18 * distribute, sub license, and/or sell copies of the Software, and to
19 * permit persons to whom the Software is furnished to do so, subject to
20 * the following conditions:
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
29 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
30 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 **************************************************************************/
45 #include <tbm_surface.h>
46 #include <tbm_surface_internal.h>
51 #include "tdm_helper.h"
52 #include "tdm_backend.h"
54 #include "tdm_macro.h"
55 #include "tdm_private.h"
58 ////////////////////////////////////////////////////////////////////////////////
79 static struct typestrings typestrs[] = {
80 {OPT_QRY, "Query", NULL},
81 {OPT_TST, "Test", NULL},
82 {OPT_GEN, "General", NULL},
85 static struct optstrings optstrs[] = {
87 OPT_QRY, "q", "show tdm output, layer information",
91 OPT_TST, "a", "set all layer objects for all connected outputs",
95 OPT_TST, "o", "set a mode for a output object",
96 "<output_idx>@<mode>[&<refresh>]", "0@1920x1080"
99 OPT_TST, "l", "set a layer object",
100 "<layer_idx>[:<w>x<h>[+<x>+<y>][,<h>x<v>][@<format>]]~<w>x<h>[+<x>+<y>][*<transform>]", NULL
103 OPT_TST, "p", "set a PP object.\n\t\t'-l' is used to show the result on screen.",
104 "<w>x<h>[+<x>+<y>][,<h>x<v>][@<format>]~<w>x<h>[+<x>+<y>][,<h>x<v>][@<format>][*<transform>][&<fps>]", NULL
107 OPT_TST, "c", "catpure a output object or a layer object.\n\t\t'-l' is used to show the result on screen.",
108 "<output_idx>[,<layer_idx>]~<w>x<h>[+<x>+<y>][,<h>x<v>][@<format>][*<transform>][^stream]", NULL
111 OPT_GEN, "w", "set the property of a object",
112 "<prop_name>:<value>", NULL
115 OPT_GEN, "b", "set the fill(smtpe,tiles,plain) and framebuffer type(scanout,noncachable,wc)",
116 "<fill>[:<buf_flag>[,<buf_flag2>[,...]]]", NULL
119 OPT_GEN, "v", "update layers every vblank",
129 static struct usagestring usages[] = {
136 "test all outputs, layers with plain buffers"
140 "Set the \"1920x1080\" mode to the output 0. And show a buffer via a primary layer of the output 0"
143 "-o 0@1920x1080 -l 1~640x480+50+100",
144 "Create the 640x480 buffer and show it in the (50,100) pos of screen via the layer 1"
147 "-p 320x240@NV12~480x360+80+40,640x480@AR24 -l 1~640x480+50+100",
148 "Convert the 320x240@NV12 buffer to the 640x480@AR24 buffer(480x360+80+40) and show the result via the layer 1"
153 usage(char *app_name)
155 int type_size = sizeof(typestrs) / sizeof(struct typestrings);
156 int opt_size = sizeof(optstrs) / sizeof(struct optstrings);
157 int usages_size = sizeof(usages) / sizeof(struct usagestring);
160 printf("usage: %s \n\n", app_name);
162 for (t = 0; t < type_size; t++) {
165 for (o = 0; o < opt_size; o++)
166 if (optstrs[o].type == typestrs[t].type) {
168 printf(" %s options: %s\n\n", typestrs[t].string, (typestrs[t].desc) ? : "");
169 printf("\t-%s\t%s\n", optstrs[o].opt, optstrs[o].desc);
171 printf("\t\t %s\n", optstrs[o].arg);
173 printf("\t\t ex) %s\n", optstrs[o].ex);
179 printf(" For example)\n\n");
181 for (t = 0; t < usages_size; t++) {
182 printf(" $ %s %s\n", app_name, usages[t].string);
183 printf("\t%s\n", usages[t].desc);
189 ////////////////////////////////////////////////////////////////////////////////
191 static const char *tdm_buf_flag_names[] = {
196 TDM_BIT_NAME_FB(buf_flag)
198 #define DEFAULT_FORMAT TBM_FORMAT_ARGB8888
200 #define print_size(s) \
201 printf("%dx%d", (s)->h, (s)->v)
202 #define print_pos(p) \
203 printf("%dx%d+%d+%d", (p)->w, (p)->h, (p)->x, (p)->y)
204 #define print_format(f) \
205 if (f) printf("%c%c%c%c", FOURCC_STR(f)); \
207 #define print_config(c) \
209 print_size(&(c)->size); \
211 print_pos(&(c)->pos); \
213 print_format((c)->format); \
215 #define print_prop(w) \
216 printf("%s(%d)", (w)->name, ((w)->value).u32)
218 typedef struct _tdm_test_server tdm_test_server;
219 typedef struct _tdm_test_server_layer tdm_test_server_layer;
220 typedef struct _tdm_test_server_capture tdm_test_server_capture;
222 typedef struct _tdm_test_server_prop {
224 char name[TDM_NAME_LEN];
227 /* variables for test */
228 struct list_head link;
229 } tdm_test_server_prop;
231 typedef struct _tdm_test_server_buffer {
232 /* variables for test */
235 tdm_test_server_layer *l;
237 tdm_test_server_capture *c;
238 tdm_buffer_release_handler done;
239 } tdm_test_server_buffer;
241 typedef struct _tdm_test_server_output {
244 char mode[TDM_NAME_LEN];
247 /* variables for test */
248 struct list_head link;
249 struct list_head prop_list;
250 struct list_head layer_list;
251 tdm_test_server *data;
254 int fill_primary_layer;
255 } tdm_test_server_output;
257 typedef struct _tdm_test_server_pp {
262 /* variables for test */
263 struct list_head link;
264 tdm_test_server *data;
265 tdm_test_server_layer *l;
267 tbm_surface_h bufs[6];
270 tdm_event_loop_source *timer_source;
271 } tdm_test_server_pp;
273 struct _tdm_test_server_capture {
277 tdm_info_capture info;
279 /* variables for test */
280 struct list_head link;
281 tdm_test_server *data;
282 tdm_test_server_layer *l;
283 tdm_capture *capture;
286 struct _tdm_test_server_layer {
291 /* variables for test */
292 struct list_head link;
293 struct list_head prop_list;
294 tdm_test_server *data;
295 tdm_test_server_output *o;
298 tdm_test_server_pp *owner_p;
299 tdm_test_server_capture *owner_c;
300 tbm_surface_h bufs[3];
304 struct _tdm_test_server {
312 /* variables for test */
313 struct list_head output_list;
314 struct list_head pp_list;
315 struct list_head capture_list;
316 tdm_display *display;
319 static void run_test(tdm_test_server *data);
320 static void output_setup(tdm_test_server_output *o);
321 static void layer_show_buffer(tdm_test_server_layer *l, tbm_surface_h b);
322 static void capture_attach(tdm_test_server_capture *c, tbm_surface_h b);
325 parse_size(tdm_size *size, char *arg)
328 size->h = strtol(arg, &end, 10);
329 TDM_EXIT_IF_FAIL(*end == 'x');
331 size->v = strtol(arg, &end, 10);
336 parse_pos(tdm_pos *pos, char *arg)
339 pos->w = strtol(arg, &end, 10);
340 TDM_EXIT_IF_FAIL(*end == 'x');
342 pos->h = strtol(arg, &end, 10);
345 pos->x = strtol(arg, &end, 10);
346 TDM_EXIT_IF_FAIL(*end == '+');
348 pos->y = strtol(arg, &end, 10);
354 parse_config(tdm_info_config *config, char *arg)
357 end = parse_pos(&config->pos, arg);
360 end = parse_size(&config->size, arg);
365 end = strtostr(temp, 32, arg, TDM_DELIM);
366 config->format = FOURCC_ID(temp);
372 parse_arg_o(tdm_test_server_output *o, char *arg)
375 TDM_EXIT_IF_FAIL(arg != NULL);
376 o->idx = strtol(arg, &end, 10);
377 TDM_EXIT_IF_FAIL(*end == '@');
379 end = strtostr(o->mode, TDM_NAME_LEN, arg, TDM_DELIM);
382 o->refresh = strtol(arg, &end, 10);
387 parse_arg_p(tdm_test_server_pp *p, char *arg)
389 tdm_info_pp *pp_info = &p->info;
391 TDM_EXIT_IF_FAIL(arg != NULL);
392 end = parse_config(&pp_info->src_config, arg);
393 TDM_EXIT_IF_FAIL(*end == '~');
395 end = parse_config(&pp_info->dst_config, arg);
398 pp_info->transform = strtol(arg, &end, 10);
402 p->fps = strtol(arg, &end, 10);
407 parse_arg_c(tdm_test_server_capture *c, char *arg)
409 tdm_info_capture *capture_info = &c->info;
411 TDM_EXIT_IF_FAIL(arg != NULL);
412 c->output_idx = strtol(arg, &end, 10);
415 c->layer_idx = strtol(arg, &end, 10);
417 TDM_EXIT_IF_FAIL(*end == '~');
419 end = parse_config(&capture_info->dst_config, arg);
422 capture_info->transform = strtol(arg, &end, 10);
426 if (strtol(arg, &end, 10) > 0)
427 capture_info->type = TDM_CAPTURE_TYPE_STREAM;
429 capture_info->type = TDM_CAPTURE_TYPE_ONESHOT;
434 parse_arg_l(tdm_test_server_layer *l, char *arg)
436 tdm_info_layer *layer_info = &l->info;
438 TDM_EXIT_IF_FAIL(arg != NULL);
439 l->idx = strtol(arg, &end, 10);
442 end = parse_config(&layer_info->src_config, arg);
444 TDM_EXIT_IF_FAIL(*end == '~');
446 end = parse_pos(&layer_info->dst_pos, arg);
449 layer_info->transform = strtol(arg, &end, 10);
454 parse_arg_w(tdm_test_server_prop *w, char *arg)
457 TDM_EXIT_IF_FAIL(arg != NULL);
458 end = strtostr(w->name, TDM_PATH_LEN, arg, TDM_DELIM);
459 TDM_EXIT_IF_FAIL(*end == ':');
461 w->value.u32 = strtol(arg, &end, 10);
465 parse_arg_b(tdm_test_server *data, char *arg)
468 char temp[TDM_NAME_LEN] = {0,};
469 TDM_EXIT_IF_FAIL(arg != NULL);
471 end = strtostr(temp, 32, arg, TDM_DELIM);
472 if (!strncmp(temp, "smpte", 5))
473 data->b_fill = PATTERN_SMPTE;
474 else if (!strncmp(temp, "tiles", 5))
475 data->b_fill = PATTERN_TILES;
476 else if (!strncmp(temp, "plain", 5))
477 data->b_fill = PATTERN_PLAIN;
479 printf("'%s': unknown flag\n", temp);
486 snprintf(temp, TDM_NAME_LEN, "%s", arg);
487 arg = strtok_r(temp, ",", &end);
489 if (!strncmp(arg, "default", 7))
490 printf("Ignore '%s' flag\n", arg);
491 else if (!strncmp(arg, "scanout", 7))
492 data->bflags |= TBM_BO_SCANOUT;
493 else if (!strncmp(arg, "noncachable", 11))
494 data->bflags |= TBM_BO_NONCACHABLE;
495 else if (!strncmp(arg, "wc", 2))
496 data->bflags |= TBM_BO_WC;
498 printf("'%s': unknown flag\n", arg);
501 arg = strtok_r(NULL, ",", &end);
507 parse_args(tdm_test_server *data, int argc, char *argv[])
509 tdm_test_server_output *o = NULL;
510 tdm_test_server_layer *l = NULL;
511 tdm_test_server_pp *p = NULL;
512 tdm_test_server_capture *c = NULL;
513 tdm_test_server_prop *w = NULL;
514 void *last_option = NULL;
515 void *last_object = NULL;
523 for (i = 1; i < argc; i++) {
524 if (!strncmp(argv[i] + 1, "q", 1)) {
527 } else if (!strncmp(argv[i] + 1, "a", 1)) {
529 } else if (!strncmp(argv[i] + 1, "o", 1)) {
530 TDM_GOTO_IF_FAIL(data->do_all == 0, all);
531 o = calloc(1, sizeof * o);
532 TDM_EXIT_IF_FAIL(o != NULL);
534 LIST_INITHEAD(&o->layer_list);
535 LIST_INITHEAD(&o->prop_list);
536 LIST_ADDTAIL(&o->link, &data->output_list);
537 parse_arg_o(o, argv[++i]);
539 } else if (!strncmp(argv[i] + 1, "p", 1)) {
540 TDM_GOTO_IF_FAIL(data->do_all == 0, all);
541 p = calloc(1, sizeof * p);
542 TDM_EXIT_IF_FAIL(p != NULL);
544 p->fps = 30; /* default 30 fps */
545 LIST_ADDTAIL(&p->link, &data->pp_list);
546 parse_arg_p(p, argv[++i]);
548 } else if (!strncmp(argv[i] + 1, "c", 1)) {
549 TDM_GOTO_IF_FAIL(data->do_all == 0, all);
550 c = calloc(1, sizeof * c);
551 TDM_EXIT_IF_FAIL(c != NULL);
555 LIST_ADDTAIL(&c->link, &data->capture_list);
556 parse_arg_c(c, argv[++i]);
558 } else if (!strncmp(argv[i] + 1, "l", 1)) {
559 TDM_GOTO_IF_FAIL(data->do_all == 0, all);
561 o = calloc(1, sizeof * o);
562 TDM_EXIT_IF_FAIL(o != NULL);
564 LIST_INITHEAD(&o->layer_list);
565 LIST_INITHEAD(&o->prop_list);
566 LIST_ADDTAIL(&o->link, &data->output_list);
568 l = calloc(1, sizeof * l);
569 TDM_EXIT_IF_FAIL(l != NULL);
570 LIST_INITHEAD(&l->prop_list);
571 LIST_ADDTAIL(&l->link, &o->layer_list);
574 parse_arg_l(l, argv[++i]);
575 if (p && last_option == p) {
578 } else if (c && last_option == c) {
583 } else if (!strncmp(argv[i] + 1, "w", 1)) {
584 TDM_GOTO_IF_FAIL(data->do_all == 0, all);
587 w = calloc(1, sizeof * w);
588 TDM_EXIT_IF_FAIL(w != NULL);
589 if (o && last_object == o)
590 LIST_ADDTAIL(&w->link, &o->prop_list);
591 else if (l && last_object == l)
592 LIST_ADDTAIL(&w->link, &l->prop_list);
593 parse_arg_w(w, argv[++i]);
594 } else if (!strncmp(argv[i] + 1, "b", 1)) {
595 parse_arg_b(data, argv[++i]);
596 } else if (!strncmp(argv[i] + 1, "v", 1)) {
604 LIST_FOR_EACH_ENTRY(p, &data->pp_list, link) {
608 LIST_FOR_EACH_ENTRY(c, &data->capture_list, link) {
615 printf("Use '-l' to set a layer for '-p' or '-c'.\n");
618 printf("Use '-o' or '-l' to set a object first.\n");
621 printf("Can't use '-%s' with '-a'.\n", argv[i] + 1);
626 interpret_args(tdm_test_server *data)
628 tdm_test_server_output *o = NULL;
629 tdm_test_server_layer *l = NULL;
632 /* create the objects of outputs */
636 ret = tdm_display_get_output_count(data->display, &output_count);
637 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
639 for (i = 0; i < output_count; i++) {
640 tdm_output *output = tdm_display_get_output(data->display, i, NULL);
641 tdm_output_conn_status status;
642 ret = tdm_output_get_conn_status(output, &status);
643 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
645 if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
647 o = calloc(1, sizeof * o);
648 TDM_EXIT_IF_FAIL(o != NULL);
650 LIST_INITHEAD(&o->layer_list);
651 LIST_INITHEAD(&o->prop_list);
652 LIST_ADDTAIL(&o->link, &data->output_list);
654 o->fill_primary_layer = 1;
658 /* check if the primary layer object exists */
659 LIST_FOR_EACH_ENTRY(o, &data->output_list, link) {
661 const tdm_output_mode *mode;
662 int j, layer_count, primary_index = 0;
663 tdm_test_server_layer *primary_l = NULL;
667 output = tdm_display_get_output(data->display, o->idx, &ret);
668 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
669 ret = tdm_output_get_mode(output, &mode);
670 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
671 ret = tdm_output_get_layer_count(output, &layer_count);
672 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
673 ret = tdm_output_get_primary_index(output, &primary_index);
674 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
676 if (LIST_IS_EMPTY(&o->layer_list))
677 o->fill_primary_layer = 1;
679 LIST_FOR_EACH_ENTRY(l, &o->layer_list, link) {
680 if (l->idx == primary_index) {
682 o->fill_primary_layer = 1;
689 if (!primary_l || data->do_all) {
690 for (j = 0; j < layer_count; j++) {
691 if (j != primary_index && !data->do_all)
693 l = calloc(1, sizeof * l);
694 TDM_EXIT_IF_FAIL(l != NULL);
695 LIST_INITHEAD(&l->prop_list);
696 LIST_ADDTAIL(&l->link, &o->layer_list);
700 if (j == primary_index) {
702 l->info.dst_pos.w = mode->hdisplay;
703 l->info.dst_pos.h = mode->vdisplay;
706 l->info.dst_pos.w = TDM_ALIGN(mode->hdisplay / 3, 2);
707 l->info.dst_pos.h = TDM_ALIGN(mode->vdisplay / 3, 2);
708 l->info.dst_pos.x = TDM_ALIGN(((mode->hdisplay / 3) / layer_count) * j, 2);
709 l->info.dst_pos.y = TDM_ALIGN(((mode->vdisplay / 3) / layer_count) * j, 2);
714 TDM_EXIT_IF_FAIL(primary_l != NULL);
715 LIST_DEL(&primary_l->link);
716 LIST_ADD(&primary_l->link, &o->layer_list);
719 /* fill the empty information of layers */
720 LIST_FOR_EACH_ENTRY(o, &data->output_list, link) {
722 int minw, minh, maxw, maxh;
724 output = tdm_display_get_output(data->display, o->idx, &ret);
725 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
726 ret = tdm_output_get_available_size(output, &minw, &minh, &maxw, &maxh, NULL);
727 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
729 /* l->info.src_config.size will be decided when a buffer shows really */
730 LIST_FOR_EACH_ENTRY(l, &o->layer_list, link) {
731 if (minw > 0 && minh > 0) {
732 TDM_EXIT_IF_FAIL(l->info.dst_pos.w >= minw);
733 TDM_EXIT_IF_FAIL(l->info.dst_pos.h >= minh);
735 if (maxw > 0 && maxh > 0) {
736 TDM_EXIT_IF_FAIL(l->info.dst_pos.w <= maxw);
737 TDM_EXIT_IF_FAIL(l->info.dst_pos.h <= maxh);
741 l->info.src_config.format = l->owner_p->info.dst_config.format;
742 if (l->info.src_config.pos.w == 0) {
743 TDM_EXIT_IF_FAIL(l->owner_p->info.dst_config.size.h > 0);
744 l->info.src_config.pos.w = l->owner_p->info.dst_config.size.h;
745 l->info.src_config.pos.h = l->owner_p->info.dst_config.size.v;
747 } else if (l->owner_c) {
748 l->info.src_config.format = l->owner_c->info.dst_config.format;
749 if (l->info.src_config.pos.w == 0) {
750 TDM_EXIT_IF_FAIL(l->owner_c->info.dst_config.size.h > 0);
751 l->info.src_config.pos.w = l->owner_c->info.dst_config.size.h;
752 l->info.src_config.pos.h = l->owner_c->info.dst_config.size.v;
755 if (l->info.src_config.pos.w == 0) {
756 TDM_EXIT_IF_FAIL(l->info.dst_pos.w > 0);
757 l->info.src_config.pos.w = l->info.dst_pos.w;
758 l->info.src_config.pos.h = l->info.dst_pos.h;
765 static tdm_test_server tts_data;
766 static int tts_buffer_key;
767 #define TTS_BUFFER_KEY ((unsigned long)&tts_buffer_key)
770 buffer_allocate(int width, int height, int format, int flags)
772 tdm_test_server_buffer *tb = calloc(1, sizeof *tb);
773 TDM_EXIT_IF_FAIL(tb != NULL);
774 tb->b = tbm_surface_internal_create_with_flags(width, height, format, flags);
775 TDM_EXIT_IF_FAIL(tb->b != NULL);
776 tdm_helper_clear_buffer(tb->b);
777 tbm_surface_internal_add_user_data(tb->b, TTS_BUFFER_KEY, free);
778 tbm_surface_internal_set_user_data(tb->b, TTS_BUFFER_KEY, tb);
782 static tdm_test_server_buffer*
783 get_tts_buffer(tbm_surface_h b)
785 tdm_test_server_buffer *tb = NULL;
786 tbm_surface_internal_get_user_data(b, TTS_BUFFER_KEY, (void **)&tb);
791 destroy(tdm_test_server *data)
793 tdm_test_server_output *o = NULL, *oo = NULL;
794 tdm_test_server_layer *l = NULL, *ll = NULL;
795 tdm_test_server_pp *p = NULL, *pp = NULL;
796 tdm_test_server_capture *c = NULL, *cc = NULL;
797 tdm_test_server_prop *w = NULL, *ww = NULL;
800 LIST_FOR_EACH_ENTRY_SAFE(c, cc, &data->capture_list, link) {
802 tdm_capture_destroy(c->capture);
806 LIST_FOR_EACH_ENTRY_SAFE(p, pp, &data->pp_list, link) {
807 tdm_display_lock(data->display);
808 tdm_event_loop_source_remove(p->timer_source);
809 tdm_display_unlock(data->display);
811 tdm_pp_destroy(p->pp);
814 LIST_FOR_EACH_ENTRY_SAFE(o, oo, &data->output_list, link) {
815 LIST_FOR_EACH_ENTRY_SAFE(l, ll, &o->layer_list, link) {
816 tdm_layer_unset_buffer(l->layer);
818 tdm_layer_commit(l->layer, NULL, NULL);
821 LIST_FOR_EACH_ENTRY_SAFE(p, pp, &data->pp_list, link) {
823 for (i = 0; i < TDM_ARRAY_SIZE(p->bufs); i++)
824 tbm_surface_destroy(p->bufs[i]);
828 LIST_FOR_EACH_ENTRY_SAFE(o, oo, &data->output_list, link) {
830 LIST_FOR_EACH_ENTRY_SAFE(l, ll, &o->layer_list, link) {
832 LIST_FOR_EACH_ENTRY_SAFE(w, ww, &l->prop_list, link) {
836 for (i = 0; i < TDM_ARRAY_SIZE(l->bufs); i++)
837 tbm_surface_destroy(l->bufs[i]);
840 LIST_FOR_EACH_ENTRY_SAFE(w, ww, &o->prop_list, link) {
849 tdm_display_deinit(data->display);
855 main(int argc, char *argv[])
857 tdm_test_server *data = &tts_data;
858 char temp[TDM_SERVER_REPLY_MSG_LEN];
859 int len = sizeof temp;
862 #if 1 /* for testing */
863 const char *s = (const char*)getenv("XDG_RUNTIME_DIR");
866 snprintf(buf, sizeof(buf), "/run");
867 int ret = setenv("XDG_RUNTIME_DIR", (const char*)buf, 1);
872 s = (const char*)getenv("TBM_DISPLAY_SERVER");
875 snprintf(buf, sizeof(buf), "1");
876 int ret = setenv("TBM_DISPLAY_SERVER", (const char*)buf, 1);
882 memset(data, 0, sizeof * data);
883 LIST_INITHEAD(&data->output_list);
884 LIST_INITHEAD(&data->pp_list);
885 LIST_INITHEAD(&data->capture_list);
888 data->bflags = TBM_BO_SCANOUT;
889 data->b_fill = PATTERN_SMPTE;
891 data->display = tdm_display_init(&ret);
892 TDM_EXIT_IF_FAIL(data->display != NULL);
894 parse_args(data, argc, argv);
895 interpret_args(data);
897 if (data->do_query) {
898 tdm_helper_get_display_information(data->display, temp, &len);
906 tdm_display_deinit(data->display);
912 output_setup(tdm_test_server_output *o)
914 tdm_test_server *data = o->data;
915 const tdm_output_mode *modes, *found = NULL, *best = NULL, *prefer = NULL;
916 tdm_test_server_prop *w = NULL;
917 const tdm_prop *props;
921 o->output = tdm_display_get_output(data->display, o->idx, &ret);
922 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
924 ret = tdm_output_get_available_modes(o->output, &modes, &count);
925 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
927 for (i = 0; i < count; i++) {
928 if (!strncmp(o->mode, modes[i].name, TDM_NAME_LEN) && o->refresh == modes[i].vrefresh) {
930 printf("found mode: %dx%d %d\n", found->hdisplay, found->vdisplay, found->vrefresh);
935 if (modes[i].type & TDM_OUTPUT_MODE_TYPE_PREFERRED)
938 if (!found && prefer) {
940 printf("found prefer mode: %dx%d %d\n", found->hdisplay, found->vdisplay, found->vrefresh);
942 if (!found && best) {
944 printf("found best mode: %dx%d %d\n", found->hdisplay, found->vdisplay, found->vrefresh);
948 printf("couldn't find any mode\n");
952 ret = tdm_output_set_mode(o->output, found);
953 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
955 printf("output %d: %s %d\n", o->idx, found->name, found->vrefresh);
957 ret = tdm_output_get_available_properties(o->output, &props, &count);
958 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
960 LIST_FOR_EACH_ENTRY(w, &o->prop_list, link) {
961 for (i = 0; i < count; i++) {
962 if (strncmp(w->name, props[i].name, TDM_NAME_LEN))
964 ret = tdm_output_set_property(o->output, props[i].id, w->value);
965 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
966 printf("\tprop '%s': %d\n", props[i].name, w->value.u32);
971 /* DPMS on forcely at the first time. */
972 ret = tdm_output_set_dpms(o->output, TDM_OUTPUT_DPMS_ON);
973 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
977 layer_get_buffer(tdm_test_server_layer *l)
979 int i, size = TDM_ARRAY_SIZE(l->bufs);
981 for (i = 0; i < size; i++) {
982 int width = (l->info.src_config.size.h) ? : l->info.src_config.pos.w;
983 int height = (l->info.src_config.size.v) ? : l->info.src_config.pos.h;
984 unsigned int format = (l->info.src_config.format) ? : DEFAULT_FORMAT;
985 int flags = l->o->data->bflags;
986 tbm_surface_h b = buffer_allocate(width, height, format, flags);
987 TDM_EXIT_IF_FAIL(b != NULL);
991 for (i = 0; i < size; i++) {
992 tdm_test_server_buffer *tb = get_tts_buffer(l->bufs[i]);
993 TDM_EXIT_IF_FAIL(tb != NULL);
997 printf("no available layer buffer.\n");
1002 layer_cb_commit(tdm_layer *layer, unsigned int sequence,
1003 unsigned int tv_sec, unsigned int tv_usec,
1006 tdm_test_server_layer *l = user_data;
1007 tbm_surface_h b = layer_get_buffer(l);
1008 TDM_EXIT_IF_FAIL(b != NULL);
1010 if (!l->is_primary || l->o->fill_primary_layer)
1011 tdm_test_buffer_fill(b, l->data->b_fill);
1013 if (!l->is_primary || l->o->fill_primary_layer)
1014 layer_show_buffer(l, b);
1018 layer_cb_buffer_release(tbm_surface_h b, void *user_data)
1020 tdm_test_server_buffer *tb = get_tts_buffer(b);
1021 TDM_EXIT_IF_FAIL(tb != NULL);
1024 tdm_buffer_remove_release_handler(b, layer_cb_buffer_release, NULL);
1026 tb->done(b, user_data);
1030 layer_show_buffer(tdm_test_server_layer *l, tbm_surface_h b)
1032 tdm_test_server *data = l->o->data;
1033 tdm_test_server_buffer *tb;
1036 ret = tdm_layer_set_buffer(l->layer, b);
1037 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1039 tb = get_tts_buffer(b);
1040 TDM_EXIT_IF_FAIL(tb != NULL);
1043 tdm_buffer_add_release_handler(b, layer_cb_buffer_release, NULL);
1045 if (data->do_vblank)
1046 ret = tdm_layer_commit(l->layer, layer_cb_commit, l);
1048 ret = tdm_layer_commit(l->layer, NULL, NULL);
1049 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1051 printf("show:\tl(%p) b(%p)\n", l, b);
1055 layer_setup(tdm_test_server_layer *l, tbm_surface_h b)
1057 tdm_test_server_prop *w = NULL;
1058 const tdm_prop *props;
1061 tbm_surface_info_s info;
1063 l->layer = tdm_output_get_layer(l->o->output, l->idx, &ret);
1064 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1066 /* The size and format information should be same with buffer's */
1067 tbm_surface_get_info(b, &info);
1068 if (IS_RGB(info.format)) {
1069 l->info.src_config.size.h = info.planes[0].stride >> 2;
1070 l->info.src_config.size.v = info.height;
1072 l->info.src_config.size.h = info.planes[0].stride;
1073 l->info.src_config.size.v = info.height;
1075 l->info.src_config.format = info.format;
1077 ret = tdm_layer_set_info(l->layer, &l->info);
1078 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1080 printf("layer %d: output(%d) ", l->idx, l->o->idx);
1081 print_config(&l->info.src_config);
1083 print_pos(&l->info.dst_pos);
1084 printf(" transform(%s)\n", tdm_transform_str(l->info.transform));
1086 ret = tdm_layer_get_available_properties(l->layer, &props, &count);
1087 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1089 LIST_FOR_EACH_ENTRY(w, &l->prop_list, link) {
1090 for (i = 0; i < count; i++) {
1091 if (strncmp(w->name, props[i].name, TDM_NAME_LEN))
1093 ret = tdm_layer_set_property(l->layer, props[i].id, w->value);
1094 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1095 printf("\tprop '%s': %d\n", props[i].name, w->value.u32);
1101 static tbm_surface_h
1102 pp_get_buffer(tdm_test_server_pp *p)
1104 int i, size = TDM_ARRAY_SIZE(p->bufs);
1106 for (i = 0; i < size; i++) {
1107 int width = (p->info.src_config.size.h) ? : p->info.src_config.pos.w;
1108 int height = (p->info.src_config.size.v) ? : p->info.src_config.pos.h;
1109 unsigned int format = (p->info.src_config.format) ? : DEFAULT_FORMAT;
1110 tbm_surface_h b = buffer_allocate(width, height, format, 0);
1111 TDM_EXIT_IF_FAIL(b != NULL);
1115 for (i = 0; i < size; i++) {
1116 tdm_test_server_buffer *tb = get_tts_buffer(p->bufs[i]);
1122 tdm_test_buffer_fill(p->bufs[i], p->data->b_fill);
1126 printf("no available pp buffer.\n");
1131 pp_cb_done(tdm_pp *pp, tbm_surface_h sb, tbm_surface_h db, void *user_data)
1133 tdm_test_server_buffer *stb, *dtb;
1135 stb = get_tts_buffer(sb);
1136 TDM_EXIT_IF_FAIL(stb != NULL);
1138 dtb = get_tts_buffer(db);
1139 TDM_EXIT_IF_FAIL(dtb != NULL);
1141 stb->in_use = dtb->in_use = 0;
1143 layer_show_buffer(dtb->l, db);
1147 pp_convert_buffer(tdm_test_server_pp *p, tbm_surface_h sb, tbm_surface_h db)
1149 tdm_test_server_buffer *stb, *dtb;
1152 stb = get_tts_buffer(sb);
1153 TDM_EXIT_IF_FAIL(stb != NULL);
1155 dtb = get_tts_buffer(db);
1156 TDM_EXIT_IF_FAIL(dtb != NULL);
1158 stb->in_use = dtb->in_use = 1;
1161 ret = tdm_pp_attach(p->pp, sb, db);
1162 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1164 ret = tdm_pp_commit(p->pp);
1165 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1167 printf("convt:\tp(%p) sb(%p) db(%p)\n", p, sb, db);
1170 /* tdm_event_loop_xxx() function is not for the display server. It's for TDM
1171 * backend module. I use them only for simulating the video play. When we call
1172 * tdm_event_loop_xxx() outside of TDM backend module, we have to lock/unlock
1173 * the TDM display. And when the callback function of tdm_event_loop_xxx() is
1174 * called, the display has been already locked. So in this test application,
1175 * we have to unlock/lock the display for testing.
1178 pp_cb_timeout(void *user_data)
1180 tdm_test_server_pp *p = user_data;
1181 tdm_test_server *data = p->l->o->data;
1182 tbm_surface_h sb, db;
1185 tdm_display_unlock(data->display);
1187 sb = pp_get_buffer(p);
1188 TDM_EXIT_IF_FAIL(sb != NULL);
1189 db = layer_get_buffer(p->l);
1190 TDM_EXIT_IF_FAIL(db != NULL);
1192 pp_convert_buffer(p, sb, db);
1194 tdm_display_lock(data->display);
1195 ret = tdm_event_loop_source_timer_update(p->timer_source, 1000 / p->fps);
1196 tdm_display_unlock(data->display);
1197 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1199 tdm_display_lock(data->display);
1201 return TDM_ERROR_NONE;
1205 pp_setup(tdm_test_server_pp *p, tbm_surface_h sb, tbm_surface_h db)
1207 tdm_test_server *data;
1208 tbm_surface_info_s info;
1211 if (!p || !p->l || !p->l->o || !p->l->o->data) {
1212 TDM_ERR("invalid parameter failed");
1215 data = p->l->o->data;
1217 p->pp = tdm_display_create_pp(data->display, &ret);
1218 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1220 /* The size and format information should be same with buffer's */
1221 tbm_surface_get_info(sb, &info);
1222 if (IS_RGB(info.format)) {
1223 p->info.src_config.size.h = info.planes[0].stride >> 2;
1224 p->info.src_config.size.v = info.height;
1226 p->info.src_config.size.h = info.planes[0].stride;
1227 p->info.src_config.size.v = info.height;
1229 p->info.src_config.format = info.format;
1231 /* The size and format information should be same with buffer's */
1232 tbm_surface_get_info(db, &info);
1233 if (IS_RGB(info.format)) {
1234 p->info.dst_config.size.h = info.planes[0].stride >> 2;
1235 p->info.dst_config.size.v = info.height;
1237 p->info.dst_config.size.h = info.planes[0].stride;
1238 p->info.dst_config.size.v = info.height;
1240 p->info.dst_config.format = info.format;
1242 ret = tdm_pp_set_info(p->pp, &p->info);
1243 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1245 ret = tdm_pp_set_done_handler(p->pp, pp_cb_done, NULL);
1246 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1249 print_config(&p->info.src_config);
1251 print_config(&p->info.dst_config);
1252 printf(" fps(%d) transform(%s)\n", p->fps, tdm_transform_str(p->info.transform));
1253 printf("\toutput_idx(%d) layer_idx(%d)\n", p->l->o->idx, p->l->idx);
1255 layer_setup(p->l, db);
1257 /* tdm_event_loop_xxx() function is not for the display server. It's for TDM
1258 * backend module. I use them only for simulating the video play. When we call
1259 * tdm_event_loop_xxx() outside of TDM backend module, we have to lock/unlock
1260 * the TDM display. And when the callback function of tdm_event_loop_xxx() is
1261 * called, the display has been already locked. So in this test application,
1262 * we have to unlock/lock the display for testing.
1264 tdm_display_lock(data->display);
1265 p->timer_source = tdm_event_loop_add_timer_handler(data->display, pp_cb_timeout, p, &ret);
1266 tdm_display_unlock(data->display);
1267 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1269 tdm_display_lock(data->display);
1270 ret = tdm_event_loop_source_timer_update(p->timer_source, 1000 / p->fps);
1271 tdm_display_unlock(data->display);
1272 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1276 capture_cb_buffer_done(tbm_surface_h b, void *user_data)
1278 tdm_test_server_buffer *tb;
1280 tb = get_tts_buffer(b);
1281 TDM_EXIT_IF_FAIL(tb != NULL);
1283 capture_attach(tb->c, b);
1287 capture_cb_done(tdm_capture *capture, tbm_surface_h b, void *user_data)
1289 tdm_test_server_buffer *tb;
1291 tb = get_tts_buffer(b);
1292 TDM_EXIT_IF_FAIL(tb != NULL);
1296 tb->done = capture_cb_buffer_done;
1297 layer_show_buffer(tb->l, b);
1301 capture_attach(tdm_test_server_capture *c, tbm_surface_h b)
1304 tdm_test_server_buffer *tb;
1306 tb = get_tts_buffer(b);
1307 TDM_EXIT_IF_FAIL(tb != NULL);
1313 ret = tdm_capture_attach(c->capture, b);
1314 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1316 printf("capture:\tc(%p) b(%p)\n", c, b);
1318 ret = tdm_capture_commit(c->capture);
1319 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1323 capture_setup(tdm_test_server_capture *c, tbm_surface_h b)
1325 tdm_test_server *data;
1328 tbm_surface_info_s info;
1331 if (!c || !c->l || !c->l->o || !c->l->o->data) {
1332 TDM_ERR("invalid parameter failed");
1335 data = c->l->o->data;
1337 if (c->output_idx != -1 && c->layer_idx == -1) {
1338 output = tdm_display_get_output(data->display, c->output_idx, &ret);
1339 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1340 c->capture = tdm_output_create_capture(output, &ret);
1341 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1342 } else if (c->output_idx != -1 && c->layer_idx != -1) {
1343 output = tdm_display_get_output(data->display, c->output_idx, &ret);
1344 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1345 layer = tdm_output_get_layer(output, c->layer_idx, &ret);
1346 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1347 c->capture = tdm_layer_create_capture(layer, &ret);
1348 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1351 TDM_EXIT_IF_FAIL(c->capture != NULL);
1353 /* The size and format information should be same with buffer's */
1354 tbm_surface_get_info(b, &info);
1355 if (IS_RGB(info.format)) {
1356 c->info.dst_config.size.h = info.planes[0].stride >> 2;
1357 c->info.dst_config.size.v = info.height;
1359 c->info.dst_config.size.h = info.planes[0].stride;
1360 c->info.dst_config.size.v = info.height;
1362 c->info.dst_config.format = info.format;
1364 ret = tdm_capture_set_info(c->capture, &c->info);
1365 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1367 ret = tdm_capture_set_done_handler(c->capture, capture_cb_done, NULL);
1368 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1370 printf("capture: o(%d) l(%d) ", c->output_idx, c->layer_idx);
1371 print_config(&c->info.dst_config);
1372 printf(" transform(%s)\n", tdm_transform_str(c->info.transform));
1373 printf("\toutput_idx(%d) layer_idx(%d)\n", c->l->o->idx, c->l->idx);
1375 layer_setup(c->l, b);
1379 run_test(tdm_test_server *data)
1381 tdm_test_server_output *o = NULL;
1382 tdm_test_server_layer *l = NULL;
1383 tdm_test_server_pp *p = NULL;
1384 tdm_test_server_capture *c = NULL;
1385 tdm_display_capability caps;
1388 ret = tdm_display_get_capabilities(data->display, &caps);
1389 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1391 LIST_FOR_EACH_ENTRY(o, &data->output_list, link) {
1392 LIST_FOR_EACH_ENTRY(l, &o->layer_list, link) {
1393 if (!l->owner_p && !l->owner_c) {
1395 b = layer_get_buffer(l);
1396 if (!l->is_primary || l->o->fill_primary_layer)
1397 tdm_test_buffer_fill(b, data->b_fill);
1399 layer_show_buffer(l, b);
1404 LIST_FOR_EACH_ENTRY(p, &data->pp_list, link) {
1405 tbm_surface_h sb, db;
1406 TDM_GOTO_IF_FAIL(caps & TDM_DISPLAY_CAPABILITY_PP, no_pp);
1407 sb = pp_get_buffer(p);
1408 TDM_EXIT_IF_FAIL(sb != NULL);
1409 db = layer_get_buffer(p->l);
1410 TDM_EXIT_IF_FAIL(db != NULL);
1411 pp_setup(p, sb, db);
1412 pp_convert_buffer(p, sb, db);
1415 LIST_FOR_EACH_ENTRY(c, &data->capture_list, link) {
1416 TDM_GOTO_IF_FAIL(caps & TDM_DISPLAY_CAPABILITY_CAPTURE, no_capture);
1418 b = layer_get_buffer(c->l);
1419 capture_setup(c, b);
1420 capture_attach(c, b);
1421 b = layer_get_buffer(c->l);
1422 capture_attach(c, b);
1423 b = layer_get_buffer(c->l);
1424 capture_attach(c, b);
1427 printf("enter test loop\n");
1430 tdm_display_handle_events(data->display);
1436 printf("no PP capability\n");
1439 printf("no Capture capability\n");