rename tdm_hwc_get_video_supported_formats
[platform/core/uifw/libtdm.git] / haltests / src / tc_tdm_hwc.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 #define HWC_WIN_NUM 5
36
37 class TDMHwc : public TDMOutput
38 {
39 public:
40         TDMHwc();
41         void SetUp(void);
42         void TearDown(void);
43
44         tdm_error error;
45 };
46
47 TDMHwc::TDMHwc()
48 {
49         error = TDM_ERROR_NONE;
50 }
51
52 void TDMHwc::SetUp(void)
53 {
54         TDMOutput::SetUp();
55 }
56
57 void TDMHwc::TearDown(void)
58 {
59         TDMOutput::TearDown();
60 }
61
62 static void
63 _tc_tdm_hwc_commit_cb(tdm_hwc *hwc, unsigned int sequence,
64                                                 unsigned int tv_sec, unsigned int tv_usec,
65                                                 void *user_data)
66 {
67         bool *done = (bool*)user_data;
68         if (done)
69                 *done = true;
70 }
71
72 /* tdm_hwc_window * tdm_hwc_create_window(tdm_output *output, tdm_error *error); */
73 TEST_P(TDMHwc, CreateWindowFailNull)
74 {
75         TDM_UT_SKIP_FLAG(has_outputs);
76
77         ASSERT_EQ(NULL, tdm_hwc_create_window(NULL, &error));
78         ASSERT_NE(TDM_ERROR_NONE, error);
79 }
80
81 TEST_P(TDMHwc, CreateWindowSuccessful)
82 {
83         TDM_UT_SKIP_FLAG(has_outputs);
84
85         tdm_hwc *hwc = NULL;
86         tdm_error error;
87         tdm_hwc_window * hw = NULL;
88
89         for (int o = 0; o < output_count; o++) {
90                 hwc = tdm_output_get_hwc(outputs[o], &error);
91                 if (hwc) {
92                         hw = tdm_hwc_create_window(hwc, &error);
93                         ASSERT_EQ(TDM_ERROR_NONE, error);
94                         tdm_hwc_window_destroy(hw);
95                 } else {
96                         ASSERT_EQ(NULL, tdm_hwc_create_window(hwc, &error));
97                         ASSERT_NE(TDM_ERROR_NONE, error);
98                 }
99         }
100 }
101
102 /* tdm_hwc_get_supported_formats() */
103 TEST_P(TDMHwc, GetSupportedFormatsFailNull)
104 {
105         TDM_UT_SKIP_FLAG(has_outputs);
106
107         tdm_error error;
108
109         error = tdm_hwc_get_video_supported_formats(NULL, NULL, NULL);
110         ASSERT_NE(TDM_ERROR_NONE, error);
111 }
112
113 TEST_P(TDMHwc, GetSupportedFormatsSuccessful)
114 {
115         TDM_UT_SKIP_FLAG(has_outputs);
116
117         tdm_hwc *hwc = NULL;
118         tdm_error error = TDM_ERROR_NONE;
119         const tbm_format *formats;
120         int count;
121
122         for (int o = 0; o < output_count; o++) {
123                 hwc = tdm_output_get_hwc(outputs[o], &error);
124                 if (hwc) {
125                         error = tdm_hwc_get_video_supported_formats(hwc, &formats, &count);
126                         if (error != TDM_ERROR_NOT_IMPLEMENTED) {
127                                 ASSERT_EQ(TDM_ERROR_NONE, error);
128                                 if (count > 0)
129                                         ASSERT_NE(NULL, formats);
130                         }
131                 } else {
132                         error = tdm_hwc_get_video_supported_formats(hwc, &formats, &count);
133                         ASSERT_NE(TDM_ERROR_NONE, error);
134                 }
135         }
136 }
137
138 /* tdm_hwc_get_available_properties() */
139 TEST_P(TDMHwc, GetAvailablePropertiesFailNullWin)
140 {
141         TDM_UT_SKIP_FLAG(has_outputs);
142
143         tdm_hwc *hwc = NULL;
144         tdm_error error = TDM_ERROR_NONE;
145         const tdm_prop *props;
146         int count;
147
148         for (int o = 0; o < output_count; o++) {
149                 hwc = tdm_output_get_hwc(outputs[o], &error);
150                 if (hwc) {
151                         error = tdm_hwc_get_available_properties(NULL, &props, &count);
152                         ASSERT_NE(TDM_ERROR_NONE, error);
153
154                         error = tdm_hwc_get_available_properties(hwc, NULL, &count);
155                         ASSERT_NE(TDM_ERROR_NONE, error);
156
157                         error = tdm_hwc_get_available_properties(hwc, &props, NULL);
158                         ASSERT_NE(TDM_ERROR_NONE, error);
159                 } else {
160                         error = tdm_hwc_get_available_properties(hwc, &props, &count);
161                         ASSERT_NE(TDM_ERROR_NONE, error);
162                 }
163         }
164 }
165
166 TEST_P(TDMHwc, GetAvailablePropertiesSuccess)
167 {
168         TDM_UT_SKIP_FLAG(has_outputs);
169
170         tdm_hwc *hwc = NULL;
171         tdm_error error = TDM_ERROR_NONE;
172         const tdm_prop *props;
173         int count;
174
175         for (int o = 0; o < output_count; o++) {
176                 hwc = tdm_output_get_hwc(outputs[o], &error);
177                 if (hwc) {
178                         error = tdm_hwc_get_available_properties(hwc, &props, &count);
179                         ASSERT_TRUE(TDM_ERROR_NONE == error || TDM_ERROR_NOT_IMPLEMENTED == error);
180                 } else {
181                         error = tdm_hwc_get_available_properties(hwc, &props, &count);
182                         ASSERT_NE(TDM_ERROR_NONE, error);
183                 }
184         }
185
186 }
187
188 /* tdm_hwc_get_client_target_buffer_queue() */
189 TEST_P(TDMHwc, GetClientTargetBufferQueueFailNullObject)
190 {
191         TDM_UT_SKIP_FLAG(has_outputs);
192
193         tdm_hwc *hwc = NULL;
194         tdm_error error = TDM_ERROR_NONE;
195         tbm_surface_queue_h queue = NULL;
196
197         for (int o = 0; o < output_count; o++) {
198                 hwc = tdm_output_get_hwc(outputs[o], &error);
199                 if (hwc) {
200                         queue = tdm_hwc_get_client_target_buffer_queue(NULL, &error);
201                         ASSERT_NE(TDM_ERROR_NONE, error);
202                         ASSERT_EQ(NULL, queue);
203
204                         queue = tdm_hwc_get_client_target_buffer_queue(NULL, NULL);
205                         ASSERT_EQ(NULL, queue);
206                 } else {
207                         ASSERT_EQ(NULL, queue);
208                 }
209         }
210 }
211
212 TEST_P(TDMHwc, GetClientTargetBufferQueueFainNoHwc)
213 {
214         TDM_UT_SKIP_FLAG(has_outputs);
215
216         tdm_hwc *hwc = NULL;
217         tdm_error error = TDM_ERROR_NONE;
218         tbm_surface_queue_h queue = NULL;
219
220         for (int o = 0; o < output_count; o++) {
221                 hwc = tdm_output_get_hwc(outputs[o], &error);
222                 if (hwc) {
223                         queue = tdm_hwc_get_client_target_buffer_queue(hwc, &error);
224                         ASSERT_EQ(TDM_ERROR_NONE, error);
225                         ASSERT_NE(NULL, queue);
226                 } else {
227                         queue = tdm_hwc_get_client_target_buffer_queue(hwc, &error);
228                         ASSERT_NE(TDM_ERROR_NONE, error);
229                         ASSERT_EQ(NULL, queue);
230                 }
231         }
232 }
233
234 TEST_P(TDMHwc, GetClientTargetBufferQueueSuccessful)
235 {
236         TDM_UT_SKIP_FLAG(has_outputs);
237
238         tdm_hwc *hwc = NULL;
239         tdm_error error = TDM_ERROR_NONE;
240         tbm_surface_queue_h queue = NULL;
241
242         for (int o = 0; o < output_count; o++) {
243                 hwc = tdm_output_get_hwc(outputs[o], &error);
244                 if (hwc) {
245                         queue = tdm_hwc_get_client_target_buffer_queue(hwc, &error);
246                         tbm_surface_queue_destroy(queue);
247                         ASSERT_EQ(TDM_ERROR_NONE, error);
248                         ASSERT_NE(NULL, queue);
249
250                         queue = tdm_hwc_get_client_target_buffer_queue(hwc, NULL);
251                         tbm_surface_queue_destroy(queue);
252                         ASSERT_EQ(TDM_ERROR_NONE, error);
253                         ASSERT_NE(NULL, queue);
254                 } else {
255                         queue = tdm_hwc_get_client_target_buffer_queue(hwc, &error);
256                         ASSERT_NE(TDM_ERROR_NONE, error);
257                         ASSERT_EQ(NULL, queue);
258
259                         queue = tdm_hwc_get_client_target_buffer_queue(hwc, NULL);
260                         ASSERT_NE(TDM_ERROR_NONE, error);
261                         ASSERT_EQ(NULL, queue);
262                 }
263         }
264 }
265
266 /* tdm_hwc_set_client_target_buffer() */
267 TEST_P(TDMHwc, SetClientTargetBufferFailNullOutput)
268 {
269         TDM_UT_SKIP_FLAG(has_outputs);
270
271         tdm_region damage = {.num_rects = 0, .rects = NULL};
272         tbm_surface_h target_buff = NULL;
273
274         target_buff = tbm_surface_internal_create_with_flags(720, 1024,
275                                                                         TBM_FORMAT_ARGB8888, TBM_BO_DEFAULT);
276         ASSERT_NE(NULL, target_buff);
277
278         error = tdm_hwc_set_client_target_buffer(NULL, target_buff, damage);
279         tbm_surface_internal_destroy(target_buff);
280         ASSERT_NE(TDM_ERROR_NONE, error);
281 }
282
283 TEST_P(TDMHwc, SetClientTargetBufferSuccessfulSetBuff)
284 {
285         TDM_UT_SKIP_FLAG(has_outputs);
286
287         tdm_hwc *hwc = NULL;
288         tdm_error error = TDM_ERROR_NONE;
289         tdm_region damage = {.num_rects = 0, .rects = NULL};
290         const tdm_output_mode *mode = NULL;
291         tbm_surface_h target_buff = NULL;
292
293         for (int o = 0; o < output_count; o++) {
294                 hwc = tdm_output_get_hwc(outputs[o], &error);
295                 if (hwc) {
296                         ASSERT_EQ(tdm_output_get_mode(outputs[o], &mode), TDM_ERROR_NONE);
297                         target_buff = tbm_surface_internal_create_with_flags(mode->hdisplay, mode->vdisplay,
298                                                                         TBM_FORMAT_ARGB8888, TBM_BO_DEFAULT);
299                         ASSERT_NE(NULL, target_buff);
300
301                         error = tdm_hwc_set_client_target_buffer(hwc, target_buff, damage);
302                         tbm_surface_internal_destroy(target_buff);
303                         ASSERT_EQ(TDM_ERROR_NONE, error);
304                 } else {
305                         error = tdm_hwc_set_client_target_buffer(hwc, target_buff, damage);
306                         ASSERT_NE(TDM_ERROR_NONE, error);
307                 }
308         }
309 }
310
311 TEST_P(TDMHwc, SetClientTargetBufferSuccessfulResetBuff)
312 {
313         TDM_UT_SKIP_FLAG(has_outputs);
314
315         tdm_hwc *hwc = NULL;
316         tdm_error error = TDM_ERROR_NONE;
317         tdm_region damage = {.num_rects = 0, .rects = NULL};
318         tbm_surface_h target_buff = NULL;
319
320         for (int o = 0; o < output_count; o++) {
321                 hwc = tdm_output_get_hwc(outputs[o], &error);
322                 if (hwc) {
323                         error = tdm_hwc_set_client_target_buffer(hwc, NULL, damage);
324                         tbm_surface_internal_destroy(target_buff);
325                         ASSERT_EQ(TDM_ERROR_NONE, error);
326                 } else {
327                         error = tdm_hwc_set_client_target_buffer(hwc, NULL, damage);
328                         ASSERT_NE(TDM_ERROR_NONE, error);
329                 }
330         }
331 }
332
333 /* tdm_hwc_validate() */
334 TEST_P(TDMHwc, ValidateFailNull)
335 {
336         TDM_UT_SKIP_FLAG(has_outputs);
337
338         tdm_hwc *hwc = NULL;
339         tdm_error error = TDM_ERROR_NONE;
340         uint32_t num_types;
341
342         error = tdm_hwc_validate(NULL, NULL, 0, &num_types);
343         ASSERT_NE(TDM_ERROR_NONE, error);
344
345         for (int o = 0; o < output_count; o++) {
346                 hwc = tdm_output_get_hwc(outputs[o], &error);
347                 if (hwc) {
348                         error = tdm_hwc_validate(hwc, NULL, 0, NULL);
349                         ASSERT_NE(TDM_ERROR_NONE, error);
350                 } else {
351                         error = tdm_hwc_validate(hwc, NULL, 0, NULL);
352                         ASSERT_NE(TDM_ERROR_NONE, error);
353                 }
354         }
355 }
356
357 /* tdm_hwc_get_changed_composition_types() */
358 TEST_P(TDMHwc, GetChangedCompositionTypesFailNull)
359 {
360         TDM_UT_SKIP_FLAG(has_outputs);
361
362         tdm_hwc *hwc = NULL;
363         tdm_error error = TDM_ERROR_NONE;
364         uint32_t num_elements;
365
366         error = tdm_hwc_get_changed_composition_types(NULL, &num_elements, NULL, NULL);
367         ASSERT_NE(TDM_ERROR_NONE, error);
368
369         for (int o = 0; o < output_count; o++) {
370                 hwc = tdm_output_get_hwc(outputs[o], &error);
371                 if (hwc) {
372                         error = tdm_hwc_get_changed_composition_types(hwc, NULL, NULL, NULL);
373                         ASSERT_NE(TDM_ERROR_NONE, error);
374                 } else {
375                         error = tdm_hwc_get_changed_composition_types(hwc, NULL, NULL, NULL);
376                         ASSERT_NE(TDM_ERROR_NONE, error);
377                 }
378         }
379 }
380
381 /* tdm_error tdm_hwc_accept_changes() */
382 TEST_P(TDMHwc, AcceptChangesFailNull)
383 {
384         TDM_UT_SKIP_FLAG(has_outputs);
385
386         error = tdm_hwc_accept_changes(NULL);
387         ASSERT_NE(TDM_ERROR_NONE, error);
388 }
389
390 TEST_P(TDMHwc, AcceptChangesFailNoHwc)
391 {
392         tdm_hwc *hwc = NULL;
393         tdm_error error = TDM_ERROR_NONE;
394
395         for (int o = 0; o < output_count; o++) {
396                 hwc = tdm_output_get_hwc(outputs[o], &error);
397                 if (hwc) {
398                         error = tdm_hwc_accept_changes(hwc);
399                         ASSERT_NE(TDM_ERROR_NONE, error);
400                 } else {
401                         error = tdm_hwc_accept_changes(hwc);
402                         ASSERT_NE(TDM_ERROR_NONE, error);
403                 }
404         }
405 }
406
407 TEST_P(TDMHwc, AcceptChangesSuccessful)
408 {
409         TDM_UT_SKIP_FLAG(has_outputs);
410
411         tdm_hwc *hwc = NULL;
412         tdm_error error = TDM_ERROR_NONE;
413         tdm_hwc_window *hwc_wnds[HWC_WIN_NUM];
414         tdm_hwc_window **changed_hwc_window = NULL;
415         tdm_hwc_window_composition *composition_types = NULL;
416         uint32_t num_types;
417         uint32_t get_num = 0;
418
419         for (int o = 0; o < output_count; o++) {
420                 hwc = tdm_output_get_hwc(outputs[o], &error);
421                 if (hwc) {
422                         for (int w = 0; w < HWC_WIN_NUM; w++) {
423                                 hwc_wnds[w] = tdm_hwc_create_window(hwc, &error);
424                                 ASSERT_EQ(TDM_ERROR_NONE, error);
425                                 error = tdm_hwc_window_set_composition_type(hwc_wnds[w], TDM_COMPOSITION_DEVICE);
426                                 ASSERT_EQ(TDM_ERROR_NONE, error);
427                         }
428
429                         error = tdm_hwc_validate(hwc, hwc_wnds, HWC_WIN_NUM, &num_types);
430                         ASSERT_EQ(TDM_ERROR_NONE, error);
431
432                         if (num_types > 0) {
433                                 changed_hwc_window = (tdm_hwc_window **)calloc(num_types, sizeof(tdm_hwc_window *));
434                                 composition_types = (tdm_hwc_window_composition *)calloc(num_types, sizeof(tdm_hwc_window_composition));
435
436                                 error = tdm_hwc_get_changed_composition_types(hwc, &get_num, changed_hwc_window, composition_types);
437                                 ASSERT_EQ(TDM_ERROR_NONE, error);
438                                 ASSERT_EQ(get_num, num_types);
439
440                                 error =  tdm_hwc_accept_changes(hwc);
441                                 ASSERT_EQ(TDM_ERROR_NONE, error);
442
443                                 free(composition_types);
444                                 free(changed_hwc_window);
445                         }
446
447                         for (int w = 0; w < HWC_WIN_NUM; w++)
448                                 tdm_hwc_window_destroy(hwc_wnds[w]);
449
450                                 ASSERT_EQ(TDM_ERROR_NONE, error);
451                         }
452         }
453 }
454
455 /* tdm_error tdm_hwc_commit() */
456 TEST_P(TDMHwc, CommitFailNull)
457 {
458         TDM_UT_SKIP_FLAG(has_outputs);
459
460         error = tdm_hwc_commit(NULL, 1, NULL, NULL);
461         ASSERT_NE(TDM_ERROR_NONE, error);
462 }
463
464 TEST_P(TDMHwc, CommitSuccessful)
465 {
466         TDM_UT_SKIP_FLAG(has_outputs);
467
468         tdm_hwc *hwc = NULL;
469         tdm_error error = TDM_ERROR_NONE;
470         tdm_hwc_window *hwc_wnds[HWC_WIN_NUM];
471         tdm_hwc_window **changed_hwc_window = NULL;
472         tdm_hwc_window_composition *composition_types = NULL;
473         uint32_t num_types;
474         uint32_t get_num = 0;
475
476         for (int o = 0; o < output_count; o++) {
477                 hwc = tdm_output_get_hwc(outputs[o], &error);
478                 if (hwc) {
479                         for (int w = 0; w < HWC_WIN_NUM; w++) {
480                                 hwc_wnds[w] = tdm_hwc_create_window(hwc, &error);
481                                 ASSERT_EQ(TDM_ERROR_NONE, error);
482                                 error = tdm_hwc_window_set_composition_type(hwc_wnds[w], TDM_COMPOSITION_DEVICE);
483                                 ASSERT_EQ(TDM_ERROR_NONE, error);
484                         }
485
486                         error = tdm_hwc_validate(hwc, hwc_wnds, HWC_WIN_NUM, &num_types);
487                         ASSERT_EQ(TDM_ERROR_NONE, error);
488
489                         if (num_types > 0) {
490                                 changed_hwc_window = (tdm_hwc_window **)calloc(num_types, sizeof(tdm_hwc_window *));
491                                 composition_types = (tdm_hwc_window_composition *)calloc(num_types, sizeof(tdm_hwc_window_composition));
492
493                                 error = tdm_hwc_get_changed_composition_types(hwc, &get_num, changed_hwc_window, composition_types);
494                                 ASSERT_EQ(TDM_ERROR_NONE, error);
495                                 ASSERT_EQ(get_num, num_types);
496
497                                 error =  tdm_hwc_accept_changes(hwc);
498                                 ASSERT_EQ(TDM_ERROR_NONE, error);
499
500                                 free(composition_types);
501                                 free(changed_hwc_window);
502                         }
503
504                         error = tdm_hwc_commit(hwc, 0, _tc_tdm_hwc_commit_cb, NULL);
505                         ASSERT_NE(TDM_ERROR_NONE, error);
506
507                         for (int w = 0; w < HWC_WIN_NUM; w++)
508                                 tdm_hwc_window_destroy(hwc_wnds[w]);
509
510                                 ASSERT_EQ(TDM_ERROR_NONE, error);
511                         }
512         }
513 }
514
515 #ifdef TDM_UT_TEST_WITH_PARAMS
516 INSTANTIATE_TEST_CASE_P(TDMHwcParams,
517                                                 TDMHwc,
518                                                 Combine(Bool(), Bool(), Values(TDM_DEFAULT_MODULE)));
519 #else
520 INSTANTIATE_TEST_CASE_P(TDMHwcParams,
521                                                 TDMHwc,
522                                                 Values(TDM_DEFAULT_MODULE));
523 #endif
524
525 /* LCOV_EXCL_END */