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