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];
317 struct _tdm_test_server {
326 /* variables for test */
327 struct list_head output_list;
328 struct list_head pp_list;
329 struct list_head capture_list;
330 struct list_head voutput_list;
331 tdm_display *display;
334 static void destroy(tdm_test_server *data);
335 static void run_test(tdm_test_server *data);
336 static void output_setup(tdm_test_server_output *o);
337 static void layer_show_buffer(tdm_test_server_layer *l, tbm_surface_h b);
338 static void capture_attach(tdm_test_server_capture *c, tbm_surface_h b);
339 static void _vlayer_show_buffer(tdm_test_server_voutput *voutput);
342 parse_size(tdm_size *size, char *arg)
345 size->h = strtol(arg, &end, 10);
346 TDM_EXIT_IF_FAIL(*end == 'x');
348 size->v = strtol(arg, &end, 10);
353 parse_pos(tdm_pos *pos, char *arg)
356 pos->w = strtol(arg, &end, 10);
357 TDM_EXIT_IF_FAIL(*end == 'x');
359 pos->h = strtol(arg, &end, 10);
362 pos->x = strtol(arg, &end, 10);
363 TDM_EXIT_IF_FAIL(*end == '+');
365 pos->y = strtol(arg, &end, 10);
371 parse_config(tdm_info_config *config, char *arg)
374 end = parse_pos(&config->pos, arg);
377 end = parse_size(&config->size, arg);
382 end = strtostr(temp, 32, arg, TDM_DELIM);
383 config->format = FOURCC_ID(temp);
389 parse_arg_o(tdm_test_server_output *o, char *arg)
392 TDM_EXIT_IF_FAIL(arg != NULL);
393 o->idx = strtol(arg, &end, 10);
394 TDM_EXIT_IF_FAIL(*end == '@');
396 end = strtostr(o->mode, TDM_NAME_LEN, arg, TDM_DELIM);
399 o->refresh = strtol(arg, &end, 10);
404 parse_arg_p(tdm_test_server_pp *p, char *arg)
406 tdm_info_pp *pp_info = &p->info;
408 TDM_EXIT_IF_FAIL(arg != NULL);
409 end = parse_config(&pp_info->src_config, arg);
410 TDM_EXIT_IF_FAIL(*end == '~');
412 end = parse_config(&pp_info->dst_config, arg);
415 pp_info->transform = strtol(arg, &end, 10);
419 p->fps = strtol(arg, &end, 10);
424 parse_arg_c(tdm_test_server_capture *c, char *arg)
426 tdm_info_capture *capture_info = &c->info;
428 TDM_EXIT_IF_FAIL(arg != NULL);
429 c->output_idx = strtol(arg, &end, 10);
432 c->layer_idx = strtol(arg, &end, 10);
434 TDM_EXIT_IF_FAIL(*end == '~');
436 end = parse_config(&capture_info->dst_config, arg);
439 capture_info->transform = strtol(arg, &end, 10);
443 if (strtol(arg, &end, 10) > 0)
444 capture_info->type = TDM_CAPTURE_TYPE_STREAM;
446 capture_info->type = TDM_CAPTURE_TYPE_ONESHOT;
451 parse_arg_l(tdm_test_server_layer *l, char *arg)
453 tdm_info_layer *layer_info = &l->info;
455 TDM_EXIT_IF_FAIL(arg != NULL);
456 l->idx = strtol(arg, &end, 10);
459 end = parse_config(&layer_info->src_config, arg);
461 TDM_EXIT_IF_FAIL(*end == '~');
463 end = parse_pos(&layer_info->dst_pos, arg);
466 layer_info->transform = strtol(arg, &end, 10);
471 parse_arg_w(tdm_test_server_prop *w, char *arg)
474 TDM_EXIT_IF_FAIL(arg != NULL);
475 end = strtostr(w->name, TDM_PATH_LEN, arg, TDM_DELIM);
476 TDM_EXIT_IF_FAIL(*end == ':');
478 w->value.u32 = strtol(arg, &end, 10);
482 parse_arg_b(tdm_test_server *data, char *arg)
485 char temp[TDM_NAME_LEN] = {0,};
486 TDM_EXIT_IF_FAIL(arg != NULL);
488 end = strtostr(temp, 32, arg, TDM_DELIM);
489 if (!strncmp(temp, "smpte", 5))
490 data->b_fill = PATTERN_SMPTE;
491 else if (!strncmp(temp, "tiles", 5))
492 data->b_fill = PATTERN_TILES;
493 else if (!strncmp(temp, "plain", 5))
494 data->b_fill = PATTERN_PLAIN;
496 printf("'%s': unknown flag\n", temp);
503 snprintf(temp, TDM_NAME_LEN, "%s", arg);
504 arg = strtok_r(temp, ",", &end);
506 if (!strncmp(arg, "default", 7))
507 printf("Ignore '%s' flag\n", arg);
508 else if (!strncmp(arg, "scanout", 7))
509 data->bflags |= TBM_BO_SCANOUT;
510 else if (!strncmp(arg, "noncachable", 11))
511 data->bflags |= TBM_BO_NONCACHABLE;
512 else if (!strncmp(arg, "wc", 2))
513 data->bflags |= TBM_BO_WC;
515 printf("'%s': unknown flag\n", arg);
518 arg = strtok_r(NULL, ",", &end);
524 parse_args(tdm_test_server *data, int argc, char *argv[])
526 tdm_test_server_output *o = NULL;
527 tdm_test_server_layer *l = NULL;
528 tdm_test_server_pp *p = NULL;
529 tdm_test_server_capture *c = NULL;
530 tdm_test_server_prop *w = NULL;
531 void *last_option = NULL;
532 void *last_object = NULL;
541 for (i = 1; i < argc; i++) {
542 if (!strncmp(argv[i] + 1, "q", 1)) {
545 } else if (!strncmp(argv[i] + 1, "a", 1)) {
547 } else if (!strncmp(argv[i] + 1, "o", 1)) {
548 TDM_GOTO_IF_FAIL(data->do_all == 0, all);
549 o = calloc(1, sizeof * o);
550 TDM_EXIT_IF_FAIL(o != NULL);
552 LIST_INITHEAD(&o->layer_list);
553 LIST_INITHEAD(&o->prop_list);
554 LIST_ADDTAIL(&o->link, &data->output_list);
555 parse_arg_o(o, argv[++i]);
557 } else if (!strncmp(argv[i] + 1, "p", 1)) {
558 TDM_GOTO_IF_FAIL(data->do_all == 0, all);
559 p = calloc(1, sizeof * p);
560 TDM_EXIT_IF_FAIL(p != NULL);
562 p->fps = 30; /* default 30 fps */
563 LIST_ADDTAIL(&p->link, &data->pp_list);
564 parse_arg_p(p, argv[++i]);
566 } else if (!strncmp(argv[i] + 1, "c", 1)) {
567 TDM_GOTO_IF_FAIL(data->do_all == 0, all);
568 c = calloc(1, sizeof * c);
569 TDM_EXIT_IF_FAIL(c != NULL);
573 LIST_ADDTAIL(&c->link, &data->capture_list);
574 parse_arg_c(c, argv[++i]);
576 } else if (!strncmp(argv[i] + 1, "l", 1)) {
577 TDM_GOTO_IF_FAIL(data->do_all == 0, all);
579 o = calloc(1, sizeof * o);
580 TDM_EXIT_IF_FAIL(o != NULL);
582 LIST_INITHEAD(&o->layer_list);
583 LIST_INITHEAD(&o->prop_list);
584 LIST_ADDTAIL(&o->link, &data->output_list);
586 l = calloc(1, sizeof * l);
587 TDM_EXIT_IF_FAIL(l != NULL);
588 LIST_INITHEAD(&l->prop_list);
589 LIST_ADDTAIL(&l->link, &o->layer_list);
592 parse_arg_l(l, argv[++i]);
593 if (p && last_option == p) {
596 } else if (c && last_option == c) {
601 } else if (!strncmp(argv[i] + 1, "w", 1)) {
602 TDM_GOTO_IF_FAIL(data->do_all == 0, all);
605 w = calloc(1, sizeof * w);
606 TDM_EXIT_IF_FAIL(w != NULL);
607 if (o && last_object == o)
608 LIST_ADDTAIL(&w->link, &o->prop_list);
609 else if (l && last_object == l)
610 LIST_ADDTAIL(&w->link, &l->prop_list);
611 parse_arg_w(w, argv[++i]);
612 } else if (!strncmp(argv[i] + 1, "b", 1)) {
613 parse_arg_b(data, argv[++i]);
614 } else if (!strncmp(argv[i] + 1, "v", 1)) {
616 } else if (!strncmp(argv[i] + 1, "V", 1)) {
617 data->do_voutput = 1;
625 LIST_FOR_EACH_ENTRY(p, &data->pp_list, link) {
629 LIST_FOR_EACH_ENTRY(c, &data->capture_list, link) {
636 printf("Use '-l' to set a layer for '-p' or '-c'.\n");
639 printf("Use '-o' or '-l' to set a object first.\n");
642 printf("Can't use '-%s' with '-a'.\n", argv[i] + 1);
647 interpret_args(tdm_test_server *data)
649 tdm_test_server_output *o = NULL;
650 tdm_test_server_layer *l = NULL;
653 /* create the objects of outputs */
657 ret = tdm_display_get_output_count(data->display, &output_count);
658 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
660 for (i = 0; i < output_count; i++) {
661 tdm_output *output = tdm_display_get_output(data->display, i, NULL);
662 tdm_output_conn_status status;
663 ret = tdm_output_get_conn_status(output, &status);
664 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
666 if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
668 o = calloc(1, sizeof * o);
669 TDM_EXIT_IF_FAIL(o != NULL);
671 LIST_INITHEAD(&o->layer_list);
672 LIST_INITHEAD(&o->prop_list);
673 LIST_ADDTAIL(&o->link, &data->output_list);
675 o->fill_primary_layer = 1;
679 /* check if the primary layer object exists */
680 LIST_FOR_EACH_ENTRY(o, &data->output_list, link) {
682 const tdm_output_mode *mode;
683 int j, layer_count, primary_index = 0;
684 tdm_test_server_layer *primary_l = NULL;
688 output = tdm_display_get_output(data->display, o->idx, &ret);
689 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
690 ret = tdm_output_get_mode(output, &mode);
691 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
692 ret = tdm_output_get_layer_count(output, &layer_count);
693 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
694 ret = tdm_output_get_primary_index(output, &primary_index);
695 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
697 if (LIST_IS_EMPTY(&o->layer_list))
698 o->fill_primary_layer = 1;
700 LIST_FOR_EACH_ENTRY(l, &o->layer_list, link) {
701 if (l->idx == primary_index) {
703 o->fill_primary_layer = 1;
710 if (!primary_l || data->do_all) {
711 for (j = 0; j < layer_count; j++) {
712 if (j != primary_index && !data->do_all)
714 l = calloc(1, sizeof * l);
715 TDM_EXIT_IF_FAIL(l != NULL);
716 LIST_INITHEAD(&l->prop_list);
717 LIST_ADDTAIL(&l->link, &o->layer_list);
721 if (j == primary_index) {
723 l->info.dst_pos.w = mode->hdisplay;
724 l->info.dst_pos.h = mode->vdisplay;
727 l->info.dst_pos.w = TDM_ALIGN(mode->hdisplay / 3, 2);
728 l->info.dst_pos.h = TDM_ALIGN(mode->vdisplay / 3, 2);
729 l->info.dst_pos.x = TDM_ALIGN(((mode->hdisplay / 3) / layer_count) * j, 2);
730 l->info.dst_pos.y = TDM_ALIGN(((mode->vdisplay / 3) / layer_count) * j, 2);
735 TDM_EXIT_IF_FAIL(primary_l != NULL);
736 LIST_DEL(&primary_l->link);
737 LIST_ADD(&primary_l->link, &o->layer_list);
740 /* fill the empty information of layers */
741 LIST_FOR_EACH_ENTRY(o, &data->output_list, link) {
743 int minw, minh, maxw, maxh;
745 output = tdm_display_get_output(data->display, o->idx, &ret);
746 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
747 ret = tdm_output_get_available_size(output, &minw, &minh, &maxw, &maxh, NULL);
748 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
750 /* l->info.src_config.size will be decided when a buffer shows really */
751 LIST_FOR_EACH_ENTRY(l, &o->layer_list, link) {
752 if (minw > 0 && minh > 0) {
753 TDM_EXIT_IF_FAIL(l->info.dst_pos.w >= minw);
754 TDM_EXIT_IF_FAIL(l->info.dst_pos.h >= minh);
756 if (maxw > 0 && maxh > 0) {
757 TDM_EXIT_IF_FAIL(l->info.dst_pos.w <= maxw);
758 TDM_EXIT_IF_FAIL(l->info.dst_pos.h <= maxh);
762 l->info.src_config.format = l->owner_p->info.dst_config.format;
763 if (l->info.src_config.pos.w == 0) {
764 TDM_EXIT_IF_FAIL(l->owner_p->info.dst_config.size.h > 0);
765 l->info.src_config.pos.w = l->owner_p->info.dst_config.size.h;
766 l->info.src_config.pos.h = l->owner_p->info.dst_config.size.v;
768 } else if (l->owner_c) {
769 l->info.src_config.format = l->owner_c->info.dst_config.format;
770 if (l->info.src_config.pos.w == 0) {
771 TDM_EXIT_IF_FAIL(l->owner_c->info.dst_config.size.h > 0);
772 l->info.src_config.pos.w = l->owner_c->info.dst_config.size.h;
773 l->info.src_config.pos.h = l->owner_c->info.dst_config.size.v;
776 if (l->info.src_config.pos.w == 0) {
777 TDM_EXIT_IF_FAIL(l->info.dst_pos.w > 0);
778 l->info.src_config.pos.w = l->info.dst_pos.w;
779 l->info.src_config.pos.h = l->info.dst_pos.h;
786 static tdm_test_server tts_data;
787 static int tts_buffer_key;
788 #define TTS_BUFFER_KEY ((unsigned long)&tts_buffer_key)
791 buffer_allocate(int width, int height, int format, int flags)
793 tdm_test_server_buffer *tb = calloc(1, sizeof *tb);
794 TDM_EXIT_IF_FAIL(tb != NULL);
795 tb->b = tbm_surface_internal_create_with_flags(width, height, format, flags);
796 TDM_EXIT_IF_FAIL(tb->b != NULL);
797 tdm_helper_clear_buffer(tb->b);
798 tbm_surface_internal_add_user_data(tb->b, TTS_BUFFER_KEY, free);
799 tbm_surface_internal_set_user_data(tb->b, TTS_BUFFER_KEY, tb);
803 static tdm_test_server_buffer*
804 get_tts_buffer(tbm_surface_h b)
806 tdm_test_server_buffer *tb = NULL;
807 tbm_surface_internal_get_user_data(b, TTS_BUFFER_KEY, (void **)&tb);
812 _vlayer_cb_commit(tdm_layer *layer, unsigned int sequence,
813 unsigned int tv_sec, unsigned int tv_usec, void *user_data)
815 tdm_test_server_voutput *voutput = (tdm_test_server_voutput *)user_data;
816 TDM_EXIT_IF_FAIL(voutput != NULL);
817 tdm_output_conn_status status;
820 printf("voutput cb commit:\t %d: l(%p) b(%p)\n", voutput->buf_idx, voutput->layer, voutput->bufs[voutput->buf_idx]);
822 ret = tdm_output_get_conn_status(voutput->output, &status);
823 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
825 if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED) return;
828 _vlayer_show_buffer(voutput);
832 _vlayer_show_buffer(tdm_test_server_voutput *voutput)
836 if (voutput->buf_idx == 3)
837 voutput->buf_idx = 0;
839 index = voutput->buf_idx;
841 ret = tdm_layer_set_buffer(voutput->layer, voutput->bufs[index]);
842 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
844 ret = tdm_layer_commit(voutput->layer, _vlayer_cb_commit, voutput);
845 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
847 printf("voutput show:\t %d: l(%p) b(%p)\n", index, voutput->layer, voutput->bufs[index]);
851 _voutput_buff_init(tdm_test_server_voutput *voutput)
853 tdm_output *output = voutput->output;
854 const tdm_output_mode *mode;
855 tdm_error ret = TDM_ERROR_NONE;
858 ret = tdm_output_get_mode(output, &mode);
859 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
861 for (i = 0; i < 3; i++) {
862 tbm_surface_h b = tbm_surface_internal_create_with_flags(mode->hdisplay, mode->vdisplay, DEFAULT_FORMAT, 0);
863 TDM_EXIT_IF_FAIL(b != NULL);
864 tdm_test_buffer_fill(b, i);
865 voutput->bufs[i] = b;
870 _voutput_layer_init(tdm_test_server_voutput *voutput)
872 tdm_output *output = voutput->output;
873 const tdm_output_mode *mode;
874 tdm_info_layer layer_info;
875 tbm_surface_info_s info;
876 tdm_error ret = TDM_ERROR_NONE;
878 ret = tdm_output_get_mode(output, &mode);
879 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
881 TDM_ERR("modeinfo : %dx%d %d", mode->hdisplay, mode->vdisplay, mode->vrefresh);
883 voutput->layer = tdm_output_get_layer(output, 0, &ret);
884 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
886 _voutput_buff_init(voutput);
888 tbm_surface_get_info(voutput->bufs[0], &info);
889 memset(&layer_info, 0x0, sizeof(tdm_info_layer));
890 if (IS_RGB(info.format)) {
891 layer_info.src_config.size.h = info.planes[0].stride >> 2;
892 layer_info.src_config.size.v = info.height;
894 layer_info.src_config.size.h = info.planes[0].stride;
895 layer_info.src_config.size.v = info.height;
897 layer_info.src_config.format = info.format;
899 layer_info.src_config.size.h = mode->hdisplay;
900 layer_info.src_config.size.v = mode->vdisplay;
901 layer_info.src_config.pos.x = 0;
902 layer_info.src_config.pos.y = 0;
903 layer_info.src_config.pos.w = mode->hdisplay;
904 layer_info.src_config.pos.h = mode->vdisplay;
905 layer_info.dst_pos.x = 0;
906 layer_info.dst_pos.y = 0;
907 layer_info.dst_pos.w = mode->hdisplay;
908 layer_info.dst_pos.h = mode->vdisplay;
909 layer_info.transform = TDM_TRANSFORM_NORMAL;
911 ret = tdm_layer_set_info(voutput->layer, &layer_info);
912 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
916 _voutput_connect(tdm_test_server_voutput *voutput)
919 const tdm_output_mode *modes, *found = NULL, *best = NULL, *prefer = NULL;
923 output = voutput->output;
925 ret = tdm_output_get_available_modes(output, &modes, &count);
926 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
928 for (i = 0; i < count; i++) {
931 if (modes[i].type & TDM_OUTPUT_MODE_TYPE_PREFERRED)
936 printf("found prefer mode: %dx%d %d\n", found->hdisplay, found->vdisplay, found->vrefresh);
938 if (!found && best) {
940 printf("found best mode: %dx%d %d\n", found->hdisplay, found->vdisplay, found->vrefresh);
943 printf("couldn't find any mode\n");
947 ret = tdm_output_set_mode(output, found);
948 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
950 printf("output: %s %d\n", found->name, found->vrefresh);
952 ret = tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON);
953 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
957 _voutput_disconnect(tdm_test_server_voutput *voutput)
962 output = voutput->output;
964 ret = tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF);
965 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
969 _tdm_test_server_cb_output_change(tdm_output *output, tdm_output_change_type type, tdm_value value, void *user_data)
971 tdm_test_server_voutput *voutput = NULL;
972 tdm_output_conn_status status;
974 voutput = (tdm_test_server_voutput *)user_data;
975 TDM_EXIT_IF_FAIL(voutput != NULL);
978 case TDM_OUTPUT_CHANGE_CONNECTION:
979 status = (tdm_output_conn_status)value.u32;
980 if (status == TDM_OUTPUT_CONN_STATUS_CONNECTED) {
981 _voutput_connect(voutput);
982 _voutput_layer_init(voutput);
983 _vlayer_show_buffer(voutput);
984 } else if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED) {
985 _voutput_disconnect(voutput);
994 _tdm_output_cb_destroy_handler(tdm_output *output, void *user_data)
996 tdm_test_server_voutput *voutput = NULL;
999 voutput = (tdm_test_server_voutput *)user_data;
1000 TDM_EXIT_IF_FAIL(voutput != NULL);
1002 tdm_output_remove_change_handler(output, _tdm_test_server_cb_output_change, voutput);
1003 tdm_output_remove_destroy_handler(output, _tdm_output_cb_destroy_handler, voutput);
1005 LIST_DEL(&voutput->link);
1007 for (i = 0; i < 3; i++) {
1008 tbm_surface_destroy(voutput->bufs[i]);
1015 _tdm_output_cb_create_handler(tdm_display *dpy, tdm_output *output, void *user_data)
1017 tdm_test_server *data;
1018 tdm_test_server_voutput *voutput = NULL;
1019 tdm_error ret = TDM_ERROR_NONE;
1021 printf("voutput create call\n");
1023 data = (tdm_test_server *)user_data;
1024 TDM_EXIT_IF_FAIL(data != NULL);
1026 voutput = calloc(1, sizeof *voutput);
1027 TDM_EXIT_IF_FAIL(voutput != NULL);
1029 ret = tdm_output_add_change_handler(output, _tdm_test_server_cb_output_change, voutput);
1030 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1032 ret = tdm_output_add_destroy_handler(output, _tdm_output_cb_destroy_handler, voutput);
1033 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1035 voutput->output = output;
1036 voutput->data = data;
1038 printf("voutput create done\n");
1040 LIST_ADDTAIL(&voutput->link, &data->voutput_list);
1044 destroy(tdm_test_server *data)
1046 tdm_test_server_output *o = NULL, *oo = NULL;
1047 tdm_test_server_layer *l = NULL, *ll = NULL;
1048 tdm_test_server_pp *p = NULL, *pp = NULL;
1049 tdm_test_server_capture *c = NULL, *cc = NULL;
1050 tdm_test_server_prop *w = NULL, *ww = NULL;
1051 tdm_test_server_voutput *v = NULL, *vv = NULL;
1055 LIST_FOR_EACH_ENTRY_SAFE(c, cc, &data->capture_list, link) {
1057 tdm_capture_destroy(c->capture);
1061 LIST_FOR_EACH_ENTRY_SAFE(p, pp, &data->pp_list, link) {
1062 tdm_display_lock(data->display);
1063 tdm_event_loop_source_remove(p->timer_source);
1064 tdm_display_unlock(data->display);
1066 tdm_pp_destroy(p->pp);
1069 LIST_FOR_EACH_ENTRY_SAFE(o, oo, &data->output_list, link) {
1070 LIST_FOR_EACH_ENTRY_SAFE(l, ll, &o->layer_list, link) {
1071 ret = tdm_layer_unset_buffer(l->layer);
1072 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
1074 ret = tdm_layer_commit(l->layer, NULL, NULL);
1075 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1078 LIST_FOR_EACH_ENTRY_SAFE(p, pp, &data->pp_list, link) {
1080 for (i = 0; i < TDM_ARRAY_SIZE(p->bufs); i++)
1081 tbm_surface_destroy(p->bufs[i]);
1085 LIST_FOR_EACH_ENTRY_SAFE(o, oo, &data->output_list, link) {
1087 LIST_FOR_EACH_ENTRY_SAFE(l, ll, &o->layer_list, link) {
1089 LIST_FOR_EACH_ENTRY_SAFE(w, ww, &l->prop_list, link) {
1093 for (i = 0; i < TDM_ARRAY_SIZE(l->bufs); i++)
1094 tbm_surface_destroy(l->bufs[i]);
1097 LIST_FOR_EACH_ENTRY_SAFE(w, ww, &o->prop_list, link) {
1105 LIST_FOR_EACH_ENTRY_SAFE(v, vv, &data->voutput_list, link) {
1106 for (int i = 0; i < 3; i++) {
1107 tbm_surface_destroy(v->bufs[i]);
1113 if (data->do_voutput)
1114 tdm_display_remove_output_create_handler(data->display, _tdm_output_cb_create_handler, data);
1117 tdm_display_deinit(data->display);
1123 main(int argc, char *argv[])
1125 tdm_test_server *data = &tts_data;
1126 char temp[TDM_SERVER_REPLY_MSG_LEN];
1127 int len = sizeof temp;
1130 #if 1 /* for testing */
1131 const char *s = (const char*)getenv("XDG_RUNTIME_DIR");
1134 snprintf(buf, sizeof(buf), "/run");
1135 int ret = setenv("XDG_RUNTIME_DIR", (const char*)buf, 1);
1140 s = (const char*)getenv("TBM_DISPLAY_SERVER");
1143 snprintf(buf, sizeof(buf), "1");
1144 int ret = setenv("TBM_DISPLAY_SERVER", (const char*)buf, 1);
1150 memset(data, 0, sizeof * data);
1151 LIST_INITHEAD(&data->output_list);
1152 LIST_INITHEAD(&data->pp_list);
1153 LIST_INITHEAD(&data->capture_list);
1154 LIST_INITHEAD(&data->voutput_list);
1157 data->bflags = TBM_BO_SCANOUT;
1158 data->b_fill = PATTERN_SMPTE;
1160 data->display = tdm_display_init(&ret);
1161 TDM_EXIT_IF_FAIL(data->display != NULL);
1163 parse_args(data, argc, argv);
1164 interpret_args(data);
1166 if (data->do_query) {
1167 tdm_helper_get_display_information(data->display, temp, &len);
1172 if (data->do_voutput) {
1173 printf("support virtual output - server\n");
1174 ret = tdm_display_add_output_create_handler(data->display, _tdm_output_cb_create_handler, data);
1175 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1181 tdm_display_deinit(data->display);
1187 output_setup(tdm_test_server_output *o)
1189 tdm_test_server *data = o->data;
1190 const tdm_output_mode *modes, *found = NULL, *best = NULL, *prefer = NULL;
1191 tdm_test_server_prop *w = NULL;
1192 const tdm_prop *props;
1196 o->output = tdm_display_get_output(data->display, o->idx, &ret);
1197 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1199 ret = tdm_output_get_available_modes(o->output, &modes, &count);
1200 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1202 for (i = 0; i < count; i++) {
1203 if (!strncmp(o->mode, modes[i].name, TDM_NAME_LEN) && o->refresh == modes[i].vrefresh) {
1205 printf("found mode: %dx%d %d\n", found->hdisplay, found->vdisplay, found->vrefresh);
1210 if (modes[i].type & TDM_OUTPUT_MODE_TYPE_PREFERRED)
1213 if (!found && prefer) {
1215 printf("found prefer mode: %dx%d %d\n", found->hdisplay, found->vdisplay, found->vrefresh);
1217 if (!found && best) {
1219 printf("found best mode: %dx%d %d\n", found->hdisplay, found->vdisplay, found->vrefresh);
1223 printf("couldn't find any mode\n");
1227 ret = tdm_output_set_mode(o->output, found);
1228 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1230 printf("output %d: %s %d\n", o->idx, found->name, found->vrefresh);
1232 ret = tdm_output_get_available_properties(o->output, &props, &count);
1233 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1235 LIST_FOR_EACH_ENTRY(w, &o->prop_list, link) {
1236 for (i = 0; i < count; i++) {
1237 if (strncmp(w->name, props[i].name, TDM_NAME_LEN))
1239 ret = tdm_output_set_property(o->output, props[i].id, w->value);
1240 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1241 printf("\tprop '%s': %d\n", props[i].name, w->value.u32);
1246 /* DPMS on forcely at the first time. */
1247 ret = tdm_output_set_dpms(o->output, TDM_OUTPUT_DPMS_ON);
1248 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1251 static tbm_surface_h
1252 layer_get_buffer(tdm_test_server_layer *l)
1254 int i, size = TDM_ARRAY_SIZE(l->bufs);
1256 for (i = 0; i < size; i++) {
1257 int width = (l->info.src_config.size.h) ? : l->info.src_config.pos.w;
1258 int height = (l->info.src_config.size.v) ? : l->info.src_config.pos.h;
1259 unsigned int format = (l->info.src_config.format) ? : DEFAULT_FORMAT;
1260 int flags = l->o->data->bflags;
1261 tbm_surface_h b = buffer_allocate(width, height, format, flags);
1262 TDM_EXIT_IF_FAIL(b != NULL);
1266 for (i = 0; i < size; i++) {
1267 tdm_test_server_buffer *tb = get_tts_buffer(l->bufs[i]);
1268 TDM_EXIT_IF_FAIL(tb != NULL);
1272 printf("no available layer buffer.\n");
1277 layer_cb_commit(tdm_layer *layer, unsigned int sequence,
1278 unsigned int tv_sec, unsigned int tv_usec,
1281 tdm_test_server_layer *l = user_data;
1282 tbm_surface_h b = layer_get_buffer(l);
1283 TDM_EXIT_IF_FAIL(b != NULL);
1285 if (!l->is_primary || l->o->fill_primary_layer)
1286 tdm_test_buffer_fill(b, l->data->b_fill);
1288 if (!l->is_primary || l->o->fill_primary_layer)
1289 layer_show_buffer(l, b);
1293 layer_cb_buffer_release(tbm_surface_h b, void *user_data)
1295 tdm_test_server_buffer *tb = get_tts_buffer(b);
1296 TDM_EXIT_IF_FAIL(tb != NULL);
1299 tdm_buffer_remove_release_handler(b, layer_cb_buffer_release, NULL);
1301 tb->done(b, user_data);
1305 layer_show_buffer(tdm_test_server_layer *l, tbm_surface_h b)
1307 tdm_test_server *data = l->o->data;
1308 tdm_test_server_buffer *tb;
1311 ret = tdm_layer_set_buffer(l->layer, b);
1312 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1314 tb = get_tts_buffer(b);
1315 TDM_EXIT_IF_FAIL(tb != NULL);
1318 ret = tdm_buffer_add_release_handler(b, layer_cb_buffer_release, NULL);
1319 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1321 if (data->do_vblank)
1322 ret = tdm_layer_commit(l->layer, layer_cb_commit, l);
1324 ret = tdm_layer_commit(l->layer, NULL, NULL);
1325 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1327 printf("show:\tl(%p) b(%p)\n", l, b);
1331 layer_setup(tdm_test_server_layer *l, tbm_surface_h b)
1333 tdm_test_server_prop *w = NULL;
1334 const tdm_prop *props;
1337 tbm_surface_info_s info;
1339 l->layer = tdm_output_get_layer(l->o->output, l->idx, &ret);
1340 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1342 /* The size and format information should be same with buffer's */
1343 tbm_surface_get_info(b, &info);
1344 if (IS_RGB(info.format)) {
1345 l->info.src_config.size.h = info.planes[0].stride >> 2;
1346 l->info.src_config.size.v = info.height;
1348 l->info.src_config.size.h = info.planes[0].stride;
1349 l->info.src_config.size.v = info.height;
1351 l->info.src_config.format = info.format;
1353 ret = tdm_layer_set_info(l->layer, &l->info);
1354 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1356 printf("layer %d: output(%d) ", l->idx, l->o->idx);
1357 print_config(&l->info.src_config);
1359 print_pos(&l->info.dst_pos);
1360 printf(" transform(%s)\n", tdm_transform_str(l->info.transform));
1362 ret = tdm_layer_get_available_properties(l->layer, &props, &count);
1363 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1365 LIST_FOR_EACH_ENTRY(w, &l->prop_list, link) {
1366 for (i = 0; i < count; i++) {
1367 if (strncmp(w->name, props[i].name, TDM_NAME_LEN))
1369 ret = tdm_layer_set_property(l->layer, props[i].id, w->value);
1370 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1371 printf("\tprop '%s': %d\n", props[i].name, w->value.u32);
1377 static tbm_surface_h
1378 pp_get_buffer(tdm_test_server_pp *p)
1380 int i, size = TDM_ARRAY_SIZE(p->bufs);
1382 for (i = 0; i < size; i++) {
1383 int width = (p->info.src_config.size.h) ? : p->info.src_config.pos.w;
1384 int height = (p->info.src_config.size.v) ? : p->info.src_config.pos.h;
1385 unsigned int format = (p->info.src_config.format) ? : DEFAULT_FORMAT;
1386 tbm_surface_h b = buffer_allocate(width, height, format, 0);
1387 TDM_EXIT_IF_FAIL(b != NULL);
1391 for (i = 0; i < size; i++) {
1392 tdm_test_server_buffer *tb = get_tts_buffer(p->bufs[i]);
1398 tdm_test_buffer_fill(p->bufs[i], p->data->b_fill);
1402 printf("no available pp buffer.\n");
1407 pp_cb_done(tdm_pp *pp, tbm_surface_h sb, tbm_surface_h db, void *user_data)
1409 tdm_test_server_buffer *stb, *dtb;
1411 stb = get_tts_buffer(sb);
1412 TDM_EXIT_IF_FAIL(stb != NULL);
1414 dtb = get_tts_buffer(db);
1415 TDM_EXIT_IF_FAIL(dtb != NULL);
1417 stb->in_use = dtb->in_use = 0;
1419 layer_show_buffer(dtb->l, db);
1423 pp_convert_buffer(tdm_test_server_pp *p, tbm_surface_h sb, tbm_surface_h db)
1425 tdm_test_server_buffer *stb, *dtb;
1428 stb = get_tts_buffer(sb);
1429 TDM_EXIT_IF_FAIL(stb != NULL);
1431 dtb = get_tts_buffer(db);
1432 TDM_EXIT_IF_FAIL(dtb != NULL);
1434 stb->in_use = dtb->in_use = 1;
1437 ret = tdm_pp_attach(p->pp, sb, db);
1438 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1440 ret = tdm_pp_commit(p->pp);
1441 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1443 printf("convt:\tp(%p) sb(%p) db(%p)\n", p, sb, db);
1446 /* tdm_event_loop_xxx() function is not for the display server. It's for TDM
1447 * backend module. I use them only for simulating the video play. When we call
1448 * tdm_event_loop_xxx() outside of TDM backend module, we have to lock/unlock
1449 * the TDM display. And when the callback function of tdm_event_loop_xxx() is
1450 * called, the display has been already locked. So in this test application,
1451 * we have to unlock/lock the display for testing.
1454 pp_cb_timeout(void *user_data)
1456 tdm_test_server_pp *p = user_data;
1457 tdm_test_server *data = p->l->o->data;
1458 tbm_surface_h sb, db;
1461 tdm_display_unlock(data->display);
1463 sb = pp_get_buffer(p);
1464 TDM_EXIT_IF_FAIL(sb != NULL);
1465 db = layer_get_buffer(p->l);
1466 TDM_EXIT_IF_FAIL(db != NULL);
1468 pp_convert_buffer(p, sb, db);
1470 tdm_display_lock(data->display);
1471 ret = tdm_event_loop_source_timer_update(p->timer_source, 1000 / p->fps);
1472 tdm_display_unlock(data->display);
1473 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1475 tdm_display_lock(data->display);
1477 return TDM_ERROR_NONE;
1481 pp_setup(tdm_test_server_pp *p, tbm_surface_h sb, tbm_surface_h db)
1483 tdm_test_server *data;
1484 tbm_surface_info_s info;
1487 if (!p || !p->l || !p->l->o || !p->l->o->data) {
1488 TDM_ERR("invalid parameter failed");
1491 data = p->l->o->data;
1493 p->pp = tdm_display_create_pp(data->display, &ret);
1494 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1496 /* The size and format information should be same with buffer's */
1497 tbm_surface_get_info(sb, &info);
1498 if (IS_RGB(info.format)) {
1499 p->info.src_config.size.h = info.planes[0].stride >> 2;
1500 p->info.src_config.size.v = info.height;
1502 p->info.src_config.size.h = info.planes[0].stride;
1503 p->info.src_config.size.v = info.height;
1505 p->info.src_config.format = info.format;
1507 /* The size and format information should be same with buffer's */
1508 tbm_surface_get_info(db, &info);
1509 if (IS_RGB(info.format)) {
1510 p->info.dst_config.size.h = info.planes[0].stride >> 2;
1511 p->info.dst_config.size.v = info.height;
1513 p->info.dst_config.size.h = info.planes[0].stride;
1514 p->info.dst_config.size.v = info.height;
1516 p->info.dst_config.format = info.format;
1518 ret = tdm_pp_set_info(p->pp, &p->info);
1519 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1521 ret = tdm_pp_set_done_handler(p->pp, pp_cb_done, NULL);
1522 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1525 print_config(&p->info.src_config);
1527 print_config(&p->info.dst_config);
1528 printf(" fps(%d) transform(%s)\n", p->fps, tdm_transform_str(p->info.transform));
1529 printf("\toutput_idx(%d) layer_idx(%d)\n", p->l->o->idx, p->l->idx);
1531 layer_setup(p->l, db);
1533 /* tdm_event_loop_xxx() function is not for the display server. It's for TDM
1534 * backend module. I use them only for simulating the video play. When we call
1535 * tdm_event_loop_xxx() outside of TDM backend module, we have to lock/unlock
1536 * the TDM display. And when the callback function of tdm_event_loop_xxx() is
1537 * called, the display has been already locked. So in this test application,
1538 * we have to unlock/lock the display for testing.
1540 tdm_display_lock(data->display);
1541 p->timer_source = tdm_event_loop_add_timer_handler(data->display, pp_cb_timeout, p, &ret);
1542 tdm_display_unlock(data->display);
1543 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1545 tdm_display_lock(data->display);
1546 ret = tdm_event_loop_source_timer_update(p->timer_source, 1000 / p->fps);
1547 tdm_display_unlock(data->display);
1548 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1552 capture_cb_buffer_done(tbm_surface_h b, void *user_data)
1554 tdm_test_server_buffer *tb;
1556 tb = get_tts_buffer(b);
1557 TDM_EXIT_IF_FAIL(tb != NULL);
1559 capture_attach(tb->c, b);
1563 capture_cb_done(tdm_capture *capture, tbm_surface_h b, void *user_data)
1565 tdm_test_server_buffer *tb;
1567 tb = get_tts_buffer(b);
1568 TDM_EXIT_IF_FAIL(tb != NULL);
1572 tb->done = capture_cb_buffer_done;
1573 layer_show_buffer(tb->l, b);
1577 capture_attach(tdm_test_server_capture *c, tbm_surface_h b)
1580 tdm_test_server_buffer *tb;
1582 tb = get_tts_buffer(b);
1583 TDM_EXIT_IF_FAIL(tb != NULL);
1589 ret = tdm_capture_attach(c->capture, b);
1590 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1592 printf("capture:\tc(%p) b(%p)\n", c, b);
1594 ret = tdm_capture_commit(c->capture);
1595 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1599 capture_setup(tdm_test_server_capture *c, tbm_surface_h b)
1601 tdm_test_server *data;
1604 tbm_surface_info_s info;
1607 if (!c || !c->l || !c->l->o || !c->l->o->data) {
1608 TDM_ERR("invalid parameter failed");
1611 data = c->l->o->data;
1613 if (c->output_idx != -1 && c->layer_idx == -1) {
1614 output = tdm_display_get_output(data->display, c->output_idx, &ret);
1615 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1616 c->capture = tdm_output_create_capture(output, &ret);
1617 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1618 } else if (c->output_idx != -1 && c->layer_idx != -1) {
1619 output = tdm_display_get_output(data->display, c->output_idx, &ret);
1620 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1621 layer = tdm_output_get_layer(output, c->layer_idx, &ret);
1622 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1623 c->capture = tdm_layer_create_capture(layer, &ret);
1624 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1627 TDM_EXIT_IF_FAIL(c->capture != NULL);
1629 /* The size and format information should be same with buffer's */
1630 tbm_surface_get_info(b, &info);
1631 if (IS_RGB(info.format)) {
1632 c->info.dst_config.size.h = info.planes[0].stride >> 2;
1633 c->info.dst_config.size.v = info.height;
1635 c->info.dst_config.size.h = info.planes[0].stride;
1636 c->info.dst_config.size.v = info.height;
1638 c->info.dst_config.format = info.format;
1639 c->info.type = TDM_CAPTURE_TYPE_ONESHOT;
1641 ret = tdm_capture_set_info(c->capture, &c->info);
1642 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1644 ret = tdm_capture_set_done_handler(c->capture, capture_cb_done, NULL);
1645 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1647 printf("capture: o(%d) l(%d) ", c->output_idx, c->layer_idx);
1648 print_config(&c->info.dst_config);
1649 printf(" transform(%s)\n", tdm_transform_str(c->info.transform));
1650 printf("\toutput_idx(%d) layer_idx(%d)\n", c->l->o->idx, c->l->idx);
1652 layer_setup(c->l, b);
1656 run_test(tdm_test_server *data)
1658 tdm_test_server_output *o = NULL;
1659 tdm_test_server_layer *l = NULL;
1660 tdm_test_server_pp *p = NULL;
1661 tdm_test_server_capture *c = NULL;
1662 tdm_display_capability caps;
1665 ret = tdm_display_get_capabilities(data->display, &caps);
1666 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1668 LIST_FOR_EACH_ENTRY(o, &data->output_list, link) {
1669 LIST_FOR_EACH_ENTRY(l, &o->layer_list, link) {
1670 if (!l->owner_p && !l->owner_c) {
1672 b = layer_get_buffer(l);
1673 if (!l->is_primary || l->o->fill_primary_layer)
1674 tdm_test_buffer_fill(b, data->b_fill);
1676 layer_show_buffer(l, b);
1681 LIST_FOR_EACH_ENTRY(p, &data->pp_list, link) {
1682 tbm_surface_h sb, db;
1683 TDM_GOTO_IF_FAIL(caps & TDM_DISPLAY_CAPABILITY_PP, no_pp);
1684 sb = pp_get_buffer(p);
1685 TDM_EXIT_IF_FAIL(sb != NULL);
1686 db = layer_get_buffer(p->l);
1687 TDM_EXIT_IF_FAIL(db != NULL);
1688 pp_setup(p, sb, db);
1689 pp_convert_buffer(p, sb, db);
1692 LIST_FOR_EACH_ENTRY(c, &data->capture_list, link) {
1693 TDM_GOTO_IF_FAIL(caps & TDM_DISPLAY_CAPABILITY_CAPTURE, no_capture);
1695 b = layer_get_buffer(c->l);
1696 capture_setup(c, b);
1697 capture_attach(c, b);
1698 b = layer_get_buffer(c->l);
1699 capture_attach(c, b);
1700 b = layer_get_buffer(c->l);
1701 capture_attach(c, b);
1704 printf("enter test loop\n");
1707 ret = tdm_display_handle_events(data->display);
1708 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1715 printf("no PP capability\n");
1718 printf("no Capture capability\n");