Revert "virtual (client): Added implementation for setting available format."
[platform/core/uifw/libtdm.git] / client / tdm_client.c
index 65c37da..92b1626 100644 (file)
@@ -92,12 +92,7 @@ typedef struct _tdm_private_client_output {
 typedef struct _tdm_private_client_voutput {
     tdm_private_client_output base;
        struct wl_tdm_voutput *wl_voutput;
-
-       struct
-       {
-               int count;
-               tbm_format *formats;
-       } available_formats;
+       struct list_head commit_handler_list;
 
        struct
        {
@@ -157,6 +152,17 @@ typedef struct _tdm_client_wait_info {
        struct list_head call_link;
 } tdm_client_wait_info;
 
+typedef struct _tdm_client_voutput_commit_handler_info
+{
+       tdm_private_client_voutput *private_voutput;
+
+       tdm_client_voutput_commit_handler func;
+       void *user_data;
+
+       struct list_head link;
+       struct list_head call_link;
+} tdm_client_voutput_commit_handler_info;
+
 static unsigned int
 _tdm_client_check_wl_error(tdm_private_client *private_client, const char *func, int line)
 {
@@ -1615,6 +1621,33 @@ tdm_client_vblank_is_waiting(tdm_client_vblank *vblank)
 }
 
 void
+tdm_client_voutput_cb_commit(void *data, struct wl_tdm_voutput *wl_voutput)
+{
+       tdm_private_client_voutput *private_voutput;
+       tdm_private_client *private_client;
+       tdm_client_voutput_commit_handler_info *h = NULL, *hh = NULL;
+       struct list_head call_list;
+
+       private_voutput = (tdm_private_client_voutput *)data;
+       TDM_RETURN_IF_FAIL(private_voutput != NULL);
+
+       private_client = private_voutput->base.private_client;
+
+       LIST_INITHEAD(&call_list);
+
+       LIST_FOR_EACH_ENTRY(h, &private_voutput->commit_handler_list, link) {
+               LIST_ADDTAIL(&h->call_link, &call_list);
+       }
+
+       pthread_mutex_unlock(&private_client->lock);
+       LIST_FOR_EACH_ENTRY_SAFE(h, hh, &call_list, call_link) {
+               if (h->func)
+                       h->func(private_voutput, h->user_data);
+       }
+       pthread_mutex_lock(&private_client->lock);
+}
+
+void
 tdm_client_voutput_cb_ack_message(void *data, struct wl_tdm_voutput *wl_voutput, uint32_t msg)
 {
        tdm_private_client_voutput *private_voutput = data;
@@ -1623,6 +1656,7 @@ tdm_client_voutput_cb_ack_message(void *data, struct wl_tdm_voutput *wl_voutput,
 }
 
 static const struct wl_tdm_voutput_listener tdm_client_voutput_lisntener = {
+       tdm_client_voutput_cb_commit,
        tdm_client_voutput_cb_ack_message
 };
 
@@ -1693,6 +1727,8 @@ tdm_client_create_voutput(tdm_client *client, const char *name, tdm_error *error
                /* LOCV_EXCL_STOP */
        }
 
+       LIST_INITHEAD(&private_voutput->commit_handler_list);
+
        private_voutput->base.private_client = private_client;
 
        private_voutput->wl_voutput = wl_tdm_create_voutput((struct wl_tdm *)wrapper, private_voutput->base.name);
@@ -1742,6 +1778,7 @@ void
 tdm_client_voutput_destroy(tdm_client_voutput *voutput)
 {
        tdm_private_client_voutput *private_voutput = (tdm_private_client_voutput *)voutput;
+       tdm_client_voutput_commit_handler_info *h = NULL, *hh = NULL;
 
        if (!private_voutput)
                return;
@@ -1749,8 +1786,10 @@ tdm_client_voutput_destroy(tdm_client_voutput *voutput)
        if (private_voutput->available_modes.modes)
                free(private_voutput->available_modes.modes);
 
-       if (private_voutput->available_formats.formats)
-               free(private_voutput->available_formats.formats);
+       LIST_FOR_EACH_ENTRY_SAFE(h, hh, &private_voutput->commit_handler_list, link) {
+               LIST_DEL(&h->link);
+               free(h);
+       }
 
        wl_tdm_voutput_destroy(private_voutput->wl_voutput);
 
@@ -1787,50 +1826,108 @@ tdm_client_voutput_set_available_modes(tdm_client_voutput *voutput, const tdm_cl
 }
 
 tdm_error
-tdm_client_voutput_set_available_formats(tdm_client_voutput *voutput, const tbm_format *formats, const int count)
+tdm_client_voutput_set_physical_size(tdm_client_voutput *voutput, unsigned int mmWidth, unsigned int mmHeight)
 {
        tdm_private_client_voutput *private_voutput;
 
        TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
-
-       if ((count > 0) && (formats == NULL))
-               return TDM_ERROR_INVALID_PARAMETER;
+       TDM_RETURN_VAL_IF_FAIL(mmWidth != 0, TDM_ERROR_INVALID_PARAMETER);
+       TDM_RETURN_VAL_IF_FAIL(mmHeight != 0, TDM_ERROR_INVALID_PARAMETER);
 
        private_voutput = (tdm_private_client_voutput *)voutput;
 
        if (private_voutput->base.connection == TDM_OUTPUT_CONN_STATUS_CONNECTED)
                return TDM_ERROR_BAD_REQUEST;
 
-       if (private_voutput->available_formats.formats)
-               free(private_voutput->available_formats.formats);
+       private_voutput->mmwidth = mmWidth;
+       private_voutput->mmheight = mmHeight;
+
+       return TDM_ERROR_NONE;
+}
+
+tdm_error
+tdm_client_voutput_add_commit_handler(tdm_client_voutput *voutput,
+                                                                         tdm_client_voutput_commit_handler func,
+                                                                         void *user_data)
+{
+       tdm_private_client_voutput *private_voutput;
+       tdm_private_client *private_client;
+       tdm_client_voutput_commit_handler_info *h = NULL;
 
-       private_voutput->available_formats.count = count;
+       TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
+       TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
 
-       if (count != 0)
-       {
-               private_voutput->available_formats.formats = calloc(count, sizeof(tbm_format));
-               memcpy(private_voutput->available_formats.formats, formats, sizeof(tbm_format) * count);
+       private_voutput = (tdm_private_client_voutput *)voutput;
+       private_client = private_voutput->base.private_client;
+
+       LIST_FOR_EACH_ENTRY(h, &private_voutput->commit_handler_list, link) {
+               if (h->func == func && h->user_data == user_data) {
+                       TDM_ERR("can't add twice");
+                       return TDM_ERROR_BAD_REQUEST;
+               }
        }
 
+       h = calloc(1, sizeof *h);
+       TDM_RETURN_VAL_IF_FAIL(h != NULL, TDM_ERROR_OUT_OF_MEMORY);
+
+       pthread_mutex_lock(&private_client->lock);
+
+       if (CHECK_WL_PROTOCOL_ERROR(private_client)) {
+               free(h);
+               pthread_mutex_unlock(&private_client->lock);
+               return TDM_ERROR_PROTOCOL_ERROR;
+       }
+
+       h->private_voutput = private_voutput;
+       h->func = func;
+       h->user_data = user_data;
+       LIST_ADDTAIL(&h->link, &private_voutput->commit_handler_list);
+       LIST_INITHEAD(&h->call_link);
+
+       pthread_mutex_unlock(&private_client->lock);
+
        return TDM_ERROR_NONE;
 }
 
-tdm_error
-tdm_client_voutput_set_physical_size(tdm_client_voutput *voutput, unsigned int mmWidth, unsigned int mmHeight)
+void
+tdm_client_voutput_remove_commit_handler(tdm_client_voutput *voutput,
+                                                                                tdm_client_voutput_commit_handler func,
+                                                                                void *user_data)
 {
        tdm_private_client_voutput *private_voutput;
+       tdm_private_client *private_client;
+       tdm_client_voutput_commit_handler_info *h = NULL;
 
-       TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
-       TDM_RETURN_VAL_IF_FAIL(mmWidth != 0, TDM_ERROR_INVALID_PARAMETER);
-       TDM_RETURN_VAL_IF_FAIL(mmHeight != 0, TDM_ERROR_INVALID_PARAMETER);
+       TDM_RETURN_IF_FAIL(voutput != NULL);
+       TDM_RETURN_IF_FAIL(func != NULL);
 
        private_voutput = (tdm_private_client_voutput *)voutput;
+       private_client = private_voutput->base.private_client;
 
-       if (private_voutput->base.connection == TDM_OUTPUT_CONN_STATUS_CONNECTED)
-               return TDM_ERROR_BAD_REQUEST;
+       pthread_mutex_lock(&private_client->lock);
 
-       private_voutput->mmwidth = mmWidth;
-       private_voutput->mmheight = mmHeight;
+       LIST_FOR_EACH_ENTRY(h, &private_voutput->commit_handler_list, link) {
+               if (h->func != func || h->user_data != user_data)
+                       continue;
+
+               LIST_DEL(&h->link);
+               free(h);
+
+               pthread_mutex_unlock(&private_client->lock);
+       }
+
+       pthread_mutex_unlock(&private_client->lock);
+}
+
+tdm_error
+tdm_client_voutput_commit_done(tdm_client_voutput *voutput)
+{
+       tdm_private_client_voutput *private_voutput;
+
+       TDM_RETURN_VAL_IF_FAIL(voutput != NULL, TDM_ERROR_INVALID_PARAMETER);
+
+       private_voutput = (tdm_private_client_voutput *)voutput;
+       wl_tdm_voutput_commit_done(private_voutput->wl_voutput);
 
        return TDM_ERROR_NONE;
 }
@@ -1876,23 +1973,6 @@ tdm_client_output_set_mode(tdm_client_output *output, const tdm_client_output_mo
 }
 
 void
-_tdm_client_voutput_send_available_formats(tdm_private_client_voutput *private_voutput)
-{
-       tbm_format *format;
-       struct wl_array array;
-       int i, size;
-
-       size = sizeof(tbm_format);
-       wl_array_init(&array);
-       for (i = 0; i < private_voutput->available_formats.count; i++) {
-               format = wl_array_add(&array, size);
-               *format = private_voutput->available_formats.formats[i];
-       }
-       wl_tdm_voutput_set_available_formats(private_voutput->wl_voutput, &array);
-        wl_array_release(&array);
-}
-
-void
 _tdm_client_voutput_send_available_modes(tdm_private_client_voutput *private_voutput)
 {
        tdm_client_output_mode *modes, *mode;
@@ -1928,7 +2008,6 @@ tdm_client_output_connect(tdm_client_output *output)
        private_output->connection = TDM_OUTPUT_CONN_STATUS_CONNECTED;
 
        _tdm_client_voutput_send_available_modes(private_voutput);
-       _tdm_client_voutput_send_available_formats(private_voutput);
 
        wl_tdm_voutput_set_physical_size(private_voutput->wl_voutput, private_voutput->mmwidth, private_voutput->mmheight);