3af1f35da4725721da80ee35fb4161df34c31c14
[platform/core/uifw/libtdm.git] / haltests / src / tc_tdm_hwc_window.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 TDMHwcWindow : public TDMOutput
38 {
39 public:
40         TDMHwcWindow();
41         void SetUp(void);
42         void TearDown(void);
43
44         tdm_error error;
45         tdm_hwc_window **hwc_wins;
46         int hwc_count;
47 };
48
49 TDMHwcWindow::TDMHwcWindow()
50 {
51         error = TDM_ERROR_NONE;
52         hwc_wins = NULL;
53         hwc_count = 0;
54         video_hwc_win = NULL;
55 }
56
57 void TDMHwcWindow::SetUp(void)
58 {
59         tdm_hwc_window *hw = NULL;
60
61         TDMOutput::SetUp();
62
63         hwc_wins = (tdm_hwc_window **)calloc(output_count * HWC_WIN_NUM, sizeof(tdm_hwc_window *));
64
65         //create HWC_WIN_NUM hwc_windows for each outputs
66         for (int o = 0; o < output_count; o++) {
67                 if (tc_tdm_output_is_hwc_enable(outputs[o])) {
68                         for (int w = 0; w < HWC_WIN_NUM; w++) {
69                                 hw = tdm_hwc_create_window(outputs[w], &error);
70                                 ASSERT_EQ(TDM_ERROR_NONE, error);
71                                 hwc_wins[hwc_count++] = hw;
72                         }
73                 }
74         }
75 }
76
77 void TDMHwcWindow::TearDown(void)
78 {
79         for (int w = 0; w < hwc_count; w++)
80                 tdm_hwc_window_destroy(hwc_wins[w]);
81
82         TDMOutput::TearDown();
83 }
84
85 /* void tdm_hwc_window_destroy(tdm_hwc_window *hwc_window); */
86 /*
87 TEST_P(TDMHwcWindow, DestroyWindowFailNull)
88 {
89         tdm_hwc_window_destroy(NULL);
90 }
91
92 TEST_P(TDMHwcWindow, DestroyWindowSuccessful)
93 {
94         TDM_UT_SKIP_FLAG(has_outputs);
95
96         tdm_hwc_window *hw = NULL;
97
98         for (int o = 0; o < output_count; o++) {
99                 if (tc_tdm_output_is_hwc_enable(outputs[o])) {
100                         hw = tdm_hwc_create_window(outputs[o], &error);
101                         ASSERT_EQ(TDM_ERROR_NONE, error);
102                         error = tdm_hwc_window_destroy(outputs[o], hw);
103                         ASSERT_EQ(TDM_ERROR_NONE, error);
104                 }
105         }
106 }
107 */
108
109 /* tbm_surface_queue_h tdm_hwc_window_get_buffer_queue(tdm_hwc_window *hwc_window, tdm_error *error); */
110 TEST_P(TDMHwcWindow, GetBufferQueueFailNull)
111 {
112         TDM_UT_SKIP_FLAG(has_outputs);
113
114         tbm_surface_queue_h queue = NULL;
115
116         queue = tdm_hwc_window_get_buffer_queue(NULL, &error);
117         ASSERT_NE(TDM_ERROR_NONE, error);
118         ASSERT_EQ(NULL, queue);
119
120         queue = tdm_hwc_window_get_buffer_queue(NULL, NULL);
121         ASSERT_EQ(NULL, queue);
122 }
123
124 TEST_P(TDMHwcWindow, GetBufferQueueSuccessful)
125 {
126         TDM_UT_SKIP_FLAG(has_outputs);
127
128         tbm_surface_queue_h queue = NULL;
129         tdm_hwc_window_info info = { 0 };
130
131         info.src_config.format = TBM_FORMAT_ARGB8888;
132         info.src_config.size.h = info.src_config.size.v = 256;
133         info.src_config.pos.h = info.src_config.pos.w = 256;
134         info.dst_pos.h = info.dst_pos.w = 256;
135         info.transform = TDM_TRANSFORM_NORMAL;
136
137         for (int w = 0; w < hwc_count; w++) {
138                 error = tdm_hwc_window_set_info(hwc_wins[w], &info);
139                 ASSERT_EQ(TDM_ERROR_NONE, error);
140
141                 queue = tdm_hwc_window_get_buffer_queue(hwc_wins[w], &error);
142                 tbm_surface_queue_destroy(queue);
143                 ASSERT_EQ(TDM_ERROR_NONE, error);
144                 ASSERT_NE(NULL, queue);
145
146                 queue = tdm_hwc_window_get_buffer_queue(hwc_wins[w], NULL);
147                 tbm_surface_queue_destroy(queue);
148                 ASSERT_NE(NULL, queue);
149         }
150 }
151
152 /* tdm_error tdm_hwc_window_set_composition_type(tdm_hwc_window *hwc_window,
153                                                                         tdm_hwc_window_composition composition_type); */
154 TEST_P(TDMHwcWindow, SetCompositionTypeFailNull)
155 {
156         TDM_UT_SKIP_FLAG(has_outputs);
157
158         error = tdm_hwc_window_set_composition_type(NULL, TDM_COMPOSITION_DEVICE);
159         ASSERT_NE(TDM_ERROR_NONE, error);
160 }
161
162 TEST_P(TDMHwcWindow, SetCompositionTypeSuccessful)
163 {
164         TDM_UT_SKIP_FLAG(has_outputs);
165
166         for (int w = 0; w < hwc_count; w++) {
167                 error = tdm_hwc_window_set_composition_type(hwc_wins[w], TDM_COMPOSITION_DEVICE);
168                 ASSERT_EQ(TDM_ERROR_NONE, error);
169                 error = tdm_hwc_window_set_composition_type(hwc_wins[w], TDM_COMPOSITION_CLIENT);
170                 ASSERT_EQ(TDM_ERROR_NONE, error);
171                 error = tdm_hwc_window_set_composition_type(hwc_wins[w], TDM_COMPOSITION_CURSOR);
172                 ASSERT_EQ(TDM_ERROR_NONE, error);
173         }
174 }
175
176 TEST_P(TDMHwcWindow, SetCompositionTypeFailInvalieCompositionType)
177 {
178         TDM_UT_SKIP_FLAG(has_outputs);
179
180         for (int w = 0; w < hwc_count; w++) {
181                 error = tdm_hwc_window_set_composition_type(hwc_wins[w], tdm_hwc_window_composition(TDM_COMPOSITION_NONE - 1));
182                 ASSERT_NE(TDM_ERROR_NONE, error);
183         }
184 }
185
186 /* tdm_error tdm_hwc_window_set_buffer_damage(tdm_hwc_window *hwc_window, tdm_region damage); */
187 TEST_P(TDMHwcWindow, SetBufferDamageFailNullHwcWindow)
188 {
189         TDM_UT_SKIP_FLAG(has_outputs);
190
191         tdm_region damage = {.num_rects = 0, .rects = NULL};
192
193         error = tdm_hwc_window_set_buffer_damage(NULL, damage);
194         ASSERT_NE(TDM_ERROR_NONE, error);
195 }
196
197 TEST_P(TDMHwcWindow, SetBufferDamageFailNullDamageRects)
198 {
199         TDM_UT_SKIP_FLAG(has_outputs);
200
201         tdm_region damage = {.num_rects = 1, .rects = NULL};
202
203         for (int w = 0; w < hwc_count; w++) {
204                 error = tdm_hwc_window_set_buffer_damage(hwc_wins[w], damage);
205                 ASSERT_NE(TDM_ERROR_NONE, error);
206         }
207 }
208
209
210 TEST_P(TDMHwcWindow, SetBufferDamageSuccessful)
211 {
212         TDM_UT_SKIP_FLAG(has_outputs);
213
214         tdm_pos const rects[1] = {0};
215         tdm_region damage = {.num_rects = 1, .rects = rects};
216
217         for (int w = 0; w < hwc_count; w++) {
218                 error = tdm_hwc_window_set_buffer_damage(hwc_wins[w], damage);
219                 ASSERT_EQ(TDM_ERROR_NONE, error);
220         }
221 }
222
223
224 /* tdm_error tdm_hwc_window_set_info(tdm_hwc_window *hwc_window, tdm_hwc_window_info *info); */
225 TEST_P(TDMHwcWindow, SetInfoFailNull)
226 {
227         TDM_UT_SKIP_FLAG(has_outputs);
228
229         tdm_hwc_window_info info = { 0 };
230
231         error = tdm_hwc_window_set_info(NULL, &info);
232         ASSERT_NE(TDM_ERROR_NONE, error);
233
234         if (hwc_count > 0) {
235                 error = tdm_hwc_window_set_info(hwc_wins[0], NULL);
236                 ASSERT_NE(TDM_ERROR_NONE, error);
237         }
238 }
239
240 TEST_P(TDMHwcWindow, SetInfoSuccessful)
241 {
242         TDM_UT_SKIP_FLAG(has_outputs);
243
244         tdm_hwc_window_info info = { 0 };
245
246         for (int w = 0; w < hwc_count; w++) {
247                 error = tdm_hwc_window_set_info(hwc_wins[w], &info);
248                 ASSERT_EQ(TDM_ERROR_NONE, error);
249         }
250 }
251
252
253 /* tdm_error tdm_hwc_window_set_buffer(tdm_hwc_window *hwc_window, tbm_surface_h buffer); */
254 TEST_P(TDMHwcWindow, SetBufferFailNull)
255 {
256         TDM_UT_SKIP_FLAG(has_outputs);
257
258         error = tdm_hwc_window_set_buffer(NULL, NULL);
259         ASSERT_NE(TDM_ERROR_NONE, error);
260 }
261
262 TEST_P(TDMHwcWindow, SetBufferSuccessful)
263 {
264         TDM_UT_SKIP_FLAG(has_outputs);
265
266         for (int w = 0; w < hwc_count; w++) {
267
268                 tbm_surface_h buff = tbm_surface_create(256, 256, TBM_FORMAT_ARGB8888);
269
270                 /* test: set*/
271                 error = tdm_hwc_window_set_buffer(hwc_wins[w], buff);
272                 tbm_surface_destroy(buff);
273                 ASSERT_EQ(TDM_ERROR_NONE, error);
274
275                 /* test: reset*/
276                 error = tdm_hwc_window_set_buffer(hwc_wins[w], NULL);
277                 ASSERT_EQ(TDM_ERROR_NONE, error);
278         }
279 }
280
281 /* tdm_hwc_get_available_properties() */
282 /*
283 TEST_P(TDMHwcWindow, GetAvailablePropertiesFailNullWin)
284 {
285         TDM_UT_SKIP_FLAG(has_outputs);
286
287         TDM_UT_SKIP_FLAG(video_hwc_win != NULL);
288         const tdm_prop *props;
289         int count;
290
291         error = tdm_hwc_get_available_properties(NULL, &props, &count);
292         ASSERT_NE(TDM_ERROR_NONE, error);
293
294         error = tdm_hwc_get_available_properties(video_hwc_win, NULL, &count);
295         ASSERT_NE(TDM_ERROR_NONE, error);
296
297         error = tdm_hwc_get_available_properties(video_hwc_win, &props, NULL);
298         ASSERT_NE(TDM_ERROR_NONE, error);
299 }
300
301 TEST_P(TDMHwcWindow, GetAvailablePropertiesSuccess)
302 {
303         TDM_UT_SKIP_FLAG(has_outputs);
304
305         TDM_UT_SKIP_FLAG(video_hwc_win != NULL);
306
307         const tdm_prop *props;
308         int count;
309
310         error = tdm_hwc_get_available_properties(video_hwc_win, &props, &count);
311         ASSERT_TRUE(TDM_ERROR_NONE == error || TDM_ERROR_NOT_IMPLEMENTED == error);
312 }
313 */
314
315 /* tdm_hwc_window_get_property() */
316 TEST_P(TDMHwcWindow, GetPropertyFailNull)
317 {
318         TDM_UT_SKIP_FLAG(has_outputs);
319         TDM_UT_SKIP_FLAG(video_hwc_win != NULL);
320
321         tdm_value value;
322         int id = 1;
323
324         error = tdm_hwc_window_get_property(NULL, id, &value);
325         ASSERT_NE(TDM_ERROR_NONE, error);
326
327         error = tdm_hwc_window_get_property(video_hwc_win, id, NULL);
328         ASSERT_NE(TDM_ERROR_NONE, error);
329 }
330
331 TEST_P(TDMHwcWindow, GetPropertyFailWrongId)
332 {
333         TDM_UT_SKIP_FLAG(has_outputs);
334         TDM_UT_SKIP_FLAG(video_hwc_win != NULL);
335
336         tdm_value value;
337         int id = INT_MAX;
338
339         error = tdm_hwc_window_get_property(video_hwc_win, id, &value);
340         ASSERT_NE(TDM_ERROR_NONE, error);
341 }
342
343 /* tdm_hwc_window_set_property() */
344 TEST_P(TDMHwcWindow, SetPropertyFailNull)
345 {
346         TDM_UT_SKIP_FLAG(has_outputs);
347         TDM_UT_SKIP_FLAG(video_hwc_win != NULL);
348
349         tdm_value value;
350         int id = 1;
351
352         error = tdm_hwc_window_set_property(NULL, id, value);
353         ASSERT_NE(TDM_ERROR_NONE, error);
354 }
355
356 TEST_P(TDMHwcWindow, SetPropertyFailWrongId)
357 {
358         TDM_UT_SKIP_FLAG(has_outputs);
359         TDM_UT_SKIP_FLAG(video_hwc_win != NULL);
360
361         tdm_value value;
362         int id = INT_MAX;
363
364         error = tdm_hwc_window_set_property(video_hwc_win, id, value);
365         ASSERT_NE(TDM_ERROR_NONE, error);
366 }
367
368 #ifdef TDM_UT_TEST_WITH_PARAMS
369 INSTANTIATE_TEST_CASE_P(TDMHwcWindowParams,
370                                                 TDMHwcWindow,
371                                                 Combine(Bool(), Bool(), Values(TDM_DEFAULT_MODULE)));
372 #else
373 INSTANTIATE_TEST_CASE_P(TDMHwcWindowParams,
374                                                 TDMHwcWindow,
375                                                 Values(TDM_DEFAULT_MODULE));
376 #endif
377
378 /* LCOV_EXCL_END */