add tdm-dbg and td-test-server for debugging
[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         const char *name, *vendor;
498         int major, minor;
499         tdm_error ret;
500         int i, count;
501         tdm_output *output;
502         const tdm_prop *props;
503         int min_w, min_h, max_w, max_h, preferred_align;
504         const tbm_format *formats;
505         tdm_display_capability display_caps;
506
507         ret = tdm_display_get_backend_info(dpy, &name, &vendor, &major, &minor);
508         TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
509
510         TDM_SNPRINTF(reply, len, "TDM backend name: %s\n", name);
511         TDM_SNPRINTF(reply, len, "TDM backend vendor: %s\n", vendor);
512         TDM_SNPRINTF(reply, len, "TDM backend version: %d.%d\n\n", major, minor);
513
514         ret =  tdm_display_get_output_count(dpy, &count);
515         TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
516
517         TDM_SNPRINTF(reply, len, "[Output information]\n");
518         TDM_SNPRINTF(reply, len, "-------------------------------------------------------------------------------------------\n");
519         TDM_SNPRINTF(reply, len, "idx   maker   model   name   type   status   dpms   subpix   prefer   min   max   phy\n");
520         TDM_SNPRINTF(reply, len, "-------------------------------------------------------------------------------------------\n");
521
522         for (i = 0; i < count; i++) {
523                 /* idx  maker  model  name  type  status  dpms  subpix  prefer  min  max  phy */
524                 const char *maker, *model, *name;
525                 tdm_output_type type;
526                 tdm_output_conn_status status;
527                 unsigned int subpixel;
528                 unsigned int mmWidth, mmHeight;
529                 tdm_output_dpms dpms;
530                 const tdm_output_mode *mode, *modes;
531                 int j, cnt;
532
533                 output = tdm_display_get_output(dpy, i, &ret);
534                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
535                 ret = tdm_output_get_model_info(output, &maker, &model, &name);
536                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
537                 ret = tdm_output_get_output_type(output, &type);
538                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
539                 ret = tdm_output_get_conn_status(output, &status);
540                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
541                 ret = tdm_output_get_dpms(output, &dpms);
542                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
543                 ret = tdm_output_get_subpixel(output, &subpixel);
544                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
545                 ret = tdm_output_get_available_size(output, &min_w, &min_h, &max_w, &max_h, &preferred_align);
546                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
547                 ret = tdm_output_get_physical_size(output, &mmWidth, &mmHeight);
548                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
549
550                 TDM_SNPRINTF(reply, len, "%d   %s   %s   %s   %s   %s   %s   %d   %d   %dx%d   %dx%d   %dx%d\n",
551                                          i, maker, model, name, tdm_conn_str(type), tdm_status_str(status),
552                                          tdm_dpms_str(dpms), subpixel, preferred_align,
553                                          min_w, min_h, max_w, max_h, mmWidth, mmHeight);
554
555                 ret = tdm_output_get_mode(output, &mode);
556                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
557
558                 ret = tdm_output_get_available_modes(output, &modes, &cnt);
559                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
560
561                 TDM_SNPRINTF(reply, len, "\t%d modes:\n", cnt);
562
563                 if (cnt > 0) {
564                         TDM_SNPRINTF(reply, len, "\t\tname refresh (Hz) hdisp hss hse htot vdisp vss vse vtot\n");
565                         for (j = 0; j < cnt; j++) {
566                                 char *current = (mode == modes + j) ? "*" : " ";
567                                 TDM_SNPRINTF(reply, len, "\t\t%s%s %d %d %d %d %d %d %d %d %d ",
568                                                          current,
569                                                          modes[j].name,
570                                                          modes[j].vrefresh,
571                                                          modes[j].hdisplay,
572                                                          modes[j].hsync_start,
573                                                          modes[j].hsync_end,
574                                                          modes[j].htotal,
575                                                          modes[j].vdisplay,
576                                                          modes[j].vsync_start,
577                                                          modes[j].vsync_end,
578                                                          modes[j].vtotal);
579                                 tdm_mode_flag_str(modes[j].flags, &reply, len);
580                                 TDM_SNPRINTF(reply, len, " ");
581                                 tdm_mode_type_str(modes[j].type, &reply, len);
582                                 TDM_SNPRINTF(reply, len, "\n");
583                         }
584                 }
585
586                 ret = tdm_output_get_available_properties(output, &props, &cnt);
587                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
588
589                 TDM_SNPRINTF(reply, len, "\t%d properties:\n", cnt);
590                 if (cnt > 0) {
591                         TDM_SNPRINTF(reply, len, "\t\tname idx value\n");
592                         for (j = 0; j < cnt; j++) {
593                                 tdm_value value;
594                                 ret = tdm_output_get_property(output, props[j].id, &value);
595                                 TDM_SNPRINTF(reply, len, "\t\t%s %d %d\n",
596                                                          props[j].name,
597                                                          props[j].id,
598                                                          value.u32);
599                         }
600                 }
601                 TDM_SNPRINTF(reply, len, "\n");
602         }
603
604         TDM_SNPRINTF(reply, len, "[Layer information]\n");
605         for (i = 0; i < count; i++) {
606                 int j, cnt;
607
608                 output = tdm_display_get_output(dpy, i, &ret);
609                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
610
611                 ret = tdm_output_get_layer_count(output, &cnt);
612                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
613
614                 if (cnt > 0) {
615                         TDM_SNPRINTF(reply, len, "-----------------------------------------------------\n");
616                         TDM_SNPRINTF(reply, len, "idx   output   zpos   buf   info   caps\n");
617                         TDM_SNPRINTF(reply, len, "-----------------------------------------------------\n");
618                         for (j = 0; j < cnt; j++) {
619                                 tdm_layer *layer;
620                                 tbm_surface_h buf;
621                                 tdm_layer_capability layer_caps;
622                                 int k, c, zpos;
623                                 tdm_info_layer info;
624
625                                 memset(&info, 0, sizeof info);
626
627                                 layer = tdm_output_get_layer(output, j, &ret);
628                                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
629                                 ret = tdm_layer_get_capabilities(layer, &layer_caps);
630                                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
631                                 ret = tdm_layer_get_zpos(layer, &zpos);
632                                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
633
634                                 ret = tdm_layer_get_info(layer, &info);
635                                 buf = tdm_layer_get_displaying_buffer(layer, &ret);
636
637                                 if (info.src_config.format)
638                                         TDM_SNPRINTF(reply, len, "%d   %d   %d   %p   %c%c%c%c %dx%d (%d,%d %dx%d) (%d,%d %dx%d) trans(%d)   ",
639                                                                  j, i, zpos, buf,
640                                                                  FOURCC_STR(info.src_config.format), info.src_config.size.h, info.src_config.size.v,
641                                                                  info.src_config.pos.x, info.src_config.pos.y, info.src_config.pos.w, info.src_config.pos.h,
642                                                                  info.dst_pos.x, info.dst_pos.y, info.dst_pos.w, info.dst_pos.h,
643                                                                  info.transform);
644                                 else
645                                         TDM_SNPRINTF(reply, len, "%d   %d   %d   %p   %c%c%c%c %dx%d (%d,%d %dx%d) (%d,%d %dx%d) trans(%d)   ",
646                                                                  j, i, zpos, buf,
647                                                                  'N', 'O', 'N', 'E', info.src_config.size.h, info.src_config.size.v,
648                                                                  info.src_config.pos.x, info.src_config.pos.y, info.src_config.pos.w, info.src_config.pos.h,
649                                                                  info.dst_pos.x, info.dst_pos.y, info.dst_pos.w, info.dst_pos.h,
650                                                                  info.transform);
651                                 tdm_layer_caps_str(layer_caps, &reply, len);
652                                 TDM_SNPRINTF(reply, len, "\n");
653
654                                 ret = tdm_layer_get_available_properties(layer, &props, &c);
655                                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
656                                 TDM_SNPRINTF(reply, len, "\t%d properties:\n", c);
657                                 if (c > 0) {
658                                         TDM_SNPRINTF(reply, len, "\t\tname idx value\n");
659                                         for (k = 0; k < c; k++) {
660                                                 tdm_value value;
661                                                 ret = tdm_layer_get_property(layer, props[k].id, &value);
662                                                 TDM_SNPRINTF(reply, len, "\t\t%s %d %d\n",
663                                                                          props[k].name,
664                                                                          props[k].id,
665                                                                          value.u32);
666                                         }
667                                 }
668
669                                 ret = tdm_layer_get_available_formats(layer, &formats, &c);
670                                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
671                                 TDM_SNPRINTF(reply, len, "\tformats:");
672                                 for (k = 0; k < c; k++)
673                                         TDM_SNPRINTF(reply, len, " %c%c%c%c", FOURCC_STR(formats[k]));
674                                 TDM_SNPRINTF(reply, len, "\n");
675                         }
676                 }
677         }
678
679         TDM_SNPRINTF(reply, len, "\n");
680
681         ret = tdm_display_get_capabilities(dpy, &display_caps);
682         TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
683
684         if (display_caps & TDM_DISPLAY_CAPABILITY_PP) {
685                 tdm_pp_capability pp_caps;
686
687                 ret = tdm_display_get_pp_capabilities(dpy, &pp_caps);
688                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
689                 ret = tdm_display_get_pp_available_formats(dpy, &formats, &count);
690                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
691                 ret = tdm_display_get_pp_available_size(dpy, &min_w, &min_h, &max_w, &max_h, &preferred_align);
692                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
693
694                 TDM_SNPRINTF(reply, len, "[PP information]\n");
695                 TDM_SNPRINTF(reply, len, "caps: ");
696                 tdm_pp_caps_str(pp_caps, &reply, len);
697                 TDM_SNPRINTF(reply, len, "\n");
698                 TDM_SNPRINTF(reply, len, "formats: ");
699                 for (i = 0; i < count; i++)
700                         TDM_SNPRINTF(reply, len, " %c%c%c%c", FOURCC_STR(formats[i]));
701                 TDM_SNPRINTF(reply, len, "\n");
702                 TDM_SNPRINTF(reply, len, "size: min(%dx%d) max(%dx%d) preferred(%d)\n",
703                                          min_w, min_h, max_w, max_h, preferred_align);
704         }
705
706         if (display_caps & TDM_DISPLAY_CAPABILITY_CAPTURE) {
707                 tdm_capture_capability capture_caps;
708
709                 ret = tdm_display_get_capture_capabilities(dpy, &capture_caps);
710                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
711                 ret = tdm_display_get_catpure_available_formats(dpy, &formats, &count);
712                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
713
714                 TDM_SNPRINTF(reply, len, "[Capture information]\n");
715                 TDM_SNPRINTF(reply, len, "caps: ");
716                 tdm_capture_caps_str(capture_caps, &reply, len);
717                 TDM_SNPRINTF(reply, len, "\n");
718                 TDM_SNPRINTF(reply, len, "formats: ");
719                 for (i = 0; i < count; i++)
720                         TDM_SNPRINTF(reply, len, " %c%c%c%c", FOURCC_STR(formats[i]));
721                 TDM_SNPRINTF(reply, len, "\n");
722         }
723 }