From 6c80f26553de39cde3962f18c418e665a48740e5 Mon Sep 17 00:00:00 2001 From: Junkyeong Kim Date: Tue, 16 Oct 2018 21:30:48 +0900 Subject: [PATCH] client: add tdm_client_output_get_mode function Change-Id: Ie21b4f8f3179624339bf97e5dce7727b36c5d6bb Signed-off-by: Junkyeong Kim --- client/tdm_client.c | 45 ++++++++++++++++++++++++++++++++++++++++++ client/tdm_client.h | 10 ++++++++++ haltests/src/tc_tdm_client.cpp | 31 +++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) diff --git a/client/tdm_client.c b/client/tdm_client.c index 972ae00..57f8ce3 100644 --- a/client/tdm_client.c +++ b/client/tdm_client.c @@ -1061,6 +1061,51 @@ tdm_client_output_get_refresh_rate(tdm_client_output *output, unsigned int *refr } tdm_error +tdm_client_output_get_mode(tdm_client_output *output, unsigned int *width, unsigned int *height) +{ + tdm_private_client_output *private_output; + tdm_private_client *private_client; + + TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER); + TDM_RETURN_VAL_IF_FAIL(width != NULL, TDM_ERROR_INVALID_PARAMETER); + TDM_RETURN_VAL_IF_FAIL(height != NULL, TDM_ERROR_INVALID_PARAMETER); + + private_output = (tdm_private_client_output*)output; + private_client = private_output->private_client; + + pthread_mutex_lock(&private_client->lock); + + if (private_output->watch_output_changes) { + *width = private_output->width; + *height = private_output->height; + pthread_mutex_unlock(&private_client->lock); + return TDM_ERROR_NONE; + } + + if (CHECK_WL_PROTOCOL_ERROR(private_client)) { + pthread_mutex_unlock(&private_client->lock); + return TDM_ERROR_PROTOCOL_ERROR; + } + + wl_proxy_set_queue((struct wl_proxy *)private_output->output, private_client->queue); + wl_tdm_output_get_mode(private_output->output); + wl_display_roundtrip_queue(private_client->display, private_client->queue); + wl_proxy_set_queue((struct wl_proxy *)private_output->output, NULL); + + if (CHECK_WL_PROTOCOL_ERROR(private_client)) { + pthread_mutex_unlock(&private_client->lock); + return TDM_ERROR_PROTOCOL_ERROR; + } + + *width = private_output->width; + *height = private_output->height; + + pthread_mutex_unlock(&private_client->lock); + + return TDM_ERROR_NONE; +} + +tdm_error tdm_client_output_get_conn_status(tdm_client_output *output, tdm_output_conn_status *status) { tdm_private_client_output *private_output; diff --git a/client/tdm_client.h b/client/tdm_client.h index 17d63cf..f8b2dec 100644 --- a/client/tdm_client.h +++ b/client/tdm_client.h @@ -219,6 +219,16 @@ tdm_error tdm_client_output_get_refresh_rate(tdm_client_output *output, unsigned int *refresh); /** + * @brief Get the width and height of the given client output mode + * @param[in] output The client output object + * @param[out] width The width of output mode + * @param[out] height The height of output mode + * @return #TDM_ERROR_NONE if success. Otherwise, error value. + */ +tdm_error +tdm_client_output_get_mode(tdm_client_output *output, unsigned int *width, unsigned int *height); + +/** * @brief Get the connection status of the given client output * @param[in] output The client output object * @param[out] status The connection status diff --git a/haltests/src/tc_tdm_client.cpp b/haltests/src/tc_tdm_client.cpp index 0d54855..504aaee 100644 --- a/haltests/src/tc_tdm_client.cpp +++ b/haltests/src/tc_tdm_client.cpp @@ -746,6 +746,37 @@ TEST_P(TDMClient, ClientOutputGetRefreshRateNullOther) ASSERT_EQ(tdm_client_output_get_refresh_rate(output, NULL), TDM_ERROR_INVALID_PARAMETER); } +/* tdm_client_output_get_mode */ +TEST_P(TDMClient, ClientOutputGetMode) +{ + unsigned int width = 0, height = 0; + + ASSERT_EQ(PrepareClient(), true); + ASSERT_EQ(PrepareOutput(), true); + + ASSERT_EQ(tdm_client_output_get_mode(output, &width, &height), TDM_ERROR_NONE); + ASSERT_GT(width, 0); + ASSERT_GT(height, 0); +} + +TEST_P(TDMClient, ClientOutputGetModeNullObject) +{ + unsigned int width = (unsigned int)TDM_UT_INVALID_VALUE; + unsigned int height = (unsigned int)TDM_UT_INVALID_VALUE; + + ASSERT_EQ(tdm_client_output_get_mode(NULL, &width, &height), TDM_ERROR_INVALID_PARAMETER); + ASSERT_EQ(width, (unsigned int)TDM_UT_INVALID_VALUE); + ASSERT_EQ(height, (unsigned int)TDM_UT_INVALID_VALUE); +} + +TEST_P(TDMClient, ClientOutputGetModeNullOther) +{ + ASSERT_EQ(PrepareClient(), true); + ASSERT_EQ(PrepareOutput(), true); + + ASSERT_EQ(tdm_client_output_get_mode(output, NULL, NULL), TDM_ERROR_INVALID_PARAMETER); +} + /* tdm_client_output_get_conn_status */ TEST_P(TDMClient, ClientOutputGetConnStatus) { -- 2.7.4