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>
50 #include "tdm_private.h"
51 #include "tdm_helper.h"
55 static const char *file_exts[2] = {"png", "yuv"};
58 char *tdm_debug_dump_dir;
61 tdm_helper_get_time(void)
65 if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
66 return (double)tp.tv_sec + ((double)tp.tv_nsec) / 1000000000.0;
72 _tdm_helper_check_file_is_valid(const char* path, int del_link)
79 real_path = realpath(path, NULL);
80 if (real_path && strncmp(path, real_path, strlen(path))) {
95 _tdm_helper_dump_raw(const char *file, void *data1, int size1, void *data2,
96 int size2, void *data3, int size3)
101 if (!_tdm_helper_check_file_is_valid(file, 1))
102 TDM_WRN("'%s' may be symbolic link\n", file);
104 fp = fopen(file, "w+");
105 TDM_RETURN_IF_FAIL(fp != NULL);
107 blocks = (unsigned int *)data1;
108 fwrite(blocks, 1, size1, fp);
111 blocks = (unsigned int *)data2;
112 fwrite(blocks, 1, size2, fp);
116 blocks = (unsigned int *)data3;
117 fwrite(blocks, 1, size3, fp);
124 _tdm_helper_dump_png(const char *file, const void *data, int width,
129 if (!_tdm_helper_check_file_is_valid(file, 1))
130 TDM_WRN("'%s' may be symbolic link\n", file);
132 fp = fopen(file, "wb");
133 TDM_RETURN_IF_FAIL(fp != NULL);
135 png_structp pPngStruct =
136 png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
142 png_infop pPngInfo = png_create_info_struct(pPngStruct);
144 png_destroy_write_struct(&pPngStruct, NULL);
149 png_init_io(pPngStruct, fp);
150 png_set_IHDR(pPngStruct,
157 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
159 png_set_bgr(pPngStruct);
160 png_write_info(pPngStruct, pPngInfo);
162 const int pixel_size = 4; // RGBA
163 png_bytep *row_pointers =
164 png_malloc(pPngStruct, height * sizeof(png_byte *));
166 png_destroy_write_struct(&pPngStruct, &pPngInfo);
171 unsigned int *blocks = (unsigned int *)data;
175 for (; y < height; ++y) {
177 png_malloc(pPngStruct, sizeof(png_byte) * width * pixel_size);
179 for (x = 0; x < y; x++)
180 png_free(pPngStruct, row_pointers[x]);
181 png_free(pPngStruct, row_pointers);
182 png_destroy_write_struct(&pPngStruct, &pPngInfo);
187 row_pointers[y] = (png_bytep)row;
188 for (x = 0; x < width; ++x) {
189 unsigned int curBlock = blocks[y * width + x];
190 row[x * pixel_size] = (curBlock & 0xFF);
191 row[1 + x * pixel_size] = (curBlock >> 8) & 0xFF;
192 row[2 + x * pixel_size] = (curBlock >> 16) & 0xFF;
193 row[3 + x * pixel_size] = (curBlock >> 24) & 0xFF;
197 png_write_image(pPngStruct, row_pointers);
198 png_write_end(pPngStruct, pPngInfo);
200 for (y = 0; y < height; y++)
201 png_free(pPngStruct, row_pointers[y]);
202 png_free(pPngStruct, row_pointers);
204 png_destroy_write_struct(&pPngStruct, &pPngInfo);
210 tdm_helper_dump_make_directory(const char *path, char *reply, int *len)
212 char *fullpath = NULL;
214 struct tm *t, *buf = NULL;
218 buf = calloc(1, sizeof(struct tm));
219 TDM_GOTO_IF_FAIL(buf != NULL, failed_make);
221 fullpath = calloc(1, TDM_PATH_LEN * sizeof(char));
222 TDM_GOTO_IF_FAIL(fullpath != NULL, failed_make);
224 t = localtime_r(&timer, buf);
225 TDM_GOTO_IF_FAIL(t != NULL, failed_make);
227 snprintf(fullpath, TDM_PATH_LEN, "%s/dump_%04d%02d%02d.%02d%02d%02d", path,
228 t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
230 if ((mkdir(fullpath, 0755)) < 0) {
231 TDM_ERR("mkdir '%s' fail\n", fullpath);
232 TDM_SNPRINTF(reply, len, "mkdir '%s' fail\n", fullpath);
248 tdm_helper_dump_buffer_str(tbm_surface_h buffer, char *dir, char *str)
250 tbm_surface_info_s info;
252 char file[TDM_PATH_LEN];
255 TDM_RETURN_IF_FAIL(buffer != NULL);
256 TDM_RETURN_IF_FAIL(dir != NULL);
257 TDM_RETURN_IF_FAIL(str != NULL);
259 ret = tbm_surface_get_info(buffer, &info);
260 TDM_RETURN_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE);
262 if (IS_RGB(info.format))
267 tdm_helper_get_buffer_full_size(buffer, &bw, &bh);
269 snprintf(file, TDM_PATH_LEN, "%s/%c%c%c%c_%dx%d_%dx%d_%s.%s",
270 dir, FOURCC_STR(info.format), bw, bh, info.width, info.height, str, ext);
272 tdm_helper_dump_buffer(buffer, file);
276 tdm_helper_dump_buffer(tbm_surface_h buffer, const char *file)
278 tbm_surface_info_s info;
284 TDM_RETURN_IF_FAIL(buffer != NULL);
285 TDM_RETURN_IF_FAIL(file != NULL);
287 ret = tbm_surface_map(buffer, TBM_OPTION_READ, &info);
288 TDM_RETURN_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE);
290 len = strnlen(file, 1024);
291 if (IS_RGB(info.format))
296 if (strncmp(file + (len - 3), ext, 3)) {
297 TDM_ERR("can't dump to '%s' file", file + (len - 3));
298 tbm_surface_unmap(buffer);
302 tdm_helper_get_buffer_full_size(buffer, &bw, &bh);
304 bo_cnt = tbm_surface_internal_get_num_bos(buffer);
305 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)",
306 bo_cnt, bw, bh, info.width, info.height, FOURCC_STR(info.format),
307 info.planes[0].ptr, info.planes[0].offset, info.planes[0].stride, info.planes[0].size,
308 info.planes[1].ptr, info.planes[1].offset, info.planes[1].stride, info.planes[1].size,
309 info.planes[2].ptr, info.planes[2].offset, info.planes[2].stride, info.planes[2].size);
311 switch (info.format) {
312 case TBM_FORMAT_ARGB8888:
313 case TBM_FORMAT_XRGB8888:
314 _tdm_helper_dump_png(file, info.planes[0].ptr, bw, bh);
316 case TBM_FORMAT_YVU420:
317 case TBM_FORMAT_YUV420:
318 _tdm_helper_dump_raw(file,
324 info.planes[2].size);
326 case TBM_FORMAT_NV12:
327 case TBM_FORMAT_NV21:
328 _tdm_helper_dump_raw(file,
332 info.planes[1].size, NULL,
335 case TBM_FORMAT_YUYV:
336 case TBM_FORMAT_UYVY:
337 _tdm_helper_dump_raw(file,
339 info.planes[0].size, NULL, 0,
343 TDM_ERR("can't dump %c%c%c%c buffer", FOURCC_STR(info.format));
344 tbm_surface_unmap(buffer);
348 tbm_surface_unmap(buffer);
350 TDM_INFO("dump %s", file);
354 tdm_helper_clear_buffer_color(tbm_surface_h buffer, tdm_pos *pos, unsigned int color)
356 tbm_surface_info_s info;
359 TDM_RETURN_IF_FAIL(buffer != NULL);
361 ret = tbm_surface_map(buffer, TBM_OPTION_READ, &info);
362 TDM_RETURN_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE);
364 switch (info.format) {
365 case TBM_FORMAT_ARGB8888:
366 case TBM_FORMAT_XRGB8888:
368 memset(info.planes[0].ptr, 0, info.planes[0].stride * info.height);
372 for (y = pos->y; y <= (pos->y + pos->h); y++) {
373 p = info.planes[0].ptr + info.planes[0].stride * y;
374 for (x = pos->x; x <= (pos->x + pos->w); x++) {
375 unsigned int *ibuf = (unsigned int*)p;
381 case TBM_FORMAT_YVU420:
382 case TBM_FORMAT_YUV420:
383 memset((char*)info.planes[0].ptr, 0x10, info.planes[0].stride * info.height);
384 memset((char*)info.planes[1].ptr, 0x80, info.planes[1].stride * (info.height >> 1));
385 memset((char*)info.planes[2].ptr, 0x80, info.planes[2].stride * (info.height >> 1));
387 case TBM_FORMAT_NV12:
388 case TBM_FORMAT_NV21:
389 memset((char*)info.planes[0].ptr, 0x10, info.planes[0].stride * info.height);
390 memset((char*)info.planes[1].ptr, 0x80, info.planes[1].stride * (info.height >> 1));
392 case TBM_FORMAT_YUYV: {
393 int *ibuf = (int*)info.planes[0].ptr;
394 int i, size = info.planes[0].stride * info.height / 4;
396 for (i = 0 ; i < size ; i++)
397 ibuf[i] = 0x10801080;
400 case TBM_FORMAT_UYVY: {
401 int *ibuf = (int*)info.planes[0].ptr;
402 int i, size = info.planes[0].stride * info.height / 4;
404 for (i = 0 ; i < size ; i++)
405 ibuf[i] = 0x80108010; /* YUYV -> 0xVYUY */
409 TDM_ERR("can't clear %c%c%c%c buffer", FOURCC_STR(info.format));
413 tbm_surface_unmap(buffer);
417 tdm_helper_clear_buffer_pos(tbm_surface_h buffer, tdm_pos *pos)
419 TDM_RETURN_IF_FAIL(buffer != NULL);
421 tdm_helper_clear_buffer_color(buffer, pos, 0);
425 tdm_helper_clear_buffer(tbm_surface_h buffer)
427 TDM_RETURN_IF_FAIL(buffer != NULL);
429 tdm_helper_clear_buffer_pos(buffer, NULL);
433 tdm_helper_get_buffer_full_size(tbm_surface_h buffer, int *buffer_w, int *buffer_h)
435 tbm_surface_info_s info;
438 TDM_RETURN_IF_FAIL(buffer != NULL);
440 ret = tbm_surface_get_info(buffer, &info);
441 TDM_RETURN_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE);
444 if (IS_RGB(info.format))
445 *buffer_w = info.planes[0].stride >> 2;
447 *buffer_w = info.planes[0].stride;
451 *buffer_h = info.planes[0].size / info.planes[0].stride;
454 static pixman_format_code_t
455 _tdm_helper_pixman_format_get(tbm_format format)
458 case TBM_FORMAT_ARGB8888:
459 return PIXMAN_a8r8g8b8;
460 case TBM_FORMAT_XRGB8888:
461 return PIXMAN_x8r8g8b8;
470 tdm_helper_convert_buffer(tbm_surface_h srcbuf, tbm_surface_h dstbuf,
471 tdm_pos *srcpos, tdm_pos *dstpos,
472 tdm_transform transform, int over)
474 tbm_surface_info_s src_info, dst_info;
475 pixman_image_t *src_img = NULL, *dst_img = NULL;
476 pixman_format_code_t src_format, dst_format;
477 double scale_x, scale_y;
478 int rotate_step, bos;
479 pixman_transform_t t;
480 struct pixman_f_transform ft;
482 int src_stride, dst_stride;
484 tdm_error ret = TDM_ERROR_OPERATION_FAILED;
486 TDM_RETURN_VAL_IF_FAIL(srcbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
487 TDM_RETURN_VAL_IF_FAIL(dstbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
489 bos = tbm_surface_internal_get_num_bos(srcbuf);
490 TDM_RETURN_VAL_IF_FAIL(bos == 1, TDM_ERROR_OPERATION_FAILED);
492 bos = tbm_surface_internal_get_num_bos(dstbuf);
493 TDM_RETURN_VAL_IF_FAIL(bos == 1, TDM_ERROR_OPERATION_FAILED);
495 err = tbm_surface_map(srcbuf, TBM_OPTION_READ, &src_info);
496 TDM_RETURN_VAL_IF_FAIL(err == TBM_SURFACE_ERROR_NONE, TDM_ERROR_OPERATION_FAILED);
498 err = tbm_surface_map(dstbuf, TBM_OPTION_WRITE, &dst_info);
499 TDM_GOTO_IF_FAIL(err == TBM_SURFACE_ERROR_NONE, unmap_srcbuf);
501 /* not handle buffers which have 2 more gem handles */
502 TDM_GOTO_IF_FAIL(src_info.planes[0].ptr != NULL, unmap_dstbuf);
503 TDM_GOTO_IF_FAIL(dst_info.planes[0].ptr != NULL, unmap_dstbuf);
505 src_format = _tdm_helper_pixman_format_get(src_info.format);
506 TDM_GOTO_IF_FAIL(src_format > 0, unmap_dstbuf);
507 dst_format = _tdm_helper_pixman_format_get(dst_info.format);
508 TDM_GOTO_IF_FAIL(dst_format > 0, unmap_dstbuf);
510 buf_width = src_info.planes[0].stride >> 2;
511 src_stride = src_info.planes[0].stride;
512 src_img = pixman_image_create_bits(src_format, buf_width, src_info.height,
513 (uint32_t*)src_info.planes[0].ptr, src_stride);
514 TDM_GOTO_IF_FAIL(src_img, unref_img);
516 buf_width = dst_info.planes[0].stride >> 2;
517 dst_stride = dst_info.planes[0].stride;
518 dst_img = pixman_image_create_bits(dst_format, buf_width, dst_info.height,
519 (uint32_t*)dst_info.planes[0].ptr, dst_stride);
520 TDM_GOTO_IF_FAIL(dst_img, unref_img);
522 pixman_f_transform_init_identity(&ft);
524 if (transform & TDM_TRANSFORM_FLIPPED) {
525 pixman_f_transform_scale(&ft, NULL, -1, 1);
526 pixman_f_transform_translate(&ft, NULL, dstpos->w, 0);
529 rotate_step = transform & 0x3;
530 if (rotate_step > 0) {
531 int c, s, tx = 0, ty = 0;
532 switch (rotate_step) {
534 c = 0, s = -1, tx = -dstpos->w;
537 c = -1, s = 0, tx = -dstpos->w, ty = -dstpos->h;
540 c = 0, s = 1, ty = -dstpos->h;
543 pixman_f_transform_translate(&ft, NULL, tx, ty);
544 pixman_f_transform_rotate(&ft, NULL, c, s);
547 if (rotate_step % 2 == 0) {
548 scale_x = (double)srcpos->w / dstpos->w;
549 scale_y = (double)srcpos->h / dstpos->h;
551 scale_x = (double)srcpos->w / dstpos->h;
552 scale_y = (double)srcpos->h / dstpos->w;
555 pixman_f_transform_scale(&ft, NULL, scale_x, scale_y);
556 pixman_f_transform_translate(&ft, NULL, srcpos->x, srcpos->y);
557 pixman_transform_from_pixman_f_transform(&t, &ft);
558 pixman_image_set_transform(src_img, &t);
560 op = (!over) ? PIXMAN_OP_SRC : PIXMAN_OP_OVER;
562 pixman_image_composite(op, src_img, NULL, dst_img, 0, 0, 0, 0,
563 dstpos->x, dstpos->y, dstpos->w, dstpos->h);
565 ret = TDM_ERROR_NONE;
569 pixman_image_unref(src_img);
571 pixman_image_unref(dst_img);
573 tbm_surface_unmap(dstbuf);
575 tbm_surface_unmap(srcbuf);
581 tdm_helper_get_fd(const char *env)
584 int fd, newfd, flags, ret;
588 value = (const char*)getenv(env);
592 const long int sl = strtol(value, &end, 10);
594 TDM_ERR("%s: not a decimal number\n", value);
596 } else if (*end != '\0') {
597 TDM_ERR("%s: extra characters at end of input: %s\n", value, end);
599 } else if ((sl == LONG_MIN || sl == LONG_MAX) && errno == ERANGE) {
600 TDM_ERR("%s out of range of type long\n", value);
602 } else if (sl >= INT_MAX) {
603 TDM_ERR("%ld greater than INT_MAX\n", sl);
605 } else if (sl <= INT_MIN) {
606 TDM_ERR("%ld less than INT_MIN\n", sl);
611 TDM_ERR("%d out of fd range\n", fd);
616 flags = fcntl(fd, F_GETFD);
618 TDM_ERR("fcntl failed: %m");
624 TDM_ERR("dup failed: %m");
628 TDM_INFO("%s: fd(%d) newfd(%d)", env, fd, newfd);
630 ret = fcntl(newfd, F_SETFD, flags | FD_CLOEXEC);
632 TDM_ERR("fcntl failed: %m");
641 tdm_helper_set_fd(const char *env, int fd)
646 snprintf(buf, sizeof(buf), "%d", fd);
648 ret = setenv(env, (const char*)buf, 1);
650 TDM_ERR("setenv failed: %m");
655 TDM_INFO("%s: fd(%d)", env, fd);
659 tdm_helper_dump_start(char *dumppath, int *count)
661 if (dumppath == NULL || count == NULL) {
662 TDM_DBG("tdm_helper_dump dumppath or count is null.");
668 TDM_DBG("tdm_helper_dump start.(path : %s)", dumppath);
672 tdm_helper_dump_stop(void)
676 TDM_DBG("tdm_helper_dump stop.");
680 _tdm_helper_buffer_convert(tbm_surface_h srcbuf, tbm_surface_h dstbuf,
681 int dx, int dy, int dw, int dh, int count)
683 pixman_image_t *src_img = NULL, *dst_img = NULL;
684 pixman_format_code_t src_format, dst_format;
685 pixman_transform_t t;
686 struct pixman_f_transform ft;
688 tbm_surface_info_s src_info = {0, };
689 tbm_surface_info_s dst_info = {0, };
691 double scale_x, scale_y;
693 TDM_RETURN_VAL_IF_FAIL(srcbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
694 TDM_RETURN_VAL_IF_FAIL(dstbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
696 if (tbm_surface_map(srcbuf, TBM_SURF_OPTION_READ, &src_info) != TBM_SURFACE_ERROR_NONE) {
697 TDM_ERR("cannot mmap srcbuf\n");
698 return TDM_ERROR_OPERATION_FAILED;
701 if (tbm_surface_map(dstbuf, TBM_SURF_OPTION_WRITE, &dst_info) != TBM_SURFACE_ERROR_NONE) {
702 TDM_ERR("cannot mmap dstbuf\n");
703 tbm_surface_unmap(srcbuf);
704 return TDM_ERROR_OPERATION_FAILED;
706 TDM_GOTO_IF_FAIL(src_info.num_planes == 1, cant_convert);
707 TDM_GOTO_IF_FAIL(dst_info.num_planes == 1, cant_convert);
710 src_format = _tdm_helper_pixman_format_get(src_info.format);
711 TDM_GOTO_IF_FAIL(src_format > 0, cant_convert);
713 width = src_info.planes[0].stride / 4;
714 stride = src_info.planes[0].stride;
715 src_img = pixman_image_create_bits(src_format, width, src_info.height,
716 (uint32_t*)src_info.planes[0].ptr, stride);
717 TDM_GOTO_IF_FAIL(src_img != NULL, cant_convert);
720 dst_format = _tdm_helper_pixman_format_get(dst_info.format);
721 TDM_GOTO_IF_FAIL(dst_format > 0, cant_convert);
723 width = dst_info.planes[0].stride / 4;
724 stride = dst_info.planes[0].stride;
725 dst_img = pixman_image_create_bits(dst_format, width, dst_info.height,
726 (uint32_t*)dst_info.planes[0].ptr, stride);
727 TDM_GOTO_IF_FAIL(dst_img != NULL, cant_convert);
729 pixman_f_transform_init_identity(&ft);
731 scale_x = (double)src_info.width / dw;
732 scale_y = (double)src_info.height / dh;
734 pixman_f_transform_scale(&ft, NULL, scale_x, scale_y);
735 pixman_f_transform_translate(&ft, NULL, 0, 0);
736 pixman_transform_from_pixman_f_transform(&t, &ft);
737 pixman_image_set_transform(src_img, &t);
744 pixman_image_composite(op, src_img, NULL, dst_img,
745 0, 0, 0, 0, dx, dy, dw, dh);
748 pixman_image_unref(src_img);
750 pixman_image_unref(dst_img);
752 tbm_surface_unmap(srcbuf);
753 tbm_surface_unmap(dstbuf);
755 return TDM_ERROR_NONE;
759 pixman_image_unref(src_img);
761 tbm_surface_unmap(srcbuf);
762 tbm_surface_unmap(dstbuf);
764 return TDM_ERROR_OPERATION_FAILED;
768 tdm_helper_capture_output(tdm_output *output, tbm_surface_h dst_buffer,
769 int x, int y, int w, int h,
770 tdm_helper_capture_handler func, void *data)
772 tbm_surface_h surface;
774 int i, count, first = 0;
776 TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
777 TDM_RETURN_VAL_IF_FAIL(dst_buffer != NULL, TDM_ERROR_INVALID_PARAMETER);
778 TDM_RETURN_VAL_IF_FAIL(x >= 0, TDM_ERROR_INVALID_PARAMETER);
779 TDM_RETURN_VAL_IF_FAIL(y >= 0, TDM_ERROR_INVALID_PARAMETER);
780 TDM_RETURN_VAL_IF_FAIL(w >= 0, TDM_ERROR_INVALID_PARAMETER);
781 TDM_RETURN_VAL_IF_FAIL(h >= 0, TDM_ERROR_INVALID_PARAMETER);
782 TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
783 TDM_RETURN_VAL_IF_FAIL(data != NULL, TDM_ERROR_INVALID_PARAMETER);
785 err = tdm_output_get_layer_count(output, &count);
786 if (err != TDM_ERROR_NONE) {
787 TDM_ERR("tdm_output_get_layer_count fail(%d)\n", err);
788 return TDM_ERROR_OPERATION_FAILED;
791 TDM_ERR("tdm_output_get_layer_count err(%d, %d)\n", err, count);
792 return TDM_ERROR_BAD_MODULE;
795 for (i = count - 1; i >= 0; i--) {
796 tdm_layer *layer = tdm_output_get_layer(output, i, NULL);
798 surface = tdm_layer_get_displaying_buffer(layer, &err);
799 if (err != TDM_ERROR_NONE)
802 err = _tdm_helper_buffer_convert(surface, dst_buffer, x, y, w, h, first++);
803 if (err != TDM_ERROR_NONE)
804 TDM_DBG("convert fail %d-layer buffer\n", i);
806 TDM_DBG("convert success %d-layer buffer\n", i);
809 func(dst_buffer, data);
811 return TDM_ERROR_NONE;
815 tdm_helper_get_display_information(tdm_display *dpy, char *reply, int *len)
817 tdm_private_display *private_display;
818 tdm_backend_module *module_data;
819 tdm_func_output *func_output;
820 tdm_func_layer *func_layer;
821 tdm_private_output *private_output = NULL;
822 tdm_private_layer *private_layer = NULL;
823 tdm_private_pp *private_pp = NULL;
824 tdm_private_capture *private_capture = NULL;
828 TDM_DBG_RETURN_IF_FAIL(dpy != NULL);
830 private_display = dpy;
831 func_output = &private_display->func_output;
832 func_layer = &private_display->func_layer;
834 /* module information */
835 module_data = private_display->module_data;
836 TDM_SNPRINTF(reply, len, "[TDM backend information]\n");
837 TDM_SNPRINTF(reply, len, "name: %s\n", module_data->name);
838 TDM_SNPRINTF(reply, len, "vendor: %s\n", module_data->vendor);
839 TDM_SNPRINTF(reply, len, "version: %d.%d\n\n",
840 (int)TDM_BACKEND_GET_ABI_MAJOR(module_data->abi_version),
841 (int)TDM_BACKEND_GET_ABI_MINOR(module_data->abi_version));
843 /* output information */
844 TDM_SNPRINTF(reply, len, "[Output information]\n");
845 TDM_SNPRINTF(reply, len, "--------------------------------------------------------------------------------------------\n");
846 TDM_SNPRINTF(reply, len, "idx maker model name type status dpms subpixel align_w min max phy(mm)\n");
847 TDM_SNPRINTF(reply, len, "--------------------------------------------------------------------------------------------\n");
848 LIST_FOR_EACH_ENTRY(private_output, &private_display->output_list, link) {
849 TDM_SNPRINTF(reply, len, "%d %s %s %s %s %s %s %u %d %dx%d %dx%d %ux%u\n",
850 private_output->index, private_output->caps.maker,
851 private_output->caps.model, private_output->caps.name,
852 tdm_conn_str(private_output->caps.type),
853 tdm_status_str(private_output->caps.status),
854 tdm_dpms_str(private_output->current_dpms_value),
855 private_output->caps.subpixel,
856 TDM_FRONT_VALUE(private_output->caps.preferred_align),
857 TDM_FRONT_VALUE(private_output->caps.min_w),
858 TDM_FRONT_VALUE(private_output->caps.min_h),
859 TDM_FRONT_VALUE(private_output->caps.max_w),
860 TDM_FRONT_VALUE(private_output->caps.max_h),
861 private_output->caps.mmWidth, private_output->caps.mmHeight);
863 TDM_SNPRINTF(reply, len, "\t%u modes:\n", private_output->caps.mode_count);
865 if (private_output->caps.mode_count > 0) {
866 const tdm_output_mode *current_mode = NULL;
868 TDM_DBG_RETURN_IF_FAIL(func_output->output_get_mode);
869 ret = func_output->output_get_mode(private_output->output_backend, ¤t_mode);
870 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
872 TDM_SNPRINTF(reply, len, "\t\t name refresh (Hz) clk hdisp hss hse htot vdisp vss vse vtot vscan\n");
873 for (i = 0; i < private_output->caps.mode_count; i++) {
874 char *current = (current_mode == private_output->caps.modes + i) ? "*" : " ";
875 TDM_SNPRINTF(reply, len, "\t\t%s%s %u %u %u %u %u %u %u %u %u %u %u ",
877 private_output->caps.modes[i].name,
878 private_output->caps.modes[i].vrefresh,
879 private_output->caps.modes[i].clock,
880 private_output->caps.modes[i].hdisplay,
881 private_output->caps.modes[i].hsync_start,
882 private_output->caps.modes[i].hsync_end,
883 private_output->caps.modes[i].htotal,
884 private_output->caps.modes[i].vdisplay,
885 private_output->caps.modes[i].vsync_start,
886 private_output->caps.modes[i].vsync_end,
887 private_output->caps.modes[i].vtotal,
888 private_output->caps.modes[i].vscan);
889 tdm_mode_flag_str(private_output->caps.modes[i].flags, &reply, len);
890 TDM_SNPRINTF(reply, len, " ");
891 tdm_mode_type_str(private_output->caps.modes[i].type, &reply, len);
892 TDM_SNPRINTF(reply, len, "\n");
896 TDM_SNPRINTF(reply, len, "\t%d properties:\n", private_output->caps.prop_count);
897 if (private_output->caps.prop_count > 0) {
898 TDM_SNPRINTF(reply, len, "\t\tname\ttype\tidx\tvalue\n");
899 for (i = 0; i < private_output->caps.prop_count; i++) {
901 TDM_DBG_RETURN_IF_FAIL(func_output->output_get_property);
902 ret = func_output->output_get_property(private_output->output_backend,
903 private_output->caps.props[i].id,
905 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
906 TDM_SNPRINTF(reply, len, "\t\t%s\t%s\t%u\t",
907 private_output->caps.props[i].name,
908 tdm_value_type_str(private_output->caps.props[i].type),
909 private_output->caps.props[i].id);
910 switch (private_output->caps.props[i].type) {
911 case TDM_VALUE_TYPE_PTR:
912 TDM_SNPRINTF(reply, len, "%p\n", value.ptr);
914 case TDM_VALUE_TYPE_INT32:
915 TDM_SNPRINTF(reply, len, "%d\n", value.s32);
917 case TDM_VALUE_TYPE_INT64:
918 TDM_SNPRINTF(reply, len, "%"PRId64"\n", value.s64);
920 case TDM_VALUE_TYPE_UINT64:
921 TDM_SNPRINTF(reply, len, "%"PRIu64"\n", value.u64);
923 case TDM_VALUE_TYPE_UINT32:
925 TDM_SNPRINTF(reply, len, "%u\n", value.u32);
931 TDM_SNPRINTF(reply, len, "\n");
933 /* layer information */
934 TDM_SNPRINTF(reply, len, "[Layer information]\n");
935 TDM_SNPRINTF(reply, len, "-----------------------------------------------------------------------\n");
936 TDM_SNPRINTF(reply, len, "idx output zpos buf format size crop geometry transform\n");
937 TDM_SNPRINTF(reply, len, "-----------------------------------------------------------------------\n");
938 LIST_FOR_EACH_ENTRY(private_output, &private_display->output_list, link) {
939 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
940 if (!private_layer->usable) {
944 tbm_surface_info_s buf_info;
946 TDM_DBG_RETURN_IF_FAIL(func_layer->layer_get_info);
947 memset(&info, 0, sizeof info);
948 ret = func_layer->layer_get_info(private_layer->layer_backend, &info);
949 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
951 if (!private_layer->showing_buffer)
954 format = tbm_surface_get_format(private_layer->showing_buffer->buffer);
955 tbm_surface_get_info(private_layer->showing_buffer->buffer, &buf_info);
958 size.h = buf_info.planes[0].stride >> 2;
960 size.h = buf_info.planes[0].stride;
961 size.v = tbm_surface_get_height(private_layer->showing_buffer->buffer);
963 if (info.src_config.format)
964 format = (info.src_config.format) ? : format;
966 TDM_SNPRINTF(reply, len, "%d %d %d %p %c%c%c%c %ux%u %ux%u+%u+%u %ux%u+%u+%u %s\n",
967 private_layer->index,
968 private_output->index,
969 private_layer->caps.zpos,
970 private_layer->showing_buffer->buffer, FOURCC_STR(format), size.h, size.v,
971 info.src_config.pos.w, info.src_config.pos.h, info.src_config.pos.x, info.src_config.pos.y,
972 info.dst_pos.w, info.dst_pos.h, info.dst_pos.x, info.dst_pos.y,
973 tdm_transform_str(info.transform));
975 TDM_SNPRINTF(reply, len, "%d %d %d -\n",
976 private_layer->index,
977 private_output->index,
978 private_layer->caps.zpos);
981 TDM_SNPRINTF(reply, len, "\tcaps\t: ");
982 tdm_layer_caps_str(private_layer->caps.capabilities, &reply, len);
983 TDM_SNPRINTF(reply, len, "\n");
985 TDM_SNPRINTF(reply, len, "\tformats\t: ");
986 if (private_layer->caps.format_count > 0) {
987 const char *sep = "";
988 for (i = 0; i < private_layer->caps.format_count; i++) {
989 if (private_layer->caps.formats[i] == 0)
991 TDM_SNPRINTF(reply, len, "%s%c%c%c%c", sep, FOURCC_STR(private_layer->caps.formats[i]));
994 TDM_SNPRINTF(reply, len, "\n");
997 TDM_SNPRINTF(reply, len, "\t%u properties:\n", private_layer->caps.prop_count);
998 if (private_layer->caps.prop_count > 0) {
999 TDM_SNPRINTF(reply, len, "\t\tname\ttype\tidx\tvalue\n");
1000 for (i = 0; i < private_layer->caps.prop_count; i++) {
1002 TDM_DBG_RETURN_IF_FAIL(func_layer->layer_get_property);
1003 ret = func_layer->layer_get_property(private_layer->layer_backend,
1004 private_layer->caps.props[i].id,
1006 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
1007 TDM_SNPRINTF(reply, len, "\t\t%s\t%s\t%u\t",
1008 private_layer->caps.props[i].name,
1009 tdm_value_type_str(private_output->caps.props[i].type),
1010 private_layer->caps.props[i].id);
1011 switch (private_layer->caps.props[i].type) {
1012 case TDM_VALUE_TYPE_PTR:
1013 TDM_SNPRINTF(reply, len, "%p\n", value.ptr);
1015 case TDM_VALUE_TYPE_INT32:
1016 TDM_SNPRINTF(reply, len, "%d\n", value.s32);
1018 case TDM_VALUE_TYPE_INT64:
1019 TDM_SNPRINTF(reply, len, "%"PRId64"\n", value.s64);
1021 case TDM_VALUE_TYPE_UINT64:
1022 TDM_SNPRINTF(reply, len, "%"PRIu64"\n", value.u64);
1024 case TDM_VALUE_TYPE_UINT32:
1026 TDM_SNPRINTF(reply, len, "%u\n", value.u32);
1033 TDM_SNPRINTF(reply, len, "\n");
1035 if (private_display->capabilities & TDM_DISPLAY_CAPABILITY_PP) {
1036 const char *sep = "";
1037 TDM_SNPRINTF(reply, len, "[PP information]\n");
1038 TDM_SNPRINTF(reply, len, "caps\t: ");
1039 tdm_pp_caps_str(private_display->caps_pp.capabilities, &reply, len);
1040 TDM_SNPRINTF(reply, len, "\n");
1041 TDM_SNPRINTF(reply, len, "formats\t: ");
1042 for (i = 0; i < private_display->caps_pp.format_count; i++) {
1043 if (private_display->caps_pp.formats[i] == 0)
1045 TDM_SNPRINTF(reply, len, "%s%c%c%c%c", sep, FOURCC_STR(private_display->caps_pp.formats[i]));
1048 TDM_SNPRINTF(reply, len, "\n");
1049 TDM_SNPRINTF(reply, len, "size\t: min(%dx%d) max(%dx%d) align_w(%d)\n",
1050 TDM_FRONT_VALUE(private_display->caps_pp.min_w),
1051 TDM_FRONT_VALUE(private_display->caps_pp.min_h),
1052 TDM_FRONT_VALUE(private_display->caps_pp.max_w),
1053 TDM_FRONT_VALUE(private_display->caps_pp.max_h),
1054 TDM_FRONT_VALUE(private_display->caps_pp.preferred_align));
1055 if (!LIST_IS_EMPTY(&private_display->pp_list)) {
1056 TDM_SNPRINTF(reply, len, "-------------------------------------------------------------\n");
1057 TDM_SNPRINTF(reply, len, "src(format size crop) | dst(format size crop) | transform\n");
1058 TDM_SNPRINTF(reply, len, "-------------------------------------------------------------\n");
1059 LIST_FOR_EACH_ENTRY(private_pp, &private_display->pp_list, link) {
1060 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",
1061 FOURCC_STR(private_pp->info.src_config.format),
1062 private_pp->info.src_config.size.h,
1063 private_pp->info.src_config.size.v,
1064 private_pp->info.src_config.pos.x, private_pp->info.src_config.pos.y,
1065 private_pp->info.src_config.pos.w, private_pp->info.src_config.pos.h,
1066 FOURCC_STR(private_pp->info.dst_config.format),
1067 private_pp->info.dst_config.size.h,
1068 private_pp->info.dst_config.size.v,
1069 private_pp->info.dst_config.pos.x, private_pp->info.dst_config.pos.y,
1070 private_pp->info.dst_config.pos.w, private_pp->info.dst_config.pos.h,
1071 tdm_transform_str(private_pp->info.transform));
1075 TDM_SNPRINTF(reply, len, "[No PP capability]\n");
1077 TDM_SNPRINTF(reply, len, "\n");
1079 if (private_display->capabilities & TDM_DISPLAY_CAPABILITY_CAPTURE) {
1080 const char *sep = "";
1081 TDM_SNPRINTF(reply, len, "[Capture information]\n");
1082 TDM_SNPRINTF(reply, len, "caps\t: ");
1083 tdm_capture_caps_str(private_display->caps_capture.capabilities, &reply, len);
1084 TDM_SNPRINTF(reply, len, "\n");
1085 TDM_SNPRINTF(reply, len, "formats\t: ");
1086 for (i = 0; i < private_display->caps_capture.format_count; i++) {
1087 if (private_display->caps_capture.formats[i] == 0)
1089 TDM_SNPRINTF(reply, len, "%s%c%c%c%c", sep, FOURCC_STR(private_display->caps_capture.formats[i]));
1092 TDM_SNPRINTF(reply, len, "\n");
1093 TDM_SNPRINTF(reply, len, "size\t: min(%dx%d) max(%dx%d) align_w(%d)\n",
1094 TDM_FRONT_VALUE(private_display->caps_capture.min_w),
1095 TDM_FRONT_VALUE(private_display->caps_capture.min_h),
1096 TDM_FRONT_VALUE(private_display->caps_capture.max_w),
1097 TDM_FRONT_VALUE(private_display->caps_capture.max_h),
1098 TDM_FRONT_VALUE(private_display->caps_capture.preferred_align));
1099 if (!LIST_IS_EMPTY(&private_display->capture_list)) {
1100 TDM_SNPRINTF(reply, len, "-----------------------------------\n");
1101 TDM_SNPRINTF(reply, len, "dst(format size crop) | transform\n");
1102 TDM_SNPRINTF(reply, len, "-----------------------------------\n");
1103 LIST_FOR_EACH_ENTRY(private_capture, &private_display->capture_list, link) {
1104 TDM_SNPRINTF(reply, len, "%c%c%c%c %ux%u %ux%u+%u+%u | %s\n",
1105 FOURCC_STR(private_capture->info.dst_config.format),
1106 private_capture->info.dst_config.size.h,
1107 private_capture->info.dst_config.size.v,
1108 private_capture->info.dst_config.pos.x, private_capture->info.dst_config.pos.y,
1109 private_capture->info.dst_config.pos.w, private_capture->info.dst_config.pos.h,
1110 tdm_transform_str(private_capture->info.transform));
1114 TDM_SNPRINTF(reply, len, "[No Capture capability]\n");
1116 TDM_SNPRINTF(reply, len, "\n");
1120 tdm_helper_commit_per_vblank_enabled(tdm_display *dpy)
1122 tdm_private_display *private_display;
1124 TDM_RETURN_VAL_IF_FAIL(dpy != NULL, 0);
1126 private_display = dpy;
1128 return private_display->commit_per_vblank;