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 **************************************************************************/
31 #include "gtest/gtest.h"
32 #include "ut_common.h"
36 #include "tdm_backend.h"
38 #include "tbm_bufmgr.h"
39 #include "tbm_drm_helper.h"
42 class TDMOutputHwc : public ::testing::Test {
44 tdm_display *dpy = NULL;
45 tbm_bufmgr tbm_bufmgr = NULL;
47 /*list of connected outputs*/
49 const tdm_output_mode **preferred_mode_array = NULL;
54 setenv("TDM_DEBUG_MODULE", "all", 1);
55 setenv("TDM_DEBUG", "1", 1);
56 setenv("TDM_THREAD", "1", 1);
57 setenv("TDM_COMMIT_PER_VBLANK", "1", 1);
58 setenv("TDM_DLOG", "1", 1);
59 setenv("TDM_HWC", "1", 1);
60 setenv("XDG_RUNTIME_DIR", ".", 1);
61 setenv("TBM_DLOG", "1", 1);
62 setenv("TBM_DISPLAY_SERVER", "1", 1);
67 unsetenv("TDM_DEBUG_MODULE");
68 unsetenv("TDM_DEBUG");
69 unsetenv("TDM_THREAD");
70 unsetenv("TDM_COMMIT_PER_VBLANK");
73 unsetenv("XDG_RUNTIME_DIR");
75 unsetenv("TBM_DISPLAY_SERVER");
78 int IsHwcEnable(int i)
80 tdm_output_capability capabilities = (tdm_output_capability)0;
81 tdm_output_get_capabilities(outputs[i], &capabilities);
82 return capabilities & TDM_OUTPUT_CAPABILITY_HWC;
85 tbm_surface_h CreateBufferForOutput(int i)
87 int w = preferred_mode_array[i]->hdisplay;
88 int h = preferred_mode_array[i]->vdisplay;
89 return tbm_surface_internal_create_with_flags(w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
94 const tdm_output_mode *preferred_mode = NULL;
95 tdm_error error = TDM_ERROR_NONE;
96 int all_output_count = 0;
100 /* FIXME: fix the error. If we initialize TBM before TDM we get fail
101 * in the tdm_output_set_dpms */
103 tbm_bufmgr = tbm_bufmgr_init(-1);
104 ASSERT_FALSE(tbm_bufmgr == NULL);
107 dpy = tdm_display_init(&error);
108 ASSERT_TRUE(error == TDM_ERROR_NONE);
109 ASSERT_FALSE(dpy == NULL);
111 master_fd = tbm_drm_helper_get_master_fd();
112 ASSERT_TRUE(tdm_display_get_output_count(dpy, &all_output_count) == TDM_ERROR_NONE);
114 outputs = (tdm_output **)calloc(all_output_count, sizeof(tdm_output *));
115 ASSERT_FALSE(NULL == outputs);
117 preferred_mode_array = (const tdm_output_mode **)calloc(all_output_count, sizeof(tdm_output_mode *));
118 ASSERT_FALSE(NULL == preferred_mode_array);
122 for (int i = 0; i < all_output_count; i++) {
123 tdm_output *output = tdm_display_get_output(dpy, i, &error);
124 int output_modes_cnt = 0;
125 const tdm_output_mode *output_modes;
127 if (TDM_ERROR_NONE != error || NULL == output)
130 tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
131 if (TDM_ERROR_NONE != tdm_output_get_conn_status(output, &status))
134 if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
137 error = tdm_output_get_available_modes(output, &output_modes, &output_modes_cnt);
138 if (TDM_ERROR_NONE != error)
140 if (output_modes_cnt <= 0) {
144 for(int j = 0; j < output_modes_cnt; j++)
145 if(output_modes[j].type & TDM_OUTPUT_MODE_TYPE_PREFERRED)
146 preferred_mode = &output_modes[j];
151 if (preferred_mode_array)
152 preferred_mode_array[output_count] = preferred_mode;
154 outputs[output_count] = output;
157 error = tdm_output_set_mode(output, preferred_mode);
158 ASSERT_EQ(TDM_ERROR_NONE, error);
163 tdm_display_deinit(dpy);
165 tbm_bufmgr_deinit(tbm_bufmgr);
169 if (preferred_mode_array)
170 free(preferred_mode_array);
171 if (master_fd > -1) {
172 int temp_master_fd = tbm_drm_helper_get_master_fd();
173 EXPECT_EQ(temp_master_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl;
174 if (temp_master_fd > -1)
183 class TDMOutputHwcWithoutHwcCap : public TDMOutputHwc {
186 TDMOutputHwc::SetEnv();
187 setenv("TDM_HWC", "0", 1);
191 #define HWC_WIN_NUM 5
192 class TDMHwcWindow : public TDMOutputHwc {
194 tdm_hwc_window **hwc_wins;
201 TDMOutputHwc::SetUp();
202 hwc_wins = (tdm_hwc_window **)calloc(output_count * HWC_WIN_NUM, sizeof(tdm_hwc_window *));
204 //create HWC_WIN_NUM hwc_windows for each outputs
205 for (int i = 0; i < output_count; i++) {
206 if (IsHwcEnable(i)) {
207 for (int j = 0; j < HWC_WIN_NUM; j++) {
208 tdm_hwc_window * hw = tdm_output_hwc_create_window(outputs[i], &error);
209 ASSERT_EQ(TDM_ERROR_NONE, error);
210 hwc_wins[hwc_count++] = hw;
218 for (int i = 0; i < hwc_count; i++) {
219 tdm_output_hwc_destroy_window(outputs[0], hwc_wins[i]);
221 TDMOutputHwc::TearDown();
226 /* tdm_hwc_window * tdm_output_hwc_create_window(tdm_output *output, tdm_error *error); */
227 TEST_F(TDMOutputHwc, CreateWindowFailNull)
229 ASSERT_EQ(NULL, tdm_output_hwc_create_window(NULL, &error));
230 ASSERT_NE(TDM_ERROR_NONE, error);
233 TEST_F(TDMOutputHwc, CreateWindowSuccessful)
235 for (int i = 0; i < output_count; i++) {
236 if (IsHwcEnable(i)) {
237 tdm_hwc_window * hw = tdm_output_hwc_create_window(outputs[i], &error);
238 ASSERT_EQ(TDM_ERROR_NONE, error);
239 error = tdm_output_hwc_destroy_window(outputs[i], hw);
240 ASSERT_EQ(TDM_ERROR_NONE, error);
242 ASSERT_EQ(NULL, tdm_output_hwc_create_window(outputs[i], &error));
243 ASSERT_NE(TDM_ERROR_NONE, error);
249 /* tdm_error tdm_output_hwc_destroy_window(tdm_output *output, tdm_hwc_window *hwc_window); */
250 TEST_F(TDMOutputHwc, DestroyWindowFailNull)
252 for (int i = 0; i < output_count; i++) {
253 tdm_hwc_window * hw = NULL;
255 if (IsHwcEnable(i)) {
256 hw = tdm_output_hwc_create_window(outputs[i], &error);
257 ASSERT_EQ(TDM_ERROR_NONE, error);
260 /* test: output is NULL*/
261 error = tdm_output_hwc_destroy_window(NULL, hw);
262 ASSERT_NE(TDM_ERROR_NONE, error);
264 /* test: hw is NULL*/
265 error = tdm_output_hwc_destroy_window(outputs[i], NULL);
266 ASSERT_NE(TDM_ERROR_NONE, error);
270 TEST_F(TDMOutputHwc, DestroyWindowSuccessful)
273 for (int i = 0; i < output_count; i++) {
274 if (IsHwcEnable(i)) {
275 hw = tdm_output_hwc_create_window(outputs[i], &error);
276 ASSERT_EQ(TDM_ERROR_NONE, error);
277 error = tdm_output_hwc_destroy_window(outputs[i], hw);
278 ASSERT_EQ(TDM_ERROR_NONE, error);
284 /* tdm_error tdm_output_hwc_set_client_target_buffer(tdm_output *output,
285 tbm_surface_h target_buffer, tdm_hwc_region damage,
286 tdm_hwc_window *composited_wnds, uint32_t num_wnds); */
287 TEST_F(TDMOutputHwc, DISABLED_SetClientTargetBufferFailNullOutput)
290 tbm_surface_h target_buff = CreateBufferForOutput(0);
291 error = tdm_output_hwc_set_client_target_buffer(NULL, target_buff, reg, NULL, 0 /* TODO: sergs_ut */);
292 tbm_surface_internal_destroy(target_buff);
293 ASSERT_NE(TDM_ERROR_NONE, error);
296 TEST_F(TDMOutputHwcWithoutHwcCap, DISABLED_SetClientTargetBufferFailNoHwc)
298 tdm_hwc_region damage;
300 for (int i = 0; i < output_count; i++) {
301 tbm_surface_h target_buff = CreateBufferForOutput(i);
302 ASSERT_NE(NULL, target_buff);
303 error = tdm_output_hwc_set_client_target_buffer(outputs[i], target_buff, damage,
304 NULL, 0 /* TODO: sergs_ut */);
305 tbm_surface_internal_destroy(target_buff);
306 ASSERT_NE(TDM_ERROR_NONE, error);
310 TEST_F(TDMOutputHwc, DISABLED_SetClientTargetBufferSuccessfulSetBuff)
312 tdm_hwc_region damage;
314 for (int i = 0; i < output_count; i++) {
315 tbm_surface_h target_buff = CreateBufferForOutput(i);
316 ASSERT_NE(NULL, target_buff);
317 if (IsHwcEnable(i)) {
318 error = tdm_output_hwc_set_client_target_buffer(outputs[i], target_buff, damage,
319 NULL, 0 /* TODO: sergs_ut_ut */);
320 tbm_surface_internal_destroy(target_buff);
321 ASSERT_EQ(TDM_ERROR_NONE, error);
323 error = tdm_output_hwc_set_client_target_buffer(outputs[i], target_buff, damage,
324 NULL, 0 /* TODO: sergs_ut */);
325 tbm_surface_internal_destroy(target_buff);
326 ASSERT_NE(TDM_ERROR_NONE, error);
331 TEST_F(TDMOutputHwc, DISABLED_SetClientTargetBufferSuccessfulResetBuff)
333 tdm_hwc_region damage = {.num_rects = 0, .rects = NULL};
335 for (int i = 0; i < output_count; i++) {
336 if (IsHwcEnable(i)) {
337 error = tdm_output_hwc_set_client_target_buffer(outputs[i], NULL, damage,
338 NULL, 0 /* TODO: sergs_ut */);
339 ASSERT_EQ(TDM_ERROR_NONE, error);
341 error = tdm_output_hwc_set_client_target_buffer(outputs[i], NULL, damage,
342 NULL, 0 /* TODO: sergs_ut */);
343 ASSERT_NE(TDM_ERROR_NONE, error);
348 /* tbm_surface_queue_h tdm_output_hwc_get_target_buffer_queue(tdm_output *output, tdm_error *error); */
349 TEST_F(TDMOutputHwc, GetTargetBufferQueueFailNullOutput)
351 tbm_surface_queue_h queue = NULL;
353 queue = tdm_output_hwc_get_target_buffer_queue(NULL, &error);
354 ASSERT_NE(TDM_ERROR_NONE, error);
355 ASSERT_EQ(NULL, queue);
357 queue = tdm_output_hwc_get_target_buffer_queue(NULL, NULL);
358 ASSERT_EQ(NULL, queue);
361 TEST_F(TDMOutputHwcWithoutHwcCap, GetTargetBufferQueueFainNoHwc)
363 tbm_surface_queue_h queue = NULL;
365 for (int i = 0; i < output_count; i++) {
366 queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], &error);
367 ASSERT_NE(TDM_ERROR_NONE, error);
368 ASSERT_EQ(NULL, queue);
372 TEST_F(TDMOutputHwc, GetTargetBufferQueueSuccessful)
374 tbm_surface_queue_h queue = NULL;
376 for (int i = 0; i < output_count; i++) {
377 if (IsHwcEnable(i)) {
378 queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], &error);
379 tbm_surface_queue_destroy(queue);
380 ASSERT_EQ(TDM_ERROR_NONE, error);
381 ASSERT_NE(NULL, queue);
383 queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], NULL);
384 tbm_surface_queue_destroy(queue);
385 ASSERT_EQ(TDM_ERROR_NONE, error);
386 ASSERT_NE(NULL, queue);
388 queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], &error);
389 ASSERT_NE(TDM_ERROR_NONE, error);
390 ASSERT_EQ(NULL, queue);
392 queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], NULL);
393 ASSERT_NE(TDM_ERROR_NONE, error);
394 ASSERT_EQ(NULL, queue);
399 /* tbm_surface_queue_h tdm_hwc_window_get_tbm_buffer_queue(tdm_hwc_window *hwc_window, tdm_error *error); */
400 TEST_F(TDMHwcWindow, GetBufferQueueFailNull)
402 tbm_surface_queue_h queue = NULL;
404 queue = tdm_hwc_window_get_tbm_buffer_queue(NULL, &error);
405 ASSERT_NE(TDM_ERROR_NONE, error);
406 ASSERT_EQ(NULL, queue);
408 queue = tdm_hwc_window_get_tbm_buffer_queue(NULL, NULL);
409 ASSERT_EQ(NULL, queue);
412 TEST_F(TDMHwcWindow, GetBufferQueueSuccessful)
414 tbm_surface_queue_h queue = NULL;
415 tdm_hwc_window_info info = { 0 };
417 info.src_config.format = TBM_FORMAT_ARGB8888;
418 info.src_config.size.h = info.src_config.size.v = 256;
419 info.src_config.pos.h = info.src_config.pos.w = 256;
420 info.dst_pos.h = info.dst_pos.w = 256;
421 info.transform = TDM_TRANSFORM_NORMAL;
423 for (int i = 0; i < hwc_count; i++) {
424 error = tdm_hwc_window_set_info(hwc_wins[i], &info);
425 ASSERT_EQ(TDM_ERROR_NONE, error);
427 queue = tdm_hwc_window_get_tbm_buffer_queue(hwc_wins[i], &error);
428 tbm_surface_queue_destroy(queue);
429 ASSERT_EQ(TDM_ERROR_NONE, error);
430 ASSERT_NE(NULL, queue);
432 queue = tdm_hwc_window_get_tbm_buffer_queue(hwc_wins[i], NULL);
433 tbm_surface_queue_destroy(queue);
434 ASSERT_NE(NULL, queue);
438 /* tdm_error tdm_hwc_window_set_zpos(tdm_hwc_window *hwc_window, uint32_t zpos); */
439 TEST_F(TDMHwcWindow, SetZposFailNull)
441 error = tdm_hwc_window_set_zpos(NULL, 1);
442 ASSERT_NE(TDM_ERROR_NONE, error);
445 TEST_F(TDMHwcWindow, SetZposSuccessful)
447 for (int i = 0; i < hwc_count; i++) {
448 error = tdm_hwc_window_set_zpos(hwc_wins[i], i);
449 ASSERT_EQ(TDM_ERROR_NONE, error);
453 /* tdm_error tdm_hwc_window_set_composition_type(tdm_hwc_window *hwc_window,
454 tdm_hwc_window_composition composition_type); */
455 TEST_F(TDMHwcWindow, SetCompositionTypeFailNull)
457 error = tdm_hwc_window_set_composition_type(NULL, TDM_COMPOSITION_DEVICE);
458 ASSERT_NE(TDM_ERROR_NONE, error);
461 TEST_F(TDMHwcWindow, SetCompositionTypeSuccessful)
463 for (int i = 0; i < hwc_count; i++) {
464 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE);
465 ASSERT_EQ(TDM_ERROR_NONE, error);
466 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_CLIENT);
467 ASSERT_EQ(TDM_ERROR_NONE, error);
468 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_CURSOR);
469 ASSERT_EQ(TDM_ERROR_NONE, error);
473 TEST_F(TDMHwcWindow, SetCompositionTypeFailInvalieCompositionType)
475 for (int i = 0; i < hwc_count; i++) {
476 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE_CANDIDATE);
477 ASSERT_NE(TDM_ERROR_NONE, error);
478 error = tdm_hwc_window_set_composition_type(hwc_wins[i], tdm_hwc_window_composition(TDM_COMPOSITION_NONE-1));
479 ASSERT_NE(TDM_ERROR_NONE, error);
483 /* tdm_error tdm_hwc_window_set_buffer_damage(tdm_hwc_window *hwc_window, tdm_hwc_region damage); */
484 TEST_F(TDMHwcWindow, SetBufferDamageFailNullHwcWindow)
486 tdm_hwc_region damage;
487 error = tdm_hwc_window_set_buffer_damage(NULL, damage);
488 ASSERT_NE(TDM_ERROR_NONE, error);
491 TEST_F(TDMHwcWindow, SetBufferDamageFailNullDamageRects)
493 tdm_hwc_region damage = {.num_rects = 1, .rects = NULL};
495 for (int i = 0; i < hwc_count; i++) {
496 error = tdm_hwc_window_set_buffer_damage(hwc_wins[i], damage);
497 ASSERT_NE(TDM_ERROR_NONE, error);
502 TEST_F(TDMHwcWindow, SetBufferDamageSuccessful)
504 tdm_pos const rects[1] = {0};
505 tdm_hwc_region damage = {.num_rects = 1, .rects = rects};
507 for (int i = 0; i < hwc_count; i++) {
508 error = tdm_hwc_window_set_buffer_damage(hwc_wins[i], damage);
509 ASSERT_EQ(TDM_ERROR_NONE, error);
514 /* tdm_error tdm_hwc_window_set_info(tdm_hwc_window *hwc_window, tdm_hwc_window_info *info); */
515 TEST_F(TDMHwcWindow, SetInfoFailNull)
517 tdm_hwc_window_info info = { 0 };
519 error = tdm_hwc_window_set_info(NULL, &info);
520 ASSERT_NE(TDM_ERROR_NONE, error);
523 error = tdm_hwc_window_set_info(hwc_wins[0], NULL);
524 ASSERT_NE(TDM_ERROR_NONE, error);
527 TEST_F(TDMHwcWindow, SetInfoSuccessful)
529 tdm_hwc_window_info info = { 0 };
531 for (int i = 0; i < hwc_count; i++) {
532 error = tdm_hwc_window_set_info(hwc_wins[i], &info);
533 ASSERT_EQ(TDM_ERROR_NONE, error);
538 /* tdm_error tdm_hwc_window_set_buffer(tdm_hwc_window *hwc_window, tbm_surface_h buffer); */
539 TEST_F(TDMHwcWindow, SetBufferFailNull)
541 error = tdm_hwc_window_set_buffer(NULL, NULL);
542 ASSERT_NE(TDM_ERROR_NONE, error);
545 TEST_F(TDMHwcWindow, SetBufferSuccessful)
547 for (int i = 0; i < hwc_count; i++) {
549 tbm_surface_h buff = tbm_surface_create(256, 256, TBM_FORMAT_ARGB8888);
552 error = tdm_hwc_window_set_buffer(hwc_wins[i], buff);
553 tbm_surface_destroy(buff);
554 ASSERT_EQ(TDM_ERROR_NONE, error);
557 error = tdm_hwc_window_set_buffer(hwc_wins[i], NULL);
558 ASSERT_EQ(TDM_ERROR_NONE, error);
562 /* tdm_error tdm_hwc_window_set_flags(tdm_hwc_window *hwc_window, tdm_hwc_window_flag flags); */
563 TEST_F(TDMHwcWindow, SetFlagsFailNull)
565 tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
567 error = tdm_hwc_window_set_flags(NULL, flag);
568 ASSERT_NE(TDM_ERROR_NONE, error);
571 TEST_F(TDMHwcWindow, SetFlagsSuccessful)
573 tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
575 for (int i = 0; i < hwc_count; i++) {
577 error = tdm_hwc_window_set_flags(hwc_wins[i], flag);
578 ASSERT_EQ(TDM_ERROR_NONE, error);
582 /* tdm_error tdm_hwc_window_unset_flags(tdm_hwc_window *hwc_window, tdm_hwc_window_flag flags); */
583 TEST_F(TDMHwcWindow, UnsetFlagsFailNull)
585 tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
587 error = tdm_hwc_window_unset_flags(NULL, flag);
588 ASSERT_NE(TDM_ERROR_NONE, error);
591 TEST_F(TDMHwcWindow, UnsetFlagsSuccessful)
593 tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
595 for (int i = 0; i < hwc_count; i++) {
597 error = tdm_hwc_window_unset_flags(hwc_wins[i], flag);
598 ASSERT_EQ(TDM_ERROR_NONE, error);
602 /* tdm_error tdm_hwc_window_video_get_capability(tdm_hwc_window *hwc_window,
603 tdm_hwc_window_video_capability *video_capability); */
604 TEST_F(TDMHwcWindow, VideoGetCapabilityFailNull)
606 tdm_hwc_window_video_capability video_capability;
608 error = tdm_hwc_window_video_get_capability(NULL, &video_capability);
609 ASSERT_NE(TDM_ERROR_NONE, error);
612 error = tdm_hwc_window_video_get_capability(hwc_wins[0], NULL);
613 ASSERT_NE(TDM_ERROR_NONE, error);
618 TEST_F(TDMHwcWindow, VideoGetCapabilitySuccessful)
620 tdm_hwc_window_video_capability video_capability;
622 for (int i = 0; i < hwc_count; i++) {
623 /* hwc_window with TDM_COMPOSITION_CLIENT dosn't support tdm_hwc_window_video_get_capability()*/
624 error = tdm_hwc_window_video_get_capability(hwc_wins[i], &video_capability);
625 ASSERT_NE(TDM_ERROR_NONE, error);
627 /*TODO:: check video capability for TDM_COMPOSITION_VIDEO*/
631 /* tdm_error tdm_output_hwc_validate(tdm_output *output, uint32_t *num_types); */
632 TEST_F(TDMOutputHwc, ValidateFailNull)
635 error = tdm_output_hwc_validate(NULL, &num_types);
636 ASSERT_NE(TDM_ERROR_NONE, error);
639 error = tdm_output_hwc_validate(outputs[0], NULL);
640 ASSERT_NE(TDM_ERROR_NONE, error);
644 TEST_F(TDMOutputHwcWithoutHwcCap, ValidateFailNoHwc)
648 for (int i = 0; i < output_count; i++) {
649 error = tdm_output_hwc_validate(outputs[i], &num_types);
650 ASSERT_NE(TDM_ERROR_NONE, error);
654 TEST_F(TDMOutputHwc, ValidateSuccessful)
657 for (int i = 0; i < output_count; i++) {
658 if (IsHwcEnable(i)) {
659 error = tdm_output_hwc_validate(outputs[i], &num_types);
660 ASSERT_EQ(TDM_ERROR_NONE, error);
662 error = tdm_output_hwc_validate(outputs[i], &num_types);
663 ASSERT_NE(TDM_ERROR_NONE, error);
668 /* tdm_error tdm_output_hwc_get_changed_composition_types(tdm_output *output,
669 uint32_t *num_elements, tdm_hwc_window **hwc_window,
670 tdm_hwc_window_composition *composition_types); */
672 TEST_F(TDMOutputHwc, GetChangedCompositionTypesFailNull)
674 uint32_t num_elements;
676 error = tdm_output_hwc_get_changed_composition_types(NULL, &num_elements, NULL, NULL);
677 ASSERT_NE(TDM_ERROR_NONE, error);
680 error = tdm_output_hwc_get_changed_composition_types(outputs[0], NULL, NULL, NULL);
681 ASSERT_NE(TDM_ERROR_NONE, error);
685 TEST_F(TDMOutputHwcWithoutHwcCap, GetChangedCompositionTypesFailNoHwc)
687 uint32_t get_num = 10;
689 for (int i = 0; i < output_count; i++) {
690 error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, NULL, NULL);
691 ASSERT_NE(TDM_ERROR_NONE, error);
695 TEST_F(TDMHwcWindow, GetChangedCompositionTypesSuccessful)
697 uint32_t validate_num;
698 uint32_t get_num = 0;
700 tdm_hwc_window_composition *composition_types;
701 tdm_hwc_window **hwc_wnds;
703 for (int i = 0; i < hwc_count; i++) {
704 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE);
705 ASSERT_EQ(TDM_ERROR_NONE, error);
709 for (int i = 0; i < output_count; i++) {
710 if (IsHwcEnable(i)) {
711 error = tdm_output_hwc_validate(outputs[i], &validate_num);
712 ASSERT_EQ(TDM_ERROR_NONE, error);
714 error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, NULL, NULL);
715 ASSERT_EQ(TDM_ERROR_NONE, error);
717 ASSERT_TRUE(get_num == validate_num);
718 hwc_wnds = (tdm_hwc_window **)calloc(get_num, sizeof(tdm_hwc_window *));
719 composition_types = (tdm_hwc_window_composition *)calloc(get_num, sizeof(tdm_hwc_window_composition));
721 error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, hwc_wnds, composition_types);
724 free(composition_types);
726 ASSERT_EQ(TDM_ERROR_NONE, error);
728 error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, NULL, NULL);
729 ASSERT_NE(TDM_ERROR_NONE, error);
734 /* tdm_error tdm_output_hwc_accept_changes(tdm_output *output); */
736 TEST_F(TDMOutputHwc, AcceptChangesFailNull)
738 error = tdm_output_hwc_accept_changes(NULL);
739 ASSERT_NE(TDM_ERROR_NONE, error);
742 TEST_F(TDMOutputHwcWithoutHwcCap, AcceptChangesFailNoHwc)
744 for (int i = 0; i < output_count; i++) {
745 error = tdm_output_hwc_accept_changes(outputs[i]);
746 ASSERT_NE(TDM_ERROR_NONE, error);
750 TEST_F(TDMHwcWindow, AcceptChangesSuccessful)
752 uint32_t validate_num;
754 for (int i = 0; i < hwc_count; i++) {
755 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE);
756 ASSERT_EQ(TDM_ERROR_NONE, error);
759 for (int i = 0; i < output_count; i++) {
760 if (IsHwcEnable(i)) {
761 error = tdm_output_hwc_validate(outputs[i], &validate_num);
762 ASSERT_EQ(TDM_ERROR_NONE, error);
764 if (validate_num > 0) {
765 error = tdm_output_hwc_accept_changes(outputs[i]);
766 ASSERT_EQ(TDM_ERROR_NONE, error);
772 static int need_validate_handler_is_called = 0;
773 static void need_validate_handler(tdm_output *output)
775 need_validate_handler_is_called = 1;
777 /* tdm_error tdm_output_hwc_set_need_validate_handler(tdm_output *output,
778 tdm_output_need_validate_handler hndl); */
779 TEST_F(TDMOutputHwc, SetNeedValidateHandlerFailNull)
781 error = tdm_output_hwc_set_need_validate_handler(NULL, &need_validate_handler);
782 ASSERT_NE(TDM_ERROR_NONE, error);
784 error = tdm_output_hwc_set_need_validate_handler(outputs[0], NULL);
785 ASSERT_NE(TDM_ERROR_NONE, error);
789 TEST_F(TDMOutputHwcWithoutHwcCap, SetNeedValidateHandlerFailNoHwc)
791 for (int i = 0; i < output_count; i++) {
792 error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
793 ASSERT_NE(TDM_ERROR_NONE, error);
797 TEST_F(TDMOutputHwc, SetNeedValidateHandlerSuccessful)
799 for (int i = 0; i < output_count; i++) {
800 if (IsHwcEnable(i)) {
802 error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
803 ASSERT_EQ(TDM_ERROR_NONE, error);
805 error = tdm_backend_trigger_need_validate_event(outputs[i]);
806 ASSERT_EQ(TDM_ERROR_NONE, error);
808 error = tdm_display_handle_events(dpy);
809 ASSERT_EQ(TDM_ERROR_NONE, error);
811 ASSERT_EQ(1, need_validate_handler_is_called);
813 /* test: second isn't allowed*/
814 error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
815 ASSERT_NE(TDM_ERROR_NONE, error);
817 error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
818 ASSERT_NE(TDM_ERROR_NONE, error);