haltests: use EXPECT intead of ASSERT
[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         EXPECT_EQ(tc_tdm_output_unset(dpy, output), true);
145
146         TDMBackendDisplay::TearDown();
147 }
148
149 bool TDMBackendPP::PreparePP(void)
150 {
151         tdm_error ret;
152         pp = tdm_display_create_pp(dpy, &ret);
153         TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
154         TDM_UT_RETURN_FALSE_IF_FAIL(pp != NULL);
155         return true;
156 }
157
158 void TDMBackendPP::DestroyPP(void)
159 {
160         if (pp) {
161                 tdm_pp_destroy(pp);
162                 pp = NULL;
163         }
164 }
165
166 bool TDMBackendPP::PrepareBuffers(int sw, int sh, tbm_format sf, int dw, int dh, tbm_format df, tdm_transform t)
167 {
168         int src_flags = 0, dst_flags = 0;
169
170         sw = TDM_UT_SIZE_ALIGN(sw, preferred_align);
171         dw = TDM_UT_SIZE_ALIGN(dw, preferred_align);
172         if (preferred_align_vertical > 0) {
173                 sh = TDM_UT_SIZE_ALIGN(sh, preferred_align_vertical);
174                 dh = TDM_UT_SIZE_ALIGN(dh, preferred_align_vertical);
175         }
176
177         if (capabilities & TDM_PP_CAPABILITY_SCANOUT)
178                 src_flags = dst_flags |= TBM_BO_SCANOUT;
179
180         if (dst_layer) {
181                 tdm_layer_capability capabilities;
182                 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_capabilities(dst_layer, &capabilities) == TDM_ERROR_NONE);
183                 if (capabilities & TDM_LAYER_CAPABILITY_SCANOUT)
184                         dst_flags |= TBM_BO_SCANOUT;
185         }
186
187         if (tc_tdm_output_is_hwc_enable(output))
188                 dst_flags |= TBM_BO_SCANOUT;
189
190         TDM_UT_RETURN_FALSE_IF_FAIL(tc_tdm_buffer_create(sw, sh, sf, src_flags, true, 3, srcbuf) == true);
191         TDM_UT_RETURN_FALSE_IF_FAIL(tc_tdm_buffer_create(dw, dh, df, dst_flags, false, 3, dstbuf) == true);
192         TDM_UT_RETURN_FALSE_IF_FAIL(tc_tdm_pp_fill_info(srcbuf[0], dstbuf[0], t, &info) == true);
193         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_pp_set_info(pp, &info) == TDM_ERROR_NONE);
194
195         return true;
196 }
197
198 bool TDMBackendPP::FindLayerUnderPrimary(void)
199 {
200         tdm_error ret;
201         int count;
202         int primary_zpos, zpos;
203
204         if (tc_tdm_output_is_hwc_enable(output)) {
205                 pp_formats = (tbm_format *)calloc(1, sizeof(tbm_format) * 2);
206                 TDM_UT_RETURN_FALSE_IF_FAIL(pp_formats != NULL);
207                 pp_formats[0] = TBM_FORMAT_NV12;
208                 pp_formats[1] = TBM_FORMAT_YUV420;
209                 dst_formats = pp_formats;
210                 dst_format_count = 2;
211                 TDM_UT_RETURN_FALSE_IF_FAIL(dst_formats != NULL);
212                 TDM_UT_RETURN_FALSE_IF_FAIL(dst_format_count > 0);
213                 dst_layer = NULL;
214                 return true;
215         }
216
217         tdm_layer *primary = tc_tdm_output_get_primary_layer(output);
218         TDM_UT_RETURN_FALSE_IF_FAIL(primary != NULL);
219         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_output_get_layer_count(output, &count) == TDM_ERROR_NONE);
220         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_zpos(primary, &primary_zpos) == TDM_ERROR_NONE);
221
222         for (int l = 0; l < count; l++) {
223                 unsigned int usable;
224                 tdm_layer *temp = tdm_output_get_layer(output, l, &ret);
225                 TDM_UT_RETURN_FALSE_IF_FAIL(temp != NULL);
226                 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_is_usable(temp, &usable) == TDM_ERROR_NONE);
227                 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_zpos(temp, &zpos) == TDM_ERROR_NONE);
228                 if (zpos < primary_zpos && usable) {
229                         dst_layer = temp;
230                         dst_zpos = zpos;
231                         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_available_formats(dst_layer, &dst_formats, &dst_format_count) == TDM_ERROR_NONE);
232                         TDM_UT_RETURN_FALSE_IF_FAIL(dst_formats != NULL);
233                         TDM_UT_RETURN_FALSE_IF_FAIL(dst_format_count > 0);
234                         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_index(dst_layer, &dst_layer_index) == TDM_ERROR_NONE);
235                         break;
236                 }
237         }
238
239         return true;
240 }
241
242 bool TDMBackendPP::FindLayerOverPrimary(void)
243 {
244         tdm_error ret;
245         int count;
246         int primary_zpos, zpos;
247
248         if (tc_tdm_output_is_hwc_enable(output)) {
249                 pp_formats = (tbm_format *)calloc(1, sizeof(tbm_format) * 2);
250                 TDM_UT_RETURN_FALSE_IF_FAIL(pp_formats != NULL);
251                 pp_formats[0] = TBM_FORMAT_ARGB8888;
252                 pp_formats[1] = TBM_FORMAT_XRGB8888;
253                 dst_formats = formats;
254                 dst_format_count = 2;
255                 TDM_UT_RETURN_FALSE_IF_FAIL(dst_formats != NULL);
256                 TDM_UT_RETURN_FALSE_IF_FAIL(dst_format_count > 0);
257                 dst_layer = NULL;
258                 return true;
259         }
260
261         tdm_layer *primary = tc_tdm_output_get_primary_layer(output);
262         TDM_UT_RETURN_FALSE_IF_FAIL(primary != NULL);
263         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_output_get_layer_count(output, &count) == TDM_ERROR_NONE);
264         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_zpos(primary, &primary_zpos) == TDM_ERROR_NONE);
265
266         for (int l = 0; l < count; l++) {
267                 tdm_layer *temp = tdm_output_get_layer(output, l, &ret);
268                 TDM_UT_RETURN_FALSE_IF_FAIL(temp != NULL);
269                 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_zpos(temp, &zpos) == TDM_ERROR_NONE);
270                 if (zpos > primary_zpos) {
271                         dst_layer = temp;
272                         dst_zpos = zpos;
273                         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_available_formats(dst_layer, &dst_formats, &dst_format_count) == TDM_ERROR_NONE);
274                         TDM_UT_RETURN_FALSE_IF_FAIL(dst_formats != NULL);
275                         TDM_UT_RETURN_FALSE_IF_FAIL(dst_format_count > 0);
276                         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_index(dst_layer, &dst_layer_index) == TDM_ERROR_NONE);
277                         break;
278                 }
279         }
280
281         return true;
282
283 }
284
285 static void
286 _tc_tdm_backend_pp_output_commit_cb(tdm_output *output, unsigned int sequence,
287                                                                         unsigned int tv_sec, unsigned int tv_usec,
288                                                                         void *user_data)
289 {
290         bool *done = (bool *)user_data;
291         if (done)
292                 *done = true;
293 }
294
295 void TDMBackendPP::ShowBuffer(int b)
296 {
297         EXPECT_NE(output, NULL);
298         if (tc_tdm_output_is_hwc_enable(output))
299                 TDM_UT_SKIP_FLAG(0);
300
301         EXPECT_NE(dst_layer, NULL);
302
303         bool done = false;
304
305         EXPECT_EQ(tc_tdm_layer_set_buffer(dst_layer, dstbuf[b]), true);
306         EXPECT_EQ(tdm_output_commit(output, 0, _tc_tdm_backend_pp_output_commit_cb, &done), TDM_ERROR_NONE);
307         while (!done) {
308                 EXPECT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
309         }
310 }
311
312 void TDMBackendPP::HideLayer(void)
313 {
314         EXPECT_NE(output, NULL);
315         if (tc_tdm_output_is_hwc_enable(output))
316                 TDM_UT_SKIP_FLAG(0);
317
318         EXPECT_NE(dst_layer, NULL);
319
320         tdm_layer_unset_buffer(dst_layer);
321         tdm_output_commit(output, 0, NULL, NULL);
322 }
323
324 void TDMBackendPP::DumpBuffer(int b, char *test)
325 {
326         char filename[256];
327         if (test)
328                 snprintf(filename, sizeof filename, "%s_%s_src_%d", typeid(*this).name(), test, b);
329         else
330                 snprintf(filename, sizeof filename, "%s_src_%d", typeid(*this).name(), b);
331         tdm_helper_dump_buffer_str(srcbuf[b], NULL, filename);
332         if (test)
333                 snprintf(filename, sizeof filename, "%s_%s_dst_%d", typeid(*this).name(), test, b);
334         else
335                 snprintf(filename, sizeof filename, "%s_dst_%d", typeid(*this).name(), b);
336         tdm_helper_dump_buffer_str(dstbuf[b], NULL, filename);
337 }
338
339 void TDMBackendPP::DestroyBuffers(void)
340 {
341         for (int b = 0; b < 3; b++) {
342                 if (srcbuf[b])
343                         tbm_surface_destroy(srcbuf[b]);
344                 if (dstbuf[b])
345                         tbm_surface_destroy(dstbuf[b]);
346                 srcbuf[b] = dstbuf[b] = NULL;
347         }
348 }
349
350 bool
351 tc_tdm_pp_fill_info(tbm_surface_h srcbuf, tbm_surface_h dstbuf, tdm_transform transform, tdm_info_pp *info)
352 {
353         int bw, bh;
354
355         memset(info, 0, sizeof *info);
356
357         bw = bh = TDM_UT_INVALID_VALUE;
358         tdm_helper_get_buffer_full_size(srcbuf, &bw, &bh);
359         TDM_UT_RETURN_FALSE_IF_FAIL(bw != TDM_UT_INVALID_VALUE);
360         TDM_UT_RETURN_FALSE_IF_FAIL(bw >= tbm_surface_get_width(srcbuf));
361         TDM_UT_RETURN_FALSE_IF_FAIL(bh != TDM_UT_INVALID_VALUE);
362         TDM_UT_RETURN_FALSE_IF_FAIL(bh >= tbm_surface_get_height(srcbuf));
363         info->src_config.size.h = bw;
364         info->src_config.size.v = bh;
365         info->src_config.pos.x = 0;
366         info->src_config.pos.y = 0;
367         info->src_config.pos.w = tbm_surface_get_width(srcbuf);
368         info->src_config.pos.h = tbm_surface_get_height(srcbuf);
369         info->src_config.format = tbm_surface_get_format(srcbuf);
370
371         bw = bh = TDM_UT_INVALID_VALUE;
372         tdm_helper_get_buffer_full_size(dstbuf, &bw, &bh);
373         TDM_UT_RETURN_FALSE_IF_FAIL(bw != TDM_UT_INVALID_VALUE);
374         TDM_UT_RETURN_FALSE_IF_FAIL(bw >= tbm_surface_get_width(dstbuf));
375         TDM_UT_RETURN_FALSE_IF_FAIL(bh != TDM_UT_INVALID_VALUE);
376         TDM_UT_RETURN_FALSE_IF_FAIL(bh >= tbm_surface_get_height(dstbuf));
377         info->dst_config.size.h = bw;
378         info->dst_config.size.v = bh;
379         info->dst_config.pos.x = 0;
380         info->dst_config.pos.y = 0;
381         info->dst_config.pos.w = tbm_surface_get_width(dstbuf);
382         info->dst_config.pos.h = tbm_surface_get_height(dstbuf);
383         info->dst_config.format = tbm_surface_get_format(dstbuf);
384
385         info->transform = transform;
386         info->sync = 0;
387         info->flags = 0;
388
389         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)",
390                                 info->src_config.size.h, info->src_config.size.v,
391                                 info->src_config.pos.x, info->src_config.pos.y, info->src_config.pos.w, info->src_config.pos.h,
392                                 FOURCC_STR(info->src_config.format),
393                                 info->dst_config.size.h, info->dst_config.size.v,
394                                 info->dst_config.pos.x, info->dst_config.pos.y, info->dst_config.pos.w, info->dst_config.pos.h,
395                                 FOURCC_STR(info->dst_config.format),
396                                 tdm_transform_str(transform), info->sync, info->flags);
397
398         return true;
399 }
400
401 TEST_P(TDMBackendPP, PPDispalyGetAvaiableFormatsNullObject)
402 {
403         const tbm_format *formats = (const tbm_format *)TDM_UT_INVALID_VALUE;
404         int count = TDM_UT_INVALID_VALUE;
405         if (tc_tdm_display_has_pp_capability(dpy))
406                 EXPECT_EQ(tdm_display_get_pp_available_formats(NULL, &formats, &count), TDM_ERROR_INVALID_PARAMETER);
407         else
408                 EXPECT_EQ(tdm_display_get_pp_available_formats(NULL, &formats, &count), TDM_ERROR_INVALID_PARAMETER);
409         EXPECT_EQ(formats, (const tbm_format *)TDM_UT_INVALID_VALUE);
410         EXPECT_EQ(count, TDM_UT_INVALID_VALUE);
411 }
412
413 TEST_P(TDMBackendPP, PPDispalyGetAvaiableFormatsNullOther)
414 {
415         if (tc_tdm_display_has_pp_capability(dpy)) {
416                 EXPECT_EQ(PreparePP(), true);
417                 EXPECT_EQ(tdm_display_get_pp_available_formats(pp, NULL, NULL), TDM_ERROR_INVALID_PARAMETER);
418         }
419 }
420
421 TEST_P(TDMBackendPP, PPDispalyGetAvaiableSizeNullObject)
422 {
423         int min_w = TDM_UT_INVALID_VALUE;
424         int min_h = TDM_UT_INVALID_VALUE;
425         int max_w = TDM_UT_INVALID_VALUE;
426         int max_h = TDM_UT_INVALID_VALUE;
427         int preferred_align = TDM_UT_INVALID_VALUE;
428         if (tc_tdm_display_has_pp_capability(dpy))
429                 EXPECT_EQ(tdm_display_get_pp_available_size(NULL, &min_w, &min_h, &max_w, &max_h, &preferred_align), TDM_ERROR_INVALID_PARAMETER);
430         else
431                 EXPECT_EQ(tdm_display_get_pp_available_size(NULL, &min_w, &min_h, &max_w, &max_h, &preferred_align), TDM_ERROR_INVALID_PARAMETER);
432         EXPECT_EQ(min_w, TDM_UT_INVALID_VALUE);
433         EXPECT_EQ(min_h, TDM_UT_INVALID_VALUE);
434         EXPECT_EQ(max_w, TDM_UT_INVALID_VALUE);
435         EXPECT_EQ(max_h, TDM_UT_INVALID_VALUE);
436         EXPECT_EQ(preferred_align, TDM_UT_INVALID_VALUE);
437 }
438
439 TEST_P(TDMBackendPP, PPDispalyGetAvaiableSizeNullOther)
440 {
441         if (tc_tdm_display_has_pp_capability(dpy)) {
442                 EXPECT_EQ(PreparePP(), true);
443                 EXPECT_EQ(tdm_display_get_pp_available_size(dpy, NULL, NULL, NULL, NULL, NULL), TDM_ERROR_NONE);
444         }
445 }
446
447 TEST_P(TDMBackendPP, PPDispalyGetPreferredAlignVerticalNullObject)
448 {
449         if (tc_tdm_display_has_pp_capability(dpy)) {
450                 EXPECT_EQ(PreparePP(), true);
451                 EXPECT_EQ(tdm_display_get_pp_preferred_align_vertical(NULL, NULL), TDM_ERROR_INVALID_PARAMETER);
452         }
453 }
454
455 TEST_P(TDMBackendPP, PPDestroy)
456 {
457         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
458
459         EXPECT_EQ(PreparePP(), true);
460         tdm_pp_destroy(pp);
461         pp = NULL;
462 }
463
464 TEST_P(TDMBackendPP, PPDestroyNullObject)
465 {
466         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
467
468         tdm_pp_destroy(NULL);
469 }
470
471 TEST_P(TDMBackendPP, PPSetInfo)
472 {
473         /* tested in PPNoScaleNoTransformNoCSC */
474 }
475
476 TEST_P(TDMBackendPP, PPSetInfoNullObject)
477 {
478         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
479
480         tdm_info_pp info;
481         memset(&info, 0, sizeof info);
482         EXPECT_EQ(tdm_pp_set_info(NULL, &info), TDM_ERROR_INVALID_PARAMETER);
483 }
484
485 TEST_P(TDMBackendPP, PPSetInfoNullOther)
486 {
487         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
488
489         EXPECT_EQ(PreparePP(), true);
490         EXPECT_EQ(tdm_pp_set_info(pp, NULL), TDM_ERROR_INVALID_PARAMETER);
491 }
492
493 static void
494 _tc_tdm_pp_done_cb(tdm_pp *pp, tbm_surface_h src, tbm_surface_h dst, void *user_data)
495 {
496         bool *done = (bool*)user_data;
497         if (done)
498                 *done = true;
499 }
500
501 TEST_P(TDMBackendPP, PPSetDoneHandler)
502 {
503         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
504
505         EXPECT_EQ(PreparePP(), true);
506         EXPECT_EQ(tdm_pp_set_done_handler(pp, _tc_tdm_pp_done_cb, NULL), TDM_ERROR_NONE);
507 }
508
509 TEST_P(TDMBackendPP, PPSetDoneHandlerNullObject)
510 {
511         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
512
513         EXPECT_EQ(tdm_pp_set_done_handler(NULL, _tc_tdm_pp_done_cb, NULL), TDM_ERROR_INVALID_PARAMETER);
514 }
515
516 TEST_P(TDMBackendPP, PPSetDoneHandlerNullOther)
517 {
518         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
519
520         EXPECT_EQ(PreparePP(), true);
521         EXPECT_EQ(tdm_pp_set_done_handler(pp, NULL, NULL), TDM_ERROR_INVALID_PARAMETER);
522 }
523
524 TEST_P(TDMBackendPP, PPAttach)
525 {
526         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
527
528         EXPECT_EQ(PreparePP(), true);
529
530         for (int f = 0; f < format_count; f++) {
531                 EXPECT_EQ(PrepareBuffers(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f],
532                                                                  TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f],
533                                                                  TDM_TRANSFORM_NORMAL), true);
534
535                 for (int b = 0; b < 3; b++)
536                         EXPECT_EQ(tdm_pp_attach(pp, srcbuf[b], dstbuf[b]), TDM_ERROR_NONE);
537
538                 DestroyBuffers();
539         }
540 }
541
542 TEST_P(TDMBackendPP, PPAttachNullObject)
543 {
544         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
545
546         tbm_surface_h srcbuf = (tbm_surface_h)TDM_UT_BUFFER_SIZE;
547         tbm_surface_h dstbuf = (tbm_surface_h)TDM_UT_BUFFER_SIZE;
548
549         EXPECT_EQ(tdm_pp_attach(NULL, srcbuf, dstbuf), TDM_ERROR_INVALID_PARAMETER);
550 }
551
552 TEST_P(TDMBackendPP, PPAttachNullOther)
553 {
554         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
555
556         EXPECT_EQ(PreparePP(), true);
557
558         EXPECT_EQ(tdm_pp_attach(pp, NULL, NULL), TDM_ERROR_INVALID_PARAMETER);
559 }
560
561 TEST_P(TDMBackendPP, PPCommit)
562 {
563         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
564
565         EXPECT_EQ(PreparePP(), true);
566
567         EXPECT_EQ(tdm_pp_commit(pp), TDM_ERROR_NONE);
568 }
569
570 TEST_P(TDMBackendPP, PPCommitNullOBject)
571 {
572         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
573
574         EXPECT_EQ(tdm_pp_commit(NULL), TDM_ERROR_INVALID_PARAMETER);
575 }
576
577 TEST_P(TDMBackendPP, PPConvertUnderlay)
578 {
579         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
580
581         FindLayerUnderPrimary();
582
583         if (!tc_tdm_output_is_hwc_enable(output))
584                 EXPECT_NE(dst_layer, NULL);
585
586         for (int f = 0; f < dst_format_count; f++) {
587                 bool done;
588
589                 TDM_UT_INFO("* testing for %c%c%c%c", FOURCC_STR(dst_formats[f]));
590
591                 EXPECT_EQ(PreparePP(), true);
592
593                 EXPECT_EQ(PrepareBuffers(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE / 2, dst_formats[f],
594                                                                  TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE / 2, dst_formats[f],
595                                                                  TDM_TRANSFORM_NORMAL), true);
596
597                 EXPECT_EQ(tdm_pp_set_done_handler(pp, _tc_tdm_pp_done_cb, &done), TDM_ERROR_NONE);
598
599 retry:
600                 for (int b = 0; b < 3; b++) {
601                         done = false;
602
603                         EXPECT_EQ(tdm_pp_attach(pp, srcbuf[b], dstbuf[b]), TDM_ERROR_NONE);
604                         EXPECT_EQ(tdm_pp_commit(pp), TDM_ERROR_NONE);
605
606                         while (!done)
607                                 EXPECT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
608
609 #if 0
610                         char temp[256];
611                         snprintf(temp, sizeof temp, "f%d_b%d", f, b);
612                         DumpBuffer(b, temp);
613 #endif
614                         ShowBuffer(b);
615                 }
616
617                 TDM_UT_ASK_YNR("* Successed to convert to '%c%c%c%c' buffers and show them to a underlay layer? (output: %d, layer: %d)",
618                                            FOURCC_STR(dst_formats[f]), pipe, dst_layer_index);
619
620                 DestroyPP();
621                 DestroyBuffers();
622         }
623         if (tc_tdm_output_is_hwc_enable(output) && pp_formats) {
624                 free(pp_formats);
625                 pp_formats = NULL;
626         }
627 }
628
629 TEST_P(TDMBackendPP, PPConvertOverlay)
630 {
631         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
632
633         FindLayerOverPrimary();
634
635         if (!tc_tdm_output_is_hwc_enable(output))
636                 TDM_UT_SKIP_FLAG(dst_layer != NULL);
637
638         for (int f = 0; f < dst_format_count; f++) {
639                 bool done;
640
641                 TDM_UT_INFO("* testing for %c%c%c%c", FOURCC_STR(dst_formats[f]));
642
643                 EXPECT_EQ(PreparePP(), true);
644
645                 EXPECT_EQ(PrepareBuffers(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE / 2, dst_formats[f],
646                                                                  TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE / 2, dst_formats[f],
647                                                                  TDM_TRANSFORM_NORMAL), true);
648
649                 EXPECT_EQ(tdm_pp_set_done_handler(pp, _tc_tdm_pp_done_cb, &done), TDM_ERROR_NONE);
650
651 retry:
652                 for (int b = 0; b < 3; b++) {
653                         done = false;
654
655                         EXPECT_EQ(tdm_pp_attach(pp, srcbuf[b], dstbuf[b]), TDM_ERROR_NONE);
656                         EXPECT_EQ(tdm_pp_commit(pp), TDM_ERROR_NONE);
657
658                         while (!done)
659                                 EXPECT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
660
661 #if 0
662                         char temp[256];
663                         snprintf(temp, sizeof temp, "f%d_b%d", f, b);
664                         DumpBuffer(b, temp);
665 #endif
666                         ShowBuffer(b);
667                 }
668
669                 TDM_UT_ASK_YNR("* Successed to convert '%c%c%c%c' buffers and show them to a overlay layer? (output: %d, layer: %d)",
670                                            FOURCC_STR(dst_formats[f]), pipe, dst_layer_index);
671
672                 DestroyPP();
673                 DestroyBuffers();
674         }
675         if (tc_tdm_output_is_hwc_enable(output) && pp_formats) {
676                 free(pp_formats);
677                 pp_formats = NULL;
678         }
679 }
680
681 TEST_P(TDMBackendPP, PPConvertScale)
682 {
683         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
684
685         FindLayerUnderPrimary();
686
687         if (!tc_tdm_output_is_hwc_enable(output))
688                 EXPECT_NE(dst_layer, NULL);
689
690         for (int f = 0; f < dst_format_count; f++) {
691                 bool done;
692
693                 TDM_UT_INFO("* testing for %c%c%c%c", FOURCC_STR(dst_formats[f]));
694
695                 EXPECT_EQ(PreparePP(), true);
696
697                 EXPECT_EQ(PrepareBuffers(640, 480, dst_formats[f],
698                                                                  mode->hdisplay, mode->vdisplay, dst_formats[f],
699                                                                  TDM_TRANSFORM_NORMAL), true);
700
701                 EXPECT_EQ(tdm_pp_set_done_handler(pp, _tc_tdm_pp_done_cb, &done), TDM_ERROR_NONE);
702
703 retry:
704                 for (int b = 0; b < 3; b++) {
705                         done = false;
706
707                         EXPECT_EQ(tdm_pp_attach(pp, srcbuf[b], dstbuf[b]), TDM_ERROR_NONE);
708                         EXPECT_EQ(tdm_pp_commit(pp), TDM_ERROR_NONE);
709
710                         while (!done)
711                                 EXPECT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
712
713 #if 0
714                         char temp[256];
715                         snprintf(temp, sizeof temp, "f%d_b%d", f, b);
716                         DumpBuffer(b, temp);
717 #endif
718                         ShowBuffer(b);
719                 }
720
721                 TDM_UT_ASK_YNR("* Successed to scale '%c%c%c%c' buffers? (output: %d, layer: %d)",
722                                            FOURCC_STR(dst_formats[f]), pipe, dst_layer_index);
723
724                 DestroyPP();
725                 DestroyBuffers();
726         }
727         if (tc_tdm_output_is_hwc_enable(output) && pp_formats) {
728                 free(pp_formats);
729                 pp_formats = NULL;
730         }
731 }
732
733 TEST_P(TDMBackendPP, PPConvertTransform)
734 {
735         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
736         TDM_UT_SKIP_FLAG(!(capabilities & TDM_PP_CAPABILITY_NO_TRANSFORM_ROTATION));
737
738         FindLayerUnderPrimary();
739
740         if (!tc_tdm_output_is_hwc_enable(output))
741                 EXPECT_NE(dst_layer, NULL);
742
743         for (int f = 0; f < dst_format_count; f++) {
744                 for (int t = (int)TDM_TRANSFORM_90; t <= (int)TDM_TRANSFORM_FLIPPED_270; t++) {
745                         bool done;
746
747                         TDM_UT_INFO("* testing for %c%c%c%c", FOURCC_STR(dst_formats[f]));
748
749                         EXPECT_EQ(PreparePP(), true);
750
751                         EXPECT_EQ(PrepareBuffers(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE / 2, dst_formats[f],
752                                                                          TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE / 2, dst_formats[f],
753                                                                          (tdm_transform)t), true);
754
755                         EXPECT_EQ(tdm_pp_set_done_handler(pp, _tc_tdm_pp_done_cb, &done), TDM_ERROR_NONE);
756
757 retry:
758                         for (int b = 0; b < 3; b++) {
759                                 done = false;
760
761                                 EXPECT_EQ(tdm_pp_attach(pp, srcbuf[b], dstbuf[b]), TDM_ERROR_NONE);
762                                 EXPECT_EQ(tdm_pp_commit(pp), TDM_ERROR_NONE);
763
764                                 while (!done)
765                                         EXPECT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
766
767 #if 0
768                                 char temp[256];
769                                 snprintf(temp, sizeof temp, "f%d_b%d_t%d", f, b, t);
770                                 DumpBuffer(b, temp);
771 #endif
772                                 ShowBuffer(b);
773                         }
774
775                         TDM_UT_ASK_YNR("* Successed to rotate '%c%c%c%c' buffers? (transform: %s, output: %d, layer: %d)",
776                                                    FOURCC_STR(dst_formats[f]), tdm_transform_str(t), pipe, dst_layer_index);
777
778                         DestroyPP();
779                         DestroyBuffers();
780                 }
781         }
782         if (tc_tdm_output_is_hwc_enable(output) && pp_formats) {
783                 free(pp_formats);
784                 pp_formats = NULL;
785         }
786 }
787
788 TEST_P(TDMBackendPP, PPConvertCSC)
789 {
790         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
791         TDM_UT_SKIP_FLAG(!(capabilities & TDM_PP_CAPABILITY_NO_CSC));
792
793         FindLayerUnderPrimary();
794
795         if (!tc_tdm_output_is_hwc_enable(output))
796                 EXPECT_NE(dst_layer, NULL);
797
798         for (int df = 0; df < dst_format_count; df++) {
799                 for (int sf = 0; sf < format_count; sf++) {
800                         bool done;
801
802                         TDM_UT_INFO("* testing for format(%c%c%c%c) -> format(%c%c%c%c)",
803                                                 FOURCC_STR(formats[sf]), FOURCC_STR(dst_formats[df]));
804
805                         EXPECT_EQ(PreparePP(), true);
806
807                         EXPECT_EQ(PrepareBuffers(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE / 2, formats[sf],
808                                                                          TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE / 2, dst_formats[df],
809                                                                          TDM_TRANSFORM_NORMAL), true);
810
811                         EXPECT_EQ(tdm_pp_set_done_handler(pp, _tc_tdm_pp_done_cb, &done), TDM_ERROR_NONE);
812
813 retry:
814                         for (int b = 0; b < 3; b++) {
815                                 done = false;
816
817                                 EXPECT_EQ(tdm_pp_attach(pp, srcbuf[b], dstbuf[b]), TDM_ERROR_NONE);
818                                 EXPECT_EQ(tdm_pp_commit(pp), TDM_ERROR_NONE);
819
820                                 while (!done)
821                                         EXPECT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
822
823 #if 0
824                                 char temp[256];
825                                 snprintf(temp, sizeof temp, "sf%d_df%d_b%d", sf, df, b);
826                                 DumpBuffer(b, temp);
827 #endif
828                                 ShowBuffer(b);
829                         }
830
831                         TDM_UT_ASK_YNR("* Successed to convert from '%c%c%c%c' to '%c%c%c%c'? (output: %d, layer: %d)",
832                                                    FOURCC_STR(formats[sf]), FOURCC_STR(dst_formats[df]), pipe, dst_layer_index);
833
834                         DestroyPP();
835                         DestroyBuffers();
836                 }
837         }
838         if (tc_tdm_output_is_hwc_enable(output) && pp_formats) {
839                 free(pp_formats);
840                 pp_formats = NULL;
841         }
842 }
843
844
845
846 static void
847 _tc_tdm_pp_done_cb2(tdm_pp *pp, tbm_surface_h src, tbm_surface_h dst, void *user_data)
848 {
849         int *done = (int*)user_data;
850         if (done)
851                 (*done)++;
852 }
853
854 /* some backend doens't implement correctly for attaching */
855 TEST_P(TDMBackendPP, DISABLED_PPAttachFewTimesInOneCommit)
856 {
857         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
858
859         EXPECT_EQ(PreparePP(), true);
860
861         int done = 0;
862         int f = 0;
863         char temp[256];
864         snprintf(temp, sizeof temp, "%c%c%c%c", FOURCC_STR(formats[f]));
865
866         EXPECT_EQ(PrepareBuffers(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f],
867                                                          TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f],
868                                                          TDM_TRANSFORM_NORMAL), true);
869
870         EXPECT_EQ(tdm_pp_set_done_handler(pp, _tc_tdm_pp_done_cb2, &done), TDM_ERROR_NONE);
871         for (int b = 0; b < 3; b++)
872                 EXPECT_EQ(tdm_pp_attach(pp, srcbuf[b], dstbuf[b]), TDM_ERROR_NONE);
873
874         EXPECT_EQ(tdm_pp_commit(pp), TDM_ERROR_NONE);
875
876         while (done != 3)
877                 EXPECT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
878
879         for (int b = 0; b < 3; b++)
880                 ShowBuffer(b);
881
882         DestroyBuffers();
883 }
884
885 TEST_P(TDMBackendPP, PPDestroyWithoutCommit)
886 {
887         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
888
889         EXPECT_EQ(PreparePP(), true);
890
891         int f = 0;
892
893         EXPECT_EQ(PrepareBuffers(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f],
894                                                          TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f],
895                                                          TDM_TRANSFORM_NORMAL), true);
896
897         EXPECT_EQ(tdm_pp_set_done_handler(pp, _tc_tdm_pp_done_cb2, NULL), TDM_ERROR_NONE);
898         for (int b = 0; b < 3; b++)
899                 EXPECT_EQ(tdm_pp_attach(pp, srcbuf[b], dstbuf[b]), TDM_ERROR_NONE);
900
901         tdm_pp_destroy(pp);
902         pp = NULL;
903
904         DestroyBuffers();
905 }
906
907 TEST_P(TDMBackendPP, PPDestroyBeforeDone)
908 {
909         TDM_UT_SKIP_FLAG(tc_tdm_display_has_pp_capability(dpy));
910
911         EXPECT_EQ(PreparePP(), true);
912
913         int f = 0;
914
915         EXPECT_EQ(PrepareBuffers(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f],
916                                                          TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f],
917                                                          TDM_TRANSFORM_NORMAL), true);
918
919         EXPECT_EQ(tdm_pp_set_done_handler(pp, _tc_tdm_pp_done_cb2, NULL), TDM_ERROR_NONE);
920         for (int b = 0; b < 3; b++)
921                 EXPECT_EQ(tdm_pp_attach(pp, srcbuf[b], dstbuf[b]), TDM_ERROR_NONE);
922
923         EXPECT_EQ(tdm_pp_commit(pp), TDM_ERROR_NONE);
924
925         tdm_pp_destroy(pp);
926         pp = NULL;
927
928         DestroyBuffers();
929 }
930
931 #ifdef TDM_UT_TEST_WITH_PARAMS
932 INSTANTIATE_TEST_CASE_P(TDMBackendPPParams,
933                                                 TDMBackendPP,
934                                                 Combine(Bool(), Bool(), Values(TDM_DEFAULT_MODULE)));
935 #else
936 INSTANTIATE_TEST_CASE_P(TDMBackendPPParams,
937                                                 TDMBackendPP,
938                                                 Values(TDM_DEFAULT_MODULE));
939 #endif
940
941 /* LCOV_EXCL_END */