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 printf("output: %p disconnect\n", voutput);
966 ret = tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF);
967 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
971 _tdm_test_server_cb_output_change(tdm_output *output, tdm_output_change_type type, tdm_value value, void *user_data)
973 tdm_test_server_voutput *voutput = NULL;
974 tdm_output_conn_status status;
976 voutput = (tdm_test_server_voutput *)user_data;
977 TDM_EXIT_IF_FAIL(voutput != NULL);
980 case TDM_OUTPUT_CHANGE_CONNECTION:
981 status = (tdm_output_conn_status)value.u32;
982 if (status == TDM_OUTPUT_CONN_STATUS_CONNECTED) {
983 _voutput_connect(voutput);
984 _voutput_layer_init(voutput);
985 _vlayer_show_buffer(voutput);
986 } else if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED) {
987 _voutput_disconnect(voutput);
996 _tdm_output_cb_destroy_handler(tdm_output *output, void *user_data)
998 tdm_test_server_voutput *voutput = NULL;
1001 voutput = (tdm_test_server_voutput *)user_data;
1002 TDM_EXIT_IF_FAIL(voutput != NULL);
1004 tdm_output_remove_change_handler(output, _tdm_test_server_cb_output_change, voutput);
1005 tdm_output_remove_destroy_handler(output, _tdm_output_cb_destroy_handler, voutput);
1007 LIST_DEL(&voutput->link);
1009 for (i = 0; i < 3; i++) {
1010 tbm_surface_destroy(voutput->bufs[i]);
1013 printf("voutput: %p destroy\n", voutput);
1019 _tdm_output_cb_create_handler(tdm_display *dpy, tdm_output *output, void *user_data)
1021 tdm_test_server *data;
1022 tdm_test_server_voutput *voutput = NULL;
1023 tdm_error ret = TDM_ERROR_NONE;
1025 printf("voutput create call\n");
1027 data = (tdm_test_server *)user_data;
1028 TDM_EXIT_IF_FAIL(data != NULL);
1030 voutput = calloc(1, sizeof *voutput);
1031 TDM_EXIT_IF_FAIL(voutput != NULL);
1033 ret = tdm_output_add_change_handler(output, _tdm_test_server_cb_output_change, voutput);
1034 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1036 ret = tdm_output_add_destroy_handler(output, _tdm_output_cb_destroy_handler, voutput);
1037 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1039 voutput->output = output;
1040 voutput->data = data;
1042 printf("voutput %p create done\n", voutput);
1044 LIST_ADDTAIL(&voutput->link, &data->voutput_list);
1048 destroy(tdm_test_server *data)
1050 tdm_test_server_output *o = NULL, *oo = NULL;
1051 tdm_test_server_layer *l = NULL, *ll = NULL;
1052 tdm_test_server_pp *p = NULL, *pp = NULL;
1053 tdm_test_server_capture *c = NULL, *cc = NULL;
1054 tdm_test_server_prop *w = NULL, *ww = NULL;
1055 tdm_test_server_voutput *v = NULL, *vv = NULL;
1059 LIST_FOR_EACH_ENTRY_SAFE(c, cc, &data->capture_list, link) {
1061 tdm_capture_destroy(c->capture);
1065 LIST_FOR_EACH_ENTRY_SAFE(p, pp, &data->pp_list, link) {
1066 tdm_display_lock(data->display);
1067 tdm_event_loop_source_remove(p->timer_source);
1068 tdm_display_unlock(data->display);
1070 tdm_pp_destroy(p->pp);
1073 LIST_FOR_EACH_ENTRY_SAFE(o, oo, &data->output_list, link) {
1074 LIST_FOR_EACH_ENTRY_SAFE(l, ll, &o->layer_list, link) {
1075 ret = tdm_layer_unset_buffer(l->layer);
1076 TDM_WARNING_IF_FAIL(ret == TDM_ERROR_NONE);
1078 ret = tdm_layer_commit(l->layer, NULL, NULL);
1079 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1082 LIST_FOR_EACH_ENTRY_SAFE(p, pp, &data->pp_list, link) {
1084 for (i = 0; i < TDM_ARRAY_SIZE(p->bufs); i++)
1085 tbm_surface_destroy(p->bufs[i]);
1089 LIST_FOR_EACH_ENTRY_SAFE(o, oo, &data->output_list, link) {
1091 LIST_FOR_EACH_ENTRY_SAFE(l, ll, &o->layer_list, link) {
1093 LIST_FOR_EACH_ENTRY_SAFE(w, ww, &l->prop_list, link) {
1097 for (i = 0; i < TDM_ARRAY_SIZE(l->bufs); i++)
1098 tbm_surface_destroy(l->bufs[i]);
1101 LIST_FOR_EACH_ENTRY_SAFE(w, ww, &o->prop_list, link) {
1109 LIST_FOR_EACH_ENTRY_SAFE(v, vv, &data->voutput_list, link) {
1110 for (int i = 0; i < 3; i++) {
1111 tbm_surface_destroy(v->bufs[i]);
1117 if (data->do_voutput)
1118 tdm_display_remove_output_create_handler(data->display, _tdm_output_cb_create_handler, data);
1121 tdm_display_deinit(data->display);
1127 main(int argc, char *argv[])
1129 tdm_test_server *data = &tts_data;
1130 char temp[TDM_SERVER_REPLY_MSG_LEN];
1131 int len = sizeof temp;
1134 #if 1 /* for testing */
1135 const char *s = (const char*)getenv("XDG_RUNTIME_DIR");
1138 snprintf(buf, sizeof(buf), "/run");
1139 int ret = setenv("XDG_RUNTIME_DIR", (const char*)buf, 1);
1144 s = (const char*)getenv("TBM_DISPLAY_SERVER");
1147 snprintf(buf, sizeof(buf), "1");
1148 int ret = setenv("TBM_DISPLAY_SERVER", (const char*)buf, 1);
1154 memset(data, 0, sizeof * data);
1155 LIST_INITHEAD(&data->output_list);
1156 LIST_INITHEAD(&data->pp_list);
1157 LIST_INITHEAD(&data->capture_list);
1158 LIST_INITHEAD(&data->voutput_list);
1161 data->bflags = TBM_BO_SCANOUT;
1162 data->b_fill = PATTERN_SMPTE;
1164 data->display = tdm_display_init(&ret);
1165 TDM_EXIT_IF_FAIL(data->display != NULL);
1167 parse_args(data, argc, argv);
1168 interpret_args(data);
1170 if (data->do_query) {
1171 tdm_helper_get_display_information(data->display, temp, &len);
1176 if (data->do_voutput) {
1177 printf("support virtual output - server\n");
1178 ret = tdm_display_add_output_create_handler(data->display, _tdm_output_cb_create_handler, data);
1179 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1185 tdm_display_deinit(data->display);
1191 output_setup(tdm_test_server_output *o)
1193 tdm_test_server *data = o->data;
1194 const tdm_output_mode *modes, *found = NULL, *best = NULL, *prefer = NULL;
1195 tdm_test_server_prop *w = NULL;
1196 const tdm_prop *props;
1200 o->output = tdm_display_get_output(data->display, o->idx, &ret);
1201 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1203 ret = tdm_output_get_available_modes(o->output, &modes, &count);
1204 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1206 for (i = 0; i < count; i++) {
1207 if (!strncmp(o->mode, modes[i].name, TDM_NAME_LEN) && o->refresh == modes[i].vrefresh) {
1209 printf("found mode: %dx%d %d\n", found->hdisplay, found->vdisplay, found->vrefresh);
1214 if (modes[i].type & TDM_OUTPUT_MODE_TYPE_PREFERRED)
1217 if (!found && prefer) {
1219 printf("found prefer mode: %dx%d %d\n", found->hdisplay, found->vdisplay, found->vrefresh);
1221 if (!found && best) {
1223 printf("found best mode: %dx%d %d\n", found->hdisplay, found->vdisplay, found->vrefresh);
1227 printf("couldn't find any mode\n");
1231 ret = tdm_output_set_mode(o->output, found);
1232 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1234 printf("output %d: %s %d\n", o->idx, found->name, found->vrefresh);
1236 ret = tdm_output_get_available_properties(o->output, &props, &count);
1237 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1239 LIST_FOR_EACH_ENTRY(w, &o->prop_list, link) {
1240 for (i = 0; i < count; i++) {
1241 if (strncmp(w->name, props[i].name, TDM_NAME_LEN))
1243 ret = tdm_output_set_property(o->output, props[i].id, w->value);
1244 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1245 printf("\tprop '%s': %d\n", props[i].name, w->value.u32);
1250 /* DPMS on forcely at the first time. */
1251 ret = tdm_output_set_dpms(o->output, TDM_OUTPUT_DPMS_ON);
1252 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1255 static tbm_surface_h
1256 layer_get_buffer(tdm_test_server_layer *l)
1258 int i, size = TDM_ARRAY_SIZE(l->bufs);
1260 for (i = 0; i < size; i++) {
1261 int width = (l->info.src_config.size.h) ? : l->info.src_config.pos.w;
1262 int height = (l->info.src_config.size.v) ? : l->info.src_config.pos.h;
1263 unsigned int format = (l->info.src_config.format) ? : DEFAULT_FORMAT;
1264 int flags = l->o->data->bflags;
1265 tbm_surface_h b = buffer_allocate(width, height, format, flags);
1266 TDM_EXIT_IF_FAIL(b != NULL);
1270 for (i = 0; i < size; i++) {
1271 tdm_test_server_buffer *tb = get_tts_buffer(l->bufs[i]);
1272 TDM_EXIT_IF_FAIL(tb != NULL);
1276 printf("no available layer buffer.\n");
1281 layer_cb_commit(tdm_layer *layer, unsigned int sequence,
1282 unsigned int tv_sec, unsigned int tv_usec,
1285 tdm_test_server_layer *l = user_data;
1286 tbm_surface_h b = layer_get_buffer(l);
1287 TDM_EXIT_IF_FAIL(b != NULL);
1289 if (!l->is_primary || l->o->fill_primary_layer)
1290 tdm_test_buffer_fill(b, l->data->b_fill);
1292 if (!l->is_primary || l->o->fill_primary_layer)
1293 layer_show_buffer(l, b);
1297 layer_cb_buffer_release(tbm_surface_h b, void *user_data)
1299 tdm_test_server_buffer *tb = get_tts_buffer(b);
1300 TDM_EXIT_IF_FAIL(tb != NULL);
1303 tdm_buffer_remove_release_handler(b, layer_cb_buffer_release, NULL);
1305 tb->done(b, user_data);
1309 layer_show_buffer(tdm_test_server_layer *l, tbm_surface_h b)
1311 tdm_test_server *data = l->o->data;
1312 tdm_test_server_buffer *tb;
1315 ret = tdm_layer_set_buffer(l->layer, b);
1316 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1318 tb = get_tts_buffer(b);
1319 TDM_EXIT_IF_FAIL(tb != NULL);
1322 ret = tdm_buffer_add_release_handler(b, layer_cb_buffer_release, NULL);
1323 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1325 if (data->do_vblank)
1326 ret = tdm_layer_commit(l->layer, layer_cb_commit, l);
1328 ret = tdm_layer_commit(l->layer, NULL, NULL);
1329 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1331 printf("show:\tl(%p) b(%p)\n", l, b);
1335 layer_setup(tdm_test_server_layer *l, tbm_surface_h b)
1337 tdm_test_server_prop *w = NULL;
1338 const tdm_prop *props;
1341 tbm_surface_info_s info;
1343 l->layer = tdm_output_get_layer(l->o->output, l->idx, &ret);
1344 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1346 /* The size and format information should be same with buffer's */
1347 tbm_surface_get_info(b, &info);
1348 if (IS_RGB(info.format)) {
1349 l->info.src_config.size.h = info.planes[0].stride >> 2;
1350 l->info.src_config.size.v = info.height;
1352 l->info.src_config.size.h = info.planes[0].stride;
1353 l->info.src_config.size.v = info.height;
1355 l->info.src_config.format = info.format;
1357 ret = tdm_layer_set_info(l->layer, &l->info);
1358 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1360 printf("layer %d: output(%d) ", l->idx, l->o->idx);
1361 print_config(&l->info.src_config);
1363 print_pos(&l->info.dst_pos);
1364 printf(" transform(%s)\n", tdm_transform_str(l->info.transform));
1366 ret = tdm_layer_get_available_properties(l->layer, &props, &count);
1367 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1369 LIST_FOR_EACH_ENTRY(w, &l->prop_list, link) {
1370 for (i = 0; i < count; i++) {
1371 if (strncmp(w->name, props[i].name, TDM_NAME_LEN))
1373 ret = tdm_layer_set_property(l->layer, props[i].id, w->value);
1374 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1375 printf("\tprop '%s': %d\n", props[i].name, w->value.u32);
1381 static tbm_surface_h
1382 pp_get_buffer(tdm_test_server_pp *p)
1384 int i, size = TDM_ARRAY_SIZE(p->bufs);
1386 for (i = 0; i < size; i++) {
1387 int width = (p->info.src_config.size.h) ? : p->info.src_config.pos.w;
1388 int height = (p->info.src_config.size.v) ? : p->info.src_config.pos.h;
1389 unsigned int format = (p->info.src_config.format) ? : DEFAULT_FORMAT;
1390 tbm_surface_h b = buffer_allocate(width, height, format, 0);
1391 TDM_EXIT_IF_FAIL(b != NULL);
1395 for (i = 0; i < size; i++) {
1396 tdm_test_server_buffer *tb = get_tts_buffer(p->bufs[i]);
1402 tdm_test_buffer_fill(p->bufs[i], p->data->b_fill);
1406 printf("no available pp buffer.\n");
1411 pp_cb_done(tdm_pp *pp, tbm_surface_h sb, tbm_surface_h db, void *user_data)
1413 tdm_test_server_buffer *stb, *dtb;
1415 stb = get_tts_buffer(sb);
1416 TDM_EXIT_IF_FAIL(stb != NULL);
1418 dtb = get_tts_buffer(db);
1419 TDM_EXIT_IF_FAIL(dtb != NULL);
1421 stb->in_use = dtb->in_use = 0;
1423 layer_show_buffer(dtb->l, db);
1427 pp_convert_buffer(tdm_test_server_pp *p, tbm_surface_h sb, tbm_surface_h db)
1429 tdm_test_server_buffer *stb, *dtb;
1432 stb = get_tts_buffer(sb);
1433 TDM_EXIT_IF_FAIL(stb != NULL);
1435 dtb = get_tts_buffer(db);
1436 TDM_EXIT_IF_FAIL(dtb != NULL);
1438 stb->in_use = dtb->in_use = 1;
1441 ret = tdm_pp_attach(p->pp, sb, db);
1442 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1444 ret = tdm_pp_commit(p->pp);
1445 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1447 printf("convt:\tp(%p) sb(%p) db(%p)\n", p, sb, db);
1450 /* tdm_event_loop_xxx() function is not for the display server. It's for TDM
1451 * backend module. I use them only for simulating the video play. When we call
1452 * tdm_event_loop_xxx() outside of TDM backend module, we have to lock/unlock
1453 * the TDM display. And when the callback function of tdm_event_loop_xxx() is
1454 * called, the display has been already locked. So in this test application,
1455 * we have to unlock/lock the display for testing.
1458 pp_cb_timeout(void *user_data)
1460 tdm_test_server_pp *p = user_data;
1461 tdm_test_server *data = p->l->o->data;
1462 tbm_surface_h sb, db;
1465 tdm_display_unlock(data->display);
1467 sb = pp_get_buffer(p);
1468 TDM_EXIT_IF_FAIL(sb != NULL);
1469 db = layer_get_buffer(p->l);
1470 TDM_EXIT_IF_FAIL(db != NULL);
1472 pp_convert_buffer(p, sb, db);
1474 tdm_display_lock(data->display);
1475 ret = tdm_event_loop_source_timer_update(p->timer_source, 1000 / p->fps);
1476 tdm_display_unlock(data->display);
1477 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1479 tdm_display_lock(data->display);
1481 return TDM_ERROR_NONE;
1485 pp_setup(tdm_test_server_pp *p, tbm_surface_h sb, tbm_surface_h db)
1487 tdm_test_server *data;
1488 tbm_surface_info_s info;
1491 if (!p || !p->l || !p->l->o || !p->l->o->data) {
1492 TDM_ERR("invalid parameter failed");
1495 data = p->l->o->data;
1497 p->pp = tdm_display_create_pp(data->display, &ret);
1498 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1500 /* The size and format information should be same with buffer's */
1501 tbm_surface_get_info(sb, &info);
1502 if (IS_RGB(info.format)) {
1503 p->info.src_config.size.h = info.planes[0].stride >> 2;
1504 p->info.src_config.size.v = info.height;
1506 p->info.src_config.size.h = info.planes[0].stride;
1507 p->info.src_config.size.v = info.height;
1509 p->info.src_config.format = info.format;
1511 /* The size and format information should be same with buffer's */
1512 tbm_surface_get_info(db, &info);
1513 if (IS_RGB(info.format)) {
1514 p->info.dst_config.size.h = info.planes[0].stride >> 2;
1515 p->info.dst_config.size.v = info.height;
1517 p->info.dst_config.size.h = info.planes[0].stride;
1518 p->info.dst_config.size.v = info.height;
1520 p->info.dst_config.format = info.format;
1522 ret = tdm_pp_set_info(p->pp, &p->info);
1523 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1525 ret = tdm_pp_set_done_handler(p->pp, pp_cb_done, NULL);
1526 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1529 print_config(&p->info.src_config);
1531 print_config(&p->info.dst_config);
1532 printf(" fps(%d) transform(%s)\n", p->fps, tdm_transform_str(p->info.transform));
1533 printf("\toutput_idx(%d) layer_idx(%d)\n", p->l->o->idx, p->l->idx);
1535 layer_setup(p->l, db);
1537 /* tdm_event_loop_xxx() function is not for the display server. It's for TDM
1538 * backend module. I use them only for simulating the video play. When we call
1539 * tdm_event_loop_xxx() outside of TDM backend module, we have to lock/unlock
1540 * the TDM display. And when the callback function of tdm_event_loop_xxx() is
1541 * called, the display has been already locked. So in this test application,
1542 * we have to unlock/lock the display for testing.
1544 tdm_display_lock(data->display);
1545 p->timer_source = tdm_event_loop_add_timer_handler(data->display, pp_cb_timeout, p, &ret);
1546 tdm_display_unlock(data->display);
1547 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1549 tdm_display_lock(data->display);
1550 ret = tdm_event_loop_source_timer_update(p->timer_source, 1000 / p->fps);
1551 tdm_display_unlock(data->display);
1552 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1556 capture_cb_buffer_done(tbm_surface_h b, void *user_data)
1558 tdm_test_server_buffer *tb;
1560 tb = get_tts_buffer(b);
1561 TDM_EXIT_IF_FAIL(tb != NULL);
1563 capture_attach(tb->c, b);
1567 capture_cb_done(tdm_capture *capture, tbm_surface_h b, void *user_data)
1569 tdm_test_server_buffer *tb;
1571 tb = get_tts_buffer(b);
1572 TDM_EXIT_IF_FAIL(tb != NULL);
1576 tb->done = capture_cb_buffer_done;
1577 layer_show_buffer(tb->l, b);
1581 capture_attach(tdm_test_server_capture *c, tbm_surface_h b)
1584 tdm_test_server_buffer *tb;
1586 tb = get_tts_buffer(b);
1587 TDM_EXIT_IF_FAIL(tb != NULL);
1593 ret = tdm_capture_attach(c->capture, b);
1594 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1596 printf("capture:\tc(%p) b(%p)\n", c, b);
1598 ret = tdm_capture_commit(c->capture);
1599 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1603 capture_setup(tdm_test_server_capture *c, tbm_surface_h b)
1605 tdm_test_server *data;
1608 tbm_surface_info_s info;
1611 if (!c || !c->l || !c->l->o || !c->l->o->data) {
1612 TDM_ERR("invalid parameter failed");
1615 data = c->l->o->data;
1617 if (c->output_idx != -1 && c->layer_idx == -1) {
1618 output = tdm_display_get_output(data->display, c->output_idx, &ret);
1619 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1620 c->capture = tdm_output_create_capture(output, &ret);
1621 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1622 } else if (c->output_idx != -1 && c->layer_idx != -1) {
1623 output = tdm_display_get_output(data->display, c->output_idx, &ret);
1624 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1625 layer = tdm_output_get_layer(output, c->layer_idx, &ret);
1626 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1627 c->capture = tdm_layer_create_capture(layer, &ret);
1628 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1631 TDM_EXIT_IF_FAIL(c->capture != NULL);
1633 /* The size and format information should be same with buffer's */
1634 tbm_surface_get_info(b, &info);
1635 if (IS_RGB(info.format)) {
1636 c->info.dst_config.size.h = info.planes[0].stride >> 2;
1637 c->info.dst_config.size.v = info.height;
1639 c->info.dst_config.size.h = info.planes[0].stride;
1640 c->info.dst_config.size.v = info.height;
1642 c->info.dst_config.format = info.format;
1643 c->info.type = TDM_CAPTURE_TYPE_ONESHOT;
1645 ret = tdm_capture_set_info(c->capture, &c->info);
1646 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1648 ret = tdm_capture_set_done_handler(c->capture, capture_cb_done, NULL);
1649 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1651 printf("capture: o(%d) l(%d) ", c->output_idx, c->layer_idx);
1652 print_config(&c->info.dst_config);
1653 printf(" transform(%s)\n", tdm_transform_str(c->info.transform));
1654 printf("\toutput_idx(%d) layer_idx(%d)\n", c->l->o->idx, c->l->idx);
1656 layer_setup(c->l, b);
1660 run_test(tdm_test_server *data)
1662 tdm_test_server_output *o = NULL;
1663 tdm_test_server_layer *l = NULL;
1664 tdm_test_server_pp *p = NULL;
1665 tdm_test_server_capture *c = NULL;
1666 tdm_display_capability caps;
1669 ret = tdm_display_get_capabilities(data->display, &caps);
1670 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1672 LIST_FOR_EACH_ENTRY(o, &data->output_list, link) {
1673 LIST_FOR_EACH_ENTRY(l, &o->layer_list, link) {
1674 if (!l->owner_p && !l->owner_c) {
1676 b = layer_get_buffer(l);
1677 if (!l->is_primary || l->o->fill_primary_layer)
1678 tdm_test_buffer_fill(b, data->b_fill);
1680 layer_show_buffer(l, b);
1685 LIST_FOR_EACH_ENTRY(p, &data->pp_list, link) {
1686 tbm_surface_h sb, db;
1687 TDM_GOTO_IF_FAIL(caps & TDM_DISPLAY_CAPABILITY_PP, no_pp);
1688 sb = pp_get_buffer(p);
1689 TDM_EXIT_IF_FAIL(sb != NULL);
1690 db = layer_get_buffer(p->l);
1691 TDM_EXIT_IF_FAIL(db != NULL);
1692 pp_setup(p, sb, db);
1693 pp_convert_buffer(p, sb, db);
1696 LIST_FOR_EACH_ENTRY(c, &data->capture_list, link) {
1697 TDM_GOTO_IF_FAIL(caps & TDM_DISPLAY_CAPABILITY_CAPTURE, no_capture);
1699 b = layer_get_buffer(c->l);
1700 capture_setup(c, b);
1701 capture_attach(c, b);
1702 b = layer_get_buffer(c->l);
1703 capture_attach(c, b);
1704 b = layer_get_buffer(c->l);
1705 capture_attach(c, b);
1708 printf("enter test loop\n");
1711 ret = tdm_display_handle_events(data->display);
1712 TDM_EXIT_IF_FAIL(ret == TDM_ERROR_NONE);
1719 printf("no PP capability\n");
1722 printf("no Capture capability\n");