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 TEST_F(TDMOutputHwc, SetClientTargetBufferFailNullOutput)
289 tbm_surface_h target_buff = CreateBufferForOutput(0);
290 error = tdm_output_hwc_set_client_target_buffer(NULL, target_buff, reg);
291 tbm_surface_internal_destroy(target_buff);
292 ASSERT_NE(TDM_ERROR_NONE, error);
295 TEST_F(TDMOutputHwcWithoutHwcCap, SetClientTargetBufferFailNoHwc)
297 tdm_hwc_region damage;
299 for (int i = 0; i < output_count; i++) {
300 tbm_surface_h target_buff = CreateBufferForOutput(i);
301 ASSERT_NE(NULL, target_buff);
302 error = tdm_output_hwc_set_client_target_buffer(outputs[i], target_buff, damage);
303 tbm_surface_internal_destroy(target_buff);
304 ASSERT_NE(TDM_ERROR_NONE, error);
308 TEST_F(TDMOutputHwc, SetClientTargetBufferSuccessfulSetBuff)
310 tdm_hwc_region damage;
312 for (int i = 0; i < output_count; i++) {
313 tbm_surface_h target_buff = CreateBufferForOutput(i);
314 ASSERT_NE(NULL, target_buff);
315 if (IsHwcEnable(i)) {
316 error = tdm_output_hwc_set_client_target_buffer(outputs[i], target_buff, damage);
317 tbm_surface_internal_destroy(target_buff);
318 ASSERT_EQ(TDM_ERROR_NONE, error);
320 error = tdm_output_hwc_set_client_target_buffer(outputs[i], target_buff, damage);
321 tbm_surface_internal_destroy(target_buff);
322 ASSERT_NE(TDM_ERROR_NONE, error);
327 TEST_F(TDMOutputHwc, SetClientTargetBufferSuccessfulResetBuff)
329 tdm_hwc_region damage;
331 for (int i = 0; i < output_count; i++) {
332 if (IsHwcEnable(i)) {
333 error = tdm_output_hwc_set_client_target_buffer(outputs[i], NULL, damage);
334 ASSERT_EQ(TDM_ERROR_NONE, error);
336 error = tdm_output_hwc_set_client_target_buffer(outputs[i], NULL, damage);
337 ASSERT_NE(TDM_ERROR_NONE, error);
342 /* tbm_surface_queue_h tdm_output_hwc_get_target_buffer_queue(tdm_output *output, tdm_error *error); */
343 TEST_F(TDMOutputHwc, GetTargetBufferQueueFailNullOutput)
345 tbm_surface_queue_h queue = NULL;
347 queue = tdm_output_hwc_get_target_buffer_queue(NULL, &error);
348 ASSERT_NE(TDM_ERROR_NONE, error);
349 ASSERT_EQ(NULL, queue);
351 queue = tdm_output_hwc_get_target_buffer_queue(NULL, NULL);
352 ASSERT_EQ(NULL, queue);
355 TEST_F(TDMOutputHwcWithoutHwcCap, GetTargetBufferQueueFainNoHwc)
357 tbm_surface_queue_h queue = NULL;
359 for (int i = 0; i < output_count; i++) {
360 queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], &error);
361 ASSERT_NE(TDM_ERROR_NONE, error);
362 ASSERT_EQ(NULL, queue);
366 TEST_F(TDMOutputHwc, GetTargetBufferQueueSuccessful)
368 tbm_surface_queue_h queue = NULL;
370 for (int i = 0; i < output_count; i++) {
371 if (IsHwcEnable(i)) {
372 queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], &error);
373 tbm_surface_queue_destroy(queue);
374 ASSERT_EQ(TDM_ERROR_NONE, error);
375 ASSERT_NE(NULL, queue);
377 queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], NULL);
378 tbm_surface_queue_destroy(queue);
379 ASSERT_EQ(TDM_ERROR_NONE, error);
380 ASSERT_NE(NULL, queue);
382 queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], &error);
383 ASSERT_NE(TDM_ERROR_NONE, error);
384 ASSERT_EQ(NULL, queue);
386 queue = tdm_output_hwc_get_target_buffer_queue(outputs[i], NULL);
387 ASSERT_NE(TDM_ERROR_NONE, error);
388 ASSERT_EQ(NULL, queue);
393 /* tbm_surface_queue_h tdm_hwc_window_get_tbm_buffer_queue(tdm_hwc_window *hwc_window, tdm_error *error); */
394 TEST_F(TDMHwcWindow, GetBufferQueueFailNull)
396 tbm_surface_queue_h queue = NULL;
398 queue = tdm_hwc_window_get_tbm_buffer_queue(NULL, &error);
399 ASSERT_NE(TDM_ERROR_NONE, error);
400 ASSERT_EQ(NULL, queue);
402 queue = tdm_hwc_window_get_tbm_buffer_queue(NULL, NULL);
403 ASSERT_EQ(NULL, queue);
406 TEST_F(TDMHwcWindow, GetBufferQueueSuccessful)
408 tbm_surface_queue_h queue = NULL;
409 tdm_hwc_window_info info = { 0 };
411 info.src_config.format = TBM_FORMAT_ARGB8888;
412 info.src_config.size.h = info.src_config.size.v = 256;
413 info.src_config.pos.h = info.src_config.pos.w = 256;
414 info.dst_pos.h = info.dst_pos.w = 256;
415 info.transform = TDM_TRANSFORM_NORMAL;
417 for (int i = 0; i < hwc_count; i++) {
418 error = tdm_hwc_window_set_info(hwc_wins[i], &info);
419 ASSERT_EQ(TDM_ERROR_NONE, error);
421 queue = tdm_hwc_window_get_tbm_buffer_queue(hwc_wins[i], &error);
422 tbm_surface_queue_destroy(queue);
423 ASSERT_EQ(TDM_ERROR_NONE, error);
424 ASSERT_NE(NULL, queue);
426 queue = tdm_hwc_window_get_tbm_buffer_queue(hwc_wins[i], NULL);
427 tbm_surface_queue_destroy(queue);
428 ASSERT_NE(NULL, queue);
432 /* tdm_error tdm_hwc_window_set_zpos(tdm_hwc_window *hwc_window, uint32_t zpos); */
433 TEST_F(TDMHwcWindow, SetZposFailNull)
435 error = tdm_hwc_window_set_zpos(NULL, 1);
436 ASSERT_NE(TDM_ERROR_NONE, error);
439 TEST_F(TDMHwcWindow, SetZposSuccessful)
441 for (int i = 0; i < hwc_count; i++) {
442 error = tdm_hwc_window_set_zpos(hwc_wins[i], i);
443 ASSERT_EQ(TDM_ERROR_NONE, error);
447 /* tdm_error tdm_hwc_window_set_composition_type(tdm_hwc_window *hwc_window,
448 tdm_hwc_window_composition composition_type); */
449 TEST_F(TDMHwcWindow, SetCompositionTypeFailNull)
451 error = tdm_hwc_window_set_composition_type(NULL, TDM_COMPOSITION_DEVICE);
452 ASSERT_NE(TDM_ERROR_NONE, error);
455 TEST_F(TDMHwcWindow, SetCompositionTypeSuccessful)
457 for (int i = 0; i < hwc_count; i++) {
458 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE);
459 ASSERT_EQ(TDM_ERROR_NONE, error);
460 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_CLIENT);
461 ASSERT_EQ(TDM_ERROR_NONE, error);
462 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_CURSOR);
463 ASSERT_EQ(TDM_ERROR_NONE, error);
467 TEST_F(TDMHwcWindow, SetCompositionTypeFailInvalieCompositionType)
469 for (int i = 0; i < hwc_count; i++) {
470 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE_CANDIDATE);
471 ASSERT_NE(TDM_ERROR_NONE, error);
472 error = tdm_hwc_window_set_composition_type(hwc_wins[i], tdm_hwc_window_composition(TDM_COMPOSITION_NONE-1));
473 ASSERT_NE(TDM_ERROR_NONE, error);
477 /* tdm_error tdm_hwc_window_set_buffer_damage(tdm_hwc_window *hwc_window, tdm_hwc_region damage); */
478 TEST_F(TDMHwcWindow, SetBufferDamageFailNullHwcWindow)
480 tdm_hwc_region damage;
481 error = tdm_hwc_window_set_buffer_damage(NULL, damage);
482 ASSERT_NE(TDM_ERROR_NONE, error);
485 TEST_F(TDMHwcWindow, SetBufferDamageFailNullDamageRects)
487 tdm_hwc_region damage = {.num_rects = 1, .rects = NULL};
489 for (int i = 0; i < hwc_count; i++) {
490 error = tdm_hwc_window_set_buffer_damage(hwc_wins[i], damage);
491 ASSERT_NE(TDM_ERROR_NONE, error);
496 TEST_F(TDMHwcWindow, SetBufferDamageSuccessful)
498 tdm_pos const rects[1] = {0};
499 tdm_hwc_region damage = {.num_rects = 1, .rects = rects};
501 for (int i = 0; i < hwc_count; i++) {
502 error = tdm_hwc_window_set_buffer_damage(hwc_wins[i], damage);
503 ASSERT_EQ(TDM_ERROR_NONE, error);
508 /* tdm_error tdm_hwc_window_set_info(tdm_hwc_window *hwc_window, tdm_hwc_window_info *info); */
509 TEST_F(TDMHwcWindow, SetInfoFailNull)
511 tdm_hwc_window_info info = { 0 };
513 error = tdm_hwc_window_set_info(NULL, &info);
514 ASSERT_NE(TDM_ERROR_NONE, error);
517 error = tdm_hwc_window_set_info(hwc_wins[0], NULL);
518 ASSERT_NE(TDM_ERROR_NONE, error);
521 TEST_F(TDMHwcWindow, SetInfoSuccessful)
523 tdm_hwc_window_info info = { 0 };
525 for (int i = 0; i < hwc_count; i++) {
526 error = tdm_hwc_window_set_info(hwc_wins[i], &info);
527 ASSERT_EQ(TDM_ERROR_NONE, error);
532 /* tdm_error tdm_hwc_window_set_buffer(tdm_hwc_window *hwc_window, tbm_surface_h buffer); */
533 TEST_F(TDMHwcWindow, SetBufferFailNull)
535 error = tdm_hwc_window_set_buffer(NULL, NULL);
536 ASSERT_NE(TDM_ERROR_NONE, error);
539 TEST_F(TDMHwcWindow, SetBufferSuccessful)
541 for (int i = 0; i < hwc_count; i++) {
543 tbm_surface_h buff = tbm_surface_create(256, 256, TBM_FORMAT_ARGB8888);
546 error = tdm_hwc_window_set_buffer(hwc_wins[i], buff);
547 tbm_surface_destroy(buff);
548 ASSERT_EQ(TDM_ERROR_NONE, error);
551 error = tdm_hwc_window_set_buffer(hwc_wins[i], NULL);
552 ASSERT_EQ(TDM_ERROR_NONE, error);
556 /* tdm_error tdm_hwc_window_set_flags(tdm_hwc_window *hwc_window, tdm_hwc_window_flag flags); */
557 TEST_F(TDMHwcWindow, SetFlagsFailNull)
559 tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
561 error = tdm_hwc_window_set_flags(NULL, flag);
562 ASSERT_NE(TDM_ERROR_NONE, error);
565 TEST_F(TDMHwcWindow, SetFlagsSuccessful)
567 tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
569 for (int i = 0; i < hwc_count; i++) {
571 error = tdm_hwc_window_set_flags(hwc_wins[i], flag);
572 ASSERT_EQ(TDM_ERROR_NONE, error);
576 /* tdm_error tdm_hwc_window_unset_flags(tdm_hwc_window *hwc_window, tdm_hwc_window_flag flags); */
577 TEST_F(TDMHwcWindow, UnsetFlagsFailNull)
579 tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
581 error = tdm_hwc_window_unset_flags(NULL, flag);
582 ASSERT_NE(TDM_ERROR_NONE, error);
585 TEST_F(TDMHwcWindow, UnsetFlagsSuccessful)
587 tdm_hwc_window_flag flag = (tdm_hwc_window_flag)0;
589 for (int i = 0; i < hwc_count; i++) {
591 error = tdm_hwc_window_unset_flags(hwc_wins[i], flag);
592 ASSERT_EQ(TDM_ERROR_NONE, error);
596 /* tdm_error tdm_hwc_window_video_get_capability(tdm_hwc_window *hwc_window,
597 tdm_hwc_window_video_capability *video_capability); */
598 TEST_F(TDMHwcWindow, VideoGetCapabilityFailNull)
600 tdm_hwc_window_video_capability video_capability;
602 error = tdm_hwc_window_video_get_capability(NULL, &video_capability);
603 ASSERT_NE(TDM_ERROR_NONE, error);
606 error = tdm_hwc_window_video_get_capability(hwc_wins[0], NULL);
607 ASSERT_NE(TDM_ERROR_NONE, error);
612 TEST_F(TDMHwcWindow, VideoGetCapabilitySuccessful)
614 tdm_hwc_window_video_capability video_capability;
616 for (int i = 0; i < hwc_count; i++) {
617 /* hwc_window with TDM_COMPOSITION_CLIENT dosn't support tdm_hwc_window_video_get_capability()*/
618 error = tdm_hwc_window_video_get_capability(hwc_wins[i], &video_capability);
619 ASSERT_NE(TDM_ERROR_NONE, error);
621 /*TODO:: check video capability for TDM_COMPOSITION_VIDEO*/
625 /* tdm_error tdm_output_hwc_validate(tdm_output *output, uint32_t *num_types); */
626 TEST_F(TDMOutputHwc, ValidateFailNull)
629 error = tdm_output_hwc_validate(NULL, &num_types);
630 ASSERT_NE(TDM_ERROR_NONE, error);
633 error = tdm_output_hwc_validate(outputs[0], NULL);
634 ASSERT_NE(TDM_ERROR_NONE, error);
638 TEST_F(TDMOutputHwcWithoutHwcCap, ValidateFailNoHwc)
642 for (int i = 0; i < output_count; i++) {
643 error = tdm_output_hwc_validate(outputs[i], &num_types);
644 ASSERT_NE(TDM_ERROR_NONE, error);
648 TEST_F(TDMOutputHwc, ValidateSuccessful)
651 for (int i = 0; i < output_count; i++) {
652 if (IsHwcEnable(i)) {
653 error = tdm_output_hwc_validate(outputs[i], &num_types);
654 ASSERT_EQ(TDM_ERROR_NONE, error);
656 error = tdm_output_hwc_validate(outputs[i], &num_types);
657 ASSERT_NE(TDM_ERROR_NONE, error);
662 /* tdm_error tdm_output_hwc_get_changed_composition_types(tdm_output *output,
663 uint32_t *num_elements, tdm_hwc_window **hwc_window,
664 tdm_hwc_window_composition *composition_types); */
666 TEST_F(TDMOutputHwc, GetChangedCompositionTypesFailNull)
668 uint32_t num_elements;
670 error = tdm_output_hwc_get_changed_composition_types(NULL, &num_elements, NULL, NULL);
671 ASSERT_NE(TDM_ERROR_NONE, error);
674 error = tdm_output_hwc_get_changed_composition_types(outputs[0], NULL, NULL, NULL);
675 ASSERT_NE(TDM_ERROR_NONE, error);
679 TEST_F(TDMOutputHwcWithoutHwcCap, GetChangedCompositionTypesFailNoHwc)
681 uint32_t get_num = 10;
683 for (int i = 0; i < output_count; i++) {
684 error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, NULL, NULL);
685 ASSERT_NE(TDM_ERROR_NONE, error);
689 TEST_F(TDMHwcWindow, GetChangedCompositionTypesSuccessful)
691 uint32_t validate_num;
692 uint32_t get_num = 0;
694 tdm_hwc_window_composition *composition_types;
695 tdm_hwc_window **hwc_wnds;
697 for (int i = 0; i < hwc_count; i++) {
698 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE);
699 ASSERT_EQ(TDM_ERROR_NONE, error);
703 for (int i = 0; i < output_count; i++) {
704 if (IsHwcEnable(i)) {
705 error = tdm_output_hwc_validate(outputs[i], &validate_num);
706 ASSERT_EQ(TDM_ERROR_NONE, error);
708 error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, NULL, NULL);
709 ASSERT_EQ(TDM_ERROR_NONE, error);
711 ASSERT_TRUE(get_num == validate_num);
712 hwc_wnds = (tdm_hwc_window **)calloc(get_num, sizeof(tdm_hwc_window *));
713 composition_types = (tdm_hwc_window_composition *)calloc(get_num, sizeof(tdm_hwc_window_composition));
715 error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, hwc_wnds, composition_types);
718 free(composition_types);
720 ASSERT_EQ(TDM_ERROR_NONE, error);
722 error = tdm_output_hwc_get_changed_composition_types(outputs[i], &get_num, NULL, NULL);
723 ASSERT_NE(TDM_ERROR_NONE, error);
728 /* tdm_error tdm_output_hwc_accept_changes(tdm_output *output); */
730 TEST_F(TDMOutputHwc, AcceptChangesFailNull)
732 error = tdm_output_hwc_accept_changes(NULL);
733 ASSERT_NE(TDM_ERROR_NONE, error);
736 TEST_F(TDMOutputHwcWithoutHwcCap, AcceptChangesFailNoHwc)
738 for (int i = 0; i < output_count; i++) {
739 error = tdm_output_hwc_accept_changes(outputs[i]);
740 ASSERT_NE(TDM_ERROR_NONE, error);
744 TEST_F(TDMHwcWindow, AcceptChangesSuccessful)
746 uint32_t validate_num;
748 for (int i = 0; i < hwc_count; i++) {
749 error = tdm_hwc_window_set_composition_type(hwc_wins[i], TDM_COMPOSITION_DEVICE);
750 ASSERT_EQ(TDM_ERROR_NONE, error);
753 for (int i = 0; i < output_count; i++) {
754 if (IsHwcEnable(i)) {
755 error = tdm_output_hwc_validate(outputs[i], &validate_num);
756 ASSERT_EQ(TDM_ERROR_NONE, error);
758 if (validate_num > 0) {
759 error = tdm_output_hwc_accept_changes(outputs[i]);
760 ASSERT_EQ(TDM_ERROR_NONE, error);
766 static int need_validate_handler_is_called = 0;
767 static void need_validate_handler(tdm_output *output)
769 need_validate_handler_is_called = 1;
771 /* tdm_error tdm_output_hwc_set_need_validate_handler(tdm_output *output,
772 tdm_output_need_validate_handler hndl); */
773 TEST_F(TDMOutputHwc, SetNeedValidateHandlerFailNull)
775 error = tdm_output_hwc_set_need_validate_handler(NULL, &need_validate_handler);
776 ASSERT_NE(TDM_ERROR_NONE, error);
778 error = tdm_output_hwc_set_need_validate_handler(outputs[0], NULL);
779 ASSERT_NE(TDM_ERROR_NONE, error);
783 TEST_F(TDMOutputHwcWithoutHwcCap, SetNeedValidateHandlerFailNoHwc)
785 for (int i = 0; i < output_count; i++) {
786 error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
787 ASSERT_NE(TDM_ERROR_NONE, error);
791 TEST_F(TDMOutputHwc, SetNeedValidateHandlerSuccessful)
793 for (int i = 0; i < output_count; i++) {
794 if (IsHwcEnable(i)) {
796 error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
797 ASSERT_EQ(TDM_ERROR_NONE, error);
799 error = tdm_backend_trigger_need_validate_event(outputs[i]);
800 ASSERT_EQ(TDM_ERROR_NONE, error);
802 error = tdm_display_handle_events(dpy);
803 ASSERT_EQ(TDM_ERROR_NONE, error);
805 ASSERT_EQ(1, need_validate_handler_is_called);
807 /* test: second isn't allowed*/
808 error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
809 ASSERT_NE(TDM_ERROR_NONE, error);
811 error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
812 ASSERT_NE(TDM_ERROR_NONE, error);