dump: add function to check whether file is link or not
[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 #include <inttypes.h>
48
49 #include "tdm.h"
50 #include "tdm_private.h"
51 #include "tdm_helper.h"
52
53 #define PNG_DEPTH 8
54
55 static const char *file_exts[2] = {"png", "yuv"};
56
57 int tdm_dump_enable;
58 char *tdm_debug_dump_dir;
59
60 EXTERN double
61 tdm_helper_get_time(void)
62 {
63         struct timespec tp;
64
65         if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
66                 return (double)tp.tv_sec + ((double)tp.tv_nsec) / 1000000000.0;
67
68         return 0;
69 }
70
71 static int
72 _tdm_helper_check_file_is_valid(const char* path, int del_link)
73 {
74         char *real_path;
75
76         if (!path)
77                 return 0;
78
79         real_path = realpath(path, NULL);
80         if (real_path && strncmp(path, real_path, strlen(path))) {
81                 if (del_link)
82                         unlink(path);
83                 free(real_path);
84
85                 return 0;
86         }
87
88         if (real_path)
89                 free(real_path);
90
91         return 1;
92 }
93
94 static void
95 _tdm_helper_dump_raw(const char *file, void *data1, int size1, void *data2,
96                                          int size2, void *data3, int size3)
97 {
98         unsigned int *blocks;
99         FILE *fp;
100
101         if (!_tdm_helper_check_file_is_valid(file, 1))
102                 TDM_WRN("'%s' may be symbolic link\n", file);
103
104         fp = fopen(file, "w+");
105         TDM_RETURN_IF_FAIL(fp != NULL);
106
107         blocks = (unsigned int *)data1;
108         fwrite(blocks, 1, size1, fp);
109
110         if (size2 > 0) {
111                 blocks = (unsigned int *)data2;
112                 fwrite(blocks, 1, size2, fp);
113         }
114
115         if (size3 > 0) {
116                 blocks = (unsigned int *)data3;
117                 fwrite(blocks, 1, size3, fp);
118         }
119
120         fclose(fp);
121 }
122
123 static void
124 _tdm_helper_dump_png(const char *file, const void *data, int width,
125                                          int height)
126 {
127         FILE *fp;
128
129         if (!_tdm_helper_check_file_is_valid(file, 1))
130                 TDM_WRN("'%s' may be symbolic link\n", file);
131
132         fp = fopen(file, "wb");
133         TDM_RETURN_IF_FAIL(fp != NULL);
134
135         png_structp pPngStruct =
136                 png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
137         if (!pPngStruct) {
138                 fclose(fp);
139                 return;
140         }
141
142         png_infop pPngInfo = png_create_info_struct(pPngStruct);
143         if (!pPngInfo) {
144                 png_destroy_write_struct(&pPngStruct, NULL);
145                 fclose(fp);
146                 return;
147         }
148
149         png_init_io(pPngStruct, fp);
150         png_set_IHDR(pPngStruct,
151                                  pPngInfo,
152                                  width,
153                                  height,
154                                  PNG_DEPTH,
155                                  PNG_COLOR_TYPE_RGBA,
156                                  PNG_INTERLACE_NONE,
157                                  PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
158
159         png_set_bgr(pPngStruct);
160         png_write_info(pPngStruct, pPngInfo);
161
162         const int pixel_size = 4;       // RGBA
163         png_bytep *row_pointers =
164                 png_malloc(pPngStruct, height * sizeof(png_byte *));
165         if (!row_pointers) {
166                 png_destroy_write_struct(&pPngStruct, &pPngInfo);
167                 fclose(fp);
168                 return;
169         }
170
171         unsigned int *blocks = (unsigned int *)data;
172         int y = 0;
173         int x = 0;
174
175         for (; y < height; ++y) {
176                 png_bytep row =
177                         png_malloc(pPngStruct, sizeof(png_byte) * width * pixel_size);
178                 if (!row) {
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);
183                         fclose(fp);
184                         return;
185                 }
186
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;
194                 }
195         }
196
197         png_write_image(pPngStruct, row_pointers);
198         png_write_end(pPngStruct, pPngInfo);
199
200         for (y = 0; y < height; y++)
201                 png_free(pPngStruct, row_pointers[y]);
202         png_free(pPngStruct, row_pointers);
203
204         png_destroy_write_struct(&pPngStruct, &pPngInfo);
205
206         fclose(fp);
207 }
208
209 INTERN char *
210 tdm_helper_dump_make_directory(const char *path, char *reply, int *len)
211 {
212         char *fullpath = NULL;
213         time_t timer;
214         struct tm *t, *buf = NULL;
215
216         timer = time(NULL);
217
218         buf = calloc(1, sizeof(struct tm));
219         TDM_GOTO_IF_FAIL(buf != NULL, failed_make);
220
221         fullpath = calloc(1, TDM_PATH_LEN * sizeof(char));
222         TDM_GOTO_IF_FAIL(fullpath != NULL, failed_make);
223
224         t = localtime_r(&timer, buf);
225         TDM_GOTO_IF_FAIL(t != NULL, failed_make);
226
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);
229
230         if ((mkdir(fullpath, 0755)) < 0) {
231                 TDM_ERR("mkdir '%s' fail\n", fullpath);
232                 TDM_SNPRINTF(reply, len, "mkdir '%s' fail\n", fullpath);
233                 goto failed_make;
234         }
235
236         free(buf);
237
238         return fullpath;
239 failed_make:
240         if (fullpath)
241                 free(fullpath);
242         if (buf)
243                 free(buf);
244         return NULL;
245 }
246
247 INTERN void
248 tdm_helper_dump_buffer_str(tbm_surface_h buffer, char *dir, char *str)
249 {
250         tbm_surface_info_s info;
251         const char *ext;
252         char file[TDM_PATH_LEN];
253         int ret, bw, bh;
254
255         TDM_RETURN_IF_FAIL(buffer != NULL);
256         TDM_RETURN_IF_FAIL(dir != NULL);
257         TDM_RETURN_IF_FAIL(str != NULL);
258
259         ret = tbm_surface_get_info(buffer, &info);
260         TDM_RETURN_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE);
261
262         if (IS_RGB(info.format))
263                 ext = file_exts[0];
264         else
265                 ext = file_exts[1];
266
267         tdm_helper_get_buffer_full_size(buffer, &bw, &bh);
268
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);
271
272         tdm_helper_dump_buffer(buffer, file);
273 }
274
275 EXTERN void
276 tdm_helper_dump_buffer(tbm_surface_h buffer, const char *file)
277 {
278         tbm_surface_info_s info;
279         int len, ret;
280         const char *ext;
281         int bo_cnt;
282         int bw, bh;
283
284         TDM_RETURN_IF_FAIL(buffer != NULL);
285         TDM_RETURN_IF_FAIL(file != NULL);
286
287         ret = tbm_surface_map(buffer, TBM_OPTION_READ, &info);
288         TDM_RETURN_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE);
289
290         len = strnlen(file, 1024);
291         if (IS_RGB(info.format))
292                 ext = file_exts[0];
293         else
294                 ext = file_exts[1];
295
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);
299                 return;
300         }
301
302         tdm_helper_get_buffer_full_size(buffer, &bw, &bh);
303
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);
310
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);
315                 break;
316         case TBM_FORMAT_YVU420:
317         case TBM_FORMAT_YUV420:
318                 _tdm_helper_dump_raw(file,
319                                                          info.planes[0].ptr,
320                                                          info.planes[0].size,
321                                                          info.planes[1].ptr,
322                                                          info.planes[1].size,
323                                                          info.planes[2].ptr,
324                                                          info.planes[2].size);
325                 break;
326         case TBM_FORMAT_NV12:
327         case TBM_FORMAT_NV21:
328                 _tdm_helper_dump_raw(file,
329                                                          info.planes[0].ptr,
330                                                          info.planes[0].size,
331                                                          info.planes[1].ptr,
332                                                          info.planes[1].size, NULL,
333                                                          0);
334                 break;
335         case TBM_FORMAT_YUYV:
336         case TBM_FORMAT_UYVY:
337                 _tdm_helper_dump_raw(file,
338                                                          info.planes[0].ptr,
339                                                          info.planes[0].size, NULL, 0,
340                                                          NULL, 0);
341                 break;
342         default:
343                 TDM_ERR("can't dump %c%c%c%c buffer", FOURCC_STR(info.format));
344                 tbm_surface_unmap(buffer);
345                 return;
346         }
347
348         tbm_surface_unmap(buffer);
349
350         TDM_INFO("dump %s", file);
351 }
352
353 void
354 tdm_helper_clear_buffer_pos(tbm_surface_h buffer, tdm_pos *pos)
355 {
356         tbm_surface_info_s info;
357         int ret;
358
359         TDM_RETURN_IF_FAIL(buffer != NULL);
360
361         ret = tbm_surface_map(buffer, TBM_OPTION_READ, &info);
362         TDM_RETURN_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE);
363
364         switch (info.format) {
365         case TBM_FORMAT_ARGB8888:
366         case TBM_FORMAT_XRGB8888:
367                 if (!pos) {
368                         memset(info.planes[0].ptr, 0, info.planes[0].stride * info.height);
369                 } else {
370                         unsigned char *p;
371                         int x, y;
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                                         int *ibuf = (int*)p;
376                                         ibuf[x] = 0x00000000;
377                                 }
378                         }
379                 }
380                 break;
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));
386                 break;
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));
391                 break;
392         case TBM_FORMAT_YUYV: {
393                 int *ibuf = (int*)info.planes[0].ptr;
394                 int i, size = info.planes[0].stride * info.height / 4;
395
396                 for (i = 0 ; i < size ; i++)
397                         ibuf[i] = 0x10801080;
398         }
399         break;
400         case TBM_FORMAT_UYVY: {
401                 int *ibuf = (int*)info.planes[0].ptr;
402                 int i, size = info.planes[0].stride * info.height / 4;
403
404                 for (i = 0 ; i < size ; i++)
405                         ibuf[i] = 0x80108010; /* YUYV -> 0xVYUY */
406         }
407         break;
408         default:
409                 TDM_ERR("can't clear %c%c%c%c buffer", FOURCC_STR(info.format));
410                 break;
411         }
412
413         tbm_surface_unmap(buffer);
414 }
415
416 EXTERN void
417 tdm_helper_clear_buffer(tbm_surface_h buffer)
418 {
419         TDM_RETURN_IF_FAIL(buffer != NULL);
420
421         tdm_helper_clear_buffer_pos(buffer, NULL);
422 }
423
424 EXTERN void
425 tdm_helper_get_buffer_full_size(tbm_surface_h buffer, int *buffer_w, int *buffer_h)
426 {
427         tbm_surface_info_s info;
428         int ret;
429
430         TDM_RETURN_IF_FAIL(buffer != NULL);
431
432         ret = tbm_surface_get_info(buffer, &info);
433         TDM_RETURN_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE);
434
435         if (buffer_w) {
436                 if (IS_RGB(info.format))
437                         *buffer_w = info.planes[0].stride >> 2;
438                 else
439                         *buffer_w = info.planes[0].stride;
440         }
441
442         if (buffer_h)
443                 *buffer_h = info.planes[0].size / info.planes[0].stride;
444 }
445
446 static pixman_format_code_t
447 _tdm_helper_pixman_format_get(tbm_format format)
448 {
449         switch (format) {
450         case TBM_FORMAT_ARGB8888:
451                 return PIXMAN_a8r8g8b8;
452         case TBM_FORMAT_XRGB8888:
453                 return PIXMAN_x8r8g8b8;
454         default:
455                 return 0;
456         }
457
458         return 0;
459 }
460
461 EXTERN tdm_error
462 tdm_helper_convert_buffer(tbm_surface_h srcbuf, tbm_surface_h dstbuf,
463                                                   tdm_pos *srcpos, tdm_pos *dstpos,
464                                                   tdm_transform transform, int over)
465 {
466         tbm_surface_info_s src_info, dst_info;
467         pixman_image_t *src_img = NULL, *dst_img = NULL;
468         pixman_format_code_t src_format, dst_format;
469         double scale_x, scale_y;
470         int rotate_step, bos;
471         pixman_transform_t t;
472         struct pixman_f_transform ft;
473         pixman_op_t op;
474         int src_stride, dst_stride;
475         int buf_width, err;
476         tdm_error ret = TDM_ERROR_OPERATION_FAILED;
477
478         TDM_RETURN_VAL_IF_FAIL(srcbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
479         TDM_RETURN_VAL_IF_FAIL(dstbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
480
481         bos = tbm_surface_internal_get_num_bos(srcbuf);
482         TDM_RETURN_VAL_IF_FAIL(bos == 1, TDM_ERROR_OPERATION_FAILED);
483
484         bos = tbm_surface_internal_get_num_bos(dstbuf);
485         TDM_RETURN_VAL_IF_FAIL(bos == 1, TDM_ERROR_OPERATION_FAILED);
486
487         err = tbm_surface_map(srcbuf, TBM_OPTION_READ, &src_info);
488         TDM_RETURN_VAL_IF_FAIL(err == TBM_SURFACE_ERROR_NONE, TDM_ERROR_OPERATION_FAILED);
489
490         err = tbm_surface_map(dstbuf, TBM_OPTION_WRITE, &dst_info);
491         TDM_GOTO_IF_FAIL(err == TBM_SURFACE_ERROR_NONE, unmap_srcbuf);
492
493         /* not handle buffers which have 2 more gem handles */
494         TDM_GOTO_IF_FAIL(src_info.planes[0].ptr != NULL, unmap_dstbuf);
495         TDM_GOTO_IF_FAIL(dst_info.planes[0].ptr != NULL, unmap_dstbuf);
496
497         src_format = _tdm_helper_pixman_format_get(src_info.format);
498         TDM_GOTO_IF_FAIL(src_format > 0, unmap_dstbuf);
499         dst_format = _tdm_helper_pixman_format_get(dst_info.format);
500         TDM_GOTO_IF_FAIL(dst_format > 0, unmap_dstbuf);
501
502         buf_width = src_info.planes[0].stride >> 2;
503         src_stride = src_info.planes[0].stride;
504         src_img = pixman_image_create_bits(src_format, buf_width, src_info.height,
505                                                                            (uint32_t*)src_info.planes[0].ptr, src_stride);
506         TDM_GOTO_IF_FAIL(src_img, unref_img);
507
508         buf_width = dst_info.planes[0].stride >> 2;
509         dst_stride = dst_info.planes[0].stride;
510         dst_img = pixman_image_create_bits(dst_format, buf_width, dst_info.height,
511                                                                            (uint32_t*)dst_info.planes[0].ptr, dst_stride);
512         TDM_GOTO_IF_FAIL(dst_img, unref_img);
513
514         pixman_f_transform_init_identity(&ft);
515
516         if (transform & TDM_TRANSFORM_FLIPPED) {
517                 pixman_f_transform_scale(&ft, NULL, -1, 1);
518                 pixman_f_transform_translate(&ft, NULL, dstpos->w, 0);
519         }
520
521         rotate_step = transform & 0x3;
522         if (rotate_step > 0) {
523                 int c, s, tx = 0, ty = 0;
524                 switch (rotate_step) {
525                 case 1:
526                         c = 0, s = -1, tx = -dstpos->w;
527                         break;
528                 case 2:
529                         c = -1, s = 0, tx = -dstpos->w, ty = -dstpos->h;
530                         break;
531                 case 3:
532                         c = 0, s = 1, ty = -dstpos->h;
533                         break;
534                 }
535                 pixman_f_transform_translate(&ft, NULL, tx, ty);
536                 pixman_f_transform_rotate(&ft, NULL, c, s);
537         }
538
539         if (rotate_step % 2 == 0) {
540                 scale_x = (double)srcpos->w / dstpos->w;
541                 scale_y = (double)srcpos->h / dstpos->h;
542         } else {
543                 scale_x = (double)srcpos->w / dstpos->h;
544                 scale_y = (double)srcpos->h / dstpos->w;
545         }
546
547         pixman_f_transform_scale(&ft, NULL, scale_x, scale_y);
548         pixman_f_transform_translate(&ft, NULL, srcpos->x, srcpos->y);
549         pixman_transform_from_pixman_f_transform(&t, &ft);
550         pixman_image_set_transform(src_img, &t);
551
552         op = (!over) ? PIXMAN_OP_SRC : PIXMAN_OP_OVER;
553
554         pixman_image_composite(op, src_img, NULL, dst_img, 0, 0, 0, 0,
555                                                    dstpos->x, dstpos->y, dstpos->w, dstpos->h);
556
557         ret = TDM_ERROR_NONE;
558
559 unref_img:
560         if (src_img)
561                 pixman_image_unref(src_img);
562         if (dst_img)
563                 pixman_image_unref(dst_img);
564 unmap_dstbuf:
565         tbm_surface_unmap(dstbuf);
566 unmap_srcbuf:
567         tbm_surface_unmap(srcbuf);
568
569         return ret;
570 }
571
572 EXTERN int
573 tdm_helper_get_fd(const char *env)
574 {
575         const char *value;
576         int fd, newfd, flags, ret;
577         char *end;
578         errno = 0;
579
580         value = (const char*)getenv(env);
581         if (!value)
582                 return -1;
583
584         const long int sl = strtol(value, &end, 10);
585         if (end == value) {
586                 TDM_ERR("%s: not a decimal number\n", value);
587                 return -1;
588         } else if (*end != '\0') {
589                 TDM_ERR("%s: extra characters at end of input: %s\n", value, end);
590                 return -1;
591         } else if ((sl == LONG_MIN || sl == LONG_MAX) && errno == ERANGE) {
592                 TDM_ERR("%s out of range of type long\n", value);
593                 return -1;
594         } else if (sl >= INT_MAX) {
595                 TDM_ERR("%ld greater than INT_MAX\n", sl);
596                 return -1;
597         } else if (sl <= INT_MIN) {
598                 TDM_ERR("%ld less than INT_MIN\n", sl);
599                 return -1;
600         } else {
601                 fd = (int)sl;
602                 if (fd < 0) {
603                         TDM_ERR("%d out of fd range\n", fd);
604                         return -1;
605                 }
606         }
607
608         flags = fcntl(fd, F_GETFD);
609         if (flags == -1) {
610                 TDM_ERR("fcntl failed: %m");
611                 return -1;
612         }
613
614         newfd = dup(fd);
615         if (newfd < 0) {
616                 TDM_ERR("dup failed: %m");
617                 return -1;
618         }
619
620         TDM_INFO("%s: fd(%d) newfd(%d)", env, fd, newfd);
621
622         ret = fcntl(newfd, F_SETFD, flags | FD_CLOEXEC);
623         if (ret == -1) {
624                 TDM_ERR("fcntl failed: %m");
625                 close(newfd);
626                 return -1;
627         }
628
629         return newfd;
630 }
631
632 EXTERN void
633 tdm_helper_set_fd(const char *env, int fd)
634 {
635         char buf[32];
636         int ret;
637
638         snprintf(buf, sizeof(buf), "%d", fd);
639
640         ret = setenv(env, (const char*)buf, 1);
641         if (ret) {
642                 TDM_ERR("setenv failed: %m");
643                 return;
644         }
645
646         if (fd >= 0)
647                 TDM_INFO("%s: fd(%d)", env, fd);
648 }
649
650 EXTERN void
651 tdm_helper_dump_start(char *dumppath, int *count)
652 {
653         if (dumppath == NULL || count == NULL) {
654                 TDM_DBG("tdm_helper_dump dumppath or count is null.");
655                 return;
656         }
657
658         tdm_dump_enable = 1;
659
660         TDM_DBG("tdm_helper_dump start.(path : %s)", dumppath);
661 }
662
663 EXTERN void
664 tdm_helper_dump_stop(void)
665 {
666         tdm_dump_enable = 0;
667
668         TDM_DBG("tdm_helper_dump stop.");
669 }
670
671 static tdm_error
672 _tdm_helper_buffer_convert(tbm_surface_h srcbuf, tbm_surface_h dstbuf,
673                                                    int dx, int dy, int dw, int dh, int count)
674 {
675         pixman_image_t *src_img = NULL, *dst_img = NULL;
676         pixman_format_code_t src_format, dst_format;
677         pixman_transform_t t;
678         struct pixman_f_transform ft;
679         pixman_op_t op;
680         tbm_surface_info_s src_info = {0, };
681         tbm_surface_info_s dst_info = {0, };
682         int stride, width;
683         double scale_x, scale_y;
684
685         TDM_RETURN_VAL_IF_FAIL(srcbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
686         TDM_RETURN_VAL_IF_FAIL(dstbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
687
688         if (tbm_surface_map(srcbuf, TBM_SURF_OPTION_READ, &src_info) != TBM_SURFACE_ERROR_NONE) {
689                 TDM_ERR("cannot mmap srcbuf\n");
690                 return TDM_ERROR_OPERATION_FAILED;
691         }
692
693         if (tbm_surface_map(dstbuf, TBM_SURF_OPTION_WRITE, &dst_info) != TBM_SURFACE_ERROR_NONE) {
694                 TDM_ERR("cannot mmap dstbuf\n");
695                 tbm_surface_unmap(srcbuf);
696                 return TDM_ERROR_OPERATION_FAILED;
697         }
698         TDM_GOTO_IF_FAIL(src_info.num_planes == 1, cant_convert);
699         TDM_GOTO_IF_FAIL(dst_info.num_planes == 1, cant_convert);
700
701         /* src */
702         src_format = _tdm_helper_pixman_format_get(src_info.format);
703         TDM_GOTO_IF_FAIL(src_format > 0, cant_convert);
704
705         width = src_info.planes[0].stride / 4;
706         stride = src_info.planes[0].stride;
707         src_img = pixman_image_create_bits(src_format, width, src_info.height,
708                                                                            (uint32_t*)src_info.planes[0].ptr, stride);
709         TDM_GOTO_IF_FAIL(src_img != NULL, cant_convert);
710
711         /* dst */
712         dst_format = _tdm_helper_pixman_format_get(dst_info.format);
713         TDM_GOTO_IF_FAIL(dst_format > 0, cant_convert);
714
715         width = dst_info.planes[0].stride / 4;
716         stride = dst_info.planes[0].stride;
717         dst_img = pixman_image_create_bits(dst_format, width, dst_info.height,
718                                                                            (uint32_t*)dst_info.planes[0].ptr, stride);
719         TDM_GOTO_IF_FAIL(dst_img != NULL, cant_convert);
720
721         pixman_f_transform_init_identity(&ft);
722
723         scale_x = (double)src_info.width / dw;
724         scale_y = (double)src_info.height / dh;
725
726         pixman_f_transform_scale(&ft, NULL, scale_x, scale_y);
727         pixman_f_transform_translate(&ft, NULL, 0, 0);
728         pixman_transform_from_pixman_f_transform(&t, &ft);
729         pixman_image_set_transform(src_img, &t);
730
731         if (count == 0)
732                 op = PIXMAN_OP_SRC;
733         else
734                 op = PIXMAN_OP_OVER;
735
736         pixman_image_composite(op, src_img, NULL, dst_img,
737                                                    0, 0, 0, 0, dx, dy, dw, dh);
738
739         if (src_img)
740                 pixman_image_unref(src_img);
741         if (dst_img)
742                 pixman_image_unref(dst_img);
743
744         tbm_surface_unmap(srcbuf);
745         tbm_surface_unmap(dstbuf);
746
747         return TDM_ERROR_NONE;
748
749 cant_convert:
750         if (src_img)
751                 pixman_image_unref(src_img);
752
753         tbm_surface_unmap(srcbuf);
754         tbm_surface_unmap(dstbuf);
755
756         return TDM_ERROR_OPERATION_FAILED;
757 }
758
759 EXTERN tdm_error
760 tdm_helper_capture_output(tdm_output *output, tbm_surface_h dst_buffer,
761                                                   int x, int y, int w, int h,
762                                                   tdm_helper_capture_handler func, void *data)
763 {
764         tbm_surface_h surface;
765         tdm_error err;
766         int i, count, first = 0;
767
768         TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
769         TDM_RETURN_VAL_IF_FAIL(dst_buffer != NULL, TDM_ERROR_INVALID_PARAMETER);
770         TDM_RETURN_VAL_IF_FAIL(x >= 0, TDM_ERROR_INVALID_PARAMETER);
771         TDM_RETURN_VAL_IF_FAIL(y >= 0, TDM_ERROR_INVALID_PARAMETER);
772         TDM_RETURN_VAL_IF_FAIL(w >= 0, TDM_ERROR_INVALID_PARAMETER);
773         TDM_RETURN_VAL_IF_FAIL(h >= 0, TDM_ERROR_INVALID_PARAMETER);
774         TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
775         TDM_RETURN_VAL_IF_FAIL(data != NULL, TDM_ERROR_INVALID_PARAMETER);
776
777         err = tdm_output_get_layer_count(output, &count);
778         if (err != TDM_ERROR_NONE) {
779                 TDM_ERR("tdm_output_get_layer_count fail(%d)\n", err);
780                 return TDM_ERROR_OPERATION_FAILED;
781         }
782         if (count <= 0) {
783                 TDM_ERR("tdm_output_get_layer_count err(%d, %d)\n", err, count);
784                 return TDM_ERROR_BAD_MODULE;
785         }
786
787         for (i = count - 1; i >= 0; i--) {
788                 tdm_layer *layer = tdm_output_get_layer(output, i, NULL);
789
790                 surface = tdm_layer_get_displaying_buffer(layer, &err);
791                 if (err != TDM_ERROR_NONE)
792                         continue;
793
794                 err = _tdm_helper_buffer_convert(surface, dst_buffer, x, y, w, h, first++);
795                 if (err != TDM_ERROR_NONE)
796                         TDM_DBG("convert fail %d-layer buffer\n", i);
797                 else
798                         TDM_DBG("convert success %d-layer buffer\n", i);
799         }
800
801         func(dst_buffer, data);
802
803         return TDM_ERROR_NONE;
804 }
805
806 EXTERN void
807 tdm_helper_get_display_information(tdm_display *dpy, char *reply, int *len)
808 {
809         tdm_private_display *private_display;
810         tdm_backend_module *module_data;
811         tdm_func_output *func_output;
812         tdm_func_layer *func_layer;
813         tdm_private_output *private_output = NULL;
814         tdm_private_layer *private_layer = NULL;
815         tdm_private_pp *private_pp = NULL;
816         tdm_private_capture *private_capture = NULL;
817         tdm_error ret;
818         int i;
819
820         TDM_DBG_RETURN_IF_FAIL(dpy != NULL);
821
822         private_display = dpy;
823         func_output = &private_display->func_output;
824         func_layer = &private_display->func_layer;
825
826         /* module information */
827         module_data = private_display->module_data;
828         TDM_SNPRINTF(reply, len, "[TDM backend information]\n");
829         TDM_SNPRINTF(reply, len, "name: %s\n", module_data->name);
830         TDM_SNPRINTF(reply, len, "vendor: %s\n", module_data->vendor);
831         TDM_SNPRINTF(reply, len, "version: %d.%d\n\n",
832                                  (int)TDM_BACKEND_GET_ABI_MAJOR(module_data->abi_version),
833                                  (int)TDM_BACKEND_GET_ABI_MINOR(module_data->abi_version));
834
835         /* output information */
836         TDM_SNPRINTF(reply, len, "[Output information]\n");
837         TDM_SNPRINTF(reply, len, "--------------------------------------------------------------------------------------------\n");
838         TDM_SNPRINTF(reply, len, "idx   maker   model   name   type   status   dpms   subpixel   align_w   min   max   phy(mm)\n");
839         TDM_SNPRINTF(reply, len, "--------------------------------------------------------------------------------------------\n");
840         LIST_FOR_EACH_ENTRY(private_output, &private_display->output_list, link) {
841                 TDM_SNPRINTF(reply, len, "%d   %s   %s   %s   %s   %s   %s   %u   %d   %dx%d   %dx%d   %ux%u\n",
842                                          private_output->index, private_output->caps.maker,
843                                          private_output->caps.model, private_output->caps.name,
844                                          tdm_conn_str(private_output->caps.type),
845                                          tdm_status_str(private_output->caps.status),
846                                          tdm_dpms_str(private_output->current_dpms_value),
847                                          private_output->caps.subpixel,
848                                          TDM_FRONT_VALUE(private_output->caps.preferred_align),
849                                          TDM_FRONT_VALUE(private_output->caps.min_w),
850                                          TDM_FRONT_VALUE(private_output->caps.min_h),
851                                          TDM_FRONT_VALUE(private_output->caps.max_w),
852                                          TDM_FRONT_VALUE(private_output->caps.max_h),
853                                          private_output->caps.mmWidth, private_output->caps.mmHeight);
854
855                 TDM_SNPRINTF(reply, len, "\t%u modes:\n", private_output->caps.mode_count);
856
857                 if (private_output->caps.mode_count > 0) {
858                         const tdm_output_mode *current_mode = NULL;
859
860                         TDM_DBG_RETURN_IF_FAIL(func_output->output_get_mode);
861                         ret = func_output->output_get_mode(private_output->output_backend, &current_mode);
862                         TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
863
864                         TDM_SNPRINTF(reply, len, "\t\t name refresh (Hz) clk hdisp hss hse htot vdisp vss vse vtot vscan\n");
865                         for (i = 0; i < private_output->caps.mode_count; i++) {
866                                 char *current = (current_mode == private_output->caps.modes + i) ? "*" : " ";
867                                 TDM_SNPRINTF(reply, len, "\t\t%s%s %u %u %u %u %u %u %u %u %u %u %u ",
868                                                          current,
869                                                          private_output->caps.modes[i].name,
870                                                          private_output->caps.modes[i].vrefresh,
871                                                          private_output->caps.modes[i].clock,
872                                                          private_output->caps.modes[i].hdisplay,
873                                                          private_output->caps.modes[i].hsync_start,
874                                                          private_output->caps.modes[i].hsync_end,
875                                                          private_output->caps.modes[i].htotal,
876                                                          private_output->caps.modes[i].vdisplay,
877                                                          private_output->caps.modes[i].vsync_start,
878                                                          private_output->caps.modes[i].vsync_end,
879                                                          private_output->caps.modes[i].vtotal,
880                                                          private_output->caps.modes[i].vscan);
881                                 tdm_mode_flag_str(private_output->caps.modes[i].flags, &reply, len);
882                                 TDM_SNPRINTF(reply, len, " ");
883                                 tdm_mode_type_str(private_output->caps.modes[i].type, &reply, len);
884                                 TDM_SNPRINTF(reply, len, "\n");
885                         }
886                 }
887
888                 TDM_SNPRINTF(reply, len, "\t%d properties:\n", private_output->caps.prop_count);
889                 if (private_output->caps.prop_count > 0) {
890                         TDM_SNPRINTF(reply, len, "\t\tname\ttype\tidx\tvalue\n");
891                         for (i = 0; i < private_output->caps.prop_count; i++) {
892                                 tdm_value value;
893                                 TDM_DBG_RETURN_IF_FAIL(func_output->output_get_property);
894                                 ret = func_output->output_get_property(private_output->output_backend,
895                                                                                                            private_output->caps.props[i].id,
896                                                                                                            &value);
897                                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
898                                 TDM_SNPRINTF(reply, len, "\t\t%s\t%s\t%u\t",
899                                                          private_output->caps.props[i].name,
900                                                          tdm_value_type_str(private_output->caps.props[i].type),
901                                                          private_output->caps.props[i].id);
902                                 switch (private_output->caps.props[i].type) {
903                                 case TDM_VALUE_TYPE_PTR:
904                                         TDM_SNPRINTF(reply, len, "%p\n", value.ptr);
905                                         break;
906                                 case TDM_VALUE_TYPE_INT32:
907                                         TDM_SNPRINTF(reply, len, "%d\n", value.s32);
908                                         break;
909                                 case TDM_VALUE_TYPE_INT64:
910                                         TDM_SNPRINTF(reply, len, "%"PRId64"\n", value.s64);
911                                         break;
912                                 case TDM_VALUE_TYPE_UINT64:
913                                         TDM_SNPRINTF(reply, len, "%"PRIu64"\n", value.u64);
914                                         break;
915                                 case TDM_VALUE_TYPE_UINT32:
916                                 default:
917                                         TDM_SNPRINTF(reply, len, "%u\n", value.u32);
918                                         break;
919                                 }
920                         }
921                 }
922         }
923         TDM_SNPRINTF(reply, len, "\n");
924
925         /* layer information */
926         TDM_SNPRINTF(reply, len, "[Layer information]\n");
927         TDM_SNPRINTF(reply, len, "-----------------------------------------------------------------------\n");
928         TDM_SNPRINTF(reply, len, "idx   output   zpos   buf   format   size   crop   geometry   transform\n");
929         TDM_SNPRINTF(reply, len, "-----------------------------------------------------------------------\n");
930         LIST_FOR_EACH_ENTRY(private_output, &private_display->output_list, link) {
931                 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
932                         if (!private_layer->usable) {
933                                 tdm_info_layer info;
934                                 unsigned int format;
935                                 tdm_size size;
936                                 tbm_surface_info_s buf_info;
937
938                                 TDM_DBG_RETURN_IF_FAIL(func_layer->layer_get_info);
939                                 memset(&info, 0, sizeof info);
940                                 ret = func_layer->layer_get_info(private_layer->layer_backend, &info);
941                                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
942
943                                 if (!private_layer->showing_buffer)
944                                         continue;
945
946                                 format = tbm_surface_get_format(private_layer->showing_buffer->buffer);
947                                 tbm_surface_get_info(private_layer->showing_buffer->buffer, &buf_info);
948
949                                 if (IS_RGB(format))
950                                         size.h = buf_info.planes[0].stride >> 2;
951                                 else
952                                         size.h = buf_info.planes[0].stride;
953                                 size.v = tbm_surface_get_height(private_layer->showing_buffer->buffer);
954
955                                 if (info.src_config.format)
956                                         format = (info.src_config.format) ? : format;
957
958                                 TDM_SNPRINTF(reply, len, "%d   %d   %d   %p   %c%c%c%c   %ux%u   %ux%u+%u+%u   %ux%u+%u+%u   %s\n",
959                                                          private_layer->index,
960                                                          private_output->index,
961                                                          private_layer->caps.zpos,
962                                                          private_layer->showing_buffer->buffer, FOURCC_STR(format), size.h, size.v,
963                                                          info.src_config.pos.w, info.src_config.pos.h, info.src_config.pos.x, info.src_config.pos.y,
964                                                          info.dst_pos.w, info.dst_pos.h, info.dst_pos.x, info.dst_pos.y,
965                                                          tdm_transform_str(info.transform));
966                         } else {
967                                 TDM_SNPRINTF(reply, len, "%d   %d   %d   -\n",
968                                                          private_layer->index,
969                                                          private_output->index,
970                                                          private_layer->caps.zpos);
971                         }
972
973                         TDM_SNPRINTF(reply, len, "\tcaps\t: ");
974                         tdm_layer_caps_str(private_layer->caps.capabilities, &reply, len);
975                         TDM_SNPRINTF(reply, len, "\n");
976
977                         TDM_SNPRINTF(reply, len, "\tformats\t: ");
978                         if (private_layer->caps.format_count > 0) {
979                                 const char *sep = "";
980                                 for (i = 0; i < private_layer->caps.format_count; i++) {
981                                         if (private_layer->caps.formats[i] == 0)
982                                                 continue;
983                                         TDM_SNPRINTF(reply, len, "%s%c%c%c%c", sep, FOURCC_STR(private_layer->caps.formats[i]));
984                                         sep = ",";
985                                 }
986                                 TDM_SNPRINTF(reply, len, "\n");
987                         }
988
989                         TDM_SNPRINTF(reply, len, "\t%u properties:\n", private_layer->caps.prop_count);
990                         if (private_layer->caps.prop_count > 0) {
991                                 TDM_SNPRINTF(reply, len, "\t\tname\ttype\tidx\tvalue\n");
992                                 for (i = 0; i < private_layer->caps.prop_count; i++) {
993                                         tdm_value value;
994                                         TDM_DBG_RETURN_IF_FAIL(func_layer->layer_get_property);
995                                         ret = func_layer->layer_get_property(private_layer->layer_backend,
996                                                                                                                  private_layer->caps.props[i].id,
997                                                                                                                  &value);
998                                         TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
999                                         TDM_SNPRINTF(reply, len, "\t\t%s\t%s\t%u\t",
1000                                                                  private_layer->caps.props[i].name,
1001                                                                  tdm_value_type_str(private_output->caps.props[i].type),
1002                                                                  private_layer->caps.props[i].id);
1003                                 switch (private_layer->caps.props[i].type) {
1004                                 case TDM_VALUE_TYPE_PTR:
1005                                         TDM_SNPRINTF(reply, len, "%p\n", value.ptr);
1006                                         break;
1007                                 case TDM_VALUE_TYPE_INT32:
1008                                         TDM_SNPRINTF(reply, len, "%d\n", value.s32);
1009                                         break;
1010                                 case TDM_VALUE_TYPE_INT64:
1011                                         TDM_SNPRINTF(reply, len, "%"PRId64"\n", value.s64);
1012                                         break;
1013                                 case TDM_VALUE_TYPE_UINT64:
1014                                         TDM_SNPRINTF(reply, len, "%"PRIu64"\n", value.u64);
1015                                         break;
1016                                 case TDM_VALUE_TYPE_UINT32:
1017                                 default:
1018                                         TDM_SNPRINTF(reply, len, "%u\n", value.u32);
1019                                         break;
1020                                 }
1021                                 }
1022                         }
1023                 }
1024         }
1025         TDM_SNPRINTF(reply, len, "\n");
1026
1027         if (private_display->capabilities & TDM_DISPLAY_CAPABILITY_PP) {
1028                 const char *sep = "";
1029                 TDM_SNPRINTF(reply, len, "[PP information]\n");
1030                 TDM_SNPRINTF(reply, len, "caps\t: ");
1031                 tdm_pp_caps_str(private_display->caps_pp.capabilities, &reply, len);
1032                 TDM_SNPRINTF(reply, len, "\n");
1033                 TDM_SNPRINTF(reply, len, "formats\t: ");
1034                 for (i = 0; i < private_display->caps_pp.format_count; i++) {
1035                         if (private_display->caps_pp.formats[i] == 0)
1036                                 continue;
1037                         TDM_SNPRINTF(reply, len, "%s%c%c%c%c", sep, FOURCC_STR(private_display->caps_pp.formats[i]));
1038                         sep = ",";
1039                 }
1040                 TDM_SNPRINTF(reply, len, "\n");
1041                 TDM_SNPRINTF(reply, len, "size\t: min(%dx%d) max(%dx%d) align_w(%d)\n",
1042                                          TDM_FRONT_VALUE(private_display->caps_pp.min_w),
1043                                          TDM_FRONT_VALUE(private_display->caps_pp.min_h),
1044                                          TDM_FRONT_VALUE(private_display->caps_pp.max_w),
1045                                          TDM_FRONT_VALUE(private_display->caps_pp.max_h),
1046                                          TDM_FRONT_VALUE(private_display->caps_pp.preferred_align));
1047                 if (!LIST_IS_EMPTY(&private_display->pp_list)) {
1048                         TDM_SNPRINTF(reply, len, "-------------------------------------------------------------\n");
1049                         TDM_SNPRINTF(reply, len, "src(format size crop)  |  dst(format size crop)  |  transform\n");
1050                         TDM_SNPRINTF(reply, len, "-------------------------------------------------------------\n");
1051                         LIST_FOR_EACH_ENTRY(private_pp, &private_display->pp_list, link) {
1052                                 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",
1053                                                          FOURCC_STR(private_pp->info.src_config.format),
1054                                                          private_pp->info.src_config.size.h,
1055                                                          private_pp->info.src_config.size.v,
1056                                                          private_pp->info.src_config.pos.x, private_pp->info.src_config.pos.y,
1057                                                          private_pp->info.src_config.pos.w, private_pp->info.src_config.pos.h,
1058                                                          FOURCC_STR(private_pp->info.dst_config.format),
1059                                                          private_pp->info.dst_config.size.h,
1060                                                          private_pp->info.dst_config.size.v,
1061                                                          private_pp->info.dst_config.pos.x, private_pp->info.dst_config.pos.y,
1062                                                          private_pp->info.dst_config.pos.w, private_pp->info.dst_config.pos.h,
1063                                                          tdm_transform_str(private_pp->info.transform));
1064                         }
1065                 }
1066         } else {
1067                 TDM_SNPRINTF(reply, len, "[No PP capability]\n");
1068         }
1069         TDM_SNPRINTF(reply, len, "\n");
1070
1071         if (private_display->capabilities & TDM_DISPLAY_CAPABILITY_CAPTURE) {
1072                 const char *sep = "";
1073                 TDM_SNPRINTF(reply, len, "[Capture information]\n");
1074                 TDM_SNPRINTF(reply, len, "caps\t: ");
1075                 tdm_capture_caps_str(private_display->caps_capture.capabilities, &reply, len);
1076                 TDM_SNPRINTF(reply, len, "\n");
1077                 TDM_SNPRINTF(reply, len, "formats\t: ");
1078                 for (i = 0; i < private_display->caps_capture.format_count; i++) {
1079                         if (private_display->caps_capture.formats[i] == 0)
1080                                 continue;
1081                         TDM_SNPRINTF(reply, len, "%s%c%c%c%c", sep, FOURCC_STR(private_display->caps_capture.formats[i]));
1082                         sep = ",";
1083                 }
1084                 TDM_SNPRINTF(reply, len, "\n");
1085                 TDM_SNPRINTF(reply, len, "size\t: min(%dx%d) max(%dx%d) align_w(%d)\n",
1086                                          TDM_FRONT_VALUE(private_display->caps_capture.min_w),
1087                                          TDM_FRONT_VALUE(private_display->caps_capture.min_h),
1088                                          TDM_FRONT_VALUE(private_display->caps_capture.max_w),
1089                                          TDM_FRONT_VALUE(private_display->caps_capture.max_h),
1090                                          TDM_FRONT_VALUE(private_display->caps_capture.preferred_align));
1091                 if (!LIST_IS_EMPTY(&private_display->capture_list)) {
1092                         TDM_SNPRINTF(reply, len, "-----------------------------------\n");
1093                         TDM_SNPRINTF(reply, len, "dst(format size crop)  |  transform\n");
1094                         TDM_SNPRINTF(reply, len, "-----------------------------------\n");
1095                         LIST_FOR_EACH_ENTRY(private_capture, &private_display->capture_list, link) {
1096                                 TDM_SNPRINTF(reply, len, "%c%c%c%c %ux%u %ux%u+%u+%u | %s\n",
1097                                                          FOURCC_STR(private_capture->info.dst_config.format),
1098                                                          private_capture->info.dst_config.size.h,
1099                                                          private_capture->info.dst_config.size.v,
1100                                                          private_capture->info.dst_config.pos.x, private_capture->info.dst_config.pos.y,
1101                                                          private_capture->info.dst_config.pos.w, private_capture->info.dst_config.pos.h,
1102                                                          tdm_transform_str(private_capture->info.transform));
1103                         }
1104                 }
1105         } else {
1106                 TDM_SNPRINTF(reply, len, "[No Capture capability]\n");
1107         }
1108         TDM_SNPRINTF(reply, len, "\n");
1109 }
1110
1111 EXTERN int
1112 tdm_helper_commit_per_vblank_enabled(tdm_display *dpy)
1113 {
1114         tdm_private_display *private_display;
1115
1116         TDM_RETURN_VAL_IF_FAIL(dpy != NULL, 0);
1117
1118         private_display = dpy;
1119
1120         return private_display->commit_per_vblank;
1121 }
1122