enhance the display information
[platform/core/uifw/libtdm.git] / src / tdm_helper.c
1 /**************************************************************************
2  *
3  * libtdm
4  *
5  * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
6  *
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>
13  *
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:
21  *
22  * The above copyright notice and this permission notice (including the
23  * next paragraph) shall be included in all copies or substantial portions
24  * of the Software.
25  *
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.
33  *
34 **************************************************************************/
35
36 #ifdef HAVE_CONFIG_H
37 #include "config.h"
38 #endif
39
40 #include <png.h>
41 #include <string.h>
42 #include <tbm_surface.h>
43 #include <tbm_surface_internal.h>
44 #include <string.h>
45 #include <time.h>
46 #include <pixman.h>
47
48 #include "tdm.h"
49 #include "tdm_private.h"
50 #include "tdm_helper.h"
51
52 #define PNG_DEPTH 8
53
54 static const char *file_exts[2] = {"png", "yuv"};
55
56 int tdm_dump_enable;
57
58 INTERN unsigned long
59 tdm_helper_get_time_in_millis(void)
60 {
61         struct timespec tp;
62
63         if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
64                 return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
65
66         return 0;
67 }
68
69 INTERN unsigned long
70 tdm_helper_get_time_in_micros(void)
71 {
72         struct timespec tp;
73
74         if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
75                 return (tp.tv_sec * 1000000) + (tp.tv_nsec / 1000L);
76
77         return 0;
78 }
79
80 static void
81 _tdm_helper_dump_raw(const char *file, void *data1, int size1, void *data2,
82                                          int size2, void *data3, int size3)
83 {
84         unsigned int *blocks;
85         FILE *fp = fopen(file, "w+");
86         TDM_RETURN_IF_FAIL(fp != NULL);
87
88         blocks = (unsigned int *)data1;
89         fwrite(blocks, 1, size1, fp);
90
91         if (size2 > 0) {
92                 blocks = (unsigned int *)data2;
93                 fwrite(blocks, 1, size2, fp);
94         }
95
96         if (size3 > 0) {
97                 blocks = (unsigned int *)data3;
98                 fwrite(blocks, 1, size3, fp);
99         }
100
101         fclose(fp);
102 }
103
104 static void
105 _tdm_helper_dump_png(const char *file, const void *data, int width,
106                                          int height)
107 {
108         FILE *fp = fopen(file, "wb");
109         TDM_RETURN_IF_FAIL(fp != NULL);
110
111         png_structp pPngStruct =
112                 png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
113         if (!pPngStruct) {
114                 fclose(fp);
115                 return;
116         }
117
118         png_infop pPngInfo = png_create_info_struct(pPngStruct);
119         if (!pPngInfo) {
120                 png_destroy_write_struct(&pPngStruct, NULL);
121                 fclose(fp);
122                 return;
123         }
124
125         png_init_io(pPngStruct, fp);
126         png_set_IHDR(pPngStruct,
127                                  pPngInfo,
128                                  width,
129                                  height,
130                                  PNG_DEPTH,
131                                  PNG_COLOR_TYPE_RGBA,
132                                  PNG_INTERLACE_NONE,
133                                  PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
134
135         png_set_bgr(pPngStruct);
136         png_write_info(pPngStruct, pPngInfo);
137
138         const int pixel_size = 4;       // RGBA
139         png_bytep *row_pointers =
140                 png_malloc(pPngStruct, height * sizeof(png_byte *));
141
142         unsigned int *blocks = (unsigned int *)data;
143         int y = 0;
144         int x = 0;
145
146         for (; y < height; ++y) {
147                 png_bytep row =
148                         png_malloc(pPngStruct, sizeof(png_byte) * width * pixel_size);
149                 row_pointers[y] = (png_bytep)row;
150                 for (x = 0; x < width; ++x) {
151                         unsigned int curBlock = blocks[y * width + x];
152                         row[x * pixel_size] = (curBlock & 0xFF);
153                         row[1 + x * pixel_size] = (curBlock >> 8) & 0xFF;
154                         row[2 + x * pixel_size] = (curBlock >> 16) & 0xFF;
155                         row[3 + x * pixel_size] = (curBlock >> 24) & 0xFF;
156                 }
157         }
158
159         png_write_image(pPngStruct, row_pointers);
160         png_write_end(pPngStruct, pPngInfo);
161
162         for (y = 0; y < height; y++)
163                 png_free(pPngStruct, row_pointers[y]);
164         png_free(pPngStruct, row_pointers);
165
166         png_destroy_write_struct(&pPngStruct, &pPngInfo);
167
168         fclose(fp);
169 }
170
171 INTERN void
172 tdm_helper_dump_buffer_str(tbm_surface_h buffer, const char *str)
173 {
174         tbm_surface_info_s info;
175         const char *dir = "/tmp/dump-tdm";
176         const char *ext;
177         char file[TDM_PATH_LEN];
178         int ret, bw;
179
180         TDM_RETURN_IF_FAIL(buffer != NULL);
181         TDM_RETURN_IF_FAIL(str != NULL);
182
183         ret = tbm_surface_get_info(buffer, &info);
184         TDM_RETURN_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE);
185
186         if (info.format == TBM_FORMAT_ARGB8888 || info.format == TBM_FORMAT_XRGB8888) {
187                 ext = file_exts[0];
188                 bw = info.planes[0].stride >> 2;
189         } else {
190                 ext = file_exts[1];
191                 bw = info.planes[0].stride;
192         }
193
194         snprintf(file, TDM_PATH_LEN, "%s/%c%c%c%c_%dx%d_%s.%s",
195                          dir, FOURCC_STR(info.format), bw, info.height, str, ext);
196
197         tdm_helper_dump_buffer(buffer, file);
198 }
199
200 EXTERN void
201 tdm_helper_dump_buffer(tbm_surface_h buffer, const char *file)
202 {
203         tbm_surface_info_s info;
204         int len, ret;
205         const char *ext;
206
207         TDM_RETURN_IF_FAIL(buffer != NULL);
208         TDM_RETURN_IF_FAIL(file != NULL);
209
210         ret = tbm_surface_map(buffer, TBM_OPTION_READ, &info);
211         TDM_RETURN_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE);
212
213         len = strnlen(file, 1024);
214         if (info.format == TBM_FORMAT_ARGB8888 || info.format == TBM_FORMAT_XRGB8888)
215                 ext = file_exts[0];
216         else
217                 ext = file_exts[1];
218
219         if (strncmp(file + (len - 3), ext, 3)) {
220                 TDM_ERR("can't dump to '%s' file", file + (len - 3));
221                 tbm_surface_unmap(buffer);
222                 return;
223         }
224
225         switch (info.format) {
226         case TBM_FORMAT_ARGB8888:
227         case TBM_FORMAT_XRGB8888:
228                 _tdm_helper_dump_png(file, info.planes[0].ptr,
229                                                          info.planes[0].stride >> 2, info.height);
230                 break;
231         case TBM_FORMAT_YVU420:
232         case TBM_FORMAT_YUV420:
233                 _tdm_helper_dump_raw(file,
234                                                          info.planes[0].ptr,
235                                                          info.planes[0].stride * info.height,
236                                                          info.planes[1].ptr,
237                                                          info.planes[1].stride * (info.height >> 1),
238                                                          info.planes[2].ptr,
239                                                          info.planes[2].stride * (info.height >> 1));
240                 break;
241         case TBM_FORMAT_NV12:
242         case TBM_FORMAT_NV21:
243                 _tdm_helper_dump_raw(file,
244                                                          info.planes[0].ptr,
245                                                          info.planes[0].stride * info.height,
246                                                          info.planes[1].ptr,
247                                                          info.planes[1].stride * (info.height >> 1), NULL,
248                                                          0);
249                 break;
250         case TBM_FORMAT_YUYV:
251         case TBM_FORMAT_UYVY:
252                 _tdm_helper_dump_raw(file,
253                                                          info.planes[0].ptr,
254                                                          info.planes[0].stride * info.height, NULL, 0,
255                                                          NULL, 0);
256                 break;
257         default:
258                 TDM_ERR("can't dump %c%c%c%c buffer", FOURCC_STR(info.format));
259                 tbm_surface_unmap(buffer);
260                 return;
261         }
262
263         tbm_surface_unmap(buffer);
264
265         TDM_INFO("dump %s", file);
266 }
267
268 EXTERN int
269 tdm_helper_get_fd(const char *env)
270 {
271         const char *value;
272         int fd, newfd, flags, ret;
273
274         value = (const char*)getenv(env);
275         if (!value)
276                 return -1;
277
278         ret = sscanf(value, "%d", &fd);
279         if (ret < 0) {
280                 TDM_ERR("sscanf failed: %m");
281                 return -1;
282         }
283
284         flags = fcntl(fd, F_GETFD);
285         if (flags == -1) {
286                 TDM_ERR("fcntl failed: %m");
287                 return -1;
288         }
289
290         newfd = dup(fd);
291         if (newfd < 0) {
292                 TDM_ERR("dup failed: %m");
293                 return -1;
294         }
295
296         TDM_INFO("%s: fd(%d) newfd(%d)", env, fd, newfd);
297
298         fcntl(newfd, F_SETFD, flags | FD_CLOEXEC);
299
300         return newfd;
301 }
302
303 EXTERN void
304 tdm_helper_set_fd(const char *env, int fd)
305 {
306         char buf[32];
307         int ret;
308
309         snprintf(buf, sizeof(buf), "%d", fd);
310
311         ret = setenv(env, (const char*)buf, 1);
312         if (ret) {
313                 TDM_ERR("setenv failed: %m");
314                 return;
315         }
316
317         if (fd >= 0)
318                 TDM_INFO("%s: fd(%d)", env, fd);
319 }
320
321 EXTERN void
322 tdm_helper_dump_start(char *dumppath, int *count)
323 {
324         if (dumppath == NULL || count == NULL) {
325                 TDM_DBG("tdm_helper_dump dumppath or count is null.");
326                 return;
327         }
328
329         tdm_dump_enable = 1;
330
331         TDM_DBG("tdm_helper_dump start.(path : %s)", dumppath);
332 }
333
334 EXTERN void
335 tdm_helper_dump_stop(void)
336 {
337         tdm_dump_enable = 0;
338
339         TDM_DBG("tdm_helper_dump stop.");
340 }
341
342 static pixman_format_code_t
343 _tdm_helper_pixman_format_get(tbm_format format)
344 {
345         switch (format) {
346         case TBM_FORMAT_ARGB8888:
347                 return PIXMAN_a8r8g8b8;
348         case TBM_FORMAT_XRGB8888:
349                 return PIXMAN_x8r8g8b8;
350         default:
351                 return 0;
352         }
353
354         return 0;
355 }
356
357 static tdm_error
358 _tdm_helper_buffer_convert(tbm_surface_h srcbuf, tbm_surface_h dstbuf,
359                                                    int dx, int dy, int dw, int dh, int count)
360 {
361         pixman_image_t *src_img = NULL, *dst_img = NULL;
362         pixman_format_code_t src_format, dst_format;
363         pixman_transform_t t;
364         struct pixman_f_transform ft;
365         pixman_op_t op;
366         tbm_surface_info_s src_info = {0, };
367         tbm_surface_info_s dst_info = {0, };
368         int stride, width;
369         double scale_x, scale_y;
370
371         TDM_RETURN_VAL_IF_FAIL(srcbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
372         TDM_RETURN_VAL_IF_FAIL(dstbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
373
374         if (tbm_surface_map(srcbuf, TBM_SURF_OPTION_READ, &src_info)
375                         != TBM_SURFACE_ERROR_NONE) {
376                 TDM_ERR("cannot mmap srcbuf\n");
377                 return TDM_ERROR_OPERATION_FAILED;
378         }
379
380         if (tbm_surface_map(dstbuf, TBM_SURF_OPTION_WRITE, &dst_info)
381                         != TBM_SURFACE_ERROR_NONE) {
382                 TDM_ERR("cannot mmap dstbuf\n");
383                 tbm_surface_unmap(srcbuf);
384                 return TDM_ERROR_OPERATION_FAILED;
385         }
386         TDM_GOTO_IF_FAIL(src_info.num_planes == 1, cant_convert);
387         TDM_GOTO_IF_FAIL(dst_info.num_planes == 1, cant_convert);
388
389         /* src */
390         src_format = _tdm_helper_pixman_format_get(src_info.format);
391         TDM_GOTO_IF_FAIL(src_format > 0, cant_convert);
392
393         width = src_info.planes[0].stride / 4;
394         stride = src_info.planes[0].stride;
395         src_img = pixman_image_create_bits(src_format, width, src_info.height,
396                                                                            (uint32_t*)src_info.planes[0].ptr, stride);
397         TDM_GOTO_IF_FAIL(src_img != NULL, cant_convert);
398
399         /* dst */
400         dst_format = _tdm_helper_pixman_format_get(dst_info.format);
401         TDM_GOTO_IF_FAIL(dst_format > 0, cant_convert);
402
403         width = dst_info.planes[0].stride / 4;
404         stride = dst_info.planes[0].stride;
405         dst_img = pixman_image_create_bits(dst_format, width, dst_info.height,
406                                                                            (uint32_t*)dst_info.planes[0].ptr, stride);
407         TDM_GOTO_IF_FAIL(dst_img != NULL, cant_convert);
408
409         pixman_f_transform_init_identity(&ft);
410
411         scale_x = (double)src_info.width / dw;
412         scale_y = (double)src_info.height / dh;
413
414         pixman_f_transform_scale(&ft, NULL, scale_x, scale_y);
415         pixman_f_transform_translate(&ft, NULL, 0, 0);
416         pixman_transform_from_pixman_f_transform(&t, &ft);
417         pixman_image_set_transform(src_img, &t);
418
419         if (count == 0)
420                 op = PIXMAN_OP_SRC;
421         else
422                 op = PIXMAN_OP_OVER;
423
424         pixman_image_composite(op, src_img, NULL, dst_img,
425                                                    0, 0, 0, 0, dx, dy, dw, dh);
426
427         if (src_img)
428                 pixman_image_unref(src_img);
429         if (dst_img)
430                 pixman_image_unref(dst_img);
431
432         tbm_surface_unmap(srcbuf);
433         tbm_surface_unmap(dstbuf);
434
435         return TDM_ERROR_NONE;
436
437 cant_convert:
438         if (src_img)
439                 pixman_image_unref(src_img);
440
441         tbm_surface_unmap(srcbuf);
442         tbm_surface_unmap(dstbuf);
443
444         return TDM_ERROR_OPERATION_FAILED;
445 }
446
447 EXTERN tdm_error
448 tdm_helper_capture_output(tdm_output *output, tbm_surface_h dst_buffer,
449                                                   int x, int y, int w, int h,
450                                                   tdm_helper_capture_handler func, void *data)
451 {
452         tbm_surface_h surface;
453         tdm_error err;
454         int i, count, first = 0;
455
456         TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
457         TDM_RETURN_VAL_IF_FAIL(dst_buffer != NULL, TDM_ERROR_INVALID_PARAMETER);
458         TDM_RETURN_VAL_IF_FAIL(x >= 0, TDM_ERROR_INVALID_PARAMETER);
459         TDM_RETURN_VAL_IF_FAIL(y >= 0, TDM_ERROR_INVALID_PARAMETER);
460         TDM_RETURN_VAL_IF_FAIL(w >= 0, TDM_ERROR_INVALID_PARAMETER);
461         TDM_RETURN_VAL_IF_FAIL(h >= 0, TDM_ERROR_INVALID_PARAMETER);
462         TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
463         TDM_RETURN_VAL_IF_FAIL(data != NULL, TDM_ERROR_INVALID_PARAMETER);
464
465         err = tdm_output_get_layer_count(output, &count);
466         if (err != TDM_ERROR_NONE) {
467                 TDM_ERR("tdm_output_get_layer_count fail(%d)\n", err);
468                 return TDM_ERROR_OPERATION_FAILED;
469         }
470         if (count <= 0) {
471                 TDM_ERR("tdm_output_get_layer_count err(%d, %d)\n", err, count);
472                 return TDM_ERROR_BAD_MODULE;
473         }
474
475         for (i = count - 1; i >= 0; i--) {
476                 tdm_layer *layer = tdm_output_get_layer(output, i, NULL);
477
478                 surface = tdm_layer_get_displaying_buffer(layer, &err);
479                 if (err != TDM_ERROR_NONE)
480                         continue;
481
482                 err = _tdm_helper_buffer_convert(surface, dst_buffer, x, y, w, h, first++);
483                 if (err != TDM_ERROR_NONE)
484                         TDM_DBG("convert fail %d-layer buffer\n", i);
485                 else
486                         TDM_DBG("convert success %d-layer buffer\n", i);
487         }
488
489         func(dst_buffer, data);
490
491         return TDM_ERROR_NONE;
492 }
493
494 EXTERN void
495 tdm_helper_get_display_information(tdm_display *dpy, char *reply, int *len)
496 {
497         tdm_private_display *private_display;
498         tdm_backend_module *module_data;
499         tdm_func_output *func_output;
500         tdm_func_layer *func_layer;
501         tdm_private_output *private_output = NULL;
502         tdm_private_layer *private_layer = NULL;
503         tdm_private_pp *private_pp = NULL;
504         tdm_private_capture *private_capture = NULL;
505         tdm_error ret;
506         int i;
507
508         TDM_DBG_RETURN_IF_FAIL(dpy != NULL);
509
510         private_display = dpy;
511         func_output = &private_display->func_output;
512         func_layer = &private_display->func_layer;
513         _pthread_mutex_lock(&private_display->lock);
514
515         /* module information */
516         module_data = private_display->module_data;
517         TDM_SNPRINTF(reply, len, "[TDM backend information]\n");
518         TDM_SNPRINTF(reply, len, "name: %s\n", module_data->name);
519         TDM_SNPRINTF(reply, len, "vendor: %s\n", module_data->vendor);
520         TDM_SNPRINTF(reply, len, "version: %d.%d\n\n",
521                                  (int)TDM_BACKEND_GET_ABI_MAJOR(module_data->abi_version),
522                                  (int)TDM_BACKEND_GET_ABI_MINOR(module_data->abi_version));
523
524         /* output information */
525         TDM_SNPRINTF(reply, len, "[Output information]\n");
526         TDM_SNPRINTF(reply, len, "--------------------------------------------------------------------------------------------\n");
527         TDM_SNPRINTF(reply, len, "idx   maker   model   name   type   status   dpms   subpixel   align_w   min   max   phy(mm)\n");
528         TDM_SNPRINTF(reply, len, "--------------------------------------------------------------------------------------------\n");
529         LIST_FOR_EACH_ENTRY(private_output, &private_display->output_list, link) {
530                 TDM_SNPRINTF(reply, len, "%d   %s   %s   %s   %s   %s   %s   %d   %d   %dx%d   %dx%d   %dx%d\n",
531                                          private_output->index, private_output->caps.maker,
532                                          private_output->caps.model, private_output->caps.name,
533                                          tdm_conn_str(private_output->caps.type),
534                                          tdm_status_str(private_output->caps.status),
535                                          tdm_dpms_str(private_output->current_dpms_value),
536                                          private_output->caps.subpixel,
537                                          private_output->caps.preferred_align,
538                                          private_output->caps.min_w, private_output->caps.min_h,
539                                          private_output->caps.max_w, private_output->caps.max_h,
540                                          private_output->caps.mmWidth, private_output->caps.mmHeight);
541
542                 TDM_SNPRINTF(reply, len, "\t%d modes:\n", private_output->caps.mode_count);
543
544                 if (private_output->caps.mode_count > 0) {
545                         const tdm_output_mode *current_mode = NULL;
546
547                         TDM_DBG_GOTO_IF_FAIL(func_output->output_get_mode, unlock);
548                         ret = func_output->output_get_mode(private_output->output_backend, &current_mode);
549                         TDM_DBG_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, unlock);
550
551                         TDM_SNPRINTF(reply, len, "\t\t name refresh (Hz) hdisp hss hse htot vdisp vss vse vtot\n");
552                         for (i = 0; i < private_output->caps.mode_count; i++) {
553                                 char *current = (current_mode == private_output->caps.modes + i) ? "*" : " ";
554                                 TDM_SNPRINTF(reply, len, "\t\t%s%s %d %d %d %d %d %d %d %d %d ",
555                                                          current,
556                                                          private_output->caps.modes[i].name,
557                                                          private_output->caps.modes[i].vrefresh,
558                                                          private_output->caps.modes[i].hdisplay,
559                                                          private_output->caps.modes[i].hsync_start,
560                                                          private_output->caps.modes[i].hsync_end,
561                                                          private_output->caps.modes[i].htotal,
562                                                          private_output->caps.modes[i].vdisplay,
563                                                          private_output->caps.modes[i].vsync_start,
564                                                          private_output->caps.modes[i].vsync_end,
565                                                          private_output->caps.modes[i].vtotal);
566                                 tdm_mode_flag_str(private_output->caps.modes[i].flags, &reply, len);
567                                 TDM_SNPRINTF(reply, len, " ");
568                                 tdm_mode_type_str(private_output->caps.modes[i].type, &reply, len);
569                                 TDM_SNPRINTF(reply, len, "\n");
570                         }
571                 }
572
573                 TDM_SNPRINTF(reply, len, "\t%d properties:\n", private_output->caps.prop_count);
574                 if (private_output->caps.prop_count > 0) {
575                         TDM_SNPRINTF(reply, len, "\t\tname\tidx\tvalue\n");
576                         for (i = 0; i < private_output->caps.prop_count; i++) {
577                                 tdm_value value;
578                                 TDM_DBG_GOTO_IF_FAIL(func_output->output_get_property, unlock);
579                                 ret = func_output->output_get_property(private_output->output_backend,
580                                                                                                            private_output->caps.props[i].id,
581                                                                                                            &value);
582                                 TDM_DBG_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, unlock);
583                                 TDM_SNPRINTF(reply, len, "\t\t%s\t%d\t%d\n",
584                                                          private_output->caps.props[i].name,
585                                                          private_output->caps.props[i].id,
586                                                          value.u32);
587                         }
588                 }
589         }
590         TDM_SNPRINTF(reply, len, "\n");
591
592         /* layer information */
593         TDM_SNPRINTF(reply, len, "[Layer information]\n");
594         TDM_SNPRINTF(reply, len, "-----------------------------------------------------------------------\n");
595         TDM_SNPRINTF(reply, len, "idx   output   zpos   buf   format   size   crop   geometry   transform\n");
596         TDM_SNPRINTF(reply, len, "-----------------------------------------------------------------------\n");
597         LIST_FOR_EACH_ENTRY(private_output, &private_display->output_list, link) {
598                 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
599                         if (!private_layer->usable) {
600                                 tdm_info_layer info;
601                                 unsigned int format;
602                                 tdm_size size;
603                                 tbm_surface_info_s buf_info;
604
605                                 TDM_DBG_GOTO_IF_FAIL(func_layer->layer_get_info, unlock);
606                                 memset(&info, 0, sizeof info);
607                                 ret = func_layer->layer_get_info(private_layer->layer_backend, &info);
608                                 TDM_DBG_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, unlock);
609
610                                 format = tbm_surface_get_format(private_layer->showing_buffer);
611                                 tbm_surface_get_info(private_layer->showing_buffer, &buf_info);
612
613                                 if (IS_RGB(format))
614                                         size.h = buf_info.planes[0].stride >> 2;
615                                 else
616                                         size.h = buf_info.planes[0].stride;
617                                 size.v = tbm_surface_get_height(private_layer->showing_buffer);
618
619                                 if (info.src_config.format)
620                                         format = (info.src_config.format)?:format;
621
622                                 TDM_SNPRINTF(reply, len, "%d   %d   %d   %p   %c%c%c%c   %dx%d   %dx%d+%d+%d   %dx%d+%d+%d   %s\n",
623                                                          private_layer->index,
624                                                          private_output->index,
625                                                          private_layer->caps.zpos,
626                                                          private_layer->showing_buffer, FOURCC_STR(format), size.h, size.v,
627                                                          info.src_config.pos.w, info.src_config.pos.h, info.src_config.pos.x, info.src_config.pos.y,
628                                                          info.dst_pos.w, info.dst_pos.h, info.dst_pos.x, info.dst_pos.y,
629                                                          tdm_transform_str(info.transform));
630                         } else {
631                                 TDM_SNPRINTF(reply, len, "%d   %d   %d   -\n",
632                                                          private_layer->index,
633                                                          private_output->index,
634                                                          private_layer->caps.zpos);
635                         }
636
637                         TDM_SNPRINTF(reply, len, "\tcaps\t: ");
638                         tdm_layer_caps_str(private_layer->caps.capabilities, &reply, len);
639                         TDM_SNPRINTF(reply, len, "\n");
640
641                         TDM_SNPRINTF(reply, len, "\tformats\t: ");
642                         if (private_layer->caps.format_count > 0) {
643                                 const char *sep = "";
644                                 for (i = 0; i < private_layer->caps.format_count; i++) {
645                                         TDM_SNPRINTF(reply, len, "%s%c%c%c%c", sep, FOURCC_STR(private_layer->caps.formats[i]));
646                                         sep = ",";
647                                 }
648                                 TDM_SNPRINTF(reply, len, "\n");
649                         }
650
651                         TDM_SNPRINTF(reply, len, "\t%d properties:\n", private_layer->caps.prop_count);
652                         if (private_layer->caps.prop_count > 0) {
653                                 TDM_SNPRINTF(reply, len, "\t\tname\tidx\tvalue\n");
654                                 for (i = 0; i < private_layer->caps.prop_count; i++) {
655                                         tdm_value value;
656                                         TDM_DBG_GOTO_IF_FAIL(func_layer->layer_get_property, unlock);
657                                         ret = func_layer->layer_get_property(private_layer->layer_backend,
658                                                                                                                  private_layer->caps.props[i].id,
659                                                                                                                  &value);
660                                         TDM_DBG_GOTO_IF_FAIL(ret == TDM_ERROR_NONE, unlock);
661                                         TDM_SNPRINTF(reply, len, "\t\t%s\t%d\t%d\n",
662                                                                  private_layer->caps.props[i].name,
663                                                                  private_layer->caps.props[i].id,
664                                                                  value.u32);
665                                 }
666                         }
667                 }
668         }
669         TDM_SNPRINTF(reply, len, "\n");
670
671         if (private_display->capabilities & TDM_DISPLAY_CAPABILITY_PP) {
672                 const char *sep = "";
673                 TDM_SNPRINTF(reply, len, "[PP information]\n");
674                 TDM_SNPRINTF(reply, len, "caps\t: ");
675                 tdm_pp_caps_str(private_display->caps_pp.capabilities, &reply, len);
676                 TDM_SNPRINTF(reply, len, "\n");
677                 TDM_SNPRINTF(reply, len, "formats\t: ");
678                 for (i = 0; i < private_display->caps_pp.format_count; i++) {
679                         TDM_SNPRINTF(reply, len, "%s%c%c%c%c", sep, FOURCC_STR(private_display->caps_pp.formats[i]));
680                         sep = ",";
681                 }
682                 TDM_SNPRINTF(reply, len, "\n");
683                 TDM_SNPRINTF(reply, len, "size\t: min(%dx%d) max(%dx%d) align_w(%d)\n",
684                                          private_display->caps_pp.min_w, private_display->caps_pp.min_h,
685                                          private_display->caps_pp.max_w, private_display->caps_pp.max_h,
686                                          private_display->caps_pp.preferred_align);
687                 if (!LIST_IS_EMPTY(&private_display->pp_list)) {
688                         TDM_SNPRINTF(reply, len, "-------------------------------------------------------------\n");
689                         TDM_SNPRINTF(reply, len, "src(format size crop)  |  dst(format size crop)  |  transform\n");
690                         TDM_SNPRINTF(reply, len, "-------------------------------------------------------------\n");
691                         LIST_FOR_EACH_ENTRY(private_pp, &private_display->pp_list, link) {
692                                 TDM_SNPRINTF(reply, len, "%c%c%c%c %dx%d %dx%d+%d+%d | %c%c%c%c %dx%d %dx%d+%d+%d | %s\n",
693                                                          FOURCC_STR(private_pp->info.src_config.format),
694                                                          private_pp->info.src_config.size.h,
695                                                          private_pp->info.src_config.size.v,
696                                                          private_pp->info.src_config.pos.x, private_pp->info.src_config.pos.y,
697                                                          private_pp->info.src_config.pos.w, private_pp->info.src_config.pos.h,
698                                                          FOURCC_STR(private_pp->info.dst_config.format),
699                                                          private_pp->info.dst_config.size.h,
700                                                          private_pp->info.dst_config.size.v,
701                                                          private_pp->info.dst_config.pos.x, private_pp->info.dst_config.pos.y,
702                                                          private_pp->info.dst_config.pos.w, private_pp->info.dst_config.pos.h,
703                                                          tdm_transform_str(private_pp->info.transform));
704                         }
705                 }
706         } else {
707                 TDM_SNPRINTF(reply, len, "[No PP capability]\n");
708         }
709         TDM_SNPRINTF(reply, len, "\n");
710
711         if (private_display->capabilities & TDM_DISPLAY_CAPABILITY_CAPTURE) {
712                 const char *sep = "";
713                 TDM_SNPRINTF(reply, len, "[Capture information]\n");
714                 TDM_SNPRINTF(reply, len, "caps\t: ");
715                 tdm_capture_caps_str(private_display->caps_capture.capabilities, &reply, len);
716                 TDM_SNPRINTF(reply, len, "\n");
717                 TDM_SNPRINTF(reply, len, "formats\t: ");
718                 for (i = 0; i < private_display->caps_capture.format_count; i++) {
719                         TDM_SNPRINTF(reply, len, "%s%c%c%c%c", sep, FOURCC_STR(private_display->caps_capture.formats[i]));
720                         sep = ",";
721                 }
722                 TDM_SNPRINTF(reply, len, "\n");
723                 TDM_SNPRINTF(reply, len, "size\t: min(%dx%d) max(%dx%d) align_w(%d)\n",
724                                          private_display->caps_capture.min_w, private_display->caps_capture.min_h,
725                                          private_display->caps_capture.max_w, private_display->caps_capture.max_h,
726                                          private_display->caps_capture.preferred_align);
727                 if (!LIST_IS_EMPTY(&private_display->capture_list)) {
728                         TDM_SNPRINTF(reply, len, "-----------------------------------\n");
729                         TDM_SNPRINTF(reply, len, "dst(format size crop)  |  transform\n");
730                         TDM_SNPRINTF(reply, len, "-----------------------------------\n");
731                         LIST_FOR_EACH_ENTRY(private_capture, &private_display->capture_list, link) {
732                                 TDM_SNPRINTF(reply, len, "%c%c%c%c %dx%d %dx%d+%d+%d | %s\n",
733                                                          FOURCC_STR(private_capture->info.dst_config.format),
734                                                          private_capture->info.dst_config.size.h,
735                                                          private_capture->info.dst_config.size.v,
736                                                          private_capture->info.dst_config.pos.x, private_capture->info.dst_config.pos.y,
737                                                          private_capture->info.dst_config.pos.w, private_capture->info.dst_config.pos.h,
738                                                          tdm_transform_str(private_capture->info.transform));
739                         }
740                 }
741         } else {
742                 TDM_SNPRINTF(reply, len, "[No Capture capability]\n");
743         }
744         TDM_SNPRINTF(reply, len, "\n");
745
746 unlock:
747         _pthread_mutex_unlock(&private_display->lock);
748 }