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