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