haltests: use EXPECT intead of ASSERT
[platform/core/uifw/libtdm.git] / haltests / src / tc_tdm_backend_capture.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 class TDMBackendCapture : public TDMBackendDisplay
35 {
36 public:
37         bool has_capture_cap;
38
39         tdm_capture *capture;
40         tdm_capture_capability capabilities;
41         const tbm_format *formats;
42         int format_count;
43         int min_w;
44         int min_h;
45         int max_w;
46         int max_h;
47         int preferred_align;
48
49         tbm_surface_h buffers[3];
50
51         tdm_info_capture info;
52
53         tdm_output *output;
54         unsigned int pipe;
55         const tdm_output_mode *mode;
56
57         tdm_layer *dst_layer;
58         int dst_zpos;
59         int dst_layer_index;
60         tdm_pos dst_pos;
61
62         bool stream_exit;
63         int stream_count;
64
65         TDMBackendCapture();
66         void SetUp(void);
67         void TearDown(void);
68
69         bool FindLayer(int output_idx, tbm_format fmt, tdm_pos *punch);
70         bool TestPrepareDefault(void);
71         bool TestPrepare(int output_idx, int w, int h, tbm_format fmt, tdm_transform t, tdm_capture_type c, int frequency, bool stretch);
72         void TestDone(void);
73         void ShowBuffer(int b, tdm_pos *pos);
74         void HideLayer(void);
75         void DumpBuffer(int b, char *test);
76         void DestroyBuffers(void);
77 };
78
79 TDMBackendCapture::TDMBackendCapture()
80 {
81         has_capture_cap = false;
82         capture = NULL;
83         capabilities = (tdm_capture_capability)0;
84         formats = NULL;
85         format_count = 0;
86         min_w = min_h = max_w = max_h = preferred_align = -1;
87
88         for (int b = 0; b < 3; b++)
89                 buffers[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_zpos = 0;
98         dst_layer_index = 0;
99         memset(&dst_pos, 0, sizeof dst_pos);
100
101         stream_exit = false;
102         stream_count = 0;
103 }
104
105 void TDMBackendCapture::SetUp(void)
106 {
107         tdm_display_capability dpy_capabilities;
108
109         TDMBackendDisplay::SetUp();
110
111         EXPECT_EQ(tdm_display_get_capabilities(dpy, &dpy_capabilities), TDM_ERROR_NONE);
112         has_capture_cap = dpy_capabilities & TDM_DISPLAY_CAPABILITY_CAPTURE;
113
114         if (!has_capture_cap)
115                 return;
116
117         EXPECT_EQ(tdm_display_get_capture_capabilities(dpy, &capabilities), TDM_ERROR_NONE);
118         EXPECT_GT(capabilities, 0);
119         EXPECT_EQ(tdm_display_get_capture_available_formats(dpy, &formats, &format_count), TDM_ERROR_NONE);
120         EXPECT_NE(formats, NULL);
121         EXPECT_GT(format_count, 0);
122         EXPECT_EQ(tdm_display_get_capture_available_size(dpy, &min_w, &min_h, &max_w, &max_h, &preferred_align), TDM_ERROR_NONE);
123         EXPECT_TRUE(min_w == -1 || min_w > 0);
124         EXPECT_TRUE(min_h == -1 || min_h > 0);
125         EXPECT_TRUE(max_w == -1 || max_w > 0);
126         EXPECT_TRUE(max_h == -1 || max_h > 0);
127         EXPECT_TRUE(preferred_align == -1 || preferred_align > 0);
128
129         for (int o = 0; o < output_count; o++) {
130                 if (!tc_tdm_output_is_connected(outputs[o]))
131                         continue;
132
133                 EXPECT_EQ(tc_tdm_output_prepare(dpy, outputs[o], true), true);
134         }
135 }
136
137 void TDMBackendCapture::TearDown(void)
138 {
139         if (capture)
140                 tdm_capture_destroy(capture);
141
142         for (int o = 0; o < output_count; o++) {
143                 if (!tc_tdm_output_is_connected(outputs[o]))
144                         continue;
145
146                 EXPECT_EQ(tc_tdm_output_unset(dpy, outputs[o]), true);
147         }
148
149         DestroyBuffers();
150
151         TDMBackendDisplay::TearDown();
152 }
153
154 bool TDMBackendCapture::FindLayer(int output_idx, tbm_format fmt, tdm_pos *punch)
155 {
156         tdm_error ret;
157         int count;
158         int primary_zpos, zpos;
159         tdm_layer *primary = tc_tdm_output_get_primary_layer(outputs[output_idx]);
160         TDM_UT_RETURN_FALSE_IF_FAIL(primary != NULL);
161         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_output_get_layer_count(outputs[output_idx], &count) == TDM_ERROR_NONE);
162         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_zpos(primary, &primary_zpos) == TDM_ERROR_NONE);
163
164         dst_layer = NULL;
165
166         for (int l = 0; l < count; l++) {
167                 unsigned int usable;
168                 const tbm_format *dst_formats;
169                 int dst_format_count;
170
171                 tdm_layer *temp = tdm_output_get_layer(outputs[output_idx], l, &ret);
172                 TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
173                 TDM_UT_RETURN_FALSE_IF_FAIL(temp != NULL);
174                 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_is_usable(temp, &usable) == TDM_ERROR_NONE);
175                 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_zpos(temp, &zpos) == TDM_ERROR_NONE);
176                 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_available_formats(temp, &dst_formats, &dst_format_count) == TDM_ERROR_NONE);
177                 TDM_UT_RETURN_FALSE_IF_FAIL(dst_formats != NULL);
178                 TDM_UT_RETURN_FALSE_IF_FAIL(dst_format_count > 0);
179
180                 if (usable) {
181                         bool found = false;
182                         for (int f = 0; f < dst_format_count; f++) {
183                                 if (dst_formats[f] == fmt) {
184                                         found = true;
185                                         break;
186                                 }
187                         }
188                         if (!found)
189                                 continue;
190                         dst_layer = temp;
191                         dst_zpos = zpos;
192                         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_index(dst_layer, &dst_layer_index) == TDM_ERROR_NONE);
193                         break;
194                 }
195         }
196
197         if (dst_layer && (dst_zpos < primary_zpos)) {
198                 tbm_surface_h displaying_buffer = tdm_layer_get_displaying_buffer(primary, &ret);
199                 TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
200                 TDM_UT_RETURN_FALSE_IF_FAIL(displaying_buffer != NULL);
201                 tdm_helper_clear_buffer_pos(displaying_buffer, punch);
202         }
203
204         return true;
205 }
206
207 bool TDMBackendCapture::TestPrepareDefault(void)
208 {
209         tdm_error ret;
210
211         for (int o = 0; o < output_count; o++) {
212                 if (!tc_tdm_output_is_connected(outputs[o]))
213                         continue;
214
215                 capture = tdm_output_create_capture(outputs[o], &ret);
216                 TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
217                 TDM_UT_RETURN_FALSE_IF_FAIL(capture != NULL);
218
219                 TDM_UT_RETURN_FALSE_IF_FAIL(tc_tdm_buffer_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[0], 0, false, 3, buffers) == true);
220                 TDM_UT_RETURN_FALSE_IF_FAIL(tc_tdm_capture_fill_info(outputs[o], buffers[0], TDM_TRANSFORM_NORMAL, TDM_CAPTURE_TYPE_ONESHOT, -1, false, &info) == true);
221                 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_capture_set_info(capture, &info) == TDM_ERROR_NONE);
222
223                 output = outputs[o];
224
225                 if (capture)
226                         break;
227         }
228
229         return (capture) ? true : false;
230 }
231
232 bool TDMBackendCapture::TestPrepare(int output_idx, int w, int h, tbm_format fmt, tdm_transform t, tdm_capture_type c, int frequency, bool stretch)
233 {
234         tdm_error ret;
235         int flags = 0;
236
237         TDM_UT_RETURN_FALSE_IF_FAIL(outputs != NULL);
238         TDM_UT_RETURN_FALSE_IF_FAIL(output_count > 0);
239         TDM_UT_RETURN_FALSE_IF_FAIL(output_count >= output_idx);
240
241         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_display_get_capture_capabilities(dpy, &capabilities) == TDM_ERROR_NONE);
242         TDM_UT_RETURN_FALSE_IF_FAIL(capabilities > 0);
243
244         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_display_get_capture_available_size(dpy, &min_w, &min_h, &max_w, &max_h, &preferred_align) == TDM_ERROR_NONE);
245         TDM_UT_RETURN_FALSE_IF_FAIL(min_w == -1 || min_w > 0);
246         TDM_UT_RETURN_FALSE_IF_FAIL(min_h == -1 || min_h > 0);
247         TDM_UT_RETURN_FALSE_IF_FAIL(max_w == -1 || max_w > 0);
248         TDM_UT_RETURN_FALSE_IF_FAIL(max_h == -1 || max_h > 0);
249         TDM_UT_RETURN_FALSE_IF_FAIL(preferred_align == -1 || preferred_align > 0);
250
251         capture = tdm_output_create_capture(outputs[output_idx], &ret);
252         TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
253         TDM_UT_RETURN_FALSE_IF_FAIL(capture != NULL);
254
255         if (dst_layer) {
256                 tdm_layer_capability capabilities;
257                 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_capabilities(dst_layer, &capabilities) == TDM_ERROR_NONE);
258                 if (capabilities & TDM_LAYER_CAPABILITY_SCANOUT)
259                         flags |= TBM_BO_SCANOUT;
260         }
261
262         if (tc_tdm_output_is_hwc_enable(outputs[output_idx]))
263                 flags |= TBM_BO_SCANOUT;
264
265         TDM_UT_RETURN_FALSE_IF_FAIL(tc_tdm_buffer_create(w, h, fmt, flags, false, 3, buffers) == true);
266         TDM_UT_RETURN_FALSE_IF_FAIL(tc_tdm_capture_fill_info(outputs[output_idx], buffers[0], t, c, frequency, stretch, &info) == true);
267         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_capture_set_info(capture, &info) == TDM_ERROR_NONE);
268
269         output = outputs[output_idx];
270
271         return true;
272 }
273
274 void TDMBackendCapture::TestDone(void)
275 {
276         if (capture) {
277                 tdm_capture_destroy(capture);
278                 capture = NULL;
279         }
280
281         DestroyBuffers();
282 }
283
284 void TDMBackendCapture::DumpBuffer(int b, char *test)
285 {
286         char filename[256];
287         if (test)
288                 snprintf(filename, sizeof filename, "%s_%s_%d", typeid(*this).name(), test, b);
289         else
290                 snprintf(filename, sizeof filename, "%s_%d", typeid(*this).name(), b);
291         tdm_helper_dump_buffer_str(buffers[b], NULL, filename);
292 }
293
294 void TDMBackendCapture::ShowBuffer(int b, tdm_pos *pos)
295 {
296         EXPECT_NE(output, NULL);
297         EXPECT_NE(dst_layer, NULL);
298
299         EXPECT_EQ(tc_tdm_layer_set_buffer_with_pos(dst_layer, buffers[b], pos), true);
300         EXPECT_EQ(tdm_output_commit(output, 0, NULL, NULL), TDM_ERROR_NONE);
301 }
302
303 void TDMBackendCapture::HideLayer(void)
304 {
305         EXPECT_NE(output, NULL);
306         EXPECT_NE(dst_layer, NULL);
307
308         tdm_layer_unset_buffer(dst_layer);
309         tdm_output_commit(output, 0, NULL, NULL);
310
311         dst_layer = NULL;
312 }
313
314 void TDMBackendCapture::DestroyBuffers(void)
315 {
316         for (int b = 0; b < 3; b++) {
317                 tbm_surface_destroy(buffers[b]);
318                 buffers[b] = NULL;
319         }
320 }
321
322 static void
323 _tc_tdm_capture_fit_rect(int src_w, int src_h, int dst_w, int dst_h, tdm_pos *fit)
324 {
325         float rw, rh;
326
327         if (src_w <= 0 || src_h <= 0 || dst_w <= 0 || dst_h <= 0 || !fit)
328                 return;
329
330         rw = (float)src_w / dst_w;
331         rh = (float)src_h / dst_h;
332
333         if (rw > rh) {
334                 fit->w = dst_w;
335                 fit->h = src_h / rw;
336                 fit->x = 0;
337                 fit->y = (dst_h - fit->h) / 2;
338         } else if (rw < rh) {
339                 fit->w = src_w / rh;
340                 fit->h = dst_h;
341                 fit->x = (dst_w - fit->w) / 2;
342                 fit->y = 0;
343         } else {
344                 fit->w = dst_w;
345                 fit->h = dst_h;
346                 fit->x = 0;
347                 fit->y = 0;
348         }
349
350         if (fit->x % 2)
351                 fit->x = fit->x - 1;
352 }
353
354 bool
355 tc_tdm_capture_fill_info(tdm_output *output, tbm_surface_h buffer, tdm_transform transform,
356                                                  tdm_capture_type type, int frequency, bool stretch, tdm_info_capture *info)
357 {
358         int bw, bh;
359         const tdm_output_mode *mode = NULL;
360
361         TDM_UT_RETURN_FALSE_IF_FAIL(tdm_output_get_mode(output, &mode) == TDM_ERROR_NONE);
362         TDM_UT_RETURN_FALSE_IF_FAIL(mode != NULL);
363
364         memset(info, 0, sizeof *info);
365
366         bw = bh = TDM_UT_INVALID_VALUE;
367         tdm_helper_get_buffer_full_size(buffer, &bw, &bh);
368
369         TDM_UT_RETURN_FALSE_IF_FAIL(bw != TDM_UT_INVALID_VALUE);
370         TDM_UT_RETURN_FALSE_IF_FAIL(bw >= tbm_surface_get_width(buffer));
371         TDM_UT_RETURN_FALSE_IF_FAIL(bh != TDM_UT_INVALID_VALUE);
372         TDM_UT_RETURN_FALSE_IF_FAIL(bh >= tbm_surface_get_height(buffer));
373         info->dst_config.size.h = bw;
374         info->dst_config.size.v = bh;
375
376         if (stretch) {
377                 info->dst_config.pos.x = 0;
378                 info->dst_config.pos.y = 0;
379                 info->dst_config.pos.w = tbm_surface_get_width(buffer);
380                 info->dst_config.pos.h = tbm_surface_get_height(buffer);
381         } else {
382                 _tc_tdm_capture_fit_rect(mode->hdisplay, mode->vdisplay,
383                                                                  tbm_surface_get_width(buffer), tbm_surface_get_height(buffer),
384                                                                  &info->dst_config.pos);
385         }
386
387         info->dst_config.format = tbm_surface_get_format(buffer);
388
389         info->transform = transform;
390         info->type = type;
391         info->flags = 0;
392
393         if (frequency <= 0)
394                 frequency = mode->vrefresh;
395
396         info->frequency = frequency;
397
398         TDM_UT_INFO("filling capture info done: dst_config(%dx%d: %d,%d %dx%d: %c%c%c%c) transform(%s) type(%s) freq(%d)",
399                                 info->dst_config.size.h, info->dst_config.size.v,
400                                 info->dst_config.pos.x, info->dst_config.pos.y, info->dst_config.pos.w, info->dst_config.pos.h,
401                                 FOURCC_STR(info->dst_config.format),
402                                 tdm_transform_str(info->transform), tdm_capture_type_str(info->type), info->frequency);
403
404         return true;
405 }
406
407 TEST_P(TDMBackendCapture, CaptureDispalyGetAvaiableFormats)
408 {
409         const tbm_format *formats = (const tbm_format *)TDM_UT_INVALID_VALUE;
410         int count = TDM_UT_INVALID_VALUE;
411         if (has_capture_cap) {
412                 EXPECT_EQ(tdm_display_get_capture_available_formats(dpy, &formats, &count), TDM_ERROR_NONE);
413                 EXPECT_TRUE(formats != NULL && formats != (const tbm_format *)TDM_UT_INVALID_VALUE);
414                 EXPECT_TRUE(count > 0 && count != TDM_UT_INVALID_VALUE);
415         } else {
416                 EXPECT_EQ(tdm_display_get_capture_available_formats(dpy, &formats, &count), TDM_ERROR_NO_CAPABILITY);
417                 EXPECT_EQ(formats, (const tbm_format *)TDM_UT_INVALID_VALUE);
418                 EXPECT_EQ(count, TDM_UT_INVALID_VALUE);
419         }
420 }
421
422 TEST_P(TDMBackendCapture, CaptureDispalyGetAvaiableFormatsNullObject)
423 {
424         const tbm_format *formats = (const tbm_format *)TDM_UT_INVALID_VALUE;
425         int count = TDM_UT_INVALID_VALUE;
426         EXPECT_EQ(tdm_display_get_capture_available_formats(NULL, &formats, &count), TDM_ERROR_INVALID_PARAMETER);
427         EXPECT_EQ(formats, (const tbm_format *)TDM_UT_INVALID_VALUE);
428         EXPECT_EQ(count, TDM_UT_INVALID_VALUE);
429 }
430
431 TEST_P(TDMBackendCapture, CaptureDispalyGetAvaiableFormatsNullOther)
432 {
433         EXPECT_EQ(tdm_display_get_capture_available_formats(dpy, NULL, NULL), TDM_ERROR_INVALID_PARAMETER);
434 }
435
436 TEST_P(TDMBackendCapture, CaptureDispalyGetAvaiableSize)
437 {
438         int min_w = TDM_UT_INVALID_VALUE;
439         int min_h = TDM_UT_INVALID_VALUE;
440         int max_w = TDM_UT_INVALID_VALUE;
441         int max_h = TDM_UT_INVALID_VALUE;
442         int preferred_align = TDM_UT_INVALID_VALUE;
443         if (has_capture_cap) {
444                 EXPECT_EQ(tdm_display_get_capture_available_size(dpy, &min_w, &min_h, &max_w, &max_h, &preferred_align), TDM_ERROR_NONE);
445                 EXPECT_NE(min_w, TDM_UT_INVALID_VALUE);
446                 EXPECT_NE(min_h, TDM_UT_INVALID_VALUE);
447                 EXPECT_NE(max_w, TDM_UT_INVALID_VALUE);
448                 EXPECT_NE(max_h, TDM_UT_INVALID_VALUE);
449                 EXPECT_NE(preferred_align, TDM_UT_INVALID_VALUE);
450         } else {
451                 EXPECT_EQ(tdm_display_get_capture_available_size(dpy, &min_w, &min_h, &max_w, &max_h, &preferred_align), TDM_ERROR_NO_CAPABILITY);
452                 EXPECT_EQ(min_w, TDM_UT_INVALID_VALUE);
453                 EXPECT_EQ(min_h, TDM_UT_INVALID_VALUE);
454                 EXPECT_EQ(max_w, TDM_UT_INVALID_VALUE);
455                 EXPECT_EQ(max_h, TDM_UT_INVALID_VALUE);
456                 EXPECT_EQ(preferred_align, TDM_UT_INVALID_VALUE);
457         }
458 }
459
460 TEST_P(TDMBackendCapture, CaptureDispalyGetAvaiableSizeNullObject)
461 {
462         int min_w = TDM_UT_INVALID_VALUE;
463         int min_h = TDM_UT_INVALID_VALUE;
464         int max_w = TDM_UT_INVALID_VALUE;
465         int max_h = TDM_UT_INVALID_VALUE;
466         int preferred_align = TDM_UT_INVALID_VALUE;
467         EXPECT_EQ(tdm_display_get_capture_available_size(NULL, &min_w, &min_h, &max_w, &max_h, &preferred_align), TDM_ERROR_INVALID_PARAMETER);
468         EXPECT_EQ(min_w, TDM_UT_INVALID_VALUE);
469         EXPECT_EQ(min_h, TDM_UT_INVALID_VALUE);
470         EXPECT_EQ(max_w, TDM_UT_INVALID_VALUE);
471         EXPECT_EQ(max_h, TDM_UT_INVALID_VALUE);
472         EXPECT_EQ(preferred_align, TDM_UT_INVALID_VALUE);
473 }
474
475 TEST_P(TDMBackendCapture, CaptureDispalyGetAvaiableSizeNullOther)
476 {
477         if (has_capture_cap)
478                 EXPECT_EQ(tdm_display_get_capture_available_size(dpy, NULL, NULL, NULL, NULL, NULL), TDM_ERROR_NONE);
479         else
480                 EXPECT_EQ(tdm_display_get_capture_available_size(dpy, NULL, NULL, NULL, NULL, NULL), TDM_ERROR_NO_CAPABILITY);
481 }
482
483 TEST_P(TDMBackendCapture, CaptureDestroy)
484 {
485         TDM_UT_SKIP_FLAG(has_capture_cap);
486         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
487
488         EXPECT_EQ(TestPrepareDefault(), true);
489
490         TestDone();
491 }
492
493 TEST_P(TDMBackendCapture, CaptureDestroyNullObject)
494 {
495         TDM_UT_SKIP_FLAG(has_capture_cap);
496         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
497
498         tdm_capture_destroy(NULL);
499 }
500
501 TEST_P(TDMBackendCapture, CaptureSetInfo)
502 {
503         /* tested in CaptureNoScaleNoTransformNoCSC */
504 }
505
506 TEST_P(TDMBackendCapture, CaptureSetInfoNullObject)
507 {
508         TDM_UT_SKIP_FLAG(has_capture_cap);
509         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
510
511         tdm_info_capture info;
512         memset(&info, 0, sizeof info);
513         EXPECT_EQ(tdm_capture_set_info(NULL, &info), TDM_ERROR_INVALID_PARAMETER);
514 }
515
516 TEST_P(TDMBackendCapture, CaptureSetInfoNullOther)
517 {
518         TDM_UT_SKIP_FLAG(has_capture_cap);
519         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
520
521         EXPECT_EQ(TestPrepareDefault(), true);
522
523         EXPECT_EQ(tdm_capture_set_info(capture, NULL), TDM_ERROR_INVALID_PARAMETER);
524
525         TestDone();
526 }
527
528 static void
529 _tc_tdm_capture_done_cb(tdm_capture *capture, tbm_surface_h buffer, void *user_data)
530 {
531         bool *done = (bool*)user_data;
532         if (done)
533                 *done = true;
534 }
535
536 TEST_P(TDMBackendCapture, CaptureSetDoneHandler)
537 {
538         TDM_UT_SKIP_FLAG(has_capture_cap);
539         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
540
541         EXPECT_EQ(TestPrepareDefault(), true);
542
543         EXPECT_EQ(tdm_capture_set_done_handler(capture, _tc_tdm_capture_done_cb, NULL), TDM_ERROR_NONE);
544
545         TestDone();
546 }
547
548 TEST_P(TDMBackendCapture, CaptureSetDoneHandlerNullObject)
549 {
550         TDM_UT_SKIP_FLAG(has_capture_cap);
551         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
552
553         EXPECT_EQ(tdm_capture_set_done_handler(NULL, _tc_tdm_capture_done_cb, NULL), TDM_ERROR_INVALID_PARAMETER);
554 }
555
556 TEST_P(TDMBackendCapture, CaptureSetDoneHandlerNullOther)
557 {
558         TDM_UT_SKIP_FLAG(has_capture_cap);
559         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
560
561         EXPECT_EQ(TestPrepareDefault(), true);
562
563         EXPECT_EQ(tdm_capture_set_done_handler(capture, NULL, NULL), TDM_ERROR_INVALID_PARAMETER);
564
565         TestDone();
566 }
567
568 TEST_P(TDMBackendCapture, CaptureAttach)
569 {
570         TDM_UT_SKIP_FLAG(has_capture_cap);
571         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
572
573         for (int o = 0; o < output_count; o++) {
574
575                 if (!tc_tdm_output_is_connected(outputs[o]))
576                         continue;
577
578                 for (int f = 0; f < format_count; f++) {
579                         if (tc_tdm_output_is_hwc_enable(outputs[o]))
580                                 dst_layer = NULL;
581                         else
582                                 FindLayer(o, formats[f], &dst_pos);
583
584                         EXPECT_EQ(TestPrepare(o, TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f],
585                                                                   TDM_TRANSFORM_NORMAL, TDM_CAPTURE_TYPE_ONESHOT, -1, false), true);
586
587                         for (int b = 0; b < 3; b++)
588                                 EXPECT_EQ(tdm_capture_attach(capture, buffers[b]), TDM_ERROR_NONE);
589
590                         TestDone();
591                 }
592         }
593 }
594
595 TEST_P(TDMBackendCapture, CaptureAttachNullObject)
596 {
597         TDM_UT_SKIP_FLAG(has_capture_cap);
598         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
599
600         tbm_surface_h buffer = (tbm_surface_h)TDM_UT_BUFFER_SIZE;
601
602         EXPECT_EQ(tdm_capture_attach(NULL, buffer), TDM_ERROR_INVALID_PARAMETER);
603 }
604
605 TEST_P(TDMBackendCapture, CaptureAttachNullOther)
606 {
607         TDM_UT_SKIP_FLAG(has_capture_cap);
608         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
609
610         EXPECT_EQ(TestPrepareDefault(), true);
611
612         EXPECT_EQ(tdm_capture_attach(capture, NULL), TDM_ERROR_INVALID_PARAMETER);
613
614         TestDone();
615 }
616
617 TEST_P(TDMBackendCapture, CaptureCommit)
618 {
619         TDM_UT_SKIP_FLAG(has_capture_cap);
620         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
621
622         EXPECT_EQ(TestPrepareDefault(), true);
623
624         EXPECT_EQ(tdm_capture_commit(capture), TDM_ERROR_NONE);
625
626         TestDone();
627 }
628
629 TEST_P(TDMBackendCapture, CaptureCommitNullOBject)
630 {
631         TDM_UT_SKIP_FLAG(has_capture_cap);
632         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
633
634         EXPECT_EQ(tdm_capture_commit(NULL), TDM_ERROR_INVALID_PARAMETER);
635 }
636
637 TEST_P(TDMBackendCapture, CaptureCommitDpmsOff)
638 {
639         TDM_UT_SKIP_FLAG(has_capture_cap);
640         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
641
642         EXPECT_EQ(TestPrepareDefault(), true);
643
644         EXPECT_EQ(tc_tdm_output_unset(dpy, output), true);
645
646         EXPECT_EQ(tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF), TDM_ERROR_NONE);
647
648         EXPECT_EQ(tdm_capture_commit(capture), TDM_ERROR_BAD_REQUEST);
649
650         TestDone();
651 }
652
653 static void
654 _tc_tdm_capture_done_cb2(tdm_capture *capture, tbm_surface_h buffer, void *user_data)
655 {
656         int *done = (int*)user_data;
657         if (done)
658                 (*done)++;
659 }
660
661 TEST_P(TDMBackendCapture, CaptureDestroyWithoutCommit)
662 {
663         TDM_UT_SKIP_FLAG(has_capture_cap);
664         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
665
666         for (int o = 0; o < output_count; o++) {
667                 const tdm_output_mode *mode = NULL;
668                 int f = 0;
669
670                 if (!tc_tdm_output_is_connected(outputs[o]))
671                         continue;
672
673                 EXPECT_EQ(tdm_output_get_mode(outputs[o], &mode), TDM_ERROR_NONE);
674
675                 if (tc_tdm_output_is_hwc_enable(outputs[o]))
676                         dst_layer = NULL;
677                 else
678                         FindLayer(o, formats[f], &dst_pos);
679
680                 EXPECT_EQ(TestPrepare(o, TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f],
681                                                           TDM_TRANSFORM_NORMAL, TDM_CAPTURE_TYPE_ONESHOT, -1, false), true);
682
683                 EXPECT_EQ(tdm_capture_set_done_handler(capture, _tc_tdm_capture_done_cb2, NULL), TDM_ERROR_NONE);
684
685                 for (int b = 0; b < 3; b++)
686                         EXPECT_EQ(tdm_capture_attach(capture, buffers[b]), TDM_ERROR_NONE);
687
688                 tdm_capture_destroy(capture);
689                 capture = NULL;
690
691                 TestDone();
692         }
693 }
694
695 TEST_P(TDMBackendCapture, CaptureDestroyBeforeDone)
696 {
697         TDM_UT_SKIP_FLAG(has_capture_cap);
698         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
699
700         for (int o = 0; o < output_count; o++) {
701                 const tdm_output_mode *mode = NULL;
702                 int f = 0;
703
704                 if (!tc_tdm_output_is_connected(outputs[o]))
705                         continue;
706
707                 EXPECT_EQ(tdm_output_get_mode(outputs[o], &mode), TDM_ERROR_NONE);
708
709                 if (tc_tdm_output_is_hwc_enable(outputs[o]))
710                         dst_layer = NULL;
711                 else
712                         FindLayer(o, formats[f], &dst_pos);
713
714                 EXPECT_EQ(TestPrepare(o, TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f],
715                                                           TDM_TRANSFORM_NORMAL, TDM_CAPTURE_TYPE_ONESHOT, -1, false), true);
716
717                 EXPECT_EQ(tdm_capture_set_done_handler(capture, _tc_tdm_capture_done_cb2, NULL), TDM_ERROR_NONE);
718
719                 for (int b = 0; b < 3; b++)
720                         EXPECT_EQ(tdm_capture_attach(capture, buffers[b]), TDM_ERROR_NONE);
721
722                 EXPECT_EQ(tdm_capture_commit(capture), TDM_ERROR_NONE);
723
724                 tdm_capture_destroy(capture);
725                 capture = NULL;
726
727                 TestDone();
728         }
729 }
730
731 TEST_P(TDMBackendCapture, CaptureOneshotLetterboxSize)
732 {
733         TDM_UT_SKIP_FLAG(has_capture_cap);
734         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
735         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_ONESHOT);
736
737         bool done;
738
739         for (int o = 0; o < output_count; o++) {
740                 const tdm_output_mode *mode = NULL;
741
742                 if (!tc_tdm_output_is_connected(outputs[o]))
743                         continue;
744
745                 EXPECT_EQ(tdm_output_get_mode(outputs[o], &mode), TDM_ERROR_NONE);
746
747                 for (int f = 0; f < format_count; f++) {
748                         int half_size = ((mode->hdisplay <= mode->vdisplay) ? mode->hdisplay : mode->vdisplay) / 2;
749
750                         dst_pos.x = (mode->hdisplay - half_size) / 2;
751                         dst_pos.y = (mode->vdisplay - half_size) / 2;
752                         dst_pos.w = half_size;
753                         dst_pos.h = half_size;
754
755                         TDM_UT_INFO("* testing for %c%c%c%c", FOURCC_STR(formats[f]));
756
757                         if (tc_tdm_output_is_hwc_enable(outputs[o]))
758                                 dst_layer = NULL;
759                         else {
760                                 FindLayer(o, formats[f], &dst_pos);
761
762                                 if (!dst_layer) {
763                                         TDM_UT_INFO("no proper layer for %c%c%c%c", FOURCC_STR(formats[f]));
764                                         continue;
765                                 }
766                         }
767
768                         EXPECT_EQ(TestPrepare(o, half_size, half_size, formats[f],
769                                                                   TDM_TRANSFORM_NORMAL, TDM_CAPTURE_TYPE_ONESHOT, -1, false), true);
770
771                         EXPECT_EQ(tdm_capture_set_done_handler(capture, _tc_tdm_capture_done_cb, &done), TDM_ERROR_NONE);
772
773 retry:
774                         for (int b = 0; b < 3; b++) {
775                                 done = false;
776                                 EXPECT_EQ(tdm_capture_attach(capture, buffers[b]), TDM_ERROR_NONE);
777                                 EXPECT_EQ(tdm_capture_commit(capture), TDM_ERROR_NONE);
778
779                                 while (!done)
780                                         EXPECT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
781
782 #if 0
783                                 char temp[256];
784                                 snprintf(temp, sizeof temp, "f%d_b%d", f, b);
785                                 DumpBuffer(b, temp);
786 #endif
787                                 if (tc_tdm_output_is_hwc_enable(outputs[o]))
788                                         TDM_UT_WRN("hwc_enable, not support showing buffer");
789                                 else
790                                         ShowBuffer(b, &dst_pos);
791                         }
792
793                         TDM_UT_ASK_YNR("* Successed to capture a output to a '%c%c%c%c' buffer as letterbox size and show? (output: %d, layer: %d)",
794                                                    FOURCC_STR(formats[f]), pipe, dst_layer_index);
795
796                         if (!tc_tdm_output_is_hwc_enable(outputs[o]))
797                                 HideLayer();
798
799                         TestDone();
800                 }
801         }
802 }
803
804 TEST_P(TDMBackendCapture, CaptureOneshotFullSize)
805 {
806         TDM_UT_SKIP_FLAG(has_capture_cap);
807         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
808         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_ONESHOT);
809
810         bool done;
811
812         for (int o = 0; o < output_count; o++) {
813                 const tdm_output_mode *mode = NULL;
814
815                 if (!tc_tdm_output_is_connected(outputs[o]))
816                         continue;
817
818                 EXPECT_EQ(tdm_output_get_mode(outputs[o], &mode), TDM_ERROR_NONE);
819
820                 for (int f = 0; f < format_count; f++) {
821                         int half_size = ((mode->hdisplay <= mode->vdisplay) ? mode->hdisplay : mode->vdisplay) / 2;
822
823                         dst_pos.x = (mode->hdisplay - half_size) / 2;
824                         dst_pos.y = (mode->vdisplay - half_size) / 2;
825                         dst_pos.w = half_size;
826                         dst_pos.h = half_size;
827
828                         TDM_UT_INFO("* testing for %c%c%c%c", FOURCC_STR(formats[f]));
829
830                         if (tc_tdm_output_is_hwc_enable(outputs[o]))
831                                 dst_layer = NULL;
832                         else {
833                                 FindLayer(o, formats[f], &dst_pos);
834
835                                 if (!dst_layer) {
836                                         TDM_UT_INFO("no proper layer for %c%c%c%c", FOURCC_STR(formats[f]));
837                                         continue;
838                                 }
839                         }
840
841                         EXPECT_EQ(TestPrepare(o, half_size, half_size, formats[f],
842                                                                   TDM_TRANSFORM_NORMAL, TDM_CAPTURE_TYPE_ONESHOT, -1, true), true);
843
844                         EXPECT_EQ(tdm_capture_set_done_handler(capture, _tc_tdm_capture_done_cb, &done), TDM_ERROR_NONE);
845
846 retry:
847                         for (int b = 0; b < 3; b++) {
848                                 done = false;
849                                 EXPECT_EQ(tdm_capture_attach(capture, buffers[b]), TDM_ERROR_NONE);
850                                 EXPECT_EQ(tdm_capture_commit(capture), TDM_ERROR_NONE);
851
852                                 while (!done)
853                                         EXPECT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
854
855 #if 0
856                                 char temp[256];
857                                 snprintf(temp, sizeof temp, "f%d_b%d", f, b);
858                                 DumpBuffer(b, temp);
859 #endif
860                                 if (tc_tdm_output_is_hwc_enable(outputs[o]))
861                                         TDM_UT_WRN("hwc_enable, not support showing buffer");
862                                 else
863                                         ShowBuffer(b, &dst_pos);
864                         }
865
866                         TDM_UT_ASK_YNR("* Successed to capture a output to a '%c%c%c%c' buffer as full size and show? (output: %d, layer: %d)",
867                                                    FOURCC_STR(formats[f]), pipe, dst_layer_index);
868
869                         if (!tc_tdm_output_is_hwc_enable(outputs[o]))
870                                 HideLayer();
871
872                         TestDone();
873                 }
874         }
875 }
876
877 TEST_P(TDMBackendCapture, CaptureOneshotAttachFewTimesInOneCommit)
878 {
879         TDM_UT_SKIP_FLAG(has_capture_cap);
880         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
881         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_ONESHOT);
882
883         int done;
884
885         for (int o = 0; o < output_count; o++) {
886                 const tdm_output_mode *mode = NULL;
887
888                 if (!tc_tdm_output_is_connected(outputs[o]))
889                         continue;
890
891                 EXPECT_EQ(tdm_output_get_mode(outputs[o], &mode), TDM_ERROR_NONE);
892
893                 for (int f = 0; f < format_count; f++) {
894                         int half_size = ((mode->hdisplay <= mode->vdisplay) ? mode->hdisplay : mode->vdisplay) / 2;
895
896                         dst_pos.x = (mode->hdisplay - half_size) / 2;
897                         dst_pos.y = (mode->vdisplay - half_size) / 2;
898                         dst_pos.w = half_size;
899                         dst_pos.h = half_size;
900
901                         TDM_UT_INFO("* testing for %c%c%c%c", FOURCC_STR(formats[f]));
902
903                         if (tc_tdm_output_is_hwc_enable(outputs[o]))
904                                 dst_layer = NULL;
905                         else {
906                                 FindLayer(o, formats[f], &dst_pos);
907
908                                 if (!dst_layer) {
909                                         TDM_UT_INFO("no proper layer for %c%c%c%c", FOURCC_STR(formats[f]));
910                                         continue;
911                                 }
912                         }
913
914                         EXPECT_EQ(TestPrepare(o, half_size, half_size, formats[f],
915                                                                   TDM_TRANSFORM_NORMAL, TDM_CAPTURE_TYPE_ONESHOT, -1, false), true);
916
917                         done = 0;
918                         EXPECT_EQ(tdm_capture_set_done_handler(capture, _tc_tdm_capture_done_cb2, &done), TDM_ERROR_NONE);
919
920 retry:
921                         for (int b = 0; b < 3; b++)
922                                 EXPECT_EQ(tdm_capture_attach(capture, buffers[b]), TDM_ERROR_NONE);
923
924                         EXPECT_EQ(tdm_capture_commit(capture), TDM_ERROR_NONE);
925
926                         while (done != 3)
927                                 EXPECT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
928
929                         for (int b = 0; b < 3; b++) {
930 #if 0
931                                 char temp[256];
932                                 snprintf(temp, sizeof temp, "f%d_b%d", f, b);
933                                 DumpBuffer(b, temp);
934 #endif
935                                 if (tc_tdm_output_is_hwc_enable(outputs[o]))
936                                         TDM_UT_WRN("hwc_enable, not support showing buffer");
937                                 else
938                                         ShowBuffer(b, &dst_pos);
939                         }
940
941                         TDM_UT_ASK_YNR("* Successed to capture a output to a '%c%c%c%c' buffer as letterbox size and show? (output: %d, layer: %d)",
942                                                    FOURCC_STR(formats[f]), pipe, dst_layer_index);
943
944                         if (!tc_tdm_output_is_hwc_enable(outputs[o]))
945                                 HideLayer();
946
947                         TestDone();
948                 }
949         }
950 }
951
952 static void
953 _tc_tdm_backend_capture_buffer_release_cb(tbm_surface_h buffer, void *user_data)
954 {
955         TDMBackendCapture *backend_capture = (TDMBackendCapture*)user_data;
956
957         tdm_buffer_remove_release_handler(buffer, _tc_tdm_backend_capture_buffer_release_cb, backend_capture);
958
959         EXPECT_EQ(tdm_capture_attach(backend_capture->capture, buffer), TDM_ERROR_NONE);
960         EXPECT_EQ(tdm_capture_commit(backend_capture->capture), TDM_ERROR_NONE);
961 }
962
963 static void
964 _tc_tdm_capture_stream_done_cb(tdm_capture *capture, tbm_surface_h buffer, void *user_data)
965 {
966         TDMBackendCapture *backend_capture = (TDMBackendCapture*)user_data;
967
968         for (int b = 0; b < 3; b++) {
969                 if (backend_capture->buffers[b] == buffer) {
970 #if 0
971                         char temp[256];
972                         snprintf(temp, sizeof temp, "f%d_b%d", f, b);
973                         DumpBuffer(b, temp);
974 #endif
975                         tdm_buffer_add_release_handler(buffer, _tc_tdm_backend_capture_buffer_release_cb, (void*)backend_capture);
976                         if (tc_tdm_output_is_hwc_enable(backend_capture->output)) {
977                                 TDM_UT_WRN("hwc_enable, not support showing buffer");
978                                 _tc_tdm_backend_capture_buffer_release_cb(buffer, user_data);
979                         }
980                         else
981                                 backend_capture->ShowBuffer(b, &backend_capture->dst_pos);
982                         break;
983                 }
984         }
985
986         if (--backend_capture->stream_count == 0) {
987                 backend_capture->stream_exit = 1;
988         }
989 }
990
991 TEST_P(TDMBackendCapture, CaptureStreamLetterboxSize)
992 {
993         TDM_UT_SKIP_FLAG(has_capture_cap);
994         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
995         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_STREAM);
996
997         for (int o = 0; o < output_count; o++) {
998                 const tdm_output_mode *mode = NULL;
999
1000                 if (!tc_tdm_output_is_connected(outputs[o]))
1001                         continue;
1002
1003                 EXPECT_EQ(tdm_output_get_mode(outputs[o], &mode), TDM_ERROR_NONE);
1004
1005                 for (int f = 0; f < format_count; f++) {
1006                         int half_size = ((mode->hdisplay <= mode->vdisplay) ? mode->hdisplay : mode->vdisplay) / 2;
1007
1008                         dst_pos.x = (mode->hdisplay - half_size) / 2;
1009                         dst_pos.y = (mode->vdisplay - half_size) / 2;
1010                         dst_pos.w = half_size;
1011                         dst_pos.h = half_size;
1012
1013                         TDM_UT_INFO("* testing for %c%c%c%c", FOURCC_STR(formats[f]));
1014
1015                         if (tc_tdm_output_is_hwc_enable(outputs[o]))
1016                                 dst_layer = NULL;
1017                         else {
1018                                 FindLayer(o, formats[f], &dst_pos);
1019
1020                                 if (!dst_layer) {
1021                                         TDM_UT_INFO("no proper layer for %c%c%c%c", FOURCC_STR(formats[f]));
1022                                         continue;
1023                                 }
1024                         }
1025
1026                         EXPECT_EQ(TestPrepare(o, half_size, half_size, formats[f],
1027                                                                   TDM_TRANSFORM_NORMAL, TDM_CAPTURE_TYPE_STREAM, -1, false), true);
1028
1029                         EXPECT_EQ(tdm_capture_set_done_handler(capture, _tc_tdm_capture_stream_done_cb, (void*)this), TDM_ERROR_NONE);
1030
1031                         for (int b = 0; b < 3; b++)
1032                                 EXPECT_EQ(tdm_capture_attach(capture, buffers[b]), TDM_ERROR_NONE);
1033
1034 retry:
1035
1036                         stream_exit = false;
1037                         stream_count = 30;
1038
1039                         EXPECT_EQ(tdm_capture_commit(capture), TDM_ERROR_NONE);
1040
1041                         while (!stream_exit)
1042                                 EXPECT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
1043
1044                         TDM_UT_ASK_YNR("* Successed to capture a output to a '%c%c%c%c' buffer as letterbox size and show? (output: %d, layer: %d)",
1045                                                    FOURCC_STR(formats[f]), pipe, dst_layer_index);
1046
1047                         if (!tc_tdm_output_is_hwc_enable(outputs[o]))
1048                                 HideLayer();
1049
1050                         TestDone();
1051                 }
1052         }
1053 }
1054
1055 TEST_P(TDMBackendCapture, CaptureStreamFullSize)
1056 {
1057         TDM_UT_SKIP_FLAG(has_capture_cap);
1058         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
1059         TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_STREAM);
1060
1061         for (int o = 0; o < output_count; o++) {
1062                 const tdm_output_mode *mode = NULL;
1063
1064                 if (!tc_tdm_output_is_connected(outputs[o]))
1065                         continue;
1066
1067                 EXPECT_EQ(tdm_output_get_mode(outputs[o], &mode), TDM_ERROR_NONE);
1068
1069                 for (int f = 0; f < format_count; f++) {
1070                         int half_size = ((mode->hdisplay <= mode->vdisplay) ? mode->hdisplay : mode->vdisplay) / 2;
1071
1072                         dst_pos.x = (mode->hdisplay - half_size) / 2;
1073                         dst_pos.y = (mode->vdisplay - half_size) / 2;
1074                         dst_pos.w = half_size;
1075                         dst_pos.h = half_size;
1076
1077                         TDM_UT_INFO("* testing for %c%c%c%c", FOURCC_STR(formats[f]));
1078
1079                         if (tc_tdm_output_is_hwc_enable(outputs[o]))
1080                                 dst_layer = NULL;
1081                         else {
1082                                 FindLayer(o, formats[f], &dst_pos);
1083
1084                                 if (!dst_layer) {
1085                                         TDM_UT_INFO("no proper layer for %c%c%c%c", FOURCC_STR(formats[f]));
1086                                         continue;
1087                                 }
1088                         }
1089
1090                         EXPECT_EQ(TestPrepare(o, half_size, half_size, formats[f],
1091                                                                   TDM_TRANSFORM_NORMAL, TDM_CAPTURE_TYPE_STREAM, -1, true), true);
1092
1093                         EXPECT_EQ(tdm_capture_set_done_handler(capture, _tc_tdm_capture_stream_done_cb, (void*)this), TDM_ERROR_NONE);
1094
1095                         for (int b = 0; b < 3; b++)
1096                                 EXPECT_EQ(tdm_capture_attach(capture, buffers[b]), TDM_ERROR_NONE);
1097
1098 retry:
1099
1100                         stream_exit = false;
1101                         stream_count = 30;
1102
1103                         EXPECT_EQ(tdm_capture_commit(capture), TDM_ERROR_NONE);
1104
1105                         while (!stream_exit)
1106                                 EXPECT_EQ(tc_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
1107
1108                         TDM_UT_ASK_YNR("* Successed to capture a output to a '%c%c%c%c' buffer as full size and show? (output: %d, layer: %d)",
1109                                                    FOURCC_STR(formats[f]), pipe, dst_layer_index);
1110
1111                         if (!tc_tdm_output_is_hwc_enable(outputs[o]))
1112                                 HideLayer();
1113
1114                         TestDone();
1115                 }
1116         }
1117 }
1118
1119 #ifdef TDM_UT_TEST_WITH_PARAMS
1120 INSTANTIATE_TEST_CASE_P(TDMBackendCaptureParams,
1121                                                 TDMBackendCapture,
1122                                                 Combine(Bool(), Bool(), Values(TDM_DEFAULT_MODULE)));
1123 #else
1124 INSTANTIATE_TEST_CASE_P(TDMBackendCaptureParams,
1125                                                 TDMBackendCapture,
1126                                                 Values(TDM_DEFAULT_MODULE));
1127 #endif
1128
1129 /* LCOV_EXCL_END */