1 /**************************************************************************
3 * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
5 * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
6 * Contact: Andrii Sokolenko <a.sokolenko@samsung.com>
7 * Contact: Roman Marchenko <r.marchenko@samsung.com>
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:
17 * The above copyright notice and this permission notice (including the
18 * next paragraph) shall be included in all copies or substantial portions
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.
29 **************************************************************************/
33 class TDMBackendCapture : public TDMBackendDisplay
39 tdm_capture_capability capabilities;
40 const tbm_format *formats;
48 tbm_surface_h buffers[3];
50 tdm_info_capture info;
54 const tdm_output_mode *mode;
68 bool FindLayer(int output_idx, tbm_format fmt, tdm_pos *punch);
69 bool TestPrepareDefault(void);
70 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 ShowBuffer(int b, tdm_pos *pos);
74 void DumpBuffer(int b, char *test);
75 void DestroyBuffers(void);
78 TDMBackendCapture::TDMBackendCapture()
80 has_capture_cap = false;
82 capabilities = (tdm_capture_capability)0;
85 min_w = min_h = max_w = max_h = preferred_align = -1;
87 for (int b = 0; b < 3; b++)
89 memset(&info, 0, sizeof info);
98 memset(&dst_pos, 0, sizeof dst_pos);
104 void TDMBackendCapture::SetUp(void)
106 tdm_display_capability dpy_capabilities;
108 TDMBackendDisplay::SetUp();
110 ASSERT_EQ(tdm_display_get_capabilities(dpy, &dpy_capabilities), TDM_ERROR_NONE);
111 has_capture_cap = dpy_capabilities & TDM_DISPLAY_CAPABILITY_CAPTURE;
113 if (!has_capture_cap)
116 ASSERT_EQ(tdm_display_get_capture_capabilities(dpy, &capabilities), TDM_ERROR_NONE);
117 ASSERT_GT(capabilities, 0);
118 ASSERT_EQ(tdm_display_get_capture_available_formats(dpy, &formats, &format_count), TDM_ERROR_NONE);
119 ASSERT_NE(formats, NULL);
120 ASSERT_GT(format_count, 0);
121 ASSERT_EQ(tdm_display_get_capture_available_size(dpy, &min_w, &min_h, &max_w, &max_h, &preferred_align), TDM_ERROR_NONE);
122 ASSERT_TRUE(min_w == -1 || min_w > 0);
123 ASSERT_TRUE(min_h == -1 || min_h > 0);
124 ASSERT_TRUE(max_w == -1 || max_w > 0);
125 ASSERT_TRUE(max_h == -1 || max_h > 0);
126 ASSERT_TRUE(preferred_align == -1 || preferred_align > 0);
128 for (int o = 0; o < output_count; o++) {
129 if (!ut_tdm_output_is_connected(outputs[o]))
132 ASSERT_EQ(ut_tdm_output_prepare(dpy, outputs[o], true), true);
136 void TDMBackendCapture::TearDown(void)
139 tdm_capture_destroy(capture);
141 for (int o = 0; o < output_count; o++) {
142 if (!ut_tdm_output_is_connected(outputs[o]))
145 ASSERT_EQ(ut_tdm_output_unset(dpy, outputs[o]), true);
150 TDMBackendDisplay::TearDown();
153 bool TDMBackendCapture::FindLayer(int output_idx, tbm_format fmt, tdm_pos *punch)
157 int primary_zpos, zpos;
158 tdm_layer *primary = ut_tdm_output_get_primary_layer(outputs[output_idx]);
159 TDM_UT_RETURN_FALSE_IF_FAIL(primary != NULL);
160 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_output_get_layer_count(outputs[output_idx], &count) == TDM_ERROR_NONE);
161 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_zpos(primary, &primary_zpos) == TDM_ERROR_NONE);
165 for (int l = 0; l < count; l++) {
167 const tbm_format *dst_formats;
168 int dst_format_count;
170 tdm_layer *temp = tdm_output_get_layer(outputs[output_idx], l, &ret);
171 TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
172 TDM_UT_RETURN_FALSE_IF_FAIL(temp != NULL);
173 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_is_usable(temp, &usable) == TDM_ERROR_NONE);
174 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_zpos(temp, &zpos) == TDM_ERROR_NONE);
175 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_available_formats(temp, &dst_formats, &dst_format_count) == TDM_ERROR_NONE);
176 TDM_UT_RETURN_FALSE_IF_FAIL(dst_formats != NULL);
177 TDM_UT_RETURN_FALSE_IF_FAIL(dst_format_count > 0);
181 for (int f = 0; f < dst_format_count; f++) {
182 if (dst_formats[f] == fmt) {
191 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_index(dst_layer, &dst_layer_index) == TDM_ERROR_NONE);
196 if (dst_layer && (dst_zpos < primary_zpos)) {
197 tbm_surface_h displaying_buffer = tdm_layer_get_displaying_buffer(primary, &ret);
198 TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
199 TDM_UT_RETURN_FALSE_IF_FAIL(displaying_buffer != NULL);
200 tdm_helper_clear_buffer_pos(displaying_buffer, punch);
206 bool TDMBackendCapture::TestPrepareDefault(void)
210 for (int o = 0; o < output_count; o++) {
211 if (!ut_tdm_output_is_connected(outputs[o]))
214 capture = tdm_output_create_capture(outputs[o], &ret);
215 TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
216 TDM_UT_RETURN_FALSE_IF_FAIL(capture != NULL);
218 TDM_UT_RETURN_FALSE_IF_FAIL(ut_tdm_buffer_create(TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[0], 0, false, 3, buffers) == true);
219 TDM_UT_RETURN_FALSE_IF_FAIL(ut_tdm_capture_fill_info(outputs[o], buffers[0], TDM_TRANSFORM_NORMAL, TDM_CAPTURE_TYPE_ONESHOT, -1, false, &info) == true);
220 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_capture_set_info(capture, &info) == TDM_ERROR_NONE);
228 return (capture) ? true : false;
231 bool TDMBackendCapture::TestPrepare(int output_idx, int w, int h, tbm_format fmt, tdm_transform t, tdm_capture_type c, int frequency, bool stretch)
236 TDM_UT_RETURN_FALSE_IF_FAIL(outputs != NULL);
237 TDM_UT_RETURN_FALSE_IF_FAIL(output_count > 0);
238 TDM_UT_RETURN_FALSE_IF_FAIL(output_count >= output_idx);
240 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_display_get_capture_capabilities(dpy, &capabilities) == TDM_ERROR_NONE);
241 TDM_UT_RETURN_FALSE_IF_FAIL(capabilities > 0);
243 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);
244 TDM_UT_RETURN_FALSE_IF_FAIL(min_w == -1 || min_w > 0);
245 TDM_UT_RETURN_FALSE_IF_FAIL(min_h == -1 || min_h > 0);
246 TDM_UT_RETURN_FALSE_IF_FAIL(max_w == -1 || max_w > 0);
247 TDM_UT_RETURN_FALSE_IF_FAIL(max_h == -1 || max_h > 0);
248 TDM_UT_RETURN_FALSE_IF_FAIL(preferred_align == -1 || preferred_align > 0);
250 capture = tdm_output_create_capture(outputs[output_idx], &ret);
251 TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
252 TDM_UT_RETURN_FALSE_IF_FAIL(capture != NULL);
255 tdm_layer_capability capabilities;
256 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_layer_get_capabilities(dst_layer, &capabilities) == TDM_ERROR_NONE);
257 if (capabilities & TDM_LAYER_CAPABILITY_SCANOUT)
258 flags |= TBM_BO_SCANOUT;
261 TDM_UT_RETURN_FALSE_IF_FAIL(ut_tdm_buffer_create(w, h, fmt, flags, false, 3, buffers) == true);
262 TDM_UT_RETURN_FALSE_IF_FAIL(ut_tdm_capture_fill_info(outputs[output_idx], buffers[0], t, c, frequency, stretch, &info) == true);
263 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_capture_set_info(capture, &info) == TDM_ERROR_NONE);
265 output = outputs[output_idx];
270 void TDMBackendCapture::TestDone(void)
273 tdm_capture_destroy(capture);
280 void TDMBackendCapture::DumpBuffer(int b, char *test)
284 snprintf(filename, sizeof filename, "%s_%s_%d", typeid(*this).name(), test, b);
286 snprintf(filename, sizeof filename, "%s_%d", typeid(*this).name(), b);
287 tdm_helper_dump_buffer_str(buffers[b], NULL, filename);
290 void TDMBackendCapture::ShowBuffer(int b, tdm_pos *pos)
292 ASSERT_NE(output, NULL);
293 ASSERT_NE(dst_layer, NULL);
295 ASSERT_EQ(ut_tdm_layer_set_buffer_with_pos(dst_layer, buffers[b], pos), true);
296 ASSERT_EQ(tdm_output_commit(output, 0, NULL, NULL), TDM_ERROR_NONE);
299 void TDMBackendCapture::HideLayer(void)
301 ASSERT_NE(output, NULL);
302 ASSERT_NE(dst_layer, NULL);
304 tdm_layer_unset_buffer(dst_layer);
305 tdm_output_commit(output, 0, NULL, NULL);
310 void TDMBackendCapture::DestroyBuffers(void)
312 for (int b = 0; b < 3; b++) {
313 tbm_surface_destroy(buffers[b]);
319 _ut_tdm_capture_fit_rect(int src_w, int src_h, int dst_w, int dst_h, tdm_pos *fit)
323 if (src_w <= 0 || src_h <= 0 || dst_w <= 0 || dst_h <= 0 || !fit)
326 rw = (float)src_w / dst_w;
327 rh = (float)src_h / dst_h;
333 fit->y = (dst_h - fit->h) / 2;
334 } else if (rw < rh) {
337 fit->x = (dst_w - fit->w) / 2;
351 ut_tdm_capture_fill_info(tdm_output *output, tbm_surface_h buffer, tdm_transform transform,
352 tdm_capture_type type, int frequency, bool stretch, tdm_info_capture *info)
355 const tdm_output_mode *mode = NULL;
357 TDM_UT_RETURN_FALSE_IF_FAIL(tdm_output_get_mode(output, &mode) == TDM_ERROR_NONE);
358 TDM_UT_RETURN_FALSE_IF_FAIL(mode != NULL);
360 memset(info, 0, sizeof *info);
362 bw = bh = TDM_UT_INVALID_VALUE;
363 tdm_helper_get_buffer_full_size(buffer, &bw, &bh);
365 TDM_UT_RETURN_FALSE_IF_FAIL(bw != TDM_UT_INVALID_VALUE);
366 TDM_UT_RETURN_FALSE_IF_FAIL(bw >= tbm_surface_get_width(buffer));
367 TDM_UT_RETURN_FALSE_IF_FAIL(bh != TDM_UT_INVALID_VALUE);
368 TDM_UT_RETURN_FALSE_IF_FAIL(bh >= tbm_surface_get_height(buffer));
369 info->dst_config.size.h = bw;
370 info->dst_config.size.v = bh;
373 info->dst_config.pos.x = 0;
374 info->dst_config.pos.y = 0;
375 info->dst_config.pos.w = tbm_surface_get_width(buffer);
376 info->dst_config.pos.h = tbm_surface_get_height(buffer);
378 _ut_tdm_capture_fit_rect(mode->hdisplay, mode->vdisplay,
379 tbm_surface_get_width(buffer), tbm_surface_get_height(buffer),
380 &info->dst_config.pos);
383 info->dst_config.format = tbm_surface_get_format(buffer);
385 info->transform = transform;
390 frequency = mode->vrefresh;
392 info->frequency = frequency;
394 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)",
395 info->dst_config.size.h, info->dst_config.size.v,
396 info->dst_config.pos.x, info->dst_config.pos.y, info->dst_config.pos.w, info->dst_config.pos.h,
397 FOURCC_STR(info->dst_config.format),
398 tdm_transform_str(info->transform), tdm_capture_type_str(info->type), info->frequency);
403 TEST_P(TDMBackendCapture, CaptureDispalyGetAvaiableFormats)
405 const tbm_format *formats = (const tbm_format *)TDM_UT_INVALID_VALUE;
406 int count = TDM_UT_INVALID_VALUE;
407 if (has_capture_cap) {
408 ASSERT_EQ(tdm_display_get_capture_available_formats(dpy, &formats, &count), TDM_ERROR_NONE);
409 ASSERT_TRUE(formats != NULL && formats != (const tbm_format *)TDM_UT_INVALID_VALUE);
410 ASSERT_TRUE(count > 0 && count != TDM_UT_INVALID_VALUE);
412 ASSERT_EQ(tdm_display_get_capture_available_formats(dpy, &formats, &count), TDM_ERROR_NO_CAPABILITY);
413 ASSERT_EQ(formats, (const tbm_format *)TDM_UT_INVALID_VALUE);
414 ASSERT_EQ(count, TDM_UT_INVALID_VALUE);
418 TEST_P(TDMBackendCapture, CaptureDispalyGetAvaiableFormatsNullObject)
420 const tbm_format *formats = (const tbm_format *)TDM_UT_INVALID_VALUE;
421 int count = TDM_UT_INVALID_VALUE;
422 ASSERT_EQ(tdm_display_get_capture_available_formats(NULL, &formats, &count), TDM_ERROR_INVALID_PARAMETER);
423 ASSERT_EQ(formats, (const tbm_format *)TDM_UT_INVALID_VALUE);
424 ASSERT_EQ(count, TDM_UT_INVALID_VALUE);
427 TEST_P(TDMBackendCapture, CaptureDispalyGetAvaiableFormatsNullOther)
429 ASSERT_EQ(tdm_display_get_capture_available_formats(dpy, NULL, NULL), TDM_ERROR_INVALID_PARAMETER);
432 TEST_P(TDMBackendCapture, CaptureDispalyGetAvaiableSize)
434 int min_w = TDM_UT_INVALID_VALUE;
435 int min_h = TDM_UT_INVALID_VALUE;
436 int max_w = TDM_UT_INVALID_VALUE;
437 int max_h = TDM_UT_INVALID_VALUE;
438 int preferred_align = TDM_UT_INVALID_VALUE;
439 if (has_capture_cap) {
440 ASSERT_EQ(tdm_display_get_capture_available_size(dpy, &min_w, &min_h, &max_w, &max_h, &preferred_align), TDM_ERROR_NONE);
441 ASSERT_NE(min_w, TDM_UT_INVALID_VALUE);
442 ASSERT_NE(min_h, TDM_UT_INVALID_VALUE);
443 ASSERT_NE(max_w, TDM_UT_INVALID_VALUE);
444 ASSERT_NE(max_h, TDM_UT_INVALID_VALUE);
445 ASSERT_NE(preferred_align, TDM_UT_INVALID_VALUE);
447 ASSERT_EQ(tdm_display_get_capture_available_size(dpy, &min_w, &min_h, &max_w, &max_h, &preferred_align), TDM_ERROR_NO_CAPABILITY);
448 ASSERT_EQ(min_w, TDM_UT_INVALID_VALUE);
449 ASSERT_EQ(min_h, TDM_UT_INVALID_VALUE);
450 ASSERT_EQ(max_w, TDM_UT_INVALID_VALUE);
451 ASSERT_EQ(max_h, TDM_UT_INVALID_VALUE);
452 ASSERT_EQ(preferred_align, TDM_UT_INVALID_VALUE);
456 TEST_P(TDMBackendCapture, CaptureDispalyGetAvaiableSizeNullObject)
458 int min_w = TDM_UT_INVALID_VALUE;
459 int min_h = TDM_UT_INVALID_VALUE;
460 int max_w = TDM_UT_INVALID_VALUE;
461 int max_h = TDM_UT_INVALID_VALUE;
462 int preferred_align = TDM_UT_INVALID_VALUE;
463 ASSERT_EQ(tdm_display_get_capture_available_size(NULL, &min_w, &min_h, &max_w, &max_h, &preferred_align), TDM_ERROR_INVALID_PARAMETER);
464 ASSERT_EQ(min_w, TDM_UT_INVALID_VALUE);
465 ASSERT_EQ(min_h, TDM_UT_INVALID_VALUE);
466 ASSERT_EQ(max_w, TDM_UT_INVALID_VALUE);
467 ASSERT_EQ(max_h, TDM_UT_INVALID_VALUE);
468 ASSERT_EQ(preferred_align, TDM_UT_INVALID_VALUE);
471 TEST_P(TDMBackendCapture, CaptureDispalyGetAvaiableSizeNullOther)
474 ASSERT_EQ(tdm_display_get_capture_available_size(dpy, NULL, NULL, NULL, NULL, NULL), TDM_ERROR_NONE);
476 ASSERT_EQ(tdm_display_get_capture_available_size(dpy, NULL, NULL, NULL, NULL, NULL), TDM_ERROR_NO_CAPABILITY);
479 TEST_P(TDMBackendCapture, CaptureDestroy)
481 TDM_UT_SKIP_FLAG(has_capture_cap);
482 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
484 ASSERT_EQ(TestPrepareDefault(), true);
489 TEST_P(TDMBackendCapture, CaptureDestroyNullObject)
491 TDM_UT_SKIP_FLAG(has_capture_cap);
492 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
494 tdm_capture_destroy(NULL);
497 TEST_P(TDMBackendCapture, CaptureSetInfo)
499 /* tested in CaptureNoScaleNoTransformNoCSC */
502 TEST_P(TDMBackendCapture, CaptureSetInfoNullObject)
504 TDM_UT_SKIP_FLAG(has_capture_cap);
505 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
507 tdm_info_capture info;
508 memset(&info, 0, sizeof info);
509 ASSERT_EQ(tdm_capture_set_info(NULL, &info), TDM_ERROR_INVALID_PARAMETER);
512 TEST_P(TDMBackendCapture, CaptureSetInfoNullOther)
514 TDM_UT_SKIP_FLAG(has_capture_cap);
515 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
517 ASSERT_EQ(TestPrepareDefault(), true);
519 ASSERT_EQ(tdm_capture_set_info(capture, NULL), TDM_ERROR_INVALID_PARAMETER);
525 _ut_tdm_capture_done_cb(tdm_capture *capture, tbm_surface_h buffer, void *user_data)
527 bool *done = (bool*)user_data;
532 TEST_P(TDMBackendCapture, CaptureSetDoneHandler)
534 TDM_UT_SKIP_FLAG(has_capture_cap);
535 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
537 ASSERT_EQ(TestPrepareDefault(), true);
539 ASSERT_EQ(tdm_capture_set_done_handler(capture, _ut_tdm_capture_done_cb, NULL), TDM_ERROR_NONE);
544 TEST_P(TDMBackendCapture, CaptureSetDoneHandlerNullObject)
546 TDM_UT_SKIP_FLAG(has_capture_cap);
547 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
549 ASSERT_EQ(tdm_capture_set_done_handler(NULL, _ut_tdm_capture_done_cb, NULL), TDM_ERROR_INVALID_PARAMETER);
552 TEST_P(TDMBackendCapture, CaptureSetDoneHandlerNullOther)
554 TDM_UT_SKIP_FLAG(has_capture_cap);
555 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
557 ASSERT_EQ(TestPrepareDefault(), true);
559 ASSERT_EQ(tdm_capture_set_done_handler(capture, NULL, NULL), TDM_ERROR_INVALID_PARAMETER);
564 TEST_P(TDMBackendCapture, CaptureAttach)
566 TDM_UT_SKIP_FLAG(has_capture_cap);
567 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
569 for (int o = 0; o < output_count; o++) {
571 if (!ut_tdm_output_is_connected(outputs[o]))
574 for (int f = 0; f < format_count; f++) {
575 FindLayer(o, formats[f], &dst_pos);
577 ASSERT_EQ(TestPrepare(o, TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f],
578 TDM_TRANSFORM_NORMAL, TDM_CAPTURE_TYPE_ONESHOT, -1, false), true);
580 for (int b = 0; b < 3; b++)
581 ASSERT_EQ(tdm_capture_attach(capture, buffers[b]), TDM_ERROR_NONE);
588 TEST_P(TDMBackendCapture, CaptureAttachNullObject)
590 TDM_UT_SKIP_FLAG(has_capture_cap);
591 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
593 tbm_surface_h buffer = (tbm_surface_h)TDM_UT_BUFFER_SIZE;
595 ASSERT_EQ(tdm_capture_attach(NULL, buffer), TDM_ERROR_INVALID_PARAMETER);
598 TEST_P(TDMBackendCapture, CaptureAttachNullOther)
600 TDM_UT_SKIP_FLAG(has_capture_cap);
601 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
603 ASSERT_EQ(TestPrepareDefault(), true);
605 ASSERT_EQ(tdm_capture_attach(capture, NULL), TDM_ERROR_INVALID_PARAMETER);
610 TEST_P(TDMBackendCapture, CaptureCommit)
612 TDM_UT_SKIP_FLAG(has_capture_cap);
613 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
615 ASSERT_EQ(TestPrepareDefault(), true);
617 ASSERT_EQ(tdm_capture_commit(capture), TDM_ERROR_NONE);
622 TEST_P(TDMBackendCapture, CaptureCommitNullOBject)
624 TDM_UT_SKIP_FLAG(has_capture_cap);
625 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
627 ASSERT_EQ(tdm_capture_commit(NULL), TDM_ERROR_INVALID_PARAMETER);
630 TEST_P(TDMBackendCapture, CaptureCommitDpmsOff)
632 TDM_UT_SKIP_FLAG(has_capture_cap);
633 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
635 ASSERT_EQ(TestPrepareDefault(), true);
637 ASSERT_EQ(ut_tdm_output_unset(dpy, output), true);
639 ASSERT_EQ(tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF), TDM_ERROR_NONE);
641 ASSERT_EQ(tdm_capture_commit(capture), TDM_ERROR_BAD_REQUEST);
647 _ut_tdm_capture_done_cb2(tdm_capture *capture, tbm_surface_h buffer, void *user_data)
649 int *done = (int*)user_data;
654 TEST_P(TDMBackendCapture, CaptureDestroyWithoutCommit)
656 TDM_UT_SKIP_FLAG(has_capture_cap);
657 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
659 for (int o = 0; o < output_count; o++) {
660 const tdm_output_mode *mode = NULL;
663 if (!ut_tdm_output_is_connected(outputs[o]))
666 ASSERT_EQ(tdm_output_get_mode(outputs[o], &mode), TDM_ERROR_NONE);
668 FindLayer(o, formats[f], &dst_pos);
670 ASSERT_EQ(TestPrepare(o, TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f],
671 TDM_TRANSFORM_NORMAL, TDM_CAPTURE_TYPE_ONESHOT, -1, false), true);
673 ASSERT_EQ(tdm_capture_set_done_handler(capture, _ut_tdm_capture_done_cb2, NULL), TDM_ERROR_NONE);
675 for (int b = 0; b < 3; b++)
676 ASSERT_EQ(tdm_capture_attach(capture, buffers[b]), TDM_ERROR_NONE);
678 tdm_capture_destroy(capture);
685 TEST_P(TDMBackendCapture, CaptureDestroyBeforeDone)
687 TDM_UT_SKIP_FLAG(has_capture_cap);
688 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
690 for (int o = 0; o < output_count; o++) {
691 const tdm_output_mode *mode = NULL;
694 if (!ut_tdm_output_is_connected(outputs[o]))
697 ASSERT_EQ(tdm_output_get_mode(outputs[o], &mode), TDM_ERROR_NONE);
699 FindLayer(o, formats[f], &dst_pos);
701 ASSERT_EQ(TestPrepare(o, TDM_UT_BUFFER_SIZE, TDM_UT_BUFFER_SIZE, formats[f],
702 TDM_TRANSFORM_NORMAL, TDM_CAPTURE_TYPE_ONESHOT, -1, false), true);
704 ASSERT_EQ(tdm_capture_set_done_handler(capture, _ut_tdm_capture_done_cb2, NULL), TDM_ERROR_NONE);
706 for (int b = 0; b < 3; b++)
707 ASSERT_EQ(tdm_capture_attach(capture, buffers[b]), TDM_ERROR_NONE);
709 ASSERT_EQ(tdm_capture_commit(capture), TDM_ERROR_NONE);
711 tdm_capture_destroy(capture);
718 TEST_P(TDMBackendCapture, CaptureOneshotLetterboxSize)
720 TDM_UT_SKIP_FLAG(has_capture_cap);
721 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
722 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_ONESHOT);
726 for (int o = 0; o < output_count; o++) {
727 const tdm_output_mode *mode = NULL;
729 if (!ut_tdm_output_is_connected(outputs[o]))
732 ASSERT_EQ(tdm_output_get_mode(outputs[o], &mode), TDM_ERROR_NONE);
734 for (int f = 0; f < format_count; f++) {
735 int half_size = ((mode->hdisplay <= mode->vdisplay) ? mode->hdisplay : mode->vdisplay) / 2;
737 dst_pos.x = (mode->hdisplay - half_size) / 2;
738 dst_pos.y = (mode->vdisplay - half_size) / 2;
739 dst_pos.w = half_size;
740 dst_pos.h = half_size;
742 TDM_UT_INFO("* testing for %c%c%c%c", FOURCC_STR(formats[f]));
744 FindLayer(o, formats[f], &dst_pos);
747 TDM_UT_INFO("no proper layer for %c%c%c%c", FOURCC_STR(formats[f]));
751 ASSERT_EQ(TestPrepare(o, half_size, half_size, formats[f],
752 TDM_TRANSFORM_NORMAL, TDM_CAPTURE_TYPE_ONESHOT, -1, false), true);
754 ASSERT_EQ(tdm_capture_set_done_handler(capture, _ut_tdm_capture_done_cb, &done), TDM_ERROR_NONE);
757 for (int b = 0; b < 3; b++) {
759 ASSERT_EQ(tdm_capture_attach(capture, buffers[b]), TDM_ERROR_NONE);
760 ASSERT_EQ(tdm_capture_commit(capture), TDM_ERROR_NONE);
763 ASSERT_EQ(ut_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
767 snprintf(temp, sizeof temp, "f%d_b%d", f, b);
770 ShowBuffer(b, &dst_pos);
773 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)",
774 FOURCC_STR(formats[f]), pipe, dst_layer_index);
784 TEST_P(TDMBackendCapture, CaptureOneshotFullSize)
786 TDM_UT_SKIP_FLAG(has_capture_cap);
787 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
788 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_ONESHOT);
792 for (int o = 0; o < output_count; o++) {
793 const tdm_output_mode *mode = NULL;
795 if (!ut_tdm_output_is_connected(outputs[o]))
798 ASSERT_EQ(tdm_output_get_mode(outputs[o], &mode), TDM_ERROR_NONE);
800 for (int f = 0; f < format_count; f++) {
801 int half_size = ((mode->hdisplay <= mode->vdisplay) ? mode->hdisplay : mode->vdisplay) / 2;
803 dst_pos.x = (mode->hdisplay - half_size) / 2;
804 dst_pos.y = (mode->vdisplay - half_size) / 2;
805 dst_pos.w = half_size;
806 dst_pos.h = half_size;
808 TDM_UT_INFO("* testing for %c%c%c%c", FOURCC_STR(formats[f]));
810 FindLayer(o, formats[f], &dst_pos);
813 TDM_UT_INFO("no proper layer for %c%c%c%c", FOURCC_STR(formats[f]));
817 ASSERT_EQ(TestPrepare(o, half_size, half_size, formats[f],
818 TDM_TRANSFORM_NORMAL, TDM_CAPTURE_TYPE_ONESHOT, -1, true), true);
820 ASSERT_EQ(tdm_capture_set_done_handler(capture, _ut_tdm_capture_done_cb, &done), TDM_ERROR_NONE);
823 for (int b = 0; b < 3; b++) {
825 ASSERT_EQ(tdm_capture_attach(capture, buffers[b]), TDM_ERROR_NONE);
826 ASSERT_EQ(tdm_capture_commit(capture), TDM_ERROR_NONE);
829 ASSERT_EQ(ut_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
833 snprintf(temp, sizeof temp, "f%d_b%d", f, b);
836 ShowBuffer(b, &dst_pos);
839 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)",
840 FOURCC_STR(formats[f]), pipe, dst_layer_index);
850 TEST_P(TDMBackendCapture, CaptureOneshotAttachFewTimesInOneCommit)
852 TDM_UT_SKIP_FLAG(has_capture_cap);
853 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
854 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_ONESHOT);
858 for (int o = 0; o < output_count; o++) {
859 const tdm_output_mode *mode = NULL;
861 if (!ut_tdm_output_is_connected(outputs[o]))
864 ASSERT_EQ(tdm_output_get_mode(outputs[o], &mode), TDM_ERROR_NONE);
866 for (int f = 0; f < format_count; f++) {
867 int half_size = ((mode->hdisplay <= mode->vdisplay) ? mode->hdisplay : mode->vdisplay) / 2;
869 dst_pos.x = (mode->hdisplay - half_size) / 2;
870 dst_pos.y = (mode->vdisplay - half_size) / 2;
871 dst_pos.w = half_size;
872 dst_pos.h = half_size;
874 TDM_UT_INFO("* testing for %c%c%c%c", FOURCC_STR(formats[f]));
876 FindLayer(o, formats[f], &dst_pos);
879 TDM_UT_INFO("no proper layer for %c%c%c%c", FOURCC_STR(formats[f]));
883 ASSERT_EQ(TestPrepare(o, half_size, half_size, formats[f],
884 TDM_TRANSFORM_NORMAL, TDM_CAPTURE_TYPE_ONESHOT, -1, false), true);
887 ASSERT_EQ(tdm_capture_set_done_handler(capture, _ut_tdm_capture_done_cb2, &done), TDM_ERROR_NONE);
890 for (int b = 0; b < 3; b++)
891 ASSERT_EQ(tdm_capture_attach(capture, buffers[b]), TDM_ERROR_NONE);
893 ASSERT_EQ(tdm_capture_commit(capture), TDM_ERROR_NONE);
896 ASSERT_EQ(ut_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
898 for (int b = 0; b < 3; b++) {
901 snprintf(temp, sizeof temp, "f%d_b%d", f, b);
904 ShowBuffer(b, &dst_pos);
907 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)",
908 FOURCC_STR(formats[f]), pipe, dst_layer_index);
919 _ut_tdm_backend_capture_buffer_release_cb(tbm_surface_h buffer, void *user_data)
921 TDMBackendCapture *backend_capture = (TDMBackendCapture*)user_data;
923 tdm_buffer_remove_release_handler(buffer, _ut_tdm_backend_capture_buffer_release_cb, backend_capture);
925 ASSERT_EQ(tdm_capture_attach(backend_capture->capture, buffer), TDM_ERROR_NONE);
926 ASSERT_EQ(tdm_capture_commit(backend_capture->capture), TDM_ERROR_NONE);
930 _ut_tdm_capture_stream_done_cb(tdm_capture *capture, tbm_surface_h buffer, void *user_data)
932 TDMBackendCapture *backend_capture = (TDMBackendCapture*)user_data;
934 for (int b = 0; b < 3; b++) {
935 if (backend_capture->buffers[b] == buffer) {
938 snprintf(temp, sizeof temp, "f%d_b%d", f, b);
941 tdm_buffer_add_release_handler(buffer, _ut_tdm_backend_capture_buffer_release_cb, (void*)backend_capture);
942 backend_capture->ShowBuffer(b, &backend_capture->dst_pos);
947 if (--backend_capture->stream_count == 0) {
948 backend_capture->stream_exit = 1;
952 TEST_P(TDMBackendCapture, CaptureStreamLetterboxSize)
954 TDM_UT_SKIP_FLAG(has_capture_cap);
955 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
956 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_STREAM);
958 for (int o = 0; o < output_count; o++) {
959 const tdm_output_mode *mode = NULL;
961 if (!ut_tdm_output_is_connected(outputs[o]))
964 ASSERT_EQ(tdm_output_get_mode(outputs[o], &mode), TDM_ERROR_NONE);
966 for (int f = 0; f < format_count; f++) {
967 int half_size = ((mode->hdisplay <= mode->vdisplay) ? mode->hdisplay : mode->vdisplay) / 2;
969 dst_pos.x = (mode->hdisplay - half_size) / 2;
970 dst_pos.y = (mode->vdisplay - half_size) / 2;
971 dst_pos.w = half_size;
972 dst_pos.h = half_size;
974 TDM_UT_INFO("* testing for %c%c%c%c", FOURCC_STR(formats[f]));
976 FindLayer(o, formats[f], &dst_pos);
979 TDM_UT_INFO("no proper layer for %c%c%c%c", FOURCC_STR(formats[f]));
983 ASSERT_EQ(TestPrepare(o, half_size, half_size, formats[f],
984 TDM_TRANSFORM_NORMAL, TDM_CAPTURE_TYPE_STREAM, -1, false), true);
986 ASSERT_EQ(tdm_capture_set_done_handler(capture, _ut_tdm_capture_stream_done_cb, (void*)this), TDM_ERROR_NONE);
988 for (int b = 0; b < 3; b++)
989 ASSERT_EQ(tdm_capture_attach(capture, buffers[b]), TDM_ERROR_NONE);
996 ASSERT_EQ(tdm_capture_commit(capture), TDM_ERROR_NONE);
999 ASSERT_EQ(ut_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
1001 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)",
1002 FOURCC_STR(formats[f]), pipe, dst_layer_index);
1012 TEST_P(TDMBackendCapture, CaptureStreamFullSize)
1014 TDM_UT_SKIP_FLAG(has_capture_cap);
1015 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_OUTPUT);
1016 TDM_UT_SKIP_FLAG(capabilities & TDM_CAPTURE_CAPABILITY_STREAM);
1018 for (int o = 0; o < output_count; o++) {
1019 const tdm_output_mode *mode = NULL;
1021 if (!ut_tdm_output_is_connected(outputs[o]))
1024 ASSERT_EQ(tdm_output_get_mode(outputs[o], &mode), TDM_ERROR_NONE);
1026 for (int f = 0; f < format_count; f++) {
1027 int half_size = ((mode->hdisplay <= mode->vdisplay) ? mode->hdisplay : mode->vdisplay) / 2;
1029 dst_pos.x = (mode->hdisplay - half_size) / 2;
1030 dst_pos.y = (mode->vdisplay - half_size) / 2;
1031 dst_pos.w = half_size;
1032 dst_pos.h = half_size;
1034 TDM_UT_INFO("* testing for %c%c%c%c", FOURCC_STR(formats[f]));
1036 FindLayer(o, formats[f], &dst_pos);
1039 TDM_UT_INFO("no proper layer for %c%c%c%c", FOURCC_STR(formats[f]));
1043 ASSERT_EQ(TestPrepare(o, half_size, half_size, formats[f],
1044 TDM_TRANSFORM_NORMAL, TDM_CAPTURE_TYPE_STREAM, -1, true), true);
1046 ASSERT_EQ(tdm_capture_set_done_handler(capture, _ut_tdm_capture_stream_done_cb, (void*)this), TDM_ERROR_NONE);
1048 for (int b = 0; b < 3; b++)
1049 ASSERT_EQ(tdm_capture_attach(capture, buffers[b]), TDM_ERROR_NONE);
1053 stream_exit = false;
1056 ASSERT_EQ(tdm_capture_commit(capture), TDM_ERROR_NONE);
1058 while (!stream_exit)
1059 ASSERT_EQ(ut_tdm_display_handle_events(dpy), TDM_ERROR_NONE);
1061 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)",
1062 FOURCC_STR(formats[f]), pipe, dst_layer_index);
1072 #ifdef TDM_UT_TEST_WITH_PARAMS
1073 INSTANTIATE_TEST_CASE_P(TDMBackendCaptureParams,
1075 Combine(Bool(), Bool(), Values(TDM_DEFAULT_MODULE)));
1077 INSTANTIATE_TEST_CASE_P(TDMBackendCaptureParams,
1079 Values(TDM_DEFAULT_MODULE));