server: check null of current mode for voutput set mode
[platform/core/uifw/libtdm.git] / src / tdm_server.c
index 4d3ad7c..6c4c6ab 100644 (file)
@@ -72,6 +72,7 @@ typedef struct _tdm_server_voutput_buffer {
        struct list_head link;
        struct wl_resource *wl_buffer;
        tbm_surface_h buffer;
+       int need_reset;
 } tdm_server_voutput_buffer;
 
 typedef struct _tdm_server_voutput_info {
@@ -870,8 +871,8 @@ _tdm_voutput_cb_set_mode(struct wl_client *client, struct wl_resource *resource,
        tdm_server_voutput_info *voutput_info = NULL;
        tdm_output *output = NULL;
        tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
-       const tdm_output_mode *modes, *mode;
-
+       const tdm_output_mode *modes, *mode, *current_mode;
+       tdm_server_voutput_buffer *vb = NULL, *vbb = NULL;
        int count = 0;
        tdm_error ret;
 
@@ -889,8 +890,21 @@ _tdm_voutput_cb_set_mode(struct wl_client *client, struct wl_resource *resource,
        mode = &modes[index];
        TDM_DBG("mode set request to index:%d (%dx%d, %d)", index, mode->hdisplay, mode->vdisplay, mode->vrefresh);
 
-       ret = tdm_output_set_mode(output, mode);
+       ret = tdm_output_get_mode(output, &current_mode);
        TDM_RETURN_IF_FAIL(ret == TDM_ERROR_NONE);
+       if (mode == current_mode) {
+               TDM_DBG("same mode");
+               return;
+       }
+
+       if (current_mode && ((mode->hdisplay != current_mode->hdisplay) || (mode->vdisplay != current_mode->vdisplay))) {
+               LIST_FOR_EACH_ENTRY_SAFE(vb, vbb, &voutput_info->buffer_list, link) {
+                       if (vb->wl_buffer == voutput_info->attach_buffer->wl_buffer)
+                               voutput_info->attach_buffer->need_reset = 1;
+                       else
+                               wl_tdm_voutput_send_destroy_buffer(voutput_info->resource, vb->wl_buffer);
+               }
+       }
 
        tdm_output_request_mode_set(voutput_info->output, index);
 }
@@ -926,16 +940,19 @@ _tdm_voutput_cb_disconnect(struct wl_client *client, struct wl_resource *resourc
        voutput_info->mmwidth = 0;
        voutput_info->mmheight = 0;
 
+       if (voutput_info->request_commit == 1) {
+               tdm_output_unset_voutput_commit(voutput_info->voutput);
+               voutput_info->request_commit = 0;
+       }
+
        if (voutput_info->attach_buffer) {
                tbm_surface_h buffer = voutput_info->attach_buffer->buffer;
                tbm_surface_internal_unref(buffer);
                voutput_info->committing = 0;
+               if (voutput_info->attach_buffer->need_reset)
+                       wl_tdm_voutput_send_destroy_buffer(voutput_info->resource, voutput_info->attach_buffer->wl_buffer);
                voutput_info->attach_buffer = NULL;
-       }
-
-       if (voutput_info->request_commit == 1) {
-               tdm_output_unset_voutput_commit(voutput_info->voutput);
-               voutput_info->request_commit = 0;
+               tdm_voutput_commit_done(voutput_info->voutput);
        }
 
        tdm_voutput_disconnect(voutput_info->voutput);
@@ -956,6 +973,8 @@ _tdm_voutput_cb_commit_done(struct wl_client *client, struct wl_resource *resour
        buffer = voutput_info->attach_buffer->buffer;
        tbm_surface_internal_unref(buffer);
        voutput_info->committing = 0;
+       if (voutput_info->attach_buffer->need_reset)
+               wl_tdm_voutput_send_destroy_buffer(voutput_info->resource, voutput_info->attach_buffer->wl_buffer);
        voutput_info->attach_buffer = NULL;
 
        if (voutput_info->request_commit == 1)
@@ -1148,7 +1167,6 @@ _tdm_output_get_voutput_buffer(tdm_server_voutput_info *voutput_info, tbm_surfac
 
        LIST_FOR_EACH_ENTRY(vb, &voutput_info->buffer_list, link) {
                if (vb && vb->buffer == buffer) {
-                       tbm_surface_internal_ref(vb->buffer);
                        return vb;
                }
        }
@@ -1206,6 +1224,7 @@ tdm_voutput_attach_buffer(tdm_voutput *voutput, tbm_surface_h buffer)
 
        voutput_info->attach_buffer = voutput_buffer;
 
+       tbm_surface_internal_ref(buffer);
        wl_tdm_voutput_send_attach_buffer(voutput_info->resource, voutput_buffer->wl_buffer);
 
        return TDM_ERROR_NONE;
@@ -1252,6 +1271,12 @@ tdm_voutput_cb_resource_destroy(struct wl_resource *resource)
                tdm_output_unset_voutput_commit(voutput_info->voutput);
 
        if (voutput) {
+               if (voutput_info->request_commit == 1) {
+                       tdm_output_unset_voutput_commit(voutput_info->voutput);
+                       voutput_info->request_commit = 0;
+                       tdm_voutput_disconnect(voutput_info->voutput);
+               }
+
                ret = tdm_voutput_destroy(voutput);
                if (ret != TDM_ERROR_NONE)
                        TDM_ERR("_tdm_voutput_cb_destroy fail");