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 **************************************************************************/
42 #include <tbm_surface.h>
43 #include <tbm_surface_internal.h>
49 #include "tdm_private.h"
50 #include "tdm_helper.h"
54 static const char *file_exts[2] = {"png", "yuv"};
57 char *tdm_debug_dump_dir;
60 tdm_helper_get_time(void)
64 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
65 return (double)tp.tv_sec + ((double)tp.tv_nsec) / 1000000000.0;
71 _tdm_helper_dump_raw(const char *file, void *data1, int size1, void *data2,
72 int size2, void *data3, int size3)
75 FILE *fp = fopen(file, "w+");
76 TDM_RETURN_IF_FAIL(fp != NULL);
78 blocks = (unsigned int *)data1;
79 fwrite(blocks, 1, size1, fp);
82 blocks = (unsigned int *)data2;
83 fwrite(blocks, 1, size2, fp);
87 blocks = (unsigned int *)data3;
88 fwrite(blocks, 1, size3, fp);
95 _tdm_helper_dump_png(const char *file, const void *data, int width,
98 FILE *fp = fopen(file, "wb");
99 TDM_RETURN_IF_FAIL(fp != NULL);
101 png_structp pPngStruct =
102 png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
108 png_infop pPngInfo = png_create_info_struct(pPngStruct);
110 png_destroy_write_struct(&pPngStruct, NULL);
115 png_init_io(pPngStruct, fp);
116 png_set_IHDR(pPngStruct,
123 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
125 png_set_bgr(pPngStruct);
126 png_write_info(pPngStruct, pPngInfo);
128 const int pixel_size = 4; // RGBA
129 png_bytep *row_pointers =
130 png_malloc(pPngStruct, height * sizeof(png_byte *));
132 png_destroy_write_struct(&pPngStruct, &pPngInfo);
137 unsigned int *blocks = (unsigned int *)data;
141 for (; y < height; ++y) {
143 png_malloc(pPngStruct, sizeof(png_byte) * width * pixel_size);
145 for (x = 0; x < y; x++)
146 png_free(pPngStruct, row_pointers[x]);
147 png_free(pPngStruct, row_pointers);
148 png_destroy_write_struct(&pPngStruct, &pPngInfo);
153 row_pointers[y] = (png_bytep)row;
154 for (x = 0; x < width; ++x) {
155 unsigned int curBlock = blocks[y * width + x];
156 row[x * pixel_size] = (curBlock & 0xFF);
157 row[1 + x * pixel_size] = (curBlock >> 8) & 0xFF;
158 row[2 + x * pixel_size] = (curBlock >> 16) & 0xFF;
159 row[3 + x * pixel_size] = (curBlock >> 24) & 0xFF;
163 png_write_image(pPngStruct, row_pointers);
164 png_write_end(pPngStruct, pPngInfo);
166 for (y = 0; y < height; y++)
167 png_free(pPngStruct, row_pointers[y]);
168 png_free(pPngStruct, row_pointers);
170 png_destroy_write_struct(&pPngStruct, &pPngInfo);
176 tdm_helper_dump_make_directory(const char *path, char *reply, int *len)
178 char *fullpath = NULL;
180 struct tm *t, *buf = NULL;
184 buf = calloc(1, sizeof(struct tm));
185 TDM_GOTO_IF_FAIL(buf != NULL, failed_make);
187 fullpath = calloc(1, TDM_PATH_LEN * sizeof(char));
188 TDM_GOTO_IF_FAIL(fullpath != NULL, failed_make);
190 t = localtime_r(&timer, buf);
191 TDM_GOTO_IF_FAIL(t != NULL, failed_make);
193 snprintf(fullpath, TDM_PATH_LEN, "%s/dump_%04d%02d%02d.%02d%02d%02d", path,
194 t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
196 if ((mkdir(fullpath, 0755)) < 0) {
197 TDM_ERR("mkdir '%s' fail\n", fullpath);
198 TDM_SNPRINTF(reply, len, "mkdir '%s' fail\n", fullpath);
214 tdm_helper_dump_buffer_str(tbm_surface_h buffer, char *dir, char *str)
216 tbm_surface_info_s info;
218 char file[TDM_PATH_LEN];
221 TDM_RETURN_IF_FAIL(buffer != NULL);
222 TDM_RETURN_IF_FAIL(dir != NULL);
223 TDM_RETURN_IF_FAIL(str != NULL);
225 ret = tbm_surface_get_info(buffer, &info);
226 TDM_RETURN_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE);
228 if (info.format == TBM_FORMAT_ARGB8888 || info.format == TBM_FORMAT_XRGB8888) {
230 bw = info.planes[0].stride >> 2;
233 bw = info.planes[0].stride;
236 snprintf(file, TDM_PATH_LEN, "%s/%c%c%c%c_%dx%d_%s.%s",
237 dir, FOURCC_STR(info.format), bw, info.height, str, ext);
239 tdm_helper_dump_buffer(buffer, file);
243 tdm_helper_dump_buffer(tbm_surface_h buffer, const char *file)
245 tbm_surface_info_s info;
250 TDM_RETURN_IF_FAIL(buffer != NULL);
251 TDM_RETURN_IF_FAIL(file != NULL);
253 ret = tbm_surface_map(buffer, TBM_OPTION_READ, &info);
254 TDM_RETURN_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE);
256 len = strnlen(file, 1024);
257 if (info.format == TBM_FORMAT_ARGB8888 || info.format == TBM_FORMAT_XRGB8888)
262 if (strncmp(file + (len - 3), ext, 3)) {
263 TDM_ERR("can't dump to '%s' file", file + (len - 3));
264 tbm_surface_unmap(buffer);
268 bo_cnt = tbm_surface_internal_get_num_bos(buffer);
269 TDM_DBG("buffer: bo_cnt(%d) %dx%d %c%c%c%c, plane: (%p+%d, %d,%d) (%p+%d, %d,%d) (%p+%d, %d,%d)",
270 bo_cnt, info.width, info.height, FOURCC_STR(info.format),
271 info.planes[0].ptr, info.planes[0].offset, info.planes[0].stride, info.planes[0].size,
272 info.planes[1].ptr, info.planes[1].offset, info.planes[1].stride, info.planes[1].size,
273 info.planes[2].ptr, info.planes[2].offset, info.planes[2].stride, info.planes[2].size);
275 switch (info.format) {
276 case TBM_FORMAT_ARGB8888:
277 case TBM_FORMAT_XRGB8888:
278 _tdm_helper_dump_png(file, info.planes[0].ptr,
279 info.planes[0].stride >> 2, info.height);
281 case TBM_FORMAT_YVU420:
282 case TBM_FORMAT_YUV420:
283 _tdm_helper_dump_raw(file,
285 info.planes[0].stride * info.height,
287 info.planes[1].stride * (info.height >> 1),
289 info.planes[2].stride * (info.height >> 1));
291 case TBM_FORMAT_NV12:
292 case TBM_FORMAT_NV21:
294 (info.planes[0].ptr + info.planes[0].stride * info.height) != info.planes[1].ptr)
295 TDM_WRN("%p != %p", info.planes[0].ptr + info.planes[0].stride * info.height, info.planes[1].ptr);
297 _tdm_helper_dump_raw(file,
299 info.planes[0].stride * info.height,
301 info.planes[1].stride * (info.height >> 1), NULL,
304 case TBM_FORMAT_YUYV:
305 case TBM_FORMAT_UYVY:
306 _tdm_helper_dump_raw(file,
308 info.planes[0].stride * info.height, NULL, 0,
312 TDM_ERR("can't dump %c%c%c%c buffer", FOURCC_STR(info.format));
313 tbm_surface_unmap(buffer);
317 tbm_surface_unmap(buffer);
319 TDM_INFO("dump %s", file);
323 tdm_helper_clear_buffer_pos(tbm_surface_h buffer, tdm_pos *pos)
325 tbm_surface_info_s info;
328 TDM_RETURN_IF_FAIL(buffer != NULL);
330 ret = tbm_surface_map(buffer, TBM_OPTION_READ, &info);
331 TDM_RETURN_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE);
333 switch (info.format) {
334 case TBM_FORMAT_ARGB8888:
335 case TBM_FORMAT_XRGB8888:
337 memset(info.planes[0].ptr, 0, info.planes[0].stride * info.height);
341 for (y = pos->y; y <= (pos->y + pos->h); y++) {
342 p = info.planes[0].ptr + info.planes[0].stride * y;
343 for (x = pos->x; x <= (pos->x + pos->w); x++) {
345 ibuf[x] = 0x00000000;
350 case TBM_FORMAT_YVU420:
351 case TBM_FORMAT_YUV420:
352 memset((char*)info.planes[0].ptr, 0x10, info.planes[0].stride * info.height);
353 memset((char*)info.planes[1].ptr, 0x80, info.planes[1].stride * (info.height >> 1));
354 memset((char*)info.planes[2].ptr, 0x80, info.planes[2].stride * (info.height >> 1));
356 case TBM_FORMAT_NV12:
357 case TBM_FORMAT_NV21:
358 memset((char*)info.planes[0].ptr, 0x10, info.planes[0].stride * info.height);
359 memset((char*)info.planes[1].ptr, 0x80, info.planes[1].stride * (info.height >> 1));
361 case TBM_FORMAT_YUYV: {
362 int *ibuf = (int*)info.planes[0].ptr;
363 int i, size = info.planes[0].stride * info.height / 4;
365 for (i = 0 ; i < size ; i++)
366 ibuf[i] = 0x10801080;
369 case TBM_FORMAT_UYVY: {
370 int *ibuf = (int*)info.planes[0].ptr;
371 int i, size = info.planes[0].stride * info.height / 4;
373 for (i = 0 ; i < size ; i++)
374 ibuf[i] = 0x80108010; /* YUYV -> 0xVYUY */
378 TDM_ERR("can't clear %c%c%c%c buffer", FOURCC_STR(info.format));
382 tbm_surface_unmap(buffer);
386 tdm_helper_clear_buffer(tbm_surface_h buffer)
388 TDM_RETURN_IF_FAIL(buffer != NULL);
390 tdm_helper_clear_buffer_pos(buffer, NULL);
394 tdm_helper_get_buffer_full_size(tbm_surface_h buffer, int *buffer_w, int *buffer_h)
396 tbm_surface_info_s info;
399 TDM_RETURN_IF_FAIL(buffer != NULL);
401 ret = tbm_surface_get_info(buffer, &info);
402 TDM_RETURN_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE);
405 if (IS_RGB(info.format))
406 *buffer_w = info.planes[0].stride >> 2;
408 *buffer_w = info.planes[0].stride;
412 *buffer_h = info.planes[0].size / info.planes[0].stride;
415 static pixman_format_code_t
416 _tdm_helper_pixman_format_get(tbm_format format)
419 case TBM_FORMAT_ARGB8888:
420 return PIXMAN_a8r8g8b8;
421 case TBM_FORMAT_XRGB8888:
422 return PIXMAN_x8r8g8b8;
431 tdm_helper_convert_buffer(tbm_surface_h srcbuf, tbm_surface_h dstbuf,
432 tdm_pos *srcpos, tdm_pos *dstpos,
433 tdm_transform transform, int over)
435 tbm_surface_info_s src_info, dst_info;
436 pixman_image_t *src_img = NULL, *dst_img = NULL;
437 pixman_format_code_t src_format, dst_format;
438 double scale_x, scale_y;
439 int rotate_step, bos;
440 pixman_transform_t t;
441 struct pixman_f_transform ft;
443 int src_stride, dst_stride;
445 tdm_error ret = TDM_ERROR_OPERATION_FAILED;
447 TDM_RETURN_VAL_IF_FAIL(srcbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
448 TDM_RETURN_VAL_IF_FAIL(dstbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
450 bos = tbm_surface_internal_get_num_bos(srcbuf);
451 TDM_RETURN_VAL_IF_FAIL(bos == 1, TDM_ERROR_OPERATION_FAILED);
453 bos = tbm_surface_internal_get_num_bos(dstbuf);
454 TDM_RETURN_VAL_IF_FAIL(bos == 1, TDM_ERROR_OPERATION_FAILED);
456 err = tbm_surface_map(srcbuf, TBM_OPTION_READ, &src_info);
457 TDM_RETURN_VAL_IF_FAIL(err == TBM_SURFACE_ERROR_NONE, TDM_ERROR_OPERATION_FAILED);
459 err = tbm_surface_map(dstbuf, TBM_OPTION_WRITE, &dst_info);
460 TDM_GOTO_IF_FAIL(err == TBM_SURFACE_ERROR_NONE, unmap_srcbuf);
462 /* not handle buffers which have 2 more gem handles */
463 TDM_GOTO_IF_FAIL(src_info.planes[0].ptr != NULL, unmap_dstbuf);
464 TDM_GOTO_IF_FAIL(dst_info.planes[0].ptr != NULL, unmap_dstbuf);
466 src_format = _tdm_helper_pixman_format_get(src_info.format);
467 TDM_GOTO_IF_FAIL(src_format > 0, unmap_dstbuf);
468 dst_format = _tdm_helper_pixman_format_get(dst_info.format);
469 TDM_GOTO_IF_FAIL(dst_format > 0, unmap_dstbuf);
471 buf_width = src_info.planes[0].stride >> 2;
472 src_stride = src_info.planes[0].stride;
473 src_img = pixman_image_create_bits(src_format, buf_width, src_info.height,
474 (uint32_t*)src_info.planes[0].ptr, src_stride);
475 TDM_GOTO_IF_FAIL(src_img, unref_img);
477 buf_width = dst_info.planes[0].stride >> 2;
478 dst_stride = dst_info.planes[0].stride;
479 dst_img = pixman_image_create_bits(dst_format, buf_width, dst_info.height,
480 (uint32_t*)dst_info.planes[0].ptr, dst_stride);
481 TDM_GOTO_IF_FAIL(dst_img, unref_img);
483 pixman_f_transform_init_identity(&ft);
485 if (transform & TDM_TRANSFORM_FLIPPED) {
486 pixman_f_transform_scale(&ft, NULL, -1, 1);
487 pixman_f_transform_translate(&ft, NULL, dstpos->w, 0);
490 rotate_step = transform & 0x3;
491 if (rotate_step > 0) {
492 int c, s, tx = 0, ty = 0;
493 switch (rotate_step) {
495 c = 0, s = -1, tx = -dstpos->w;
498 c = -1, s = 0, tx = -dstpos->w, ty = -dstpos->h;
501 c = 0, s = 1, ty = -dstpos->h;
504 pixman_f_transform_translate(&ft, NULL, tx, ty);
505 pixman_f_transform_rotate(&ft, NULL, c, s);
508 if (rotate_step % 2 == 0) {
509 scale_x = (double)srcpos->w / dstpos->w;
510 scale_y = (double)srcpos->h / dstpos->h;
512 scale_x = (double)srcpos->w / dstpos->h;
513 scale_y = (double)srcpos->h / dstpos->w;
516 pixman_f_transform_scale(&ft, NULL, scale_x, scale_y);
517 pixman_f_transform_translate(&ft, NULL, srcpos->x, srcpos->y);
518 pixman_transform_from_pixman_f_transform(&t, &ft);
519 pixman_image_set_transform(src_img, &t);
521 op = (!over) ? PIXMAN_OP_SRC : PIXMAN_OP_OVER;
523 pixman_image_composite(op, src_img, NULL, dst_img, 0, 0, 0, 0,
524 dstpos->x, dstpos->y, dstpos->w, dstpos->h);
526 ret = TDM_ERROR_NONE;
530 pixman_image_unref(src_img);
532 pixman_image_unref(dst_img);
534 tbm_surface_unmap(dstbuf);
536 tbm_surface_unmap(srcbuf);
542 tdm_helper_get_fd(const char *env)
545 int fd, newfd, flags, ret;
549 value = (const char*)getenv(env);
553 const long sl = strtol(value, &end, 10);
555 TDM_ERR("%s: not a decimal number\n", value);
557 } else if (*end != '\0') {
558 TDM_ERR("%s: extra characters at end of input: %s\n", value, end);
560 } else if ((sl == LONG_MIN || sl == LONG_MAX) && errno == ERANGE) {
561 TDM_ERR("%s out of range of type long\n", value);
563 } else if (sl > INT_MAX) {
564 TDM_ERR("%ld greater than INT_MAX\n", sl);
566 } else if (sl < INT_MIN) {
567 TDM_ERR("%ld less than INT_MIN\n", sl);
572 TDM_ERR("%d out of fd range\n", fd);
577 flags = fcntl(fd, F_GETFD);
579 TDM_ERR("fcntl failed: %m");
585 TDM_ERR("dup failed: %m");
589 TDM_INFO("%s: fd(%d) newfd(%d)", env, fd, newfd);
591 ret = fcntl(newfd, F_SETFD, flags | FD_CLOEXEC);
593 TDM_ERR("fcntl failed: %m");
602 tdm_helper_set_fd(const char *env, int fd)
607 snprintf(buf, sizeof(buf), "%d", fd);
609 ret = setenv(env, (const char*)buf, 1);
611 TDM_ERR("setenv failed: %m");
616 TDM_INFO("%s: fd(%d)", env, fd);
620 tdm_helper_dump_start(char *dumppath, int *count)
622 if (dumppath == NULL || count == NULL) {
623 TDM_DBG("tdm_helper_dump dumppath or count is null.");
629 TDM_DBG("tdm_helper_dump start.(path : %s)", dumppath);
633 tdm_helper_dump_stop(void)
637 TDM_DBG("tdm_helper_dump stop.");
641 _tdm_helper_buffer_convert(tbm_surface_h srcbuf, tbm_surface_h dstbuf,
642 int dx, int dy, int dw, int dh, int count)
644 pixman_image_t *src_img = NULL, *dst_img = NULL;
645 pixman_format_code_t src_format, dst_format;
646 pixman_transform_t t;
647 struct pixman_f_transform ft;
649 tbm_surface_info_s src_info = {0, };
650 tbm_surface_info_s dst_info = {0, };
652 double scale_x, scale_y;
654 TDM_RETURN_VAL_IF_FAIL(srcbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
655 TDM_RETURN_VAL_IF_FAIL(dstbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
657 if (tbm_surface_map(srcbuf, TBM_SURF_OPTION_READ, &src_info) != TBM_SURFACE_ERROR_NONE) {
658 TDM_ERR("cannot mmap srcbuf\n");
659 return TDM_ERROR_OPERATION_FAILED;
662 if (tbm_surface_map(dstbuf, TBM_SURF_OPTION_WRITE, &dst_info) != TBM_SURFACE_ERROR_NONE) {
663 TDM_ERR("cannot mmap dstbuf\n");
664 tbm_surface_unmap(srcbuf);
665 return TDM_ERROR_OPERATION_FAILED;
667 TDM_GOTO_IF_FAIL(src_info.num_planes == 1, cant_convert);
668 TDM_GOTO_IF_FAIL(dst_info.num_planes == 1, cant_convert);
671 src_format = _tdm_helper_pixman_format_get(src_info.format);
672 TDM_GOTO_IF_FAIL(src_format > 0, cant_convert);
674 width = src_info.planes[0].stride / 4;
675 stride = src_info.planes[0].stride;
676 src_img = pixman_image_create_bits(src_format, width, src_info.height,
677 (uint32_t*)src_info.planes[0].ptr, stride);
678 TDM_GOTO_IF_FAIL(src_img != NULL, cant_convert);
681 dst_format = _tdm_helper_pixman_format_get(dst_info.format);
682 TDM_GOTO_IF_FAIL(dst_format > 0, cant_convert);
684 width = dst_info.planes[0].stride / 4;
685 stride = dst_info.planes[0].stride;
686 dst_img = pixman_image_create_bits(dst_format, width, dst_info.height,
687 (uint32_t*)dst_info.planes[0].ptr, stride);
688 TDM_GOTO_IF_FAIL(dst_img != NULL, cant_convert);
690 pixman_f_transform_init_identity(&ft);
692 scale_x = (double)src_info.width / dw;
693 scale_y = (double)src_info.height / dh;
695 pixman_f_transform_scale(&ft, NULL, scale_x, scale_y);
696 pixman_f_transform_translate(&ft, NULL, 0, 0);
697 pixman_transform_from_pixman_f_transform(&t, &ft);
698 pixman_image_set_transform(src_img, &t);
705 pixman_image_composite(op, src_img, NULL, dst_img,
706 0, 0, 0, 0, dx, dy, dw, dh);
709 pixman_image_unref(src_img);
711 pixman_image_unref(dst_img);
713 tbm_surface_unmap(srcbuf);
714 tbm_surface_unmap(dstbuf);
716 return TDM_ERROR_NONE;
720 pixman_image_unref(src_img);
722 tbm_surface_unmap(srcbuf);
723 tbm_surface_unmap(dstbuf);
725 return TDM_ERROR_OPERATION_FAILED;
729 tdm_helper_capture_output(tdm_output *output, tbm_surface_h dst_buffer,
730 int x, int y, int w, int h,
731 tdm_helper_capture_handler func, void *data)
733 tbm_surface_h surface;
735 int i, count, first = 0;
737 TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
738 TDM_RETURN_VAL_IF_FAIL(dst_buffer != NULL, TDM_ERROR_INVALID_PARAMETER);
739 TDM_RETURN_VAL_IF_FAIL(x >= 0, TDM_ERROR_INVALID_PARAMETER);
740 TDM_RETURN_VAL_IF_FAIL(y >= 0, TDM_ERROR_INVALID_PARAMETER);
741 TDM_RETURN_VAL_IF_FAIL(w >= 0, TDM_ERROR_INVALID_PARAMETER);
742 TDM_RETURN_VAL_IF_FAIL(h >= 0, TDM_ERROR_INVALID_PARAMETER);
743 TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
744 TDM_RETURN_VAL_IF_FAIL(data != NULL, TDM_ERROR_INVALID_PARAMETER);
746 err = tdm_output_get_layer_count(output, &count);
747 if (err != TDM_ERROR_NONE) {
748 TDM_ERR("tdm_output_get_layer_count fail(%d)\n", err);
749 return TDM_ERROR_OPERATION_FAILED;
752 TDM_ERR("tdm_output_get_layer_count err(%d, %d)\n", err, count);
753 return TDM_ERROR_BAD_MODULE;
756 for (i = count - 1; i >= 0; i--) {
757 tdm_layer *layer = tdm_output_get_layer(output, i, NULL);
759 surface = tdm_layer_get_displaying_buffer(layer, &err);
760 if (err != TDM_ERROR_NONE)
763 err = _tdm_helper_buffer_convert(surface, dst_buffer, x, y, w, h, first++);
764 if (err != TDM_ERROR_NONE)
765 TDM_DBG("convert fail %d-layer buffer\n", i);
767 TDM_DBG("convert success %d-layer buffer\n", i);
770 func(dst_buffer, data);
772 return TDM_ERROR_NONE;
776 tdm_helper_get_display_information(tdm_display *dpy, char *reply, int *len)
778 tdm_private_display *private_display;
779 tdm_backend_module *module_data;
780 tdm_func_output *func_output;
781 tdm_func_layer *func_layer;
782 tdm_private_output *private_output = NULL;
783 tdm_private_layer *private_layer = NULL;
784 tdm_private_pp *private_pp = NULL;
785 tdm_private_capture *private_capture = NULL;
789 TDM_DBG_RETURN_IF_FAIL(dpy != NULL);
791 private_display = dpy;
792 func_output = &private_display->func_output;
793 func_layer = &private_display->func_layer;
794 _pthread_mutex_lock(&private_display->lock);
796 /* module information */
797 module_data = private_display->module_data;
798 TDM_SNPRINTF(reply, len, "[TDM backend information]\n");
799 TDM_SNPRINTF(reply, len, "name: %s\n", module_data->name);
800 TDM_SNPRINTF(reply, len, "vendor: %s\n", module_data->vendor);
801 TDM_SNPRINTF(reply, len, "version: %d.%d\n\n",
802 (int)TDM_BACKEND_GET_ABI_MAJOR(module_data->abi_version),
803 (int)TDM_BACKEND_GET_ABI_MINOR(module_data->abi_version));
805 /* output information */
806 TDM_SNPRINTF(reply, len, "[Output information]\n");
807 TDM_SNPRINTF(reply, len, "--------------------------------------------------------------------------------------------\n");
808 TDM_SNPRINTF(reply, len, "idx maker model name type status dpms subpixel align_w min max phy(mm)\n");
809 TDM_SNPRINTF(reply, len, "--------------------------------------------------------------------------------------------\n");
810 LIST_FOR_EACH_ENTRY(private_output, &private_display->output_list, link) {
811 TDM_SNPRINTF(reply, len, "%d %s %s %s %s %s %s %u %d %dx%d %dx%d %ux%u\n",
812 private_output->index, private_output->caps.maker,
813 private_output->caps.model, private_output->caps.name,
814 tdm_conn_str(private_output->caps.type),
815 tdm_status_str(private_output->caps.status),
816 tdm_dpms_str(private_output->current_dpms_value),
817 private_output->caps.subpixel,
818 TDM_FRONT_VALUE(private_output->caps.preferred_align),
819 TDM_FRONT_VALUE(private_output->caps.min_w),
820 TDM_FRONT_VALUE(private_output->caps.min_h),
821 TDM_FRONT_VALUE(private_output->caps.max_w),
822 TDM_FRONT_VALUE(private_output->caps.max_h),
823 private_output->caps.mmWidth, private_output->caps.mmHeight);
825 TDM_SNPRINTF(reply, len, "\t%u modes:\n", private_output->caps.mode_count);
827 if (private_output->caps.mode_count > 0) {
828 const tdm_output_mode *current_mode = NULL;
830 TDM_DBG_GOTO_IF_FAIL(func_output->output_get_mode, unlock);
831 ret = func_output->output_get_mode(private_output->output_backend, ¤t_mode);
832 TDM_DBG_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, unlock);
834 TDM_SNPRINTF(reply, len, "\t\t name refresh (Hz) clk hdisp hss hse htot vdisp vss vse vtot vscan\n");
835 for (i = 0; i < private_output->caps.mode_count; i++) {
836 char *current = (current_mode == private_output->caps.modes + i) ? "*" : " ";
837 TDM_SNPRINTF(reply, len, "\t\t%s%s %u %u %u %u %u %u %u %u %u %u %u ",
839 private_output->caps.modes[i].name,
840 private_output->caps.modes[i].vrefresh,
841 private_output->caps.modes[i].clock,
842 private_output->caps.modes[i].hdisplay,
843 private_output->caps.modes[i].hsync_start,
844 private_output->caps.modes[i].hsync_end,
845 private_output->caps.modes[i].htotal,
846 private_output->caps.modes[i].vdisplay,
847 private_output->caps.modes[i].vsync_start,
848 private_output->caps.modes[i].vsync_end,
849 private_output->caps.modes[i].vtotal,
850 private_output->caps.modes[i].vscan);
851 tdm_mode_flag_str(private_output->caps.modes[i].flags, &reply, len);
852 TDM_SNPRINTF(reply, len, " ");
853 tdm_mode_type_str(private_output->caps.modes[i].type, &reply, len);
854 TDM_SNPRINTF(reply, len, "\n");
858 TDM_SNPRINTF(reply, len, "\t%d properties:\n", private_output->caps.prop_count);
859 if (private_output->caps.prop_count > 0) {
860 TDM_SNPRINTF(reply, len, "\t\tname\tidx\tvalue\n");
861 for (i = 0; i < private_output->caps.prop_count; i++) {
863 TDM_DBG_GOTO_IF_FAIL(func_output->output_get_property, unlock);
864 ret = func_output->output_get_property(private_output->output_backend,
865 private_output->caps.props[i].id,
867 TDM_DBG_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, unlock);
868 TDM_SNPRINTF(reply, len, "\t\t%s\t%u\t%u\n",
869 private_output->caps.props[i].name,
870 private_output->caps.props[i].id,
875 TDM_SNPRINTF(reply, len, "\n");
877 /* layer information */
878 TDM_SNPRINTF(reply, len, "[Layer information]\n");
879 TDM_SNPRINTF(reply, len, "-----------------------------------------------------------------------\n");
880 TDM_SNPRINTF(reply, len, "idx output zpos buf format size crop geometry transform\n");
881 TDM_SNPRINTF(reply, len, "-----------------------------------------------------------------------\n");
882 LIST_FOR_EACH_ENTRY(private_output, &private_display->output_list, link) {
883 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
884 if (!private_layer->usable) {
888 tbm_surface_info_s buf_info;
890 TDM_DBG_GOTO_IF_FAIL(func_layer->layer_get_info, unlock);
891 memset(&info, 0, sizeof info);
892 ret = func_layer->layer_get_info(private_layer->layer_backend, &info);
893 TDM_DBG_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, unlock);
895 if (!private_layer->showing_buffer)
898 format = tbm_surface_get_format(private_layer->showing_buffer->buffer);
899 tbm_surface_get_info(private_layer->showing_buffer->buffer, &buf_info);
902 size.h = buf_info.planes[0].stride >> 2;
904 size.h = buf_info.planes[0].stride;
905 size.v = tbm_surface_get_height(private_layer->showing_buffer->buffer);
907 if (info.src_config.format)
908 format = (info.src_config.format) ? : format;
910 TDM_SNPRINTF(reply, len, "%d %d %d %p %c%c%c%c %ux%u %ux%u+%u+%u %ux%u+%u+%u %s\n",
911 private_layer->index,
912 private_output->index,
913 private_layer->caps.zpos,
914 private_layer->showing_buffer->buffer, FOURCC_STR(format), size.h, size.v,
915 info.src_config.pos.w, info.src_config.pos.h, info.src_config.pos.x, info.src_config.pos.y,
916 info.dst_pos.w, info.dst_pos.h, info.dst_pos.x, info.dst_pos.y,
917 tdm_transform_str(info.transform));
919 TDM_SNPRINTF(reply, len, "%d %d %d -\n",
920 private_layer->index,
921 private_output->index,
922 private_layer->caps.zpos);
925 TDM_SNPRINTF(reply, len, "\tcaps\t: ");
926 tdm_layer_caps_str(private_layer->caps.capabilities, &reply, len);
927 TDM_SNPRINTF(reply, len, "\n");
929 TDM_SNPRINTF(reply, len, "\tformats\t: ");
930 if (private_layer->caps.format_count > 0) {
931 const char *sep = "";
932 for (i = 0; i < private_layer->caps.format_count; i++) {
933 if (private_layer->caps.formats[i] == 0)
935 TDM_SNPRINTF(reply, len, "%s%c%c%c%c", sep, FOURCC_STR(private_layer->caps.formats[i]));
938 TDM_SNPRINTF(reply, len, "\n");
941 TDM_SNPRINTF(reply, len, "\t%u properties:\n", private_layer->caps.prop_count);
942 if (private_layer->caps.prop_count > 0) {
943 TDM_SNPRINTF(reply, len, "\t\tname\tidx\tvalue\n");
944 for (i = 0; i < private_layer->caps.prop_count; i++) {
946 TDM_DBG_GOTO_IF_FAIL(func_layer->layer_get_property, unlock);
947 ret = func_layer->layer_get_property(private_layer->layer_backend,
948 private_layer->caps.props[i].id,
950 TDM_DBG_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, unlock);
951 TDM_SNPRINTF(reply, len, "\t\t%s\t%u\t%u\n",
952 private_layer->caps.props[i].name,
953 private_layer->caps.props[i].id,
959 TDM_SNPRINTF(reply, len, "\n");
961 if (private_display->capabilities & TDM_DISPLAY_CAPABILITY_PP) {
962 const char *sep = "";
963 TDM_SNPRINTF(reply, len, "[PP information]\n");
964 TDM_SNPRINTF(reply, len, "caps\t: ");
965 tdm_pp_caps_str(private_display->caps_pp.capabilities, &reply, len);
966 TDM_SNPRINTF(reply, len, "\n");
967 TDM_SNPRINTF(reply, len, "formats\t: ");
968 for (i = 0; i < private_display->caps_pp.format_count; i++) {
969 if (private_display->caps_pp.formats[i] == 0)
971 TDM_SNPRINTF(reply, len, "%s%c%c%c%c", sep, FOURCC_STR(private_display->caps_pp.formats[i]));
974 TDM_SNPRINTF(reply, len, "\n");
975 TDM_SNPRINTF(reply, len, "size\t: min(%dx%d) max(%dx%d) align_w(%d)\n",
976 TDM_FRONT_VALUE(private_display->caps_pp.min_w),
977 TDM_FRONT_VALUE(private_display->caps_pp.min_h),
978 TDM_FRONT_VALUE(private_display->caps_pp.max_w),
979 TDM_FRONT_VALUE(private_display->caps_pp.max_h),
980 TDM_FRONT_VALUE(private_display->caps_pp.preferred_align));
981 if (!LIST_IS_EMPTY(&private_display->pp_list)) {
982 TDM_SNPRINTF(reply, len, "-------------------------------------------------------------\n");
983 TDM_SNPRINTF(reply, len, "src(format size crop) | dst(format size crop) | transform\n");
984 TDM_SNPRINTF(reply, len, "-------------------------------------------------------------\n");
985 LIST_FOR_EACH_ENTRY(private_pp, &private_display->pp_list, link) {
986 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",
987 FOURCC_STR(private_pp->info.src_config.format),
988 private_pp->info.src_config.size.h,
989 private_pp->info.src_config.size.v,
990 private_pp->info.src_config.pos.x, private_pp->info.src_config.pos.y,
991 private_pp->info.src_config.pos.w, private_pp->info.src_config.pos.h,
992 FOURCC_STR(private_pp->info.dst_config.format),
993 private_pp->info.dst_config.size.h,
994 private_pp->info.dst_config.size.v,
995 private_pp->info.dst_config.pos.x, private_pp->info.dst_config.pos.y,
996 private_pp->info.dst_config.pos.w, private_pp->info.dst_config.pos.h,
997 tdm_transform_str(private_pp->info.transform));
1001 TDM_SNPRINTF(reply, len, "[No PP capability]\n");
1003 TDM_SNPRINTF(reply, len, "\n");
1005 if (private_display->capabilities & TDM_DISPLAY_CAPABILITY_CAPTURE) {
1006 const char *sep = "";
1007 TDM_SNPRINTF(reply, len, "[Capture information]\n");
1008 TDM_SNPRINTF(reply, len, "caps\t: ");
1009 tdm_capture_caps_str(private_display->caps_capture.capabilities, &reply, len);
1010 TDM_SNPRINTF(reply, len, "\n");
1011 TDM_SNPRINTF(reply, len, "formats\t: ");
1012 for (i = 0; i < private_display->caps_capture.format_count; i++) {
1013 if (private_display->caps_capture.formats[i] == 0)
1015 TDM_SNPRINTF(reply, len, "%s%c%c%c%c", sep, FOURCC_STR(private_display->caps_capture.formats[i]));
1018 TDM_SNPRINTF(reply, len, "\n");
1019 TDM_SNPRINTF(reply, len, "size\t: min(%dx%d) max(%dx%d) align_w(%d)\n",
1020 TDM_FRONT_VALUE(private_display->caps_capture.min_w),
1021 TDM_FRONT_VALUE(private_display->caps_capture.min_h),
1022 TDM_FRONT_VALUE(private_display->caps_capture.max_w),
1023 TDM_FRONT_VALUE(private_display->caps_capture.max_h),
1024 TDM_FRONT_VALUE(private_display->caps_capture.preferred_align));
1025 if (!LIST_IS_EMPTY(&private_display->capture_list)) {
1026 TDM_SNPRINTF(reply, len, "-----------------------------------\n");
1027 TDM_SNPRINTF(reply, len, "dst(format size crop) | transform\n");
1028 TDM_SNPRINTF(reply, len, "-----------------------------------\n");
1029 LIST_FOR_EACH_ENTRY(private_capture, &private_display->capture_list, link) {
1030 TDM_SNPRINTF(reply, len, "%c%c%c%c %ux%u %ux%u+%u+%u | %s\n",
1031 FOURCC_STR(private_capture->info.dst_config.format),
1032 private_capture->info.dst_config.size.h,
1033 private_capture->info.dst_config.size.v,
1034 private_capture->info.dst_config.pos.x, private_capture->info.dst_config.pos.y,
1035 private_capture->info.dst_config.pos.w, private_capture->info.dst_config.pos.h,
1036 tdm_transform_str(private_capture->info.transform));
1040 TDM_SNPRINTF(reply, len, "[No Capture capability]\n");
1042 TDM_SNPRINTF(reply, len, "\n");
1045 _pthread_mutex_unlock(&private_display->lock);
1049 tdm_helper_commit_per_vblank_enabled(tdm_display *dpy)
1051 tdm_private_display *private_display;
1053 TDM_RETURN_VAL_IF_FAIL(dpy != NULL, 0);
1055 private_display = dpy;
1057 return private_display->commit_per_vblank;