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"
35 #include <sys/epoll.h>
36 #include <sys/timerfd.h>
40 #include "tbm_bufmgr.h"
41 #include "tbm_drm_helper.h"
42 #include "tbm_surface.h"
43 #include "tbm_surface_queue.h"
46 class TDMLayer : public ::testing::Test {
48 tdm_display *dpy = NULL;
49 tbm_bufmgr tbm_bufmgr = NULL;
50 int master_fd = -42, tbm_fd = -42, layer_count = 0, output_count = 0;
51 tdm_layer **tdm_layer_array = NULL;
52 tbm_surface_h *tdm_layers_buffer_array = NULL;
53 tbm_surface_queue_h *tdm_layers_buffer_queue_array = NULL;
54 int *tdm_layer_output_idx = NULL;
55 const tdm_output_mode **preferred_mode_array = NULL;
56 bool has_layers = false;
59 setenv("TDM_DEBUG_MODULE", "all", 1);
60 setenv("TDM_DEBUG", "1", 1);
61 setenv("TDM_THREAD", "0", 1);
62 setenv("TDM_COMMIT_PER_VBLANK", "1", 1);
63 setenv("TDM_DLOG", "1", 1);
64 setenv("XDG_RUNTIME_DIR", ".", 1);
65 setenv("TBM_DLOG", "1", 1);
66 setenv("TBM_DISPLAY_SERVER", "1", 1);
70 const tdm_output_mode *preferred_mode = NULL;
71 tdm_error error = TDM_ERROR_NONE;
75 /* FIXME: fix the error. If we initialize TBM before TDM we get fail
76 * in the tdm_output_set_dpms */
78 tbm_bufmgr = tbm_bufmgr_init(-1);
79 ASSERT_FALSE(tbm_bufmgr == NULL);
82 dpy = tdm_display_init(&error);
83 ASSERT_TRUE(error == TDM_ERROR_NONE);
84 ASSERT_FALSE(dpy == NULL);
86 master_fd = tbm_drm_helper_get_master_fd();
87 tbm_fd = tbm_drm_helper_get_fd();
88 ASSERT_TRUE(tdm_display_get_output_count(dpy, &output_count) == TDM_ERROR_NONE);
90 tdm_layer_output_idx = (int *) calloc(output_count, sizeof(int));
91 ASSERT_FALSE(NULL == tdm_layer_output_idx);
93 preferred_mode_array = (const tdm_output_mode **)calloc(output_count, sizeof(tdm_output_mode *));
94 ASSERT_FALSE(NULL == preferred_mode_array);
96 for (int i = 0; i < output_count; i++) {
97 tdm_output *output = tdm_display_get_output(dpy, i, &error);
98 int output_modes_cnt = 0;
99 const tdm_output_mode *output_modes;
101 if (TDM_ERROR_NONE != error || NULL == output)
104 tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
105 if (TDM_ERROR_NONE != tdm_output_get_conn_status(output, &status))
108 if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
111 error = tdm_output_get_available_modes(output, &output_modes, &output_modes_cnt);
112 if (TDM_ERROR_NONE != error)
114 if (output_modes_cnt <= 0) {
118 for(int j = 0; j < output_modes_cnt; j++)
119 if(output_modes[j].type & TDM_OUTPUT_MODE_TYPE_PREFERRED)
120 preferred_mode = &output_modes[j];
125 int temp_layer_count = 0;
126 if (TDM_ERROR_NONE != tdm_output_get_layer_count(output, &temp_layer_count))
128 if (0 == temp_layer_count)
130 tdm_layer_array = (tdm_layer **) realloc(tdm_layer_array,
131 (layer_count + temp_layer_count)*sizeof(tdm_layer *));
133 ASSERT_FALSE(NULL == tdm_layer_array);
135 for (int k = layer_count; k < (layer_count + temp_layer_count); k++) {
136 tdm_layer_array[k] = tdm_output_get_layer(output, k, &error);
137 tdm_layer_output_idx[k] = i;
138 ASSERT_TRUE(TDM_ERROR_NONE == error);
139 ASSERT_FALSE(NULL == tdm_layer_array[k]);
141 layer_count += temp_layer_count;
142 preferred_mode_array[i] = preferred_mode;
145 tdm_layers_buffer_array = (tbm_surface_h *) calloc(layer_count, sizeof(tbm_surface_h));
146 ASSERT_FALSE(NULL == tdm_layers_buffer_array);
148 tdm_layers_buffer_queue_array = (tbm_surface_queue_h *) calloc(layer_count, sizeof(tbm_surface_queue_h));
149 ASSERT_FALSE(NULL == tdm_layers_buffer_queue_array);
151 #ifdef FAIL_ON_UNSUPPORTED
152 ASSERT_GT(layer_count, 0);
161 for (int i = 0; i < layer_count; ++i) {
162 error = tdm_layer_unset_buffer(tdm_layer_array[i]);
163 EXPECT_TRUE(error == TDM_ERROR_NONE);
165 if (tdm_layers_buffer_array[i])
166 tbm_surface_destroy(tdm_layers_buffer_array[i]);
168 if (tdm_layers_buffer_queue_array[i])
169 tbm_surface_queue_destroy(tdm_layers_buffer_queue_array[i]);
171 tdm_layers_buffer_array[i] = NULL;
172 tdm_layers_buffer_queue_array[i] = NULL;
175 tdm_display_deinit(dpy);
177 tbm_bufmgr_deinit(tbm_bufmgr);
180 free(tdm_layer_array);
181 if (tdm_layer_output_idx)
182 free(tdm_layer_output_idx);
183 if (preferred_mode_array)
184 free(preferred_mode_array);
185 if (master_fd > -1) {
186 int temp_master_fd = tbm_drm_helper_get_master_fd();
187 EXPECT_EQ(temp_master_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl;
188 if (temp_master_fd > -1)
193 int temp_tbm_fd = tbm_drm_helper_get_fd();
194 EXPECT_EQ(temp_tbm_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl;
195 if (temp_tbm_fd > -1)
200 unsetenv("TDM_DEBUG_MODULE");
201 unsetenv("TDM_DEBUG");
202 unsetenv("TDM_THREAD");
203 unsetenv("TDM_COMMIT_PER_VBLANK");
204 unsetenv("TDM_DLOG");
205 unsetenv("XDG_RUNTIME_DIR");
206 unsetenv("TBM_DLOG");
207 unsetenv("TBM_DISPLAY_SERVER");
210 tbm_surface_h UtCreateBufferForLayer(int layer_idx, int width, int height,
211 int format, int flags)
213 tbm_surface_h buffer;
215 buffer = tbm_surface_internal_create_with_flags(width, height, format, flags);
217 tdm_layers_buffer_array[layer_idx] = buffer;
222 tbm_surface_queue_h UtCreateBufferQueueForLayer(int layer_idx, int width, int height,
223 int format, int flags)
225 tbm_surface_queue_h buffer_queue;
227 buffer_queue = tbm_surface_queue_create(2, width, height, format, flags);
229 tdm_layers_buffer_queue_array[layer_idx] = buffer_queue;
235 class TDMLayerCommit : public TDMLayer
241 static const int timeLimitSec = 0;
242 static const int timeLimitNsec = 100000000;
245 static int utLayerCommitHandlerCounter;
246 static void UtLayerCommitHandler(tdm_layer *layer, unsigned int sequence,
247 unsigned int tv_sec, unsigned int tv_usec,
250 int *data = (int *)user_data;
254 utLayerCommitHandlerCounter++;
261 struct epoll_event ep;
263 utLayerCommitHandlerCounter = 0;
265 ASSERT_NO_FATAL_FAILURE(TDMLayer::SetUp());
267 for (int i = 0; i < output_count; ++i) {
268 if (!preferred_mode_array[i])
271 output = tdm_display_get_output(dpy, i, &error);
272 ASSERT_FALSE(output == NULL);
273 ASSERT_TRUE(error == TDM_ERROR_NONE);
275 error = tdm_output_set_mode(output, preferred_mode_array[i]);
276 ASSERT_TRUE(error == TDM_ERROR_NONE);
278 error = tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON);
279 ASSERT_TRUE(error == TDM_ERROR_NONE);
282 epFd = epoll_create1(0);
283 ASSERT_TRUE(epFd != -1);
285 timerFd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
286 ASSERT_TRUE(timerFd != -1);
288 memset(&ep, 0, sizeof ep);
289 ep.events |= EPOLLIN;
290 ep.data.fd = timerFd;
291 ASSERT_TRUE(epoll_ctl(epFd, EPOLL_CTL_ADD, timerFd, &ep) == 0);
293 ASSERT_TRUE(tdm_display_get_fd(dpy, &tdmFd) == TDM_ERROR_NONE);
295 memset(&ep, 0, sizeof ep);
296 ep.events |= EPOLLIN;
298 ASSERT_TRUE(epoll_ctl(epFd, EPOLL_CTL_ADD, tdmFd, &ep) == 0);
306 for (int i = 0; i < output_count; ++i) {
307 if (!preferred_mode_array[i])
310 output = tdm_display_get_output(dpy, i, &error);
311 EXPECT_FALSE(output == NULL);
312 EXPECT_TRUE(error == TDM_ERROR_NONE);
314 error = tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF);
315 EXPECT_TRUE(error == TDM_ERROR_NONE);
318 TDMLayer::TearDown();
321 void UtHandleCommitEvent(int num_waiting_layers)
323 struct itimerspec its;
325 struct epoll_event ep_event[2];
327 if (utLayerCommitHandlerCounter == num_waiting_layers)
330 its.it_interval.tv_sec = 0;
331 its.it_interval.tv_nsec = 0;
332 its.it_value.tv_sec = timeLimitSec;
333 its.it_value.tv_nsec = timeLimitNsec;
335 ASSERT_TRUE(timerfd_settime(timerFd, 0, &its, NULL) == 0);
338 count = epoll_wait(epFd, ep_event, sizeof(ep_event), -1);
339 ASSERT_TRUE(count >= 0);
341 for (int i = 0; i < count; i++) {
342 if (ep_event[i].data.fd == timerFd) {
345 ASSERT_TRUE(tdm_display_handle_events(dpy) == TDM_ERROR_NONE);
346 if (utLayerCommitHandlerCounter == num_waiting_layers)
354 class TDMLayerCommitThread : public TDMLayerCommit
359 setenv("TDM_DEBUG_MODULE", "all", 1);
360 setenv("TDM_DEBUG", "1", 1);
361 setenv("TDM_THREAD", "1", 1);
362 setenv("TDM_COMMIT_PER_VBLANK", "1", 1);
363 setenv("TDM_DLOG", "1", 1);
364 setenv("XDG_RUNTIME_DIR", ".", 1);
365 setenv("TBM_DLOG", "1", 1);
366 setenv("TBM_DISPLAY_SERVER", "1", 1);
370 class TDMLayerCommitWithDisabledCommitPerVblank : public TDMLayerCommit
375 setenv("TDM_DEBUG_MODULE", "all", 1);
376 setenv("TDM_DEBUG", "1", 1);
377 setenv("TDM_THREAD", "0", 1);
378 setenv("TDM_COMMIT_PER_VBLANK", "0", 1);
379 setenv("TDM_DLOG", "1", 1);
380 setenv("XDG_RUNTIME_DIR", ".", 1);
381 setenv("TBM_DLOG", "1", 1);
382 setenv("TBM_DISPLAY_SERVER", "1", 1);
386 int TDMLayerCommit::utLayerCommitHandlerCounter = 0;
388 TEST_F(TDMLayer, LayerGetCapabilitiesSuccessful)
390 SKIP_FLAG(has_layers);
391 for (int i = 0; i < layer_count; i++) {
392 tdm_layer_capability capabilities = (tdm_layer_capability) -42;
393 ASSERT_TRUE(TDM_ERROR_NONE == tdm_layer_get_capabilities(tdm_layer_array[i], &capabilities));
394 ASSERT_NE(capabilities, -42);
398 TEST_F(TDMLayer, LayerGetCapabilitiesFailNullAll)
400 SKIP_FLAG(has_layers);
401 ASSERT_EXIT({if (tdm_layer_get_capabilities(NULL, NULL) == TDM_ERROR_NONE) exit(1);
402 exit(0);}, ::testing::ExitedWithCode(0), "");
405 TEST_F(TDMLayer, LayerGetCapabilitiesFailOnlyLayer)
407 SKIP_FLAG(has_layers);
408 ASSERT_EXIT({for (int i = 0; i < layer_count; i++) {
409 if (tdm_layer_get_capabilities(tdm_layer_array[i], NULL) == TDM_ERROR_NONE) exit(1);
411 exit(0);}, ::testing::ExitedWithCode(0), "");
414 TEST_F(TDMLayer, OutputGetPrimaryIndexSuccessful)
416 SKIP_FLAG(has_layers);
417 for (int i = 0; i < output_count; i++) {
418 tdm_error error = TDM_ERROR_NONE;
420 tdm_output * output = tdm_display_get_output(dpy, i, &error);
421 ASSERT_FALSE(NULL == output);
422 ASSERT_TRUE(TDM_ERROR_NONE == error);
423 ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_primary_index(output, &index));
424 ASSERT_NE(index, -42);
428 TEST_F(TDMLayer, OutputGetPrimaryIndexFailNullAll)
430 SKIP_FLAG(has_layers);
431 ASSERT_EXIT({if (tdm_output_get_primary_index(NULL, NULL) == TDM_ERROR_NONE) exit(1);
432 exit(0);}, ::testing::ExitedWithCode(0), "");
435 TEST_F(TDMLayer, OutputGetPrimaryIndexFailOnlyOutput)
437 SKIP_FLAG(has_layers);
438 ASSERT_EXIT({for (int i = 0; i < output_count; i++) {
439 tdm_error error = TDM_ERROR_NONE;
440 tdm_output * output = tdm_display_get_output(dpy, i, &error);
441 if (NULL == output) exit(1);
442 if (TDM_ERROR_NONE != error) exit(1);
443 if (tdm_output_get_primary_index(output, NULL) == TDM_ERROR_NONE) exit(1);
445 exit(0);}, ::testing::ExitedWithCode(0), "");
448 /* tdm_layer_get_available_formats() */
450 TEST_F(TDMLayer, LayerGetAvailableFormatsFailNullAll)
452 SKIP_FLAG(has_layers);
453 ASSERT_EXIT({if (tdm_layer_get_available_formats(NULL, NULL, NULL) == TDM_ERROR_NONE) exit(1);
454 exit(0);}, ::testing::ExitedWithCode(0), "");
457 TEST_F(TDMLayer, LayerGetAvailableFormatsFailNullLayer)
459 SKIP_FLAG(has_layers);
460 ASSERT_EXIT({const tbm_format *formats;
462 if (tdm_layer_get_available_formats(NULL, &formats, &count) == TDM_ERROR_NONE) exit(1);
463 exit(0);}, ::testing::ExitedWithCode(0), "");
466 TEST_F(TDMLayer, LayerGetAvailableFormatsFailNullFormats)
468 SKIP_FLAG(has_layers);
469 ASSERT_EXIT({int count;
470 for (int i = 0; i < layer_count; i++) {
471 if (tdm_layer_get_available_formats(tdm_layer_array[i], NULL, &count) == TDM_ERROR_NONE) exit(1);
473 exit(0);}, ::testing::ExitedWithCode(0), "");
476 TEST_F(TDMLayer, LayerGetAvailableFormatsFailNullCount)
478 SKIP_FLAG(has_layers);
479 ASSERT_EXIT({const tbm_format *formats;
480 for (int i = 0; i < layer_count; i++) {
481 if (tdm_layer_get_available_formats(tdm_layer_array[i], &formats, NULL) == TDM_ERROR_NONE) exit(1);
483 exit(0);}, ::testing::ExitedWithCode(0), "");
486 TEST_F(TDMLayer, LayerGetAvailableFormatsSuccess)
488 SKIP_FLAG(has_layers);
490 const tbm_format *formats;
493 for (int i = 0; i < layer_count; ++i) {
494 error = tdm_layer_get_available_formats(tdm_layer_array[i], &formats, &count);
495 ASSERT_EQ(TDM_ERROR_NONE, error);
496 ASSERT_NE(NULL, formats);
501 /* tdm_layer_get_available_properties() */
503 TEST_F(TDMLayer, LayerGetAvailablePropertiesFailNullAll)
505 SKIP_FLAG(has_layers);
506 ASSERT_EXIT({if (tdm_layer_get_available_properties(NULL, NULL, NULL) == TDM_ERROR_NONE) exit(1);
507 exit(0);}, ::testing::ExitedWithCode(0), "");
510 TEST_F(TDMLayer, LayerGetAvailablePropertiesFailNullLayer)
512 SKIP_FLAG(has_layers);
513 ASSERT_EXIT({const tdm_prop *props;
515 if (tdm_layer_get_available_properties(NULL, &props, &count) == TDM_ERROR_NONE) exit(1);
516 exit(0);}, ::testing::ExitedWithCode(0), "");
519 TEST_F(TDMLayer, LayerGetAvailablePropertiesFailNullFormats)
521 SKIP_FLAG(has_layers);
522 ASSERT_EXIT({int count;
523 for (int i = 0; i < layer_count; i++) {
524 if (tdm_layer_get_available_properties(tdm_layer_array[i], NULL, &count) == TDM_ERROR_NONE) exit(1);
526 exit(0);}, ::testing::ExitedWithCode(0), "");
529 TEST_F(TDMLayer, LayerGetAvailablePropertiesFailNullCount)
531 SKIP_FLAG(has_layers);
532 ASSERT_EXIT({const tdm_prop *props;
533 for (int i = 0; i < layer_count; i++) {
534 if (tdm_layer_get_available_properties(tdm_layer_array[i], &props, NULL) == TDM_ERROR_NONE) exit(1);
536 exit(0);}, ::testing::ExitedWithCode(0), "");
539 TEST_F(TDMLayer, LayerGetAvailablePropertiesSuccess)
541 SKIP_FLAG(has_layers);
543 const tdm_prop *props;
546 for (int i = 0; i < layer_count; ++i) {
547 error = tdm_layer_get_available_properties(tdm_layer_array[i], &props, &count);
548 ASSERT_EQ(TDM_ERROR_NONE, error);
552 /* tdm_layer_get_zpos() */
554 TEST_F(TDMLayer, LayerGetZposFailNullAll)
556 SKIP_FLAG(has_layers);
557 ASSERT_EXIT({if (tdm_layer_get_zpos(NULL, NULL) == TDM_ERROR_NONE) exit(1);
558 exit(0);}, ::testing::ExitedWithCode(0), "");
561 TEST_F(TDMLayer, LayerGetZposFailNullLayer)
563 SKIP_FLAG(has_layers);
564 ASSERT_EXIT({int zpos;
565 if (tdm_layer_get_zpos(NULL, &zpos) == TDM_ERROR_NONE) exit(1);
566 exit(0);}, ::testing::ExitedWithCode(0), "");
569 TEST_F(TDMLayer, LayerGetZposFailNullZpos)
571 SKIP_FLAG(has_layers);
572 ASSERT_EXIT({for (int i = 0; i < layer_count; i++) {
573 if (tdm_layer_get_zpos(tdm_layer_array[i], NULL) == TDM_ERROR_NONE) exit(1);
575 exit(0);}, ::testing::ExitedWithCode(0), "");
578 TEST_F(TDMLayer, LayerGetZposSuccess)
580 SKIP_FLAG(has_layers);
583 for (int i = 0; i < layer_count; ++i) {
585 error = tdm_layer_get_zpos(tdm_layer_array[i], &zpos);
586 ASSERT_EQ(TDM_ERROR_NONE, error);
587 ASSERT_NE(INT_MIN, zpos);
591 /* tdm_layer_set_property() */
593 TEST_F(TDMLayer, LayerSetPropertyFailNullLayer)
595 SKIP_FLAG(has_layers);
596 ASSERT_EXIT({tdm_value value;
598 if (tdm_layer_set_property(NULL, id, value) == TDM_ERROR_NONE) exit(1);
599 exit(0);}, ::testing::ExitedWithCode(0), "");
602 TEST_F(TDMLayer, LayerSetPropertyFailWrongId)
604 SKIP_FLAG(has_layers);
609 for (int i = 0; i < layer_count; ++i) {
610 error = tdm_layer_set_property(tdm_layer_array[i], id, value);
611 ASSERT_NE(TDM_ERROR_NONE, error);
615 /* tdm_layer_get_property() */
617 TEST_F(TDMLayer, LayerGetPropertyFailNullLayer)
619 SKIP_FLAG(has_layers);
620 ASSERT_EXIT({tdm_value value;
622 if (tdm_layer_get_property(NULL, id, &value) == TDM_ERROR_NONE) exit(1);
623 exit(0);}, ::testing::ExitedWithCode(0), "");
626 TEST_F(TDMLayer, LayerGetPropertyFailNullValue)
628 SKIP_FLAG(has_layers);
629 ASSERT_EXIT({int id = INT_MAX;
630 for (int i = 0; i < layer_count; ++i) {
631 if (tdm_layer_get_property(tdm_layer_array[i], id, NULL) == TDM_ERROR_NONE) exit(1);
633 exit(0);}, ::testing::ExitedWithCode(0), "");
636 TEST_F(TDMLayer, LayerGetPropertyFailWrongId)
638 SKIP_FLAG(has_layers);
643 for (int i = 0; i < layer_count; ++i) {
644 error = tdm_layer_get_property(tdm_layer_array[i], id, &value);
645 ASSERT_NE(TDM_ERROR_NONE, error);
649 /* tdm_layer_set_info() */
651 TEST_F(TDMLayer, LayerSetInfoFailNullAll)
653 SKIP_FLAG(has_layers);
654 ASSERT_EXIT({if (tdm_layer_set_info(NULL, NULL) == TDM_ERROR_NONE) exit(1);
655 exit(0);}, ::testing::ExitedWithCode(0), "");
658 TEST_F(TDMLayer, LayerSetInfoFailNullLayer)
660 SKIP_FLAG(has_layers);
662 ASSERT_EXIT({tdm_info_layer info = {0};
663 if (tdm_layer_set_info(NULL, &info) == TDM_ERROR_NONE) exit(1);
664 exit(0);}, ::testing::ExitedWithCode(0), "");
667 TEST_F(TDMLayer, LayerSetInfoFailNullInfo)
669 SKIP_FLAG(has_layers);
671 ASSERT_EXIT({for (int i = 0; i < layer_count; ++i)
672 if (tdm_layer_set_info(tdm_layer_array[i], NULL) == TDM_ERROR_NONE) exit(1);
673 exit(0);}, ::testing::ExitedWithCode(0), "");
677 _ut_tdm_layer_set_info(tdm_layer *layer, int w, int h)
679 tdm_info_layer info = {0};
681 info.src_config.size.h = w;
682 info.src_config.size.v = h;
683 info.src_config.pos.x = 0;
684 info.src_config.pos.y = 0;
685 info.src_config.pos.w = w;
686 info.src_config.pos.h = h;
687 info.src_config.format = TBM_FORMAT_ARGB8888;
692 info.transform = TDM_TRANSFORM_NORMAL;
694 return tdm_layer_set_info(layer, &info);
697 TEST_F(TDMLayer, LayerSetInfoSuccess)
699 SKIP_FLAG(has_layers);
702 for (int i = 0; i < layer_count; ++i) {
703 error = _ut_tdm_layer_set_info(tdm_layer_array[i], 128, 128);
704 ASSERT_EQ(TDM_ERROR_NONE, error);
708 /* tdm_layer_get_info() */
710 TEST_F(TDMLayer, LayerGetInfoFailNullAll)
712 SKIP_FLAG(has_layers);
713 ASSERT_EXIT({if (tdm_layer_get_info(NULL, NULL) == TDM_ERROR_NONE) exit(1);
714 exit(0);}, ::testing::ExitedWithCode(0), "");
717 TEST_F(TDMLayer, LayerGetInfoFailNullLayer)
719 SKIP_FLAG(has_layers);
721 ASSERT_EXIT({tdm_info_layer info = {0};
722 if (tdm_layer_get_info(NULL, &info) == TDM_ERROR_NONE) exit(1);
723 exit(0);}, ::testing::ExitedWithCode(0), "");
726 TEST_F(TDMLayer, LayerGetInfoFailNullInfo)
728 SKIP_FLAG(has_layers);
730 ASSERT_EXIT({for (int i = 0; i < layer_count; ++i)
731 if (tdm_layer_get_info(tdm_layer_array[i], NULL) == TDM_ERROR_NONE) exit(1);
732 exit(0);}, ::testing::ExitedWithCode(0), "");
735 TEST_F(TDMLayer, LayerGetInfoSuccess)
737 SKIP_FLAG(has_layers);
739 tdm_info_layer set_info = {0};
740 tdm_info_layer ret_info = {0};
742 set_info.src_config.size.h = 128;
743 set_info.src_config.size.v = 128;
744 set_info.src_config.pos.x = 0;
745 set_info.src_config.pos.y = 0;
746 set_info.src_config.pos.w = 128;
747 set_info.src_config.pos.h = 128;
748 set_info.src_config.format = TBM_FORMAT_ARGB8888;
749 set_info.dst_pos.x = 0;
750 set_info.dst_pos.y = 0;
751 set_info.dst_pos.w = 128;
752 set_info.dst_pos.h = 128;
753 set_info.transform = TDM_TRANSFORM_NORMAL;
755 for (int i = 0; i < layer_count; ++i) {
756 error = tdm_layer_get_info(tdm_layer_array[i], &set_info);
757 ASSERT_EQ(TDM_ERROR_NONE, error);
759 error = tdm_layer_get_info(tdm_layer_array[i], &ret_info);
760 ASSERT_EQ(TDM_ERROR_NONE, error);
762 ASSERT_TRUE(!memcmp(&ret_info, &set_info, sizeof(tdm_info_layer)));
766 /* tdm_layer_set_buffer() */
768 TEST_F(TDMLayer, LayerSetBufferFailNullAll)
770 SKIP_FLAG(has_layers);
771 ASSERT_EXIT({if (tdm_layer_set_buffer(NULL, NULL) == TDM_ERROR_NONE) exit(1);
772 exit(0);}, ::testing::ExitedWithCode(0), "");
775 TEST_F(TDMLayer, LayerSetBufferFailNullLayer)
777 SKIP_FLAG(has_layers);
779 ASSERT_EXIT({tdm_error error;
780 tbm_surface_h buffer = UtCreateBufferForLayer(0, 128, 128, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
781 if (!buffer) exit(1);
782 error = tdm_layer_set_buffer(NULL, buffer);
783 if (error == TDM_ERROR_NONE) exit(1);
784 exit(0);}, ::testing::ExitedWithCode(0), "");
787 TEST_F(TDMLayer, LayerSetBufferFailNullBuffer)
789 SKIP_FLAG(has_layers);
791 ASSERT_EXIT({for (int i = 0; i < layer_count; ++i)
792 if (tdm_layer_set_buffer(tdm_layer_array[i], NULL) == TDM_ERROR_NONE) exit(1);
793 exit(0);}, ::testing::ExitedWithCode(0), "");
796 TEST_F(TDMLayer, LayerSetBufferSuccess)
798 SKIP_FLAG(has_layers);
799 tbm_surface_h buffer;
802 for (int i = 0; i < layer_count; ++i) {
803 buffer = UtCreateBufferForLayer(i, 128, 128, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
804 ASSERT_NE(NULL, buffer);
806 error = tdm_layer_set_buffer(tdm_layer_array[i], buffer);
807 ASSERT_EQ(TDM_ERROR_NONE, error);
811 TEST_F(TDMLayer, LayerSetBufferSuccessTwice)
813 SKIP_FLAG(has_layers);
814 tbm_surface_h buffer;
817 for (int i = 0; i < layer_count; ++i) {
818 buffer = UtCreateBufferForLayer(i, 128, 128, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
819 ASSERT_NE(NULL, buffer);
821 error = tdm_layer_set_buffer(tdm_layer_array[i], buffer);
822 ASSERT_EQ(TDM_ERROR_NONE, error);
824 error = tdm_layer_set_buffer(tdm_layer_array[i], buffer);
825 ASSERT_EQ(TDM_ERROR_NONE, error);
829 /* tdm_layer_unset_buffer() */
831 TEST_F(TDMLayer, LayerUnsetBufferFailNullLayer)
833 SKIP_FLAG(has_layers);
835 ASSERT_EXIT({tdm_error error;
836 error = tdm_layer_unset_buffer(NULL);
837 if (error == TDM_ERROR_NONE) exit(1);
838 exit(0);}, ::testing::ExitedWithCode(0), "");
841 TEST_F(TDMLayer, LayerUnsetBufferSuccess)
843 SKIP_FLAG(has_layers);
844 tbm_surface_h buffer;
847 for (int i = 0; i < layer_count; ++i) {
848 buffer = UtCreateBufferForLayer(i, 128, 128, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
849 ASSERT_NE(NULL, buffer);
851 error = tdm_layer_set_buffer(tdm_layer_array[i], buffer);
852 ASSERT_EQ(TDM_ERROR_NONE, error);
854 error = tdm_layer_unset_buffer(tdm_layer_array[i]);
855 ASSERT_EQ(TDM_ERROR_NONE, error);
859 /* tdm_layer_commit() */
861 TEST_F(TDMLayer, LayerCommitFailNullAll)
863 SKIP_FLAG(has_layers);
865 ASSERT_EXIT({tdm_error error;
866 error = tdm_layer_commit(NULL, NULL, NULL);
867 if (error == TDM_ERROR_NONE) exit(1);
868 exit(0);}, ::testing::ExitedWithCode(0), "");
871 TEST_F(TDMLayer, LayerCommitFailDpmsOff)
873 SKIP_FLAG(has_layers);
876 for (int i = 0; i < layer_count; ++i) {
877 error = tdm_layer_commit(tdm_layer_array[i], NULL, NULL);
878 ASSERT_NE(TDM_ERROR_NONE, error);
882 TEST_F(TDMLayerCommit, LayerCommitSuccess)
884 SKIP_FLAG(has_layers);
888 for (int i = 0; i < layer_count; ++i) {
889 tbm_surface_h buffer = NULL;
890 tdm_layer_capability layer_capability;
892 int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay;
893 int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay;
895 error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability);
896 ASSERT_EQ(TDM_ERROR_NONE, error);
898 if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) {
903 error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h);
904 ASSERT_EQ(TDM_ERROR_NONE, error);
906 buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
907 ASSERT_NE(NULL, buffer);
909 error = tdm_layer_set_buffer(tdm_layer_array[i], buffer);
910 ASSERT_EQ(TDM_ERROR_NONE, error);
912 error = tdm_layer_commit(tdm_layer_array[i], UtLayerCommitHandler, &data);
913 ASSERT_EQ(TDM_ERROR_NONE, error);
916 UtHandleCommitEvent(layer_count);
918 ASSERT_EQ(layer_count, utLayerCommitHandlerCounter);
919 ASSERT_EQ(layer_count, data);
922 TEST_F(TDMLayerCommitThread, LayerCommitSuccess)
924 SKIP_FLAG(has_layers);
928 for (int i = 0; i < layer_count; ++i) {
929 tbm_surface_h buffer = NULL;
930 tdm_layer_capability layer_capability;
932 int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay;
933 int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay;
935 error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability);
936 ASSERT_EQ(TDM_ERROR_NONE, error);
938 if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) {
943 error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h);
944 ASSERT_EQ(TDM_ERROR_NONE, error);
946 buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
947 ASSERT_NE(NULL, buffer);
949 error = tdm_layer_set_buffer(tdm_layer_array[i], buffer);
950 ASSERT_EQ(TDM_ERROR_NONE, error);
952 error = tdm_layer_commit(tdm_layer_array[i], UtLayerCommitHandler, &data);
953 ASSERT_EQ(TDM_ERROR_NONE, error);
956 UtHandleCommitEvent(layer_count);
958 ASSERT_EQ(layer_count, utLayerCommitHandlerCounter);
959 ASSERT_EQ(layer_count, data);
962 TEST_F(TDMLayerCommit, LayerCommitSuccessOnlyPrimaryLayers)
964 SKIP_FLAG(has_layers);
967 int num_waiting_layers = 0;
969 for (int i = 0; i < layer_count; ++i) {
970 tbm_surface_h buffer = NULL;
971 tdm_layer_capability layer_capability;
973 int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay;
974 int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay;
976 error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability);
977 ASSERT_EQ(TDM_ERROR_NONE, error);
979 if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY))
982 num_waiting_layers++;
984 error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h);
985 ASSERT_EQ(TDM_ERROR_NONE, error);
987 buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
988 ASSERT_NE(NULL, buffer);
990 error = tdm_layer_set_buffer(tdm_layer_array[i], buffer);
991 ASSERT_EQ(TDM_ERROR_NONE, error);
993 error = tdm_layer_commit(tdm_layer_array[i], UtLayerCommitHandler, &data);
994 ASSERT_EQ(TDM_ERROR_NONE, error);
997 UtHandleCommitEvent(num_waiting_layers);
999 ASSERT_EQ(num_waiting_layers, utLayerCommitHandlerCounter);
1000 ASSERT_EQ(num_waiting_layers, data);
1003 TEST_F(TDMLayerCommitThread, LayerCommitSuccessOnlyPrimaryLayers)
1005 SKIP_FLAG(has_layers);
1008 int num_waiting_layers = 0;
1010 for (int i = 0; i < layer_count; ++i) {
1011 tbm_surface_h buffer = NULL;
1012 tdm_layer_capability layer_capability;
1014 int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay;
1015 int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay;
1017 error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability);
1018 ASSERT_EQ(TDM_ERROR_NONE, error);
1020 if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY))
1023 num_waiting_layers++;
1025 error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h);
1026 ASSERT_EQ(TDM_ERROR_NONE, error);
1028 buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
1029 ASSERT_NE(NULL, buffer);
1031 error = tdm_layer_set_buffer(tdm_layer_array[i], buffer);
1032 ASSERT_EQ(TDM_ERROR_NONE, error);
1034 error = tdm_layer_commit(tdm_layer_array[i], UtLayerCommitHandler, &data);
1035 ASSERT_EQ(TDM_ERROR_NONE, error);
1038 UtHandleCommitEvent(num_waiting_layers);
1040 ASSERT_EQ(num_waiting_layers, utLayerCommitHandlerCounter);
1041 ASSERT_EQ(num_waiting_layers, data);
1044 TEST_F(TDMLayerCommitWithDisabledCommitPerVblank, LayerCommitSuccess)
1046 SKIP_FLAG(has_layers);
1050 for (int i = 0; i < layer_count; ++i) {
1051 tbm_surface_h buffer = NULL;
1052 tdm_layer_capability layer_capability;
1054 int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay;
1055 int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay;
1057 error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability);
1058 ASSERT_EQ(TDM_ERROR_NONE, error);
1060 if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) {
1065 error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h);
1066 ASSERT_EQ(TDM_ERROR_NONE, error);
1068 buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
1069 ASSERT_NE(NULL, buffer);
1071 error = tdm_layer_set_buffer(tdm_layer_array[i], buffer);
1072 ASSERT_EQ(TDM_ERROR_NONE, error);
1074 error = tdm_layer_commit(tdm_layer_array[i], UtLayerCommitHandler, &data);
1075 ASSERT_EQ(TDM_ERROR_NONE, error);
1078 UtHandleCommitEvent(layer_count);
1080 ASSERT_EQ(layer_count, utLayerCommitHandlerCounter);
1081 ASSERT_EQ(layer_count, data);
1084 TEST_F(TDMLayerCommitWithDisabledCommitPerVblank, LayerCommitSuccessOnlyPrimaryLayers)
1086 SKIP_FLAG(has_layers);
1089 int num_waiting_layers = 0;
1091 for (int i = 0; i < layer_count; ++i) {
1092 tbm_surface_h buffer = NULL;
1093 tdm_layer_capability layer_capability;
1095 int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay;
1096 int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay;
1098 error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability);
1099 ASSERT_EQ(TDM_ERROR_NONE, error);
1101 if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY))
1104 num_waiting_layers++;
1106 error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h);
1107 ASSERT_EQ(TDM_ERROR_NONE, error);
1109 buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
1110 ASSERT_NE(NULL, buffer);
1112 error = tdm_layer_set_buffer(tdm_layer_array[i], buffer);
1113 ASSERT_EQ(TDM_ERROR_NONE, error);
1115 error = tdm_layer_commit(tdm_layer_array[i], UtLayerCommitHandler, &data);
1116 ASSERT_EQ(TDM_ERROR_NONE, error);
1119 UtHandleCommitEvent(num_waiting_layers);
1121 ASSERT_EQ(num_waiting_layers, utLayerCommitHandlerCounter);
1122 ASSERT_EQ(num_waiting_layers, data);
1125 TEST_F(TDMLayerCommit, LayerCommitSuccessUnsetAfterCommit)
1127 SKIP_FLAG(has_layers);
1131 for (int i = 0; i < layer_count; ++i) {
1132 tbm_surface_h buffer = NULL;
1133 tdm_layer_capability layer_capability;
1135 int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay;
1136 int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay;
1138 error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability);
1139 ASSERT_EQ(TDM_ERROR_NONE, error);
1141 if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) {
1146 error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h);
1147 ASSERT_EQ(TDM_ERROR_NONE, error);
1149 buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
1150 ASSERT_NE(NULL, buffer);
1152 error = tdm_layer_set_buffer(tdm_layer_array[i], buffer);
1153 ASSERT_EQ(TDM_ERROR_NONE, error);
1155 error = tdm_layer_commit(tdm_layer_array[i], UtLayerCommitHandler, &data);
1156 ASSERT_EQ(TDM_ERROR_NONE, error);
1159 for (int i = 0; i < layer_count; ++i) {
1160 error = tdm_layer_unset_buffer(tdm_layer_array[i]);
1161 ASSERT_EQ(TDM_ERROR_NONE, error);
1164 UtHandleCommitEvent(layer_count);
1165 ASSERT_EQ(0, utLayerCommitHandlerCounter);
1169 TEST_F(TDMLayerCommit, LayerCommitSuccessUnsetBeforeCommit_2)
1171 SKIP_FLAG(has_layers);
1175 for (int i = 0; i < layer_count; ++i) {
1176 tbm_surface_h buffer = NULL;
1177 tdm_layer_capability layer_capability;
1179 int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay;
1180 int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay;
1182 error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability);
1183 ASSERT_EQ(TDM_ERROR_NONE, error);
1185 if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) {
1190 error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h);
1191 ASSERT_EQ(TDM_ERROR_NONE, error);
1193 buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
1194 ASSERT_NE(NULL, buffer);
1196 error = tdm_layer_set_buffer(tdm_layer_array[i], buffer);
1197 ASSERT_EQ(TDM_ERROR_NONE, error);
1199 error = tdm_layer_commit(tdm_layer_array[i], UtLayerCommitHandler, &data);
1200 ASSERT_EQ(TDM_ERROR_NONE, error);
1203 UtHandleCommitEvent(layer_count);
1204 ASSERT_EQ(layer_count, utLayerCommitHandlerCounter);
1205 ASSERT_EQ(layer_count, data);
1207 for (int i = 0; i < layer_count; ++i) {
1208 error = tdm_layer_unset_buffer(tdm_layer_array[i]);
1209 ASSERT_EQ(TDM_ERROR_NONE, error);
1213 /* tdm_layer_is_committing() */
1215 TEST_F(TDMLayer, LayerIsCommittingFailNullAll)
1217 SKIP_FLAG(has_layers);
1219 ASSERT_EXIT({tdm_error error;
1220 error = tdm_layer_is_committing(NULL, NULL);
1221 if (error == TDM_ERROR_NONE) exit(1);
1222 exit(0);}, ::testing::ExitedWithCode(0), "");
1225 TEST_F(TDMLayer, LayerIsCommittingFailNullLayer)
1227 SKIP_FLAG(has_layers);
1228 unsigned int committing;
1230 ASSERT_EXIT({tdm_error error;
1231 error = tdm_layer_is_committing(NULL, &committing);
1232 if (error == TDM_ERROR_NONE) exit(1);
1233 exit(0);}, ::testing::ExitedWithCode(0), "");
1236 TEST_F(TDMLayer, LayerIsCommittingFailNullCommitting)
1238 SKIP_FLAG(has_layers);
1240 ASSERT_EXIT({tdm_error error;
1241 error = tdm_layer_is_committing(tdm_layer_array[0], NULL);
1242 if (error == TDM_ERROR_NONE) exit(1);
1243 exit(0);}, ::testing::ExitedWithCode(0), "");
1246 TEST_F(TDMLayer, LayerIsCommittingSuccessWithoutCommit)
1248 SKIP_FLAG(has_layers);
1250 unsigned int committing;
1252 for (int i = 0; i < layer_count; ++i) {
1253 error = tdm_layer_is_committing(tdm_layer_array[0], &committing);
1254 ASSERT_EQ(TDM_ERROR_NONE, error);
1256 ASSERT_EQ(0, committing);
1260 TEST_F(TDMLayerCommit, LayerIsCommittingSuccess)
1262 SKIP_FLAG(has_layers);
1264 unsigned int committing;
1266 for (int i = 0; i < layer_count; ++i) {
1267 tbm_surface_h buffer = NULL;
1268 tdm_layer_capability layer_capability;
1270 int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay;
1271 int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay;
1273 error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability);
1274 ASSERT_EQ(TDM_ERROR_NONE, error);
1276 if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) {
1281 error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h);
1282 ASSERT_EQ(TDM_ERROR_NONE, error);
1284 buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
1285 ASSERT_NE(NULL, buffer);
1287 error = tdm_layer_set_buffer(tdm_layer_array[i], buffer);
1288 ASSERT_EQ(TDM_ERROR_NONE, error);
1290 error = tdm_layer_commit(tdm_layer_array[i], NULL, NULL);
1291 ASSERT_EQ(TDM_ERROR_NONE, error);
1293 error = tdm_layer_is_committing(tdm_layer_array[0], &committing);
1294 ASSERT_EQ(TDM_ERROR_NONE, error);
1296 ASSERT_EQ(1, committing);
1300 /* tdm_layer_remove_commit_handler() */
1302 TEST_F(TDMLayer, LayerRemoveCommitHandlerFailNullAll)
1304 SKIP_FLAG(has_layers);
1306 ASSERT_EXIT({tdm_error error;
1307 error = tdm_layer_remove_commit_handler(NULL, NULL, NULL);
1308 if (error == TDM_ERROR_NONE) exit(1);
1309 exit(0);}, ::testing::ExitedWithCode(0), "");
1312 TEST_F(TDMLayerCommit, LayerRemoveCommitHandlerSuccess)
1314 SKIP_FLAG(has_layers);
1318 for (int i = 0; i < layer_count; ++i) {
1319 tbm_surface_h buffer = NULL;
1320 tdm_layer_capability layer_capability;
1322 int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay;
1323 int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay;
1325 error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability);
1326 ASSERT_EQ(TDM_ERROR_NONE, error);
1328 if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) {
1333 error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h);
1334 ASSERT_EQ(TDM_ERROR_NONE, error);
1336 buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
1337 ASSERT_NE(NULL, buffer);
1339 error = tdm_layer_set_buffer(tdm_layer_array[i], buffer);
1340 ASSERT_EQ(TDM_ERROR_NONE, error);
1342 error = tdm_layer_commit(tdm_layer_array[i], UtLayerCommitHandler, &data);
1343 ASSERT_EQ(TDM_ERROR_NONE, error);
1345 error = tdm_layer_remove_commit_handler(tdm_layer_array[i], UtLayerCommitHandler, &data);
1346 ASSERT_EQ(TDM_ERROR_NONE, error);
1349 UtHandleCommitEvent(layer_count);
1350 ASSERT_EQ(0, utLayerCommitHandlerCounter);
1354 /* tdm_layer_get_displaying_buffer() */
1356 TEST_F(TDMLayerCommit, LayerGetDisplayingBufferFailNullAll)
1358 SKIP_FLAG(has_layers);
1360 ASSERT_EXIT({if (tdm_layer_get_displaying_buffer(NULL, NULL) != NULL) exit(1);
1361 exit(0);}, ::testing::ExitedWithCode(0), "");
1364 TEST_F(TDMLayerCommit, LayerGetDisplayingBufferFailWithoutCommit)
1366 SKIP_FLAG(has_layers);
1369 for (int i = 0; i < layer_count; ++i) {
1370 ASSERT_EQ(NULL, tdm_layer_get_displaying_buffer(tdm_layer_array[i], &error));
1371 ASSERT_NE(TDM_ERROR_NONE, error);
1375 TEST_F(TDMLayerCommit, LayerGetDisplayingBufferSuccess)
1377 SKIP_FLAG(has_layers);
1381 for (int i = 0; i < layer_count; ++i) {
1382 tbm_surface_h buffer = NULL;
1383 tdm_layer_capability layer_capability;
1385 int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay;
1386 int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay;
1388 error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability);
1389 ASSERT_EQ(TDM_ERROR_NONE, error);
1391 if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) {
1396 error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h);
1397 ASSERT_EQ(TDM_ERROR_NONE, error);
1399 buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
1400 ASSERT_NE(NULL, buffer);
1402 error = tdm_layer_set_buffer(tdm_layer_array[i], buffer);
1403 ASSERT_EQ(TDM_ERROR_NONE, error);
1405 error = tdm_layer_commit(tdm_layer_array[i], UtLayerCommitHandler, &data);
1406 ASSERT_EQ(TDM_ERROR_NONE, error);
1409 UtHandleCommitEvent(layer_count);
1410 ASSERT_EQ(layer_count, utLayerCommitHandlerCounter);
1411 ASSERT_EQ(layer_count, data);
1413 for (int i = 0; i < layer_count; ++i) {
1414 ASSERT_EQ(tdm_layers_buffer_array[i], tdm_layer_get_displaying_buffer(tdm_layer_array[i], &error));
1415 ASSERT_EQ(TDM_ERROR_NONE, error);
1419 /* tdm_layer_is_usable() */
1421 TEST_F(TDMLayer, LayerIsUsableFailNullAll)
1423 SKIP_FLAG(has_layers);
1425 ASSERT_EXIT({if (tdm_layer_is_usable(NULL, NULL) == TDM_ERROR_NONE) exit(1);
1426 exit(0);}, ::testing::ExitedWithCode(0), "");
1429 TEST_F(TDMLayer, LayerIsUsableFailNullLayer)
1431 SKIP_FLAG(has_layers);
1432 unsigned int usable;
1434 ASSERT_EXIT({if (tdm_layer_is_usable(NULL, &usable) == TDM_ERROR_NONE) exit(1);
1435 exit(0);}, ::testing::ExitedWithCode(0), "");
1438 TEST_F(TDMLayer, LayerIsUsableFailNullUsable)
1440 SKIP_FLAG(has_layers);
1442 ASSERT_EXIT({if (tdm_layer_is_usable(tdm_layer_array[0], NULL) == TDM_ERROR_NONE) exit(1);
1443 exit(0);}, ::testing::ExitedWithCode(0), "");
1446 TEST_F(TDMLayer, LayerIsUsableSuccessAllUsable)
1448 SKIP_FLAG(has_layers);
1449 unsigned int usable;
1452 for (int i = 0; i < layer_count; ++i) {
1453 error = tdm_layer_is_usable(tdm_layer_array[i], &usable);
1454 ASSERT_EQ(TDM_ERROR_NONE, error);
1455 ASSERT_NE(0, usable);
1459 TEST_F(TDMLayer, LayerIsUsableSuccessAllUsable_2)
1461 SKIP_FLAG(has_layers);
1462 unsigned int usable;
1465 for (int i = 0; i < layer_count; ++i) {
1466 tbm_surface_h buffer;
1468 int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay;
1469 int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay;
1471 buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
1472 ASSERT_NE(NULL, buffer);
1474 error = tdm_layer_set_buffer(tdm_layer_array[i], buffer);
1475 ASSERT_EQ(TDM_ERROR_NONE, error);
1477 error = tdm_layer_unset_buffer(tdm_layer_array[i]);
1478 ASSERT_EQ(TDM_ERROR_NONE, error);
1480 error = tdm_layer_is_usable(tdm_layer_array[i], &usable);
1481 ASSERT_EQ(TDM_ERROR_NONE, error);
1482 ASSERT_NE(0, usable);
1486 TEST_F(TDMLayer, LayerIsUsableSuccessAllNoUsable)
1488 SKIP_FLAG(has_layers);
1489 unsigned int usable;
1492 for (int i = 0; i < layer_count; ++i) {
1493 tbm_surface_h buffer;
1495 int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay;
1496 int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay;
1498 buffer = UtCreateBufferForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
1499 ASSERT_NE(NULL, buffer);
1501 error = tdm_layer_set_buffer(tdm_layer_array[i], buffer);
1502 ASSERT_EQ(TDM_ERROR_NONE, error);
1504 error = tdm_layer_is_usable(tdm_layer_array[i], &usable);
1505 ASSERT_EQ(TDM_ERROR_NONE, error);
1506 ASSERT_EQ(0, usable);
1510 /* tdm_layer_set_video_pos() */
1512 TEST_F(TDMLayer, LayerSetVideoPosFailNullAll)
1514 SKIP_FLAG(has_layers);
1516 ASSERT_EXIT({if (tdm_layer_set_video_pos(NULL, -1) == TDM_ERROR_NONE) exit(1);
1517 exit(0);}, ::testing::ExitedWithCode(0), "");
1520 TEST_F(TDMLayer, LayerSetVideoPosFailNoVideoLayers)
1522 SKIP_FLAG(has_layers);
1524 tdm_layer_capability layer_capability;
1526 for (int i = 0; i < layer_count; ++i) {
1527 error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability);
1528 ASSERT_EQ(TDM_ERROR_NONE, error);
1530 if (layer_capability & TDM_LAYER_CAPABILITY_VIDEO)
1533 error = tdm_layer_set_video_pos(tdm_layer_array[i], -1);
1534 ASSERT_NE(TDM_ERROR_NONE, error);
1538 TEST_F(TDMLayer, LayerSetVideoPosSuccess)
1540 SKIP_FLAG(has_layers);
1542 tdm_layer_capability layer_capability;
1544 for (int i = 0; i < layer_count; ++i) {
1545 error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability);
1546 ASSERT_EQ(TDM_ERROR_NONE, error);
1548 if (!(layer_capability & TDM_LAYER_CAPABILITY_VIDEO))
1551 error = tdm_layer_set_video_pos(tdm_layer_array[i], -1);
1552 ASSERT_EQ(TDM_ERROR_NONE, error);
1556 /* tdm_layer_create_capture() */
1558 TEST_F(TDMLayer, LayerCreateCaptureNullAll)
1560 SKIP_FLAG(has_layers);
1562 ASSERT_EXIT({if (tdm_layer_create_capture(NULL, NULL) != NULL) exit(1);
1563 exit(0);}, ::testing::ExitedWithCode(0), "");
1566 TEST_F(TDMLayer, LayerCreateCaptureSuccess)
1568 SKIP_FLAG(has_layers);
1570 tdm_capture *capture;
1572 for (int i = 0; i < layer_count; ++i) {
1573 capture = tdm_layer_create_capture(tdm_layer_array[i], &error);
1574 if (error == TDM_ERROR_NO_CAPABILITY)
1577 ASSERT_EQ(TDM_ERROR_NONE, error);
1578 ASSERT_NE(NULL, capture);
1582 /* tdm_layer_get_buffer_flags() */
1584 TEST_F(TDMLayer, LayerGetBufferFlagsNullAll)
1586 SKIP_FLAG(has_layers);
1588 ASSERT_EXIT({if (tdm_layer_get_buffer_flags(NULL, NULL) == TDM_ERROR_NONE) exit(1);
1589 exit(0);}, ::testing::ExitedWithCode(0), "");
1592 TEST_F(TDMLayer, LayerGetBufferFlagsNullLayer)
1594 SKIP_FLAG(has_layers);
1597 ASSERT_EXIT({if (tdm_layer_get_buffer_flags(NULL, &flags) == TDM_ERROR_NONE) exit(1);
1598 exit(0);}, ::testing::ExitedWithCode(0), "");
1601 TEST_F(TDMLayer, LayerGetBufferFlagsNullFlags)
1603 SKIP_FLAG(has_layers);
1605 ASSERT_EXIT({if (tdm_layer_get_buffer_flags(tdm_layer_array[0], NULL) == TDM_ERROR_NONE) exit(1);
1606 exit(0);}, ::testing::ExitedWithCode(0), "");
1609 TEST_F(TDMLayer, LayerGetBufferFlagsSuccess)
1611 SKIP_FLAG(has_layers);
1615 for (int i = 0; i < layer_count; ++i) {
1616 error = tdm_layer_get_buffer_flags(tdm_layer_array[i], &flags);
1617 if (error == TDM_ERROR_NOT_IMPLEMENTED)
1620 ASSERT_EQ(TDM_ERROR_NONE, error);
1624 /* tdm_layer_set_buffer_queue() */
1626 TEST_F(TDMLayer, LayerSetBufferQueueFailNullAll)
1628 SKIP_FLAG(has_layers);
1630 ASSERT_EXIT({if (tdm_layer_set_buffer_queue(NULL, NULL) == TDM_ERROR_NONE) exit(1);
1631 exit(0);}, ::testing::ExitedWithCode(0), "");
1634 TEST_F(TDMLayer, LayerSetBufferQueueFailNullLayer)
1636 SKIP_FLAG(has_layers);
1637 tbm_surface_queue_h bufer_queue;
1639 bufer_queue = UtCreateBufferQueueForLayer(0, 128, 128, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
1640 ASSERT_NE(NULL, bufer_queue);
1642 ASSERT_EXIT({if (tdm_layer_set_buffer_queue(NULL, bufer_queue) == TDM_ERROR_NONE) exit(1);
1643 exit(0);}, ::testing::ExitedWithCode(0), "");
1646 TEST_F(TDMLayer, LayerSetBufferQueueFailNullBufferQueue)
1648 SKIP_FLAG(has_layers);
1650 ASSERT_EXIT({if (tdm_layer_set_buffer_queue(tdm_layer_array[0], NULL) == TDM_ERROR_NONE) exit(1);
1651 exit(0);}, ::testing::ExitedWithCode(0), "");
1654 TEST_F(TDMLayer, LayerSetBufferQueueSuccess)
1656 SKIP_FLAG(has_layers);
1658 tbm_surface_queue_h buffer_queue;
1659 tdm_layer_capability layer_capability;
1661 for (int i = 0; i < layer_count; ++i) {
1662 int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay;
1663 int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay;
1665 error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability);
1666 ASSERT_EQ(TDM_ERROR_NONE, error);
1668 if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) {
1673 buffer_queue = UtCreateBufferQueueForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
1674 ASSERT_NE(NULL, buffer_queue);
1676 error = tdm_layer_set_buffer_queue(tdm_layer_array[i], buffer_queue);
1677 ASSERT_EQ(TDM_ERROR_NONE, error);
1681 TEST_F(TDMLayer, LayerSetBufferQueueSuccessTwice)
1683 SKIP_FLAG(has_layers);
1685 tbm_surface_queue_h buffer_queue;
1686 tdm_layer_capability layer_capability;
1688 for (int i = 0; i < layer_count; ++i) {
1689 int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay;
1690 int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay;
1692 error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability);
1693 ASSERT_EQ(TDM_ERROR_NONE, error);
1695 if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) {
1700 buffer_queue = UtCreateBufferQueueForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
1701 ASSERT_NE(NULL, buffer_queue);
1703 error = tdm_layer_set_buffer_queue(tdm_layer_array[i], buffer_queue);
1704 ASSERT_EQ(TDM_ERROR_NONE, error);
1706 error = tdm_layer_set_buffer_queue(tdm_layer_array[i], buffer_queue);
1707 ASSERT_EQ(TDM_ERROR_NONE, error);
1711 TEST_F(TDMLayerCommitThread, LayerSetBufferQueueSuccessRemoveBufferQueue)
1713 SKIP_FLAG(has_layers);
1715 tbm_surface_queue_error_e tbm_err;
1716 tbm_surface_queue_h buffer_queue;
1717 tdm_layer_capability layer_capability;
1719 for (int i = 0; i < layer_count; ++i) {
1720 tbm_surface_h surface;
1722 int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay;
1723 int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay;
1725 error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability);
1726 ASSERT_EQ(TDM_ERROR_NONE, error);
1728 if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) {
1733 error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h);
1734 ASSERT_EQ(TDM_ERROR_NONE, error);
1736 buffer_queue = UtCreateBufferQueueForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
1737 ASSERT_NE(NULL, buffer_queue);
1739 error = tdm_layer_set_buffer_queue(tdm_layer_array[i], buffer_queue);
1740 ASSERT_EQ(TDM_ERROR_NONE, error);
1742 tbm_err = tbm_surface_queue_dequeue(buffer_queue, &surface);
1743 ASSERT_EQ(TBM_SURFACE_QUEUE_ERROR_NONE, tbm_err);
1745 tdm_layer_commit(tdm_layer_array[i], NULL, NULL);
1747 tbm_err = tbm_surface_queue_enqueue(buffer_queue, surface);
1748 ASSERT_EQ(TBM_SURFACE_QUEUE_ERROR_NONE, tbm_err);
1751 /* FIXME: use another func. */
1752 UtHandleCommitEvent(1);
1754 for (int i = 0; i < layer_count; ++i) {
1755 ASSERT_NE(NULL, tdm_layer_get_displaying_buffer(tdm_layer_array[i], &error));
1756 ASSERT_EQ(TDM_ERROR_NONE, error);
1758 tbm_surface_queue_destroy(tdm_layers_buffer_queue_array[i]);
1759 tdm_layers_buffer_queue_array[i] = NULL;
1761 ASSERT_EQ(NULL, tdm_layer_get_displaying_buffer(tdm_layer_array[i], &error));
1762 ASSERT_NE(TDM_ERROR_NONE, error);
1766 TEST_F(TDMLayerCommitWithDisabledCommitPerVblank, LayerSetBufferQueueSuccessRemoveBufferQueue)
1768 SKIP_FLAG(has_layers);
1770 tbm_surface_queue_error_e tbm_err;
1771 tbm_surface_queue_h buffer_queue;
1772 tdm_layer_capability layer_capability;
1774 for (int i = 0; i < layer_count; ++i) {
1775 tbm_surface_h surface;
1777 int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay;
1778 int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay;
1780 error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability);
1781 ASSERT_EQ(TDM_ERROR_NONE, error);
1783 if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) {
1788 error = _ut_tdm_layer_set_info(tdm_layer_array[i], w, h);
1789 ASSERT_EQ(TDM_ERROR_NONE, error);
1791 buffer_queue = UtCreateBufferQueueForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
1792 ASSERT_NE(NULL, buffer_queue);
1794 error = tdm_layer_set_buffer_queue(tdm_layer_array[i], buffer_queue);
1795 ASSERT_EQ(TDM_ERROR_NONE, error);
1797 tbm_err = tbm_surface_queue_dequeue(buffer_queue, &surface);
1798 ASSERT_EQ(TBM_SURFACE_QUEUE_ERROR_NONE, tbm_err);
1800 tdm_layer_commit(tdm_layer_array[i], NULL, NULL);
1802 tbm_err = tbm_surface_queue_enqueue(buffer_queue, surface);
1803 ASSERT_EQ(TBM_SURFACE_QUEUE_ERROR_NONE, tbm_err);
1806 /* FIXME: use another func. */
1807 UtHandleCommitEvent(1);
1809 for (int i = 0; i < layer_count; ++i) {
1810 tbm_surface_h surface;
1812 tbm_err = tbm_surface_queue_dequeue(tdm_layers_buffer_queue_array[i], &surface);
1813 ASSERT_EQ(TBM_SURFACE_QUEUE_ERROR_NONE, error);
1815 tbm_err = tbm_surface_queue_enqueue(tdm_layers_buffer_queue_array[i], surface);
1816 ASSERT_EQ(TBM_SURFACE_QUEUE_ERROR_NONE, error);
1818 error = tdm_layer_unset_buffer_queue(tdm_layer_array[i]);
1819 ASSERT_EQ(TDM_ERROR_NONE, error);
1822 /* FIXME: use another func. */
1823 UtHandleCommitEvent(1);
1825 for (int i = 0; i < layer_count; ++i) {
1826 ASSERT_EQ(NULL, tdm_layer_get_displaying_buffer(tdm_layer_array[i], &error));
1827 ASSERT_NE(TDM_ERROR_NONE, error);
1831 /* tdm_layer_unset_buffer_queue() */
1833 TEST_F(TDMLayer, LayerUnsetBufferQueueFailNullAll)
1835 SKIP_FLAG(has_layers);
1837 ASSERT_EXIT({if (tdm_layer_unset_buffer_queue(NULL) == TDM_ERROR_NONE) exit(1);
1838 exit(0);}, ::testing::ExitedWithCode(0), "");
1841 TEST_F(TDMLayer, LayerUnsetBufferQueueSuccess)
1843 SKIP_FLAG(has_layers);
1845 tbm_surface_queue_h buffer_queue;
1846 tdm_layer_capability layer_capability;
1848 for (int i = 0; i < layer_count; ++i) {
1849 int w = preferred_mode_array[tdm_layer_output_idx[i]]->hdisplay;
1850 int h = preferred_mode_array[tdm_layer_output_idx[i]]->vdisplay;
1852 error = tdm_layer_get_capabilities(tdm_layer_array[i], &layer_capability);
1853 ASSERT_EQ(TDM_ERROR_NONE, error);
1855 if (!(layer_capability & TDM_LAYER_CAPABILITY_PRIMARY)) {
1860 buffer_queue = UtCreateBufferQueueForLayer(i, w, h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT);
1861 ASSERT_NE(NULL, buffer_queue);
1863 error = tdm_layer_set_buffer_queue(tdm_layer_array[i], buffer_queue);
1864 ASSERT_EQ(TDM_ERROR_NONE, error);
1866 error = tdm_layer_unset_buffer_queue(tdm_layer_array[i]);
1867 ASSERT_EQ(TDM_ERROR_NONE, error);