Allow output name "primary" in tdm_client_wait_vblank
[platform/core/uifw/libtdm.git] / src / tdm_server.c
index 41538ef..1233deb 100644 (file)
@@ -1,36 +1,36 @@
 /**************************************************************************
-
-libtdm
-
-Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
-
-Contact: Eunchul Kim <chulspro.kim@samsung.com>,
-         JinYoung Jeon <jy0.jeon@samsung.com>,
-         Taeheon Kim <th908.kim@samsung.com>,
-         YoungJun Cho <yj44.cho@samsung.com>,
-         SooChan Lim <sc1.lim@samsung.com>,
-         Boram Park <sc1.lim@samsung.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sub license, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice (including the
-next paragraph) shall be included in all copies or substantial portions
-of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
+ *
+ * libtdm
+ *
+ * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
*          JinYoung Jeon <jy0.jeon@samsung.com>,
*          Taeheon Kim <th908.kim@samsung.com>,
*          YoungJun Cho <yj44.cho@samsung.com>,
*          SooChan Lim <sc1.lim@samsung.com>,
*          Boram Park <sc1.lim@samsung.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
 **************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -85,7 +85,7 @@ static int tdm_debug_server;
 
 static void
 _tdm_server_send_done(tdm_server_vblank_info *vblank_info, unsigned int sequence,
-                      unsigned int tv_sec, unsigned int tv_usec);
+                                         unsigned int tv_sec, unsigned int tv_usec);
 
 static tdm_error
 _tdm_server_cb_timer(void *user_data)
@@ -93,8 +93,8 @@ _tdm_server_cb_timer(void *user_data)
        tdm_server_vblank_info *vblank_info = (tdm_server_vblank_info*)user_data;
 
        _tdm_server_send_done(vblank_info, 0,
-                             vblank_info->timer_target_sec,
-                             vblank_info->timer_target_usec);
+                                                 vblank_info->timer_target_sec,
+                                                 vblank_info->timer_target_usec);
 
        return TDM_ERROR_NONE;
 }
@@ -106,7 +106,7 @@ _tdm_server_update_timer(tdm_server_vblank_info *vblank_info, int interval)
        tdm_private_server *private_server = client_info->private_server;
        tdm_private_loop *private_loop = private_server->private_loop;
        unsigned long last, prev_req, req, curr, next;
-       int ms_delay;
+       unsigned int ms_delay;
        tdm_error ret;
 
        ret = tdm_display_lock(private_loop->dpy);
@@ -115,9 +115,9 @@ _tdm_server_update_timer(tdm_server_vblank_info *vblank_info, int interval)
        if (!vblank_info->timer_source) {
                vblank_info->timer_source =
                        tdm_event_loop_add_timer_handler(private_loop->dpy,
-                                                        _tdm_server_cb_timer,
-                                                        vblank_info,
-                                                        NULL);
+                                                                                        _tdm_server_cb_timer,
+                                                                                        vblank_info,
+                                                                                        NULL);
                if (!vblank_info->timer_source) {
                        TDM_ERR("couldn't add timer");
                        tdm_display_unlock(private_loop->dpy);
@@ -136,9 +136,9 @@ _tdm_server_update_timer(tdm_server_vblank_info *vblank_info, int interval)
                next += (unsigned long)client_info->vblank_gap;
 
        TDM_DBG("last(%.6lu) req(%.6lu) curr(%.6lu) prev_req(%.6lu) next(%.6lu)",
-               last, req, curr, prev_req, next);
+                       last, req, curr, prev_req, next);
 
-       ms_delay = (int)ceil((double)(next - curr) / 1000);
+       ms_delay = (unsigned int)ceil((double)(next - curr) / 1000);
        if (ms_delay == 0)
                ms_delay = 1;
 
@@ -165,7 +165,7 @@ _tdm_server_update_timer(tdm_server_vblank_info *vblank_info, int interval)
 
 static void
 _tdm_server_send_done(tdm_server_vblank_info *vblank_info, unsigned int sequence,
-                      unsigned int tv_sec, unsigned int tv_usec)
+                                         unsigned int tv_sec, unsigned int tv_usec)
 {
        tdm_server_vblank_info *found;
        tdm_server_client_info *client_info;
@@ -176,7 +176,7 @@ _tdm_server_send_done(tdm_server_vblank_info *vblank_info, unsigned int sequence
                return;
 
        LIST_FIND_ITEM(vblank_info, &keep_private_server->vblank_list,
-                      tdm_server_vblank_info, link, found);
+                                  tdm_server_vblank_info, link, found);
        if (!found) {
                TDM_DBG("vblank_info(%p) is destroyed", vblank_info);
                return;
@@ -187,7 +187,7 @@ _tdm_server_send_done(tdm_server_vblank_info *vblank_info, unsigned int sequence
        client_info->last_tv_usec = tv_usec;
 
        TDM_DBG("wl_tdm_vblank@%d done. tv(%lu) curr(%lu)",
-               wl_resource_get_id(vblank_info->resource), vtime, curr);
+                       wl_resource_get_id(vblank_info->resource), vtime, curr);
 
        if (tdm_debug_server) {
                if (curr - vtime > 1000) /* 1ms */
@@ -200,8 +200,8 @@ _tdm_server_send_done(tdm_server_vblank_info *vblank_info, unsigned int sequence
 
 static void
 _tdm_server_cb_output_vblank(tdm_output *output, unsigned int sequence,
-                             unsigned int tv_sec, unsigned int tv_usec,
-                             void *user_data)
+                                                        unsigned int tv_sec, unsigned int tv_usec,
+                                                        void *user_data)
 {
        tdm_server_vblank_info *vblank_info = (tdm_server_vblank_info*)user_data;
 
@@ -233,10 +233,10 @@ _tdm_server_client_cb_destroy(struct wl_client *client, struct wl_resource *reso
 
 static void
 _tdm_server_client_cb_wait_vblank(struct wl_client *client,
-                                  struct wl_resource *resource,
-                                  uint32_t id, const char *name,
-                                  int32_t sw_timer, int32_t interval,
-                                  uint32_t req_sec, uint32_t req_usec)
+                                                                 struct wl_resource *resource,
+                                                                 uint32_t id, const char *name,
+                                                                 int32_t sw_timer, int32_t interval,
+                                                                 uint32_t req_sec, uint32_t req_usec)
 {
        tdm_server_client_info *client_info = wl_resource_get_user_data(resource);
        tdm_private_server *private_server = client_info->private_server;
@@ -264,13 +264,16 @@ _tdm_server_client_cb_wait_vblank(struct wl_client *client,
                        found = client_info->vblank_output;
        }
 
+       if (!strncmp(name, "primary", TDM_NAME_LEN))
+               found = tdm_display_get_output(private_loop->dpy, 0, NULL);
+
        if (!found) {
                int count = 0, i;
 
                tdm_display_get_output_count(private_loop->dpy, &count);
 
                for (i = 0; i < count; i++) {
-                       tdm_output *output= tdm_display_get_output(private_loop->dpy, i, NULL);
+                       tdm_output *output = tdm_display_get_output(private_loop->dpy, i, NULL);
                        tdm_output_conn_status status;
 
                        ret = tdm_output_get_conn_status(output, &status);
@@ -292,7 +295,7 @@ _tdm_server_client_cb_wait_vblank(struct wl_client *client,
 
        if (!found) {
                wl_resource_post_error(resource, WL_TDM_CLIENT_ERROR_INVALID_NAME,
-                                      "There is no '%s' output", name);
+                                                          "There is no '%s' output", name);
                TDM_ERR("There is no '%s' output", name);
                return;
        }
@@ -305,7 +308,7 @@ _tdm_server_client_cb_wait_vblank(struct wl_client *client,
                tdm_output_get_mode(client_info->vblank_output, &mode);
                if (!mode || mode->vrefresh <= 0) {
                        wl_resource_post_error(resource, WL_TDM_CLIENT_ERROR_OPERATION_FAILED,
-                                              "couldn't get mode of %s", name);
+                                                                  "couldn't get mode of %s", name);
                        TDM_ERR("couldn't get mode of %s", name);
                        return;
                }
@@ -318,12 +321,12 @@ _tdm_server_client_cb_wait_vblank(struct wl_client *client,
 
        if (dpms_value != TDM_OUTPUT_DPMS_ON && !sw_timer) {
                wl_resource_post_error(resource, WL_TDM_CLIENT_ERROR_DPMS_OFF,
-                                      "dpms '%s'", tdm_get_dpms_str(dpms_value));
+                                                          "dpms '%s'", tdm_get_dpms_str(dpms_value));
                TDM_ERR("dpms '%s'", tdm_get_dpms_str(dpms_value));
                return;
        }
 
-       vblank_info = calloc(1, sizeof *vblank_info);
+       vblank_info = calloc(1, sizeof * vblank_info);
        if (!vblank_info) {
                wl_resource_post_no_memory(resource);
                TDM_ERR("alloc failed");
@@ -334,7 +337,7 @@ _tdm_server_client_cb_wait_vblank(struct wl_client *client,
 
        vblank_resource =
                wl_resource_create(client, &wl_tdm_vblank_interface,
-                                  wl_resource_get_version(resource), id);
+                                                  wl_resource_get_version(resource), id);
        if (!vblank_resource) {
                wl_resource_post_no_memory(resource);
                TDM_ERR("wl_resource_create failed");
@@ -348,10 +351,10 @@ _tdm_server_client_cb_wait_vblank(struct wl_client *client,
 
        if (dpms_value == TDM_OUTPUT_DPMS_ON) {
                ret = tdm_output_wait_vblank(found, interval, 0,
-                                            _tdm_server_cb_output_vblank, vblank_info);
+                                                                        _tdm_server_cb_output_vblank, vblank_info);
                if (ret != TDM_ERROR_NONE) {
                        wl_resource_post_error(resource, WL_TDM_CLIENT_ERROR_OPERATION_FAILED,
-                                              "couldn't wait vblank for %s", name);
+                                                                  "couldn't wait vblank for %s", name);
                        TDM_ERR("couldn't wait vblank for %s", name);
                        goto destroy_resource;
                }
@@ -359,19 +362,19 @@ _tdm_server_client_cb_wait_vblank(struct wl_client *client,
                ret = _tdm_server_update_timer(vblank_info, interval);
                if (ret != TDM_ERROR_NONE) {
                        wl_resource_post_error(resource, WL_TDM_CLIENT_ERROR_OPERATION_FAILED,
-                                              "couldn't update timer for %s", name);
+                                                                  "couldn't update timer for %s", name);
                        TDM_ERR("couldn't update timer for %s", name);
                        goto destroy_resource;
                }
        } else {
                wl_resource_post_error(resource, WL_TDM_CLIENT_ERROR_OPERATION_FAILED,
-                                      "bad implementation");
+                                                          "bad implementation");
                TDM_NEVER_GET_HERE();
                goto destroy_resource;
        }
 
        wl_resource_set_implementation(vblank_resource, NULL, vblank_info,
-                                      destroy_vblank_callback);
+                                                                  destroy_vblank_callback);
 
        LIST_ADDTAIL(&vblank_info->link, &private_server->vblank_list);
        return;
@@ -396,13 +399,13 @@ destroy_client_callback(struct wl_resource *resource)
 
 static void
 _tdm_server_cb_create_client(struct wl_client *client,
-                             struct wl_resource *resource, uint32_t id)
+                                                        struct wl_resource *resource, uint32_t id)
 {
        tdm_private_server *private_server = wl_resource_get_user_data(resource);
        tdm_server_client_info *client_info;
        struct wl_resource *client_resource;
 
-       client_info = calloc(1, sizeof *client_info);
+       client_info = calloc(1, sizeof * client_info);
        if (!client_info) {
                wl_resource_post_no_memory(resource);
                TDM_ERR("alloc failed");
@@ -411,7 +414,7 @@ _tdm_server_cb_create_client(struct wl_client *client,
 
        client_resource =
                wl_resource_create(client, &wl_tdm_client_interface,
-                                  wl_resource_get_version(resource), id);
+                                                  wl_resource_get_version(resource), id);
        if (!client_resource) {
                wl_resource_post_no_memory(resource);
                free(client_info);
@@ -423,7 +426,7 @@ _tdm_server_cb_create_client(struct wl_client *client,
        client_info->resource = client_resource;
 
        wl_resource_set_implementation(client_resource, &tdm_client_implementation,
-                                      client_info, destroy_client_callback);
+                                                                  client_info, destroy_client_callback);
 
        LIST_ADDTAIL(&client_info->link, &private_server->client_list);
 }
@@ -434,7 +437,7 @@ static const struct wl_tdm_interface tdm_implementation = {
 
 static void
 _tdm_server_bind(struct wl_client *client, void *data,
-                 uint32_t version, uint32_t id)
+                                uint32_t version, uint32_t id)
 {
        struct wl_resource *resource;
 
@@ -465,12 +468,12 @@ tdm_server_init(tdm_private_loop *private_loop)
        TDM_RETURN_VAL_IF_FAIL(private_loop, TDM_ERROR_OPERATION_FAILED);
        TDM_RETURN_VAL_IF_FAIL(private_loop->wl_display, TDM_ERROR_OPERATION_FAILED);
 
-       if(wl_display_add_socket(private_loop->wl_display, "tdm-socket")) {
+       if (wl_display_add_socket(private_loop->wl_display, "tdm-socket")) {
                TDM_ERR("createing a tdm-socket failed");
                return TDM_ERROR_OPERATION_FAILED;
        }
 
-       private_server = calloc(1, sizeof *private_server);
+       private_server = calloc(1, sizeof * private_server);
        if (!private_server) {
                TDM_ERR("alloc failed");
                return TDM_ERROR_OUT_OF_MEMORY;
@@ -480,7 +483,7 @@ tdm_server_init(tdm_private_loop *private_loop)
        LIST_INITHEAD(&private_server->vblank_list);
 
        if (!wl_global_create(private_loop->wl_display, &wl_tdm_interface, 1,
-                             private_server, _tdm_server_bind)) {
+                                                 private_server, _tdm_server_bind)) {
                TDM_ERR("creating a global resource failed");
                free(private_server);
                return TDM_ERROR_OUT_OF_MEMORY;