1 /**************************************************************************
5 * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
7 * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
8 * JinYoung Jeon <jy0.jeon@samsung.com>,
9 * Taeheon Kim <th908.kim@samsung.com>,
10 * YoungJun Cho <yj44.cho@samsung.com>,
11 * SooChan Lim <sc1.lim@samsung.com>,
12 * Boram Park <sc1.lim@samsung.com>
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the
16 * "Software"), to deal in the Software without restriction, including
17 * without limitation the rights to use, copy, modify, merge, publish,
18 * distribute, sub license, and/or sell copies of the Software, and to
19 * permit persons to whom the Software is furnished to do so, subject to
20 * the following conditions:
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
29 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
30 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 **************************************************************************/
43 #include "tdm_private.h"
47 static const char *file_exts[2] = {"png", "yuv"};
50 char *tdm_debug_dump_dir;
53 tdm_helper_get_time(void)
57 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
58 return (double)tp.tv_sec + ((double)tp.tv_nsec) / 1000000000.0;
64 _tdm_helper_check_file_is_symbolic_link(const char* path)
71 if (stat(path, &sb) != 0)
74 if (S_ISLNK(sb.st_mode))
81 _tdm_helper_dump_raw(const char *file, void *data1, int size1, void *data2,
82 int size2, void *data3, int size3)
87 if (_tdm_helper_check_file_is_symbolic_link(file)) {
88 TDM_ERR("'%s' may be symbolic link\n", file);
92 fp = fopen(file, "w+");
93 TDM_RETURN_IF_FAIL(fp != NULL);
95 blocks = (unsigned int *)data1;
96 fwrite(blocks, 1, size1, fp);
99 blocks = (unsigned int *)data2;
100 fwrite(blocks, 1, size2, fp);
104 blocks = (unsigned int *)data3;
105 fwrite(blocks, 1, size3, fp);
112 _tdm_helper_dump_png(const char *file, const void *data, int width,
117 if (_tdm_helper_check_file_is_symbolic_link(file)) {
118 TDM_ERR("'%s' may be symbolic link\n", file);
122 fp = fopen(file, "wb");
123 TDM_RETURN_IF_FAIL(fp != NULL);
125 png_structp pPngStruct =
126 png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
132 png_infop pPngInfo = png_create_info_struct(pPngStruct);
134 png_destroy_write_struct(&pPngStruct, NULL);
139 png_init_io(pPngStruct, fp);
140 png_set_IHDR(pPngStruct,
147 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
149 png_set_bgr(pPngStruct);
150 png_write_info(pPngStruct, pPngInfo);
152 const int pixel_size = 4; // RGBA
153 png_bytep *row_pointers =
154 png_malloc(pPngStruct, height * sizeof(png_byte *));
156 png_destroy_write_struct(&pPngStruct, &pPngInfo);
161 unsigned int *blocks = (unsigned int *)data;
165 for (; y < height; ++y) {
167 png_malloc(pPngStruct, sizeof(png_byte) * width * pixel_size);
169 for (x = 0; x < y; x++)
170 png_free(pPngStruct, row_pointers[x]);
171 png_free(pPngStruct, row_pointers);
172 png_destroy_write_struct(&pPngStruct, &pPngInfo);
177 row_pointers[y] = (png_bytep)row;
178 for (x = 0; x < width; ++x) {
179 unsigned int curBlock = blocks[y * width + x];
180 row[x * pixel_size] = (curBlock & 0xFF);
181 row[1 + x * pixel_size] = (curBlock >> 8) & 0xFF;
182 row[2 + x * pixel_size] = (curBlock >> 16) & 0xFF;
183 row[3 + x * pixel_size] = (curBlock >> 24) & 0xFF;
187 png_write_image(pPngStruct, row_pointers);
188 png_write_end(pPngStruct, pPngInfo);
190 for (y = 0; y < height; y++)
191 png_free(pPngStruct, row_pointers[y]);
192 png_free(pPngStruct, row_pointers);
194 png_destroy_write_struct(&pPngStruct, &pPngInfo);
199 /* LCOV_EXCL_START */
201 tdm_helper_dump_make_directory(const char *path, char *reply, int *len)
203 char *fullpath = NULL;
205 struct tm *t, *buf = NULL;
209 buf = calloc(1, sizeof(struct tm));
210 TDM_GOTO_IF_FAIL(buf != NULL, failed_make);
212 fullpath = calloc(1, TDM_PATH_LEN * sizeof(char));
213 TDM_GOTO_IF_FAIL(fullpath != NULL, failed_make);
215 t = localtime_r(&timer, buf);
216 TDM_GOTO_IF_FAIL(t != NULL, failed_make);
218 snprintf(fullpath, TDM_PATH_LEN, "%s/dump_%04d%02d%02d.%02d%02d%02d", path,
219 t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
221 if ((mkdir(fullpath, 0755)) < 0) {
222 TDM_ERR("mkdir '%s' fail\n", fullpath);
223 TDM_SNPRINTF(reply, len, "mkdir '%s' fail\n", fullpath);
239 tdm_helper_dump_buffer_str(tbm_surface_h buffer, char *dir, char *str)
241 tbm_surface_info_s info;
242 char file[TDM_PATH_LEN];
245 TDM_RETURN_IF_FAIL(buffer != NULL);
246 TDM_RETURN_IF_FAIL(str != NULL);
251 ret = tbm_surface_get_info(buffer, &info);
252 TDM_RETURN_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE);
254 tdm_helper_get_buffer_full_size(buffer, &bw, &bh);
256 snprintf(file, TDM_PATH_LEN, "%s/%c%c%c%c_%dx%d_%dx%d_%s",
257 dir, FOURCC_STR(info.format), bw, bh, info.width, info.height, str);
259 tdm_helper_dump_buffer(buffer, file);
264 tdm_helper_dump_buffer(tbm_surface_h buffer, const char *file)
266 char temp[TDM_PATH_LEN] = {0,};
267 tbm_surface_info_s info;
272 char *dot, *p = temp;
274 TDM_RETURN_IF_FAIL(buffer != NULL);
275 TDM_RETURN_IF_FAIL(file != NULL);
277 ret = tbm_surface_map(buffer, TBM_OPTION_READ, &info);
278 TDM_RETURN_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE);
280 if (IS_RGB(info.format))
285 dot = strrchr(file, '.');
286 if (!dot || strlen(dot + 1) != 3 || strncmp(dot + 1, ext, 3)) {
287 len = strnlen(file, TDM_PATH_LEN - 5);
288 strncat(p, file, len);
296 tdm_helper_get_buffer_full_size(buffer, &bw, &bh);
298 bo_cnt = tbm_surface_internal_get_num_bos(buffer);
299 TDM_DBG("buffer: bo_cnt(%d) %dx%d(%dx%d) %c%c%c%c, plane: (%p+%d, %d,%d) (%p+%d, %d,%d) (%p+%d, %d,%d)",
300 bo_cnt, bw, bh, info.width, info.height, FOURCC_STR(info.format),
301 info.planes[0].ptr, info.planes[0].offset, info.planes[0].stride, info.planes[0].size,
302 info.planes[1].ptr, info.planes[1].offset, info.planes[1].stride, info.planes[1].size,
303 info.planes[2].ptr, info.planes[2].offset, info.planes[2].stride, info.planes[2].size);
305 switch (info.format) {
306 case TBM_FORMAT_ARGB8888:
307 case TBM_FORMAT_XRGB8888:
308 _tdm_helper_dump_png(temp, info.planes[0].ptr, bw, bh);
310 case TBM_FORMAT_YVU420:
311 case TBM_FORMAT_YUV420:
312 _tdm_helper_dump_raw((const char*)temp,
318 info.planes[2].size);
320 case TBM_FORMAT_NV12:
321 case TBM_FORMAT_NV21:
322 _tdm_helper_dump_raw((const char*)temp,
326 info.planes[1].size, NULL,
330 TDM_ERR("can't dump %c%c%c%c buffer", FOURCC_STR(info.format));
331 tbm_surface_unmap(buffer);
335 tbm_surface_unmap(buffer);
337 TDM_INFO("dump %s", temp);
341 tdm_helper_clear_buffer_color(tbm_surface_h buffer, tdm_pos *pos, unsigned int color)
343 tbm_surface_info_s info;
346 TDM_RETURN_IF_FAIL(buffer != NULL);
348 ret = tbm_surface_map(buffer, TBM_OPTION_READ, &info);
349 TDM_RETURN_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE);
351 switch (info.format) {
352 case TBM_FORMAT_ARGB8888:
353 case TBM_FORMAT_XRGB8888:
355 memset(info.planes[0].ptr, 0, info.planes[0].stride * info.height);
359 for (y = pos->y; y <= (pos->y + pos->h); y++) {
360 p = info.planes[0].ptr + info.planes[0].stride * y;
361 for (x = pos->x; x <= (pos->x + pos->w); x++) {
362 unsigned int *ibuf = (unsigned int*)p;
368 case TBM_FORMAT_YVU420:
369 case TBM_FORMAT_YUV420:
370 memset((char*)info.planes[0].ptr, 0x10, info.planes[0].stride * info.height);
371 memset((char*)info.planes[1].ptr, 0x80, info.planes[1].stride * (info.height >> 1));
372 memset((char*)info.planes[2].ptr, 0x80, info.planes[2].stride * (info.height >> 1));
374 case TBM_FORMAT_NV12:
375 case TBM_FORMAT_NV21:
376 memset((char*)info.planes[0].ptr, 0x10, info.planes[0].stride * info.height);
377 memset((char*)info.planes[1].ptr, 0x80, info.planes[1].stride * (info.height >> 1));
380 TDM_ERR("can't clear %c%c%c%c buffer", FOURCC_STR(info.format));
384 tbm_surface_unmap(buffer);
388 tdm_helper_clear_buffer_pos(tbm_surface_h buffer, tdm_pos *pos)
390 TDM_RETURN_IF_FAIL(buffer != NULL);
392 tdm_helper_clear_buffer_color(buffer, pos, 0);
396 tdm_helper_clear_buffer(tbm_surface_h buffer)
398 TDM_RETURN_IF_FAIL(buffer != NULL);
400 tdm_helper_clear_buffer_pos(buffer, NULL);
404 tdm_helper_get_buffer_full_size(tbm_surface_h buffer, int *buffer_w, int *buffer_h)
406 tbm_surface_info_s info;
409 TDM_RETURN_IF_FAIL(buffer != NULL);
411 ret = tbm_surface_get_info(buffer, &info);
412 TDM_RETURN_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE);
415 if (IS_RGB(info.format))
416 *buffer_w = info.planes[0].stride >> 2;
418 *buffer_w = info.planes[0].stride;
422 *buffer_h = info.planes[0].size / info.planes[0].stride;
425 static pixman_format_code_t
426 _tdm_helper_pixman_format_get(tbm_format format)
429 case TBM_FORMAT_ARGB8888:
430 return PIXMAN_a8r8g8b8;
431 case TBM_FORMAT_XRGB8888:
432 return PIXMAN_x8r8g8b8;
441 tdm_helper_convert_buffer(tbm_surface_h srcbuf, tbm_surface_h dstbuf,
442 tdm_pos *srcpos, tdm_pos *dstpos,
443 tdm_transform transform, int over)
445 tbm_surface_info_s src_info, dst_info;
446 pixman_image_t *src_img = NULL, *dst_img = NULL;
447 pixman_format_code_t src_format, dst_format;
448 double scale_x, scale_y;
449 int rotate_step, bos;
450 pixman_transform_t t;
451 struct pixman_f_transform ft;
453 int src_stride, dst_stride;
455 tdm_error ret = TDM_ERROR_OPERATION_FAILED;
457 TDM_RETURN_VAL_IF_FAIL(srcbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
458 TDM_RETURN_VAL_IF_FAIL(dstbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
460 bos = tbm_surface_internal_get_num_bos(srcbuf);
461 TDM_RETURN_VAL_IF_FAIL(bos == 1, TDM_ERROR_OPERATION_FAILED);
463 bos = tbm_surface_internal_get_num_bos(dstbuf);
464 TDM_RETURN_VAL_IF_FAIL(bos == 1, TDM_ERROR_OPERATION_FAILED);
466 err = tbm_surface_map(srcbuf, TBM_OPTION_READ, &src_info);
467 TDM_RETURN_VAL_IF_FAIL(err == TBM_SURFACE_ERROR_NONE, TDM_ERROR_OPERATION_FAILED);
469 err = tbm_surface_map(dstbuf, TBM_OPTION_WRITE, &dst_info);
470 TDM_GOTO_IF_FAIL(err == TBM_SURFACE_ERROR_NONE, unmap_srcbuf);
472 /* not handle buffers which have 2 more gem handles */
473 TDM_GOTO_IF_FAIL(src_info.planes[0].ptr != NULL, unmap_dstbuf);
474 TDM_GOTO_IF_FAIL(dst_info.planes[0].ptr != NULL, unmap_dstbuf);
476 src_format = _tdm_helper_pixman_format_get(src_info.format);
477 TDM_GOTO_IF_FAIL(src_format > 0, unmap_dstbuf);
478 dst_format = _tdm_helper_pixman_format_get(dst_info.format);
479 TDM_GOTO_IF_FAIL(dst_format > 0, unmap_dstbuf);
481 buf_width = src_info.planes[0].stride >> 2;
482 src_stride = src_info.planes[0].stride;
483 src_img = pixman_image_create_bits(src_format, buf_width, src_info.height,
484 (uint32_t*)src_info.planes[0].ptr, src_stride);
485 TDM_GOTO_IF_FAIL(src_img, unref_img);
487 buf_width = dst_info.planes[0].stride >> 2;
488 dst_stride = dst_info.planes[0].stride;
489 dst_img = pixman_image_create_bits(dst_format, buf_width, dst_info.height,
490 (uint32_t*)dst_info.planes[0].ptr, dst_stride);
491 TDM_GOTO_IF_FAIL(dst_img, unref_img);
493 pixman_f_transform_init_identity(&ft);
495 if (transform & TDM_TRANSFORM_FLIPPED) {
496 pixman_f_transform_scale(&ft, NULL, -1, 1);
497 pixman_f_transform_translate(&ft, NULL, dstpos->w, 0);
500 rotate_step = transform & 0x3;
501 if (rotate_step > 0) {
502 int c, s, tx = 0, ty = 0;
503 switch (rotate_step) {
505 c = 0, s = -1, tx = -dstpos->w;
508 c = -1, s = 0, tx = -dstpos->w, ty = -dstpos->h;
511 c = 0, s = 1, ty = -dstpos->h;
514 pixman_f_transform_translate(&ft, NULL, tx, ty);
515 pixman_f_transform_rotate(&ft, NULL, c, s);
518 if (rotate_step % 2 == 0) {
519 scale_x = (double)srcpos->w / dstpos->w;
520 scale_y = (double)srcpos->h / dstpos->h;
522 scale_x = (double)srcpos->w / dstpos->h;
523 scale_y = (double)srcpos->h / dstpos->w;
526 pixman_f_transform_scale(&ft, NULL, scale_x, scale_y);
527 pixman_f_transform_translate(&ft, NULL, srcpos->x, srcpos->y);
528 pixman_transform_from_pixman_f_transform(&t, &ft);
529 pixman_image_set_transform(src_img, &t);
531 op = (!over) ? PIXMAN_OP_SRC : PIXMAN_OP_OVER;
533 pixman_image_composite(op, src_img, NULL, dst_img, 0, 0, 0, 0,
534 dstpos->x, dstpos->y, dstpos->w, dstpos->h);
536 ret = TDM_ERROR_NONE;
540 pixman_image_unref(src_img);
542 pixman_image_unref(dst_img);
544 tbm_surface_unmap(dstbuf);
546 tbm_surface_unmap(srcbuf);
551 /* LCOV_EXCL_START */
553 tdm_helper_get_fd(const char *env)
555 if (strncmp(env, "TBM_DRM_MASTER_FD", 17) && strncmp(env, "TDM_DRM_MASTER_FD", 17)) {
556 TDM_INFO("DEPRECATED! '%s'", env);
560 return tbm_drm_helper_get_master_fd();
564 tdm_helper_set_fd(const char *env, int fd)
566 if (strncmp(env, "TBM_DRM_MASTER_FD", 17) && strncmp(env, "TDM_DRM_MASTER_FD", 17)) {
567 TDM_INFO("DEPRECATED! '%s'", env);
571 tbm_drm_helper_set_tbm_master_fd(fd);
576 tdm_helper_dump_start(char *dumppath, int *count)
578 if (dumppath == NULL || count == NULL) {
579 TDM_DBG("tdm_helper_dump dumppath or count is null.");
585 TDM_DBG("tdm_helper_dump start.(path : %s)", dumppath);
589 tdm_helper_dump_stop(void)
593 TDM_DBG("tdm_helper_dump stop.");
596 /* LCOV_EXCL_START */
598 _tdm_helper_buffer_convert(tbm_surface_h srcbuf, tbm_surface_h dstbuf,
599 int dx, int dy, int dw, int dh, int count)
601 pixman_image_t *src_img = NULL, *dst_img = NULL;
602 pixman_format_code_t src_format, dst_format;
603 pixman_transform_t t;
604 struct pixman_f_transform ft;
606 tbm_surface_info_s src_info = {0, };
607 tbm_surface_info_s dst_info = {0, };
609 double scale_x, scale_y;
611 TDM_RETURN_VAL_IF_FAIL(srcbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
612 TDM_RETURN_VAL_IF_FAIL(dstbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
614 if (tbm_surface_map(srcbuf, TBM_SURF_OPTION_READ, &src_info) != TBM_SURFACE_ERROR_NONE) {
615 TDM_ERR("cannot mmap srcbuf\n");
616 return TDM_ERROR_OPERATION_FAILED;
619 if (tbm_surface_map(dstbuf, TBM_SURF_OPTION_WRITE, &dst_info) != TBM_SURFACE_ERROR_NONE) {
620 TDM_ERR("cannot mmap dstbuf\n");
621 tbm_surface_unmap(srcbuf);
622 return TDM_ERROR_OPERATION_FAILED;
624 TDM_GOTO_IF_FAIL(src_info.num_planes == 1, cant_convert);
625 TDM_GOTO_IF_FAIL(dst_info.num_planes == 1, cant_convert);
628 src_format = _tdm_helper_pixman_format_get(src_info.format);
629 TDM_GOTO_IF_FAIL(src_format > 0, cant_convert);
631 width = src_info.planes[0].stride / 4;
632 stride = src_info.planes[0].stride;
633 src_img = pixman_image_create_bits(src_format, width, src_info.height,
634 (uint32_t*)src_info.planes[0].ptr, stride);
635 TDM_GOTO_IF_FAIL(src_img != NULL, cant_convert);
638 dst_format = _tdm_helper_pixman_format_get(dst_info.format);
639 TDM_GOTO_IF_FAIL(dst_format > 0, cant_convert);
641 width = dst_info.planes[0].stride / 4;
642 stride = dst_info.planes[0].stride;
643 dst_img = pixman_image_create_bits(dst_format, width, dst_info.height,
644 (uint32_t*)dst_info.planes[0].ptr, stride);
645 TDM_GOTO_IF_FAIL(dst_img != NULL, cant_convert);
647 pixman_f_transform_init_identity(&ft);
649 scale_x = (double)src_info.width / dw;
650 scale_y = (double)src_info.height / dh;
652 pixman_f_transform_scale(&ft, NULL, scale_x, scale_y);
653 pixman_f_transform_translate(&ft, NULL, 0, 0);
654 pixman_transform_from_pixman_f_transform(&t, &ft);
655 pixman_image_set_transform(src_img, &t);
662 pixman_image_composite(op, src_img, NULL, dst_img,
663 0, 0, 0, 0, dx, dy, dw, dh);
666 pixman_image_unref(src_img);
668 pixman_image_unref(dst_img);
670 tbm_surface_unmap(srcbuf);
671 tbm_surface_unmap(dstbuf);
673 return TDM_ERROR_NONE;
677 pixman_image_unref(src_img);
679 tbm_surface_unmap(srcbuf);
680 tbm_surface_unmap(dstbuf);
682 return TDM_ERROR_OPERATION_FAILED;
688 tdm_helper_capture_output(tdm_output *output, tbm_surface_h dst_buffer,
689 int x, int y, int w, int h,
690 tdm_helper_capture_handler func, void *data)
692 tbm_surface_h surface;
694 int i, count, first = 0;
696 TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
697 TDM_RETURN_VAL_IF_FAIL(dst_buffer != NULL, TDM_ERROR_INVALID_PARAMETER);
698 TDM_RETURN_VAL_IF_FAIL(x >= 0, TDM_ERROR_INVALID_PARAMETER);
699 TDM_RETURN_VAL_IF_FAIL(y >= 0, TDM_ERROR_INVALID_PARAMETER);
700 TDM_RETURN_VAL_IF_FAIL(w >= 0, TDM_ERROR_INVALID_PARAMETER);
701 TDM_RETURN_VAL_IF_FAIL(h >= 0, TDM_ERROR_INVALID_PARAMETER);
702 TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
704 err = tdm_output_get_layer_count(output, &count);
705 if (err != TDM_ERROR_NONE) {
706 TDM_ERR("tdm_output_get_layer_count fail(%d)\n", err);
707 return TDM_ERROR_OPERATION_FAILED;
710 TDM_ERR("tdm_output_get_layer_count err(%d, %d)\n", err, count);
711 return TDM_ERROR_BAD_MODULE;
714 for (i = count - 1; i >= 0; i--) {
715 tdm_layer *layer = tdm_output_get_layer(output, i, NULL);
717 surface = tdm_layer_get_displaying_buffer(layer, &err);
718 if (err != TDM_ERROR_NONE)
721 err = _tdm_helper_buffer_convert(surface, dst_buffer, x, y, w, h, first++);
722 if (err != TDM_ERROR_NONE)
723 TDM_DBG("convert fail %d-layer buffer\n", i);
725 TDM_DBG("convert success %d-layer buffer\n", i);
728 func(dst_buffer, data);
730 return TDM_ERROR_NONE;
734 _tdm_helper_get_backend_information(tdm_private_module *private_module, char *reply, int *len)
736 tdm_backend_module *module_data;
737 tdm_func_output *func_output;
738 tdm_func_layer *func_layer;
739 tdm_private_output *private_output = NULL;
740 tdm_private_layer *private_layer = NULL;
741 tdm_private_pp *private_pp = NULL;
742 tdm_private_capture *private_capture = NULL;
746 func_output = &private_module->func_output;
747 func_layer = &private_module->func_layer;
749 /* module information */
750 module_data = private_module->module_data;
751 TDM_SNPRINTF(reply, len, "['%s' backend information]\n", module_data->name);
752 TDM_SNPRINTF(reply, len, "vendor: %s\n", module_data->vendor);
753 TDM_SNPRINTF(reply, len, "version: %d.%d\n\n",
754 (int)TDM_BACKEND_GET_ABI_MAJOR(module_data->abi_version),
755 (int)TDM_BACKEND_GET_ABI_MINOR(module_data->abi_version));
757 /* output information */
758 TDM_SNPRINTF(reply, len, "['%s' backend output information]\n", module_data->name);
759 TDM_SNPRINTF(reply, len, "--------------------------------------------------------------------------------------------\n");
760 TDM_SNPRINTF(reply, len, "idx maker model name type status dpms subpixel align_w min max phy(mm)\n");
761 TDM_SNPRINTF(reply, len, "--------------------------------------------------------------------------------------------\n");
762 LIST_FOR_EACH_ENTRY(private_output, &private_module->output_list, link) {
763 TDM_SNPRINTF(reply, len, "%d %s %s %s %s %s %s %u %d %dx%d %dx%d %ux%u\n",
764 private_output->index, private_output->caps.maker,
765 private_output->caps.model, private_output->caps.name,
766 tdm_conn_str(private_output->caps.type),
767 tdm_status_str(private_output->caps.status),
768 tdm_dpms_str(private_output->current_dpms_value),
769 private_output->caps.subpixel,
770 TDM_FRONT_VALUE(private_output->caps.preferred_align),
771 TDM_FRONT_VALUE(private_output->caps.min_w),
772 TDM_FRONT_VALUE(private_output->caps.min_h),
773 TDM_FRONT_VALUE(private_output->caps.max_w),
774 TDM_FRONT_VALUE(private_output->caps.max_h),
775 private_output->caps.mmWidth, private_output->caps.mmHeight);
777 TDM_SNPRINTF(reply, len, "\t%u modes:\n", private_output->caps.mode_count);
779 if (private_output->caps.mode_count > 0) {
780 TDM_SNPRINTF(reply, len, "\t\t name refresh (Hz) clk hdisp hss hse htot vdisp vss vse vtot vscan\n");
781 for (i = 0; i < private_output->caps.mode_count; i++) {
782 char *current = (private_output->current_mode == private_output->caps.modes + i) ? "*" : " ";
783 TDM_SNPRINTF(reply, len, "\t\t%s%s %u %u %u %u %u %u %u %u %u %u %u ",
785 private_output->caps.modes[i].name,
786 private_output->caps.modes[i].vrefresh,
787 private_output->caps.modes[i].clock,
788 private_output->caps.modes[i].hdisplay,
789 private_output->caps.modes[i].hsync_start,
790 private_output->caps.modes[i].hsync_end,
791 private_output->caps.modes[i].htotal,
792 private_output->caps.modes[i].vdisplay,
793 private_output->caps.modes[i].vsync_start,
794 private_output->caps.modes[i].vsync_end,
795 private_output->caps.modes[i].vtotal,
796 private_output->caps.modes[i].vscan);
797 tdm_mode_flag_str(private_output->caps.modes[i].flags, &reply, len);
798 TDM_SNPRINTF(reply, len, " ");
799 tdm_mode_type_str(private_output->caps.modes[i].type, &reply, len);
800 TDM_SNPRINTF(reply, len, "\n");
804 TDM_SNPRINTF(reply, len, "\t%d properties:\n", private_output->caps.prop_count);
805 if (private_output->caps.prop_count > 0) {
806 TDM_SNPRINTF(reply, len, "\t\tname\ttype\tidx\tvalue\n");
807 for (i = 0; i < private_output->caps.prop_count; i++) {
809 TDM_DBG_RETURN_VAL_IF_FAIL(func_output->output_get_property, reply);
810 ret = func_output->output_get_property(private_output->output_backend,
811 private_output->caps.props[i].id,
813 TDM_DBG_RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, reply);
814 TDM_SNPRINTF(reply, len, "\t\t%s\t%s\t%u\t",
815 private_output->caps.props[i].name,
816 tdm_value_type_str(private_output->caps.props[i].type),
817 private_output->caps.props[i].id);
818 switch (private_output->caps.props[i].type) {
819 case TDM_VALUE_TYPE_PTR:
820 TDM_SNPRINTF(reply, len, "%p\n", value.ptr);
822 case TDM_VALUE_TYPE_INT32:
823 TDM_SNPRINTF(reply, len, "%d\n", value.s32);
825 case TDM_VALUE_TYPE_INT64:
826 TDM_SNPRINTF(reply, len, "%"PRId64"\n", value.s64);
828 case TDM_VALUE_TYPE_UINT64:
829 TDM_SNPRINTF(reply, len, "%"PRIu64"\n", value.u64);
831 case TDM_VALUE_TYPE_UINT32:
833 TDM_SNPRINTF(reply, len, "%u\n", value.u32);
839 TDM_SNPRINTF(reply, len, "\n");
841 /* layer information */
842 TDM_SNPRINTF(reply, len, "['%s' backend layer information]\n", module_data->name);
843 TDM_SNPRINTF(reply, len, "-----------------------------------------------------------------------\n");
844 TDM_SNPRINTF(reply, len, "idx output zpos buf format size crop geometry transform\n");
845 TDM_SNPRINTF(reply, len, "-----------------------------------------------------------------------\n");
846 LIST_FOR_EACH_ENTRY(private_output, &private_module->output_list, link) {
847 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
848 if (!private_layer->usable) {
852 tbm_surface_info_s buf_info;
854 TDM_DBG_RETURN_VAL_IF_FAIL(func_layer->layer_get_info, reply);
855 memset(&info, 0, sizeof info);
856 ret = func_layer->layer_get_info(private_layer->layer_backend, &info);
857 TDM_DBG_RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, reply);
859 if (!private_layer->showing_buffer)
862 format = tbm_surface_get_format(private_layer->showing_buffer->buffer);
863 tbm_surface_get_info(private_layer->showing_buffer->buffer, &buf_info);
866 size.h = buf_info.planes[0].stride >> 2;
868 size.h = buf_info.planes[0].stride;
869 size.v = tbm_surface_get_height(private_layer->showing_buffer->buffer);
871 if (info.src_config.format)
872 format = (info.src_config.format) ? : format;
874 TDM_SNPRINTF(reply, len, "%d %d %d %p %c%c%c%c %ux%u %ux%u+%u+%u %ux%u+%u+%u %s\n",
875 private_layer->index,
876 private_output->index,
877 private_layer->caps.zpos,
878 private_layer->showing_buffer->buffer, FOURCC_STR(format), size.h, size.v,
879 info.src_config.pos.w, info.src_config.pos.h, info.src_config.pos.x, info.src_config.pos.y,
880 info.dst_pos.w, info.dst_pos.h, info.dst_pos.x, info.dst_pos.y,
881 tdm_transform_str(info.transform));
883 TDM_SNPRINTF(reply, len, "%d %d %d -\n",
884 private_layer->index,
885 private_output->index,
886 private_layer->caps.zpos);
889 TDM_SNPRINTF(reply, len, "\tcaps\t: ");
890 tdm_layer_caps_str(private_layer->caps.capabilities, &reply, len);
891 TDM_SNPRINTF(reply, len, "\n");
893 TDM_SNPRINTF(reply, len, "\tformats\t: ");
894 if (private_layer->caps.format_count > 0) {
895 const char *sep = "";
896 for (i = 0; i < private_layer->caps.format_count; i++) {
897 if (private_layer->caps.formats[i] == 0)
899 TDM_SNPRINTF(reply, len, "%s%c%c%c%c", sep, FOURCC_STR(private_layer->caps.formats[i]));
902 TDM_SNPRINTF(reply, len, "\n");
905 TDM_SNPRINTF(reply, len, "\t%u properties:\n", private_layer->caps.prop_count);
906 if (private_layer->caps.prop_count > 0) {
907 TDM_SNPRINTF(reply, len, "\t\tname\ttype\tidx\tvalue\n");
908 for (i = 0; i < private_layer->caps.prop_count; i++) {
910 TDM_DBG_RETURN_VAL_IF_FAIL(func_layer->layer_get_property, reply);
911 ret = func_layer->layer_get_property(private_layer->layer_backend,
912 private_layer->caps.props[i].id,
914 TDM_DBG_RETURN_VAL_IF_FAIL(ret == TDM_ERROR_NONE, reply);
915 TDM_SNPRINTF(reply, len, "\t\t%s\t%s\t%u\t",
916 private_layer->caps.props[i].name,
917 tdm_value_type_str(private_output->caps.props[i].type),
918 private_layer->caps.props[i].id);
919 switch (private_layer->caps.props[i].type) {
920 case TDM_VALUE_TYPE_PTR:
921 TDM_SNPRINTF(reply, len, "%p\n", value.ptr);
923 case TDM_VALUE_TYPE_INT32:
924 TDM_SNPRINTF(reply, len, "%d\n", value.s32);
926 case TDM_VALUE_TYPE_INT64:
927 TDM_SNPRINTF(reply, len, "%"PRId64"\n", value.s64);
929 case TDM_VALUE_TYPE_UINT64:
930 TDM_SNPRINTF(reply, len, "%"PRIu64"\n", value.u64);
932 case TDM_VALUE_TYPE_UINT32:
934 TDM_SNPRINTF(reply, len, "%u\n", value.u32);
941 TDM_SNPRINTF(reply, len, "\n");
943 if (private_module->capabilities & TDM_DISPLAY_CAPABILITY_PP) {
944 const char *sep = "";
945 TDM_SNPRINTF(reply, len, "['%s' backend PP information]\n", module_data->name);
946 TDM_SNPRINTF(reply, len, "caps\t: ");
947 tdm_pp_caps_str(private_module->caps_pp.capabilities, &reply, len);
948 TDM_SNPRINTF(reply, len, "\n");
949 TDM_SNPRINTF(reply, len, "formats\t: ");
950 for (i = 0; i < private_module->caps_pp.format_count; i++) {
951 if (private_module->caps_pp.formats[i] == 0)
953 TDM_SNPRINTF(reply, len, "%s%c%c%c%c", sep, FOURCC_STR(private_module->caps_pp.formats[i]));
956 TDM_SNPRINTF(reply, len, "\n");
957 TDM_SNPRINTF(reply, len, "size\t: min(%dx%d) max(%dx%d) align_w(%d)\n",
958 TDM_FRONT_VALUE(private_module->caps_pp.min_w),
959 TDM_FRONT_VALUE(private_module->caps_pp.min_h),
960 TDM_FRONT_VALUE(private_module->caps_pp.max_w),
961 TDM_FRONT_VALUE(private_module->caps_pp.max_h),
962 TDM_FRONT_VALUE(private_module->caps_pp.preferred_align));
963 if (!LIST_IS_EMPTY(&private_module->pp_list)) {
964 TDM_SNPRINTF(reply, len, "-------------------------------------------------------------\n");
965 TDM_SNPRINTF(reply, len, "src(format size crop) | dst(format size crop) | transform\n");
966 TDM_SNPRINTF(reply, len, "-------------------------------------------------------------\n");
967 LIST_FOR_EACH_ENTRY(private_pp, &private_module->pp_list, link) {
968 TDM_SNPRINTF(reply, len, "%c%c%c%c %ux%u %ux%u+%u+%u | %c%c%c%c %ux%u %ux%u+%u+%u | %s\n",
969 FOURCC_STR(private_pp->info.src_config.format),
970 private_pp->info.src_config.size.h,
971 private_pp->info.src_config.size.v,
972 private_pp->info.src_config.pos.x, private_pp->info.src_config.pos.y,
973 private_pp->info.src_config.pos.w, private_pp->info.src_config.pos.h,
974 FOURCC_STR(private_pp->info.dst_config.format),
975 private_pp->info.dst_config.size.h,
976 private_pp->info.dst_config.size.v,
977 private_pp->info.dst_config.pos.x, private_pp->info.dst_config.pos.y,
978 private_pp->info.dst_config.pos.w, private_pp->info.dst_config.pos.h,
979 tdm_transform_str(private_pp->info.transform));
983 TDM_SNPRINTF(reply, len, "['%s' backend No PP capability]\n", module_data->name);
985 TDM_SNPRINTF(reply, len, "\n");
987 if (private_module->capabilities & TDM_DISPLAY_CAPABILITY_CAPTURE) {
988 const char *sep = "";
989 TDM_SNPRINTF(reply, len, "['%s' backend capture information]\n", module_data->name);
990 TDM_SNPRINTF(reply, len, "caps\t: ");
991 tdm_capture_caps_str(private_module->caps_capture.capabilities, &reply, len);
992 TDM_SNPRINTF(reply, len, "\n");
993 TDM_SNPRINTF(reply, len, "formats\t: ");
994 for (i = 0; i < private_module->caps_capture.format_count; i++) {
995 if (private_module->caps_capture.formats[i] == 0)
997 TDM_SNPRINTF(reply, len, "%s%c%c%c%c", sep, FOURCC_STR(private_module->caps_capture.formats[i]));
1000 TDM_SNPRINTF(reply, len, "\n");
1001 TDM_SNPRINTF(reply, len, "size\t: min(%dx%d) max(%dx%d) align_w(%d)\n",
1002 TDM_FRONT_VALUE(private_module->caps_capture.min_w),
1003 TDM_FRONT_VALUE(private_module->caps_capture.min_h),
1004 TDM_FRONT_VALUE(private_module->caps_capture.max_w),
1005 TDM_FRONT_VALUE(private_module->caps_capture.max_h),
1006 TDM_FRONT_VALUE(private_module->caps_capture.preferred_align));
1007 if (!LIST_IS_EMPTY(&private_module->capture_list)) {
1008 TDM_SNPRINTF(reply, len, "-----------------------------------\n");
1009 TDM_SNPRINTF(reply, len, "dst(format size crop) | transform\n");
1010 TDM_SNPRINTF(reply, len, "-----------------------------------\n");
1011 LIST_FOR_EACH_ENTRY(private_capture, &private_module->capture_list, link) {
1012 TDM_SNPRINTF(reply, len, "%c%c%c%c %ux%u %ux%u+%u+%u | %s\n",
1013 FOURCC_STR(private_capture->info.dst_config.format),
1014 private_capture->info.dst_config.size.h,
1015 private_capture->info.dst_config.size.v,
1016 private_capture->info.dst_config.pos.x, private_capture->info.dst_config.pos.y,
1017 private_capture->info.dst_config.pos.w, private_capture->info.dst_config.pos.h,
1018 tdm_transform_str(private_capture->info.transform));
1022 TDM_SNPRINTF(reply, len, "['%s' backend No Capture capability]\n", module_data->name);
1024 TDM_SNPRINTF(reply, len, "\n");
1029 tdm_helper_get_display_information(tdm_display *dpy, char *reply, int *len)
1031 tdm_private_display *private_display;
1032 tdm_private_module *private_module = NULL;
1034 TDM_DBG_RETURN_IF_FAIL(dpy != NULL);
1036 private_display = dpy;
1038 _pthread_mutex_lock(&private_display->lock);
1040 LIST_FOR_EACH_ENTRY(private_module, &private_display->module_list, link) {
1041 reply = _tdm_helper_get_backend_information(private_module, reply, len);
1044 _pthread_mutex_unlock(&private_display->lock);
1047 /* LCOV_EXCL_START */
1049 tdm_helper_commit_per_vblank_enabled(tdm_display *dpy)
1051 TDM_DEPRECATED("Use tdm_helper_output_commit_per_vblank_enabled");
1055 /* LCOV_EXCL_STOP */
1058 tdm_helper_output_commit_per_vblank_enabled(tdm_output *output)
1060 tdm_private_output *private_output = output;
1062 TDM_RETURN_VAL_IF_FAIL(private_output != NULL, -1);
1064 return !!private_output->commit_per_vblank;
1068 tdm_helper_output_vblank_timer_expired(tdm_output *output)
1070 tdm_private_output *private_output = output;
1072 TDM_RETURN_VAL_IF_FAIL(private_output != NULL, -1);
1074 return private_output->vblank_timeout_timer_expired;