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 <boram1288.park@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_TST, "V", "virtual output test.\n\t\t'-l' is used to show the result on screen.",
115 OPT_GEN, "w", "set the property of a object",
116 "<prop_name>:<value>", NULL
119 OPT_GEN, "b", "set the fill(smtpe,tiles,plain) and framebuffer type(scanout,noncachable,wc)",
120 "<fill>[:<buf_flag>[,<buf_flag2>[,...]]]", NULL
123 OPT_GEN, "v", "update layers every vblank",
133 static struct usagestring usages[] = {
140 "test all outputs, layers with plain buffers"
144 "Set the \"1920x1080\" mode to the output 0. And show a buffer via a primary layer of the output 0"
147 "-o 0@1920x1080 -l 1~640x480+50+100",
148 "Create the 640x480 buffer and show it in the (50,100) pos of screen via the layer 1"
151 "-p 320x240@NV12~480x360+80+40,640x480@AR24 -l 1~640x480+50+100",
152 "Convert the 320x240@NV12 buffer to the 640x480@AR24 buffer(480x360+80+40) and show the result via the layer 1"
157 usage(char *app_name)
159 int type_size = sizeof(typestrs) / sizeof(struct typestrings);
160 int opt_size = sizeof(optstrs) / sizeof(struct optstrings);
161 int usages_size = sizeof(usages) / sizeof(struct usagestring);
164 printf("usage: %s \n\n", app_name);
166 for (t = 0; t < type_size; t++) {
169 for (o = 0; o < opt_size; o++)
170 if (optstrs[o].type == typestrs[t].type) {
172 printf(" %s options: %s\n\n", typestrs[t].string, (typestrs[t].desc) ? : "");
173 printf("\t-%s\t%s\n", optstrs[o].opt, optstrs[o].desc);
175 printf("\t\t %s\n", optstrs[o].arg);
177 printf("\t\t ex) %s\n", optstrs[o].ex);
183 printf(" For example)\n\n");
185 for (t = 0; t < usages_size; t++) {
186 printf(" $ %s %s\n", app_name, usages[t].string);
187 printf("\t%s\n", usages[t].desc);
192 ////////////////////////////////////////////////////////////////////////////////
194 static const char *tdm_buf_flag_names[] = {
199 TDM_BIT_NAME_FB(buf_flag)
201 #define DEFAULT_FORMAT TBM_FORMAT_ARGB8888
203 #define print_size(s) \
204 printf("%dx%d", (s)->h, (s)->v)
205 #define print_pos(p) \
206 printf("%dx%d+%d+%d", (p)->w, (p)->h, (p)->x, (p)->y)
207 #define print_format(f) \
208 if (f) printf("%c%c%c%c", FOURCC_STR(f)); \
210 #define print_config(c) \
212 print_size(&(c)->size); \
214 print_pos(&(c)->pos); \
216 print_format((c)->format); \
218 #define print_prop(w) \
219 printf("%s(%d)", (w)->name, ((w)->value).u32)
221 typedef struct _tdm_test_server tdm_test_server;
222 typedef struct _tdm_test_server_layer tdm_test_server_layer;
223 typedef struct _tdm_test_server_capture tdm_test_server_capture;
224 typedef struct _tdm_test_server_voutput tdm_test_server_voutput;
226 typedef struct _tdm_test_server_prop {
228 char name[TDM_NAME_LEN];
231 /* variables for test */
232 struct list_head link;
233 } tdm_test_server_prop;
235 typedef struct _tdm_test_server_buffer {
236 /* variables for test */
239 tdm_test_server_layer *l;
241 tdm_test_server_capture *c;
242 tdm_buffer_release_handler done;
243 } tdm_test_server_buffer;
245 typedef struct _tdm_test_server_output {
248 char mode[TDM_NAME_LEN];
251 /* variables for test */
252 struct list_head link;
253 struct list_head prop_list;
254 struct list_head layer_list;
255 tdm_test_server *data;
258 int fill_primary_layer;
259 } tdm_test_server_output;
261 typedef struct _tdm_test_server_pp {
266 /* variables for test */
267 struct list_head link;
268 tdm_test_server *data;
269 tdm_test_server_layer *l;
271 tbm_surface_h bufs[6];
274 tdm_event_loop_source *timer_source;
275 } tdm_test_server_pp;
277 struct _tdm_test_server_capture {
281 tdm_info_capture info;
283 /* variables for test */
284 struct list_head link;
285 tdm_test_server *data;
286 tdm_test_server_layer *l;
287 tdm_capture *capture;
290 struct _tdm_test_server_layer {
295 /* variables for test */
296 struct list_head link;
297 struct list_head prop_list;
298 tdm_test_server *data;
299 tdm_test_server_output *o;
302 tdm_test_server_pp *owner_p;
303 tdm_test_server_capture *owner_c;
304 tbm_surface_h bufs[3];
308 struct _tdm_test_server_voutput {
309 struct list_head link;
310 tdm_test_server *data;
313 tbm_surface_h bufs[3];
315 int need_mode_change;
319 struct _tdm_test_server {
328 /* variables for test */
329 struct list_head output_list;
330 struct list_head pp_list;
331 struct list_head capture_list;
332 struct list_head voutput_list;
333 tdm_display *display;
336 static void destroy(tdm_test_server *data);
337 static void run_test(tdm_test_server *data);
338 static void output_setup(tdm_test_server_output *o);
339 static void layer_show_buffer(tdm_test_server_layer *l, tbm_surface_h b);
340 static void capture_attach(tdm_test_server_capture *c, tbm_surface_h b);
341 static void _vlayer_show_buffer(tdm_test_server_voutput *voutput);
342 static void _voutput_layer_init(tdm_test_server_voutput *voutput);
345 parse_size(tdm_size *size, char *arg)
348 size->h = strtol(arg, &end, 10);
349 TDM_EXIT_IF_FAIL(*end == 'x');
351 size->v = strtol(arg, &end, 10);
356 parse_pos(tdm_pos *pos, char *arg)
359 pos->w = strtol(arg, &end, 10);
360 TDM_EXIT_IF_FAIL(*end == 'x');
362 pos->h = strtol(arg, &end, 10);
365 pos->x = strtol(arg, &end, 10);
366 TDM_EXIT_IF_FAIL(*end == '+');
368 pos->y = strtol(arg, &end, 10);
374 parse_config(tdm_info_config *config, char *arg)
377 end = parse_pos(&config->pos, arg);
380 end = parse_size(&config->size, arg);
385 end = strtostr(temp, 32, arg, TDM_DELIM);
386 config->format = FOURCC_ID(temp);
392 parse_arg_o(tdm_test_server_output *o, char *arg)
395 TDM_EXIT_IF_FAIL(arg != NULL);
396 o->idx = strtol(arg, &end, 10);
397 TDM_EXIT_IF_FAIL(*end == '@');
399 end = strtostr(o->mode, TDM_NAME_LEN, arg, TDM_DELIM);
402 o->refresh = strtol(arg, &end, 10);
407 parse_arg_p(tdm_test_server_pp *p, char *arg)
409 tdm_info_pp *pp_info = &p->info;
411 TDM_EXIT_IF_FAIL(arg != NULL);
412 end = parse_config(&pp_info->src_config, arg);
413 TDM_EXIT_IF_FAIL(*end == '~');
415 end = parse_config(&pp_info->dst_config, arg);
418 pp_info->transform = strtol(arg, &end, 10);
422 p->fps = strtol(arg, &end, 10);
427 parse_arg_c(tdm_test_server_capture *c, char *arg)
429 tdm_info_capture *capture_info = &c->info;
431 TDM_EXIT_IF_FAIL(arg != NULL);
432 c->output_idx = strtol(arg, &end, 10);
435 c->layer_idx = strtol(arg, &end, 10);
437 TDM_EXIT_IF_FAIL(*end == '~');
439 end = parse_config(&capture_info->dst_config, arg);
442 capture_info->transform = strtol(arg, &end, 10);
446 if (strtol(arg, &end, 10) > 0)
447 capture_info->type = TDM_CAPTURE_TYPE_STREAM;
449 capture_info->type = TDM_CAPTURE_TYPE_ONESHOT;
454 parse_arg_l(tdm_test_server_layer *l, char *arg)
456 tdm_info_layer *layer_info = &l->info;
458 TDM_EXIT_IF_FAIL(arg != NULL);
459 l->idx = strtol(arg, &end, 10);
462 end = parse_config(&layer_info->src_config, arg);
464 TDM_EXIT_IF_FAIL(*end == '~');
466 end = parse_pos(&layer_info->dst_pos, arg);
469 layer_info->transform = strtol(arg, &end, 10);
474 parse_arg_w(tdm_test_server_prop *w, char *arg)
477 TDM_EXIT_IF_FAIL(arg != NULL);
478 end = strtostr(w->name, TDM_PATH_LEN, arg, TDM_DELIM);
479 TDM_EXIT_IF_FAIL(*end == ':');
481 w->value.u32 = strtol(arg, &end, 10);
485 parse_arg_b(tdm_test_server *data, char *arg)
488 char temp[TDM_NAME_LEN] = {0,};
489 TDM_EXIT_IF_FAIL(arg != NULL);
491 end = strtostr(temp, 32, arg, TDM_DELIM);
492 if (!strncmp(temp, "smpte", 5))
493 data->b_fill = PATTERN_SMPTE;
494 else if (!strncmp(temp, "tiles", 5))
495 data->b_fill = PATTERN_TILES;
496 else if (!strncmp(temp, "plain", 5))
497 data->b_fill = PATTERN_PLAIN;
499 printf("'%s': unknown flag\n", temp);
506 snprintf(temp, TDM_NAME_LEN, "%s", arg);
507 arg = strtok_r(temp, ",", &end);
509 if (!strncmp(arg, "default", 7))
510 printf("Ignore '%s' flag\n", arg);
511 else if (!strncmp(arg, "scanout", 7))
512 data->bflags |= TBM_BO_SCANOUT;
513 else if (!strncmp(arg, "noncachable", 11))
514 data->bflags |= TBM_BO_NONCACHABLE;
515 else if (!strncmp(arg, "wc", 2))
516 data->bflags |= TBM_BO_WC;
518 printf("'%s': unknown flag\n", arg);
521 arg = strtok_r(NULL, ",", &end);
527 parse_args(tdm_test_server *data, int argc, char *argv[])
529 tdm_test_server_output *o = NULL;
530 tdm_test_server_layer *l = NULL;
531 tdm_test_server_pp *p = NULL;
532 tdm_test_server_capture *c = NULL;
533 tdm_test_server_prop *w = NULL;
534 void *last_option = NULL;
535 void *last_object = NULL;
544 for (i = 1; i < argc; i++) {
545 if (!strncmp(argv[i] + 1, "q", 1)) {
548 } else if (!strncmp(argv[i] + 1, "a", 1)) {
550 } else if (!strncmp(argv[i] + 1, "o", 1)) {
551 TDM_GOTO_IF_FAIL(data->do_all == 0, all);
552 o = calloc(1, sizeof * o);
553 TDM_EXIT_IF_FAIL(o != NULL);
555 LIST_INITHEAD(&o->layer_list);
556 LIST_INITHEAD(&o->prop_list);
557 LIST_ADDTAIL(&o->link, &data->output_list);
558 parse_arg_o(o, argv[++i]);
560 } else if (!strncmp(argv[i] + 1, "p", 1)) {
561 TDM_GOTO_IF_FAIL(data->do_all == 0, all);
562 p = calloc(1, sizeof * p);
563 TDM_EXIT_IF_FAIL(p != NULL);
565 p->fps = 30; /* default 30 fps */
566 LIST_ADDTAIL(&p->link, &data->pp_list);
567 parse_arg_p(p, argv[++i]);
569 } else if (!strncmp(argv[i] + 1, "c", 1)) {
570 TDM_GOTO_IF_FAIL(data->do_all == 0, all);
571 c = calloc(1, sizeof * c);
572 TDM_EXIT_IF_FAIL(c != NULL);
576 LIST_ADDTAIL(&c->link, &data->capture_list);
577 parse_arg_c(c, argv[++i]);
579 } else if (!strncmp(argv[i] + 1, "l", 1)) {
580 TDM_GOTO_IF_FAIL(data->do_all == 0, all);
582 o = calloc(1, sizeof * o);
583 TDM_EXIT_IF_FAIL(o != NULL);
585 LIST_INITHEAD(&o->layer_list);
586 LIST_INITHEAD(&o->prop_list);
587 LIST_ADDTAIL(&o->link, &data->output_list);
589 l = calloc(1, sizeof * l);
590 TDM_EXIT_IF_FAIL(l != NULL);
591 LIST_INITHEAD(&l->prop_list);
592 LIST_ADDTAIL(&l->link, &o->layer_list);
595 parse_arg_l(l, argv[++i]);
596 if (p && last_option == p) {
599 } else if (c && last_option == c) {
604 } else if (!strncmp(argv[i] + 1, "w", 1)) {
605 TDM_GOTO_IF_FAIL(data->do_all == 0, all);
608 w = calloc(1, sizeof * w);
609 TDM_EXIT_IF_FAIL(w != NULL);
610 if (o && last_object == o)
611 LIST_ADDTAIL(&w->link, &o->prop_list);
612 else if (l && last_object == l)
613 LIST_ADDTAIL(&w->link, &l->prop_list);
614 parse_arg_w(w, argv[++i]);
615 } else if (!strncmp(argv[i] + 1, "b", 1)) {
616 parse_arg_b(data, argv[++i]);
617 } else if (!strncmp(argv[i] + 1, "v", 1)) {
619 } else if (!strncmp(argv[i] + 1, "V", 1)) {
620 data->do_voutput = 1;
628 LIST_FOR_EACH_ENTRY(p, &data->pp_list, link) {
632 LIST_FOR_EACH_ENTRY(c, &data->capture_list, link) {
639 printf("Use '-l' to set a layer for '-p' or '-c'.\n");
642 printf("Use '-o' or '-l' to set a object first.\n");
645 printf("Can't use '-%s' with '-a'.\n", argv[i] + 1);
650 interpret_args(tdm_test_server *data)
652 tdm_test_server_output *o = NULL;
653 tdm_test_server_layer *l = NULL;
656 /* create the objects of outputs */
660 ret = tdm_display_get_output_count(data->display, &output_count);
661 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
663 for (i = 0; i < output_count; i++) {
664 tdm_output *output = tdm_display_get_output(data->display, i, NULL);
665 tdm_output_conn_status status;
666 ret = tdm_output_get_conn_status(output, &status);
667 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
669 if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
671 o = calloc(1, sizeof * o);
672 TDM_EXIT_IF_FAIL(o != NULL);
674 LIST_INITHEAD(&o->layer_list);
675 LIST_INITHEAD(&o->prop_list);
676 LIST_ADDTAIL(&o->link, &data->output_list);
678 o->fill_primary_layer = 1;
682 /* check if the primary layer object exists */
683 LIST_FOR_EACH_ENTRY(o, &data->output_list, link) {
685 const tdm_output_mode *mode;
686 int j, layer_count, primary_index = 0;
687 tdm_test_server_layer *primary_l = NULL;
691 output = tdm_display_get_output(data->display, o->idx, &ret);
692 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
693 ret = tdm_output_get_mode(output, &mode);
694 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
695 ret = tdm_output_get_layer_count(output, &layer_count);
696 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
697 ret = tdm_output_get_primary_index(output, &primary_index);
698 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
700 if (LIST_IS_EMPTY(&o->layer_list))
701 o->fill_primary_layer = 1;
703 LIST_FOR_EACH_ENTRY(l, &o->layer_list, link) {
704 if (l->idx == primary_index) {
706 o->fill_primary_layer = 1;
713 if (!primary_l || data->do_all) {
714 for (j = 0; j < layer_count; j++) {
715 if (j != primary_index && !data->do_all)
717 l = calloc(1, sizeof * l);
718 TDM_EXIT_IF_FAIL(l != NULL);
719 LIST_INITHEAD(&l->prop_list);
720 LIST_ADDTAIL(&l->link, &o->layer_list);
724 if (j == primary_index) {
726 l->info.dst_pos.w = mode->hdisplay;
727 l->info.dst_pos.h = mode->vdisplay;
730 l->info.dst_pos.w = TDM_ALIGN(mode->hdisplay / 3, 2);
731 l->info.dst_pos.h = TDM_ALIGN(mode->vdisplay / 3, 2);
732 l->info.dst_pos.x = TDM_ALIGN(((mode->hdisplay / 3) / layer_count) * j, 2);
733 l->info.dst_pos.y = TDM_ALIGN(((mode->vdisplay / 3) / layer_count) * j, 2);
738 TDM_EXIT_IF_FAIL(primary_l != NULL);
739 LIST_DEL(&primary_l->link);
740 LIST_ADD(&primary_l->link, &o->layer_list);
743 /* fill the empty information of layers */
744 LIST_FOR_EACH_ENTRY(o, &data->output_list, link) {
746 int minw, minh, maxw, maxh;
748 output = tdm_display_get_output(data->display, o->idx, &ret);
749 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
750 ret = tdm_output_get_available_size(output, &minw, &minh, &maxw, &maxh, NULL);
751 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
753 /* l->info.src_config.size will be decided when a buffer shows really */
754 LIST_FOR_EACH_ENTRY(l, &o->layer_list, link) {
755 if (minw > 0 && minh > 0) {
756 TDM_EXIT_IF_FAIL(l->info.dst_pos.w >= minw);
757 TDM_EXIT_IF_FAIL(l->info.dst_pos.h >= minh);
759 if (maxw > 0 && maxh > 0) {
760 TDM_EXIT_IF_FAIL(l->info.dst_pos.w <= maxw);
761 TDM_EXIT_IF_FAIL(l->info.dst_pos.h <= maxh);
765 l->info.src_config.format = l->owner_p->info.dst_config.format;
766 if (l->info.src_config.pos.w == 0) {
767 TDM_EXIT_IF_FAIL(l->owner_p->info.dst_config.size.h > 0);
768 l->info.src_config.pos.w = l->owner_p->info.dst_config.size.h;
769 l->info.src_config.pos.h = l->owner_p->info.dst_config.size.v;
771 } else if (l->owner_c) {
772 l->info.src_config.format = l->owner_c->info.dst_config.format;
773 if (l->info.src_config.pos.w == 0) {
774 TDM_EXIT_IF_FAIL(l->owner_c->info.dst_config.size.h > 0);
775 l->info.src_config.pos.w = l->owner_c->info.dst_config.size.h;
776 l->info.src_config.pos.h = l->owner_c->info.dst_config.size.v;
779 if (l->info.src_config.pos.w == 0) {
780 TDM_EXIT_IF_FAIL(l->info.dst_pos.w > 0);
781 l->info.src_config.pos.w = l->info.dst_pos.w;
782 l->info.src_config.pos.h = l->info.dst_pos.h;
789 static tdm_test_server tts_data;
790 static int tts_buffer_key;
791 #define TTS_BUFFER_KEY ((unsigned long)&tts_buffer_key)
794 buffer_allocate(int width, int height, int format, int flags)
796 tdm_test_server_buffer *tb = calloc(1, sizeof *tb);
797 TDM_EXIT_IF_FAIL(tb != NULL);
798 tb->b = tbm_surface_internal_create_with_flags(width, height, format, flags);
799 TDM_EXIT_IF_FAIL(tb->b != NULL);
800 tdm_helper_clear_buffer(tb->b);
801 tbm_surface_internal_add_user_data(tb->b, TTS_BUFFER_KEY, free);
802 tbm_surface_internal_set_user_data(tb->b, TTS_BUFFER_KEY, tb);
806 static tdm_test_server_buffer*
807 get_tts_buffer(tbm_surface_h b)
809 tdm_test_server_buffer *tb = NULL;
810 tbm_surface_internal_get_user_data(b, TTS_BUFFER_KEY, (void **)&tb);
815 _voutput_buff_deinit(tdm_test_server_voutput *voutput)
819 for (i = 0; i < 3; i++) {
820 if (!voutput->bufs[i]) continue;
822 tbm_surface_destroy(voutput->bufs[i]);
823 voutput->bufs[i] = NULL;
828 _voutput_buff_init(tdm_test_server_voutput *voutput)
830 tdm_output *output = voutput->output;
831 const tdm_output_mode *mode;
832 tdm_error ret = TDM_ERROR_NONE;
835 ret = tdm_output_get_mode(output, &mode);
836 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
838 for (i = 0; i < 3; i++) {
839 tbm_surface_h b = tbm_surface_internal_create_with_flags(mode->hdisplay, mode->vdisplay, DEFAULT_FORMAT, 0);
840 TDM_EXIT_IF_FAIL(b != NULL);
841 tdm_test_buffer_fill(b, i);
842 voutput->bufs[i] = b;
846 _vlayer_cb_commit(tdm_layer *layer, unsigned int sequence,
847 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
849 tdm_test_server_voutput *voutput = (tdm_test_server_voutput *)user_data;
850 TDM_EXIT_IF_FAIL(voutput != NULL);
851 tdm_output_conn_status status;
854 printf("voutput cb:\t %d: l(%p) b(%p)\n", voutput->buf_idx, voutput->layer, voutput->bufs[voutput->buf_idx]);
856 ret = tdm_output_get_conn_status(voutput->output, &status);
857 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
859 if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED) return;
861 if (voutput->need_mode_change) {
862 const tdm_output_mode *modes;
865 tdm_output_get_available_modes(voutput->output, &modes, &count);
866 if (count > voutput->index) {
867 const tdm_output_mode *mode, *current;
869 ret = tdm_output_get_mode(voutput->output, ¤t);
870 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
872 mode = &modes[voutput->index];
874 if (mode != current) {
875 printf("mode change to %d (%dx%d, %d)\n",
876 voutput->index, mode->hdisplay, mode->vdisplay, mode->vrefresh);
877 _voutput_buff_deinit(voutput);
878 _voutput_buff_init(voutput);
880 ret = tdm_output_set_mode(voutput->output, mode);
881 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
883 _voutput_layer_init(voutput);
884 voutput->buf_idx = 2;
887 voutput->need_mode_change = 0;
891 _vlayer_show_buffer(voutput);
895 _vlayer_show_buffer(tdm_test_server_voutput *voutput)
899 if (voutput->buf_idx == 3)
900 voutput->buf_idx = 0;
902 index = voutput->buf_idx;
904 ret = tdm_layer_set_buffer(voutput->layer, voutput->bufs[index]);
905 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
907 ret = tdm_layer_commit(voutput->layer, _vlayer_cb_commit, voutput);
908 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
910 printf("voutput show:\t %d: l(%p) b(%p)\n", index, voutput->layer, voutput->bufs[index]);
914 _voutput_layer_init(tdm_test_server_voutput *voutput)
916 tdm_output *output = voutput->output;
917 const tdm_output_mode *mode;
918 tdm_info_layer layer_info;
919 tbm_surface_info_s info;
920 tdm_error ret = TDM_ERROR_NONE;
922 ret = tdm_output_get_mode(output, &mode);
923 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
925 TDM_ERR("modeinfo : %dx%d %d", mode->hdisplay, mode->vdisplay, mode->vrefresh);
927 voutput->layer = tdm_output_get_layer(output, 0, &ret);
928 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
930 _voutput_buff_init(voutput);
932 tbm_surface_get_info(voutput->bufs[0], &info);
933 memset(&layer_info, 0x0, sizeof(tdm_info_layer));
934 if (IS_RGB(info.format)) {
935 layer_info.src_config.size.h = info.planes[0].stride >> 2;
936 layer_info.src_config.size.v = info.height;
938 layer_info.src_config.size.h = info.planes[0].stride;
939 layer_info.src_config.size.v = info.height;
941 layer_info.src_config.format = info.format;
943 layer_info.src_config.size.h = mode->hdisplay;
944 layer_info.src_config.size.v = mode->vdisplay;
945 layer_info.src_config.pos.x = 0;
946 layer_info.src_config.pos.y = 0;
947 layer_info.src_config.pos.w = mode->hdisplay;
948 layer_info.src_config.pos.h = mode->vdisplay;
949 layer_info.dst_pos.x = 0;
950 layer_info.dst_pos.y = 0;
951 layer_info.dst_pos.w = mode->hdisplay;
952 layer_info.dst_pos.h = mode->vdisplay;
953 layer_info.transform = TDM_TRANSFORM_NORMAL;
955 ret = tdm_layer_set_info(voutput->layer, &layer_info);
956 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
960 _voutput_connect(tdm_test_server_voutput *voutput)
963 const tdm_output_mode *modes, *found = NULL, *best = NULL, *prefer = NULL;
967 output = voutput->output;
969 ret = tdm_output_get_available_modes(output, &modes, &count);
970 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
972 for (i = 0; i < count; i++) {
975 if (modes[i].type & TDM_OUTPUT_MODE_TYPE_PREFERRED)
980 printf("found prefer mode: %dx%d %d\n", found->hdisplay, found->vdisplay, found->vrefresh);
982 if (!found && best) {
984 printf("found best mode: %dx%d %d\n", found->hdisplay, found->vdisplay, found->vrefresh);
987 printf("couldn't find any mode\n");
991 ret = tdm_output_set_mode(output, found);
992 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
994 printf("output: %s %d\n", found->name, found->vrefresh);
996 ret = tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON);
997 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1001 _voutput_disconnect(tdm_test_server_voutput *voutput)
1006 output = voutput->output;
1008 printf("output: %p disconnect\n", voutput);
1010 ret = tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF);
1011 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1015 _tdm_test_server_cb_output_change(tdm_output *output, tdm_output_change_type type, tdm_value value, void *user_data)
1017 tdm_test_server_voutput *voutput = NULL;
1018 tdm_output_conn_status status;
1020 voutput = (tdm_test_server_voutput *)user_data;
1021 TDM_EXIT_IF_FAIL(voutput != NULL);
1024 case TDM_OUTPUT_CHANGE_CONNECTION:
1025 status = (tdm_output_conn_status)value.u32;
1026 if (status == TDM_OUTPUT_CONN_STATUS_CONNECTED) {
1027 _voutput_connect(voutput);
1028 _voutput_layer_init(voutput);
1029 _vlayer_show_buffer(voutput);
1030 } else if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED) {
1031 _voutput_disconnect(voutput);
1040 _tdm_test_server_cb_output_mode_change(tdm_output *output, unsigned int index, void *user_data)
1042 tdm_test_server_voutput *voutput = NULL;
1043 const tdm_output_mode *modes;
1047 voutput = (tdm_test_server_voutput *)user_data;
1048 TDM_EXIT_IF_FAIL(voutput != NULL);
1050 ret = tdm_output_get_available_modes(output, &modes, &count);
1051 TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
1052 TDM_RETURN_IF_FAIL(index < count);
1054 voutput->need_mode_change = 1;
1055 voutput->index = index;
1057 printf("mode change request. index:%d\n", index);
1061 _tdm_output_cb_destroy_handler(tdm_output *output, void *user_data)
1063 tdm_test_server_voutput *voutput = NULL;
1065 voutput = (tdm_test_server_voutput *)user_data;
1066 TDM_EXIT_IF_FAIL(voutput != NULL);
1068 tdm_output_remove_mode_change_request_handler(output, _tdm_test_server_cb_output_mode_change, voutput);
1069 tdm_output_remove_change_handler(output, _tdm_test_server_cb_output_change, voutput);
1070 tdm_output_remove_destroy_handler(output, _tdm_output_cb_destroy_handler, voutput);
1072 LIST_DEL(&voutput->link);
1074 _voutput_buff_deinit(voutput);
1076 printf("voutput: %p destroy\n", voutput);
1082 _tdm_output_cb_create_handler(tdm_display *dpy, tdm_output *output, void *user_data)
1084 tdm_test_server *data;
1085 tdm_test_server_voutput *voutput = NULL;
1086 tdm_error ret = TDM_ERROR_NONE;
1088 printf("voutput create call\n");
1090 data = (tdm_test_server *)user_data;
1091 TDM_EXIT_IF_FAIL(data != NULL);
1093 voutput = calloc(1, sizeof *voutput);
1094 TDM_EXIT_IF_FAIL(voutput != NULL);
1096 ret = tdm_output_add_change_handler(output, _tdm_test_server_cb_output_change, voutput);
1097 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1099 ret = tdm_output_add_mode_change_request_handler(output, _tdm_test_server_cb_output_mode_change, voutput);
1100 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1102 ret = tdm_output_add_destroy_handler(output, _tdm_output_cb_destroy_handler, voutput);
1103 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1105 voutput->output = output;
1106 voutput->data = data;
1108 printf("voutput %p create done\n", voutput);
1110 LIST_ADDTAIL(&voutput->link, &data->voutput_list);
1114 destroy(tdm_test_server *data)
1116 tdm_test_server_output *o = NULL, *oo = NULL;
1117 tdm_test_server_layer *l = NULL, *ll = NULL;
1118 tdm_test_server_pp *p = NULL, *pp = NULL;
1119 tdm_test_server_capture *c = NULL, *cc = NULL;
1120 tdm_test_server_prop *w = NULL, *ww = NULL;
1121 tdm_test_server_voutput *v = NULL, *vv = NULL;
1125 LIST_FOR_EACH_ENTRY_SAFE(c, cc, &data->capture_list, link) {
1127 tdm_capture_destroy(c->capture);
1131 LIST_FOR_EACH_ENTRY_SAFE(p, pp, &data->pp_list, link) {
1132 tdm_display_lock(data->display);
1133 tdm_event_loop_source_remove(p->timer_source);
1134 tdm_display_unlock(data->display);
1136 tdm_pp_destroy(p->pp);
1139 LIST_FOR_EACH_ENTRY_SAFE(o, oo, &data->output_list, link) {
1140 LIST_FOR_EACH_ENTRY_SAFE(l, ll, &o->layer_list, link) {
1141 ret = tdm_layer_unset_buffer(l->layer);
1142 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
1144 ret = tdm_layer_commit(l->layer, NULL, NULL);
1145 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1148 LIST_FOR_EACH_ENTRY_SAFE(p, pp, &data->pp_list, link) {
1150 for (i = 0; i < TDM_ARRAY_SIZE(p->bufs); i++)
1151 tbm_surface_destroy(p->bufs[i]);
1155 LIST_FOR_EACH_ENTRY_SAFE(o, oo, &data->output_list, link) {
1157 LIST_FOR_EACH_ENTRY_SAFE(l, ll, &o->layer_list, link) {
1159 LIST_FOR_EACH_ENTRY_SAFE(w, ww, &l->prop_list, link) {
1163 for (i = 0; i < TDM_ARRAY_SIZE(l->bufs); i++)
1164 tbm_surface_destroy(l->bufs[i]);
1167 LIST_FOR_EACH_ENTRY_SAFE(w, ww, &o->prop_list, link) {
1175 LIST_FOR_EACH_ENTRY_SAFE(v, vv, &data->voutput_list, link) {
1176 _voutput_buff_deinit(v);
1181 if (data->do_voutput)
1182 tdm_display_remove_output_create_handler(data->display, _tdm_output_cb_create_handler, data);
1185 tdm_display_deinit(data->display);
1191 main(int argc, char *argv[])
1193 tdm_test_server *data = &tts_data;
1194 char temp[TDM_SERVER_REPLY_MSG_LEN];
1195 int len = sizeof temp;
1198 #if 1 /* for testing */
1199 const char *s = (const char*)getenv("XDG_RUNTIME_DIR");
1202 snprintf(buf, sizeof(buf), "/run");
1203 int ret = setenv("XDG_RUNTIME_DIR", (const char*)buf, 1);
1208 s = (const char*)getenv("TBM_DISPLAY_SERVER");
1211 snprintf(buf, sizeof(buf), "1");
1212 int ret = setenv("TBM_DISPLAY_SERVER", (const char*)buf, 1);
1218 memset(data, 0, sizeof * data);
1219 LIST_INITHEAD(&data->output_list);
1220 LIST_INITHEAD(&data->pp_list);
1221 LIST_INITHEAD(&data->capture_list);
1222 LIST_INITHEAD(&data->voutput_list);
1225 data->bflags = TBM_BO_SCANOUT;
1226 data->b_fill = PATTERN_SMPTE;
1228 data->display = tdm_display_init(&ret);
1229 TDM_EXIT_IF_FAIL(data->display != NULL);
1231 parse_args(data, argc, argv);
1232 interpret_args(data);
1234 if (data->do_query) {
1235 tdm_helper_get_display_information(data->display, temp, &len);
1240 if (data->do_voutput) {
1241 printf("support virtual output - server\n");
1242 ret = tdm_display_add_output_create_handler(data->display, _tdm_output_cb_create_handler, data);
1243 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1249 tdm_display_deinit(data->display);
1255 output_setup(tdm_test_server_output *o)
1257 tdm_test_server *data = o->data;
1258 const tdm_output_mode *modes, *found = NULL, *best = NULL, *prefer = NULL;
1259 tdm_test_server_prop *w = NULL;
1260 const tdm_prop *props;
1264 o->output = tdm_display_get_output(data->display, o->idx, &ret);
1265 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1267 ret = tdm_output_get_available_modes(o->output, &modes, &count);
1268 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1270 for (i = 0; i < count; i++) {
1271 if (!strncmp(o->mode, modes[i].name, TDM_NAME_LEN) && o->refresh == modes[i].vrefresh) {
1273 printf("found mode: %dx%d %d\n", found->hdisplay, found->vdisplay, found->vrefresh);
1278 if (modes[i].type & TDM_OUTPUT_MODE_TYPE_PREFERRED)
1281 if (!found && prefer) {
1283 printf("found prefer mode: %dx%d %d\n", found->hdisplay, found->vdisplay, found->vrefresh);
1285 if (!found && best) {
1287 printf("found best mode: %dx%d %d\n", found->hdisplay, found->vdisplay, found->vrefresh);
1291 printf("couldn't find any mode\n");
1295 ret = tdm_output_set_mode(o->output, found);
1296 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1298 printf("output %d: %s %d\n", o->idx, found->name, found->vrefresh);
1300 ret = tdm_output_get_available_properties(o->output, &props, &count);
1301 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1303 LIST_FOR_EACH_ENTRY(w, &o->prop_list, link) {
1304 for (i = 0; i < count; i++) {
1305 if (strncmp(w->name, props[i].name, TDM_NAME_LEN))
1307 ret = tdm_output_set_property(o->output, props[i].id, w->value);
1308 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1309 printf("\tprop '%s': %d\n", props[i].name, w->value.u32);
1314 /* DPMS on forcely at the first time. */
1315 ret = tdm_output_set_dpms(o->output, TDM_OUTPUT_DPMS_ON);
1316 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1319 static tbm_surface_h
1320 layer_get_buffer(tdm_test_server_layer *l)
1322 int i, size = TDM_ARRAY_SIZE(l->bufs);
1324 for (i = 0; i < size; i++) {
1325 int width = (l->info.src_config.size.h) ? : l->info.src_config.pos.w;
1326 int height = (l->info.src_config.size.v) ? : l->info.src_config.pos.h;
1327 unsigned int format = (l->info.src_config.format) ? : DEFAULT_FORMAT;
1328 int flags = l->o->data->bflags;
1329 tbm_surface_h b = buffer_allocate(width, height, format, flags);
1330 TDM_EXIT_IF_FAIL(b != NULL);
1334 for (i = 0; i < size; i++) {
1335 tdm_test_server_buffer *tb = get_tts_buffer(l->bufs[i]);
1336 TDM_EXIT_IF_FAIL(tb != NULL);
1340 printf("no available layer buffer.\n");
1345 layer_cb_commit(tdm_layer *layer, unsigned int sequence,
1346 unsigned int tv_sec, unsigned int tv_usec,
1349 tdm_test_server_layer *l = user_data;
1350 tbm_surface_h b = layer_get_buffer(l);
1351 TDM_EXIT_IF_FAIL(b != NULL);
1353 if (!l->is_primary || l->o->fill_primary_layer)
1354 tdm_test_buffer_fill(b, l->data->b_fill);
1356 if (!l->is_primary || l->o->fill_primary_layer)
1357 layer_show_buffer(l, b);
1361 layer_cb_buffer_release(tbm_surface_h b, void *user_data)
1363 tdm_test_server_buffer *tb = get_tts_buffer(b);
1364 TDM_EXIT_IF_FAIL(tb != NULL);
1367 tdm_buffer_remove_release_handler(b, layer_cb_buffer_release, NULL);
1369 tb->done(b, user_data);
1373 layer_show_buffer(tdm_test_server_layer *l, tbm_surface_h b)
1375 tdm_test_server *data = l->o->data;
1376 tdm_test_server_buffer *tb;
1379 ret = tdm_layer_set_buffer(l->layer, b);
1380 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1382 tb = get_tts_buffer(b);
1383 TDM_EXIT_IF_FAIL(tb != NULL);
1386 ret = tdm_buffer_add_release_handler(b, layer_cb_buffer_release, NULL);
1387 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1389 if (data->do_vblank)
1390 ret = tdm_layer_commit(l->layer, layer_cb_commit, l);
1392 ret = tdm_layer_commit(l->layer, NULL, NULL);
1393 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1395 printf("show:\tl(%p) b(%p)\n", l, b);
1399 layer_setup(tdm_test_server_layer *l, tbm_surface_h b)
1401 tdm_test_server_prop *w = NULL;
1402 const tdm_prop *props;
1405 tbm_surface_info_s info;
1407 l->layer = tdm_output_get_layer(l->o->output, l->idx, &ret);
1408 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1410 /* The size and format information should be same with buffer's */
1411 tbm_surface_get_info(b, &info);
1412 if (IS_RGB(info.format)) {
1413 l->info.src_config.size.h = info.planes[0].stride >> 2;
1414 l->info.src_config.size.v = info.height;
1416 l->info.src_config.size.h = info.planes[0].stride;
1417 l->info.src_config.size.v = info.height;
1419 l->info.src_config.format = info.format;
1421 ret = tdm_layer_set_info(l->layer, &l->info);
1422 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1424 printf("layer %d: output(%d) ", l->idx, l->o->idx);
1425 print_config(&l->info.src_config);
1427 print_pos(&l->info.dst_pos);
1428 printf(" transform(%s)\n", tdm_transform_str(l->info.transform));
1430 ret = tdm_layer_get_available_properties(l->layer, &props, &count);
1431 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1433 LIST_FOR_EACH_ENTRY(w, &l->prop_list, link) {
1434 for (i = 0; i < count; i++) {
1435 if (strncmp(w->name, props[i].name, TDM_NAME_LEN))
1437 ret = tdm_layer_set_property(l->layer, props[i].id, w->value);
1438 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1439 printf("\tprop '%s': %d\n", props[i].name, w->value.u32);
1445 static tbm_surface_h
1446 pp_get_buffer(tdm_test_server_pp *p)
1448 int i, size = TDM_ARRAY_SIZE(p->bufs);
1450 for (i = 0; i < size; i++) {
1451 int width = (p->info.src_config.size.h) ? : p->info.src_config.pos.w;
1452 int height = (p->info.src_config.size.v) ? : p->info.src_config.pos.h;
1453 unsigned int format = (p->info.src_config.format) ? : DEFAULT_FORMAT;
1454 tbm_surface_h b = buffer_allocate(width, height, format, 0);
1455 TDM_EXIT_IF_FAIL(b != NULL);
1459 for (i = 0; i < size; i++) {
1460 tdm_test_server_buffer *tb = get_tts_buffer(p->bufs[i]);
1466 tdm_test_buffer_fill(p->bufs[i], p->data->b_fill);
1470 printf("no available pp buffer.\n");
1475 pp_cb_done(tdm_pp *pp, tbm_surface_h sb, tbm_surface_h db, void *user_data)
1477 tdm_test_server_buffer *stb, *dtb;
1479 stb = get_tts_buffer(sb);
1480 TDM_EXIT_IF_FAIL(stb != NULL);
1482 dtb = get_tts_buffer(db);
1483 TDM_EXIT_IF_FAIL(dtb != NULL);
1485 stb->in_use = dtb->in_use = 0;
1487 layer_show_buffer(dtb->l, db);
1491 pp_convert_buffer(tdm_test_server_pp *p, tbm_surface_h sb, tbm_surface_h db)
1493 tdm_test_server_buffer *stb, *dtb;
1496 stb = get_tts_buffer(sb);
1497 TDM_EXIT_IF_FAIL(stb != NULL);
1499 dtb = get_tts_buffer(db);
1500 TDM_EXIT_IF_FAIL(dtb != NULL);
1502 stb->in_use = dtb->in_use = 1;
1505 ret = tdm_pp_attach(p->pp, sb, db);
1506 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1508 ret = tdm_pp_commit(p->pp);
1509 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1511 printf("convt:\tp(%p) sb(%p) db(%p)\n", p, sb, db);
1514 /* tdm_event_loop_xxx() function is not for the display server. It's for TDM
1515 * backend module. I use them only for simulating the video play. When we call
1516 * tdm_event_loop_xxx() outside of TDM backend module, we have to lock/unlock
1517 * the TDM display. And when the callback function of tdm_event_loop_xxx() is
1518 * called, the display has been already locked. So in this test application,
1519 * we have to unlock/lock the display for testing.
1522 pp_cb_timeout(void *user_data)
1524 tdm_test_server_pp *p = user_data;
1525 tdm_test_server *data = p->l->o->data;
1526 tbm_surface_h sb, db;
1529 tdm_display_unlock(data->display);
1531 sb = pp_get_buffer(p);
1532 TDM_EXIT_IF_FAIL(sb != NULL);
1533 db = layer_get_buffer(p->l);
1534 TDM_EXIT_IF_FAIL(db != NULL);
1536 pp_convert_buffer(p, sb, db);
1538 tdm_display_lock(data->display);
1539 ret = tdm_event_loop_source_timer_update(p->timer_source, 1000 / p->fps);
1540 tdm_display_unlock(data->display);
1541 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1543 tdm_display_lock(data->display);
1545 return TDM_ERROR_NONE;
1549 pp_setup(tdm_test_server_pp *p, tbm_surface_h sb, tbm_surface_h db)
1551 tdm_test_server *data;
1552 tbm_surface_info_s info;
1555 if (!p || !p->l || !p->l->o || !p->l->o->data) {
1556 TDM_ERR("invalid parameter failed");
1559 data = p->l->o->data;
1561 p->pp = tdm_display_create_pp(data->display, &ret);
1562 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1564 /* The size and format information should be same with buffer's */
1565 tbm_surface_get_info(sb, &info);
1566 if (IS_RGB(info.format)) {
1567 p->info.src_config.size.h = info.planes[0].stride >> 2;
1568 p->info.src_config.size.v = info.height;
1570 p->info.src_config.size.h = info.planes[0].stride;
1571 p->info.src_config.size.v = info.height;
1573 p->info.src_config.format = info.format;
1575 /* The size and format information should be same with buffer's */
1576 tbm_surface_get_info(db, &info);
1577 if (IS_RGB(info.format)) {
1578 p->info.dst_config.size.h = info.planes[0].stride >> 2;
1579 p->info.dst_config.size.v = info.height;
1581 p->info.dst_config.size.h = info.planes[0].stride;
1582 p->info.dst_config.size.v = info.height;
1584 p->info.dst_config.format = info.format;
1586 ret = tdm_pp_set_info(p->pp, &p->info);
1587 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1589 ret = tdm_pp_set_done_handler(p->pp, pp_cb_done, NULL);
1590 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1593 print_config(&p->info.src_config);
1595 print_config(&p->info.dst_config);
1596 printf(" fps(%d) transform(%s)\n", p->fps, tdm_transform_str(p->info.transform));
1597 printf("\toutput_idx(%d) layer_idx(%d)\n", p->l->o->idx, p->l->idx);
1599 layer_setup(p->l, db);
1601 /* tdm_event_loop_xxx() function is not for the display server. It's for TDM
1602 * backend module. I use them only for simulating the video play. When we call
1603 * tdm_event_loop_xxx() outside of TDM backend module, we have to lock/unlock
1604 * the TDM display. And when the callback function of tdm_event_loop_xxx() is
1605 * called, the display has been already locked. So in this test application,
1606 * we have to unlock/lock the display for testing.
1608 tdm_display_lock(data->display);
1609 p->timer_source = tdm_event_loop_add_timer_handler(data->display, pp_cb_timeout, p, &ret);
1610 tdm_display_unlock(data->display);
1611 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1613 tdm_display_lock(data->display);
1614 ret = tdm_event_loop_source_timer_update(p->timer_source, 1000 / p->fps);
1615 tdm_display_unlock(data->display);
1616 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1620 capture_cb_buffer_done(tbm_surface_h b, void *user_data)
1622 tdm_test_server_buffer *tb;
1624 tb = get_tts_buffer(b);
1625 TDM_EXIT_IF_FAIL(tb != NULL);
1627 capture_attach(tb->c, b);
1631 capture_cb_done(tdm_capture *capture, tbm_surface_h b, void *user_data)
1633 tdm_test_server_buffer *tb;
1635 tb = get_tts_buffer(b);
1636 TDM_EXIT_IF_FAIL(tb != NULL);
1640 tb->done = capture_cb_buffer_done;
1641 layer_show_buffer(tb->l, b);
1645 capture_attach(tdm_test_server_capture *c, tbm_surface_h b)
1648 tdm_test_server_buffer *tb;
1650 tb = get_tts_buffer(b);
1651 TDM_EXIT_IF_FAIL(tb != NULL);
1657 ret = tdm_capture_attach(c->capture, b);
1658 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1660 printf("capture:\tc(%p) b(%p)\n", c, b);
1662 ret = tdm_capture_commit(c->capture);
1663 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1667 capture_setup(tdm_test_server_capture *c, tbm_surface_h b)
1669 tdm_test_server *data;
1672 tbm_surface_info_s info;
1675 if (!c || !c->l || !c->l->o || !c->l->o->data) {
1676 TDM_ERR("invalid parameter failed");
1679 data = c->l->o->data;
1681 if (c->output_idx != -1 && c->layer_idx == -1) {
1682 output = tdm_display_get_output(data->display, c->output_idx, &ret);
1683 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1684 c->capture = tdm_output_create_capture(output, &ret);
1685 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1686 } else if (c->output_idx != -1 && c->layer_idx != -1) {
1687 output = tdm_display_get_output(data->display, c->output_idx, &ret);
1688 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1689 layer = tdm_output_get_layer(output, c->layer_idx, &ret);
1690 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1691 c->capture = tdm_layer_create_capture(layer, &ret);
1692 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1695 TDM_EXIT_IF_FAIL(c->capture != NULL);
1697 /* The size and format information should be same with buffer's */
1698 tbm_surface_get_info(b, &info);
1699 if (IS_RGB(info.format)) {
1700 c->info.dst_config.size.h = info.planes[0].stride >> 2;
1701 c->info.dst_config.size.v = info.height;
1703 c->info.dst_config.size.h = info.planes[0].stride;
1704 c->info.dst_config.size.v = info.height;
1706 c->info.dst_config.format = info.format;
1707 c->info.type = TDM_CAPTURE_TYPE_ONESHOT;
1709 ret = tdm_capture_set_info(c->capture, &c->info);
1710 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1712 ret = tdm_capture_set_done_handler(c->capture, capture_cb_done, NULL);
1713 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1715 printf("capture: o(%d) l(%d) ", c->output_idx, c->layer_idx);
1716 print_config(&c->info.dst_config);
1717 printf(" transform(%s)\n", tdm_transform_str(c->info.transform));
1718 printf("\toutput_idx(%d) layer_idx(%d)\n", c->l->o->idx, c->l->idx);
1720 layer_setup(c->l, b);
1724 run_test(tdm_test_server *data)
1726 tdm_test_server_output *o = NULL;
1727 tdm_test_server_layer *l = NULL;
1728 tdm_test_server_pp *p = NULL;
1729 tdm_test_server_capture *c = NULL;
1730 tdm_display_capability caps;
1733 ret = tdm_display_get_capabilities(data->display, &caps);
1734 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1736 LIST_FOR_EACH_ENTRY(o, &data->output_list, link) {
1737 LIST_FOR_EACH_ENTRY(l, &o->layer_list, link) {
1738 if (!l->owner_p && !l->owner_c) {
1740 b = layer_get_buffer(l);
1741 if (!l->is_primary || l->o->fill_primary_layer)
1742 tdm_test_buffer_fill(b, data->b_fill);
1744 layer_show_buffer(l, b);
1749 LIST_FOR_EACH_ENTRY(p, &data->pp_list, link) {
1750 tbm_surface_h sb, db;
1751 TDM_GOTO_IF_FAIL(caps & TDM_DISPLAY_CAPABILITY_PP, no_pp);
1752 sb = pp_get_buffer(p);
1753 TDM_EXIT_IF_FAIL(sb != NULL);
1754 db = layer_get_buffer(p->l);
1755 TDM_EXIT_IF_FAIL(db != NULL);
1756 pp_setup(p, sb, db);
1757 pp_convert_buffer(p, sb, db);
1760 LIST_FOR_EACH_ENTRY(c, &data->capture_list, link) {
1761 TDM_GOTO_IF_FAIL(caps & TDM_DISPLAY_CAPABILITY_CAPTURE, no_capture);
1763 b = layer_get_buffer(c->l);
1764 capture_setup(c, b);
1765 capture_attach(c, b);
1766 b = layer_get_buffer(c->l);
1767 capture_attach(c, b);
1768 b = layer_get_buffer(c->l);
1769 capture_attach(c, b);
1772 printf("enter test loop\n");
1775 ret = tdm_display_handle_events(data->display);
1776 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1783 printf("no PP capability\n");
1786 printf("no Capture capability\n");