add tdm_helper_clear_buffer_color function
[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 EXTERN void
354 tdm_helper_clear_buffer_color(tbm_surface_h buffer, tdm_pos *pos, unsigned int color)
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                                         unsigned int *ibuf = (unsigned int*)p;
376                                         ibuf[x] = color;
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_pos(tbm_surface_h buffer, tdm_pos *pos)
418 {
419         TDM_RETURN_IF_FAIL(buffer != NULL);
420
421         tdm_helper_clear_buffer_color(buffer, pos, 0);
422 }
423
424 EXTERN void
425 tdm_helper_clear_buffer(tbm_surface_h buffer)
426 {
427         TDM_RETURN_IF_FAIL(buffer != NULL);
428
429         tdm_helper_clear_buffer_pos(buffer, NULL);
430 }
431
432 EXTERN void
433 tdm_helper_get_buffer_full_size(tbm_surface_h buffer, int *buffer_w, int *buffer_h)
434 {
435         tbm_surface_info_s info;
436         int ret;
437
438         TDM_RETURN_IF_FAIL(buffer != NULL);
439
440         ret = tbm_surface_get_info(buffer, &info);
441         TDM_RETURN_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE);
442
443         if (buffer_w) {
444                 if (IS_RGB(info.format))
445                         *buffer_w = info.planes[0].stride >> 2;
446                 else
447                         *buffer_w = info.planes[0].stride;
448         }
449
450         if (buffer_h)
451                 *buffer_h = info.planes[0].size / info.planes[0].stride;
452 }
453
454 static pixman_format_code_t
455 _tdm_helper_pixman_format_get(tbm_format format)
456 {
457         switch (format) {
458         case TBM_FORMAT_ARGB8888:
459                 return PIXMAN_a8r8g8b8;
460         case TBM_FORMAT_XRGB8888:
461                 return PIXMAN_x8r8g8b8;
462         default:
463                 return 0;
464         }
465
466         return 0;
467 }
468
469 EXTERN tdm_error
470 tdm_helper_convert_buffer(tbm_surface_h srcbuf, tbm_surface_h dstbuf,
471                                                   tdm_pos *srcpos, tdm_pos *dstpos,
472                                                   tdm_transform transform, int over)
473 {
474         tbm_surface_info_s src_info, dst_info;
475         pixman_image_t *src_img = NULL, *dst_img = NULL;
476         pixman_format_code_t src_format, dst_format;
477         double scale_x, scale_y;
478         int rotate_step, bos;
479         pixman_transform_t t;
480         struct pixman_f_transform ft;
481         pixman_op_t op;
482         int src_stride, dst_stride;
483         int buf_width, err;
484         tdm_error ret = TDM_ERROR_OPERATION_FAILED;
485
486         TDM_RETURN_VAL_IF_FAIL(srcbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
487         TDM_RETURN_VAL_IF_FAIL(dstbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
488
489         bos = tbm_surface_internal_get_num_bos(srcbuf);
490         TDM_RETURN_VAL_IF_FAIL(bos == 1, TDM_ERROR_OPERATION_FAILED);
491
492         bos = tbm_surface_internal_get_num_bos(dstbuf);
493         TDM_RETURN_VAL_IF_FAIL(bos == 1, TDM_ERROR_OPERATION_FAILED);
494
495         err = tbm_surface_map(srcbuf, TBM_OPTION_READ, &src_info);
496         TDM_RETURN_VAL_IF_FAIL(err == TBM_SURFACE_ERROR_NONE, TDM_ERROR_OPERATION_FAILED);
497
498         err = tbm_surface_map(dstbuf, TBM_OPTION_WRITE, &dst_info);
499         TDM_GOTO_IF_FAIL(err == TBM_SURFACE_ERROR_NONE, unmap_srcbuf);
500
501         /* not handle buffers which have 2 more gem handles */
502         TDM_GOTO_IF_FAIL(src_info.planes[0].ptr != NULL, unmap_dstbuf);
503         TDM_GOTO_IF_FAIL(dst_info.planes[0].ptr != NULL, unmap_dstbuf);
504
505         src_format = _tdm_helper_pixman_format_get(src_info.format);
506         TDM_GOTO_IF_FAIL(src_format > 0, unmap_dstbuf);
507         dst_format = _tdm_helper_pixman_format_get(dst_info.format);
508         TDM_GOTO_IF_FAIL(dst_format > 0, unmap_dstbuf);
509
510         buf_width = src_info.planes[0].stride >> 2;
511         src_stride = src_info.planes[0].stride;
512         src_img = pixman_image_create_bits(src_format, buf_width, src_info.height,
513                                                                            (uint32_t*)src_info.planes[0].ptr, src_stride);
514         TDM_GOTO_IF_FAIL(src_img, unref_img);
515
516         buf_width = dst_info.planes[0].stride >> 2;
517         dst_stride = dst_info.planes[0].stride;
518         dst_img = pixman_image_create_bits(dst_format, buf_width, dst_info.height,
519                                                                            (uint32_t*)dst_info.planes[0].ptr, dst_stride);
520         TDM_GOTO_IF_FAIL(dst_img, unref_img);
521
522         pixman_f_transform_init_identity(&ft);
523
524         if (transform & TDM_TRANSFORM_FLIPPED) {
525                 pixman_f_transform_scale(&ft, NULL, -1, 1);
526                 pixman_f_transform_translate(&ft, NULL, dstpos->w, 0);
527         }
528
529         rotate_step = transform & 0x3;
530         if (rotate_step > 0) {
531                 int c, s, tx = 0, ty = 0;
532                 switch (rotate_step) {
533                 case 1:
534                         c = 0, s = -1, tx = -dstpos->w;
535                         break;
536                 case 2:
537                         c = -1, s = 0, tx = -dstpos->w, ty = -dstpos->h;
538                         break;
539                 case 3:
540                         c = 0, s = 1, ty = -dstpos->h;
541                         break;
542                 }
543                 pixman_f_transform_translate(&ft, NULL, tx, ty);
544                 pixman_f_transform_rotate(&ft, NULL, c, s);
545         }
546
547         if (rotate_step % 2 == 0) {
548                 scale_x = (double)srcpos->w / dstpos->w;
549                 scale_y = (double)srcpos->h / dstpos->h;
550         } else {
551                 scale_x = (double)srcpos->w / dstpos->h;
552                 scale_y = (double)srcpos->h / dstpos->w;
553         }
554
555         pixman_f_transform_scale(&ft, NULL, scale_x, scale_y);
556         pixman_f_transform_translate(&ft, NULL, srcpos->x, srcpos->y);
557         pixman_transform_from_pixman_f_transform(&t, &ft);
558         pixman_image_set_transform(src_img, &t);
559
560         op = (!over) ? PIXMAN_OP_SRC : PIXMAN_OP_OVER;
561
562         pixman_image_composite(op, src_img, NULL, dst_img, 0, 0, 0, 0,
563                                                    dstpos->x, dstpos->y, dstpos->w, dstpos->h);
564
565         ret = TDM_ERROR_NONE;
566
567 unref_img:
568         if (src_img)
569                 pixman_image_unref(src_img);
570         if (dst_img)
571                 pixman_image_unref(dst_img);
572 unmap_dstbuf:
573         tbm_surface_unmap(dstbuf);
574 unmap_srcbuf:
575         tbm_surface_unmap(srcbuf);
576
577         return ret;
578 }
579
580 EXTERN int
581 tdm_helper_get_fd(const char *env)
582 {
583         const char *value;
584         int fd, newfd, flags, ret;
585         char *end;
586         errno = 0;
587
588         value = (const char*)getenv(env);
589         if (!value)
590                 return -1;
591
592         const long int sl = strtol(value, &end, 10);
593         if (end == value) {
594                 TDM_ERR("%s: not a decimal number\n", value);
595                 return -1;
596         } else if (*end != '\0') {
597                 TDM_ERR("%s: extra characters at end of input: %s\n", value, end);
598                 return -1;
599         } else if ((sl == LONG_MIN || sl == LONG_MAX) && errno == ERANGE) {
600                 TDM_ERR("%s out of range of type long\n", value);
601                 return -1;
602         } else if (sl >= INT_MAX) {
603                 TDM_ERR("%ld greater than INT_MAX\n", sl);
604                 return -1;
605         } else if (sl <= INT_MIN) {
606                 TDM_ERR("%ld less than INT_MIN\n", sl);
607                 return -1;
608         } else {
609                 fd = (int)sl;
610                 if (fd < 0) {
611                         TDM_ERR("%d out of fd range\n", fd);
612                         return -1;
613                 }
614         }
615
616         flags = fcntl(fd, F_GETFD);
617         if (flags == -1) {
618                 TDM_ERR("fcntl failed: %m");
619                 return -1;
620         }
621
622         newfd = dup(fd);
623         if (newfd < 0) {
624                 TDM_ERR("dup failed: %m");
625                 return -1;
626         }
627
628         TDM_INFO("%s: fd(%d) newfd(%d)", env, fd, newfd);
629
630         ret = fcntl(newfd, F_SETFD, flags | FD_CLOEXEC);
631         if (ret == -1) {
632                 TDM_ERR("fcntl failed: %m");
633                 close(newfd);
634                 return -1;
635         }
636
637         return newfd;
638 }
639
640 EXTERN void
641 tdm_helper_set_fd(const char *env, int fd)
642 {
643         char buf[32];
644         int ret;
645
646         snprintf(buf, sizeof(buf), "%d", fd);
647
648         ret = setenv(env, (const char*)buf, 1);
649         if (ret) {
650                 TDM_ERR("setenv failed: %m");
651                 return;
652         }
653
654         if (fd >= 0)
655                 TDM_INFO("%s: fd(%d)", env, fd);
656 }
657
658 EXTERN void
659 tdm_helper_dump_start(char *dumppath, int *count)
660 {
661         if (dumppath == NULL || count == NULL) {
662                 TDM_DBG("tdm_helper_dump dumppath or count is null.");
663                 return;
664         }
665
666         tdm_dump_enable = 1;
667
668         TDM_DBG("tdm_helper_dump start.(path : %s)", dumppath);
669 }
670
671 EXTERN void
672 tdm_helper_dump_stop(void)
673 {
674         tdm_dump_enable = 0;
675
676         TDM_DBG("tdm_helper_dump stop.");
677 }
678
679 static tdm_error
680 _tdm_helper_buffer_convert(tbm_surface_h srcbuf, tbm_surface_h dstbuf,
681                                                    int dx, int dy, int dw, int dh, int count)
682 {
683         pixman_image_t *src_img = NULL, *dst_img = NULL;
684         pixman_format_code_t src_format, dst_format;
685         pixman_transform_t t;
686         struct pixman_f_transform ft;
687         pixman_op_t op;
688         tbm_surface_info_s src_info = {0, };
689         tbm_surface_info_s dst_info = {0, };
690         int stride, width;
691         double scale_x, scale_y;
692
693         TDM_RETURN_VAL_IF_FAIL(srcbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
694         TDM_RETURN_VAL_IF_FAIL(dstbuf != NULL, TDM_ERROR_INVALID_PARAMETER);
695
696         if (tbm_surface_map(srcbuf, TBM_SURF_OPTION_READ, &src_info) != TBM_SURFACE_ERROR_NONE) {
697                 TDM_ERR("cannot mmap srcbuf\n");
698                 return TDM_ERROR_OPERATION_FAILED;
699         }
700
701         if (tbm_surface_map(dstbuf, TBM_SURF_OPTION_WRITE, &dst_info) != TBM_SURFACE_ERROR_NONE) {
702                 TDM_ERR("cannot mmap dstbuf\n");
703                 tbm_surface_unmap(srcbuf);
704                 return TDM_ERROR_OPERATION_FAILED;
705         }
706         TDM_GOTO_IF_FAIL(src_info.num_planes == 1, cant_convert);
707         TDM_GOTO_IF_FAIL(dst_info.num_planes == 1, cant_convert);
708
709         /* src */
710         src_format = _tdm_helper_pixman_format_get(src_info.format);
711         TDM_GOTO_IF_FAIL(src_format > 0, cant_convert);
712
713         width = src_info.planes[0].stride / 4;
714         stride = src_info.planes[0].stride;
715         src_img = pixman_image_create_bits(src_format, width, src_info.height,
716                                                                            (uint32_t*)src_info.planes[0].ptr, stride);
717         TDM_GOTO_IF_FAIL(src_img != NULL, cant_convert);
718
719         /* dst */
720         dst_format = _tdm_helper_pixman_format_get(dst_info.format);
721         TDM_GOTO_IF_FAIL(dst_format > 0, cant_convert);
722
723         width = dst_info.planes[0].stride / 4;
724         stride = dst_info.planes[0].stride;
725         dst_img = pixman_image_create_bits(dst_format, width, dst_info.height,
726                                                                            (uint32_t*)dst_info.planes[0].ptr, stride);
727         TDM_GOTO_IF_FAIL(dst_img != NULL, cant_convert);
728
729         pixman_f_transform_init_identity(&ft);
730
731         scale_x = (double)src_info.width / dw;
732         scale_y = (double)src_info.height / dh;
733
734         pixman_f_transform_scale(&ft, NULL, scale_x, scale_y);
735         pixman_f_transform_translate(&ft, NULL, 0, 0);
736         pixman_transform_from_pixman_f_transform(&t, &ft);
737         pixman_image_set_transform(src_img, &t);
738
739         if (count == 0)
740                 op = PIXMAN_OP_SRC;
741         else
742                 op = PIXMAN_OP_OVER;
743
744         pixman_image_composite(op, src_img, NULL, dst_img,
745                                                    0, 0, 0, 0, dx, dy, dw, dh);
746
747         if (src_img)
748                 pixman_image_unref(src_img);
749         if (dst_img)
750                 pixman_image_unref(dst_img);
751
752         tbm_surface_unmap(srcbuf);
753         tbm_surface_unmap(dstbuf);
754
755         return TDM_ERROR_NONE;
756
757 cant_convert:
758         if (src_img)
759                 pixman_image_unref(src_img);
760
761         tbm_surface_unmap(srcbuf);
762         tbm_surface_unmap(dstbuf);
763
764         return TDM_ERROR_OPERATION_FAILED;
765 }
766
767 EXTERN tdm_error
768 tdm_helper_capture_output(tdm_output *output, tbm_surface_h dst_buffer,
769                                                   int x, int y, int w, int h,
770                                                   tdm_helper_capture_handler func, void *data)
771 {
772         tbm_surface_h surface;
773         tdm_error err;
774         int i, count, first = 0;
775
776         TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
777         TDM_RETURN_VAL_IF_FAIL(dst_buffer != NULL, TDM_ERROR_INVALID_PARAMETER);
778         TDM_RETURN_VAL_IF_FAIL(x >= 0, TDM_ERROR_INVALID_PARAMETER);
779         TDM_RETURN_VAL_IF_FAIL(y >= 0, TDM_ERROR_INVALID_PARAMETER);
780         TDM_RETURN_VAL_IF_FAIL(w >= 0, TDM_ERROR_INVALID_PARAMETER);
781         TDM_RETURN_VAL_IF_FAIL(h >= 0, TDM_ERROR_INVALID_PARAMETER);
782         TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
783         TDM_RETURN_VAL_IF_FAIL(data != NULL, TDM_ERROR_INVALID_PARAMETER);
784
785         err = tdm_output_get_layer_count(output, &count);
786         if (err != TDM_ERROR_NONE) {
787                 TDM_ERR("tdm_output_get_layer_count fail(%d)\n", err);
788                 return TDM_ERROR_OPERATION_FAILED;
789         }
790         if (count <= 0) {
791                 TDM_ERR("tdm_output_get_layer_count err(%d, %d)\n", err, count);
792                 return TDM_ERROR_BAD_MODULE;
793         }
794
795         for (i = count - 1; i >= 0; i--) {
796                 tdm_layer *layer = tdm_output_get_layer(output, i, NULL);
797
798                 surface = tdm_layer_get_displaying_buffer(layer, &err);
799                 if (err != TDM_ERROR_NONE)
800                         continue;
801
802                 err = _tdm_helper_buffer_convert(surface, dst_buffer, x, y, w, h, first++);
803                 if (err != TDM_ERROR_NONE)
804                         TDM_DBG("convert fail %d-layer buffer\n", i);
805                 else
806                         TDM_DBG("convert success %d-layer buffer\n", i);
807         }
808
809         func(dst_buffer, data);
810
811         return TDM_ERROR_NONE;
812 }
813
814 EXTERN void
815 tdm_helper_get_display_information(tdm_display *dpy, char *reply, int *len)
816 {
817         tdm_private_display *private_display;
818         tdm_backend_module *module_data;
819         tdm_func_output *func_output;
820         tdm_func_layer *func_layer;
821         tdm_private_output *private_output = NULL;
822         tdm_private_layer *private_layer = NULL;
823         tdm_private_pp *private_pp = NULL;
824         tdm_private_capture *private_capture = NULL;
825         tdm_error ret;
826         int i;
827
828         TDM_DBG_RETURN_IF_FAIL(dpy != NULL);
829
830         private_display = dpy;
831         func_output = &private_display->func_output;
832         func_layer = &private_display->func_layer;
833
834         /* module information */
835         module_data = private_display->module_data;
836         TDM_SNPRINTF(reply, len, "[TDM backend information]\n");
837         TDM_SNPRINTF(reply, len, "name: %s\n", module_data->name);
838         TDM_SNPRINTF(reply, len, "vendor: %s\n", module_data->vendor);
839         TDM_SNPRINTF(reply, len, "version: %d.%d\n\n",
840                                  (int)TDM_BACKEND_GET_ABI_MAJOR(module_data->abi_version),
841                                  (int)TDM_BACKEND_GET_ABI_MINOR(module_data->abi_version));
842
843         /* output information */
844         TDM_SNPRINTF(reply, len, "[Output information]\n");
845         TDM_SNPRINTF(reply, len, "--------------------------------------------------------------------------------------------\n");
846         TDM_SNPRINTF(reply, len, "idx   maker   model   name   type   status   dpms   subpixel   align_w   min   max   phy(mm)\n");
847         TDM_SNPRINTF(reply, len, "--------------------------------------------------------------------------------------------\n");
848         LIST_FOR_EACH_ENTRY(private_output, &private_display->output_list, link) {
849                 TDM_SNPRINTF(reply, len, "%d   %s   %s   %s   %s   %s   %s   %u   %d   %dx%d   %dx%d   %ux%u\n",
850                                          private_output->index, private_output->caps.maker,
851                                          private_output->caps.model, private_output->caps.name,
852                                          tdm_conn_str(private_output->caps.type),
853                                          tdm_status_str(private_output->caps.status),
854                                          tdm_dpms_str(private_output->current_dpms_value),
855                                          private_output->caps.subpixel,
856                                          TDM_FRONT_VALUE(private_output->caps.preferred_align),
857                                          TDM_FRONT_VALUE(private_output->caps.min_w),
858                                          TDM_FRONT_VALUE(private_output->caps.min_h),
859                                          TDM_FRONT_VALUE(private_output->caps.max_w),
860                                          TDM_FRONT_VALUE(private_output->caps.max_h),
861                                          private_output->caps.mmWidth, private_output->caps.mmHeight);
862
863                 TDM_SNPRINTF(reply, len, "\t%u modes:\n", private_output->caps.mode_count);
864
865                 if (private_output->caps.mode_count > 0) {
866                         const tdm_output_mode *current_mode = NULL;
867
868                         TDM_DBG_RETURN_IF_FAIL(func_output->output_get_mode);
869                         ret = func_output->output_get_mode(private_output->output_backend, &current_mode);
870                         TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
871
872                         TDM_SNPRINTF(reply, len, "\t\t name refresh (Hz) clk hdisp hss hse htot vdisp vss vse vtot vscan\n");
873                         for (i = 0; i < private_output->caps.mode_count; i++) {
874                                 char *current = (current_mode == private_output->caps.modes + i) ? "*" : " ";
875                                 TDM_SNPRINTF(reply, len, "\t\t%s%s %u %u %u %u %u %u %u %u %u %u %u ",
876                                                          current,
877                                                          private_output->caps.modes[i].name,
878                                                          private_output->caps.modes[i].vrefresh,
879                                                          private_output->caps.modes[i].clock,
880                                                          private_output->caps.modes[i].hdisplay,
881                                                          private_output->caps.modes[i].hsync_start,
882                                                          private_output->caps.modes[i].hsync_end,
883                                                          private_output->caps.modes[i].htotal,
884                                                          private_output->caps.modes[i].vdisplay,
885                                                          private_output->caps.modes[i].vsync_start,
886                                                          private_output->caps.modes[i].vsync_end,
887                                                          private_output->caps.modes[i].vtotal,
888                                                          private_output->caps.modes[i].vscan);
889                                 tdm_mode_flag_str(private_output->caps.modes[i].flags, &reply, len);
890                                 TDM_SNPRINTF(reply, len, " ");
891                                 tdm_mode_type_str(private_output->caps.modes[i].type, &reply, len);
892                                 TDM_SNPRINTF(reply, len, "\n");
893                         }
894                 }
895
896                 TDM_SNPRINTF(reply, len, "\t%d properties:\n", private_output->caps.prop_count);
897                 if (private_output->caps.prop_count > 0) {
898                         TDM_SNPRINTF(reply, len, "\t\tname\ttype\tidx\tvalue\n");
899                         for (i = 0; i < private_output->caps.prop_count; i++) {
900                                 tdm_value value;
901                                 TDM_DBG_RETURN_IF_FAIL(func_output->output_get_property);
902                                 ret = func_output->output_get_property(private_output->output_backend,
903                                                                                                            private_output->caps.props[i].id,
904                                                                                                            &value);
905                                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
906                                 TDM_SNPRINTF(reply, len, "\t\t%s\t%s\t%u\t",
907                                                          private_output->caps.props[i].name,
908                                                          tdm_value_type_str(private_output->caps.props[i].type),
909                                                          private_output->caps.props[i].id);
910                                 switch (private_output->caps.props[i].type) {
911                                 case TDM_VALUE_TYPE_PTR:
912                                         TDM_SNPRINTF(reply, len, "%p\n", value.ptr);
913                                         break;
914                                 case TDM_VALUE_TYPE_INT32:
915                                         TDM_SNPRINTF(reply, len, "%d\n", value.s32);
916                                         break;
917                                 case TDM_VALUE_TYPE_INT64:
918                                         TDM_SNPRINTF(reply, len, "%"PRId64"\n", value.s64);
919                                         break;
920                                 case TDM_VALUE_TYPE_UINT64:
921                                         TDM_SNPRINTF(reply, len, "%"PRIu64"\n", value.u64);
922                                         break;
923                                 case TDM_VALUE_TYPE_UINT32:
924                                 default:
925                                         TDM_SNPRINTF(reply, len, "%u\n", value.u32);
926                                         break;
927                                 }
928                         }
929                 }
930         }
931         TDM_SNPRINTF(reply, len, "\n");
932
933         /* layer information */
934         TDM_SNPRINTF(reply, len, "[Layer information]\n");
935         TDM_SNPRINTF(reply, len, "-----------------------------------------------------------------------\n");
936         TDM_SNPRINTF(reply, len, "idx   output   zpos   buf   format   size   crop   geometry   transform\n");
937         TDM_SNPRINTF(reply, len, "-----------------------------------------------------------------------\n");
938         LIST_FOR_EACH_ENTRY(private_output, &private_display->output_list, link) {
939                 LIST_FOR_EACH_ENTRY(private_layer, &private_output->layer_list, link) {
940                         if (!private_layer->usable) {
941                                 tdm_info_layer info;
942                                 unsigned int format;
943                                 tdm_size size;
944                                 tbm_surface_info_s buf_info;
945
946                                 TDM_DBG_RETURN_IF_FAIL(func_layer->layer_get_info);
947                                 memset(&info, 0, sizeof info);
948                                 ret = func_layer->layer_get_info(private_layer->layer_backend, &info);
949                                 TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
950
951                                 if (!private_layer->showing_buffer)
952                                         continue;
953
954                                 format = tbm_surface_get_format(private_layer->showing_buffer->buffer);
955                                 tbm_surface_get_info(private_layer->showing_buffer->buffer, &buf_info);
956
957                                 if (IS_RGB(format))
958                                         size.h = buf_info.planes[0].stride >> 2;
959                                 else
960                                         size.h = buf_info.planes[0].stride;
961                                 size.v = tbm_surface_get_height(private_layer->showing_buffer->buffer);
962
963                                 if (info.src_config.format)
964                                         format = (info.src_config.format) ? : format;
965
966                                 TDM_SNPRINTF(reply, len, "%d   %d   %d   %p   %c%c%c%c   %ux%u   %ux%u+%u+%u   %ux%u+%u+%u   %s\n",
967                                                          private_layer->index,
968                                                          private_output->index,
969                                                          private_layer->caps.zpos,
970                                                          private_layer->showing_buffer->buffer, FOURCC_STR(format), size.h, size.v,
971                                                          info.src_config.pos.w, info.src_config.pos.h, info.src_config.pos.x, info.src_config.pos.y,
972                                                          info.dst_pos.w, info.dst_pos.h, info.dst_pos.x, info.dst_pos.y,
973                                                          tdm_transform_str(info.transform));
974                         } else {
975                                 TDM_SNPRINTF(reply, len, "%d   %d   %d   -\n",
976                                                          private_layer->index,
977                                                          private_output->index,
978                                                          private_layer->caps.zpos);
979                         }
980
981                         TDM_SNPRINTF(reply, len, "\tcaps\t: ");
982                         tdm_layer_caps_str(private_layer->caps.capabilities, &reply, len);
983                         TDM_SNPRINTF(reply, len, "\n");
984
985                         TDM_SNPRINTF(reply, len, "\tformats\t: ");
986                         if (private_layer->caps.format_count > 0) {
987                                 const char *sep = "";
988                                 for (i = 0; i < private_layer->caps.format_count; i++) {
989                                         if (private_layer->caps.formats[i] == 0)
990                                                 continue;
991                                         TDM_SNPRINTF(reply, len, "%s%c%c%c%c", sep, FOURCC_STR(private_layer->caps.formats[i]));
992                                         sep = ",";
993                                 }
994                                 TDM_SNPRINTF(reply, len, "\n");
995                         }
996
997                         TDM_SNPRINTF(reply, len, "\t%u properties:\n", private_layer->caps.prop_count);
998                         if (private_layer->caps.prop_count > 0) {
999                                 TDM_SNPRINTF(reply, len, "\t\tname\ttype\tidx\tvalue\n");
1000                                 for (i = 0; i < private_layer->caps.prop_count; i++) {
1001                                         tdm_value value;
1002                                         TDM_DBG_RETURN_IF_FAIL(func_layer->layer_get_property);
1003                                         ret = func_layer->layer_get_property(private_layer->layer_backend,
1004                                                                                                                  private_layer->caps.props[i].id,
1005                                                                                                                  &value);
1006                                         TDM_DBG_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
1007                                         TDM_SNPRINTF(reply, len, "\t\t%s\t%s\t%u\t",
1008                                                                  private_layer->caps.props[i].name,
1009                                                                  tdm_value_type_str(private_output->caps.props[i].type),
1010                                                                  private_layer->caps.props[i].id);
1011                                 switch (private_layer->caps.props[i].type) {
1012                                 case TDM_VALUE_TYPE_PTR:
1013                                         TDM_SNPRINTF(reply, len, "%p\n", value.ptr);
1014                                         break;
1015                                 case TDM_VALUE_TYPE_INT32:
1016                                         TDM_SNPRINTF(reply, len, "%d\n", value.s32);
1017                                         break;
1018                                 case TDM_VALUE_TYPE_INT64:
1019                                         TDM_SNPRINTF(reply, len, "%"PRId64"\n", value.s64);
1020                                         break;
1021                                 case TDM_VALUE_TYPE_UINT64:
1022                                         TDM_SNPRINTF(reply, len, "%"PRIu64"\n", value.u64);
1023                                         break;
1024                                 case TDM_VALUE_TYPE_UINT32:
1025                                 default:
1026                                         TDM_SNPRINTF(reply, len, "%u\n", value.u32);
1027                                         break;
1028                                 }
1029                                 }
1030                         }
1031                 }
1032         }
1033         TDM_SNPRINTF(reply, len, "\n");
1034
1035         if (private_display->capabilities & TDM_DISPLAY_CAPABILITY_PP) {
1036                 const char *sep = "";
1037                 TDM_SNPRINTF(reply, len, "[PP information]\n");
1038                 TDM_SNPRINTF(reply, len, "caps\t: ");
1039                 tdm_pp_caps_str(private_display->caps_pp.capabilities, &reply, len);
1040                 TDM_SNPRINTF(reply, len, "\n");
1041                 TDM_SNPRINTF(reply, len, "formats\t: ");
1042                 for (i = 0; i < private_display->caps_pp.format_count; i++) {
1043                         if (private_display->caps_pp.formats[i] == 0)
1044                                 continue;
1045                         TDM_SNPRINTF(reply, len, "%s%c%c%c%c", sep, FOURCC_STR(private_display->caps_pp.formats[i]));
1046                         sep = ",";
1047                 }
1048                 TDM_SNPRINTF(reply, len, "\n");
1049                 TDM_SNPRINTF(reply, len, "size\t: min(%dx%d) max(%dx%d) align_w(%d)\n",
1050                                          TDM_FRONT_VALUE(private_display->caps_pp.min_w),
1051                                          TDM_FRONT_VALUE(private_display->caps_pp.min_h),
1052                                          TDM_FRONT_VALUE(private_display->caps_pp.max_w),
1053                                          TDM_FRONT_VALUE(private_display->caps_pp.max_h),
1054                                          TDM_FRONT_VALUE(private_display->caps_pp.preferred_align));
1055                 if (!LIST_IS_EMPTY(&private_display->pp_list)) {
1056                         TDM_SNPRINTF(reply, len, "-------------------------------------------------------------\n");
1057                         TDM_SNPRINTF(reply, len, "src(format size crop)  |  dst(format size crop)  |  transform\n");
1058                         TDM_SNPRINTF(reply, len, "-------------------------------------------------------------\n");
1059                         LIST_FOR_EACH_ENTRY(private_pp, &private_display->pp_list, link) {
1060                                 TDM_SNPRINTF(reply, len, "%c%c%c%c %ux%u %ux%u+%u+%u | %c%c%c%c %ux%u %ux%u+%u+%u | %s\n",
1061                                                          FOURCC_STR(private_pp->info.src_config.format),
1062                                                          private_pp->info.src_config.size.h,
1063                                                          private_pp->info.src_config.size.v,
1064                                                          private_pp->info.src_config.pos.x, private_pp->info.src_config.pos.y,
1065                                                          private_pp->info.src_config.pos.w, private_pp->info.src_config.pos.h,
1066                                                          FOURCC_STR(private_pp->info.dst_config.format),
1067                                                          private_pp->info.dst_config.size.h,
1068                                                          private_pp->info.dst_config.size.v,
1069                                                          private_pp->info.dst_config.pos.x, private_pp->info.dst_config.pos.y,
1070                                                          private_pp->info.dst_config.pos.w, private_pp->info.dst_config.pos.h,
1071                                                          tdm_transform_str(private_pp->info.transform));
1072                         }
1073                 }
1074         } else {
1075                 TDM_SNPRINTF(reply, len, "[No PP capability]\n");
1076         }
1077         TDM_SNPRINTF(reply, len, "\n");
1078
1079         if (private_display->capabilities & TDM_DISPLAY_CAPABILITY_CAPTURE) {
1080                 const char *sep = "";
1081                 TDM_SNPRINTF(reply, len, "[Capture information]\n");
1082                 TDM_SNPRINTF(reply, len, "caps\t: ");
1083                 tdm_capture_caps_str(private_display->caps_capture.capabilities, &reply, len);
1084                 TDM_SNPRINTF(reply, len, "\n");
1085                 TDM_SNPRINTF(reply, len, "formats\t: ");
1086                 for (i = 0; i < private_display->caps_capture.format_count; i++) {
1087                         if (private_display->caps_capture.formats[i] == 0)
1088                                 continue;
1089                         TDM_SNPRINTF(reply, len, "%s%c%c%c%c", sep, FOURCC_STR(private_display->caps_capture.formats[i]));
1090                         sep = ",";
1091                 }
1092                 TDM_SNPRINTF(reply, len, "\n");
1093                 TDM_SNPRINTF(reply, len, "size\t: min(%dx%d) max(%dx%d) align_w(%d)\n",
1094                                          TDM_FRONT_VALUE(private_display->caps_capture.min_w),
1095                                          TDM_FRONT_VALUE(private_display->caps_capture.min_h),
1096                                          TDM_FRONT_VALUE(private_display->caps_capture.max_w),
1097                                          TDM_FRONT_VALUE(private_display->caps_capture.max_h),
1098                                          TDM_FRONT_VALUE(private_display->caps_capture.preferred_align));
1099                 if (!LIST_IS_EMPTY(&private_display->capture_list)) {
1100                         TDM_SNPRINTF(reply, len, "-----------------------------------\n");
1101                         TDM_SNPRINTF(reply, len, "dst(format size crop)  |  transform\n");
1102                         TDM_SNPRINTF(reply, len, "-----------------------------------\n");
1103                         LIST_FOR_EACH_ENTRY(private_capture, &private_display->capture_list, link) {
1104                                 TDM_SNPRINTF(reply, len, "%c%c%c%c %ux%u %ux%u+%u+%u | %s\n",
1105                                                          FOURCC_STR(private_capture->info.dst_config.format),
1106                                                          private_capture->info.dst_config.size.h,
1107                                                          private_capture->info.dst_config.size.v,
1108                                                          private_capture->info.dst_config.pos.x, private_capture->info.dst_config.pos.y,
1109                                                          private_capture->info.dst_config.pos.w, private_capture->info.dst_config.pos.h,
1110                                                          tdm_transform_str(private_capture->info.transform));
1111                         }
1112                 }
1113         } else {
1114                 TDM_SNPRINTF(reply, len, "[No Capture capability]\n");
1115         }
1116         TDM_SNPRINTF(reply, len, "\n");
1117 }
1118
1119 EXTERN int
1120 tdm_helper_commit_per_vblank_enabled(tdm_display *dpy)
1121 {
1122         tdm_private_display *private_display;
1123
1124         TDM_RETURN_VAL_IF_FAIL(dpy != NULL, 0);
1125
1126         private_display = dpy;
1127
1128         return private_display->commit_per_vblank;
1129 }
1130