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