fix some tc fail errors
[platform/core/uifw/libtdm.git] / haltests / src / tc_tdm_backend_pp.cpp
1 /**************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
4  *
5  * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
6  * Contact: Andrii Sokolenko <a.sokolenko@samsung.com>
7  * Contact: Roman Marchenko <r.marchenko@samsung.com>
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sub license, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice (including the
18  * next paragraph) shall be included in all copies or substantial portions
19  * of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
24  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
25  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28  *
29 **************************************************************************/
30
31 #include "tc_tdm.h"
32
33 /* LCOV_EXCL_START */
34
35 class TDMBackendPP : public TDMBackendDisplay
36 {
37 public:
38         tdm_pp *pp;
39         tdm_pp_capability capabilities;
40         const tbm_format *formats;
41         int format_count;
42         int min_w;
43         int min_h;
44         int max_w;
45         int max_h;
46         int preferred_align;
47         int preferred_align_vertical;
48
49         tbm_surface_h srcbuf[3];
50         tbm_surface_h dstbuf[3];
51
52         tdm_info_pp info;
53
54         tdm_output *output;
55         unsigned int pipe;
56         const tdm_output_mode *mode;
57
58         tdm_layer *dst_layer;
59         const tbm_format *dst_formats;
60         tbm_format *pp_formats;
61         int dst_format_count;
62         int dst_zpos;
63         int dst_layer_index;
64
65         TDMBackendPP();
66         void SetUp(void);
67         void TearDown(void);
68
69         bool FindLayerUnderPrimary(void);
70         bool FindLayerOverPrimary(void);
71         bool PreparePP(void);
72         bool PrepareBuffers(int sw, int sh, tbm_format sf, int dw, int dh, tbm_format df, tdm_transform t);
73         void ShowBuffer(int b);
74         void HideLayer(void);
75         void DumpBuffer(int b, char *test);
76         void DestroyBuffers(void);
77         void DestroyPP(void);
78 };
79
80 TDMBackendPP::TDMBackendPP()
81 {
82         pp = NULL;
83         capabilities = (tdm_pp_capability)0;
84         formats = NULL;
85         format_count = 0;
86         min_w = min_h = max_w = max_h = preferred_align = preferred_align_vertical = -1;
87
88         for (int b = 0; b < 3; b++)
89                 srcbuf[b] = dstbuf[b] = NULL;
90         memset(&info, 0, sizeof info);
91
92         output = NULL;
93         pipe = 0;
94         mode = NULL;
95
96         dst_layer = NULL;
97         dst_formats = NULL;
98         dst_format_count = 0;
99         dst_zpos = 0;
100         dst_layer_index = 0;
101         pp_formats = NULL;
102 }
103
104 void TDMBackendPP::SetUp(void)
105 {
106         TDMBackendDisplay::SetUp();
107
108         if (!tc_tdm_display_has_pp_capability(dpy))
109                 return;
110
111         EXPECT_EQ(tdm_display_get_pp_capabilities(dpy, &capabilities), TDM_ERROR_NONE);
112         EXPECT_GT(capabilities, 0);
113         EXPECT_EQ(tdm_display_get_pp_available_formats(dpy, &formats, &format_count), TDM_ERROR_NONE);
114         EXPECT_NE(formats, NULL);
115         EXPECT_GT(format_count, 0);
116         EXPECT_EQ(tdm_display_get_pp_available_size(dpy, &min_w, &min_h, &max_w, &max_h, &preferred_align), TDM_ERROR_NONE);
117         EXPECT_TRUE(min_w == -1 || min_w > 0);
118         EXPECT_TRUE(min_h == -1 || min_h > 0);
119         EXPECT_TRUE(max_w == -1 || max_w > 0);
120         EXPECT_TRUE(max_h == -1 || max_h > 0);
121         EXPECT_TRUE(preferred_align == -1 || preferred_align > 0);
122         EXPECT_EQ(tdm_display_get_pp_preferred_align_vertical(dpy, &preferred_align_vertical), TDM_ERROR_NONE);
123         EXPECT_TRUE(preferred_align_vertical == -1 || preferred_align_vertical > 0);
124
125         for (int o = 0; o < output_count; o++) {
126                 if (!tc_tdm_output_is_connected(outputs[o]))
127                         continue;
128
129                 output = outputs[o];
130                 EXPECT_EQ(tdm_output_get_pipe(output, &pipe), TDM_ERROR_NONE);
131                 EXPECT_EQ(tc_tdm_output_prepare(dpy, output, false), true);
132                 EXPECT_EQ(tdm_output_get_mode(output, &mode), TDM_ERROR_NONE);
133                 EXPECT_NE(mode, NULL);
134                 break;
135         }
136 }
137
138 void TDMBackendPP::TearDown(void)
139 {
140         if (pp)
141                 tdm_pp_destroy(pp);
142
143         DestroyBuffers();
144         if (output)
145                 EXPECT_EQ(tc_tdm_output_unset(dpy, output), true);
146
147         TDMBackendDisplay::TearDown();
148 }
149
150 bool TDMBackendPP::PreparePP(void)
151 {
152         tdm_error ret;
153         pp = tdm_display_create_pp(dpy, &ret);
154         TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
155         TDM_UT_RETURN_FALSE_IF_FAIL(pp != NULL);
156         return true;
157 }
158
159 void TDMBackendPP::DestroyPP(void)
160 {
161         if (pp) {
162                 tdm_pp_destroy(pp);
163                 pp = NULL;
164         }
165 }
166
167 bool TDMBackendPP::PrepareBuffers(int sw, int sh, tbm_format sf, int dw, int dh, tbm_format df, tdm_transform t)
168 {
169         int src_flags = 0, dst_flags = 0;
170
171         sw = TDM_UT_SIZE_ALIGN(sw, preferred_align);
172         dw = TDM_UT_SIZE_ALIGN(dw, preferred_align);
173         if (preferred_align_vertical > 0) {
174                 sh = TDM_UT_SIZE_ALIGN(sh, preferred_align_vertical);
175                 dh = TDM_UT_SIZE_ALIGN(dh, preferred_align_vertical);
176         }
177
178         if (capabilities & TDM_PP_CAPABILITY_SCANOUT)
179                 src_flags = dst_flags |= TBM_BO_SCANOUT;
180
181         if (dst_layer) {
182                 tdm_layer_capability capabilities;
183                 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_capabilities(dst_layer, &capabilities) == TDM_ERROR_NONE);
184                 if (capabilities & TDM_LAYER_CAPABILITY_SCANOUT)
185                         dst_flags |= TBM_BO_SCANOUT;
186         }
187
188         if (tc_tdm_output_is_hwc_enable(output))
189                 dst_flags |= TBM_BO_SCANOUT;
190
191         TDM_UT_RETURN_FALSE_IF_FAIL(tc_tdm_buffer_create(sw, sh, sf, src_flags, true, 3, srcbuf) == true);
192         TDM_UT_RETURN_FALSE_IF_FAIL(tc_tdm_buffer_create(dw, dh, df, dst_flags, false, 3, dstbuf) == true);
193         TDM_UT_RETURN_FALSE_IF_FAIL(tc_tdm_pp_fill_info(srcbuf[0], dstbuf[0], t, &info) == true);
194         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_pp_set_info(pp, &info) == TDM_ERROR_NONE);
195
196         return true;
197 }
198
199 bool TDMBackendPP::FindLayerUnderPrimary(void)
200 {
201         tdm_error ret;
202         int count;
203         int primary_zpos, zpos;
204
205         if (tc_tdm_output_is_hwc_enable(output)) {
206                 pp_formats = (tbm_format *)calloc(1, sizeof(tbm_format) * 2);
207                 TDM_UT_RETURN_FALSE_IF_FAIL(pp_formats != NULL);
208                 pp_formats[0] = TBM_FORMAT_NV12;
209                 pp_formats[1] = TBM_FORMAT_YUV420;
210                 dst_formats = pp_formats;
211                 dst_format_count = 2;
212                 TDM_UT_RETURN_FALSE_IF_FAIL(dst_formats != NULL);
213                 TDM_UT_RETURN_FALSE_IF_FAIL(dst_format_count > 0);
214                 dst_layer = NULL;
215                 return true;
216         }
217
218         tdm_layer *primary = tc_tdm_output_get_primary_layer(output);
219         TDM_UT_RETURN_FALSE_IF_FAIL(primary != NULL);
220         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_output_get_layer_count(output, &count) == TDM_ERROR_NONE);
221         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_zpos(primary, &primary_zpos) == TDM_ERROR_NONE);
222
223         for (int l = 0; l < count; l++) {
224                 unsigned int usable;
225                 tdm_layer *temp = tdm_output_get_layer(output, l, &ret);
226                 TDM_UT_RETURN_FALSE_IF_FAIL(temp != NULL);
227                 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_is_usable(temp, &usable) == TDM_ERROR_NONE);
228                 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_zpos(temp, &zpos) == TDM_ERROR_NONE);
229                 if (zpos < primary_zpos && usable) {
230                         dst_layer = temp;
231                         dst_zpos = zpos;
232                         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_available_formats(dst_layer, &dst_formats, &dst_format_count) == TDM_ERROR_NONE);
233                         TDM_UT_RETURN_FALSE_IF_FAIL(dst_formats != NULL);
234                         TDM_UT_RETURN_FALSE_IF_FAIL(dst_format_count > 0);
235                         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_index(dst_layer, &dst_layer_index) == TDM_ERROR_NONE);
236                         break;
237                 }
238         }
239
240         return true;
241 }
242
243 bool TDMBackendPP::FindLayerOverPrimary(void)
244 {
245         tdm_error ret;
246         int count;
247         int primary_zpos, zpos;
248
249         if (tc_tdm_output_is_hwc_enable(output)) {
250                 pp_formats = (tbm_format *)calloc(1, sizeof(tbm_format) * 2);
251                 TDM_UT_RETURN_FALSE_IF_FAIL(pp_formats != NULL);
252                 pp_formats[0] = TBM_FORMAT_ARGB8888;
253                 pp_formats[1] = TBM_FORMAT_XRGB8888;
254                 dst_formats = formats;
255                 dst_format_count = 2;
256                 TDM_UT_RETURN_FALSE_IF_FAIL(dst_formats != NULL);
257                 TDM_UT_RETURN_FALSE_IF_FAIL(dst_format_count > 0);
258                 dst_layer = NULL;
259                 return true;
260         }
261
262         tdm_layer *primary = tc_tdm_output_get_primary_layer(output);
263         TDM_UT_RETURN_FALSE_IF_FAIL(primary != NULL);
264         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_output_get_layer_count(output, &count) == TDM_ERROR_NONE);
265         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_zpos(primary, &primary_zpos) == TDM_ERROR_NONE);
266
267         for (int l = 0; l < count; l++) {
268                 tdm_layer *temp = tdm_output_get_layer(output, l, &ret);
269                 TDM_UT_RETURN_FALSE_IF_FAIL(temp != NULL);
270                 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_zpos(temp, &zpos) == TDM_ERROR_NONE);
271                 if (zpos > primary_zpos) {
272                         dst_layer = temp;
273                         dst_zpos = zpos;
274                         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_available_formats(dst_layer, &dst_formats, &dst_format_count) == TDM_ERROR_NONE);
275                         TDM_UT_RETURN_FALSE_IF_FAIL(dst_formats != NULL);
276                         TDM_UT_RETURN_FALSE_IF_FAIL(dst_format_count > 0);
277                         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_index(dst_layer, &dst_layer_index) == TDM_ERROR_NONE);
278                         break;
279                 }
280         }
281
282         return true;
283
284 }
285
286 static void
287 _tc_tdm_backend_pp_output_commit_cb(tdm_output *output, unsigned int sequence,
288                                                                         unsigned int tv_sec, unsigned int tv_usec,
289                                                                         void *user_data)
290 {
291         bool *done = (bool *)user_data;
292         if (done)
293                 *done = true;
294 }
295
296 void TDMBackendPP::ShowBuffer(int b)
297 {
298         EXPECT_NE(output, NULL);
299         if (tc_tdm_output_is_hwc_enable(output))
300                 TDM_UT_SKIP_FLAG(0);
301
302         EXPECT_NE(dst_layer, NULL);
303
304         bool done = false;
305
306         EXPECT_EQ(tc_tdm_layer_set_buffer(dst_layer, dstbuf[b]), true);
307         EXPECT_EQ(tdm_output_commit(output, 0, _tc_tdm_backend_pp_output_commit_cb, &done), TDM_ERROR_NONE);
308         while (!done) {
309                 EXPECT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
310         }
311 }
312
313 void TDMBackendPP::HideLayer(void)
314 {
315         EXPECT_NE(output, NULL);
316         if (tc_tdm_output_is_hwc_enable(output))
317                 TDM_UT_SKIP_FLAG(0);
318
319         EXPECT_NE(dst_layer, NULL);
320
321         tdm_layer_unset_buffer(dst_layer);
322         tdm_output_commit(output, 0, NULL, NULL);
323 }
324
325 void TDMBackendPP::DumpBuffer(int b, char *test)
326 {
327         char filename[256];
328         if (test)
329                 snprintf(filename, sizeof filename, "%s_%s_src_%d", typeid(*this).name(), test, b);
330         else
331                 snprintf(filename, sizeof filename, "%s_src_%d", typeid(*this).name(), b);
332         tdm_helper_dump_buffer_str(srcbuf[b], NULL, filename);
333         if (test)
334                 snprintf(filename, sizeof filename, "%s_%s_dst_%d", typeid(*this).name(), test, b);
335         else
336                 snprintf(filename, sizeof filename, "%s_dst_%d", typeid(*this).name(), b);
337         tdm_helper_dump_buffer_str(dstbuf[b], NULL, filename);
338 }
339
340 void TDMBackendPP::DestroyBuffers(void)
341 {
342         for (int b = 0; b < 3; b++) {
343                 if (srcbuf[b])
344                         tbm_surface_destroy(srcbuf[b]);
345                 if (dstbuf[b])
346                         tbm_surface_destroy(dstbuf[b]);
347                 srcbuf[b] = dstbuf[b] = NULL;
348         }
349 }
350
351 bool
352 tc_tdm_pp_fill_info(tbm_surface_h srcbuf, tbm_surface_h dstbuf, tdm_transform transform, tdm_info_pp *info)
353 {
354         int bw, bh;
355
356         memset(info, 0, sizeof *info);
357
358         bw = bh = TDM_UT_INVALID_VALUE;
359         tdm_helper_get_buffer_full_size(srcbuf, &bw, &bh);
360         TDM_UT_RETURN_FALSE_IF_FAIL(bw != TDM_UT_INVALID_VALUE);
361         TDM_UT_RETURN_FALSE_IF_FAIL(bw >= tbm_surface_get_width(srcbuf));
362         TDM_UT_RETURN_FALSE_IF_FAIL(bh != TDM_UT_INVALID_VALUE);
363         TDM_UT_RETURN_FALSE_IF_FAIL(bh >= tbm_surface_get_height(srcbuf));
364         info->src_config.size.h = bw;
365         info->src_config.size.v = bh;
366         info->src_config.pos.x = 0;
367         info->src_config.pos.y = 0;
368         info->src_config.pos.w = tbm_surface_get_width(srcbuf);
369         info->src_config.pos.h = tbm_surface_get_height(srcbuf);
370         info->src_config.format = tbm_surface_get_format(srcbuf);
371
372         bw = bh = TDM_UT_INVALID_VALUE;
373         tdm_helper_get_buffer_full_size(dstbuf, &bw, &bh);
374         TDM_UT_RETURN_FALSE_IF_FAIL(bw != TDM_UT_INVALID_VALUE);
375         TDM_UT_RETURN_FALSE_IF_FAIL(bw >= tbm_surface_get_width(dstbuf));
376         TDM_UT_RETURN_FALSE_IF_FAIL(bh != TDM_UT_INVALID_VALUE);
377         TDM_UT_RETURN_FALSE_IF_FAIL(bh >= tbm_surface_get_height(dstbuf));
378         info->dst_config.size.h = bw;
379         info->dst_config.size.v = bh;
380         info->dst_config.pos.x = 0;
381         info->dst_config.pos.y = 0;
382         info->dst_config.pos.w = tbm_surface_get_width(dstbuf);
383         info->dst_config.pos.h = tbm_surface_get_height(dstbuf);
384         info->dst_config.format = tbm_surface_get_format(dstbuf);
385
386         info->transform = transform;
387         info->sync = 0;
388         info->flags = 0;
389
390         TDM_UT_INFO("src_config(%dx%d: %d,%d %dx%d: %c%c%c%c) dst_config(%dx%d: %d,%d %dx%d: %c%c%c%c) transform(%s) sync(%d) info->flags(%x)",
391                                 info->src_config.size.h, info->src_config.size.v,
392                                 info->src_config.pos.x, info->src_config.pos.y, info->src_config.pos.w, info->src_config.pos.h,
393                                 FOURCC_STR(info->src_config.format),
394                                 info->dst_config.size.h, info->dst_config.size.v,
395                                 info->dst_config.pos.x, info->dst_config.pos.y, info->dst_config.pos.w, info->dst_config.pos.h,
396                                 FOURCC_STR(info->dst_config.format),
397                                 tdm_transform_str(transform), info->sync, info->flags);
398
399         return true;
400 }
401
402 TEST_P(TDMBackendPP, PPDispalyGetAvaiableFormatsNullObject)
403 {
404         const tbm_format *formats = (const tbm_format *)TDM_UT_INVALID_VALUE;
405         int count = TDM_UT_INVALID_VALUE;
406         if (tc_tdm_display_has_pp_capability(dpy))
407                 EXPECT_EQ(tdm_display_get_pp_available_formats(NULL, &formats, &count), TDM_ERROR_INVALID_PARAMETER);
408         else
409                 EXPECT_EQ(tdm_display_get_pp_available_formats(NULL, &formats, &count), TDM_ERROR_INVALID_PARAMETER);
410         EXPECT_EQ(formats, (const tbm_format *)TDM_UT_INVALID_VALUE);
411         EXPECT_EQ(count, TDM_UT_INVALID_VALUE);
412 }
413
414 TEST_P(TDMBackendPP, PPDispalyGetAvaiableFormatsNullOther)
415 {
416         if (tc_tdm_display_has_pp_capability(dpy)) {
417                 EXPECT_EQ(PreparePP(), true);
418                 EXPECT_EQ(tdm_display_get_pp_available_formats(pp, NULL, NULL), TDM_ERROR_INVALID_PARAMETER);
419         }
420 }
421
422 TEST_P(TDMBackendPP, PPDispalyGetAvaiableSizeNullObject)
423 {
424         int min_w = TDM_UT_INVALID_VALUE;
425         int min_h = TDM_UT_INVALID_VALUE;
426         int max_w = TDM_UT_INVALID_VALUE;
427         int max_h = TDM_UT_INVALID_VALUE;
428         int preferred_align = TDM_UT_INVALID_VALUE;
429         if (tc_tdm_display_has_pp_capability(dpy))
430                 EXPECT_EQ(tdm_display_get_pp_available_size(NULL, &min_w, &min_h, &max_w, &max_h, &preferred_align), TDM_ERROR_INVALID_PARAMETER);
431         else
432                 EXPECT_EQ(tdm_display_get_pp_available_size(NULL, &min_w, &min_h, &max_w, &max_h, &preferred_align), TDM_ERROR_INVALID_PARAMETER);
433         EXPECT_EQ(min_w, TDM_UT_INVALID_VALUE);
434         EXPECT_EQ(min_h, TDM_UT_INVALID_VALUE);
435         EXPECT_EQ(max_w, TDM_UT_INVALID_VALUE);
436         EXPECT_EQ(max_h, TDM_UT_INVALID_VALUE);
437         EXPECT_EQ(preferred_align, TDM_UT_INVALID_VALUE);
438 }
439
440 TEST_P(TDMBackendPP, PPDispalyGetAvaiableSizeNullOther)
441 {
442         if (tc_tdm_display_has_pp_capability(dpy)) {
443                 EXPECT_EQ(PreparePP(), true);
444                 EXPECT_EQ(tdm_display_get_pp_available_size(dpy, NULL, NULL, NULL, NULL, NULL), TDM_ERROR_NONE);
445         }
446 }
447
448 TEST_P(TDMBackendPP, PPDispalyGetPreferredAlignVerticalNullObject)
449 {
450         if (tc_tdm_display_has_pp_capability(dpy)) {
451                 EXPECT_EQ(PreparePP(), true);
452                 EXPECT_EQ(tdm_display_get_pp_preferred_align_vertical(NULL, NULL), TDM_ERROR_INVALID_PARAMETER);
453         }
454 }
455
456 TEST_P(TDMBackendPP, PPDestroy)
457 {
458         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
459
460         EXPECT_EQ(PreparePP(), true);
461         tdm_pp_destroy(pp);
462         pp = NULL;
463 }
464
465 TEST_P(TDMBackendPP, PPDestroyNullObject)
466 {
467         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
468
469         tdm_pp_destroy(NULL);
470 }
471
472 TEST_P(TDMBackendPP, PPSetInfo)
473 {
474         /* tested in PPNoScaleNoTransformNoCSC */
475 }
476
477 TEST_P(TDMBackendPP, PPSetInfoNullObject)
478 {
479         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
480
481         tdm_info_pp info;
482         memset(&info, 0, sizeof info);
483         EXPECT_EQ(tdm_pp_set_info(NULL, &info), TDM_ERROR_INVALID_PARAMETER);
484 }
485
486 TEST_P(TDMBackendPP, PPSetInfoNullOther)
487 {
488         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
489
490         EXPECT_EQ(PreparePP(), true);
491         EXPECT_EQ(tdm_pp_set_info(pp, NULL), TDM_ERROR_INVALID_PARAMETER);
492 }
493
494 static void
495 _tc_tdm_pp_done_cb(tdm_pp *pp, tbm_surface_h src, tbm_surface_h dst, void *user_data)
496 {
497         bool *done = (bool*)user_data;
498         if (done)
499                 *done = true;
500 }
501
502 TEST_P(TDMBackendPP, PPSetDoneHandler)
503 {
504         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
505
506         EXPECT_EQ(PreparePP(), true);
507         EXPECT_EQ(tdm_pp_set_done_handler(pp, _tc_tdm_pp_done_cb, NULL), TDM_ERROR_NONE);
508 }
509
510 TEST_P(TDMBackendPP, PPSetDoneHandlerNullObject)
511 {
512         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
513
514         EXPECT_EQ(tdm_pp_set_done_handler(NULL, _tc_tdm_pp_done_cb, NULL), TDM_ERROR_INVALID_PARAMETER);
515 }
516
517 TEST_P(TDMBackendPP, PPSetDoneHandlerNullOther)
518 {
519         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
520
521         EXPECT_EQ(PreparePP(), true);
522         EXPECT_EQ(tdm_pp_set_done_handler(pp, NULL, NULL), TDM_ERROR_INVALID_PARAMETER);
523 }
524
525 TEST_P(TDMBackendPP, PPAttach)
526 {
527         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
528
529         EXPECT_EQ(PreparePP(), true);
530
531         for (int f = 0; f < format_count; f++) {
532                 EXPECT_EQ(PrepareBuffers(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f],
533                                                                  TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f],
534                                                                  TDM_TRANSFORM_NORMAL), true);
535
536                 for (int b = 0; b < 3; b++)
537                         EXPECT_EQ(tdm_pp_attach(pp, srcbuf[b], dstbuf[b]), TDM_ERROR_NONE);
538
539                 DestroyBuffers();
540         }
541 }
542
543 TEST_P(TDMBackendPP, PPAttachNullObject)
544 {
545         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
546
547         tbm_surface_h srcbuf = (tbm_surface_h)TDM_UT_BUFFER_SIZE;
548         tbm_surface_h dstbuf = (tbm_surface_h)TDM_UT_BUFFER_SIZE;
549
550         EXPECT_EQ(tdm_pp_attach(NULL, srcbuf, dstbuf), TDM_ERROR_INVALID_PARAMETER);
551 }
552
553 TEST_P(TDMBackendPP, PPAttachNullOther)
554 {
555         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
556
557         EXPECT_EQ(PreparePP(), true);
558
559         EXPECT_EQ(tdm_pp_attach(pp, NULL, NULL), TDM_ERROR_INVALID_PARAMETER);
560 }
561
562 TEST_P(TDMBackendPP, PPCommit)
563 {
564         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
565
566         EXPECT_EQ(PreparePP(), true);
567
568         EXPECT_EQ(tdm_pp_commit(pp), TDM_ERROR_NONE);
569 }
570
571 TEST_P(TDMBackendPP, PPCommitNullOBject)
572 {
573         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
574
575         EXPECT_EQ(tdm_pp_commit(NULL), TDM_ERROR_INVALID_PARAMETER);
576 }
577
578 TEST_P(TDMBackendPP, PPConvertUnderlay)
579 {
580         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
581
582         FindLayerUnderPrimary();
583
584         if (!tc_tdm_output_is_hwc_enable(output))
585                 EXPECT_NE(dst_layer, NULL);
586
587         for (int f = 0; f < dst_format_count; f++) {
588                 bool done;
589
590                 TDM_UT_INFO("* testing for %c%c%c%c", FOURCC_STR(dst_formats[f]));
591
592                 EXPECT_EQ(PreparePP(), true);
593
594                 EXPECT_EQ(PrepareBuffers(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE / 2, dst_formats[f],
595                                                                  TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE / 2, dst_formats[f],
596                                                                  TDM_TRANSFORM_NORMAL), true);
597
598                 EXPECT_EQ(tdm_pp_set_done_handler(pp, _tc_tdm_pp_done_cb, &done), TDM_ERROR_NONE);
599
600 retry:
601                 for (int b = 0; b < 3; b++) {
602                         done = false;
603
604                         EXPECT_EQ(tdm_pp_attach(pp, srcbuf[b], dstbuf[b]), TDM_ERROR_NONE);
605                         EXPECT_EQ(tdm_pp_commit(pp), TDM_ERROR_NONE);
606
607                         while (!done)
608                                 EXPECT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
609
610 #if 0
611                         char temp[256];
612                         snprintf(temp, sizeof temp, "f%d_b%d", f, b);
613                         DumpBuffer(b, temp);
614 #endif
615                         ShowBuffer(b);
616                 }
617
618                 TDM_UT_ASK_YNR("* Successed to convert to '%c%c%c%c' buffers and show them to a underlay layer? (output: %d, layer: %d)",
619                                            FOURCC_STR(dst_formats[f]), pipe, dst_layer_index);
620
621                 DestroyPP();
622                 DestroyBuffers();
623         }
624         if (tc_tdm_output_is_hwc_enable(output) && pp_formats) {
625                 free(pp_formats);
626                 pp_formats = NULL;
627         }
628 }
629
630 TEST_P(TDMBackendPP, PPConvertOverlay)
631 {
632         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
633
634         FindLayerOverPrimary();
635
636         if (!tc_tdm_output_is_hwc_enable(output))
637                 TDM_UT_SKIP_FLAG(dst_layer != NULL);
638
639         for (int f = 0; f < dst_format_count; f++) {
640                 bool done;
641
642                 TDM_UT_INFO("* testing for %c%c%c%c", FOURCC_STR(dst_formats[f]));
643
644                 EXPECT_EQ(PreparePP(), true);
645
646                 EXPECT_EQ(PrepareBuffers(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE / 2, dst_formats[f],
647                                                                  TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE / 2, dst_formats[f],
648                                                                  TDM_TRANSFORM_NORMAL), true);
649
650                 EXPECT_EQ(tdm_pp_set_done_handler(pp, _tc_tdm_pp_done_cb, &done), TDM_ERROR_NONE);
651
652 retry:
653                 for (int b = 0; b < 3; b++) {
654                         done = false;
655
656                         EXPECT_EQ(tdm_pp_attach(pp, srcbuf[b], dstbuf[b]), TDM_ERROR_NONE);
657                         EXPECT_EQ(tdm_pp_commit(pp), TDM_ERROR_NONE);
658
659                         while (!done)
660                                 EXPECT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
661
662 #if 0
663                         char temp[256];
664                         snprintf(temp, sizeof temp, "f%d_b%d", f, b);
665                         DumpBuffer(b, temp);
666 #endif
667                         ShowBuffer(b);
668                 }
669
670                 TDM_UT_ASK_YNR("* Successed to convert '%c%c%c%c' buffers and show them to a overlay layer? (output: %d, layer: %d)",
671                                            FOURCC_STR(dst_formats[f]), pipe, dst_layer_index);
672
673                 DestroyPP();
674                 DestroyBuffers();
675         }
676         if (tc_tdm_output_is_hwc_enable(output) && pp_formats) {
677                 free(pp_formats);
678                 pp_formats = NULL;
679         }
680 }
681
682 TEST_P(TDMBackendPP, PPConvertScale)
683 {
684         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
685
686         FindLayerUnderPrimary();
687
688         if (!tc_tdm_output_is_hwc_enable(output))
689                 EXPECT_NE(dst_layer, NULL);
690
691         for (int f = 0; f < dst_format_count; f++) {
692                 bool done;
693
694                 TDM_UT_INFO("* testing for %c%c%c%c", FOURCC_STR(dst_formats[f]));
695
696                 EXPECT_EQ(PreparePP(), true);
697
698                 EXPECT_EQ(PrepareBuffers(640, 480, dst_formats[f],
699                                                                  mode->hdisplay, mode->vdisplay, dst_formats[f],
700                                                                  TDM_TRANSFORM_NORMAL), true);
701
702                 EXPECT_EQ(tdm_pp_set_done_handler(pp, _tc_tdm_pp_done_cb, &done), TDM_ERROR_NONE);
703
704 retry:
705                 for (int b = 0; b < 3; b++) {
706                         done = false;
707
708                         EXPECT_EQ(tdm_pp_attach(pp, srcbuf[b], dstbuf[b]), TDM_ERROR_NONE);
709                         EXPECT_EQ(tdm_pp_commit(pp), TDM_ERROR_NONE);
710
711                         while (!done)
712                                 EXPECT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
713
714 #if 0
715                         char temp[256];
716                         snprintf(temp, sizeof temp, "f%d_b%d", f, b);
717                         DumpBuffer(b, temp);
718 #endif
719                         ShowBuffer(b);
720                 }
721
722                 TDM_UT_ASK_YNR("* Successed to scale '%c%c%c%c' buffers? (output: %d, layer: %d)",
723                                            FOURCC_STR(dst_formats[f]), pipe, dst_layer_index);
724
725                 DestroyPP();
726                 DestroyBuffers();
727         }
728         if (tc_tdm_output_is_hwc_enable(output) && pp_formats) {
729                 free(pp_formats);
730                 pp_formats = NULL;
731         }
732 }
733
734 TEST_P(TDMBackendPP, PPConvertTransform)
735 {
736         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
737         TDM_UT_SKIP_FLAG(!(capabilities & TDM_PP_CAPABILITY_NO_TRANSFORM_ROTATION));
738
739         FindLayerUnderPrimary();
740
741         if (!tc_tdm_output_is_hwc_enable(output))
742                 EXPECT_NE(dst_layer, NULL);
743
744         for (int f = 0; f < dst_format_count; f++) {
745                 for (int t = (int)TDM_TRANSFORM_90; t <= (int)TDM_TRANSFORM_FLIPPED_270; t++) {
746                         bool done;
747
748                         TDM_UT_INFO("* testing for %c%c%c%c", FOURCC_STR(dst_formats[f]));
749
750                         EXPECT_EQ(PreparePP(), true);
751
752                         EXPECT_EQ(PrepareBuffers(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE / 2, dst_formats[f],
753                                                                          TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE / 2, dst_formats[f],
754                                                                          (tdm_transform)t), true);
755
756                         EXPECT_EQ(tdm_pp_set_done_handler(pp, _tc_tdm_pp_done_cb, &done), TDM_ERROR_NONE);
757
758 retry:
759                         for (int b = 0; b < 3; b++) {
760                                 done = false;
761
762                                 EXPECT_EQ(tdm_pp_attach(pp, srcbuf[b], dstbuf[b]), TDM_ERROR_NONE);
763                                 EXPECT_EQ(tdm_pp_commit(pp), TDM_ERROR_NONE);
764
765                                 while (!done)
766                                         EXPECT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
767
768 #if 0
769                                 char temp[256];
770                                 snprintf(temp, sizeof temp, "f%d_b%d_t%d", f, b, t);
771                                 DumpBuffer(b, temp);
772 #endif
773                                 ShowBuffer(b);
774                         }
775
776                         TDM_UT_ASK_YNR("* Successed to rotate '%c%c%c%c' buffers? (transform: %s, output: %d, layer: %d)",
777                                                    FOURCC_STR(dst_formats[f]), tdm_transform_str(t), pipe, dst_layer_index);
778
779                         DestroyPP();
780                         DestroyBuffers();
781                 }
782         }
783         if (tc_tdm_output_is_hwc_enable(output) && pp_formats) {
784                 free(pp_formats);
785                 pp_formats = NULL;
786         }
787 }
788
789 TEST_P(TDMBackendPP, PPConvertCSC)
790 {
791         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
792         TDM_UT_SKIP_FLAG(!(capabilities & TDM_PP_CAPABILITY_NO_CSC));
793
794         FindLayerUnderPrimary();
795
796         if (!tc_tdm_output_is_hwc_enable(output))
797                 EXPECT_NE(dst_layer, NULL);
798
799         for (int df = 0; df < dst_format_count; df++) {
800                 for (int sf = 0; sf < format_count; sf++) {
801                         bool done;
802
803                         TDM_UT_INFO("* testing for format(%c%c%c%c) -> format(%c%c%c%c)",
804                                                 FOURCC_STR(formats[sf]), FOURCC_STR(dst_formats[df]));
805
806                         EXPECT_EQ(PreparePP(), true);
807
808                         EXPECT_EQ(PrepareBuffers(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE / 2, formats[sf],
809                                                                          TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE / 2, dst_formats[df],
810                                                                          TDM_TRANSFORM_NORMAL), true);
811
812                         EXPECT_EQ(tdm_pp_set_done_handler(pp, _tc_tdm_pp_done_cb, &done), TDM_ERROR_NONE);
813
814 retry:
815                         for (int b = 0; b < 3; b++) {
816                                 done = false;
817
818                                 EXPECT_EQ(tdm_pp_attach(pp, srcbuf[b], dstbuf[b]), TDM_ERROR_NONE);
819                                 EXPECT_EQ(tdm_pp_commit(pp), TDM_ERROR_NONE);
820
821                                 while (!done)
822                                         EXPECT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
823
824 #if 0
825                                 char temp[256];
826                                 snprintf(temp, sizeof temp, "sf%d_df%d_b%d", sf, df, b);
827                                 DumpBuffer(b, temp);
828 #endif
829                                 ShowBuffer(b);
830                         }
831
832                         TDM_UT_ASK_YNR("* Successed to convert from '%c%c%c%c' to '%c%c%c%c'? (output: %d, layer: %d)",
833                                                    FOURCC_STR(formats[sf]), FOURCC_STR(dst_formats[df]), pipe, dst_layer_index);
834
835                         DestroyPP();
836                         DestroyBuffers();
837                 }
838         }
839         if (tc_tdm_output_is_hwc_enable(output) && pp_formats) {
840                 free(pp_formats);
841                 pp_formats = NULL;
842         }
843 }
844
845
846
847 static void
848 _tc_tdm_pp_done_cb2(tdm_pp *pp, tbm_surface_h src, tbm_surface_h dst, void *user_data)
849 {
850         int *done = (int*)user_data;
851         if (done)
852                 (*done)++;
853 }
854
855 /* some backend doens't implement correctly for attaching */
856 TEST_P(TDMBackendPP, DISABLED_PPAttachFewTimesInOneCommit)
857 {
858         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
859
860         EXPECT_EQ(PreparePP(), true);
861
862         int done = 0;
863         int f = 0;
864         char temp[256];
865         snprintf(temp, sizeof temp, "%c%c%c%c", FOURCC_STR(formats[f]));
866
867         EXPECT_EQ(PrepareBuffers(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f],
868                                                          TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f],
869                                                          TDM_TRANSFORM_NORMAL), true);
870
871         EXPECT_EQ(tdm_pp_set_done_handler(pp, _tc_tdm_pp_done_cb2, &done), TDM_ERROR_NONE);
872         for (int b = 0; b < 3; b++)
873                 EXPECT_EQ(tdm_pp_attach(pp, srcbuf[b], dstbuf[b]), TDM_ERROR_NONE);
874
875         EXPECT_EQ(tdm_pp_commit(pp), TDM_ERROR_NONE);
876
877         while (done != 3)
878                 EXPECT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
879
880         for (int b = 0; b < 3; b++)
881                 ShowBuffer(b);
882
883         DestroyBuffers();
884 }
885
886 TEST_P(TDMBackendPP, PPDestroyWithoutCommit)
887 {
888         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
889
890         EXPECT_EQ(PreparePP(), true);
891
892         int f = 0;
893
894         EXPECT_EQ(PrepareBuffers(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f],
895                                                          TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f],
896                                                          TDM_TRANSFORM_NORMAL), true);
897
898         EXPECT_EQ(tdm_pp_set_done_handler(pp, _tc_tdm_pp_done_cb2, NULL), TDM_ERROR_NONE);
899         for (int b = 0; b < 3; b++)
900                 EXPECT_EQ(tdm_pp_attach(pp, srcbuf[b], dstbuf[b]), TDM_ERROR_NONE);
901
902         tdm_pp_destroy(pp);
903         pp = NULL;
904
905         DestroyBuffers();
906 }
907
908 TEST_P(TDMBackendPP, PPDestroyBeforeDone)
909 {
910         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
911
912         EXPECT_EQ(PreparePP(), true);
913
914         int f = 0;
915
916         EXPECT_EQ(PrepareBuffers(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f],
917                                                          TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f],
918                                                          TDM_TRANSFORM_NORMAL), true);
919
920         EXPECT_EQ(tdm_pp_set_done_handler(pp, _tc_tdm_pp_done_cb2, NULL), TDM_ERROR_NONE);
921         for (int b = 0; b < 3; b++)
922                 EXPECT_EQ(tdm_pp_attach(pp, srcbuf[b], dstbuf[b]), TDM_ERROR_NONE);
923
924         EXPECT_EQ(tdm_pp_commit(pp), TDM_ERROR_NONE);
925
926         tdm_pp_destroy(pp);
927         pp = NULL;
928
929         DestroyBuffers();
930 }
931
932 #ifdef TDM_UT_TEST_WITH_PARAMS
933 INSTANTIATE_TEST_CASE_P(TDMBackendPPParams,
934                                                 TDMBackendPP,
935                                                 Combine(Bool(), Bool(), Values(TDM_DEFAULT_MODULE)));
936 #else
937 INSTANTIATE_TEST_CASE_P(TDMBackendPPParams,
938                                                 TDMBackendPP,
939                                                 Values(TDM_DEFAULT_MODULE));
940 #endif
941
942 /* LCOV_EXCL_END */